Skip to content

Commit b71442f

Browse files
[3.13] gh-132742: Fix newly added tcflush() tests on Android (GH-133070) (GH-133104)
(cherry picked from commit 25186c2) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent ab89f6e commit b71442f

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

Lib/test/test_ioctl.py

Lines changed: 11 additions & 7 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')
@@ -173,20 +175,22 @@ def test_ioctl_suspend_and_resume_output(self):
173175

174176
def writer():
175177
os.write(wfd, b'abc')
176-
write_suspended.wait()
178+
self.assertTrue(write_suspended.wait(support.SHORT_TIMEOUT))
177179
os.write(wfd, b'def')
178180
write_finished.set()
179181

180182
with threading_helper.start_threads([threading.Thread(target=writer)]):
181183
self.assertEqual(os.read(rfd, 3), b'abc')
182184
try:
183-
fcntl.ioctl(wfd, termios.TCXONC, termios.TCOOFF)
184-
write_suspended.set()
185+
try:
186+
fcntl.ioctl(wfd, termios.TCXONC, termios.TCOOFF)
187+
finally:
188+
write_suspended.set()
185189
self.assertFalse(write_finished.wait(0.5),
186190
'output was not suspended')
187191
finally:
188192
fcntl.ioctl(wfd, termios.TCXONC, termios.TCOON)
189-
self.assertTrue(write_finished.wait(0.5),
193+
self.assertTrue(write_finished.wait(support.SHORT_TIMEOUT),
190194
'output was not resumed')
191195
self.assertEqual(os.read(rfd, 1024), b'def')
192196

Lib/test/test_termios.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ def test_tcflush_errors(self):
142142
def test_tcflush_clear_input_or_output(self):
143143
wfd = self.fd
144144
rfd = self.master_fd
145-
inbuf = sys.platform == 'linux'
145+
# The data is buffered in the input buffer on Linux, and in
146+
# the output buffer on other platforms.
147+
inbuf = sys.platform in ('linux', 'android')
146148

147149
os.write(wfd, b'abcdef')
148150
self.assertEqual(os.read(rfd, 2), b'ab')
@@ -187,20 +189,22 @@ def test_tcflow_suspend_and_resume_output(self):
187189

188190
def writer():
189191
os.write(wfd, b'abc')
190-
write_suspended.wait()
192+
self.assertTrue(write_suspended.wait(support.SHORT_TIMEOUT))
191193
os.write(wfd, b'def')
192194
write_finished.set()
193195

194196
with threading_helper.start_threads([threading.Thread(target=writer)]):
195197
self.assertEqual(os.read(rfd, 3), b'abc')
196198
try:
197-
termios.tcflow(wfd, termios.TCOOFF)
198-
write_suspended.set()
199+
try:
200+
termios.tcflow(wfd, termios.TCOOFF)
201+
finally:
202+
write_suspended.set()
199203
self.assertFalse(write_finished.wait(0.5),
200204
'output was not suspended')
201205
finally:
202206
termios.tcflow(wfd, termios.TCOON)
203-
self.assertTrue(write_finished.wait(0.5),
207+
self.assertTrue(write_finished.wait(support.SHORT_TIMEOUT),
204208
'output was not resumed')
205209
self.assertEqual(os.read(rfd, 1024), b'def')
206210

0 commit comments

Comments
 (0)