From fb427f8824486f1e6df8236a1f1512b0cfbff429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Sun, 8 Jun 2025 19:44:55 +0200 Subject: [PATCH 1/5] ci: esp32c3: runner: Store QEMU pid Ensure that qemu fully exited before proceeding --- examples/esp32c3/runner.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/esp32c3/runner.sh b/examples/esp32c3/runner.sh index 1db211197ce8..05cc6c823fb2 100755 --- a/examples/esp32c3/runner.sh +++ b/examples/esp32c3/runner.sh @@ -20,6 +20,8 @@ esptool.py image_info --version 2 "$outputfilename" 1>&2 # Run in QEMU $qemuexec -nographic -monitor tcp:127.0.0.1:55555,server,nowait -icount 3 -machine esp32c3 -drive file="$outputfilename",if=mtd,format=raw -serial file:"$logfile" > qemuoutput.log 2>&1 & +qemupid=$! + # Let it run sleep 3s From b4addb86a1efb41bbf6b12592f7877049c716f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Sun, 15 Jun 2025 21:25:06 +0200 Subject: [PATCH 2/5] ci: QEMU esp32c3: Output into unique tmp dir --- examples/esp32c3/runner.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/esp32c3/runner.sh b/examples/esp32c3/runner.sh index 05cc6c823fb2..bfaf5f97e85f 100755 --- a/examples/esp32c3/runner.sh +++ b/examples/esp32c3/runner.sh @@ -8,9 +8,13 @@ outputfilenamecargo=$1 outputfilename="$outputfilenamecargo".bin logfile=qemu.log +qemuoutputfile=qemuoutput.log qemuexec=qemu-system-riscv32 +# Create a temporary directory for all output files +tempdir=$(mktemp -d) || exit 1 + # Building ESP32-C3 image espflash save-image --chip esp32c3 --merge "$outputfilenamecargo" "$outputfilename" 1>&2 @@ -18,7 +22,7 @@ espflash save-image --chip esp32c3 --merge "$outputfilenamecargo" "$outputfilena esptool.py image_info --version 2 "$outputfilename" 1>&2 # Run in QEMU -$qemuexec -nographic -monitor tcp:127.0.0.1:55555,server,nowait -icount 3 -machine esp32c3 -drive file="$outputfilename",if=mtd,format=raw -serial file:"$logfile" > qemuoutput.log 2>&1 & +$qemuexec -nographic -monitor tcp:127.0.0.1:55555,server,nowait -icount 3 -machine esp32c3 -drive file="$outputfilename",if=mtd,format=raw -serial file:"$tempdir/$logfile" >"$tempdir"/$qemuoutputfile 2>&1 & qemupid=$! @@ -26,13 +30,17 @@ qemupid=$! sleep 3s # Kill QEMU nicely by sending 'q' (quit) over tcp -echo q | nc -N 127.0.0.1 55555 >> qemuoutput.log 2>&1 +echo q | nc -N 127.0.0.1 55555 >>"$tempdir"/$qemuoutputfile 2>&1 # Output that will be compared must be printed to stdout # Make boot phase silent, for debugging change, run with e.g. $ `env DEBUGGING=true` cargo xtask.... if [ -n "${DEBUGGING}" ]; then # Debugging: strip leading "I (xyz)" where xyz is an incrementing number, and esp_image specifics - sed -e 's/esp_image: .*$/esp_image: REDACTED/' -e 's/I\s\([0-9]*\)(.*)/\1/' < $logfile + sed -e 's/esp_image: .*$/esp_image: REDACTED/' -e 's/I\s\([0-9]*\)(.*)/\1/' <"$tempdir"/$logfile else - tail -n +12 "$logfile" | sed -e '/I\s\([0-9]*\)(.*)/d' + tail -n +12 "$tempdir/$logfile" | sed -e '/I\s\([0-9]*\)(.*)/d' fi + +mv "$tempdir/$logfile" "$(basename "$outputfilename")"-$logfile +mv "$tempdir/$qemuoutputfile" "$(basename "$outputfilename")"-$qemuoutputfile +rm -r "$tempdir" From ac3186390a7fa31a86e75e6cd818a8721df5329e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Sun, 15 Jun 2025 21:25:06 +0200 Subject: [PATCH 3/5] ci: QEMU esp32c3: There is no kill like overkill --- examples/esp32c3/runner.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/examples/esp32c3/runner.sh b/examples/esp32c3/runner.sh index bfaf5f97e85f..67d10070de78 100755 --- a/examples/esp32c3/runner.sh +++ b/examples/esp32c3/runner.sh @@ -33,6 +33,18 @@ sleep 3s echo q | nc -N 127.0.0.1 55555 >>"$tempdir"/$qemuoutputfile 2>&1 # Output that will be compared must be printed to stdout +sleep 0.1s +# If still running, try again nicely +pgrep -af "qemu-system.*" >/dev/null 2>&1 && echo q | nc -N 127.0.0.1 55555 >>"$tempdir"/$qemuoutputfile 2>&1 + +# Ask a bit more firmly with SIGTERM +pgrep -af "qemu-system.*" >/dev/null 2>&1 && kill $qemupid >/dev/null 2>&1 + +pgrep -af "qemu-system.*" >/dev/null 2>&1 && sleep 0.1s >/dev/null 2>&1 + +# Time to die +pgrep -af "qemu-system.*" >/dev/null 2>&1 && kill -9 $qemupid >/dev/null 2>&1 + # Make boot phase silent, for debugging change, run with e.g. $ `env DEBUGGING=true` cargo xtask.... if [ -n "${DEBUGGING}" ]; then # Debugging: strip leading "I (xyz)" where xyz is an incrementing number, and esp_image specifics From 6ba8da801040acfb588921e6f257176b50f0492f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Sun, 15 Jun 2025 22:33:47 +0200 Subject: [PATCH 4/5] gitignore: Ignore QEMU logs: Updated filenames --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 10d2d78f9860..589adde39200 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ book-target/ .DS_Store .vscode/ -qemu.log +*qemu.log +*qemuoutput.log From d80128f1d02436c2eb68957d619d817d6b8c7732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Wed, 18 Jun 2025 20:47:26 +0200 Subject: [PATCH 5/5] ci: QEMU: Match more precisely with "our" QEMU --- examples/esp32c3/runner.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/esp32c3/runner.sh b/examples/esp32c3/runner.sh index 67d10070de78..b9c3fbb3ee70 100755 --- a/examples/esp32c3/runner.sh +++ b/examples/esp32c3/runner.sh @@ -35,15 +35,15 @@ echo q | nc -N 127.0.0.1 55555 >>"$tempdir"/$qemuoutputfile 2>&1 sleep 0.1s # If still running, try again nicely -pgrep -af "qemu-system.*" >/dev/null 2>&1 && echo q | nc -N 127.0.0.1 55555 >>"$tempdir"/$qemuoutputfile 2>&1 +pgrep -af "qemu-system.*esp32c3.*" >/dev/null 2>&1 && echo q | nc -N 127.0.0.1 55555 >>"$tempdir"/$qemuoutputfile 2>&1 # Ask a bit more firmly with SIGTERM -pgrep -af "qemu-system.*" >/dev/null 2>&1 && kill $qemupid >/dev/null 2>&1 +pgrep -af "qemu-system.*esp32c3.*" >/dev/null 2>&1 && kill $qemupid >/dev/null 2>&1 -pgrep -af "qemu-system.*" >/dev/null 2>&1 && sleep 0.1s >/dev/null 2>&1 +pgrep -af "qemu-system.*esp32c3.*" >/dev/null 2>&1 && sleep 0.1s >/dev/null 2>&1 # Time to die -pgrep -af "qemu-system.*" >/dev/null 2>&1 && kill -9 $qemupid >/dev/null 2>&1 +pgrep -af "qemu-system.*esp32c3.*" >/dev/null 2>&1 && kill -9 $qemupid >/dev/null 2>&1 # Make boot phase silent, for debugging change, run with e.g. $ `env DEBUGGING=true` cargo xtask.... if [ -n "${DEBUGGING}" ]; then