Skip to content

Commit 25186c2

Browse files
gh-132742: Fix newly added tcflush() tests on Android (GH-133070)
1 parent 3940e1f commit 25186c2

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

Lib/test/test_ioctl.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
import threading
66
import unittest
7-
from test.support import get_attribute
7+
from test import support
88
from test.support import threading_helper
99
from test.support.import_helper import import_module
1010
fcntl = import_module('fcntl')
@@ -13,7 +13,7 @@
1313
class IoctlTestsTty(unittest.TestCase):
1414
@classmethod
1515
def setUpClass(cls):
16-
TIOCGPGRP = get_attribute(termios, 'TIOCGPGRP')
16+
TIOCGPGRP = support.get_attribute(termios, 'TIOCGPGRP')
1717
try:
1818
tty = open("/dev/tty", "rb")
1919
except OSError:
@@ -143,7 +143,9 @@ def setUp(self):
143143
def test_ioctl_clear_input_or_output(self):
144144
wfd = self.slave_fd
145145
rfd = self.master_fd
146-
inbuf = sys.platform == 'linux'
146+
# The data is buffered in the input buffer on Linux, and in
147+
# the output buffer on other platforms.
148+
inbuf = sys.platform in ('linux', 'android')
147149

148150
os.write(wfd, b'abcdef')
149151
self.assertEqual(os.read(rfd, 2), b'ab')
@@ -163,7 +165,8 @@ def test_ioctl_clear_input_or_output(self):
163165
os.write(wfd, b'ABCDEF')
164166
self.assertEqual(os.read(rfd, 1024), b'ABCDEF')
165167

166-
@unittest.skipUnless(sys.platform == 'linux', 'only works on Linux')
168+
@support.skip_android_selinux('tcflow')
169+
@unittest.skipUnless(sys.platform in ('linux', 'android'), 'only works on Linux')
167170
@unittest.skipUnless(hasattr(termios, 'TCXONC'), 'requires termios.TCXONC')
168171
def test_ioctl_suspend_and_resume_output(self):
169172
wfd = self.slave_fd
@@ -173,20 +176,22 @@ def test_ioctl_suspend_and_resume_output(self):
173176

174177
def writer():
175178
os.write(wfd, b'abc')
176-
write_suspended.wait()
179+
self.assertTrue(write_suspended.wait(support.SHORT_TIMEOUT))
177180
os.write(wfd, b'def')
178181
write_finished.set()
179182

180183
with threading_helper.start_threads([threading.Thread(target=writer)]):
181184
self.assertEqual(os.read(rfd, 3), b'abc')
182185
try:
183-
fcntl.ioctl(wfd, termios.TCXONC, termios.TCOOFF)
184-
write_suspended.set()
186+
try:
187+
fcntl.ioctl(wfd, termios.TCXONC, termios.TCOOFF)
188+
finally:
189+
write_suspended.set()
185190
self.assertFalse(write_finished.wait(0.5),
186191
'output was not suspended')
187192
finally:
188193
fcntl.ioctl(wfd, termios.TCXONC, termios.TCOON)
189-
self.assertTrue(write_finished.wait(0.5),
194+
self.assertTrue(write_finished.wait(support.SHORT_TIMEOUT),
190195
'output was not resumed')
191196
self.assertEqual(os.read(rfd, 1024), b'def')
192197

Lib/test/test_termios.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ def test_tcflush_errors(self):
152152
def test_tcflush_clear_input_or_output(self):
153153
wfd = self.fd
154154
rfd = self.master_fd
155-
inbuf = sys.platform == 'linux'
155+
# The data is buffered in the input buffer on Linux, and in
156+
# the output buffer on other platforms.
157+
inbuf = sys.platform in ('linux', 'android')
156158

157159
os.write(wfd, b'abcdef')
158160
self.assertEqual(os.read(rfd, 2), b'ab')
@@ -190,7 +192,8 @@ def test_tcflow_errors(self):
190192
self.assertRaises(TypeError, termios.tcflow, object(), termios.TCOON)
191193
self.assertRaises(TypeError, termios.tcflow, self.fd)
192194

193-
@unittest.skipUnless(sys.platform == 'linux', 'only works on Linux')
195+
@support.skip_android_selinux('tcflow')
196+
@unittest.skipUnless(sys.platform in ('linux', 'android'), 'only works on Linux')
194197
def test_tcflow_suspend_and_resume_output(self):
195198
wfd = self.fd
196199
rfd = self.master_fd
@@ -199,20 +202,22 @@ def test_tcflow_suspend_and_resume_output(self):
199202

200203
def writer():
201204
os.write(wfd, b'abc')
202-
write_suspended.wait()
205+
self.assertTrue(write_suspended.wait(support.SHORT_TIMEOUT))
203206
os.write(wfd, b'def')
204207
write_finished.set()
205208

206209
with threading_helper.start_threads([threading.Thread(target=writer)]):
207210
self.assertEqual(os.read(rfd, 3), b'abc')
208211
try:
209-
termios.tcflow(wfd, termios.TCOOFF)
210-
write_suspended.set()
212+
try:
213+
termios.tcflow(wfd, termios.TCOOFF)
214+
finally:
215+
write_suspended.set()
211216
self.assertFalse(write_finished.wait(0.5),
212217
'output was not suspended')
213218
finally:
214219
termios.tcflow(wfd, termios.TCOON)
215-
self.assertTrue(write_finished.wait(0.5),
220+
self.assertTrue(write_finished.wait(support.SHORT_TIMEOUT),
216221
'output was not resumed')
217222
self.assertEqual(os.read(rfd, 1024), b'def')
218223

0 commit comments

Comments
 (0)