Skip to content

Implement Record/Replay functionality for btest #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
- main

# TODO: add jobs that test on different host platforms (windows, aarch64, etc)
# TODO: build examples on CI
# May require a special support for build-only mode in btest

jobs:
btest:
Expand All @@ -31,6 +33,3 @@ jobs:
- name: Run Tests
run: |
PATH=$(realpath uxn11/bin):$PATH ./build/btest
- name: Build Examples
run: |
PATH=$(realpath uxn11/bin):$PATH ./build/btest -dir ./examples/ -build-only
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ LINUX_OBJS=\
$(BUILD)/flag.linux.o \
$(BUILD)/libc.linux.o \
$(BUILD)/arena.linux.o \
$(BUILD)/fake6502.linux.o
$(BUILD)/fake6502.linux.o \
$(BUILD)/jim.linux.o \
$(BUILD)/jimp.linux.o

MINGW32_OBJS=\
$(BUILD)/nob.mingw32.o \
$(BUILD)/flag.mingw32.o \
$(BUILD)/libc.mingw32.o \
$(BUILD)/arena.mingw32.o \
$(BUILD)/fake6502.mingw32.o
$(BUILD)/fake6502.mingw32.o \
$(BUILD)/jim.mingw32.o \
$(BUILD)/jimp.mingw32.o

.PHONY: all
all: $(BUILD)/b $(BUILD)/btest
Expand Down
40 changes: 19 additions & 21 deletions src/b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1139,9 +1139,9 @@ pub unsafe fn compile_program(l: *mut Lexer, c: *mut Compiler) -> Option<()> {
}

pub unsafe fn include_path_if_exists(input_paths: &mut Array<*const c_char>, path: *const c_char) -> Option<()> {
let path_exists = file_exists(path);
if path_exists < 0 { return None; }
if path_exists > 0 { da_append(input_paths, path); }
if file_exists(path)? {
da_append(input_paths, path);
}
Some(())
}

Expand Down Expand Up @@ -1238,9 +1238,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
//
// - rexim (2025-06-12 20:56:08)
let libb_path = c!("./libb");
let libb_path_exist = file_exists(libb_path);
if libb_path_exist < 0 { return None; }
if libb_path_exist == 0 {
if !file_exists(libb_path)? {
fprintf(stderr(), c!("ERROR: No standard library path %s found. Please run the compiler from the same folder where %s is located. Or if you don't want to use the standard library pass the -%s flag.\n"), libb_path, libb_path, flag_name(nostdlib));
return None;
}
Expand Down Expand Up @@ -1272,7 +1270,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
let input_path = *input_paths.items.add(i);

input.count = 0;
if !read_entire_file(input_path, &mut input) { return None; }
read_entire_file(input_path, &mut input)?;

let mut l: Lexer = lexer::new(input_path, input.items, input.items.add(input.count), *historical);

Expand Down Expand Up @@ -1310,7 +1308,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
}

let output_asm_path = temp_sprintf(c!("%s.s"), effective_output_path);
if !write_entire_file(output_asm_path, output.items as *const c_void, output.count) { return None; }
write_entire_file(output_asm_path, output.items as *const c_void, output.count)?;
printf(c!("INFO: Generated %s\n"), output_asm_path);

let (gas, cc) = if cfg!(target_arch = "aarch64") && (cfg!(target_os = "linux") || cfg!(target_os = "android")) {
Expand Down Expand Up @@ -1351,7 +1349,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
}
if !cmd_run_sync_and_reset(&mut cmd) { return None; }
if *run {
runner::gas_aarch64_linux::run(&mut cmd, effective_output_path, da_slice(run_args))?;
runner::gas_aarch64_linux::run(&mut cmd, effective_output_path, da_slice(run_args), None)?;
}
}
Target::Gas_x86_64_Linux => {
Expand All @@ -1369,7 +1367,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
}

let output_asm_path = temp_sprintf(c!("%s.s"), effective_output_path);
if !write_entire_file(output_asm_path, output.items as *const c_void, output.count) { return None; }
write_entire_file(output_asm_path, output.items as *const c_void, output.count)?;
printf(c!("INFO: Generated %s\n"), output_asm_path);

