|
| 1 | +#!/bin/sh |
| 2 | +# |
| 3 | +# Kernel Selftests Validation Script for ARM64 (RB3GEN2) |
| 4 | +# |
| 5 | +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. |
| 6 | +# SPDX-License-Identifier: BSD-3-Clause-Clear |
| 7 | + |
| 8 | +# Dynamically locate and source init_env (robust for any repo structure) |
| 9 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 10 | +INIT_ENV="" |
| 11 | +SEARCH="$SCRIPT_DIR" |
| 12 | +while [ "$SEARCH" != "/" ]; do |
| 13 | + if [ -f "$SEARCH/init_env" ]; then |
| 14 | + INIT_ENV="$SEARCH/init_env" |
| 15 | + break |
| 16 | + fi |
| 17 | + SEARCH=$(dirname "$SEARCH") |
| 18 | +done |
| 19 | + |
| 20 | +if [ -z "$INIT_ENV" ]; then |
| 21 | + echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2 |
| 22 | + exit 1 |
| 23 | +fi |
| 24 | + |
| 25 | +# Only source if not already loaded (idempotent) |
| 26 | +if [ -z "$__INIT_ENV_LOADED" ]; then |
| 27 | + # shellcheck disable=SC1090 |
| 28 | + . "$INIT_ENV" |
| 29 | +fi |
| 30 | + |
| 31 | +# Always source functestlib.sh, using $TOOLS exported by init_env |
| 32 | +# shellcheck disable=SC1090 |
| 33 | +. "$TOOLS/functestlib.sh" |
| 34 | + |
| 35 | +TESTNAME="Kernel_Selftests" |
| 36 | +test_path=$(find_test_case_by_name "$TESTNAME") |
| 37 | +if [ -z "$test_path" ] || [ ! -d "$test_path" ]; then |
| 38 | + log_fail "$TESTNAME : Test directory not found." |
| 39 | + echo "FAIL $TESTNAME" > "./$TESTNAME.run" |
| 40 | + exit 1 |
| 41 | +fi |
| 42 | + |
| 43 | +cd "$test_path" || exit 1 |
| 44 | + |
| 45 | +res_file="./$TESTNAME.res" |
| 46 | +summary_file="./$TESTNAME.run" |
| 47 | +whitelist="./enabled_tests.list" |
| 48 | +selftest_dir="/kselftest" |
| 49 | +arch="$(uname -m)" |
| 50 | +skip_arch="x86 powerpc mips sparc" |
| 51 | + |
| 52 | +pass=0 |
| 53 | +fail=0 |
| 54 | +skip=0 |
| 55 | + |
| 56 | +rm -f "$res_file" "$summary_file" |
| 57 | +echo "SUITE: $TESTNAME" > "$res_file" |
| 58 | + |
| 59 | +log_info "Starting $TESTNAME..." |
| 60 | + |
| 61 | +check_dependencies "find" "/kselftest" |
| 62 | + |
| 63 | +if [ ! -f "$whitelist" ]; then |
| 64 | + log_fail "$TESTNAME: whitelist $whitelist not found" |
| 65 | + echo "FAIL $TESTNAME" > "$summary_file" |
| 66 | + exit 1 |
| 67 | +fi |
| 68 | + |
| 69 | +while IFS= read -r test || [ -n "$test" ]; do |
| 70 | + case "$test" in |
| 71 | + ''|\#*) continue ;; # Skip blanks and comments |
| 72 | + esac |
| 73 | + |
| 74 | + # If test is architecture-specific, skip if not supported |
| 75 | + for a in $skip_arch; do |
| 76 | + if [ "$test" = "$a" ]; then |
| 77 | + log_skip "$test skipped on $arch" |
| 78 | + echo "SKIP $test (unsupported arch)" >> "$res_file" |
| 79 | + skip=$((skip+1)) |
| 80 | + continue 2 |
| 81 | + fi |
| 82 | + done |
| 83 | + |
| 84 | + # Check for directory/binary (e.g., timers/thread_test) |
| 85 | + case "$test" in |
| 86 | + */*) |
| 87 | + test_dir="${test%%/*}" |
| 88 | + test_bin="${test#*/}" |
| 89 | + bin_path="$selftest_dir/$test_dir/$test_bin" |
| 90 | + if [ ! -d "$selftest_dir/$test_dir" ]; then |
| 91 | + log_skip "$test_dir not found" |
| 92 | + echo "SKIP $test (directory not found)" >> "$res_file" |
| 93 | + skip=$((skip+1)) |
| 94 | + continue |
| 95 | + fi |
| 96 | + if [ -x "$bin_path" ]; then |
| 97 | + log_info "Running $test_dir/$test_bin" |
| 98 | + if timeout 300 "$bin_path" > "${test_dir}_${test_bin}.log" 2>&1; then |
| 99 | + log_pass "$test: passed" |
| 100 | + echo "PASS $test" >> "$res_file" |
| 101 | + pass=$((pass+1)) |
| 102 | + else |
| 103 | + log_fail "$test: failed" |
| 104 | + echo "FAIL $test" >> "$res_file" |
| 105 | + fail=$((fail+1)) |
| 106 | + fi |
| 107 | + else |
| 108 | + log_skip "$test: not found or not executable" |
| 109 | + echo "SKIP $test (not found or not executable)" >> "$res_file" |
| 110 | + skip=$((skip+1)) |
| 111 | + fi |
| 112 | + continue |
| 113 | + ;; |
| 114 | + esac |
| 115 | + |
| 116 | + # Standard: just the directory (run run_test.sh or all *test bins) |
| 117 | + test_dir="$selftest_dir/$test" |
| 118 | + if [ ! -d "$test_dir" ]; then |
| 119 | + log_skip "$test not found" |
| 120 | + echo "SKIP $test (not found)" >> "$res_file" |
| 121 | + skip=$((skip+1)) |
| 122 | + continue |
| 123 | + fi |
| 124 | + |
| 125 | + if [ -x "$test_dir/run_test.sh" ]; then |
| 126 | + log_info "Running $test/run_test.sh" |
| 127 | + if timeout 300 "$test_dir/run_test.sh" > "$test.log" 2>&1; then |
| 128 | + log_pass "$test passed" |
| 129 | + echo "PASS $test" >> "$res_file" |
| 130 | + pass=$((pass+1)) |
| 131 | + else |
| 132 | + log_fail "$test failed" |
| 133 | + echo "FAIL $test" >> "$res_file" |
| 134 | + fail=$((fail+1)) |
| 135 | + fi |
| 136 | + else |
| 137 | + found_bin=0 |
| 138 | + for bin in "$test_dir"/*test; do |
| 139 | + [ -f "$bin" ] && [ -x "$bin" ] || continue |
| 140 | + found_bin=1 |
| 141 | + binname=$(basename "$bin") |
| 142 | + log_info "Running $test/$binname" |
| 143 | + if timeout 300 "$bin" > "${test}_${binname}.log" 2>&1; then |
| 144 | + log_pass "$test/$binname passed" |
| 145 | + echo "PASS $test/$binname" >> "$res_file" |
| 146 | + pass=$((pass+1)) |
| 147 | + else |
| 148 | + log_fail "$test/$binname failed" |
| 149 | + echo "FAIL $test/$binname" >> "$res_file" |
| 150 | + fail=$((fail+1)) |
| 151 | + fi |
| 152 | + done |
| 153 | + if [ "$found_bin" -eq 0 ]; then |
| 154 | + log_skip "$test: no test binaries" |
| 155 | + echo "SKIP $test (no test binaries)" >> "$res_file" |
| 156 | + skip=$((skip+1)) |
| 157 | + fi |
| 158 | + fi |
| 159 | +done < "$whitelist" |
| 160 | + |
| 161 | +echo "SUMMARY PASS=$pass FAIL=$fail SKIP=$skip" >> "$res_file" |
| 162 | + |
| 163 | +if [ "$fail" -eq 0 ] && [ "$pass" -gt 0 ]; then |
| 164 | + echo "PASS $TESTNAME" > "$summary_file" |
| 165 | + log_pass "$TESTNAME: all tests passed" |
| 166 | +else |
| 167 | + echo "FAIL $TESTNAME" > "$summary_file" |
| 168 | + log_fail "$TESTNAME: one or more tests failed" |
| 169 | +fi |
| 170 | + |
| 171 | +exit 0 |
0 commit comments