Skip to content

Commit 7f50d4c

Browse files
committed
qemu_runner: Add a printline quirk to fix runner (#25)
1 parent 6f56203 commit 7f50d4c

File tree

3 files changed

+30
-64
lines changed

3 files changed

+30
-64
lines changed

qemu_runner/Makefile

Lines changed: 25 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ endif
2020

2121
ELF := $(BUILD_DIR)/z6m_debug
2222

23-
.PHONY: xpack-elf
23+
.PHONY: xpack-elf xpack-zilkworm xpack-zilkworm-eest gdb rlp-qemu qemu-eest-stdio qemu-eest-fileio rerun-ctest
24+
2425
xpack-elf: xpack-zilkworm
25-
@[ -d $(BUILD_DIR) ] || mkdir $(BUILD_DIR)
26-
cmake -B$(BUILD_DIR) -S. -DCMAKE_BUILD_TYPE=Debug \
26+
@mkdir -p $(BUILD_DIR)
27+
cmake -B$(BUILD_DIR) -S. \
2728
-DCMAKE_TOOLCHAIN_FILE=$(CMAKE_TOOLCHAIN) \
2829
-DCMAKE_BUILD_TYPE=Debug \
2930
-DCONAN_PROFILE_HOST=$(CONAN_PROFILE) \
@@ -37,9 +38,8 @@ xpack-elf: xpack-zilkworm
3738
cmake --build $(BUILD_DIR) -j --verbose
3839

3940
xpack-zilkworm:
40-
@[ -d $(BUILD_DIR) ] || mkdir $(BUILD_DIR)
41-
@[ -d $(BUILD_DIR)/zilkworm ] || mkdir $(BUILD_DIR)/zilkworm
42-
cmake -B$(BUILD_DIR)/zilkworm -S.. -DCMAKE_BUILD_TYPE=Debug \
41+
@mkdir -p $(BUILD_DIR)/zilkworm
42+
cmake -B$(BUILD_DIR)/zilkworm -S.. \
4343
-DCMAKE_TOOLCHAIN_FILE=$(CMAKE_TOOLCHAIN) \
4444
-DCMAKE_BUILD_TYPE=Debug \
4545
-DCONAN_PROFILE_HOST=$(CONAN_PROFILE) \
@@ -55,11 +55,11 @@ xpack-zilkworm:
5555
cmake --build $(BUILD_DIR)/zilkworm -j --target install
5656

5757
gdb:
58-
riscv-none-elf-gdb -q -ex "target remote :1234" -x .gdbinit build/z6m_debug
58+
riscv-none-elf-gdb -q -ex "target remote :1234" -x .gdbinit $(ELF)
5959

6060
## make rlp-qemu file-name=../prover/temp/blocks/2347866/uni...bin
6161
rlp-qemu: xpack-elf
62-
@if [ -z "$(file-name)" ]; then echo "Usage: make rlp-qemu file-name=path/to.json"; exit 1; fi
62+
@if [ -z "$(file-name)" ]; then echo "Usage: make rlp-qemu file-name=path/to.json (ARCH=$(ARCH))"; exit 1; fi
6363
@echo "QEMU waiting for GDB on :1234..."
6464
@N=$$(wc -c <"$(file-name)"); \
6565
{ printf "123456789_123456789_123456789_123"; printf "%u\n" $$N; cat "$(file-name)"; } | \
@@ -72,9 +72,8 @@ rlp-qemu: xpack-elf
7272

7373

7474
xpack-zilkworm-eest:
75-
@[ -d $(BUILD_DIR) ] || mkdir $(BUILD_DIR)
76-
@[ -d $(BUILD_DIR)/zilkworm ] || mkdir $(BUILD_DIR)/zilkworm
77-
cmake -B$(BUILD_DIR)/zilkworm -S.. \
75+
@mkdir -p $(BUILD_DIR)/zilkworm
76+
cmake -B$(BUILD_DIR)/zilkworm -S.. \
7877
-DCMAKE_TOOLCHAIN_FILE=$(CMAKE_TOOLCHAIN) \
7978
-DCMAKE_BUILD_TYPE=Release \
8079
-DCONAN_PROFILE_HOST=$(CONAN_PROFILE) \
@@ -88,7 +87,6 @@ xpack-zilkworm-eest:
8887
-Wno-dev
8988
cmake --build $(BUILD_DIR)/zilkworm -j --target install
9089

91-
.PHONY: xpack-elf-eest
9290
xpack-elf-eest: xpack-zilkworm-eest
9391
cmake -B$(BUILD_DIR) -S. \
9492
-DCMAKE_TOOLCHAIN_FILE=$(CMAKE_TOOLCHAIN) \
@@ -107,13 +105,12 @@ xpack-elf-eest: xpack-zilkworm-eest
107105
cmake --build $(BUILD_DIR) -j --verbose
108106

109107

110-
.PHONY: qemu-eest
111-
qemu-eest: xpack-elf-eest
112-
@if [ -z "$(file-name)" ]; then echo "Usage: make qemu-eest file-name=path/to.json"; exit 1; fi
108+
qemu-eest-stdio: xpack-elf-eest
109+
@if [ -z "$(file-name)" ]; then echo "Usage: make qemu-eest-stdio file-name=path/to.json (ARCH=$(ARCH))"; exit 1; fi
113110
@N=$$(wc -c <"$(file-name)"); \
114111
{ printf "123456789_123456789_123456789_123"; printf "1 %u\n" $$N; cat "$(file-name)"; } | \
115112
$(QEMU_SYSTEM) -M virt -m 2G -nographic \
116-
-bios $(BUILD_DIR)/z6m_debug \
113+
-bios $(ELF) \
117114
-chardev stdio,mux=on,id=stdio0 \
118115
-serial chardev:stdio0 \
119116
-semihosting-config enable=on,chardev=stdio0 \
@@ -122,57 +119,20 @@ qemu-eest: xpack-elf-eest
122119
eest-blockchain-tests: xpack-elf-eest
123120
ctest --test-dir $(BUILD_DIR) --parallel --output-on-failure
124121

125-
rerun-ctest:
122+
rerun-ctest: xpack-elf-eest
126123
ctest --test-dir $(BUILD_DIR) --parallel --output-on-failure -V --timeout 7200
127124

128-
# rerun-qemu-eest:
129-
# @if [ -z "$(file-name)" ]; then echo "Usage: make qemu-eest file-name=path/to.json"; exit 1; fi
130-
# @N=$$(wc -c <"$(file-name)"); \
131-
# { printf "123456789_123456789_123456789_123"; printf "1 %u\n" $$N; cat "$(file-name)"; } | \
132-
# qemu-system-riscv32 -M virt -m 2G -nographic \
133-
# -bios $(BUILD_DIR)/z6m_debug \
134-
# -chardev stdio,mux=on,id=stdio0 \
135-
# -serial chardev:stdio0 \
136-
# -semihosting-config enable=on,target=native,chardev=stdio0 \
137-
# -monitor none \
138-
# -qmp unix:/tmp/qmp.sock,server=on,wait=off
139-
140-
# rerun-qemu-eest:
141-
# which script;
142-
# @if [ -z "$(file-name)" ]; then echo "Usage: make rerun-qemu-eest file-name=path/to.json"; exit 1; fi
143-
# @N=$$(wc -c <"$(file-name)"); \
144-
# rm -f semihost.log; \
145-
# script -qefc "{ printf '123456789_123456789_123456789_123'; printf '1 %u\n' $$N; cat '$(file-name)'; } | \
146-
# qemu-system-riscv32 -M virt -m 2G -nographic \
147-
# -bios $(BUILD_DIR)/z6m_debug \
148-
# -chardev stdio,mux=on,id=stdio0,signal=off \
149-
# -serial chardev:stdio0 \
150-
# -semihosting-config enable=on,chardev=stdio0,target=native \
151-
# -monitor none" semihost.log
152-
153-
# rerun-qemu-eest:
154-
# @if [ -z "$(file-name)" ]; then echo "Usage: make rerun-qemu-eest file-name=path/to.json"; exit 1; fi
155-
# @N=$$(wc -c <"$(file-name)"); \
156-
# rm -f semihost.log serial.log; \
157-
# { printf "123456789_123456789_123456789_123"; printf "1 %u\n" $$N; cat "$(file-name)"; } | \
158-
# qemu-system-riscv32 -M virt -m 2G -display none \
159-
# -bios $(BUILD_DIR)/z6m_debug \
160-
# -chardev stdio,id=sh0,signal=off \
161-
# -semihosting-config enable=on,target=native,chardev=sh0 \
162-
# -serial none \
163-
# -monitor none
164-
165-
166-
rerun-qemu-eest:
167-
@if [ -z "$(file-name)" ]; then echo "Usage: make rerun-qemu-eest file-name=path/to.json"; exit 1; fi
125+
qemu-eest-fileio: xpack-elf-eest
126+
@if [ -z "$(file-name)" ]; then echo "Usage: make qemu-eest-fileio file-name=path/to.json (ARCH=$(ARCH))"; exit 1; fi
127+
@mkdir -p $(CURDIR)/temp
168128
@N=$$(wc -c <"$(file-name)"); \
169-
rm -f semihost.log serial.log; \
170-
{ printf "1 %u\n" $$N; cat "$(file-name)"; } > stdin_payload.bin; \
129+
rm -f $(CURDIR)/temp/semihost.log $(CURDIR)/temp/serial.log; \
130+
{ printf "1 %u\n" $$N; cat "$(file-name)"; } > $(CURDIR)/temp/stdin_payload.bin; \
171131
$(QEMU_SYSTEM) -M virt -m 2G -display none \
172-
-bios $(BUILD_DIR)/z6m_debug \
132+
-bios $(ELF) \
173133
-monitor none \
174134
-serial none \
175-
-chardev file,id=shlog,path=semihost.log \
135+
-chardev file,id=shlog,path=$(CURDIR)/temp/semihost.log \
176136
-semihosting-config enable=on,target=native,chardev=shlog
177137

178138

@@ -194,9 +154,12 @@ eest-rv64:
194154
$(MAKE) ARCH=rv64 eest-blockchain-tests
195155

196156
# Clean build artifacts
197-
.PHONY: clean clean-all
157+
.PHONY: clean clean-all clean-temp
198158
clean:
199159
rm -rf $(BUILD_DIR)
200160

201161
clean-all:
202162
rm -rf $(CURDIR)/build $(CURDIR)/build64
163+
164+
clean-temp:
165+
rm -f $(CURDIR)/temp/stdin_payload.bin $(CURDIR)/temp/semihost.log $(CURDIR)/temp/serial.log

qemu_runner/src/include/semihosting.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22
#include <cstddef>
33
#include <cstdint>
4+
#include <string_view>
45

56
static inline void sys_print(const char* s)
67
{
@@ -16,9 +17,9 @@ static inline void sys_print(const char* s)
1617
: "+r"(a0) : "r"(a1) : "memory");
1718
}
1819

19-
static inline void sys_println(const char* s)
20+
static inline void sys_println(std::string_view s)
2021
{
21-
sys_print(s);
22+
sys_print(s.data());
2223
sys_print("\n");
2324
}
2425

qemu_runner/src/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <cstdio>
33
#include <string>
44
#include "./include/semihosting.hpp"
5+
#include <format>
56

67
// Static buffer big enough for all the JSON payloads.
78
static char JSON_BUF[200 * 1024 * 1024];
@@ -89,5 +90,6 @@ int main(int argc, char* argv[])
8990
const uint64_t res = sample_run_wrapped(is_test, jsonStr);
9091

9192
// Exit QEMU with the result code
93+
sys_println(std::format("Run complete. Result: {}", res));
9294
sh::exit(static_cast<int>(res));
9395
}

0 commit comments

Comments
 (0)