testimage: implement test artifacts retriever for failing tests

Add a basic artifacts retrievers in testimage class which:
- triggers when at least one runtime test fails but tests execution
  encountered no major issue
- reads a list of paths to retrieve from TESTIMAGE_FAILED_QA_ARTIFACTS
- checks for artifacts presence on target
- retrieve those files over scp thanks to existing ssh class
- store those files in an "artifacts" directory in "tmp/log/oeqa/<image>"

This implementation assumes that the SSH or Qemu target has run and
finished gracefully. If tests do not finish because of an exception,
artifacts will not be retrieved

Bring partial solution to [YOCTO #14901]

(From OE-Core rev: 36ef582b8c1c99e6af1ce79ea79f5b059d2a1aad)

Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Alexis Lothoré
2023-06-09 08:48:01 +02:00
committed by Richard Purdie
parent cdac245fc2
commit 58206ea8d9

View File

@@ -18,6 +18,15 @@ inherit image-artifact-names
TESTIMAGE_AUTO ??= "0"
# When any test fails, TESTIMAGE_FAILED_QA ARTIFACTS will be parsed and for
# each entry in it, if artifact pointed by path description exists on target,
# it will be retrieved onto host
TESTIMAGE_FAILED_QA_ARTIFACTS ??= "\
${localstatedir}/log \
${sysconfdir}/version \
${sysconfdir}/os-release"
# You can set (or append to) TEST_SUITES in local.conf to select the tests
# which you want to run for your target.
# The test names are the module names in meta/lib/oeqa/runtime/cases.
@@ -192,6 +201,39 @@ def get_testimage_boot_patterns(d):
boot_patterns[flag] = flagval.encode().decode('unicode-escape')
return boot_patterns
def get_artifacts_list(target, raw_list):
result = []
# Passed list may contains patterns in paths, expand them directly on target
for raw_path in raw_list.split():
cmd = f"for p in {raw_path}; do if [ -e $p ]; then echo $p; fi; done"
try:
status, output = target.run(cmd)
if status != 0 or not output:
raise Exception()
result += output.split()
except:
bb.warn(f"No file/directory matching path {raw_path}")
return result
def retrieve_test_artifacts(target, artifacts_list, target_dir):
import shutil
local_artifacts_dir = os.path.join(target_dir, "artifacts")
if os.path.isdir(local_artifacts_dir):
shutil.rmtree(local_artifacts_dir)
os.makedirs(local_artifacts_dir)
for artifact_path in artifacts_list:
if not os.path.isabs(artifact_path):
bb.warn(f"{artifact_path} is not an absolute path")
continue
try:
dest_dir = os.path.join(local_artifacts_dir, os.path.dirname(artifact_path[1:]))
os.makedirs(dest_dir, exist_ok=True)
target.copyFrom(artifact_path, dest_dir)
except:
bb.warn(f"Can not retrieve {artifact_path} from test target")
def testimage_main(d):
import os
@@ -383,6 +425,12 @@ def testimage_main(d):
pass
results = tc.runTests()
complete = True
if results.hasAnyFailingTest():
artifacts_list = get_artifacts_list(tc.target, d.getVar("TESTIMAGE_FAILED_QA_ARTIFACTS"))
if not artifacts_list:
bb.warn("Could not load artifacts list, skip artifacts retrieval")
else:
retrieve_test_artifacts(tc.target, artifacts_list, get_testimage_json_result_dir(d))
except (KeyboardInterrupt, BlockingIOError) as err:
if isinstance(err, KeyboardInterrupt):
bb.error('testimage interrupted, shutting down...')