asterinas/test/syscall_test/run_syscall_test.sh

75 lines
1.9 KiB
Bash
Raw Normal View History

2023-05-29 05:29:53 +00:00
#!/bin/sh
# SPDX-License-Identifier: MPL-2.0
2023-05-29 05:29:53 +00:00
SCRIPT_DIR=$(dirname "$0")
2023-11-28 04:17:42 +00:00
TEST_TMP_DIR=${SYSCALL_TEST_DIR:-/tmp}
2023-05-29 05:29:53 +00:00
TEST_BIN_DIR=$SCRIPT_DIR/tests
BLOCKLIST_DIR=$SCRIPT_DIR/blocklists
FAIL_CASES=$SCRIPT_DIR/fail_cases
BLOCK=""
TESTS=0
PASSED_TESTS=0
RESULT=0
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
get_blocklist_subtests(){
if [ -f $BLOCKLIST_DIR/$1 ]; then
BLOCK=$(grep -v '^#' $BLOCKLIST_DIR/$1 | tr '\n' ':')
2023-05-29 05:29:53 +00:00
else
BLOCK=""
fi
2024-03-18 07:58:37 +00:00
for extra_dir in $EXTRA_BLOCKLISTS_DIRS ; do
if [ -f $SCRIPT_DIR/$extra_dir/$1 ]; then
BLOCK="${BLOCK}:$(grep -v '^#' $SCRIPT_DIR/$extra_dir/$1 | tr '\n' ':')"
2024-03-18 07:58:37 +00:00
fi
done
return 0
2023-05-29 05:29:53 +00:00
}
run_one_test(){
echo -e "Run Test Case: $1"
2023-11-28 04:17:42 +00:00
# The gvisor test framework utilizes the "TEST_TMPDIR" environment variable to dictate the directory's location.
export TEST_TMPDIR=$TEST_TMP_DIR
2023-05-29 05:29:53 +00:00
ret=0
if [ -f $TEST_BIN_DIR/$1 ]; then
get_blocklist_subtests $1
2024-01-03 03:29:28 +00:00
cd $TEST_BIN_DIR && ./$1 --gtest_filter=-$BLOCK
2023-05-29 05:29:53 +00:00
ret=$?
2024-03-18 07:58:37 +00:00
#After executing the test, it is necessary to clean the directory to ensure no residual data remains
rm -rf $TEST_TMP_DIR/*
2023-05-29 05:29:53 +00:00
else
echo -e "Warning: $1 test does not exit"
ret=1
fi
echo ""
return $ret
}
rm -f $FAIL_CASES && touch $FAIL_CASES
2024-03-18 07:58:37 +00:00
rm -rf $TEST_TMP_DIR/*
2023-05-29 05:29:53 +00:00
for syscall_test in $(find $TEST_BIN_DIR/. -name \*_test) ; do
test_name=$(basename "$syscall_test")
run_one_test $test_name
if [ $? -eq 0 ] && PASSED_TESTS=$((PASSED_TESTS+1));then
TESTS=$((TESTS+1))
else
echo -e "$test_name" >> $FAIL_CASES
TESTS=$((TESTS+1))
fi
done
echo -e "$GREEN$PASSED_TESTS$NC of $GREEN$TESTS$NC test cases passed."
2023-05-29 05:29:53 +00:00
[ $PASSED_TESTS -ne $TESTS ] && RESULT=1
if [ $TESTS != $PASSED_TESTS ]; then
echo -e "The $RED$(($TESTS-$PASSED_TESTS))$NC failed test cases are as follows:"
2023-05-29 05:29:53 +00:00
cat $FAIL_CASES
fi
2024-01-03 03:29:28 +00:00
exit $RESULT