blob: 2cf84b9ba26e9849bc2a14dcbe0f0b74489086b1 [file] [log] [blame]
#!/usr/bin/env python
# Copyright 2015 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.
"""Test runner for Mojo application tests.
TODO(vtl|msw): Add a way of specifying data dependencies.
"""
import argparse
import logging
import sys
from devtoolslib import apptest_dart
from devtoolslib import apptest_gtest
from devtoolslib import shell_arguments
from devtoolslib import shell_config
_DESCRIPTION = """Runner for Mojo application tests.
|test_list_file| has to be a valid Python program that sets a |tests| global
variable, containing entries of the following form:
{
# Required URL for apptest.
"test": "mojo:test_app_url",
# Optional display name (otherwise the entry for "test" above is used).
"name": "mojo:test_app_url (more details)",
# Optional test type. Valid values:
# * "gtest" (default)
# * "gtest_isolated": like "gtest", but run with fixture isolation,
# i.e., each test in a fresh mojo_shell
# * "dart"
"type": "gtest",
# Optional arguments to be passed to the apptest.
"test-args": ["--an_arg", "another_arg"],
# Optional shell arguments.
"shell-args": ["--some-flag-for-the-shell", "--another-flag"],
# Optional timeout in seconds, 60 by default.
"timeout": 120,
}
|test_list_file| may reference the |target_os| global that will be any of
['android', 'linux'], indicating the system on which the tests are to be run.
Any arguments not recognized by the script will be passed on as shell arguments.
"""
_logger = logging.getLogger()
def main():
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description=_DESCRIPTION)
parser.add_argument("test_list_file", type=file,
help="a file listing apptests to run")
shell_config.add_shell_arguments(parser)
script_args, shell_args = parser.parse_known_args()
try:
config = shell_config.get_shell_config(script_args)
shell, common_shell_args = shell_arguments.get_shell(config, shell_args)
except shell_config.ShellConfigurationException as e:
print e
return 1
target_os = "android" if script_args.android else "linux"
test_list_globals = {"target_os": target_os}
exec script_args.test_list_file in test_list_globals
test_list = test_list_globals["tests"]
succeeded = True
for test_dict in test_list:
test = test_dict["test"]
test_name = test_dict.get("name", test)
test_type = test_dict.get("type", "gtest")
test_args = test_dict.get("test-args", [])
shell_args = test_dict.get("shell-args", []) + common_shell_args
timeout = test_dict.get("timeout", 60)
_logger.info("Will start: %s" % test_name)
print "Running %s...." % test_name,
sys.stdout.flush()
if test_type == "dart":
apptest_result = apptest_dart.run_dart_apptest(shell, shell_args, test,
test_args, timeout)
elif test_type == "gtest":
apptest_result = apptest_gtest.run_gtest_apptest(shell, shell_args, test,
test_args, timeout,
False)
elif test_type == "gtest_isolated":
apptest_result = apptest_gtest.run_gtest_apptest(shell, shell_args, test,
test_args, timeout,
True)
else:
apptest_result = False
print "Unrecognized test type in %r" % test_dict
print "Succeeded" if apptest_result else "Failed"
_logger.info("Completed: %s" % test_name)
if not apptest_result:
succeeded = False
return 0 if succeeded else 1
if __name__ == '__main__':
sys.exit(main())