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

Side by Side Diff: build/android/pylib/test_package_apk.py

Issue 11649008: Reorganize Android's test scripts into packages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « build/android/pylib/test_package.py ('k') | build/android/pylib/test_package_executable.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5
6 import os
7 import shlex
8 import sys
9 import tempfile
10 import time
11
12 import android_commands
13 import constants
14 from android_commands import errors
15 from test_package import TestPackage
16 from pylib import pexpect
17
18 class TestPackageApk(TestPackage):
19 """A helper class for running APK-based native tests.
20
21 Args:
22 adb: ADB interface the tests are using.
23 device: Device to run the tests.
24 test_suite: A specific test suite to run, empty to run all.
25 timeout: Timeout for each test.
26 cleanup_test_files: Whether or not to cleanup test files on device.
27 tool: Name of the Valgrind tool.
28 dump_debug_info: A debug_info object.
29 """
30
31 def __init__(self, adb, device, test_suite, timeout,
32 cleanup_test_files, tool, dump_debug_info):
33 TestPackage.__init__(self, adb, device, test_suite, timeout,
34 cleanup_test_files, tool, dump_debug_info)
35
36 def _CreateTestRunnerScript(self, options):
37 command_line_file = tempfile.NamedTemporaryFile()
38 # GTest expects argv[0] to be the executable path.
39 command_line_file.write(self.test_suite_basename + ' ' + options)
40 command_line_file.flush()
41 self.adb.PushIfNeeded(command_line_file.name,
42 constants.TEST_EXECUTABLE_DIR +
43 '/chrome-native-tests-command-line')
44
45 def _GetGTestReturnCode(self):
46 return None
47
48 def _GetFifo(self):
49 # The test.fifo path is determined by:
50 # testing/android/java/src/org/chromium/native_test/
51 # ChromeNativeTestActivity.java and
52 # testing/android/native_test_launcher.cc
53 return '/data/data/org.chromium.native_test/files/test.fifo'
54
55 def _ClearFifo(self):
56 self.adb.RunShellCommand('rm -f ' + self._GetFifo())
57
58 def _WatchFifo(self, timeout, logfile=None):
59 for i in range(10):
60 if self.adb.FileExistsOnDevice(self._GetFifo()):
61 print 'Fifo created...'
62 break
63 time.sleep(i)
64 else:
65 raise errors.DeviceUnresponsiveError(
66 'Unable to find fifo on device %s ' % self._GetFifo())
67 args = shlex.split(self.adb.Adb()._target_arg)
68 args += ['shell', 'cat', self._GetFifo()]
69 return pexpect.spawn('adb', args, timeout=timeout, logfile=logfile)
70
71 def GetAllTests(self):
72 """Returns a list of all tests available in the test suite."""
73 self._CreateTestRunnerScript('--gtest_list_tests')
74 try:
75 self.tool.SetupEnvironment()
76 # Clear and start monitoring logcat.
77 self._ClearFifo()
78 self.adb.RunShellCommand(
79 'am start -n '
80 'org.chromium.native_test/'
81 'org.chromium.native_test.ChromeNativeTestActivity')
82 # Wait for native test to complete.
83 p = self._WatchFifo(timeout=30 * self.tool.GetTimeoutScale())
84 p.expect("<<ScopedMainEntryLogger")
85 p.close()
86 finally:
87 self.tool.CleanUpEnvironment()
88 # We need to strip the trailing newline.
89 content = [line.rstrip() for line in p.before.splitlines()]
90 ret = self._ParseGTestListTests(content)
91 return ret
92
93 def CreateTestRunnerScript(self, gtest_filter, test_arguments):
94 self._CreateTestRunnerScript('--gtest_filter=%s %s' % (gtest_filter,
95 test_arguments))
96
97 def RunTestsAndListResults(self):
98 try:
99 self.tool.SetupEnvironment()
100 self._ClearFifo()
101 self.adb.RunShellCommand(
102 'am start -n '
103 'org.chromium.native_test/'
104 'org.chromium.native_test.ChromeNativeTestActivity')
105 finally:
106 self.tool.CleanUpEnvironment()
107 logfile = android_commands.NewLineNormalizer(sys.stdout)
108 return self._WatchTestOutput(self._WatchFifo(timeout=10, logfile=logfile))
109
110 def StripAndCopyExecutable(self):
111 self.tool.CopyFiles()
112 # Always uninstall the previous one (by activity name); we don't
113 # know what was embedded in it.
114 self.adb.ManagedInstall(self.test_suite_full, False,
115 package_name='org.chromium.native_test')
116
117 def _GetTestSuiteBaseName(self):
118 """Returns the base name of the test suite."""
119 # APK test suite names end with '-debug.apk'
120 return os.path.basename(self.test_suite).rsplit('-debug', 1)[0]
OLDNEW
« no previous file with comments | « build/android/pylib/test_package.py ('k') | build/android/pylib/test_package_executable.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698