|
| 1 | +name: hook simulator tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ 'master', 'main', 'release/**' ] |
| 6 | + pull_request: |
| 7 | + branches: [ '*' ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + hooks_test: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + timeout-minutes: 30 |
| 13 | + strategy: |
| 14 | + fail-fast: false |
| 15 | + matrix: |
| 16 | + include: |
| 17 | + - mechanism: flash |
| 18 | + config: sim.config |
| 19 | + test_script: sim-sunnyday-update.sh |
| 20 | + expected_preinit: 2 |
| 21 | + expected_postinit: 2 |
| 22 | + expected_boot: 2 |
| 23 | + expected_panic: 0 |
| 24 | + - mechanism: dualbank |
| 25 | + config: sim-dualbank.config |
| 26 | + test_script: sim-dualbank-swap-update.sh |
| 27 | + expected_preinit: 3 |
| 28 | + expected_postinit: 3 |
| 29 | + expected_boot: 3 |
| 30 | + expected_panic: 0 |
| 31 | + - mechanism: panic |
| 32 | + config: sim.config |
| 33 | + test_script: "" |
| 34 | + expected_preinit: 1 |
| 35 | + expected_postinit: 1 |
| 36 | + expected_boot: 0 |
| 37 | + expected_panic: 1 |
| 38 | + |
| 39 | + name: hooks (${{ matrix.mechanism }}) |
| 40 | + |
| 41 | + steps: |
| 42 | + - uses: actions/checkout@v4 |
| 43 | + with: |
| 44 | + submodules: true |
| 45 | + |
| 46 | + - name: Workaround for sources.list |
| 47 | + run: | |
| 48 | + set -euxo pipefail |
| 49 | +
|
| 50 | + apt-cache policy |
| 51 | + grep -RInE '^(deb|Types|URIs)' /etc/apt || true |
| 52 | +
|
| 53 | + shopt -s nullglob |
| 54 | +
|
| 55 | + echo "Replace sources.list (legacy)" |
| 56 | + sudo sed -i \ |
| 57 | + -e "s|https\?://azure\.archive\.ubuntu\.com/ubuntu/?|http://mirror.arizona.edu/ubuntu/|g" \ |
| 58 | + /etc/apt/sources.list || true |
| 59 | +
|
| 60 | + echo "Replace sources.list.d/*.list (legacy)" |
| 61 | + for f in /etc/apt/sources.list.d/*.list; do |
| 62 | + sudo sed -i \ |
| 63 | + -e "s|https\?://azure\.archive\.ubuntu\.com/ubuntu/?|http://mirror.arizona.edu/ubuntu/|g" \ |
| 64 | + "$f" |
| 65 | + done |
| 66 | +
|
| 67 | + echo "Replace sources.list.d/*.sources (deb822)" |
| 68 | + for f in /etc/apt/sources.list.d/*.sources; do |
| 69 | + sudo sed -i \ |
| 70 | + -e "s|https\?://azure\.archive\.ubuntu\.com/ubuntu/?|http://mirror.arizona.edu/ubuntu/|g" \ |
| 71 | + -e "s|https\?://azure\.archive\.ubuntu\.com|http://mirror.arizona.edu|g" \ |
| 72 | + "$f" |
| 73 | + done |
| 74 | +
|
| 75 | + echo "Fix /etc/apt/apt-mirrors.txt (used by URIs: mirror+file:...)" |
| 76 | + if grep -qE '^[[:space:]]*https?://azure\.archive\.ubuntu\.com/ubuntu/?' /etc/apt/apt-mirrors.txt; then |
| 77 | + sudo sed -i 's|https\?://azure\.archive\.ubuntu\.com/ubuntu/|http://mirror.arizona.edu/ubuntu/|g' /etc/apt/apt-mirrors.txt |
| 78 | + fi |
| 79 | +
|
| 80 | + grep -RIn "azure.archive.ubuntu.com" /etc/apt || true |
| 81 | + grep -RInE '^(deb|Types|URIs)' /etc/apt || true |
| 82 | + echo "--- apt-mirrors.txt ---" |
| 83 | + cat /etc/apt/apt-mirrors.txt || true |
| 84 | +
|
| 85 | + - name: Update repository |
| 86 | + run: sudo apt-get update -o Acquire::Retries=3 |
| 87 | + |
| 88 | + - name: Create test_hooks.c |
| 89 | + run: | |
| 90 | + cat > test_hooks.c << 'EOF' |
| 91 | + #include <stdio.h> |
| 92 | + #include "hooks.h" |
| 93 | +
|
| 94 | + #define HOOK_LOG_FILE "/tmp/wolfboot_hooks.log" |
| 95 | +
|
| 96 | + static void log_hook(const char *name) |
| 97 | + { |
| 98 | + FILE *f = fopen(HOOK_LOG_FILE, "a"); |
| 99 | + if (f) { |
| 100 | + fprintf(f, "%s\n", name); |
| 101 | + fclose(f); |
| 102 | + } |
| 103 | + } |
| 104 | +
|
| 105 | + void wolfBoot_hook_preinit(void) { log_hook("preinit"); } |
| 106 | + void wolfBoot_hook_postinit(void) { log_hook("postinit"); } |
| 107 | + void wolfBoot_hook_boot(struct wolfBoot_image *boot_img) { (void)boot_img; log_hook("boot"); } |
| 108 | + void wolfBoot_hook_panic(void) { log_hook("panic"); } |
| 109 | + EOF |
| 110 | +
|
| 111 | + - name: Select config |
| 112 | + run: | |
| 113 | + cp config/examples/${{ matrix.config }} .config |
| 114 | +
|
| 115 | + - name: Build tools |
| 116 | + run: | |
| 117 | + make -C tools/keytools && make -C tools/bin-assemble |
| 118 | +
|
| 119 | + - name: Build wolfboot.elf with hooks |
| 120 | + run: | |
| 121 | + make clean && make test-sim-internal-flash-with-update \ |
| 122 | + WOLFBOOT_HOOKS_FILE=test_hooks.c \ |
| 123 | + WOLFBOOT_HOOK_LOADER_PREINIT=1 \ |
| 124 | + WOLFBOOT_HOOK_LOADER_POSTINIT=1 \ |
| 125 | + WOLFBOOT_HOOK_BOOT=1 \ |
| 126 | + WOLFBOOT_HOOK_PANIC=1 |
| 127 | +
|
| 128 | + - name: Clear hook log |
| 129 | + run: | |
| 130 | + rm -f /tmp/wolfboot_hooks.log |
| 131 | +
|
| 132 | + - name: Corrupt partitions and run panic test |
| 133 | + if: matrix.mechanism == 'panic' |
| 134 | + run: | |
| 135 | + # Zero out boot partition header (offset 0x80000) to invalidate image |
| 136 | + printf '\x00\x00\x00\x00\x00\x00\x00\x00' | \ |
| 137 | + dd of=internal_flash.dd bs=1 seek=$((0x80000)) conv=notrunc |
| 138 | + # Zero out update partition header (offset 0x100000) to invalidate image |
| 139 | + printf '\x00\x00\x00\x00\x00\x00\x00\x00' | \ |
| 140 | + dd of=internal_flash.dd bs=1 seek=$((0x100000)) conv=notrunc |
| 141 | + # wolfBoot_panic() calls exit('P') = exit(80) on ARCH_SIM |
| 142 | + ./wolfboot.elf get_version 2>&1 || EXIT_CODE=$? |
| 143 | + echo "wolfboot.elf exited with code ${EXIT_CODE:-0}" |
| 144 | + if [ "${EXIT_CODE:-0}" -ne 80 ]; then |
| 145 | + echo "FAIL: expected exit code 80 (panic), got ${EXIT_CODE:-0}" |
| 146 | + exit 1 |
| 147 | + fi |
| 148 | + echo "OK: wolfboot panicked as expected" |
| 149 | +
|
| 150 | + - name: Run ${{ matrix.mechanism }} update test |
| 151 | + if: matrix.mechanism != 'panic' |
| 152 | + run: | |
| 153 | + tools/scripts/${{ matrix.test_script }} |
| 154 | +
|
| 155 | + - name: Display hook log |
| 156 | + if: always() |
| 157 | + run: | |
| 158 | + echo "=== Hook log contents ===" |
| 159 | + cat /tmp/wolfboot_hooks.log || echo "(no log file found)" |
| 160 | +
|
| 161 | + - name: Verify hook call counts |
| 162 | + run: | |
| 163 | + LOG="/tmp/wolfboot_hooks.log" |
| 164 | + PASS=true |
| 165 | +
|
| 166 | + check_count() { |
| 167 | + local hook_name="$1" |
| 168 | + local expected="$2" |
| 169 | + local actual |
| 170 | + actual=$(grep -c "^${hook_name}$" "$LOG" 2>/dev/null || echo 0) |
| 171 | + if [ "$actual" -ne "$expected" ]; then |
| 172 | + echo "FAIL: ${hook_name} expected=${expected} actual=${actual}" |
| 173 | + PASS=false |
| 174 | + else |
| 175 | + echo "OK: ${hook_name} expected=${expected} actual=${actual}" |
| 176 | + fi |
| 177 | + } |
| 178 | +
|
| 179 | + check_count "preinit" ${{ matrix.expected_preinit }} |
| 180 | + check_count "postinit" ${{ matrix.expected_postinit }} |
| 181 | + check_count "boot" ${{ matrix.expected_boot }} |
| 182 | + check_count "panic" ${{ matrix.expected_panic }} |
| 183 | +
|
| 184 | + if [ "$PASS" != "true" ]; then |
| 185 | + echo "Hook verification FAILED" |
| 186 | + exit 1 |
| 187 | + fi |
| 188 | + echo "All hook counts verified successfully" |
0 commit comments