if !(cfg!(target_arch = "x86_64") && cfg!(target_os = "linux")) {
Expand Down Expand Up @@ -1402,7 +1400,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
}
if !cmd_run_sync_and_reset(&mut cmd) { return None; }
if *run {
runner::gas_x86_64_linux::run(&mut cmd, effective_output_path, da_slice(run_args))?
runner::gas_x86_64_linux::run(&mut cmd, effective_output_path, da_slice(run_args), None)?
}
}
Target::Gas_x86_64_Windows => {
Expand All @@ -1426,7 +1424,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
let effective_output_path = temp_sprintf(c!("%s.exe"), base_path);

let output_asm_path = temp_sprintf(c!("%s.s"), base_path);
if !write_entire_file(output_asm_path, output.items as *const c_void, output.count) { return None; }
write_entire_file(output_asm_path, output.items as *const c_void, output.count)?;
printf(c!("INFO: Generated %s\n"), output_asm_path);

let cc = if cfg!(target_arch = "x86_64") && cfg!(target_os = "windows") {
Expand Down Expand Up @@ -1459,7 +1457,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
}
if !cmd_run_sync_and_reset(&mut cmd) { return None; }
if *run {
runner::gas_x86_64_windows::run(&mut cmd, effective_output_path, da_slice(run_args))?;
runner::gas_x86_64_windows::run(&mut cmd, effective_output_path, da_slice(run_args), None)?;
}
}
Target::Fasm_x86_64_Linux => {
Expand All @@ -1477,7 +1475,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
}

let output_asm_path = temp_sprintf(c!("%s.asm"), effective_output_path);
if !write_entire_file(output_asm_path, output.items as *const c_void, output.count) { return None; }
write_entire_file(output_asm_path, output.items as *const c_void, output.count)?;
printf(c!("INFO: Generated %s\n"), output_asm_path);

if !(cfg!(target_arch = "x86_64") && cfg!(target_os = "linux")) {
Expand Down Expand Up @@ -1510,7 +1508,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
}
if !cmd_run_sync_and_reset(&mut cmd) { return None; }
if *run {
runner::fasm_x86_64_linux::run(&mut cmd, effective_output_path, da_slice(run_args))?
runner::fasm_x86_64_linux::run(&mut cmd, effective_output_path, da_slice(run_args), None)?
}
}
Target::Fasm_x86_64_Windows => {
Expand All @@ -1534,7 +1532,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
let effective_output_path = temp_sprintf(c!("%s.exe"), base_path);

let output_asm_path = temp_sprintf(c!("%s.asm"), base_path);
if !write_entire_file(output_asm_path, output.items as *const c_void, output.count) { return None; }
write_entire_file(output_asm_path, output.items as *const c_void, output.count)?;
printf(c!("INFO: Generated %s\n"), output_asm_path);

let cc = if cfg!(target_arch = "x86_64") && cfg!(target_os = "windows") {
Expand Down Expand Up @@ -1567,7 +1565,7 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
}
if !cmd_run_sync_and_reset(&mut cmd) { return None; }
if *run {
runner::fasm_x86_64_windows::run(&mut cmd, effective_output_path, da_slice(run_args))?;
runner::fasm_x86_64_windows::run(&mut cmd, effective_output_path, da_slice(run_args), None)?;
}
}
Target::Uxn => {
Expand All @@ -1582,10 +1580,10 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
effective_output_path = *output_path;
}

if !write_entire_file(effective_output_path, output.items as *const c_void, output.count) { return None; }
write_entire_file(effective_output_path, output.items as *const c_void, output.count)?;
printf(c!("INFO: Generated %s\n"), effective_output_path);
if *run {
runner::uxn::run(&mut cmd, c!("uxnemu"), effective_output_path, da_slice(run_args))?;
runner::uxn::run(&mut cmd, c!("uxnemu"), effective_output_path, da_slice(run_args), None)?;
}
}
Target::Mos6502 => {
Expand All @@ -1601,10 +1599,10 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
effective_output_path = *output_path;
}

if !write_entire_file(effective_output_path, output.items as *const c_void, output.count) { return None; }
write_entire_file(effective_output_path, output.items as *const c_void, output.count)?;
printf(c!("INFO: Generated %s\n"), effective_output_path);
if *run {
runner::mos6502::run(&mut output, config, effective_output_path)?;
runner::mos6502::run(&mut output, config, effective_output_path, None)?;
}
}
}
Expand Down
Loading