Skip to content

Instantly share code, notes, and snippets.

@kartben
Created February 11, 2025 10:32
Show Gist options
  • Save kartben/b8b3b18c77754f0364c85036503a6b6e to your computer and use it in GitHub Desktop.
Save kartben/b8b3b18c77754f0364c85036503a6b6e to your computer and use it in GitHub Desktop.
#!/bin/bash
# Configuration
#GOOD_COMMIT="v4.0.0"
GOOD_COMMIT="v4.0.0"
# Tests to exclude (space-separated list of test names)
# Example: EXCLUDED_TESTS="drivers.adc kernel.common"
EXCLUDED_TESTS=""
# Platforms to exclude (space-separated list of platform names)
# Example: EXCLUDED_PLATFORMS="qemu_x86 frdm_k64f"
EXCLUDED_PLATFORMS=""
# Store the original script in a variable to detect failing tests
get_failing_tests() {
awk '
/<h4>/ {suite=$0; sub(/^ *<h4>/, "", suite); sub(/<\/h4>$/, "", suite)}
/Outcome:<\/th><td>Failed/ {getline; getline; print suite}
' "/Users/kartben/Downloads/junit.html" | sed -E 's/<[^>]+>//g' | sort -h | awk -F ':' '{print "west twister -p " $1 " -s " $2}' | \
while read -r line; do
platform=$(echo "$line" | awk '{print $4}')
test=$(echo "$line" | awk '{print $6}')
# Check if platform is in excluded list
skip_platform=0
for excluded in $EXCLUDED_PLATFORMS; do
if [[ "$platform" == *"$excluded"* ]]; then
skip_platform=1
break
fi
done
[ $skip_platform -eq 1 ] && continue
# Check if test is in excluded list
skip_test=0
for excluded in $EXCLUDED_TESTS; do
if [[ "$test" == "$excluded"* ]]; then
skip_test=1
break
fi
done
[ $skip_test -eq 1 ] && continue
echo "$line"
done
}
# Get all failing tests. They will be in the format:
# west twister -p adafruit_trinket_m0/samd21e18a -s drivers.adc
# west twister -p another_board -s drivers.adc
# ...
failing_tests=$(get_failing_tests)
# Print the number of failing tests (count the number of lines)
printf "Analyzing %d failing tests\n" $(echo "$failing_tests" | wc -l)
# Save the current commit
original_commit=$(git rev-parse HEAD)
# Get total number of tests
total_tests=$(echo "$failing_tests" | wc -l)
current_test=0
while IFS= read -r test_cmd; do
current_test=$((current_test + 1))
printf "[%d/%d] Bisecting: %s\n" "$current_test" "$total_tests" "$test_cmd"
git bisect start >/dev/null 2>&1
git bisect bad >/dev/null 2>&1
git bisect good "$GOOD_COMMIT" >/dev/null 2>&1
if git bisect run bash -c "west update >/dev/null 2>&1 && $test_cmd >/dev/null 2>&1"; then
if git bisect log | grep -q "^# first bad commit"; then
git bisect log | grep "^# first bad commit" -A 1
else
echo "No regression found (test fails in $GOOD_COMMIT too)"
fi
else
echo "Bisect aborted (test may be flaky or build failed)"
fi
git bisect reset >/dev/null 2>&1
git checkout "$original_commit" >/dev/null 2>&1
echo
echo
echo
done <<< "$failing_tests"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment