1#!/usr/bin/env python3
2#
3#   Copyright 2021 - The Android Open Source Project
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an "AS IS" BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16
17from blueberry.tests.gd.gd_all_tests import ALL_TESTS
18from blueberry.tests.gd.gd_presubmit_tests import PRESUBMIT_TESTS
19from blueberry.tests.gd.gd_postsubmit_tests import POSTSUBMIT_TESTS
20
21from mobly import suite_runner
22import sys
23import argparse
24import pathlib
25
26DISABLED_TESTS = set()
27
28ENABLED_TESTS = list(ALL_TESTS - DISABLED_TESTS)
29
30
31def main():
32    """
33    Local test runner that allows  to specify list of tests to and customize
34    test config file location
35    """
36    parser = argparse.ArgumentParser(description="Run local GD cert tests.")
37    parser.add_argument(
38        '-c', '--config', type=str, required=True, metavar='<PATH>', help='Path to the test configuration file.')
39    parser.add_argument(
40        '--tests',
41        '--test_case',
42        nargs='+',
43        type=str,
44        metavar='[ClassA[.test_a] ClassB[.test_b] ...]',
45        help='A list of test classes and optional tests to execute.')
46    parser.add_argument("--all_tests", "-A", type=bool, dest="all_tests", default=False, nargs="?")
47    parser.add_argument("--presubmit", type=bool, dest="presubmit", default=False, nargs="?")
48    parser.add_argument("--postsubmit", type=bool, dest="postsubmit", default=False, nargs="?")
49    args = parser.parse_args()
50    test_list = ALL_TESTS
51    if args.all_tests:
52        test_list = ALL_TESTS
53    elif args.presubmit:
54        test_list = PRESUBMIT_TESTS
55    elif args.postsubmit:
56        test_list = POSTSUBMIT_TESTS
57    # Do not pass this layer's cmd line argument to next layer
58    argv = ["--config", args.config]
59    if args.tests:
60        argv.append("--tests")
61        for test in args.tests:
62            argv.append(test)
63
64    suite_runner.run_suite(test_list, argv=argv)
65
66
67if __name__ == "__main__":
68    main()
69