-
-
Notifications
You must be signed in to change notification settings - Fork 40
373 lines (335 loc) · 12.1 KB
/
integration-test.yml
File metadata and controls
373 lines (335 loc) · 12.1 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
name: Integration Tests
on:
push:
branches:
- main
- 'feature/**'
workflow_dispatch:
permissions:
contents: read
checks: write
pull-requests: write
jobs:
unity-tests:
name: Unity C Tests (Layer 1 + Layer 2)
runs-on: ubuntu-latest
container: debian:sid-slim
timeout-minutes: 10
steps:
- name: Install C build dependencies
run: |
apt-get update
apt-get install -y \
git \
build-essential \
cmake \
pkg-config \
libavcodec-dev \
libavformat-dev \
libavutil-dev \
libswscale-dev \
libsqlite3-dev \
libuv1-dev \
libllhttp-dev \
libcurl4-openssl-dev \
libcjson-dev \
libmbedtls-dev \
lcov \
curl \
gpg
- name: Checkout
uses: actions/checkout@v5
with:
submodules: false
- name: Build Unity tests
run: |
mkdir -p build
cd build
cmake .. \
-DCMAKE_BUILD_TYPE=Debug \
-DBUILD_TESTS=ON \
-DENABLE_SOD=OFF \
-DENABLE_GO2RTC=OFF \
-DENABLE_MQTT=OFF \
-DCMAKE_C_FLAGS="--coverage" \
-DCMAKE_EXE_LINKER_FLAGS="--coverage"
make -j$(nproc) \
test_storage_pressure \
test_storage_pressure_extended \
test_detection_result_structures \
test_storage_retention_sqlite \
test_config \
test_logger \
test_strings \
test_memory \
test_request_response \
test_shutdown_coordinator \
test_detection_config \
test_detection_model_motion \
test_db_streams \
test_db_recordings_extended \
test_db_detections \
test_db_zones \
test_db_events \
test_db_auth \
test_db_transactions \
test_db_maintenance \
test_db_query_builder \
test_logger_json \
test_batch_delete_progress \
test_db_motion_config \
test_db_recordings_sync \
test_httpd_utils \
test_zone_filter \
test_onvif_soap_fault \
test_stream_manager \
test_stream_state \
test_packet_buffer \
test_timestamp_manager
echo "Unity test binaries built:"
ls -la bin/test_*
- name: Run Unity tests
run: |
cd build
ctest --output-on-failure -V \
-R "test_storage_pressure$|test_storage_pressure_extended|test_detection_result_structures|test_storage_retention_sqlite|test_config|test_logger|test_strings|test_memory|test_request_response|test_shutdown_coordinator|test_detection_config|test_detection_model_motion|test_db_streams|test_db_recordings_extended|test_db_detections|test_db_zones|test_db_events|test_db_auth|test_db_transactions|test_db_maintenance|test_db_query_builder|test_logger_json|test_batch_delete_progress|test_db_motion_config|test_db_recordings_sync|test_httpd_utils|test_zone_filter|test_onvif_soap_fault|test_stream_manager|test_stream_state|test_packet_buffer|test_timestamp_manager"
- name: Generate coverage report
if: always()
run: |
cd build
# Collect coverage data from all .gcda files generated during the test run
lcov --capture \
--directory . \
--output-file coverage.info \
--ignore-errors mismatch
# Strip noise: system headers, third-party code, and the test files themselves
lcov --remove coverage.info \
'/usr/*' \
'*/third_party/*' \
'*/external/*' \
'*/tests/*' \
--output-file coverage_filtered.info \
--ignore-errors unused
# Print a quick per-file summary to the job log
lcov --list coverage_filtered.info
# Render HTML
genhtml coverage_filtered.info \
--output-directory ../coverage-report \
--title "LightNVR C Unit-Test Coverage" \
--show-details \
--legend
echo "Coverage report generated at coverage-report/"
- name: Upload coverage report
uses: actions/upload-artifact@v6
if: always()
with:
name: c-coverage-report
path: coverage-report/
retention-days: 30
- name: Upload to Codecov
uses: codecov/codecov-action@v5
if: always()
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: build/coverage_filtered.info
flags: unity-c
name: lightnvr-c-coverage
fail_ci_if_error: false
- name: Upload test results on failure
uses: actions/upload-artifact@v6
if: failure()
with:
name: unity-test-results
path: build/Testing/
retention-days: 7
playwright-tests:
name: Playwright Integration Tests (Layer 3)
needs: unity-tests
runs-on: ubuntu-latest
container: debian:sid-slim
timeout-minutes: 30
steps:
- name: Install system dependencies
run: |
apt-get update
apt-get install -y \
git \
build-essential \
cmake \
pkg-config \
libavcodec-dev \
libavformat-dev \
libavutil-dev \
libswscale-dev \
libsqlite3-dev \
libuv1-dev \
libllhttp-dev \
libcurl4-openssl-dev \
libcjson-dev \
libmbedtls-dev \
ffmpeg \
curl \
jq \
golang-go \
nodejs \
npm \
procps
- name: Checkout
uses: actions/checkout@v5
with:
submodules: recursive
- name: Build go2rtc from source
run: |
# Build go2rtc from the opensensor fork submodule
cd go2rtc
echo "Building go2rtc from source..."
CGO_ENABLED=0 go build -buildvcs=false -ldflags "-s -w" -trimpath -o go2rtc
chmod +x go2rtc
./go2rtc --version || echo "go2rtc built successfully"
echo "go2rtc binary size: $(stat -c%s go2rtc) bytes"
# Binary is now at go2rtc/go2rtc - exactly where lightnvr-test.ini expects it
- name: Build lightNVR
run: |
mkdir -p build
cd build
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DENABLE_GO2RTC=ON \
-DGO2RTC_BINARY_PATH=$(pwd)/../go2rtc/go2rtc
make -j$(nproc)
echo "lightNVR built successfully"
ls -la bin/lightnvr
- name: Build web frontend
run: |
cd web
npm ci
npm run build
echo "Web frontend built successfully"
ls -la dist/ | head -10
- name: Install Playwright dependencies
run: |
npm ci
npx playwright install --with-deps chromium
- name: Run Playwright UI tests
run: |
# Clean any existing playwright reports to ensure fresh state
rm -rf playwright-report test-results
mkdir -p playwright-report test-results
# Pre-flight checks before running tests
echo "=== Pre-flight checks ==="
echo "Checking if lightNVR binary exists..."
ls -la build/bin/lightnvr || echo "lightNVR binary NOT found"
echo ""
echo "Checking if go2rtc binary exists..."
ls -la go2rtc/go2rtc || echo "go2rtc binary NOT found"
echo ""
echo "Checking if web/dist exists..."
ls -la web/dist/ | head -5 || echo "web/dist NOT found"
echo ""
echo "Checking if config file exists..."
ls -la config/lightnvr-test.ini || echo "Config file NOT found"
echo ""
# Try to manually start lightNVR to see if it works
echo "=== Attempting manual lightNVR start for diagnostics ==="
mkdir -p /tmp/lightnvr-test/recordings /tmp/lightnvr-test/go2rtc
timeout 10 ./build/bin/lightnvr -c config/lightnvr-test.ini &
MANUAL_PID=$!
echo "Started lightNVR manually with PID: $MANUAL_PID"
sleep 5
# Check if it's still running
if kill -0 $MANUAL_PID 2>/dev/null; then
echo "lightNVR is running (PID: $MANUAL_PID)"
# Check if it's listening on port 18080
if curl -s -u admin:admin http://localhost:18080/api/system > /dev/null 2>&1; then
echo "lightNVR is responding on port 18080"
else
echo "lightNVR is NOT responding on port 18080"
netstat -tlpn | grep 18080 || echo "Port 18080 is not listening"
fi
else
echo "lightNVR process exited"
wait $MANUAL_PID
echo "Exit code: $?"
fi
# Check logs
if [ -f /tmp/lightnvr-test/lightnvr.log ]; then
echo "=== lightNVR log (last 50 lines) ==="
tail -50 /tmp/lightnvr-test/lightnvr.log
else
echo "No log file at /tmp/lightnvr-test/lightnvr.log"
fi
# Kill the manual instance and ALL child processes it spawned
# (lightNVR starts go2rtc as a child; killing only $MANUAL_PID leaves
# go2rtc alive on port 11984, causing playwright's lightNVR to fail
# with "Cannot start go2rtc because port 11984 is already in use")
kill $MANUAL_PID 2>/dev/null || true
pkill -TERM -f lightnvr 2>/dev/null || true
pkill -TERM -f go2rtc 2>/dev/null || true
sleep 3
pkill -KILL -f lightnvr 2>/dev/null || true
pkill -KILL -f go2rtc 2>/dev/null || true
sleep 1
# Clean up for actual test run
rm -rf /tmp/lightnvr-test
echo ""
echo "=== Running Playwright tests ==="
# Run Playwright tests with output capture.
# Avoid ${PIPESTATUS[0]} — it is bash-only and the container
# shell is /bin/sh (dash). Capture the exit code directly.
RESULT=0
npx playwright test --project=ui > playwright-output.log 2>&1 || RESULT=$?
cat playwright-output.log
if [ $RESULT -ne 0 ]; then
echo ""
echo "=== Playwright tests failed ==="
echo ""
echo "Checking if lightNVR is still running..."
pgrep -a lightnvr || echo "lightNVR is NOT running"
pgrep -a go2rtc || echo "go2rtc is NOT running"
echo ""
echo "Checking lightNVR logs..."
if [ -f /tmp/lightnvr-test/lightnvr.log ]; then
echo "=== Last 200 lines of lightnvr.log ==="
tail -200 /tmp/lightnvr-test/lightnvr.log
else
echo "No log file found at /tmp/lightnvr-test/lightnvr.log"
fi
echo ""
echo "Checking for core dumps..."
ls -la /tmp/core* 2>/dev/null || echo "No core dumps found"
echo ""
exit $RESULT
fi
env:
CI: true
- name: Upload Playwright report
uses: actions/upload-artifact@v6
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
- name: Upload test screenshots
uses: actions/upload-artifact@v6
if: failure()
with:
name: test-screenshots
path: test-results/
retention-days: 7
- name: Upload lightNVR logs
uses: actions/upload-artifact@v6
if: failure()
with:
name: lightnvr-logs
path: |
/tmp/lightnvr-test/
playwright-output.log
retention-days: 7
- name: Cleanup
if: always()
run: |
# Stop any remaining processes
pkill -f lightnvr || true
pkill -f go2rtc || true
# Clean up test artifacts
rm -rf /tmp/lightnvr-test