mirror of
https://git.yoctoproject.org/poky
synced 2026-05-31 12:49:46 +00:00
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>
This commit is contained in:
committed by
Richard Purdie
parent
4c5f3371ed
commit
215f6dcd0a
@@ -11,6 +11,7 @@
|
|||||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
# more details.
|
# more details.
|
||||||
#
|
#
|
||||||
|
import os
|
||||||
import resulttool.resultutils as resultutils
|
import resulttool.resultutils as resultutils
|
||||||
|
|
||||||
def show_ptest(result, ptest, logger):
|
def show_ptest(result, ptest, logger):
|
||||||
@@ -24,22 +25,38 @@ def show_ptest(result, ptest, logger):
|
|||||||
|
|
||||||
def log(args, logger):
|
def log(args, logger):
|
||||||
results = resultutils.load_resultsdata(args.source)
|
results = resultutils.load_resultsdata(args.source)
|
||||||
for path in results:
|
|
||||||
for res in results[path]:
|
|
||||||
if 'result' not in results[path][res]:
|
|
||||||
continue
|
|
||||||
r = results[path][res]['result']
|
|
||||||
|
|
||||||
if args.raw:
|
ptest_count = sum(1 for _, _, _, r in resultutils.test_run_results(results) if 'ptestresult.sections' in r)
|
||||||
if 'ptestresult.rawlogs' in r:
|
if ptest_count > 1 and not args.prepend_run:
|
||||||
print(r['ptestresult.rawlogs']['log'])
|
print("%i ptest sections found. '--prepend-run' is required" % ptest_count)
|
||||||
else:
|
return 1
|
||||||
print('Raw logs not found')
|
|
||||||
return 1
|
|
||||||
|
|
||||||
for ptest in args.ptest:
|
for _, run_name, _, r in resultutils.test_run_results(results):
|
||||||
if not show_ptest(r, ptest, logger):
|
if args.dump_ptest:
|
||||||
return 1
|
if 'ptestresult.sections' in r:
|
||||||
|
for name, ptest in r['ptestresult.sections'].items():
|
||||||
|
if 'log' in ptest:
|
||||||
|
dest_dir = args.dump_ptest
|
||||||
|
if args.prepend_run:
|
||||||
|
dest_dir = os.path.join(dest_dir, run_name)
|
||||||
|
|
||||||
|
os.makedirs(dest_dir, exist_ok=True)
|
||||||
|
|
||||||
|
dest = os.path.join(dest_dir, '%s.log' % name)
|
||||||
|
print(dest)
|
||||||
|
with open(dest, 'w') as f:
|
||||||
|
f.write(ptest['log'])
|
||||||
|
|
||||||
|
if args.raw:
|
||||||
|
if 'ptestresult.rawlogs' in r:
|
||||||
|
print(r['ptestresult.rawlogs']['log'])
|
||||||
|
else:
|
||||||
|
print('Raw logs not found')
|
||||||
|
return 1
|
||||||
|
|
||||||
|
for ptest in args.ptest:
|
||||||
|
if not show_ptest(r, ptest, logger):
|
||||||
|
return 1
|
||||||
|
|
||||||
def register_commands(subparsers):
|
def register_commands(subparsers):
|
||||||
"""Register subcommands from this plugin"""
|
"""Register subcommands from this plugin"""
|
||||||
@@ -51,6 +68,11 @@ def register_commands(subparsers):
|
|||||||
help='the results file/directory/URL to import')
|
help='the results file/directory/URL to import')
|
||||||
parser.add_argument('--ptest', action='append', default=[],
|
parser.add_argument('--ptest', action='append', default=[],
|
||||||
help='show logs for a ptest')
|
help='show logs for a ptest')
|
||||||
|
parser.add_argument('--dump-ptest', metavar='DIR',
|
||||||
|
help='Dump all ptest log files to the specified directory.')
|
||||||
|
parser.add_argument('--prepend-run', action='store_true',
|
||||||
|
help='''Dump ptest results to a subdirectory named after the test run when using --dump-ptest.
|
||||||
|
Required if more than one test run is present in the result file''')
|
||||||
parser.add_argument('--raw', action='store_true',
|
parser.add_argument('--raw', action='store_true',
|
||||||
help='show raw logs')
|
help='show raw logs')
|
||||||
|
|
||||||
|
|||||||
@@ -167,3 +167,19 @@ def git_get_result(repo, tags):
|
|||||||
append_resultsdata(results, obj)
|
append_resultsdata(results, obj)
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
def test_run_results(results):
|
||||||
|
"""
|
||||||
|
Convenient generator function that iterates over all test runs that have a
|
||||||
|
result section.
|
||||||
|
|
||||||
|
Generates a tuple of:
|
||||||
|
(result json file path, test run name, test run (dict), test run "results" (dict))
|
||||||
|
for each test run that has a "result" section
|
||||||
|
"""
|
||||||
|
for path in results:
|
||||||
|
for run_name, test_run in results[path].items():
|
||||||
|
if not 'result' in test_run:
|
||||||
|
continue
|
||||||
|
yield path, run_name, test_run, test_run['result']
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user