blob: f6f4f2637dd69f4041e927d5d82adda4682348f3 [file] [log] [blame]
Zhuoyao Zhangefe168d2017-02-15 18:01:04 -08001#!/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
18import argparse
19import os
20import re
21import sys
22
Hsin-Yi Chen6d41b172018-04-26 18:55:02 +080023from build.build_rule_gen import BuildRuleGen
Zhuoyao Zhangefe168d2017-02-15 18:01:04 -080024from build.vts_spec_parser import VtsSpecParser
25from configure.test_case_creator import TestCaseCreator
Zhuoyao Zhangbf6d0b82018-04-25 15:39:25 -070026from utils.const import Constant
Zhuoyao Zhangefe168d2017-02-15 18:01:04 -080027
Zhuoyao Zhangefe168d2017-02-15 18:01:04 -080028TEST_TIME_OUT_PATTERN = '(([0-9]+)(m|s|h))+'
Zhuoyao Zhangbf6d0b82018-04-25 15:39:25 -070029
Hsin-Yi Chen6d41b172018-04-26 18:55:02 +080030"""Generate Android.mk, Android.bp, and AndroidTest.xml files for given hal
Keun Soo Yimcb4cdbd2017-03-15 09:11:47 -070031
32Usage:
Zhuoyao Zhangbf6d0b82018-04-25 15:39:25 -070033 python launch_hal_test.py [--options] hal_package name
Keun Soo Yimcb4cdbd2017-03-15 09:11:47 -070034
Zhuoyao Zhangbf6d0b82018-04-25 15:39:25 -070035 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 Zhangbf6d0b82018-04-25 15:39:25 -070043 --replay: Whether this is a replay test.
44 --disable_stop_runtime: Whether to stop framework before the test.
Keun Soo Yimcb4cdbd2017-03-15 09:11:47 -070045Example:
46 python launch_hal_test.py android.hardware.nfc@1.0
Keun Soo Yimcb4cdbd2017-03-15 09:11:47 -070047 python launch_hal_test.py --test_type=host --time_out=5m android.hardware.nfc@1.0
Zhuoyao Zhangbf6d0b82018-04-25 15:39:25 -070048 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 Yimcb4cdbd2017-03-15 09:11:47 -070051"""
Zhuoyao Zhangefe168d2017-02-15 18:01:04 -080052
53
54def 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 Zhangbf6d0b82018-04-25 15:39:25 -070060 default='target',
61 help='Test type, currently support two types: target and host.')
Zhuoyao Zhangefe168d2017-02-15 18:01:04 -080062 parser.add_argument(
63 '--time_out',
64 dest='time_out',
65 required=False,
Zhuoyao Zhangbf6d0b82018-04-25 15:39:25 -070066 default='1m',
Zhuoyao Zhangcb4e2a52017-02-28 15:16:35 -080067 help='Timeout for the test, default is 1m.')
Zhuoyao Zhangefe168d2017-02-15 18:01:04 -080068 parser.add_argument(
Zhuoyao Zhang71b4fa62017-03-15 15:09:53 -070069 '--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 Zhang32bb5872017-04-11 17:48:00 -070075 '--disable_stop_runtime',
76 dest='disable_stop_runtime',
Zhuoyao Zhangcb4e2a52017-02-28 15:16:35 -080077 action='store_true',
78 required=False,
79 help='Whether to stop framework before the test.')
Zhuoyao Zhangefe168d2017-02-15 18:01:04 -080080 parser.add_argument(
Zhuoyao Zhangbf6d0b82018-04-25 15:39:25 -070081 '--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 Zhangefe168d2017-02-15 18:01:04 -0800109 'hal_package_name',
Zhuoyao Zhangcb4e2a52017-02-28 15:16:35 -0800110 help='hal package name (e.g. android.hardware.nfc@1.0).')
Zhuoyao Zhangefe168d2017-02-15 18:01:04 -0800111 args = parser.parse_args()
112
Hsin-Yi Chen6d41b172018-04-26 18:55:02 +0800113 regex = re.compile(Constant.HAL_PACKAGE_NAME_PATTERN)
Zhuoyao Zhangefe168d2017-02-15 18:01:04 -0800114 result = re.match(regex, args.hal_package_name)
115 if not result:
116 print 'Invalid hal package name. Exiting..'
117 sys.exit(1)
Zhuoyao Zhangefe168d2017-02-15 18:01:04 -0800118
Hsin-Yi Chen6d41b172018-04-26 18:55:02 +0800119 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 Zhangbf6d0b82018-04-25 15:39:25 -0700123 if args.test_type != 'target' and args.test_type != 'host':
Zhuoyao Zhangefe168d2017-02-15 18:01:04 -0800124 print 'Unsupported test type. Exiting...'
125 sys.exit(1)
Zhuoyao Zhang71b4fa62017-03-15 15:09:53 -0700126 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 Zhangefe168d2017-02-15 18:01:04 -0800129
Zhuoyao Zhangbf6d0b82018-04-25 15:39:25 -0700130 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 Zhangefe168d2017-02-15 18:01:04 -0800141
Zhuoyao Zhang32bb5872017-04-11 17:48:00 -0700142 stop_runtime = False
143 if args.test_type == 'target' and not args.disable_stop_runtime:
144 stop_runtime = True
145
Zhuoyao Zhangbf6d0b82018-04-25 15:39:25 -0700146 vts_spec_parser = VtsSpecParser(
147 package_root=args.package_root, path_root=args.path_root)
Zhuoyao Zhangefe168d2017-02-15 18:01:04 -0800148 test_case_creater = TestCaseCreator(vts_spec_parser, args.hal_package_name)
Zhuoyao Zhangcb4e2a52017-02-28 15:16:35 -0800149 if not test_case_creater.LaunchTestCase(
Zhuoyao Zhang71b4fa62017-03-15 15:09:53 -0700150 args.test_type,
151 args.time_out,
152 is_replay=args.is_replay,
Zhuoyao Zhangbf6d0b82018-04-25 15:39:25 -0700153 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 Zhangefe168d2017-02-15 18:01:04 -0800159 print('Error: Failed to launch test for %s. Exiting...' %
160 args.hal_package_name)
161 sys.exit(1)
162
Zhuoyao Zhangefe168d2017-02-15 18:01:04 -0800163if __name__ == '__main__':
164 main()