|
| 1 | +name: Headless Backend Tests |
| 2 | + |
| 3 | +on: [push, pull_request] |
| 4 | + |
| 5 | +jobs: |
| 6 | + headless-test: |
| 7 | + runs-on: ubuntu-24.04 |
| 8 | + |
| 9 | + steps: |
| 10 | + - uses: actions/checkout@v4 |
| 11 | + with: |
| 12 | + submodules: recursive |
| 13 | + |
| 14 | + - name: Install dependencies |
| 15 | + run: | |
| 16 | + sudo apt-get update |
| 17 | + sudo apt-get install -y valgrind imagemagick python3 |
| 18 | +
|
| 19 | + - name: Configure build |
| 20 | + run: | |
| 21 | + make defconfig |
| 22 | + python3 tools/kconfig/setconfig.py --kconfig configs/Kconfig \ |
| 23 | + BACKEND_HEADLESS=y \ |
| 24 | + TOOLS=y \ |
| 25 | + TOOL_HEADLESS_CTL=y \ |
| 26 | + DEMO_MULTI=y |
| 27 | +
|
| 28 | + - name: Build with headless backend |
| 29 | + run: | |
| 30 | + make -j$(nproc) |
| 31 | +
|
| 32 | + - name: Verify build outputs |
| 33 | + run: | |
| 34 | + test -x ./demo-headless || (echo "demo-headless not built" && exit 1) |
| 35 | + test -x ./headless-ctl || (echo "headless-ctl not built" && exit 1) |
| 36 | + echo "Build outputs verified successfully" |
| 37 | +
|
| 38 | + - name: Run basic headless test |
| 39 | + run: | |
| 40 | + # Start demo in background |
| 41 | + timeout 30s ./demo-headless & |
| 42 | + DEMO_PID=$! |
| 43 | + echo "Started demo-headless with PID $DEMO_PID" |
| 44 | +
|
| 45 | + # Wait for backend to initialize |
| 46 | + sleep 3 |
| 47 | +
|
| 48 | + # Test control tool commands |
| 49 | + ./headless-ctl status |
| 50 | + ./headless-ctl shot test_output.png |
| 51 | +
|
| 52 | + # Inject mouse events |
| 53 | + ./headless-ctl mouse move 100 100 |
| 54 | + ./headless-ctl mouse down 100 100 1 |
| 55 | + ./headless-ctl mouse up 100 100 1 |
| 56 | +
|
| 57 | + # Check status again after events |
| 58 | + ./headless-ctl status |
| 59 | +
|
| 60 | + # Shutdown gracefully |
| 61 | + ./headless-ctl shutdown || true |
| 62 | +
|
| 63 | + # Wait for process to exit |
| 64 | + wait $DEMO_PID || true |
| 65 | + echo "Basic test completed" |
| 66 | +
|
| 67 | + - name: Verify screenshot output |
| 68 | + run: | |
| 69 | + test -f test_output.png || (echo "Screenshot not created" && exit 1) |
| 70 | + file test_output.png | grep -q PNG || (echo "Screenshot is not a valid PNG" && exit 1) |
| 71 | + echo "Screenshot verification passed" |
| 72 | +
|
| 73 | + - name: Test deterministic rendering |
| 74 | + run: | |
| 75 | + # Run twice and compare outputs for determinism |
| 76 | + echo "First run..." |
| 77 | + timeout 10s ./demo-headless & |
| 78 | + PID1=$! |
| 79 | + sleep 3 |
| 80 | + ./headless-ctl shot run1.png |
| 81 | + ./headless-ctl shutdown |
| 82 | + wait $PID1 || true |
| 83 | +
|
| 84 | + echo "Second run..." |
| 85 | + timeout 10s ./demo-headless & |
| 86 | + PID2=$! |
| 87 | + sleep 3 |
| 88 | + ./headless-ctl shot run2.png |
| 89 | + ./headless-ctl shutdown |
| 90 | + wait $PID2 || true |
| 91 | +
|
| 92 | + # Compare images (allowing minor differences) |
| 93 | + DIFF=$(compare -metric AE run1.png run2.png null: 2>&1 || echo "0") |
| 94 | + echo "Pixel difference: $DIFF" |
| 95 | +
|
| 96 | + if [ "$DIFF" -gt "100" ]; then |
| 97 | + echo "ERROR: Renderings differ by more than 100 pixels" |
| 98 | + exit 1 |
| 99 | + fi |
| 100 | + echo "Deterministic rendering test passed" |
| 101 | +
|
| 102 | + - name: Memory leak detection with Valgrind |
| 103 | + run: | |
| 104 | + # Run with Valgrind for leak detection |
| 105 | + timeout 15s valgrind \ |
| 106 | + --leak-check=full \ |
| 107 | + --show-leak-kinds=definite,possible \ |
| 108 | + --errors-for-leak-kinds=definite \ |
| 109 | + --error-exitcode=1 \ |
| 110 | + --log-file=valgrind.log \ |
| 111 | + ./demo-headless & |
| 112 | + VALGRIND_PID=$! |
| 113 | +
|
| 114 | + sleep 5 |
| 115 | +
|
| 116 | + # Perform some operations |
| 117 | + ./headless-ctl mouse move 50 50 || true |
| 118 | + ./headless-ctl shot valgrind_screenshot.png || true |
| 119 | + ./headless-ctl shutdown || true |
| 120 | +
|
| 121 | + # Wait for Valgrind to finish |
| 122 | + wait $VALGRIND_PID || VALGRIND_EXIT=$? |
| 123 | +
|
| 124 | + # Display Valgrind summary |
| 125 | + echo "=== Valgrind Summary ===" |
| 126 | + grep -A 10 "LEAK SUMMARY" valgrind.log || true |
| 127 | + grep "ERROR SUMMARY" valgrind.log || true |
| 128 | +
|
| 129 | + # Check for definite leaks |
| 130 | + if grep -q "definitely lost: [1-9]" valgrind.log; then |
| 131 | + echo "ERROR: Memory leaks detected" |
| 132 | + cat valgrind.log |
| 133 | + exit 1 |
| 134 | + fi |
| 135 | + echo "No definite memory leaks detected" |
0 commit comments