Skip to content

Commit 11ecb29

Browse files
committed
test: Import remote-selftests
1 parent aefaf76 commit 11ecb29

File tree

3 files changed

+138
-4
lines changed

3 files changed

+138
-4
lines changed

lib/ngci.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,24 @@ def setup(self, state, boot, test_dir):
270270

271271

272272
class SelftestsConfig(TestConfig):
273-
def __init__(self, name, selftest_build):
273+
def __init__(self, selftest_build, collection, exclude=[]):
274+
name = f'selftests-{collection}'
274275
super().__init__(name)
275-
self.name = name
276276
self.selftests = selftest_build
277+
self.collection = collection
278+
self.exclude = exclude
277279

278280
def setup(self, state, boot, test_dir):
279281
selftests_tar = f'{state.build_dir}/{self.selftests.output_dir}/selftests.tar.gz'
280282
run(f'ln -sf {selftests_tar}'.split(), cwd=test_dir, check=True)
281-
gen_script(f'{test_dir}/run.sh', f'{state.script_dir}/scripts/test/{self.name} {boot.name}\n')
283+
284+
cmd = [f'{state.script_dir}/scripts/test/remote-selftests']
285+
for test in self.exclude:
286+
cmd.append(f'-x {test}')
287+
288+
cmd.append(f'-c {self.collection} {boot.name}\n')
289+
cmd = ' '.join(cmd)
290+
gen_script(f'{test_dir}/run.sh', cmd)
282291

283292

284293
class QemuNetTestConfig(TestConfig):

lib/utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def test_harness(func, name, *args, **kwargs):
150150
return rc
151151

152152

153-
def filter_log_warnings(infile, outfile):
153+
def filter_log_warnings(infile, outfile, extra_patterns=[]):
154154
from configparser import ConfigParser
155155
import re
156156

@@ -169,6 +169,7 @@ def filter_log_warnings(infile, outfile):
169169
strings = [t[1] for t in parser.items('strings', [])]
170170
patterns = [t[1] for t in parser.items('patterns', [])]
171171
patterns = [re.compile(p) for p in patterns]
172+
patterns.extend(extra_patterns)
172173

173174
def suppress(line):
174175
for suppression in suppressions:

scripts/test/remote-selftests

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/usr/bin/python3
2+
3+
import os, sys
4+
sys.path.append(f'{os.path.dirname(sys.argv[0])}/../../lib')
5+
6+
import argparse
7+
import logging
8+
from subprocess import run
9+
from boot_utils import *
10+
from utils import setup_logging, filter_log_warnings
11+
12+
13+
def main(orig_args):
14+
setup_logging()
15+
16+
parser = argparse.ArgumentParser()
17+
parser.add_argument('-c', '--collection', required=True, type=str, help='Test collection to run')
18+
parser.add_argument('-x', dest='exclude', type=str, default=None, action='append', help='Exclude test(s)')
19+
parser.add_argument('host', type=str, help='Host to run the test on')
20+
args = parser.parse_args(orig_args)
21+
22+
hostname = f'root@{args.host}'
23+
collection = args.collection
24+
25+
logging.info(f'Selftests ({collection}) starting.')
26+
27+
logging.info(f'Copying selftests to {hostname} ...')
28+
run(['rsync', '-aL', 'selftests.tar.gz', f'{hostname}:/var/tmp/ngci-selftests.tar.gz'], check=True, timeout=minutes(5))
29+
30+
if collection == 'powerpc':
31+
collection = 'powerpc.*'
32+
33+
if args.exclude:
34+
paths = [s.replace('/', r'\/') for s in args.exclude]
35+
exprs = [f"-e '/^{s}$/d'" for s in paths]
36+
exprs = ' '.join(exprs)
37+
remove_excluded = f'sed -i {exprs} kselftest-list.txt'
38+
else:
39+
remove_excluded = '# none'
40+
41+
logging.info(f'Running selftests on {hostname} ...')
42+
script = f'''
43+
set -e
44+
echo "-> Running on: $(hostname)"
45+
echo "-> Kernel version: $(uname -a)"
46+
dmesg -n 8
47+
echo "ngci: selftests ({collection}) starting" > /dev/kmsg
48+
mkdir -p /var/tmp/ngci
49+
cd /var/tmp/ngci
50+
rm -rf selftests || true
51+
tar -xf /var/tmp/ngci-selftests.tar.gz
52+
cd selftests
53+
54+
echo "Disabling xmon ..."
55+
echo 0 > /sys/kernel/debug/powerpc/xmon || true
56+
57+
echo "Current BPF JIT settings ..."
58+
grep . /proc/sys/net/core/bpf_* || true
59+
echo "Enabling BPF JIT options ..."
60+
echo 1 > /proc/sys/net/core/bpf_jit_enable || true
61+
echo 2 > /proc/sys/net/core/bpf_jit_harden || true
62+
grep . /proc/sys/net/core/bpf_* || true
63+
64+
echo 0 > /proc/sys/kernel/perf_event_paranoid || true
65+
66+
ppc64_cpu --info || true
67+
68+
echo "-> Running tests ..."
69+
70+
echo "Excluding tests: {remove_excluded}"
71+
{remove_excluded}
72+
73+
rm -f test.log
74+
rc=0
75+
(set -o pipefail; ./run_kselftest.sh -c {collection} 2>&1 | tee test.log) || rc=1
76+
77+
echo "Dumping dmesg after test run:"
78+
echo "=============================="
79+
dmesg
80+
echo "=============================="
81+
82+
if [[ $rc -ne 0 ]]; then
83+
echo "Error: script failed!"
84+
echo "-> Finished FAIL"
85+
rc=1
86+
else
87+
rc=1
88+
grep -w -e "not ok" -e failure -e FAIL test.log || rc=0
89+
if [[ $rc -ne 0 ]]; then
90+
echo "Error: Saw failures!"
91+
echo "-> Finished FAIL"
92+
rc=1
93+
else
94+
echo "-> Finished OK"
95+
rc=0
96+
fi
97+
fi
98+
99+
echo "ngci: selftests ({collection}) finishing" > /dev/kmsg
100+
exit $rc
101+
EOF
102+
'''.encode('utf-8')
103+
104+
f = open('remote.log', 'w')
105+
result = run_ssh_script(hostname, script, timeout=minutes(60), stdout=f)
106+
f.close()
107+
108+
if not result:
109+
logging.error('Running remote selftests failed!')
110+
run(['tail', 'remote.log'])
111+
112+
patterns = [re.compile('\bnot ok\b'), re.compile('\bfailure:')]
113+
114+
if filter_log_warnings(open('remote.log'), open('warnings.txt', 'w'), patterns):
115+
logging.error('Errors/warnings seen in remote.log')
116+
run(['tail', 'warnings.txt'])
117+
result = False
118+
119+
if result:
120+
logging.info('Completed OK')
121+
122+
return result
123+
124+
sys.exit(0 if main(sys.argv[1:]) else 1)

0 commit comments

Comments
 (0)