Skip to content

Commit fbe0d74

Browse files
authored
Merge pull request #86 from choco-technologies/copilot/move-renode-tests-to-script
Move Renode tests from inline CI steps to a reusable script
2 parents c63ac6c + cd0db44 commit fbe0d74

5 files changed

Lines changed: 117 additions & 70 deletions

File tree

.github/workflows/build.yml

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -165,74 +165,9 @@ jobs:
165165
git submodule init
166166
git submodule update --recursive
167167
168-
- name: Build with emulation mode enabled
168+
- name: Run Renode emulation tests
169169
run: |
170-
cmake -DCMAKE_BUILD_TYPE=Debug -DBOARD=stm32f746g-disco -DDMBOOT_EMULATION=ON -S . -B build
171-
cmake --build build --config Debug
172-
173-
- name: Test install-firmware target
174-
run: |
175-
cd build
176-
cmake --build . --target install-firmware
177-
ls -lh renode_firmware.elf
178-
echo "✓ install-firmware target works correctly"
179-
180-
- name: Test Renode workflow and monitor-gdb
181-
run: |
182-
cd build
183-
184-
echo "Starting Renode emulation test..."
185-
186-
# Start Renode with connect target in background
187-
echo "Launching Renode..."
188-
timeout 90 cmake --build . --target connect > connect.log 2>&1 &
189-
CONNECT_PID=$!
190-
191-
# Wait for Renode to start and GDB server to be ready
192-
echo "Waiting for Renode GDB server to start..."
193-
sleep 3
194-
195-
# Check if Renode is still running
196-
if ! ps -p $CONNECT_PID > /dev/null 2>&1; then
197-
echo "✗ Renode failed to start"
198-
cat connect.log
199-
exit 1
200-
fi
201-
202-
echo "✓ Renode started successfully"
203-
204-
# Now test monitor-gdb to read logs
205-
echo "Testing monitor-gdb to read firmware logs..."
206-
timeout 60 cmake --build . --target monitor-gdb > monitor.log 2>&1 &
207-
MONITOR_PID=$!
208-
209-
# Wait for monitor to capture some output
210-
sleep 60
211-
212-
# Check monitor output
213-
if [ -f monitor.log ]; then
214-
echo "Monitor output:"
215-
cat monitor.log
216-
echo ""
217-
218-
# Verify expected logs using the verification script
219-
bash "$GITHUB_WORKSPACE"/scripts/verify_renode_logs.sh monitor.log "$GITHUB_WORKSPACE"/configs/renode/expected_logs.txt
220-
else
221-
echo "✗ No monitor output captured"
222-
exit 1
223-
fi
224-
225-
# Cleanup
226-
echo ""
227-
echo "Cleaning up processes..."
228-
kill $MONITOR_PID 2>/dev/null || true
229-
kill $CONNECT_PID 2>/dev/null || true
230-
sleep 2
231-
pkill -9 -f renode || true
232-
pkill -9 -f mono || true
233-
234-
echo ""
235-
echo "Renode workflow test completed!"
170+
./scripts/run_renode_tests.sh
236171
237172
build-all:
238173
name: All builds completed

configs/renode/expected_logs.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# Each line is a pattern that must appear in the monitor-gdb output
33
# Lines starting with # are comments and empty lines are ignored
44

5-
DMOD-Boot started
5+
DMOD-Boot started

lib/dmheap

