2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """A test runner for gtest application tests."""
12 from mopy
import dart_apptest
13 from mopy
import gtest
14 # TODO(msw): Mojo's script pulls in android.py via mojo/devtools/common/pylib.
15 from mopy
.android
import AndroidShell
16 from mopy
.config
import Config
17 from mopy
.gn
import ConfigForGNArgs
, ParseGNConfig
18 from mopy
.log
import InitLogging
19 from mopy
.paths
import Paths
22 _logger
= logging
.getLogger()
26 parser
= argparse
.ArgumentParser(description
="A test runner for application "
29 parser
.add_argument("--verbose", help="be verbose (multiple times for more)",
30 default
=0, dest
="verbose_count", action
="count")
31 parser
.add_argument("test_list_file", type=file,
32 help="a file listing apptests to run")
33 parser
.add_argument("build_dir", type=str,
34 help="the build output directory")
35 args
= parser
.parse_args()
37 InitLogging(args
.verbose_count
)
38 config
= ConfigForGNArgs(ParseGNConfig(args
.build_dir
))
40 _logger
.debug("Test list file: %s", args
.test_list_file
)
41 execution_globals
= {"config": config
}
42 exec args
.test_list_file
in execution_globals
43 test_list
= execution_globals
["tests"]
44 _logger
.debug("Test list: %s" % test_list
)
47 if config
.target_os
== Config
.OS_ANDROID
:
49 shell
= AndroidShell(paths
.target_mojo_shell_path
, paths
.build_dir
,
51 extra_args
.extend(shell
.PrepareShellRun(fixed_port
=False))
58 for test_dict
in test_list
:
59 test
= test_dict
["test"]
60 test_name
= test_dict
.get("name", test
)
61 test_type
= test_dict
.get("type", "gtest")
62 test_args
= test_dict
.get("test-args", [])
63 shell_args
= test_dict
.get("shell-args", []) + extra_args
65 _logger
.info("Will start: %s" % test_name
)
66 print "Running %s...." % test_name
,
69 if test_type
== "dart":
70 apptest_result
= dart_apptest
.run_test(config
, shell
, test_dict
,
71 shell_args
, {test
: test_args
})
72 elif test_type
== "gtest":
73 apptest_result
= gtest
.run_fixtures(config
, shell
, test_dict
,
75 test_args
, shell_args
)
76 elif test_type
== "gtest_isolated":
77 apptest_result
= gtest
.run_fixtures(config
, shell
, test_dict
,
78 test
, True, test_args
, shell_args
)
80 apptest_result
= "Invalid test type in %r" % test_dict
82 if apptest_result
!= "Succeeded":
85 _logger
.info("Completed: %s" % test_name
)
90 if __name__
== '__main__':