adb: add `adb shell exit 42` stress test.
Add a test to hammer on `adb shell exit $n` for flakiness.
Bug: http://b/74616284
Test: python test_device.py
Change-Id: I6a842960f5b55ff739044698f5c9683992fc42f1
diff --git a/adb/test_device.py b/adb/test_device.py
index 4cf2206..d422df2 100644
--- a/adb/test_device.py
+++ b/adb/test_device.py
@@ -31,6 +31,7 @@
import subprocess
import sys
import tempfile
+import threading
import time
import unittest
@@ -493,6 +494,29 @@
stdout, _ = self.device.shell(["cat", log_path])
self.assertEqual(stdout.strip(), "SIGHUP")
+ def test_exit_stress(self):
+ """Hammer `adb shell exit 42` with multiple threads."""
+ thread_count = 48
+ result = dict()
+ def hammer(thread_idx, thread_count, result):
+ success = True
+ for i in range(thread_idx, 240, thread_count):
+ ret = subprocess.call(['adb', 'shell', 'exit {}'.format(i)])
+ if ret != i % 256:
+ success = False
+ break
+ result[thread_idx] = success
+
+ threads = []
+ for i in range(thread_count):
+ thread = threading.Thread(target=hammer, args=(i, thread_count, result))
+ thread.start()
+ threads.append(thread)
+ for thread in threads:
+ thread.join()
+ for i, success in result.iteritems():
+ self.assertTrue(success)
+
class ArgumentEscapingTest(DeviceTest):
def test_shell_escaping(self):