Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / lib / python2.4 / test / test_ioctl.py
CommitLineData
86530b38
AT
1import unittest
2from test.test_support import TestSkipped, run_unittest
3import os, struct
4try:
5 import fcntl, termios
6except ImportError:
7 raise TestSkipped("No fcntl or termios module")
8if not hasattr(termios,'TIOCGPGRP'):
9 raise TestSkipped("termios module doesn't have TIOCGPGRP")
10
11try:
12 tty = open("/dev/tty", "r")
13 tty.close()
14except IOError:
15 raise TestSkipped("Unable to open /dev/tty")
16
17class IoctlTests(unittest.TestCase):
18 def test_ioctl(self):
19 # If this process has been put into the background, TIOCGPGRP returns
20 # the session ID instead of the process group id.
21 ids = (os.getpgrp(), os.getsid(0))
22 tty = open("/dev/tty", "r")
23 r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ")
24 rpgrp = struct.unpack("i", r)[0]
25 self.assert_(rpgrp in ids, "%s not in %s" % (rpgrp, ids))
26
27 def test_ioctl_mutate(self):
28 import array
29 buf = array.array('i', [0])
30 ids = (os.getpgrp(), os.getsid(0))
31 tty = open("/dev/tty", "r")
32 r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, 1)
33 rpgrp = buf[0]
34 self.assertEquals(r, 0)
35 self.assert_(rpgrp in ids, "%s not in %s" % (rpgrp, ids))
36
37def test_main():
38 run_unittest(IoctlTests)
39
40if __name__ == "__main__":
41 test_main()