summaryrefslogtreecommitdiffstats
path: root/scripts/lib
diff options
context:
space:
mode:
authorYeoh Ee Peng <ee.peng.yeoh@intel.com>2019-04-09 13:53:08 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-04-10 13:46:17 +0100
commit974d786d0886e3b9b3a34a01dc3db59a02d06e9b (patch)
treef87764a6077bf924a54128f0bd214da7d5404167 /scripts/lib
parent8d70c776785fd88143bb34f53651e37483a726c5 (diff)
downloadpoky-974d786d0886e3b9b3a34a01dc3db59a02d06e9b.tar.gz
resulttool/manualexecution: Enable creation of configuration option file
Allow the creation of configuration option file based on user inputs. Where this configuration option file will be used by the the manual execution to display options for configuration rather than user need to inputs configuration manually. (From OE-Core rev: 23c7a037a85a825aa088bfac3a144c14087a9f49) Signed-off-by: Yeoh Ee Peng <ee.peng.yeoh@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib')
-rwxr-xr-xscripts/lib/resulttool/manualexecution.py54
1 files changed, 53 insertions, 1 deletions
diff --git a/scripts/lib/resulttool/manualexecution.py b/scripts/lib/resulttool/manualexecution.py
index 57e7b2999e..12ef90d6af 100755
--- a/scripts/lib/resulttool/manualexecution.py
+++ b/scripts/lib/resulttool/manualexecution.py
@@ -24,6 +24,11 @@ def load_json_file(file):
24 with open(file, "r") as f: 24 with open(file, "r") as f:
25 return json.load(f) 25 return json.load(f)
26 26
27def write_json_file(f, json_data):
28 os.makedirs(os.path.dirname(f), exist_ok=True)
29 with open(f, 'w') as filedata:
30 filedata.write(json.dumps(json_data, sort_keys=True, indent=4))
31
27class ManualTestRunner(object): 32class ManualTestRunner(object):
28 33
29 def _get_testcases(self, file): 34 def _get_testcases(self, file):
@@ -139,8 +144,53 @@ class ManualTestRunner(object):
139 test_results.update(test_result) 144 test_results.update(test_result)
140 return self.configuration, self.result_id, self.write_dir, test_results 145 return self.configuration, self.result_id, self.write_dir, test_results
141 146
147 def _get_true_false_input(self, input_message):
148 yes_list = ['Y', 'YES']
149 no_list = ['N', 'NO']
150 while True:
151 more_config_option = input(input_message).upper()
152 if more_config_option in yes_list or more_config_option in no_list:
153 break
154 print('Invalid input!')
155 if more_config_option in no_list:
156 return False
157 return True
158
159 def make_config_option_file(self, logger, manual_case_file, config_options_file):
160 config_options = {}
161 if config_options_file:
162 config_options = load_json_file(config_options_file)
163 new_test_module = os.path.basename(manual_case_file).split('.')[0]
164 print('Creating configuration options file for test module: %s' % new_test_module)
165 new_config_options = {}
166
167 while True:
168 config_name = input('\nPlease provide test configuration to create:\n').upper()
169 new_config_options[config_name] = {}
170 while True:
171 config_value = self._get_input('Configuration possible option value')
172 config_option_index = len(new_config_options[config_name]) + 1
173 new_config_options[config_name][config_option_index] = config_value
174 more_config_option = self._get_true_false_input('\nIs there more configuration option input: (Y)es/(N)o\n')
175 if not more_config_option:
176 break
177 more_config = self._get_true_false_input('\nIs there more configuration to create: (Y)es/(N)o\n')
178 if not more_config:
179 break
180
181 if new_config_options:
182 config_options[new_test_module] = new_config_options
183 if not config_options_file:
184 self._create_write_dir()
185 config_options_file = os.path.join(self.write_dir, 'manual_config_options.json')
186 write_json_file(config_options_file, config_options)
187 logger.info('Configuration option file created at %s' % config_options_file)
188
142def manualexecution(args, logger): 189def manualexecution(args, logger):
143 testrunner = ManualTestRunner() 190 testrunner = ManualTestRunner()
191 if args.make_config_options_file:
192 testrunner.make_config_option_file(logger, args.file, args.config_options_file)
193 return 0
144 get_configuration, get_result_id, get_write_dir, get_test_results = testrunner.run_test(args.file, args.config_options_file) 194 get_configuration, get_result_id, get_write_dir, get_test_results = testrunner.run_test(args.file, args.config_options_file)
145 resultjsonhelper = OETestResultJSONHelper() 195 resultjsonhelper = OETestResultJSONHelper()
146 resultjsonhelper.dump_testresult_file(get_write_dir, get_configuration, get_result_id, get_test_results) 196 resultjsonhelper.dump_testresult_file(get_write_dir, get_configuration, get_result_id, get_test_results)
@@ -154,4 +204,6 @@ def register_commands(subparsers):
154 parser_build.set_defaults(func=manualexecution) 204 parser_build.set_defaults(func=manualexecution)
155 parser_build.add_argument('file', help='specify path to manual test case JSON file.Note: Please use \"\" to encapsulate the file path.') 205 parser_build.add_argument('file', help='specify path to manual test case JSON file.Note: Please use \"\" to encapsulate the file path.')
156 parser_build.add_argument('-c', '--config-options-file', default='', 206 parser_build.add_argument('-c', '--config-options-file', default='',
157 help='the config options file to import and used as available configuration option selection') 207 help='the config options file to import and used as available configuration option selection or make config option file')
208 parser_build.add_argument('-m', '--make-config-options-file', action='store_true',
209 help='make the configuration options file based on provided inputs')