From c970aefadace2203f23f0b028b6c6be16e55dd04 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Mon, 19 Mar 2018 15:35:11 -0700 Subject: [PATCH] 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 --- adb/test_device.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/adb/test_device.py b/adb/test_device.py index 4cf2206f1..d422df25d 100644 --- a/adb/test_device.py +++ b/adb/test_device.py @@ -31,6 +31,7 @@ import string import subprocess import sys import tempfile +import threading import time import unittest @@ -493,6 +494,29 @@ class ShellTest(DeviceTest): 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):