blob: 5c28fc037fa2ff2740ad20a1d79daec4e9b6e9b1 [file] [log] [blame]
#!/usr/bin/env bash
# Copyright 2021 The Android KVM Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -eufo pipefail
KSFT_TEST="$(sed -E 's/.*ksft=([^ ]*).*/\1/' /proc/cmdline)"
PASS() { echo -e "\e[32mPASS\e[0m ${KSFT_TEST} ${1-}"; }
SKIP() { echo -e "\e[33mSKIP\e[0m ${KSFT_TEST} ${1-}"; }
FAIL() { echo -e "\e[31mFAIL\e[0m ${KSFT_TEST} ${1-}"; }
KSFT_LOG=/tmp/output.log
KSFT_DIR=/mnt
MODULES_DIR=/lib/modules
RUN_KSFT=${KSFT_DIR}/run_kselftest.sh
mount -t 9p -o trans=virtio,version=9p2000.L kselftest "${KSFT_DIR}"
mount -t 9p -o trans=virtio,version=9p2000.L modules "${MODULES_DIR}"
# Run kselftests.
"${RUN_KSFT}" -t "${KSFT_TEST}" | tee "${KSFT_LOG}" || true
# Count test results for summary.
OK_TEST=$(egrep -c '^ok ' "${KSFT_LOG}" || test $? -eq 1)
SKIPPED=$(egrep -c '^ok .* # SKIP$' "${KSFT_LOG}" || test $? -eq 1)
PASSED=$(expr ${OK_TEST} - ${SKIPPED} || test $? -eq 1)
FAILED=$(egrep -c '^not ok ' "${KSFT_LOG}" || test $? -eq 1)
TOTAL=$(expr ${PASSED} + ${SKIPPED} + ${FAILED} || test $? -eq 1)
MSG="${TOTAL} tests"
if [ "${FAILED}" -ne 0 ]; then
MSG+=", ${FAILED} failed"
fi
if [ "${SKIPPED}" -ne 0 ]; then
MSG+=", ${SKIPPED} skipped"
fi
if [ "${TOTAL}" -eq 0 ]; then
FAIL "(no tests found)"
exit 1
elif [ "${FAILED}" -ne 0 ]; then
FAIL "(${MSG})"
exit 1
elif [ "${PASSED}" -eq 0 ]; then
SKIP "(${MSG})"
exit 0
else
PASS "(${MSG})"
exit 0
fi