|
| 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