3 ### Test system-specific functionality
5 ### (c) 2019 Straylight/Edgeware
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of the Python interface to mLib.
12 ### mLib/Python is free software: you can redistribute it and/or modify it
13 ### under the terms of the GNU General Public License as published by the
14 ### Free Software Foundation; either version 2 of the License, or (at your
15 ### option) any later version.
17 ### mLib/Python is distributed in the hope that it will be useful, but
18 ### WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ### General Public License for more details.
22 ### You should have received a copy of the GNU General Public License
23 ### along with mLib/Python. If not, write to the Free Software
24 ### Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
35 ## Cygwin leaves cruft in the top bits of inode numbers for some reason.
36 if SYS
.platform
.startswith('cygwin'):
37 def _hack_inode(ino
): return ino
&0x0000ffffffffffff
39 def _hack_inode(ino
): return ino
41 ###--------------------------------------------------------------------------
42 class TestSys (U
.TestCase
):
46 return st
.st_dev
, _hack_inode(st
.st_ino
)
48 def _check_same_file(me
, fd0
, fd1
):
49 me
.assertEqual(me
._fdid(fd0
), me
._fdid(fd1
))
58 f
= OS
.fdopen(fd
, "r")
60 of
, ofd
= FC
.fcntl(fd
, FC
.F_GETFL
), FC
.fcntl(fd
, FC
.F_GETFD
)
61 M
.fdflags(fd
, fbic
= OS
.O_NONBLOCK
, fxor
= OS
.O_NONBLOCK
)
62 me
.assertEqual(FC
.fcntl(fd
, FC
.F_GETFL
), of | OS
.O_NONBLOCK
)
63 M
.fdflags(f
, fbic
= OS
.O_NONBLOCK
)
64 me
.assertEqual(FC
.fcntl(fd
, FC
.F_GETFL
), of
&~OS
.O_NONBLOCK
)
65 M
.fdflags(fd
, fdbic
= FC
.FD_CLOEXEC
, fdxor
= FC
.FD_CLOEXEC
)
66 me
.assertEqual(FC
.fcntl(fd
, FC
.F_GETFD
), ofd | FC
.FD_CLOEXEC
)
67 M
.fdflags(f
, fdbic
= FC
.FD_CLOEXEC
)
68 me
.assertEqual(FC
.fcntl(fd
, FC
.F_GETFD
), ofd
&~FC
.FD_CLOEXEC
)
69 me
.assertRaises(AttributeError, M
.fdflags
, "bzzt")
70 me
.assertRaises(OSError, M
.fdflags
, -1, 1, 1)
75 sk0
, sk1
= SK
.socketpair(SK
.AF_UNIX
, SK
.SOCK_STREAM
)
79 msg
= T
.bin("some unnecessary message")
80 n
= M
.fdsend(sk0
, fd
, msg
)
81 me
.assertEqual(n
, len(msg
))
82 nfd
, buf
= M
.fdrecv(sk1
, 32)
83 me
.assertEqual(buf
, msg
)
84 me
._check_same_file(fd
, nfd
)
85 OS
.close(nfd
); nfd
= -1
87 sk0
.close(); sk1
.close()
89 if nfd
!= -1: OS
.close(nfd
)
93 fds
= [me
._make_fd() for i
in T
.range(NFD
)]
94 v
= [(fds
[i
], fds
[(i
+ 1)%5]) for i
in T
.range(NFD
)]
96 id = [me
._fdid(fds
[i
]) for i
in T
.range(NFD
)]
98 me
.assertTrue(vv
is v
)
99 for i
in T
.range(NFD
):
101 me
.assertEqual(cur
, want
)
102 me
.assertEqual(cur
, fds
[(i
+ 1)%NFD
])
103 me
.assertEqual(me
._fdid(cur
), id[i
])
105 for fd
, _
in v
: OS
.close(fd
)
107 ###----- That's all, folks --------------------------------------------------
109 if __name__
== "__main__": U
.main()