Skip to content

Commit 2e0d742

Browse files
committed
Add test for ioctl
1 parent cd60a2c commit 2e0d742

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_fcntl.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -111,3 +111,26 @@ def test_flock_s_and_s(self):
111111
finally:
112112
fcntl.flock(file, fcntl.LOCK_UN)
113113
os.close(file)
114+
115+
116+
class IoctlTests(unittest.TestCase):
117+
# Taken from CPython test_ioctl.py which unfortunately skips the whole file when not in a terminal
118+
def test_ioctl_signed_unsigned_code_param(self):
119+
import pty, termios, struct
120+
mfd, sfd = pty.openpty()
121+
try:
122+
if termios.TIOCSWINSZ < 0:
123+
set_winsz_opcode_maybe_neg = termios.TIOCSWINSZ
124+
set_winsz_opcode_pos = termios.TIOCSWINSZ & 0xffffffff
125+
else:
126+
set_winsz_opcode_pos = termios.TIOCSWINSZ
127+
set_winsz_opcode_maybe_neg, = struct.unpack("i",
128+
struct.pack("I", termios.TIOCSWINSZ))
129+
130+
our_winsz = struct.pack("HHHH",80,25,0,0)
131+
# test both with a positive and potentially negative ioctl code
132+
new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_pos, our_winsz)
133+
new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_maybe_neg, our_winsz)
134+
finally:
135+
os.close(mfd)
136+
os.close(sfd)

0 commit comments

Comments
 (0)