1#!/usr/bin/env python3
2#
3#   Copyright 2022 - 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.topshim.adapter.adapter_test import AdapterTest
18from blueberry.tests.topshim.hfp.hfp_test import HfpTest
19from blueberry.tests.topshim.power.suspend_test import SuspendTest
20from blueberry.tests.topshim.security.classic_security_test import ClassicSecurityTest
21from blueberry.tests.topshim.security.le_security_test import LeSecurityTest
22
23from mobly import suite_runner
24import argparse
25
26ALL_TESTS = [AdapterTest, ClassicSecurityTest, HfpTest, LeSecurityTest, SuspendTest]
27
28
29def main():
30    """
31    Local test runner that allows  to specify list of tests to and customize
32    test config file location
33    """
34    parser = argparse.ArgumentParser(description="Run local Topshim to Topshim tests.")
35    parser.add_argument('-c',
36                        '--config',
37                        type=str,
38                        required=True,
39                        metavar='<PATH>',
40                        help='Path to the test configuration file.')
41    parser.add_argument('--tests',
42                        '--test_case',
43                        nargs='+',
44                        type=str,
45                        metavar='[ClassA[.test_a] ClassB[.test_b] ...]',
46                        help='A list of test classes and optional tests to execute.')
47    parser.add_argument("--all_tests", "-A", type=bool, dest="all_tests", default=False, nargs="?")
48    parser.add_argument("--presubmit", type=bool, dest="presubmit", default=False, nargs="?")
49    parser.add_argument("--postsubmit", type=bool, dest="postsubmit", default=False, nargs="?")
50    args = parser.parse_args()
51    test_list = ALL_TESTS
52    if args.all_tests:
53        test_list = ALL_TESTS
54    elif args.presubmit:
55        test_list = ALL_TESTS
56    elif args.postsubmit:
57        test_list = ALL_TESTS
58    # Do not pass this layer's cmd line argument to next layer
59    argv = ["--config", args.config]
60    if args.tests:
61        argv.append("--tests")
62        for test in args.tests:
63            argv.append(test)
64
65    suite_runner.run_suite(test_list, argv=argv)
66
67
68if __name__ == "__main__":
69    main()
70