summaryrefslogtreecommitdiffstats
path: root/scripts/lib/resulttool
diff options
context:
space:
mode:
authorJoshua Watt <jpewhacker@gmail.com>2019-05-08 11:16:23 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-05-20 14:38:16 +0100
commit215f6dcd0ae35e8f700bae1bdc68d25e2e642d03 (patch)
tree7c00544e052b6a7b7a7181ee0d7b1b48f47204be /scripts/lib/resulttool
parent4c5f3371ede0b5a8c472e142c4add94268a74f51 (diff)
downloadpoky-215f6dcd0ae35e8f700bae1bdc68d25e2e642d03.tar.gz
resulttool: Add option to dump all ptest logs
Adds an option to dump all the ptest logs to individual files in a specified directory. If multiple test runs are present, the '--prepend-run' argument will create separate directories for each test run under the target directory and put the logs there to prevent each test run from clobbering the others. [YOCTO #13331] (From OE-Core rev: bb5a0fedda2817b9d71186a90a1f77bff3cbecaf) Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> Signed-off-by: Armin Kuster <akuster808@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/resulttool')
-rw-r--r--scripts/lib/resulttool/log.py54
-rw-r--r--scripts/lib/resulttool/resultutils.py16
2 files changed, 54 insertions, 16 deletions
diff --git a/scripts/lib/resulttool/log.py b/scripts/lib/resulttool/log.py
index 5584f2d0a9..49816357cd 100644
--- a/scripts/lib/resulttool/log.py
+++ b/scripts/lib/resulttool/log.py
@@ -11,6 +11,7 @@
11# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12# more details. 12# more details.
13# 13#
14import os
14import resulttool.resultutils as resultutils 15import resulttool.resultutils as resultutils
15 16
16def show_ptest(result, ptest, logger): 17def show_ptest(result, ptest, logger):
@@ -24,22 +25,38 @@ def show_ptest(result, ptest, logger):
24 25
25def log(args, logger): 26def log(args, logger):
26 results = resultutils.load_resultsdata(args.source) 27 results = resultutils.load_resultsdata(args.source)
27 for path in results: 28
28 for res in results[path]: 29 ptest_count = sum(1 for _, _, _, r in resultutils.test_run_results(results) if 'ptestresult.sections' in r)
29 if 'result' not in results[path][res]: 30 if ptest_count > 1 and not args.prepend_run:
30 continue 31 print("%i ptest sections found. '--prepend-run' is required" % ptest_count)
31 r = results[path][res]['result'] 32 return 1
32 33
33 if args.raw: 34 for _, run_name, _, r in resultutils.test_run_results(results):
34 if 'ptestresult.rawlogs' in r: 35 if args.dump_ptest:
35 print(r['ptestresult.rawlogs']['log']) 36 if 'ptestresult.sections' in r:
36 else: 37 for name, ptest in r['ptestresult.sections'].items():
37 print('Raw logs not found') 38 if 'log' in ptest:
38 return 1 39 dest_dir = args.dump_ptest
39 40 if args.prepend_run:
40 for ptest in args.ptest: 41 dest_dir = os.path.join(dest_dir, run_name)
41 if not show_ptest(r, ptest, logger): 42
42 return 1 43 os.makedirs(dest_dir, exist_ok=True)
44
45 dest = os.path.join(dest_dir, '%s.log' % name)
46 print(dest)
47 with open(dest, 'w') as f:
48 f.write(ptest['log'])
49
50 if args.raw:
51 if 'ptestresult.rawlogs' in r:
52 print(r['ptestresult.rawlogs']['log'])
53 else:
54 print('Raw logs not found')
55 return 1
56
57 for ptest in args.ptest:
58 if not show_ptest(r, ptest, logger):
59 return 1
43 60
44def register_commands(subparsers): 61def register_commands(subparsers):
45 """Register subcommands from this plugin""" 62 """Register subcommands from this plugin"""
@@ -51,6 +68,11 @@ def register_commands(subparsers):
51 help='the results file/directory/URL to import') 68 help='the results file/directory/URL to import')
52 parser.add_argument('--ptest', action='append', default=[], 69 parser.add_argument('--ptest', action='append', default=[],
53 help='show logs for a ptest') 70 help='show logs for a ptest')
71 parser.add_argument('--dump-ptest', metavar='DIR',
72 help='Dump all ptest log files to the specified directory.')
73 parser.add_argument('--prepend-run', action='store_true',
74 help='''Dump ptest results to a subdirectory named after the test run when using --dump-ptest.
75 Required if more than one test run is present in the result file''')
54 parser.add_argument('--raw', action='store_true', 76 parser.add_argument('--raw', action='store_true',
55 help='show raw logs') 77 help='show raw logs')
56 78
diff --git a/scripts/lib/resulttool/resultutils.py b/scripts/lib/resulttool/resultutils.py
index 8d17c7cd65..07dab4cbd3 100644
--- a/scripts/lib/resulttool/resultutils.py
+++ b/scripts/lib/resulttool/resultutils.py
@@ -167,3 +167,19 @@ def git_get_result(repo, tags):
167 append_resultsdata(results, obj) 167 append_resultsdata(results, obj)
168 168
169 return results 169 return results
170
171def test_run_results(results):
172 """
173 Convenient generator function that iterates over all test runs that have a
174 result section.
175
176 Generates a tuple of:
177 (result json file path, test run name, test run (dict), test run "results" (dict))
178 for each test run that has a "result" section
179 """
180 for path in results:
181 for run_name, test_run in results[path].items():
182 if not 'result' in test_run:
183 continue
184 yield path, run_name, test_run, test_run['result']
185