scripts/run_renode_tests.sh

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/bin/bash
2+
# run_renode_tests.sh - Run Renode emulation tests for dmod-boot
3+
#
4+
# This script reproduces the Renode CI tests locally.
5+
# It builds the firmware with emulation mode, starts Renode, runs monitor-gdb
6+
# to capture firmware logs, and verifies the expected log messages.
7+
#
8+
# Usage:
9+
# ./scripts/run_renode_tests.sh [SOURCE_DIR [BUILD_DIR]]
10+
#
11+
# SOURCE_DIR Path to the project root.
12+
# Defaults to the parent directory of this script.
13+
# BUILD_DIR Path to the build directory.
14+
# Defaults to SOURCE_DIR/build.
15+
16+
set -e
17+
18+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
19+
SOURCE_DIR="${1:-$(cd "$SCRIPT_DIR/.." && pwd)}"
20+
BUILD_DIR="${2:-$SOURCE_DIR/build}"
21+
22+
BOARD="stm32f746g-disco"
23+
EXPECTED_LOGS="$SOURCE_DIR/configs/renode/expected_logs.txt"
24+
VERIFY_SCRIPT="$SOURCE_DIR/scripts/verify_renode_logs.sh"
25+
26+
# Timeouts (seconds)
27+
CONNECT_TIMEOUT=90
28+
MONITOR_TIMEOUT=30
29+
30+
echo "=============================================="
31+
echo " dmod-boot Renode emulation tests"
32+
echo "=============================================="
33+
echo "Source dir : $SOURCE_DIR"
34+
echo "Build dir : $BUILD_DIR"
35+
echo "Board : $BOARD"
36+
echo ""
37+
38+
# -------------------------------------------------------
39+
# Step 1 – Build firmware with emulation mode enabled
40+
# -------------------------------------------------------
41+
echo "[1/4] Building firmware with emulation mode enabled..."
42+
cmake -DCMAKE_BUILD_TYPE=Debug \
43+
-DBOARD="$BOARD" \
44+
-DDMBOOT_EMULATION=ON \
45+
-S "$SOURCE_DIR" \
46+
-B "$BUILD_DIR"
47+
cmake --build "$BUILD_DIR" --config Debug
48+
echo "✓ Build completed"
49+
echo ""
50+
51+
# -------------------------------------------------------
52+
# Step 2 – Verify install-firmware target
53+
# -------------------------------------------------------
54+
echo "[2/4] Testing install-firmware target..."
55+
cmake --build "$BUILD_DIR" --target install-firmware
56+
if [ ! -f "$BUILD_DIR/renode_firmware.elf" ]; then
57+
echo "✗ renode_firmware.elf not found after install-firmware"
58+
exit 1
59+
fi
60+
ls -lh "$BUILD_DIR/renode_firmware.elf"
61+
echo "✓ install-firmware target works correctly"
62+
echo ""
63+
64+
# -------------------------------------------------------
65+
# Step 3 – Start Renode in the background
66+
# -------------------------------------------------------
67+
echo "[3/4] Starting Renode emulation..."
68+
CONNECT_LOG="$BUILD_DIR/connect.log"
69+
timeout "$CONNECT_TIMEOUT" cmake --build "$BUILD_DIR" --target connect > "$CONNECT_LOG" 2>&1 &
70+
CONNECT_PID=$!
71+
72+
echo "Waiting for Renode GDB server to start (PID $CONNECT_PID)..."
73+
sleep 5
74+
75+
if ! ps -p "$CONNECT_PID" > /dev/null 2>&1; then
76+
echo "✗ Renode failed to start"
77+
echo "--- connect.log ---"
78+
cat "$CONNECT_LOG"
79+
exit 1
80+
fi
81+
echo "✓ Renode started successfully"
82+
echo ""
83+
84+
# -------------------------------------------------------
85+
# Step 4 – Run monitor-gdb and verify firmware logs
86+
# -------------------------------------------------------
87+
echo "[4/4] Running monitor-gdb to capture firmware logs..."
88+
MONITOR_LOG="$BUILD_DIR/monitor.log"
89+
timeout "$MONITOR_TIMEOUT" cmake --build "$BUILD_DIR" --target monitor-gdb > "$MONITOR_LOG" 2>&1 &
90+
MONITOR_PID=$!
91+
92+
# Give the firmware time to produce log output
93+
sleep "$MONITOR_TIMEOUT"
94+
95+
echo "Monitor output:"
96+
cat "$MONITOR_LOG"
97+
echo ""
98+
99+
# Verify expected log messages
100+
bash "$VERIFY_SCRIPT" "$MONITOR_LOG" "$EXPECTED_LOGS"
101+
VERIFY_STATUS=$?
102+
103+
echo ""
104+
echo "=============================================="
105+
if [ "$VERIFY_STATUS" -eq 0 ]; then
106+
echo " Renode emulation tests PASSED"
107+
else
108+
echo " Renode emulation tests FAILED"
109+
fi
110+
echo "=============================================="
111+
112+
exit "$VERIFY_STATUS"

0 commit comments

Comments
 (0)