test-case-mgmt
cover test-case-mgmt
v1:
Face key error from oe-git-archive
Undesirable behavior when storing to multiple git branch
v2:
Include fix for oe-git-archive
Include fix for store result to multiple git branch Improve git commit message
Mazliana (1):
scripts/test-case-mgmt: enable manual execution and result creation
Yeoh Ee Peng (2):
scripts/oe-git-archive: fix non-existent key referencing error scripts/test-case-mgmt: store test result and reporting
scripts/lib/testcasemgmt/__init__.py | 0 scripts/lib/testcasemgmt/gitstore.py | 172 +++++++++++++++++++++ scripts/lib/testcasemgmt/manualexecution.py | 142 +++++++++++++++++ scripts/lib/testcasemgmt/report.py | 136 ++++++++++++++++ scripts/lib/testcasemgmt/store.py | 40 +++++ .../template/test_report_full_text.txt | 33 ++++ scripts/oe-git-archive | 28 +++- scripts/test-case-mgmt | 105 +++++++++++++ 8 files changed, 650 insertions(+), 6 deletions(-) create mode 100644 scripts/lib/testcasemgmt/__init__.py create mode 100644 scripts/lib/testcasemgmt/gitstore.py create mode 100644 scripts/lib/testcasemgmt/manualexecution.py create mode 100644 scripts/lib/testcasemgmt/report.py create mode 100644 scripts/lib/testcasemgmt/store.py create mode 100644 scripts/lib/testcasemgmt/template/test_report_full_text.txt create mode 100755 scripts/test-case-mgmt
Signature · 1 line
2.7.4
PATCH v2 1/3 scripts/oe-git-archive: fix non-existent key referencing error
Without installing gitpython package, oe-git-archive will face error below, where it was referencing key that was non-existent inside metadata object.
Traceback (most recent call last):
File "<poky_dir>/scripts/oe-git-archive", line 271, in <module>
sys.exit(main())
File "<poky_dir>/scripts/oe-git-archive", line 229, in main
'commit_count': metadata['layers']['meta']['commit_count'],KeyError: 'commit_count'
Fix this error by checking the key existent from metadata before referencing it.
[YOCTO# 13082]
--- scripts/oe-git-archive | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
scripts/oe-git-archive +22 -6
@@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 # # Helper script for committing data to git and pushing upstream #
@@ -208,6 +208,18 @@ def parse_args(argv): help="Data to commit") return parser.parse_args(argv) +def _get_metadata_value(metadata, keys): + if len(keys) > 0: + key = keys.pop(0) + if key in metadata: + if len(keys) == 0: + return metadata[key] + else: + return _get_metadata_value(metadata[key], keys) + else: + return "" + else: + return "" def main(argv=None): """Script entry point"""
@@ -223,11 +235,15 @@ def main(argv=None): # Get keywords to be used in tag and branch names and messages metadata = metadata_from_bb() - keywords = {'hostname': metadata['hostname'], - 'branch': metadata['layers']['meta']['branch'], - 'commit': metadata['layers']['meta']['commit'], - 'commit_count': metadata['layers']['meta']['commit_count'], - 'machine': metadata['config']['MACHINE']} + keywords_map = {'hostname': ['hostname'], + 'branch': ['layers', 'meta', 'branch'], + 'commit': ['layers', 'meta', 'commit'], + 'commit_count': ['layers', 'meta', 'commit_count'], + 'machine': ['config', 'MACHINE']} + keywords = {} + for map_key in keywords_map.keys(): + keywords_value = _get_metadata_value(metadata, keywords_map[map_key]) + keywords[map_key] = keywords_value # Expand strings early in order to avoid getting into inconsistent # state (e.g. no tag even if data was committed)
Signature · 1 line
2.7.4
Re: [PATCH 1/3 v2] scripts/oe-git-archive: fix non-existent key referencing error
Quoted 37 lines · Yeoh Ee Peng
Without installing gitpython package, oe-git-archive will face error below, where it was referencing key that was non-existent inside metadata object.
Traceback (most recent call last):
File "<poky_dir>/scripts/oe-git-archive", line 271, in <module>sys.exit(main()) File "<poky_dir>/scripts/oe-git-archive", line 229, in main 'commit_count': metadata['layers']['meta']['commit_count'],KeyError: '
commit_count'Fix this error by checking the key existent from metadata before referencing it.
[YOCTO# 13082]
Signed-off-by Yeoh Ee Peng <[email protected]>--- scripts/oe-git-archive | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)scripts/oe-git-archive +3
-1@@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 # # Helper script for committing data to git and pushing upstream #@@ -208,6 +208,18 @@ def parse_args(argv): help="Data to commit") return parser.parse_args(argv) +def _get_metadata_value(metadata, keys): + if len(keys) > 0:
scripts/oe-git-archive def parse_args(argv): · line 222
Quoted 10 lines
scripts/oe-git-archive +10
-0+ key = keys.pop(0) + if key in metadata: + if len(keys) == 0: + return metadata[key] + else: + return _get_metadata_value(metadata[key], keys) + else: + return "" + else: + return ""
This isn't very pythonic unfortunately. You can do "if X:" instead of "if len(X)" or "if len(X) > 0:". You can also remove the else: return "" and just put return "" at the end of the function.
I also think the recursion here is hard to understand and python has a better way of handling this, python tends to work on the "forgiveness" rather than "permission" approach to code. By that I mean:
try:
return metadata[key]
except KeyError:
return ""
is more "pythonic" than:
if key in metadata:
return metadata[key]
else:
return ""
(for dicts you can also do metadata.get(key, "") )
Quoted 25 lines
scripts/oe-git-archive +0
-0def main(argv=None): """Script entry point"""@@ -223,11 +235,15 @@ def main(argv=None): # Get keywords to be used in tag and branch names andmessages
metadata =metadata_from_bb()scripts/oe-git-archive +0
-4- keywords = {'hostname': metadata['hostname'], - 'branch': metadata['layers']['meta']['branch'], - 'commit': metadata['layers']['meta']['commit'], - 'commit_count':metadata['layers']['meta']['commit_count'],
scripts/oe-git-archive +4
-1- 'machine': metadata['config']['MACHINE']} + keywords_map = {'hostname': ['hostname'], + 'branch': ['layers', 'meta', 'branch'], + 'commit': ['layers', 'meta', 'commit'], + 'commit_count': ['layers', 'meta','
commit_count'],scripts/oe-git-archive +4
-0+ 'machine': ['config', 'MACHINE']} + keywords = {} + for map_key in keywords_map.keys(): + keywords_value = _get_metadata_value(metadata,keywords_map[map_key])
+ keywords[map_key] =keywords_value
Quoted 3 lines
# Expand strings early in order to avoid getting into
inconsistent# state (e.g. no tag even if data was committed)
How about something like:
def get_nested(d, list_of_keys):
try:
for k in list_of_keys:
d = d[k]
return d
except KeyError:
return ""
keywords = {'hostname': get_nested(metadata, ['hostname']),
'branch': get_nested(metadata, ['layers', 'meta', 'branch']),
'commit': get_nested(metadata, ['layers', 'meta', 'commit']),
'commit_count': get_nested(metadata, ['layers', 'meta', 'commit_count']),
'machine': get_nested(metadata, ['config', 'MACHINE'])}Cheers,
Richard
PATCH v2 2/3 scripts/test-case-mgmt: store test result and reporting
In reply to Yeoh Ee PengThese scripts were developed as an alternative testcase management tool to Testopia. Using these scripts, user can manage the testresults.json files generated by oeqa automated tests. Using the "store" operation, user can store multiple groups of test result each into individual git branch. Within each git branch, user can store multiple testresults.json files under different directories (eg. categorize directory by selftest-<distro>, runtime-<image>-<machine>). Then, using the "report" operation, user can view the test result summary for all available testresults.json files being stored that were grouped by directory and test configuration.
The "report" operation expect the testresults.json file to use the json format below.
{
"<testresult_1>": {
"configuration": {
"<config_name_1>": "<config_value_1>",
"<config_name_2>": "<config_value_2>",
...
"<config_name_n>": "<config_value_n>",
},
"result": {
"<testcase_namespace_1>": {
"status": "<PASSED or FAILED or ERROR or SKIPPED>",
"log": "<failure or error logging>"
},
"<testcase_namespace_2>": {
"status": "<PASSED or FAILED or ERROR or SKIPPED>",
"log": "<failure or error logging>"
},
...
"<testcase_namespace_n>": {
"status": "<PASSED or FAILED or ERROR or SKIPPED>",
"log": "<failure or error logging>"
},
}
},
...
"<testresult_n>": {
"configuration": {
"<config_name_1>": "<config_value_1>",
"<config_name_2>": "<config_value_2>",
...
"<config_name_n>": "<config_value_n>",
},
"result": {
"<testcase_namespace_1>": {
"status": "<PASSED or FAILED or ERROR or SKIPPED>",
"log": "<failure or error logging>"
},
"<testcase_namespace_2>": {
"status": "<PASSED or FAILED or ERROR or SKIPPED>",
"log": "<failure or error logging>"
},
...
"<testcase_namespace_n>": {
"status": "<PASSED or FAILED or ERROR or SKIPPED>",
"log": "<failure or error logging>"
},
}
},
}To use these scripts, first source oe environment, then run the entry point script to look for help.
$ test-case-mgmt
To store test result from oeqa automated tests, execute the below
$ test-case-mgmt store <source_dir> <git_branch> By default, test result will be stored at <top_dir>/testresults
To store test result from oeqa automated tests under a specific directory, execute the below
$ test-case-mgmt store <source_dir> <git_branch> -s <sub_directory>
To view test report, execute the below
$ test-case-mgmt view <git_branch>
This scripts depends on scripts/oe-git-archive where it was facing error if gitpython package was not installed. Refer to [YOCTO# 13082] for more detail.
[YOCTO# 12654]
--- scripts/lib/testcasemgmt/__init__.py | 0 scripts/lib/testcasemgmt/gitstore.py | 172 +++++++++++++++++++++ scripts/lib/testcasemgmt/report.py | 136 ++++++++++++++++ scripts/lib/testcasemgmt/store.py | 40 +++++ .../template/test_report_full_text.txt | 33 ++++ scripts/test-case-mgmt | 96 ++++++++++++ 6 files changed, 477 insertions(+) create mode 100644 scripts/lib/testcasemgmt/__init__.py create mode 100644 scripts/lib/testcasemgmt/gitstore.py create mode 100644 scripts/lib/testcasemgmt/report.py create mode 100644 scripts/lib/testcasemgmt/store.py create mode 100644 scripts/lib/testcasemgmt/template/test_report_full_text.txt create mode 100755 scripts/test-case-mgmt
scripts/lib/testcasemgmt/__init__.py new file +0 -0
scripts/lib/testcasemgmt/gitstore.py new file +172 -0
172 lines not on this page · raw message
scripts/lib/testcasemgmt/report.py new file +136 -0
136 lines not on this page · raw message
scripts/lib/testcasemgmt/store.py new file +40 -0
@@ -0,0 +1,40 @@ +# test case management tool - store test result +# +# Copyright (c) 2018, Intel Corporation. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms and conditions of the GNU General Public License, +# version 2, as published by the Free Software Foundation. +# +# This program is distributed in the hope it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +from testcasemgmt.gitstore import GitStore + +def store(args, logger): + gitstore = GitStore(args.git_dir, args.git_branch) + gitstore.store_test_result(logger, args.source_dir, args.git_sub_dir, args.overwrite_result) + return 0 + +def register_commands(subparsers): + """Register subcommands from this plugin""" + parser_build = subparsers.add_parser('store', help='store test result files into git repository', + description='store the testresults.json file from the source directory into ' + 'the destination git repository with the given git branch', + group='store') + parser_build.set_defaults(func=store) + parser_build.add_argument('source_dir', + help='source directory that contain the test result files to be stored') + parser_build.add_argument('git_branch', help='git branch (new or existing) used to store the test result files') + parser_build.add_argument('-d', '--git-dir', default='', + help='(optional) destination directory (new or existing) to be used as git repository ' + 'to store the test result files from the source directory where ' + 'default location for destination directory will be <top_dir>/testresults') + parser_build.add_argument('-s', '--git-sub-dir', default='', + help='(optional) additional sub directory (new or existing) under the destination ' + 'directory (git-dir) where it will be used to hold the test result files, used ' + 'this if storing multiple test result files') + parser_build.add_argument('-o', '--overwrite-result', action='store_true', + help='(optional) overwrite existing test result file with new file provided')
scripts/lib/testcasemgmt/template/test_report_full_text.txt new file +33 -0
@@ -0,0 +1,33 @@ +============================================================================================================== +Test Report (Count of passed, failed, skipped group by test_component, test_configuration) +============================================================================================================== +-------------------------------------------------------------------------------------------------------------- +{{ 'test_component'.ljust(max_len_component) }} | {{ 'test_configuration'.ljust(max_len_config) }} | {{ 'passed'.ljust(10) }} | {{ 'failed'.ljust(10) }} | {{ 'skipped'.ljust(10) }} +-------------------------------------------------------------------------------------------------------------- +{% for report in test_reports |sort(attribute='test_component_configuration') %} +{{ report.test_component.ljust(max_len_component) }} | {{ report.test_configuration.ljust(max_len_config) }} | {{ report.passed.ljust(10) }} | {{ report.failed.ljust(10) }} | {{ report.skipped.ljust(10) }} +{% endfor %} +-------------------------------------------------------------------------------------------------------------- + +============================================================================================================== +Test Report (Percent of passed, failed, skipped group by test_component, test_configuration) +============================================================================================================== +-------------------------------------------------------------------------------------------------------------- +{{ 'test_component'.ljust(max_len_component) }} | {{ 'test_configuration'.ljust(max_len_config) }} | {{ 'passed_%'.ljust(10) }} | {{ 'failed_%'.ljust(10) }} | {{ 'skipped_%'.ljust(10) }} +-------------------------------------------------------------------------------------------------------------- +{% for report in test_reports |sort(attribute='test_component_configuration') %} +{{ report.test_component.ljust(max_len_component) }} | {{ report.test_configuration.ljust(max_len_config) }} | {{ report.passed_percent.ljust(10) }} | {{ report.failed_percent.ljust(10) }} | {{ report.skipped_percent.ljust(10) }} +{% endfor %} +-------------------------------------------------------------------------------------------------------------- + +============================================================================================================== +Test Report (Failed test cases group by test_component, test_configuration) +============================================================================================================== +-------------------------------------------------------------------------------------------------------------- +{% for report in test_reports |sort(attribute='test_component_configuration') %} +test_component | test_configuration : {{ report.test_component }} | {{ report.test_configuration }} +{% for testcase in report.failed_testcases %} + {{ testcase }} +{% endfor %} +{% endfor %} +--------------------------------------------------------------------------------------------------------------
scripts/test-case-mgmt new file +96 -0
96 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v2 3/3 scripts/test-case-mgmt: enable manual execution and result creation
In reply to Yeoh Ee PengFrom: Mazliana <[email protected]>
Integrated “manualexecution” operation to test-case-mgmt scripts. Manual execution script is a helper script to execute all manual test cases in baseline command, which consists of user guideline steps and the expected results. The last step will ask user to provide their input to execute result. The input options are passed/failed/blocked/skipped status. The result given will be written in testresults.json including log error from the user input and configuration if there is any.The output test result for json file is created by using OEQA library.
The configuration part is manually key-in by the user. The system allow user to specify how many configuration they want to add and they need to define the required configuration name and value pair. In QA perspective, "configuration" means the test environments and parameters used during QA setup before testing can be carry out. Example of configurations: image used for boot up, host machine distro used, poky configurations, etc.
The purpose of adding the configuration is to standardize the output test result format between automation and manual execution.
To use these scripts, first source oe environment, then run the entry point script to look for help.
$ test-case-mgmt
To execute manual test cases, execute the below
$ test-case-mgmt manualexecution <manualjsonfile>
By default testresults.json store in <build_dir>/tmp/log/manual/
[YOCTO #12651]
--- scripts/lib/testcasemgmt/manualexecution.py | 142 ++++++++++++++++++++++++++++ scripts/test-case-mgmt | 11 ++- 2 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 scripts/lib/testcasemgmt/manualexecution.py
scripts/lib/testcasemgmt/manualexecution.py new file +142 -0
@@ -0,0 +1,142 @@ +# test case management tool - manual execution from testopia test cases +# +# Copyright (c) 2018, Intel Corporation. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms and conditions of the GNU General Public License, +# version 2, as published by the Free Software Foundation. +# +# This program is distributed in the hope it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +import argparse +import json +import os +import sys +import datetime +import re +from oeqa.core.runner import OETestResultJSONHelper + +class ManualTestRunner(object): + def __init__(self): + self.jdata = '' + self.test_module = '' + self.test_suite = '' + self.test_case = '' + self.configuration = '' + self.starttime = '' + self.result_id = '' + self.write_dir = '' + + def _read_json(self, file): + self.jdata = json.load(open('%s' % file)) + self.test_case = [] + self.test_module = self.jdata[0]['test']['@alias'].split('.', 2)[0] + self.test_suite = self.jdata[0]['test']['@alias'].split('.', 2)[1] + for i in range(0, len(self.jdata)): + self.test_case.append(self.jdata[i]['test']['@alias'].split('.', 2)[2]) + + def _get_input(self, config): + while True: + output = input('{} = '.format(config)) + if re.match('^[a-zA-Z0-9_]+$', output): + break + print('Only alphanumeric and underscore are allowed. Please try again') + return output + + def _create_config(self): + self.configuration = {} + while True: + try: + conf_total = int(input('\nPlease provide how many configuration you want to save \n')) + break + except ValueError: + print('Invalid input. Please provide input as a number not character.') + for i in range(conf_total): + print('---------------------------------------------') + print('This is configuration #%s ' % (i + 1) + '. Please provide configuration name and its value') + print('---------------------------------------------') + name_conf = self._get_input('Configuration Name') + value_conf = self._get_input('Configuration Value') + print('---------------------------------------------\n') + self.configuration[name_conf.upper()] = value_conf + current_datetime = datetime.datetime.now() + self.starttime = current_datetime.strftime('%Y%m%d%H%M%S') + self.configuration['STARTTIME'] = self.starttime + self.configuration['TEST_TYPE'] = self.test_module + + def _create_result_id(self): + self.result_id = 'manual_' + self.test_module + '_' + self.starttime + + def _execute_test_steps(self, test_id): + test_result = {} + testcase_id = self.test_module + '.' + self.test_suite + '.' + self.test_case[test_id] + total_steps = len(self.jdata[test_id]['test']['execution'].keys()) + print('------------------------------------------------------------------------') + print('Executing test case:' + '' '' + self.test_case[test_id]) + print('------------------------------------------------------------------------') + print('You have total ' + str(total_steps) + ' test steps to be executed.') + print('------------------------------------------------------------------------\n') + + for step in range (1, (total_steps + 1)): + print('Step %s: ' % step + self.jdata[test_id]['test']['execution']['%s' % step]['action']) + print('Expected output: ' + self.jdata[test_id]['test']['execution']['%s' % step]['expected_results']) + if step == total_steps: + while True: + try: + done = input('\nPlease provide test results: (P)assed/(F)ailed/(B)locked/(S)kipped? \n') + done = done.lower() + if done == 'p': + res = 'PASSED' + elif done == 'f': + res = 'FAILED' + log_input = input('\nPlease enter the error and the description of the log: (Ex:log:211 Error Bitbake)\n') + elif done == 'b': + res = 'BLOCKED' + elif done == 's': + res = 'SKIPPED' + + if res == 'FAILED': + test_result.update({testcase_id: {'status': '%s' % res, 'log': '%s' % log_input}}) + else: + test_result.update({testcase_id: {'status': '%s' % res}}) + break + except: + print('Invalid input!') + else: + done = input('\nPlease press ENTER when you are done to proceed to next step.\n') + return test_result + + def _create_write_dir(self): + basepath = os.environ['BUILDDIR'] + self.write_dir = basepath + '/tmp/log/manual/' + + def run_test(self, file): + self._read_json(file) + self._create_config() + self._create_result_id() + self._create_write_dir() + test_results = {} + print('\nTotal number of test cases in this test suite: ' + '%s\n' % len(self.jdata)) + for i in range(0, len(self.jdata)): + test_result = self._execute_test_steps(i) + test_results.update(test_result) + return self.configuration, self.result_id, self.write_dir, test_results + +def manualexecution(args, logger): + testrunner = ManualTestRunner() + get_configuration, get_result_id, get_write_dir, get_test_results = testrunner.run_test(args.file) + resultjsonhelper = OETestResultJSONHelper() + resultjsonhelper.dump_testresult_file(get_write_dir, get_configuration, get_result_id, + get_test_results) + return 0 + +def register_commands(subparsers): + """Register subcommands from this plugin""" + parser_build = subparsers.add_parser('manualexecution', help='Helper script for results populating during manual test execution.', + description='Helper script for results populating during manual test execution. You can find manual test case JSON file in meta/lib/oeqa/manual/', + group='manualexecution') + parser_build.set_defaults(func=manualexecution) + parser_build.add_argument('file', help='Specify path to manual test case JSON file.Note: Please use \"\" to encapsulate the file path.')
scripts/test-case-mgmt +10 -1
@@ -8,7 +8,7 @@ # test-case-mgmt script was designed as part of the helper script for below purpose: # 1. To store test result inside git repository # 2. To report text-based test result summary -# 3. (Future) To execute manual test cases +# 3. To execute manual test cases # # To look for help information. # $ test-case-mgmt
@@ -19,6 +19,12 @@ # To report test result summary, execute the below # $ test-case-mgmt report <git_branch> # +# To execute manual test cases, execute the below +# $ test-case-mgmt manualexecution <manualjsonfile> +# +# By default testresults.json for manualexecution store in <build_dir>/tmp/log/manual/ +# +# # Copyright (c) 2018, Intel Corporation. # # This program is free software; you can redistribute it and/or modify it
@@ -42,6 +48,7 @@ import argparse_oe import scriptutils import testcasemgmt.store import testcasemgmt.report +import testcasemgmt.manualexecution logger = scriptutils.logger_create('test-case-mgmt') def _validate_user_input_arguments(args):
@@ -72,6 +79,8 @@ def main(): parser.add_argument('-q', '--quiet', help='print only errors', action='store_true') subparsers = parser.add_subparsers(dest="subparser_name", title='subcommands', metavar='<subcommand>') subparsers.required = True + subparsers.add_subparser_group('manualexecution', 'execute manual test cases', 300) + testcasemgmt.manualexecution.register_commands(subparsers) subparsers.add_subparser_group('store', 'store test result', 200) testcasemgmt.store.register_commands(subparsers) subparsers.add_subparser_group('report', 'report test result summary', 100)
Signature · 1 line
2.7.4