summaryrefslogtreecommitdiffstats
path: root/meta/lib/patchtest/selftest/selftest
diff options
context:
space:
mode:
authorTrevor Gamblin <tgamblin@baylibre.com>2023-09-13 13:00:46 -0400
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-09-14 15:20:08 +0100
commit4a6f38c5327b40a45c340af49fee9a0d5cc890bd (patch)
tree669ae555ecc031990579baa207d40f38ab7e1335 /meta/lib/patchtest/selftest/selftest
parente12e6d94ecbea6e0dafc080f2f196e12228730eb (diff)
downloadpoky-4a6f38c5327b40a45c340af49fee9a0d5cc890bd.tar.gz
patchtest: Add tests from patchtest oe repo
Copy the core components of the patchtest-oe repo into meta/lib/patchtest in oe-core. (From OE-Core rev: 257f64f4e4414b78981104aec132b067beb5a92a) Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/patchtest/selftest/selftest')
-rwxr-xr-xmeta/lib/patchtest/selftest/selftest91
1 files changed, 91 insertions, 0 deletions
diff --git a/meta/lib/patchtest/selftest/selftest b/meta/lib/patchtest/selftest/selftest
new file mode 100755
index 0000000000..c2e6b4863d
--- /dev/null
+++ b/meta/lib/patchtest/selftest/selftest
@@ -0,0 +1,91 @@
1#!/usr/bin/env python3
2
3# Test every patch from files folder and output error on failure
4#
5# Copyright (C) 2016 Intel Corporation
6#
7# SPDX-License-Identifier: GPL-2.0
8
9import os
10import subprocess
11import sys
12
13currentdir = os.path.dirname(os.path.abspath(__file__))
14patchesdir = os.path.join(currentdir, 'files')
15topdir = os.path.dirname(currentdir)
16parentdir = os.path.dirname(topdir)
17
18def print_results(passcount, skipcount, failcount, xpasscount, xfailcount, errorcount):
19 total = passcount + skipcount + failcount + xpasscount + xfailcount + errorcount
20 print("============================================================================")
21 print("Testsuite summary for %s" % os.path.basename(topdir))
22 print("============================================================================")
23 print("# TOTAL: %s" % str(total))
24 print("# XPASS: %s" % str(xpasscount))
25 print("# XFAIL: %s" % str(xfailcount))
26 print("# PASS: %s" % str(passcount))
27 print("# FAIL: %s" % str(failcount))
28 print("# SKIP: %s" % str(skipcount))
29 print("# ERROR: %s" % str(errorcount))
30 print("============================================================================")
31
32# Once the tests are in oe-core, we can remove the testdir param and use os.path.dirname to get relative paths
33def test(root, patch, testdir):
34 res = True
35 patchpath = os.path.abspath(os.path.join(root, patch))
36
37
38 cmd = 'patchtest %s %s/tests --patch %s' % (testdir, topdir, patchpath)
39 results = subprocess.check_output(cmd, stderr=subprocess.STDOUT, universal_newlines=True, shell=True)
40
41 return results
42
43if __name__ == '__main__':
44 # sys.argv[1] should be the repo to target for selftest, i.e. oe-core
45 if len(sys.argv) == 1:
46 sys.exit("Error: Must provide the path to openembedded-core, e.g. \"selftest /workspace/yocto/openembedded-core\"")
47
48 passcount = 0
49 failcount = 0
50 skipcount = 0
51 xpasscount = 0
52 xfailcount = 0
53 errorcount = 0
54
55 results = None
56
57 for root, dirs, patches in os.walk(patchesdir):
58 for patch in patches:
59 results = test(root, patch, sys.argv[1])
60
61 a = patch.split('.')
62 klass, testname = a[0], a[1]
63 expected_result = a[-1]
64 testid = ".%s.%s" % (klass,testname)
65
66 for resultline in results.splitlines():
67 if testid in resultline:
68 result, _ = resultline.split()
69
70 if expected_result.upper() == "FAIL" and result.upper() == "FAIL":
71 xfailcount = xfailcount + 1
72 print("XFAIL: %s (file: %s)" % (testid.strip("."), os.path.basename(patch)))
73 elif expected_result.upper() == "PASS" and result.upper() == "PASS":
74 xpasscount = xpasscount + 1
75 print("XPASS: %s (file: %s)" % (testid.strip("."), os.path.basename(patch)))
76 else:
77 print("%s: %s (%s)" % (result.upper(), testid.strip("."), os.path.basename(patch)))
78 if result.upper() == "PASS":
79 passcount = passcount + 1
80 elif result.upper() == "FAIL":
81 failcount = failcount + 1
82 elif result.upper() == "SKIP":
83 skipcount = skipcount + 1
84 else:
85 print("Bad result on test %s against %s" % (testid.strip("."), os.path.basename(patch)))
86 errorcount = errorcount + 1
87 break
88 else:
89 print ("No test for=%s" % patch)
90
91 print_results(passcount, skipcount, failcount, xpasscount, xfailcount, errorcount)