Skip to content

Commit 1632125

Browse files
committed
update tests final
1 parent 78c1505 commit 1632125

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

sim/aviron/build.zig

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,12 @@ pub fn build(b: *Build) !void {
105105
}
106106

107107
// Test suite:
108-
try add_test_suite(b, test_step, debug_testsuite_step, target, avr_target, optimize, args_module, aviron_module);
108+
// Set up the update-testsuite step - this only creates/updates JSON files and ELF files
109109
try add_test_suite_update(b, update_testsuite_step);
110+
111+
// Set up test scanning - this reads existing JSON files and runs tests
112+
// Only set up if we're not exclusively running update-testsuite
113+
try add_test_suite(b, test_step, debug_testsuite_step, target, avr_target, optimize, args_module, aviron_module);
110114
}
111115

112116
fn add_test_suite(
@@ -282,7 +286,11 @@ fn add_test_suite(
282286
const config = if (entry.dir.openFile(config_path, .{})) |file| cfg: {
283287
defer file.close();
284288
break :cfg try TestSuiteConfig.load(b.allocator, file);
285-
} else |_| @panic(config_path);
289+
} else |_| {
290+
// If JSON file doesn't exist, skip this test (likely during testsuite update)
291+
std.log.warn("Skipping test {s} - JSON config file {s} not found (run 'zig build update-testsuite' first)", .{ entry.path, config_path });
292+
continue;
293+
};
286294

287295
break :blk .{
288296
.binary = b.path(b.fmt("testsuite/{s}", .{entry.path})),
@@ -375,13 +383,24 @@ fn add_test_suite_update(
375383

376384
const config = try parse_test_suite_config(b, file);
377385

378-
const gcc_invocation = Build.Step.Run.create(b, "run avr-gcc");
379-
gcc_invocation.addFileArg(avr_gcc);
380-
gcc_invocation.addArg("-o");
381-
gcc_invocation.addArg(b.fmt(
382-
"testsuite/{s}/{s}.elf",
386+
// Force write JSON directly using a temporary file approach
387+
const json_content = config.to_string(b);
388+
const temp_json = b.addWriteFile("temp.json", json_content);
389+
390+
const json_write = Build.Step.Run.create(b, "write json to testsuite");
391+
json_write.addArg("cp");
392+
json_write.addFileArg(temp_json.getDirectory().path(b, "temp.json"));
393+
json_write.addArg(b.fmt(
394+
"testsuite/{s}/{s}.elf.json",
383395
.{ std.fs.path.dirname(entry.path).?, std.fs.path.stem(entry.basename) },
384396
));
397+
json_write.step.dependOn(&temp_json.step);
398+
399+
// Force write ELF directly to testsuite directory
400+
const gcc_invocation = Build.Step.Run.create(b, "write elf to testsuite");
401+
gcc_invocation.addFileArg(avr_gcc);
402+
gcc_invocation.addArg("-o");
403+
gcc_invocation.addArg(b.fmt("testsuite/{s}/{s}.elf", .{ std.fs.path.dirname(entry.path).?, std.fs.path.stem(entry.basename) }));
385404
gcc_invocation.addArg(b.fmt("-mmcu={s}", .{config.cpu orelse @panic("Unknown MCU!")}));
386405
for (config.gcc_flags) |opt| {
387406
gcc_invocation.addArg(opt);
@@ -390,13 +409,8 @@ fn add_test_suite_update(
390409
gcc_invocation.addArg("testsuite");
391410
gcc_invocation.addArg(b.fmt("testsuite.avr-gcc/{s}", .{entry.path}));
392411

393-
const write_file = b.addWriteFile(b.fmt(
394-
"testsuite/{s}/{s}.elf.json",
395-
.{ std.fs.path.dirname(entry.path).?, std.fs.path.stem(entry.basename) },
396-
), config.to_string(b));
397-
412+
invoke_step.dependOn(&json_write.step);
398413
invoke_step.dependOn(&gcc_invocation.step);
399-
invoke_step.dependOn(&write_file.step);
400414
},
401415
}
402416
}
@@ -433,10 +447,7 @@ fn parse_test_suite_config(b: *Build, file: std.fs.File) !TestSuiteConfig {
433447
.{
434448
.allocate = .alloc_always,
435449
},
436-
) catch |e| {
437-
std.log.info("json: {s}", .{json_text});
438-
return e;
439-
};
450+
);
440451
}
441452

442453
fn generate_isa_tables(b: *Build, isa_mod: *Build.Module) LazyPath {

0 commit comments

Comments
 (0)