summaryrefslogtreecommitdiffstats
path: root/scripts/lib/resulttool/log.py
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-08 22:56:45 +0100
commit9a97ea263c571b27283c59e69c880df0fa094052 (patch)
tree6e514f716c36991f06d21568426d738f23dfdf0c /scripts/lib/resulttool/log.py
parentd6b53084af4d2923fccd6d6c9b43721fb4f414fb (diff)
downloadpoky-9a97ea263c571b27283c59e69c880df0fa094052.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: f262b9e7482e38f04dfa162f0aaf65b17e86f8b2) Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/resulttool/log.py')
-rw-r--r--scripts/lib/resulttool/log.py54
1 files changed, 38 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