Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # resulttool - Show logs |
| 2 | # |
| 3 | # Copyright (c) 2019 Garmin International |
| 4 | # |
| 5 | # SPDX-License-Identifier: GPL-2.0-only |
| 6 | # |
| 7 | import os |
| 8 | import resulttool.resultutils as resultutils |
| 9 | |
| 10 | def show_ptest(result, ptest, logger): |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 11 | logdata = resultutils.ptestresult_get_log(result, ptest) |
| 12 | if logdata is not None: |
| 13 | print(logdata) |
| 14 | return 0 |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 15 | |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 16 | print("ptest '%s' log not found" % ptest) |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 17 | return 1 |
| 18 | |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 19 | def show_reproducible(result, reproducible, logger): |
| 20 | try: |
| 21 | print(result['reproducible'][reproducible]['diffoscope.text']) |
| 22 | return 0 |
| 23 | |
| 24 | except KeyError: |
| 25 | print("reproducible '%s' not found" % reproducible) |
| 26 | return 1 |
| 27 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 28 | def log(args, logger): |
| 29 | results = resultutils.load_resultsdata(args.source) |
| 30 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 31 | for _, run_name, _, r in resultutils.test_run_results(results): |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 32 | if args.list_ptest: |
| 33 | print('\n'.join(sorted(r['ptestresult.sections'].keys()))) |
| 34 | |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 35 | if args.dump_ptest: |
| 36 | for sectname in ['ptestresult.sections', 'ltpposixresult.sections', 'ltpresult.sections']: |
| 37 | if sectname in r: |
| 38 | for name, ptest in r[sectname].items(): |
| 39 | logdata = resultutils.generic_get_log(sectname, r, name) |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 40 | if logdata is not None: |
| 41 | dest_dir = args.dump_ptest |
| 42 | if args.prepend_run: |
| 43 | dest_dir = os.path.join(dest_dir, run_name) |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 44 | if not sectname.startswith("ptest"): |
| 45 | dest_dir = os.path.join(dest_dir, sectname.split(".")[0]) |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 46 | |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 47 | os.makedirs(dest_dir, exist_ok=True) |
| 48 | dest = os.path.join(dest_dir, '%s.log' % name) |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 49 | if os.path.exists(dest): |
| 50 | print("Overlapping ptest logs found, skipping %s. The '--prepend-run' option would avoid this" % name) |
| 51 | continue |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 52 | print(dest) |
| 53 | with open(dest, 'w') as f: |
| 54 | f.write(logdata) |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 55 | |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 56 | if args.raw_ptest: |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 57 | found = False |
| 58 | for sectname in ['ptestresult.rawlogs', 'ltpposixresult.rawlogs', 'ltpresult.rawlogs']: |
| 59 | rawlog = resultutils.generic_get_rawlogs(sectname, r) |
| 60 | if rawlog is not None: |
| 61 | print(rawlog) |
| 62 | found = True |
| 63 | if not found: |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 64 | print('Raw ptest logs not found') |
| 65 | return 1 |
| 66 | |
| 67 | if args.raw_reproducible: |
| 68 | if 'reproducible.rawlogs' in r: |
| 69 | print(r['reproducible.rawlogs']['log']) |
| 70 | else: |
| 71 | print('Raw reproducible logs not found') |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 72 | return 1 |
| 73 | |
| 74 | for ptest in args.ptest: |
| 75 | if not show_ptest(r, ptest, logger): |
| 76 | return 1 |
| 77 | |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 78 | for reproducible in args.reproducible: |
| 79 | if not show_reproducible(r, reproducible, logger): |
| 80 | return 1 |
| 81 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 82 | def register_commands(subparsers): |
| 83 | """Register subcommands from this plugin""" |
| 84 | parser = subparsers.add_parser('log', help='show logs', |
| 85 | description='show the logs from test results', |
| 86 | group='analysis') |
| 87 | parser.set_defaults(func=log) |
| 88 | parser.add_argument('source', |
| 89 | help='the results file/directory/URL to import') |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 90 | parser.add_argument('--list-ptest', action='store_true', |
| 91 | help='list the ptest test names') |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 92 | parser.add_argument('--ptest', action='append', default=[], |
| 93 | help='show logs for a ptest') |
| 94 | parser.add_argument('--dump-ptest', metavar='DIR', |
| 95 | help='Dump all ptest log files to the specified directory.') |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 96 | parser.add_argument('--reproducible', action='append', default=[], |
| 97 | help='show logs for a reproducible test') |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 98 | parser.add_argument('--prepend-run', action='store_true', |
| 99 | help='''Dump ptest results to a subdirectory named after the test run when using --dump-ptest. |
| 100 | Required if more than one test run is present in the result file''') |
| 101 | parser.add_argument('--raw', action='store_true', |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 102 | help='show raw (ptest) logs. Deprecated. Alias for "--raw-ptest"', dest='raw_ptest') |
| 103 | parser.add_argument('--raw-ptest', action='store_true', |
| 104 | help='show raw ptest log') |
| 105 | parser.add_argument('--raw-reproducible', action='store_true', |
| 106 | help='show raw reproducible build logs') |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 107 | |