-
Notifications
You must be signed in to change notification settings - Fork 146
151 lines (131 loc) · 4.81 KB
/
test-hooks-simulator.yml
File metadata and controls
151 lines (131 loc) · 4.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: hook simulator tests
on:
push:
branches: [ 'master', 'main', 'release/**' ]
pull_request:
branches: [ '*' ]
jobs:
hooks_test:
runs-on: ubuntu-latest
container:
image: ghcr.io/wolfssl/wolfboot-ci-sim:v1.0
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
include:
- mechanism: flash
config: sim.config
test_script: sim-sunnyday-update.sh
expected_preinit: 2
expected_postinit: 2
expected_boot: 2
expected_panic: 0
- mechanism: dualbank
config: sim-dualbank.config
test_script: sim-dualbank-swap-update.sh
expected_preinit: 3
expected_postinit: 3
expected_boot: 3
expected_panic: 0
- mechanism: panic
config: sim.config
test_script: ""
expected_preinit: 1
expected_postinit: 1
expected_boot: 0
expected_panic: 1
name: hooks (${{ matrix.mechanism }})
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Trust workspace
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Create test_hooks.c
run: |
cat > test_hooks.c << 'EOF'
#include <stdio.h>
#include "hooks.h"
#define HOOK_LOG_FILE "/tmp/wolfboot_hooks.log"
static void log_hook(const char *name)
{
FILE *f = fopen(HOOK_LOG_FILE, "a");
if (f) {
fprintf(f, "%s\n", name);
fclose(f);
}
}
void wolfBoot_hook_preinit(void) { log_hook("preinit"); }
void wolfBoot_hook_postinit(void) { log_hook("postinit"); }
void wolfBoot_hook_boot(struct wolfBoot_image *boot_img) { (void)boot_img; log_hook("boot"); }
void wolfBoot_hook_panic(void) { log_hook("panic"); }
EOF
- name: Select config
run: |
cp config/examples/${{ matrix.config }} .config
- name: Build tools
run: |
make -C tools/keytools && make -C tools/bin-assemble
- name: Build wolfboot.elf with hooks
run: |
make clean && make test-sim-internal-flash-with-update \
WOLFBOOT_HOOKS_FILE=test_hooks.c \
WOLFBOOT_HOOK_LOADER_PREINIT=1 \
WOLFBOOT_HOOK_LOADER_POSTINIT=1 \
WOLFBOOT_HOOK_BOOT=1 \
WOLFBOOT_HOOK_PANIC=1
- name: Clear hook log
run: |
rm -f /tmp/wolfboot_hooks.log
- name: Corrupt partitions and run panic test
if: matrix.mechanism == 'panic'
run: |
# Zero out boot partition header (offset 0x80000) to invalidate image
printf '\x00\x00\x00\x00\x00\x00\x00\x00' | \
dd of=internal_flash.dd bs=1 seek=$((0x80000)) conv=notrunc
# Zero out update partition header (offset 0x100000) to invalidate image
printf '\x00\x00\x00\x00\x00\x00\x00\x00' | \
dd of=internal_flash.dd bs=1 seek=$((0x100000)) conv=notrunc
# wolfBoot_panic() calls exit('P') = exit(80) on ARCH_SIM
./wolfboot.elf get_version 2>&1 || EXIT_CODE=$?
echo "wolfboot.elf exited with code ${EXIT_CODE:-0}"
if [ "${EXIT_CODE:-0}" -ne 80 ]; then
echo "FAIL: expected exit code 80 (panic), got ${EXIT_CODE:-0}"
exit 1
fi
echo "OK: wolfboot panicked as expected"
- name: Run ${{ matrix.mechanism }} update test
if: matrix.mechanism != 'panic'
run: |
tools/scripts/${{ matrix.test_script }}
- name: Display hook log
if: always()
run: |
echo "=== Hook log contents ==="
cat /tmp/wolfboot_hooks.log || echo "(no log file found)"
- name: Verify hook call counts
run: |
LOG="/tmp/wolfboot_hooks.log"
PASS=true
check_count() {
local hook_name="$1"
local expected="$2"
local actual
actual=$(grep -c "^${hook_name}$" "$LOG" 2>/dev/null || echo 0)
if [ "$actual" -ne "$expected" ]; then
echo "FAIL: ${hook_name} expected=${expected} actual=${actual}"
PASS=false
else
echo "OK: ${hook_name} expected=${expected} actual=${actual}"
fi
}
check_count "preinit" ${{ matrix.expected_preinit }}
check_count "postinit" ${{ matrix.expected_postinit }}
check_count "boot" ${{ matrix.expected_boot }}
check_count "panic" ${{ matrix.expected_panic }}
if [ "$PASS" != "true" ]; then
echo "Hook verification FAILED"
exit 1
fi
echo "All hook counts verified successfully"