summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa
diff options
context:
space:
mode:
authorAlexis Lothoré <alexis.lothore@bootlin.com>2024-02-26 10:19:19 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2024-02-27 11:35:43 +0000
commit3add7b301e38d11a47b55abfb583a648e6a4ac04 (patch)
treedbcd07bdf6a44df0d0468d944860395f25dd5bbb /meta/lib/oeqa
parentfec128bd625dbbb5a239d6ff6999e1e4a41a5a9b (diff)
downloadpoky-3add7b301e38d11a47b55abfb583a648e6a4ac04.tar.gz
testimage: create a list of failed test post actions
testimage is able to detect whenever a test run leads to some tests failing, and execute some actions in this case. The only action currently defined in such case is to retrieve artifacts from the target under test, as listed in TESTIMAGE_FAILED_QA_ARTIFACTS In order to be able to add multiple actions, define a central function to gather all "post actions" to run whenever a test has failed (run_failed_tests_post_actions). This function contains a table listing all functions to be called whenever a test fails. Any function in this table will be provided with bitbake internal data dictionary ("d") and the current runtime testing context ("tc"). Isolate all this feature in a dedicated postactions.py file inherited by testimage. This patch does not bring any functional change. (From OE-Core rev: c01aa8df0613a103859b4431d3cc5056b2fef1b8) Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa')
-rw-r--r--meta/lib/oeqa/utils/postactions.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/meta/lib/oeqa/utils/postactions.py b/meta/lib/oeqa/utils/postactions.py
new file mode 100644
index 0000000000..09c338ef68
--- /dev/null
+++ b/meta/lib/oeqa/utils/postactions.py
@@ -0,0 +1,68 @@
1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7# Run a set of actions after tests. The runner provides internal data
8# dictionary as well as test context to any action to run.
9
10from oeqa.utils import get_json_result_dir
11
12##################################################################
13# Artifacts retrieval
14##################################################################
15
16def get_artifacts_list(target, raw_list):
17 result = []
18 # Passed list may contains patterns in paths, expand them directly on target
19 for raw_path in raw_list.split():
20 cmd = f"for p in {raw_path}; do if [ -e $p ]; then echo $p; fi; done"
21 try:
22 status, output = target.run(cmd)
23 if status != 0 or not output:
24 raise Exception()
25 result += output.split()
26 except:
27 bb.note(f"No file/directory matching path {raw_path}")
28
29 return result
30
31def retrieve_test_artifacts(target, artifacts_list, target_dir):
32 import shutil
33
34 local_artifacts_dir = os.path.join(target_dir, "artifacts")
35 if os.path.isdir(local_artifacts_dir):
36 shutil.rmtree(local_artifacts_dir)
37
38 os.makedirs(local_artifacts_dir)
39 for artifact_path in artifacts_list:
40 if not os.path.isabs(artifact_path):
41 bb.warn(f"{artifact_path} is not an absolute path")
42 continue
43 try:
44 dest_dir = os.path.join(local_artifacts_dir, os.path.dirname(artifact_path[1:]))
45 os.makedirs(dest_dir, exist_ok=True)
46 target.copyFrom(artifact_path, dest_dir)
47 except Exception as e:
48 bb.warn(f"Can not retrieve {artifact_path} from test target: {e}")
49
50def list_and_fetch_failed_tests_artifacts(d, tc):
51 artifacts_list = get_artifacts_list(tc.target, d.getVar("TESTIMAGE_FAILED_QA_ARTIFACTS"))
52 if not artifacts_list:
53 bb.warn("Could not load artifacts list, skip artifacts retrieval")
54 else:
55 retrieve_test_artifacts(tc.target, artifacts_list, get_json_result_dir(d))
56
57
58##################################################################
59# General post actions runner
60##################################################################
61
62def run_failed_tests_post_actions(d, tc):
63 post_actions=[
64 list_and_fetch_failed_tests_artifacts
65 ]
66
67 for action in post_actions:
68 action(d, tc)