3 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 """Runs all the native unit tests.
9 1. Copy over test binary to /data/local on device.
10 2. Resources: chrome/unit_tests requires resources (chrome.pak and en-US.pak)
11 to be deployed to the device. We use the device's $EXTERNAL_STORAGE as the
12 base dir (which maps to Context.getExternalFilesDir()).
14 3.1. chrome/unit_tests requires (via chrome_paths.cc) a directory named:
15 $EXTERNAL_STORAGE + /chrome/test/data
16 4. Run the binary in the device and stream the log to the host.
17 4.1. Optionally, filter specific tests.
18 4.2. If we're running a single test suite and we have multiple devices
19 connected, we'll shard the tests.
20 5. Clean up the device.
24 Individual tests in a test binary can be suppressed by listing it in
25 the gtest_filter directory in a file of the same name as the test binary,
26 one test per line. Here is an example:
28 $ cat gtest_filter/base_unittests_disabled
30 ReadOnlyFileUtilTest.ContentsEqual
32 This file is generated by the tests running on devices. If running on emulator,
33 additonal filter file which lists the tests only failed in emulator will be
34 loaded. We don't care about the rare testcases which succeeded on emuatlor, but
41 from pylib
import cmd_helper
42 from pylib
.gtest
import dispatch
43 from pylib
.utils
import emulator
44 from pylib
.utils
import run_tests_helper
45 from pylib
.utils
import test_options_parser
49 option_parser
= optparse
.OptionParser()
50 test_options_parser
.AddGTestOptions(option_parser
)
51 options
, args
= option_parser
.parse_args(argv
)
54 option_parser
.error('Unknown argument: %s' % args
[1:])
56 run_tests_helper
.SetLogLevel(options
.verbose_count
)
58 if options
.out_directory
:
59 cmd_helper
.OutDirectory
.set(options
.out_directory
)
61 if options
.use_emulator
:
62 emulator
.DeleteAllTempAVDs()
64 failed_tests_count
= dispatch
.Dispatch(options
)
66 # Failures of individual test suites are communicated by printing a
67 # STEP_FAILURE message.
68 # Returning a success exit status also prevents the buildbot from incorrectly
69 # marking the last suite as failed if there were failures in other suites in
70 # the batch (this happens because the exit status is a sum of all failures
71 # from all suites, but the buildbot associates the exit status only with the
74 return failed_tests_count
78 if __name__
== '__main__':
79 sys
.exit(main(sys
.argv
))