Skip to content

Commit

Permalink
Merge branch 'master' into combine-deadline-and-level
Browse files Browse the repository at this point in the history
  • Loading branch information
erlingrj authored Mar 5, 2024
2 parents d60e037 + a06d639 commit 91b6dec
Showing 1 changed file with 45 additions and 94 deletions.
139 changes: 45 additions & 94 deletions .github/scripts/run-zephyr-tests.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
#!/bin/bash
timeout=300 # 5min timeout is hopefully enough
verbose=false

# Function to recursively find all folders containing the top-level CMakeLists.txt
overall_success=true
num_successes=0
num_failures=0
failed_tests=""

# Skip tests doing file IO and tracing
skip=("FileReader" "FilePkgReader" "Tracing" "ThreadedThreaded" "CountTest" "AsyncCallback")
# Skip
skip=("FileReader" "FilePkgReader")

find_kconfig_folders() {
if [ -f "$folder/CMakeLists.txt" ]; then
Expand All @@ -20,17 +12,15 @@ find_kconfig_folders() {
echo "Skipping: $test_name"
else
echo "Running: $test_name"
if run_qemu_zephyr_test "$folder"; then
echo "Test $test_name successful"
run_qemu_zephyr_test $folder
if [ "$?" -eq 0 ]; then
echo "Test passed"
let "num_successes+=1"
else
echo "Test $test_name failed"
let "num_failures+=1"
failed_tests+="$test_name, "
overall_success=false
echo "Test failed."
exit 1
fi
fi

return
fi
for folder in "$1"/*; do
Expand All @@ -40,88 +30,55 @@ find_kconfig_folders() {
done
}

run_native_zephyr_test() {
return_val=0
pushd $1/build

rm -f res.text

timeout 60s make run | tee res.txt
result=$?

if [ $result -eq 0 ]; then
echo "Command completed within the timeout."
return_val=0
else
echo "Command terminated or timed out."
echo "Test output:"
echo "----------------------------------------------------------------"
cat res.txt
echo "----------------------------------------------------------------"
return_val=1
fi

popd
return "$return_val"




}

# Run Zephyr test until either: Timeout or finds match in output
# https://www.unix.com/shell-programming-and-scripting/171401-kill-process-if-grep-match-found.html
# Run Zephyr test until either: Timeout or finds match in output using expect
# https://spin.atomicobject.com/monitoring-stdout-with-a-timeout/
run_qemu_zephyr_test() {
success=false
pushd $1/build

rm -f /tmp/procfifo
rm -f res.text
mkfifo /tmp/procfifo

make run | tee res.txt > /tmp/procfifo &
PID=$!
SECONDS=0
while IFS= read -t $timeout line
do
if [ "$verbose" = "true" ]; then echo $line; fi

if echo "$line" | grep -q 'FATAL ERROR';
res="_res.txt"
# Run test program in background and pipe results to a file.
make run > $res &
if [ $? -ne 0 ]; then
echo "ERROR: make run failed."
exit 1
fi
pid=$!
return_val=2
wait_count=0
timeout=60
# Parse the file and match on known outputs. With timeout.
while [ "$wait_count" -le "$timeout" ]; do
sleep 1
if grep --quiet 'FATAL ERROR' "$res"
then
echo "Matched on ERROR"
echo $line
success=false
pkill -P $$
cat $res
echo "-----------------------------------------------------------------------------------------------------------"
echo "ERROR: Found 'FATAL ERROR'"
return_val=1
break
fi

if echo "$line" | grep -q '^exit';
if grep --quiet '^exit' "$res"
then
echo "Matched on exit"
success=true
pkill -P $$
break
fi

if (($SECONDS > $timeout)) ; then
echo "Timeout without freeze"
success=false
cat $res
echo "-----------------------------------------------------------------------------------------------------------"
echo "SUCCESS: Found 'exit'"
return_val=0
break
fi
done < /tmp/procfifo

return_val=0
if [ "$success" = false ]; then
echo "General Timeout"
pkill -P $$
echo "Test output:"
echo "----------------------------------------------------------------"
cat res.txt
echo "----------------------------------------------------------------"
return_val=1
((wait_count++))
done
kill $pid
if [ $? -ne 0 ]; then
echo "ERROR: Could not kill qemu process"
exit 1
fi

rm -f /tmp/procfifo
if [ "$return_val" -eq 2 ]; then
cat $res
echo "-----------------------------------------------------------------------------------------------------------"
echo "ERROR: Timed out"
fi
popd
return "$return_val"
}
Expand All @@ -137,14 +94,8 @@ cd -

# Print report
echo "================================================================================================================"

if [ "$overall_success" = false ]; then
echo "Results: FAIL"
else
echo "Results: PASS"
fi
echo "Tests passed!"
echo "Number of passes: $num_successes"
echo "Number of fails: $num_failures"
echo "Skipped tests: ${skip[@]}"

if [ "$overall_success" = false ]; then
Expand Down

0 comments on commit 91b6dec

Please sign in to comment.