From 39cda3498ec68b91a671ead256231324d74f7d4c Mon Sep 17 00:00:00 2001 From: Yeoh Ee Peng Date: Thu, 14 Feb 2019 13:50:37 +0800 Subject: resulttool: enable merge, store, report and regression analysis OEQA outputs test results into json files and these files were archived by Autobuilder during QA releases. Example: each oe-selftest run by Autobuilder for different host distro generate a testresults.json file. These scripts were developed as a test result tools to manage these testresults.json file. Using the "store" operation, user can store multiple testresults.json files as well as the pre-configured directories used to hold those files. Using the "merge" operation, user can merge multiple testresults.json files to a target file. Using the "report" operation, user can view the test result summary for all available testresults.json files inside a ordinary directory or a git repository. Using the "regression-file" operation, user can perform regression analysis on testresults.json files specified. Using the "regression-dir" and "regression-git" operations, user can perform regression analysis on directory and git accordingly. These resulttool operations expect the testresults.json file to use the json format below. { "": { "configuration": { "": "", "": "", ... "": "", }, "result": { "": { "status": "", "log": "" }, "": { "status": "", "log": "" }, ... "": { "status": "", "log": "" }, } }, ... "": { "configuration": { "": "", "": "", ... "": "", }, "result": { "": { "status": "", "log": "" }, "": { "status": "", "log": "" }, ... "": { "status": "", "log": "" }, } }, } To use these scripts, first source oe environment, then run the entry point script to look for help. $ resulttool To store test result from oeqa automated tests, execute the below $ resulttool store To merge multiple testresults.json files, execute the below $ resulttool merge To report test report, execute the below $ resulttool report To perform regression file analysis, execute the below $ resulttool regression-file To perform regression dir analysis, execute the below $ resulttool regression-dir To perform regression git analysis, execute the below $ resulttool regression-git [YOCTO# 13012] [YOCTO# 12654] Signed-off-by: Yeoh Ee Peng Signed-off-by: Richard Purdie --- scripts/lib/resulttool/resultsutils.py | 67 ++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 scripts/lib/resulttool/resultsutils.py (limited to 'scripts/lib/resulttool/resultsutils.py') diff --git a/scripts/lib/resulttool/resultsutils.py b/scripts/lib/resulttool/resultsutils.py new file mode 100644 index 0000000000..368786922c --- /dev/null +++ b/scripts/lib/resulttool/resultsutils.py @@ -0,0 +1,67 @@ +# test result tool - utilities +# +# Copyright (c) 2019, 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 os +import json +import scriptpath +scriptpath.add_oe_lib_path() +from oeqa.utils.git import GitRepo, GitError + +def load_json_file(file): + with open(file, "r") as f: + return json.load(f) + +def dump_json_data(write_dir, file_name, json_data): + file_content = json.dumps(json_data, sort_keys=True, indent=4) + file_path = os.path.join(write_dir, file_name) + with open(file_path, 'w') as the_file: + the_file.write(file_content) + +def get_dict_value(logger, dict, key): + try: + return dict[key] + except KeyError: + if logger: + logger.debug('Faced KeyError exception: dict=%s: key=%s' % (dict, key)) + return None + except TypeError: + if logger: + logger.debug('Faced TypeError exception: dict=%s: key=%s' % (dict, key)) + return None + +def pop_dict_element(logger, dict, key): + try: + dict.pop(key) + except KeyError: + if logger: + logger.debug('Faced KeyError exception: dict=%s: key=%s' % (dict, key)) + except AttributeError: + if logger: + logger.debug('Faced AttributeError exception: dict=%s: key=%s' % (dict, key)) + +def checkout_git_dir(git_dir, git_branch): + try: + repo = GitRepo(git_dir, is_topdir=True) + repo.run_cmd('checkout %s' % git_branch) + return True + except GitError: + return False + +def get_directory_files(source_dir, excludes, file): + files_in_dir = [] + for root, dirs, files in os.walk(source_dir, topdown=True): + [dirs.remove(d) for d in list(dirs) if d in excludes] + for name in files: + if name == file: + files_in_dir.append(os.path.join(root, name)) + return files_in_dir \ No newline at end of file -- cgit v1.2.3