summaryrefslogtreecommitdiffstats
path: root/scripts/lib/resulttool/merge.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/resulttool/merge.py')
-rw-r--r--scripts/lib/resulttool/merge.py69
1 files changed, 20 insertions, 49 deletions
diff --git a/scripts/lib/resulttool/merge.py b/scripts/lib/resulttool/merge.py
index 1d9cfafd41..3e4b7a38ad 100644
--- a/scripts/lib/resulttool/merge.py
+++ b/scripts/lib/resulttool/merge.py
@@ -1,6 +1,7 @@
1# test result tool - merge multiple testresults.json files 1# resulttool - merge multiple testresults.json files into a file or directory
2# 2#
3# Copyright (c) 2019, Intel Corporation. 3# Copyright (c) 2019, Intel Corporation.
4# Copyright (c) 2019, Linux Foundation
4# 5#
5# This program is free software; you can redistribute it and/or modify it 6# 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# under the terms and conditions of the GNU General Public License,
@@ -11,61 +12,31 @@
11# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12# more details. 13# more details.
13# 14#
14from resulttool.resultsutils import load_json_file, get_dict_value, dump_json_data
15import os 15import os
16import json 16import json
17 17import resulttool.resultutils as resultutils
18class ResultsMerge(object):
19
20 def get_test_results(self, logger, file, result_id):
21 results = load_json_file(file)
22 if result_id:
23 result = get_dict_value(logger, results, result_id)
24 if result:
25 return {result_id: result}
26 return result
27 return results
28
29 def merge_results(self, base_results, target_results):
30 for k in target_results:
31 base_results[k] = target_results[k]
32 return base_results
33
34 def _get_write_dir(self):
35 basepath = os.environ['BUILDDIR']
36 return basepath + '/tmp/'
37
38 def dump_merged_results(self, results, output_dir):
39 file_output_dir = output_dir if output_dir else self._get_write_dir()
40 dump_json_data(file_output_dir, 'testresults.json', results)
41 print('Successfully merged results to: %s' % os.path.join(file_output_dir, 'testresults.json'))
42
43 def run(self, logger, base_result_file, target_result_file, target_result_id, output_dir):
44 base_results = self.get_test_results(logger, base_result_file, '')
45 target_results = self.get_test_results(logger, target_result_file, target_result_id)
46 if base_results and target_results:
47 merged_results = self.merge_results(base_results, target_results)
48 self.dump_merged_results(merged_results, output_dir)
49 18
50def merge(args, logger): 19def merge(args, logger):
51 merge = ResultsMerge() 20 if os.path.isdir(args.target_results):
52 merge.run(logger, args.base_result_file, args.target_result_file, args.target_result_id, args.output_dir) 21 results = resultutils.load_resultsdata(args.target_results, configmap=resultutils.store_map)
22 resultutils.append_resultsdata(results, args.base_results, configmap=resultutils.store_map)
23 resultutils.save_resultsdata(results, args.target_results)
24 else:
25 results = resultutils.load_resultsdata(args.base_results, configmap=resultutils.flatten_map)
26 if os.path.exists(args.target_results):
27 resultutils.append_resultsdata(results, args.target_results, configmap=resultutils.flatten_map)
28 resultutils.save_resultsdata(results, os.path.dirname(args.target_results), fn=os.path.basename(args.target_results))
29
53 return 0 30 return 0
54 31
55def register_commands(subparsers): 32def register_commands(subparsers):
56 """Register subcommands from this plugin""" 33 """Register subcommands from this plugin"""
57 parser_build = subparsers.add_parser('merge', help='merge test results', 34 parser_build = subparsers.add_parser('merge', help='merge test result files/directories',
58 description='merge results from multiple files', 35 description='merge the results from multiple files/directories into the target file or directory',
59 group='setup') 36 group='setup')
60 parser_build.set_defaults(func=merge) 37 parser_build.set_defaults(func=merge)
61 parser_build.add_argument('base_result_file', 38 parser_build.add_argument('base_results',
62 help='base result file provide the base result set') 39 help='the results file/directory to import')
63 parser_build.add_argument('target_result_file', 40 parser_build.add_argument('target_results',
64 help='target result file provide the target result set for merging into the ' 41 help='the target file or directory to merge the base_results with')
65 'base result set') 42
66 parser_build.add_argument('-t', '--target-result-id', default='',
67 help='(optional) default merge all result sets available from target to base '
68 'unless specific target result id was provided')
69 parser_build.add_argument('-o', '--output-dir', default='',
70 help='(optional) default write merged results to <poky>/build/tmp/ unless specific '
71 'output directory was provided')