Zhuoyao Zhang | efe168d | 2017-02-15 18:01:04 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # Copyright 2017 - 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 | # |
| 17 | |
| 18 | import argparse |
| 19 | import os |
| 20 | import re |
| 21 | import sys |
| 22 | |
Hsin-Yi Chen | 6d41b17 | 2018-04-26 18:55:02 +0800 | [diff] [blame] | 23 | from build.build_rule_gen import BuildRuleGen |
Zhuoyao Zhang | efe168d | 2017-02-15 18:01:04 -0800 | [diff] [blame] | 24 | from build.vts_spec_parser import VtsSpecParser |
| 25 | from configure.test_case_creator import TestCaseCreator |
Zhuoyao Zhang | bf6d0b8 | 2018-04-25 15:39:25 -0700 | [diff] [blame] | 26 | from utils.const import Constant |
Zhuoyao Zhang | efe168d | 2017-02-15 18:01:04 -0800 | [diff] [blame] | 27 | |
Zhuoyao Zhang | efe168d | 2017-02-15 18:01:04 -0800 | [diff] [blame] | 28 | TEST_TIME_OUT_PATTERN = '(([0-9]+)(m|s|h))+' |
Zhuoyao Zhang | bf6d0b8 | 2018-04-25 15:39:25 -0700 | [diff] [blame] | 29 | |
Hsin-Yi Chen | 6d41b17 | 2018-04-26 18:55:02 +0800 | [diff] [blame] | 30 | """Generate Android.mk, Android.bp, and AndroidTest.xml files for given hal |
Keun Soo Yim | cb4cdbd | 2017-03-15 09:11:47 -0700 | [diff] [blame] | 31 | |
| 32 | Usage: |
Zhuoyao Zhang | bf6d0b8 | 2018-04-25 15:39:25 -0700 | [diff] [blame] | 33 | python launch_hal_test.py [--options] hal_package name |
Keun Soo Yim | cb4cdbd | 2017-03-15 09:11:47 -0700 | [diff] [blame] | 34 | |
Zhuoyao Zhang | bf6d0b8 | 2018-04-25 15:39:25 -0700 | [diff] [blame] | 35 | where options are: |
| 36 | --test_type: Test type, currently support two types: target and host. |
| 37 | --time_out: Timeout for the test, default is 1m. |
| 38 | --package_root: Prefix of the HAL package. default is android.hardware |
| 39 | --path_root: Root path that stores the HAL definition. default is hardware/interfaces |
| 40 | --test_binary_file: Test binary file for target-side HAL test. |
| 41 | --test_script_file: Test script file for host-side HAL test. |
| 42 | --test_config_dir: Directory path to store the test configure files. |
Zhuoyao Zhang | bf6d0b8 | 2018-04-25 15:39:25 -0700 | [diff] [blame] | 43 | --replay: Whether this is a replay test. |
| 44 | --disable_stop_runtime: Whether to stop framework before the test. |
Keun Soo Yim | cb4cdbd | 2017-03-15 09:11:47 -0700 | [diff] [blame] | 45 | Example: |
| 46 | python launch_hal_test.py android.hardware.nfc@1.0 |
Keun Soo Yim | cb4cdbd | 2017-03-15 09:11:47 -0700 | [diff] [blame] | 47 | python launch_hal_test.py --test_type=host --time_out=5m android.hardware.nfc@1.0 |
Zhuoyao Zhang | bf6d0b8 | 2018-04-25 15:39:25 -0700 | [diff] [blame] | 48 | python launch_hal_test.py --package_root com.qualcomm.qti |
| 49 | --path_root vendor/qcom/proprietary/interfaces/com/qualcomm/qti/ |
| 50 | --test_configure_dir temp/ com.qualcomm.qti.qcril.qcrilhook@1.0 |
Keun Soo Yim | cb4cdbd | 2017-03-15 09:11:47 -0700 | [diff] [blame] | 51 | """ |
Zhuoyao Zhang | efe168d | 2017-02-15 18:01:04 -0800 | [diff] [blame] | 52 | |
| 53 | |
| 54 | def main(): |
| 55 | parser = argparse.ArgumentParser(description='Initiate a test case.') |
| 56 | parser.add_argument( |
| 57 | '--test_type', |
| 58 | dest='test_type', |
| 59 | required=False, |
Zhuoyao Zhang | bf6d0b8 | 2018-04-25 15:39:25 -0700 | [diff] [blame] | 60 | default='target', |
| 61 | help='Test type, currently support two types: target and host.') |
Zhuoyao Zhang | efe168d | 2017-02-15 18:01:04 -0800 | [diff] [blame] | 62 | parser.add_argument( |
| 63 | '--time_out', |
| 64 | dest='time_out', |
| 65 | required=False, |
Zhuoyao Zhang | bf6d0b8 | 2018-04-25 15:39:25 -0700 | [diff] [blame] | 66 | default='1m', |
Zhuoyao Zhang | cb4e2a5 | 2017-02-28 15:16:35 -0800 | [diff] [blame] | 67 | help='Timeout for the test, default is 1m.') |
Zhuoyao Zhang | efe168d | 2017-02-15 18:01:04 -0800 | [diff] [blame] | 68 | parser.add_argument( |
Zhuoyao Zhang | 71b4fa6 | 2017-03-15 15:09:53 -0700 | [diff] [blame] | 69 | '--replay', |
| 70 | dest='is_replay', |
| 71 | action='store_true', |
| 72 | required=False, |
| 73 | help='Whether this is a replay test.') |
| 74 | parser.add_argument( |
Zhuoyao Zhang | 32bb587 | 2017-04-11 17:48:00 -0700 | [diff] [blame] | 75 | '--disable_stop_runtime', |
| 76 | dest='disable_stop_runtime', |
Zhuoyao Zhang | cb4e2a5 | 2017-02-28 15:16:35 -0800 | [diff] [blame] | 77 | action='store_true', |
| 78 | required=False, |
| 79 | help='Whether to stop framework before the test.') |
Zhuoyao Zhang | efe168d | 2017-02-15 18:01:04 -0800 | [diff] [blame] | 80 | parser.add_argument( |
Zhuoyao Zhang | bf6d0b8 | 2018-04-25 15:39:25 -0700 | [diff] [blame] | 81 | '--package_root', |
| 82 | dest='package_root', |
| 83 | required=False, |
| 84 | default=Constant.HAL_PACKAGE_PREFIX, |
| 85 | help='Prefix of the HAL package. e.g. android.hardware') |
| 86 | parser.add_argument( |
| 87 | '--path_root', |
| 88 | dest='path_root', |
| 89 | required=False, |
| 90 | default=Constant.HAL_INTERFACE_PATH, |
| 91 | help= |
| 92 | 'Root path that stores the HAL definition. e.g. hardware/interfaces') |
| 93 | parser.add_argument( |
| 94 | '--test_binary_file', |
| 95 | dest='test_binary_file', |
| 96 | required=False, |
| 97 | help='Test binary file for target-side HAL test.') |
| 98 | parser.add_argument( |
| 99 | '--test_script_file', |
| 100 | dest='test_script_file', |
| 101 | required=False, |
| 102 | help='Test script file for host-side HAL test.') |
| 103 | parser.add_argument( |
| 104 | '--test_config_dir', |
| 105 | dest='test_config_dir', |
| 106 | required=False, |
| 107 | help='Directory path to store the test configure files.') |
| 108 | parser.add_argument( |
Zhuoyao Zhang | efe168d | 2017-02-15 18:01:04 -0800 | [diff] [blame] | 109 | 'hal_package_name', |
Zhuoyao Zhang | cb4e2a5 | 2017-02-28 15:16:35 -0800 | [diff] [blame] | 110 | help='hal package name (e.g. android.hardware.nfc@1.0).') |
Zhuoyao Zhang | efe168d | 2017-02-15 18:01:04 -0800 | [diff] [blame] | 111 | args = parser.parse_args() |
| 112 | |
Hsin-Yi Chen | 6d41b17 | 2018-04-26 18:55:02 +0800 | [diff] [blame] | 113 | regex = re.compile(Constant.HAL_PACKAGE_NAME_PATTERN) |
Zhuoyao Zhang | efe168d | 2017-02-15 18:01:04 -0800 | [diff] [blame] | 114 | result = re.match(regex, args.hal_package_name) |
| 115 | if not result: |
| 116 | print 'Invalid hal package name. Exiting..' |
| 117 | sys.exit(1) |
Zhuoyao Zhang | efe168d | 2017-02-15 18:01:04 -0800 | [diff] [blame] | 118 | |
Hsin-Yi Chen | 6d41b17 | 2018-04-26 18:55:02 +0800 | [diff] [blame] | 119 | if not args.hal_package_name.startswith(args.package_root + '.'): |
| 120 | print 'hal_package_name does not start with package_root. Exiting...' |
| 121 | sys.exit(1) |
| 122 | |
Zhuoyao Zhang | bf6d0b8 | 2018-04-25 15:39:25 -0700 | [diff] [blame] | 123 | if args.test_type != 'target' and args.test_type != 'host': |
Zhuoyao Zhang | efe168d | 2017-02-15 18:01:04 -0800 | [diff] [blame] | 124 | print 'Unsupported test type. Exiting...' |
| 125 | sys.exit(1) |
Zhuoyao Zhang | 71b4fa6 | 2017-03-15 15:09:53 -0700 | [diff] [blame] | 126 | elif args.test_type == 'host' and args.is_replay: |
| 127 | print 'Host side replay test is not supported yet. Exiting...' |
| 128 | sys.exit(1) |
Zhuoyao Zhang | efe168d | 2017-02-15 18:01:04 -0800 | [diff] [blame] | 129 | |
Zhuoyao Zhang | bf6d0b8 | 2018-04-25 15:39:25 -0700 | [diff] [blame] | 130 | regex = re.compile(TEST_TIME_OUT_PATTERN) |
| 131 | result = re.match(regex, args.time_out) |
| 132 | if not result: |
| 133 | print 'Invalid test time out format. Exiting...' |
| 134 | sys.exit(1) |
| 135 | |
| 136 | if not args.test_config_dir: |
| 137 | if args.package_root == Constant.HAL_PACKAGE_PREFIX: |
| 138 | args.test_config_dir = Constant.VTS_HAL_TEST_CASE_PATH |
| 139 | else: |
| 140 | args.test_config_dir = args.path_root |
Zhuoyao Zhang | efe168d | 2017-02-15 18:01:04 -0800 | [diff] [blame] | 141 | |
Zhuoyao Zhang | 32bb587 | 2017-04-11 17:48:00 -0700 | [diff] [blame] | 142 | stop_runtime = False |
| 143 | if args.test_type == 'target' and not args.disable_stop_runtime: |
| 144 | stop_runtime = True |
| 145 | |
Zhuoyao Zhang | bf6d0b8 | 2018-04-25 15:39:25 -0700 | [diff] [blame] | 146 | vts_spec_parser = VtsSpecParser( |
| 147 | package_root=args.package_root, path_root=args.path_root) |
Zhuoyao Zhang | efe168d | 2017-02-15 18:01:04 -0800 | [diff] [blame] | 148 | test_case_creater = TestCaseCreator(vts_spec_parser, args.hal_package_name) |
Zhuoyao Zhang | cb4e2a5 | 2017-02-28 15:16:35 -0800 | [diff] [blame] | 149 | if not test_case_creater.LaunchTestCase( |
Zhuoyao Zhang | 71b4fa6 | 2017-03-15 15:09:53 -0700 | [diff] [blame] | 150 | args.test_type, |
| 151 | args.time_out, |
| 152 | is_replay=args.is_replay, |
Zhuoyao Zhang | bf6d0b8 | 2018-04-25 15:39:25 -0700 | [diff] [blame] | 153 | stop_runtime=stop_runtime, |
| 154 | test_binary_file=args.test_binary_file, |
| 155 | test_script_file=args.test_script_file, |
| 156 | test_config_dir=args.test_config_dir, |
| 157 | package_root=args.package_root, |
| 158 | path_root=args.path_root): |
Zhuoyao Zhang | efe168d | 2017-02-15 18:01:04 -0800 | [diff] [blame] | 159 | print('Error: Failed to launch test for %s. Exiting...' % |
| 160 | args.hal_package_name) |
| 161 | sys.exit(1) |
| 162 | |
Zhuoyao Zhang | efe168d | 2017-02-15 18:01:04 -0800 | [diff] [blame] | 163 | if __name__ == '__main__': |
| 164 | main() |