Skip to content

gh-132742: Fix newly added tcflush() tests on Android #133070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions Lib/test/test_ioctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
import threading
import unittest
from test.support import get_attribute
from test import support
from test.support import threading_helper
from test.support.import_helper import import_module
fcntl = import_module('fcntl')
Expand All @@ -13,7 +13,7 @@
class IoctlTestsTty(unittest.TestCase):
@classmethod
def setUpClass(cls):
TIOCGPGRP = get_attribute(termios, 'TIOCGPGRP')
TIOCGPGRP = support.get_attribute(termios, 'TIOCGPGRP')
try:
tty = open("/dev/tty", "rb")
except OSError:
Expand Down Expand Up @@ -143,7 +143,9 @@ def setUp(self):
def test_ioctl_clear_input_or_output(self):
wfd = self.slave_fd
rfd = self.master_fd
inbuf = sys.platform == 'linux'
# The data is buffered in the input buffer on Linux, and in
# the output buffer on other platforms.
inbuf = sys.platform in ('linux', 'android')

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

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

def writer():
os.write(wfd, b'abc')
write_suspended.wait()
self.assertTrue(write_suspended.wait(support.SHORT_TIMEOUT))
os.write(wfd, b'def')
write_finished.set()

with threading_helper.start_threads([threading.Thread(target=writer)]):
self.assertEqual(os.read(rfd, 3), b'abc')
try:
fcntl.ioctl(wfd, termios.TCXONC, termios.TCOOFF)
write_suspended.set()
try:
fcntl.ioctl(wfd, termios.TCXONC, termios.TCOOFF)
finally:
write_suspended.set()
self.assertFalse(write_finished.wait(0.5),
'output was not suspended')
finally:
fcntl.ioctl(wfd, termios.TCXONC, termios.TCOON)
self.assertTrue(write_finished.wait(0.5),
self.assertTrue(write_finished.wait(support.SHORT_TIMEOUT),
'output was not resumed')
self.assertEqual(os.read(rfd, 1024), b'def')

Expand Down
17 changes: 11 additions & 6 deletions Lib/test/test_termios.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ def test_tcflush_errors(self):
def test_tcflush_clear_input_or_output(self):
wfd = self.fd
rfd = self.master_fd
inbuf = sys.platform == 'linux'
# The data is buffered in the input buffer on Linux, and in
# the output buffer on other platforms.
inbuf = sys.platform in ('linux', 'android')

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

@unittest.skipUnless(sys.platform == 'linux', 'only works on Linux')
@support.skip_android_selinux('tcflow')
@unittest.skipUnless(sys.platform in ('linux', 'android'), 'only works on Linux')
def test_tcflow_suspend_and_resume_output(self):
wfd = self.fd
rfd = self.master_fd
Expand All @@ -199,20 +202,22 @@ def test_tcflow_suspend_and_resume_output(self):

def writer():
os.write(wfd, b'abc')
write_suspended.wait()
self.assertTrue(write_suspended.wait(support.SHORT_TIMEOUT))
os.write(wfd, b'def')
write_finished.set()

with threading_helper.start_threads([threading.Thread(target=writer)]):
self.assertEqual(os.read(rfd, 3), b'abc')
try:
termios.tcflow(wfd, termios.TCOOFF)
write_suspended.set()
try:
termios.tcflow(wfd, termios.TCOOFF)
finally:
write_suspended.set()
self.assertFalse(write_finished.wait(0.5),
'output was not suspended')
finally:
termios.tcflow(wfd, termios.TCOON)
self.assertTrue(write_finished.wait(0.5),
self.assertTrue(write_finished.wait(support.SHORT_TIMEOUT),
'output was not resumed')
self.assertEqual(os.read(rfd, 1024), b'def')

Expand Down
Loading