Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2578)

Unified Diff: build/android/pylib/monkey/test_runner.py

Issue 22617003: Converts monkey test to its own test type (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Inlines TEST_TOKEN Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/pylib/monkey/test_options.py ('k') | build/android/run_monkey_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/monkey/test_runner.py
diff --git a/build/android/pylib/monkey/test_runner.py b/build/android/pylib/monkey/test_runner.py
new file mode 100644
index 0000000000000000000000000000000000000000..2bd617362f34f23103c5b6681e6b3b1002e9e322
--- /dev/null
+++ b/build/android/pylib/monkey/test_runner.py
@@ -0,0 +1,77 @@
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Runs a monkey test on a single device."""
+
+import random
+
+from pylib.base import base_test_result
+from pylib.base import base_test_runner
+
+
+class TestRunner(base_test_runner.BaseTestRunner):
+ """A TestRunner instance runs a monkey test on a single device."""
+
+ def __init__(self, test_options, device, shard_index):
+ super(TestRunner, self).__init__(device, None, test_options.build_type)
+ self.options = test_options
+
+ def _LaunchMonkeyTest(self):
+ """Runs monkey test for a given package.
+
+ Returns:
+ Output from the monkey command on the device.
+ """
+
+ timeout_ms = self.options.event_count * self.options.throttle * 1.5
+
+ cmd = ['monkey',
+ '-p %s' % self.options.package_name,
+ ' '.join(['-c %s' % c for c in self.options.category]),
+ '--throttle %d' % self.options.throttle,
+ '-s %d' % (self.options.seed or random.randint(1, 100)),
+ '-v ' * self.options.verbose_count,
+ '--monitor-native-crashes',
+ '--kill-process-after-error',
+ self.options.extra_args,
+ '%d' % self.options.event_count]
+ return self.adb.RunShellCommand(' '.join(cmd), timeout_time=timeout_ms)
+
+ def RunTest(self, test_name):
+ """Run a Monkey test on the device.
+
+ Args:
+ test_name: String to use for logging the test result.
+
+ Returns:
+ A tuple of (TestRunResults, retry).
+ """
+ self.adb.StartActivity(self.options.package_name,
+ self.options.activity_name,
+ wait_for_completion=True,
+ action='android.intent.action.MAIN',
+ force_stop=True)
+
+ # Chrome crashes are not always caught by Monkey test runner.
+ # Verify Chrome has the same PID before and after the test.
+ before_pids = self.adb.ExtractPid(self.options.package_name)
+
+ # Run the test.
+ output = ''
+ if before_pids:
+ output = '\n'.join(self._LaunchMonkeyTest())
+ after_pids = self.adb.ExtractPid(self.options.package_name)
+
+ crashed = (not before_pids or not after_pids
+ or after_pids[0] != before_pids[0])
+
+ results = base_test_result.TestRunResults()
+ if 'Monkey finished' in output and not crashed:
+ result = base_test_result.BaseTestResult(
+ test_name, base_test_result.ResultType.PASS, log=output)
+ else:
+ result = base_test_result.BaseTestResult(
+ test_name, base_test_result.ResultType.FAIL, log=output)
+ results.AddResult(result)
+ return results, False
« no previous file with comments | « build/android/pylib/monkey/test_options.py ('k') | build/android/run_monkey_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698