diff options
| author | Joshua Watt <jpewhacker@gmail.com> | 2019-05-08 11:16:23 -0500 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2019-05-08 22:56:45 +0100 |
| commit | 9a97ea263c571b27283c59e69c880df0fa094052 (patch) | |
| tree | 6e514f716c36991f06d21568426d738f23dfdf0c /scripts/lib | |
| parent | d6b53084af4d2923fccd6d6c9b43721fb4f414fb (diff) | |
| download | poky-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')
| -rw-r--r-- | scripts/lib/resulttool/log.py | 54 | ||||
| -rw-r--r-- | scripts/lib/resulttool/resultutils.py | 16 |
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 | # |
| 14 | import os | ||
| 14 | import resulttool.resultutils as resultutils | 15 | import resulttool.resultutils as resultutils |
| 15 | 16 | ||
| 16 | def show_ptest(result, ptest, logger): | 17 | def show_ptest(result, ptest, logger): |
| @@ -24,22 +25,38 @@ def show_ptest(result, ptest, logger): | |||
| 24 | 25 | ||
| 25 | def log(args, logger): | 26 | def 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 | ||
| 44 | def register_commands(subparsers): | 61 | def 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 | |||
| 171 | def 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 | |||
