-
Notifications
You must be signed in to change notification settings - Fork 1
157 lines (134 loc) · 5.07 KB
/
test-scan.yml
File metadata and controls
157 lines (134 loc) · 5.07 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
152
153
154
155
156
157
name: Test Scan
on:
push:
branches: [main]
paths:
- 'src/bmlab_toolkit/scan_cli.py'
- 'src/bmlab_toolkit/jlink_programmer.py'
- 'src/bmlab_toolkit/programmer.py'
- 'src/bmlab_toolkit/constants.py'
- 'pyproject.toml'
- '.github/actions/setup-jlink-network/**'
- '.github/workflows/test-scan.yml'
pull_request:
paths:
- 'src/bmlab_toolkit/scan_cli.py'
- 'src/bmlab_toolkit/jlink_programmer.py'
- 'src/bmlab_toolkit/programmer.py'
- 'src/bmlab_toolkit/constants.py'
- 'pyproject.toml'
- '.github/actions/setup-jlink-network/**'
- '.github/workflows/test-scan.yml'
workflow_dispatch:
permissions:
contents: read
packages: read
env:
VNET_BASE: 192.168.3
VNET_MASK: 24
jobs:
test-scan:
runs-on: self-hosted
steps:
- name: Cleanup before start (containers)
if: always()
run: |
docker rm -f jlink100 jlink101 jlink102 2>/dev/null || true
docker network rm jlink-net 2>/dev/null || true
pkill -9 -f JLinkRemoteServer || true
sleep 2
- uses: actions/checkout@v5
- name: Build release distributions
run: |
python3 -m venv .venv
. .venv/bin/activate
pip install -e ".[dev]"
- name: Test 1 — bml scan (no arguments)
run: |
. .venv/bin/activate
bml scan | tee scan1.txt
count=$(grep -c "Target: *STM32F103RE" scan1.txt)
awk '/JLink Programmer/ {serial=""} /Serial:/ {serial=$2} /Target: *STM32F103RE/ && serial {print serial}' scan1.txt | sort | uniq > serials.txt
if [ "$count" -ne 3 ]; then
echo "Test 1 failed: expected 3 STM32F103RE, found $count"
cat scan1.txt
exit 1
fi
- name: Test 2 — bml scan -p jlink
run: |
. .venv/bin/activate
bml scan -p jlink | tee scan2.txt
diff scan1.txt scan2.txt
- name: Test 3 — Start JLinkRemoteServer and scan via network
run: |
. .venv/bin/activate
serial=$(head -n1 serials.txt)
nohup JLinkRemoteServer -select usb=$serial -device STM32F103RE -endian little -speed 4000 -if swd > /dev/null 2>&1 &
sleep 3
bml scan --network 127.0.0.1/32 | tee scan3.txt
grep -q "Target: *STM32F103RE" scan3.txt
grep -q "IP: *127.0.0.1" scan3.txt
pkill -9 -f JLinkRemoteServer || true
sleep 1
- name: Test 4 — bml scan --network 127.0.0.1/32 -p jlink
run: |
. .venv/bin/activate
serial=$(head -n1 serials.txt)
nohup JLinkRemoteServer -select usb=$serial -device STM32F103RE -endian little -speed 4000 -if swd > /dev/null 2>&1 &
sleep 3
bml scan --network 127.0.0.1/32 -p jlink | tee scan4.txt
diff scan3.txt scan4.txt
pkill -9 -f JLinkRemoteServer || true
sleep 1
- name: Test 5 — bml scan --network 127.0.0.2/32 (negative)
run: |
. .venv/bin/activate
! bml scan --network 127.0.0.2/32 | tee scan5.txt | grep -q "STM32F103RE"
grep -qi "No JLink Remote Servers found on the network." scan5.txt
- name: Setup JLink network containers
uses: ./.github/actions/setup-jlink-network
with:
serials-file: serials.txt
vnet-base: ${{ env.VNET_BASE }}
vnet-mask: ${{ env.VNET_MASK }}
- name: Test 6 — Multiple RemoteServers network scan
run: |
. .venv/bin/activate
bml scan --network $VNET_BASE.0/$VNET_MASK | tee scan6.txt
f103_count=$(grep -c "Target:.*STM32F103RE" scan6.txt || echo 0)
if [ "$f103_count" -ne 3 ]; then
echo "Expected 3 STM32F103RE devices, found $f103_count"
cat scan6.txt
exit 1
fi
for ip in 100 101 102; do
if ! grep -q "IP:.*$VNET_BASE\.$ip" scan6.txt; then
echo "No device found at $VNET_BASE.$ip"
cat scan6.txt
exit 1
fi
done
- name: Test 7 — Network scan with IP range filter
run: |
. .venv/bin/activate
bml scan --network $VNET_BASE.0/$VNET_MASK --start-ip 100 --end-ip 150 | tee scan7.txt
f103_count=$(grep -c "Target:.*STM32F103RE" scan7.txt || echo 0)
if [ "$f103_count" -ne 3 ]; then
echo "Expected 3 STM32F103RE devices, found $f103_count"
cat scan7.txt
exit 1
fi
for ip in 100 101 102; do
if ! grep -q "IP:.*$VNET_BASE\.$ip" scan7.txt; then
echo "No device found at $VNET_BASE.$ip"
cat scan7.txt
exit 1
fi
done
- name: Cleanup after tests (containers)
if: always()
run: |
docker rm -f jlink100 jlink101 jlink102 2>/dev/null || true
docker network rm jlink-net 2>/dev/null || true
pkill -9 -f JLinkRemoteServer || true
sleep 2