blob: c94f98126b08289fd7f735040bdb4b2452be4b3f [file] [log] [blame]
Brad Bishop40320b12019-03-26 16:08:25 -04001# 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#
14import argparse
15import json
16import os
17import sys
18import datetime
19import re
20from oeqa.core.runner import OETestResultJSONHelper
21
22
23def load_json_file(file):
24 with open(file, "r") as f:
25 return json.load(f)
26
Brad Bishop40320b12019-03-26 16:08:25 -040027class ManualTestRunner(object):
Brad Bishop40320b12019-03-26 16:08:25 -040028
29 def _get_testcases(self, file):
30 self.jdata = load_json_file(file)
Brad Bishop40320b12019-03-26 16:08:25 -040031 self.test_module = self.jdata[0]['test']['@alias'].split('.', 2)[0]
Brad Bishop19323692019-04-05 15:28:33 -040032
Brad Bishop40320b12019-03-26 16:08:25 -040033 def _get_input(self, config):
34 while True:
35 output = input('{} = '.format(config))
Brad Bishop19323692019-04-05 15:28:33 -040036 if re.match('^[a-z0-9-.]+$', output):
Brad Bishop40320b12019-03-26 16:08:25 -040037 break
Brad Bishop19323692019-04-05 15:28:33 -040038 print('Only lowercase alphanumeric, hyphen and dot are allowed. Please try again')
Brad Bishop40320b12019-03-26 16:08:25 -040039 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 Bishop19323692019-04-05 15:28:33 -040058 print('This is configuration #%s. Please provide configuration value(use "None" if not applicable).' % config)
Brad Bishop40320b12019-03-26 16:08:25 -040059 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 Bishop19323692019-04-05 15:28:33 -040065 self.result_id = 'manual_%s_%s' % (self.test_module, self.starttime)
Brad Bishop40320b12019-03-26 16:08:25 -040066
Brad Bishop19323692019-04-05 15:28:33 -040067 def _execute_test_steps(self, test):
Brad Bishop40320b12019-03-26 16:08:25 -040068 test_result = {}
Brad Bishop40320b12019-03-26 16:08:25 -040069 print('------------------------------------------------------------------------')
Brad Bishop19323692019-04-05 15:28:33 -040070 print('Executing test case: %s' % test['test']['@alias'])
Brad Bishop40320b12019-03-26 16:08:25 -040071 print('------------------------------------------------------------------------')
Brad Bishop19323692019-04-05 15:28:33 -040072 print('You have total %s test steps to be executed.' % len(test['test']['execution']))
Brad Bishop40320b12019-03-26 16:08:25 -040073 print('------------------------------------------------------------------------\n')
Brad Bishop19323692019-04-05 15:28:33 -040074 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 Bishop40320b12019-03-26 16:08:25 -040079 while True:
Brad Bishop19323692019-04-05 15:28:33 -040080 done = input('\nPlease provide test results: (P)assed/(F)ailed/(B)locked/(S)kipped? \n').lower()
Brad Bishop40320b12019-03-26 16:08:25 -040081 result_types = {'p':'PASSED',
Brad Bishop19323692019-04-05 15:28:33 -040082 'f':'FAILED',
83 'b':'BLOCKED',
84 's':'SKIPPED'}
Brad Bishop40320b12019-03-26 16:08:25 -040085 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 Bishop19323692019-04-05 15:28:33 -040091 test_result.update({test['test']['@alias']: {'status': '%s' % res, 'log': '%s' % log_input}})
Brad Bishop40320b12019-03-26 16:08:25 -040092 else:
Brad Bishop19323692019-04-05 15:28:33 -040093 test_result.update({test['test']['@alias']: {'status': '%s' % res}})
Brad Bishop40320b12019-03-26 16:08:25 -040094 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 Bishop19323692019-04-05 15:28:33 -0400108 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 Bishop40320b12019-03-26 16:08:25 -0400111 test_results.update(test_result)
112 return self.configuration, self.result_id, self.write_dir, test_results
113
114def 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 Bishop19323692019-04-05 15:28:33 -0400118 resultjsonhelper.dump_testresult_file(get_write_dir, get_configuration, get_result_id, get_test_results)
Brad Bishop40320b12019-03-26 16:08:25 -0400119 return 0
120
121def 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.')