Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 1 | # test case management tool - manual execution from testopia test cases |
| 2 | # |
| 3 | # Copyright (c) 2018, Intel Corporation. |
| 4 | # |
| 5 | # This program is free software; you can redistribute it and/or modify it |
| 6 | # under the terms and conditions of the GNU General Public License, |
| 7 | # version 2, as published by the Free Software Foundation. |
| 8 | # |
| 9 | # This program is distributed in the hope it will be useful, but WITHOUT |
| 10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | # more details. |
| 13 | # |
| 14 | import argparse |
| 15 | import json |
| 16 | import os |
| 17 | import sys |
| 18 | import datetime |
| 19 | import re |
| 20 | from oeqa.core.runner import OETestResultJSONHelper |
| 21 | |
| 22 | |
| 23 | def load_json_file(file): |
| 24 | with open(file, "r") as f: |
| 25 | return json.load(f) |
| 26 | |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 27 | class ManualTestRunner(object): |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 28 | |
| 29 | def _get_testcases(self, file): |
| 30 | self.jdata = load_json_file(file) |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 31 | self.test_module = self.jdata[0]['test']['@alias'].split('.', 2)[0] |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 32 | |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 33 | def _get_input(self, config): |
| 34 | while True: |
| 35 | output = input('{} = '.format(config)) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 36 | if re.match('^[a-z0-9-.]+$', output): |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 37 | break |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 38 | print('Only lowercase alphanumeric, hyphen and dot are allowed. Please try again') |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 39 | return output |
| 40 | |
| 41 | def _create_config(self): |
| 42 | from oeqa.utils.metadata import get_layers |
| 43 | from oeqa.utils.commands import get_bb_var |
| 44 | from resulttool.resultutils import store_map |
| 45 | |
| 46 | layers = get_layers(get_bb_var('BBLAYERS')) |
| 47 | self.configuration = {} |
| 48 | self.configuration['LAYERS'] = layers |
| 49 | current_datetime = datetime.datetime.now() |
| 50 | self.starttime = current_datetime.strftime('%Y%m%d%H%M%S') |
| 51 | self.configuration['STARTTIME'] = self.starttime |
| 52 | self.configuration['TEST_TYPE'] = 'manual' |
| 53 | self.configuration['TEST_MODULE'] = self.test_module |
| 54 | |
| 55 | extra_config = set(store_map['manual']) - set(self.configuration) |
| 56 | for config in sorted(extra_config): |
| 57 | print('---------------------------------------------') |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 58 | print('This is configuration #%s. Please provide configuration value(use "None" if not applicable).' % config) |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 59 | print('---------------------------------------------') |
| 60 | value_conf = self._get_input('Configuration Value') |
| 61 | print('---------------------------------------------\n') |
| 62 | self.configuration[config] = value_conf |
| 63 | |
| 64 | def _create_result_id(self): |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 65 | self.result_id = 'manual_%s_%s' % (self.test_module, self.starttime) |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 66 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 67 | def _execute_test_steps(self, test): |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 68 | test_result = {} |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 69 | print('------------------------------------------------------------------------') |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 70 | print('Executing test case: %s' % test['test']['@alias']) |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 71 | print('------------------------------------------------------------------------') |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 72 | print('You have total %s test steps to be executed.' % len(test['test']['execution'])) |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 73 | print('------------------------------------------------------------------------\n') |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 74 | for step, _ in sorted(test['test']['execution'].items(), key=lambda x: int(x[0])): |
| 75 | print('Step %s: %s' % (step, test['test']['execution'][step]['action'])) |
| 76 | expected_output = test['test']['execution'][step]['expected_results'] |
| 77 | if expected_output: |
| 78 | print('Expected output: %s' % expected_output) |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 79 | while True: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 80 | done = input('\nPlease provide test results: (P)assed/(F)ailed/(B)locked/(S)kipped? \n').lower() |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 81 | result_types = {'p':'PASSED', |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 82 | 'f':'FAILED', |
| 83 | 'b':'BLOCKED', |
| 84 | 's':'SKIPPED'} |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 85 | if done in result_types: |
| 86 | for r in result_types: |
| 87 | if done == r: |
| 88 | res = result_types[r] |
| 89 | if res == 'FAILED': |
| 90 | log_input = input('\nPlease enter the error and the description of the log: (Ex:log:211 Error Bitbake)\n') |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 91 | test_result.update({test['test']['@alias']: {'status': '%s' % res, 'log': '%s' % log_input}}) |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 92 | else: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 93 | test_result.update({test['test']['@alias']: {'status': '%s' % res}}) |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 94 | break |
| 95 | print('Invalid input!') |
| 96 | return test_result |
| 97 | |
| 98 | def _create_write_dir(self): |
| 99 | basepath = os.environ['BUILDDIR'] |
| 100 | self.write_dir = basepath + '/tmp/log/manual/' |
| 101 | |
| 102 | def run_test(self, file): |
| 103 | self._get_testcases(file) |
| 104 | self._create_config() |
| 105 | self._create_result_id() |
| 106 | self._create_write_dir() |
| 107 | test_results = {} |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 108 | print('\nTotal number of test cases in this test suite: %s\n' % len(self.jdata)) |
| 109 | for t in self.jdata: |
| 110 | test_result = self._execute_test_steps(t) |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 111 | test_results.update(test_result) |
| 112 | return self.configuration, self.result_id, self.write_dir, test_results |
| 113 | |
| 114 | def manualexecution(args, logger): |
| 115 | testrunner = ManualTestRunner() |
| 116 | get_configuration, get_result_id, get_write_dir, get_test_results = testrunner.run_test(args.file) |
| 117 | resultjsonhelper = OETestResultJSONHelper() |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 118 | resultjsonhelper.dump_testresult_file(get_write_dir, get_configuration, get_result_id, get_test_results) |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 119 | return 0 |
| 120 | |
| 121 | def register_commands(subparsers): |
| 122 | """Register subcommands from this plugin""" |
| 123 | parser_build = subparsers.add_parser('manualexecution', help='helper script for results populating during manual test execution.', |
| 124 | description='helper script for results populating during manual test execution. You can find manual test case JSON file in meta/lib/oeqa/manual/', |
| 125 | group='manualexecution') |
| 126 | parser_build.set_defaults(func=manualexecution) |
| 127 | parser_build.add_argument('file', help='specify path to manual test case JSON file.Note: Please use \"\" to encapsulate the file path.') |