Skip to content

Instantly share code, notes, and snippets.

@Phineas1500
Last active July 16, 2025 16:38
Show Gist options
  • Save Phineas1500/38b84002907cc684dd3a8cb0433763e2 to your computer and use it in GitHub Desktop.
Save Phineas1500/38b84002907cc684dd3a8cb0433763e2 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Commit Test Runner
# Tests the last 65 commits to track 32-bit functionality over time
OUTPUT_FILE="commit_test_results.log"
TEST_SCRIPT_URL="$1"
TOTAL_COMMITS=65
# Check if gist URL was provided
if [ -z "$TEST_SCRIPT_URL" ]; then
echo "Usage: $0 <test_script_gist_url>"
echo "Example: $0 https://gist.githubusercontent.com/username/gist-id/raw/hash/test_32bit.sh"
exit 1
fi
echo "========================================="
echo "Commit Test Runner"
echo "Testing last $TOTAL_COMMITS commits"
echo "Test script URL: $TEST_SCRIPT_URL"
echo "========================================="
# Save current branch/commit
ORIGINAL_HEAD=$(git rev-parse HEAD)
ORIGINAL_BRANCH=$(git branch --show-current)
# Clear output file
> "$OUTPUT_FILE"
# Get list of last 65 commit hashes
echo "Getting commit list..."
COMMITS=($(git log --oneline -n $TOTAL_COMMITS --format="%H"))
echo "Found ${#COMMITS[@]} commits to test"
echo "Results will be saved to: $OUTPUT_FILE"
echo ""
# Function to extract summary sections from test output
extract_summary() {
local temp_file="$1"
# Extract from "TEST RESULTS SUMMARY" to the end
sed -n '/^=========================================/,/^=========================================$/{
/^TEST RESULTS SUMMARY$/,/^=========================================$/{
p
}
}' "$temp_file"
}
# Function to run test on a specific commit
test_commit() {
local commit_hash="$1"
local commit_number="$2"
echo "[$commit_number/$TOTAL_COMMITS] Testing commit: $commit_hash"
# Get commit info
local commit_info=$(git log --oneline -n 1 "$commit_hash")
local commit_date=$(git show -s --format=%ci "$commit_hash")
echo "==========================================" >> "$OUTPUT_FILE"
echo "COMMIT $commit_number/$TOTAL_COMMITS: $commit_info" >> "$OUTPUT_FILE"
echo "Date: $commit_date" >> "$OUTPUT_FILE"
echo "Hash: $commit_hash" >> "$OUTPUT_FILE"
echo "==========================================" >> "$OUTPUT_FILE"
# Checkout commit
git checkout "$commit_hash" --quiet 2>/dev/null
if [ $? -ne 0 ]; then
echo "❌ Failed to checkout commit $commit_hash" >> "$OUTPUT_FILE"
echo "❌ Failed to checkout commit $commit_hash"
echo "" >> "$OUTPUT_FILE"
return 1
fi
# Check for alpine filesystem before running tests
if [ ! -d "alpine-32bit-processed" ]; then
echo "⚠️ alpine-32bit-processed directory not found - tests may fail" >> "$OUTPUT_FILE"
echo "⚠️ alpine-32bit-processed directory not found"
fi
# Download test script from gist
echo " Downloading test script..."
local temp_script=$(mktemp)
curl -s "$TEST_SCRIPT_URL" > "$temp_script"
if [ $? -ne 0 ] || [ ! -s "$temp_script" ]; then
echo "❌ Failed to download test script from gist" >> "$OUTPUT_FILE"
echo "❌ Failed to download test script from gist"
echo "" >> "$OUTPUT_FILE"
rm -f "$temp_script"
return 1
fi
# Make script executable
chmod +x "$temp_script"
# Run test script and capture output
local temp_output=$(mktemp)
echo " Running tests..."
# Set LC_ALL to handle encoding issues
export LC_ALL=C
timeout 600 bash "$temp_script" > "$temp_output" 2>&1
local test_exit_code=$?
if [ $test_exit_code -eq 124 ]; then
echo "⏱️ Test timed out after 10 minutes" >> "$OUTPUT_FILE"
echo "⏱️ Test timed out after 10 minutes"
echo "" >> "$OUTPUT_FILE"
rm -f "$temp_output" "$temp_script"
return 1
elif [ $test_exit_code -ne 0 ]; then
echo "❌ Test script failed with exit code: $test_exit_code" >> "$OUTPUT_FILE"
echo "❌ Test script failed with exit code: $test_exit_code"
# Still try to extract any summary that might have been generated
fi
# Extract and save summary sections - more robust approach
local summary_found=false
# Try to find the summary section with grep and awk (more robust than sed)
if grep -n "TEST RESULTS SUMMARY" "$temp_output" >/dev/null 2>&1; then
summary_found=true
# Get line number of "TEST RESULTS SUMMARY"
local start_line=$(grep -n "TEST RESULTS SUMMARY" "$temp_output" | head -1 | cut -d: -f1)
if [ -n "$start_line" ]; then
# Extract from that line to end of file
tail -n +$start_line "$temp_output" >> "$OUTPUT_FILE" 2>/dev/null || {
echo "⚠️ Error extracting summary (encoding issue)" >> "$OUTPUT_FILE"
# Try alternative extraction method
grep -A 50 "TEST RESULTS SUMMARY" "$temp_output" 2>/dev/null >> "$OUTPUT_FILE" || {
echo "⚠️ Could not extract summary due to encoding issues" >> "$OUTPUT_FILE"
}
}
fi
fi
if [ "$summary_found" = false ]; then
echo "⚠️ No test summary found in output" >> "$OUTPUT_FILE"
echo "⚠️ No test summary found in output"
# Check if build failed
if grep -q "ninja: error" "$temp_output" 2>/dev/null; then
echo "❌ Build failed - ninja error detected" >> "$OUTPUT_FILE"
elif grep -q "meson.build not found" "$temp_output" 2>/dev/null; then
echo "❌ Build system not found - meson.build missing" >> "$OUTPUT_FILE"
elif grep -q "No such file or directory" "$temp_output" 2>/dev/null; then
echo "❌ Missing files or directories" >> "$OUTPUT_FILE"
else
echo "Debug info - Last 15 lines of output:" >> "$OUTPUT_FILE"
tail -n 15 "$temp_output" 2>/dev/null >> "$OUTPUT_FILE" || {
echo "Could not extract debug info due to encoding issues" >> "$OUTPUT_FILE"
}
fi
fi
echo "" >> "$OUTPUT_FILE"
rm -f "$temp_output" "$temp_script"
# Brief progress indicator
if [ "$summary_found" = true ]; then
local passed_count=$(grep -c "PASSED" "$OUTPUT_FILE" | tail -1)
local failed_count=$(grep -c "FAILED" "$OUTPUT_FILE" | tail -1)
echo " Results: Some tests completed"
fi
}
# Main test loop
echo "Starting tests..."
echo "Progress will be shown here, full results in $OUTPUT_FILE"
echo ""
for i in "${!COMMITS[@]}"; do
commit_number=$((i + 1))
test_commit "${COMMITS[$i]}" "$commit_number"
# Show progress every 5 commits and provide more details
if [ $((commit_number % 5)) -eq 0 ]; then
local passed_summary=$(grep -c "✅.*PASSED" "$OUTPUT_FILE" 2>/dev/null || echo "0")
local failed_summary=$(grep -c "❌.*FAILED" "$OUTPUT_FILE" 2>/dev/null || echo "0")
echo "Progress: $commit_number/$TOTAL_COMMITS commits tested (Recent results: ~$passed_summary passed, ~$failed_summary failed)"
fi
done
# Return to original state
echo ""
echo "Testing complete. Returning to original state..."
if [ -n "$ORIGINAL_BRANCH" ]; then
git checkout "$ORIGINAL_BRANCH" --quiet
else
git checkout "$ORIGINAL_HEAD" --quiet
fi
echo ""
echo "========================================="
echo "TESTING COMPLETE"
echo "========================================="
echo "Results saved to: $OUTPUT_FILE"
echo "Total commits tested: $TOTAL_COMMITS"
echo "Test script used: $TEST_SCRIPT_URL"
echo ""
echo "To view results:"
echo " cat $OUTPUT_FILE"
echo ""
echo "To search for specific patterns:"
echo " grep -A5 -B5 'Passed: 6' $OUTPUT_FILE # Find commits with all tests passing"
echo " grep -A5 -B5 'Failed: 0' $OUTPUT_FILE # Find commits with no failures"
echo " grep -A2 'COMMIT.*:' $OUTPUT_FILE # Show commit info and dates"
echo " grep -B2 -A2 'Build failed' $OUTPUT_FILE # Find build failures"
echo " grep -B2 -A2 'timed out' $OUTPUT_FILE # Find timeouts"
echo " grep -B2 -A2 'encoding' $OUTPUT_FILE # Find encoding issues"
echo ""
echo "To analyze the progression:"
echo " grep -A1 'OVERALL SUMMARY' $OUTPUT_FILE | grep -E '(Passed|Failed):' | head -20"
echo ""
echo "Returned to original state: $ORIGINAL_HEAD"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment