2018-09-24 13:44:18 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2018-09-27 15:29:27 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2018-09-24 13:44:18 +00:00
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2018-10-01 22:50:52 +00:00
|
|
|
from lib.native_tests import TestsList, Verbosity
|
2018-09-24 13:44:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Command:
|
|
|
|
LIST = 'list'
|
|
|
|
RUN = 'run'
|
|
|
|
|
2018-09-27 15:29:27 +00:00
|
|
|
|
2018-09-24 13:44:18 +00:00
|
|
|
def parse_args():
|
|
|
|
parser = argparse.ArgumentParser(description='Run Google Test binaries')
|
|
|
|
|
|
|
|
parser.add_argument('command',
|
|
|
|
choices=[Command.LIST, Command.RUN],
|
|
|
|
help='command to execute')
|
|
|
|
|
2018-09-24 20:47:06 +00:00
|
|
|
parser.add_argument('-b', '--binary', nargs='+', required=False,
|
|
|
|
help='binaries to run')
|
2018-09-24 13:44:18 +00:00
|
|
|
parser.add_argument('-c', '--config', required=True,
|
|
|
|
help='path to a tests config')
|
2018-10-22 20:12:19 +00:00
|
|
|
parser.add_argument('--run-only-disabled-tests',
|
|
|
|
action='store_true', default=False,
|
|
|
|
help='if disabled tests should be run')
|
2018-09-24 13:44:18 +00:00
|
|
|
parser.add_argument('-t', '--tests-dir', required=False,
|
2018-09-24 20:47:06 +00:00
|
|
|
help='path to a directory with test binaries')
|
2018-09-24 13:44:18 +00:00
|
|
|
parser.add_argument('-o', '--output-dir', required=False,
|
|
|
|
help='path to a folder to save tests results')
|
|
|
|
|
2018-09-24 20:47:06 +00:00
|
|
|
verbosity = parser.add_mutually_exclusive_group()
|
|
|
|
verbosity.add_argument('-v', '--verbosity', required=False,
|
2018-09-27 15:29:27 +00:00
|
|
|
default=Verbosity.CHATTY,
|
|
|
|
choices=Verbosity.get_all(),
|
2018-09-24 20:47:06 +00:00
|
|
|
help='set verbosity level')
|
|
|
|
verbosity.add_argument('-q', '--quiet', required=False, action='store_const',
|
|
|
|
const=Verbosity.ERRORS, dest='verbosity',
|
|
|
|
help='suppress stdout from test binaries')
|
|
|
|
verbosity.add_argument('-qq', '--quiet-quiet',
|
2018-09-27 15:29:27 +00:00
|
|
|
# https://youtu.be/bXd-zZLV2i0?t=41s
|
2018-09-24 20:47:06 +00:00
|
|
|
required=False, action='store_const',
|
|
|
|
const=Verbosity.SILENT, dest='verbosity',
|
|
|
|
help='suppress stdout and stderr from test binaries')
|
|
|
|
|
2018-09-24 13:44:18 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
# Additional checks.
|
|
|
|
if args.command == Command.RUN and args.tests_dir is None:
|
|
|
|
parser.error("specify a path to a dir with test binaries via --tests-dir")
|
|
|
|
|
|
|
|
# Absolutize and check paths.
|
|
|
|
# 'config' must exist and be a file.
|
|
|
|
args.config = os.path.abspath(args.config)
|
|
|
|
if not os.path.isfile(args.config):
|
|
|
|
parser.error("file '{}' doesn't exist".format(args.config))
|
|
|
|
|
|
|
|
# 'tests_dir' must exist and be a directory.
|
|
|
|
if args.tests_dir is not None:
|
|
|
|
args.tests_dir = os.path.abspath(args.tests_dir)
|
|
|
|
if not os.path.isdir(args.tests_dir):
|
|
|
|
parser.error("directory '{}' doesn't exist".format(args.tests_dir))
|
|
|
|
|
|
|
|
# 'output_dir' must exist and be a directory.
|
|
|
|
if args.output_dir is not None:
|
|
|
|
args.output_dir = os.path.abspath(args.output_dir)
|
|
|
|
if not os.path.isdir(args.output_dir):
|
|
|
|
parser.error("directory '{}' doesn't exist".format(args.output_dir))
|
|
|
|
|
|
|
|
return args
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
args = parse_args()
|
|
|
|
tests_list = TestsList(args.config, args.tests_dir)
|
|
|
|
|
|
|
|
if args.command == Command.LIST:
|
2018-09-27 15:29:27 +00:00
|
|
|
all_binaries_names = tests_list.get_for_current_platform()
|
|
|
|
print('\n'.join(all_binaries_names))
|
2018-09-24 13:44:18 +00:00
|
|
|
return 0
|
|
|
|
|
|
|
|
if args.command == Command.RUN:
|
|
|
|
if args.binary is not None:
|
2018-10-22 20:12:19 +00:00
|
|
|
return tests_list.run(args.binary, args.output_dir, args.verbosity,
|
|
|
|
args.run_only_disabled_tests)
|
2018-09-24 13:44:18 +00:00
|
|
|
else:
|
2018-10-22 20:12:19 +00:00
|
|
|
return tests_list.run_all(args.output_dir, args.verbosity,
|
|
|
|
args.run_only_disabled_tests)
|
2018-09-24 13:44:18 +00:00
|
|
|
|
2018-09-27 15:29:27 +00:00
|
|
|
assert False, "unexpected command '{}'".format(args.command)
|
2018-09-24 13:44:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|