authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-09-17 00:34:37+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-09-17 03:40:26+02:00
log89ff10d568522e7a64a3a8e5dbe9e873a17eff4f
tree765d5c883ebdccf3928c86d347311f3c9000dd7f
parented1617dd20cd5bf8618565472e898da8300f832d
signature Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

test: only run test-libc-nsz in debug mode

libzigc uses compilerRtOptMode(), so is always either small or fast. As such, we don't get much value from running these tests in all optimize modes. debug seems like the sensible choice to make the tests more debuggable.

1 files changed, 60 insertions(+), 57 deletions(-)

test/src/Libc.zig+60-57
......@@ -44,6 +44,11 @@ pub fn addLibcTestCase(
4444}
4545
4646pub fn addTarget(libc: *const Libc, target: std.Build.ResolvedTarget) void {
47 const want_debug = for (libc.options.optimize_modes) |m| {
48 if (m == .debug) break true;
49 } else false;
50 if (!want_debug) return;
51
4752 if (libc.options.skip_wasm and target.query.cpu_arch != null and target.query.cpu_arch.?.isWasm()) return;
4853
4954 if (libc.options.test_target_filters.len > 0) {
......@@ -55,73 +60,71 @@ pub fn addTarget(libc: *const Libc, target: std.Build.ResolvedTarget) void {
5560
5661 const common = libc.libc_test_src_path.path(libc.b, "common");
5762
58 for (libc.options.optimize_modes) |optimize| {
59 const libtest_mod = libc.b.createModule(.{
63 const libtest_mod = libc.b.createModule(.{
64 .target = target,
65 .optimize = .debug,
66 .link_libc = true,
67 });
68
69 const libtest_c_source_files: []const []const u8 = &.{
70 "print.c", "rand.c", "mtest.c", "setrlim.c", "memfill.c", "vmfill.c", "fdfill.c", "utf8.c",
71 };
72 libtest_mod.addCSourceFiles(.{
73 .root = common,
74 .files = libtest_c_source_files[0..if (target.result.isMuslLibC()) 8 else 3],
75 .flags = &.{"-fno-builtin"},
76 });
77
78 const libtest = libc.b.addLibrary(.{
79 .name = "test",
80 .root_module = libtest_mod,
81 });
82
83 for (libc.test_cases.items) |*test_case| {
84 if (target.result.isWasiLibC() and !test_case.supports_wasi_libc)
85 continue;
86
87 const annotated_case_name = libc.b.fmt("run libc-test {s}", .{test_case.name});
88 for (libc.options.test_filters) |test_filter| {
89 if (std.mem.find(u8, annotated_case_name, test_filter)) |_| break;
90 } else if (libc.options.test_filters.len > 0) continue;
91
92 const mod = libc.b.createModule(.{
6093 .target = target,
61 .optimize = optimize,
94 .optimize = .debug,
6295 .link_libc = true,
6396 });
64
65 var libtest_c_source_files: []const []const u8 = &.{
66 "print.c", "rand.c", "mtest.c", "setrlim.c", "memfill.c", "vmfill.c", "fdfill.c", "utf8.c",
67 };
68 libtest_mod.addCSourceFiles(.{
69 .root = common,
70 .files = libtest_c_source_files[0..if (target.result.isMuslLibC()) 8 else 3],
97 mod.addIncludePath(common);
98 if (target.result.isWasiLibC())
99 mod.addCMacro("_WASI_EMULATED_SIGNAL", "");
100 mod.addCSourceFile(.{
101 .file = test_case.src_file,
71102 .flags = &.{"-fno-builtin"},
72103 });
73
74 const libtest = libc.b.addLibrary(.{
75 .name = "test",
76 .root_module = libtest_mod,
77 });
78
79 for (libc.test_cases.items) |*test_case| {
80 if (target.result.isWasiLibC() and !test_case.supports_wasi_libc)
81 continue;
82
83 const annotated_case_name = libc.b.fmt("run libc-test {s} ({t})", .{ test_case.name, optimize });
84 for (libc.options.test_filters) |test_filter| {
85 if (std.mem.find(u8, annotated_case_name, test_filter)) |_| break;
86 } else if (libc.options.test_filters.len > 0) continue;
87
88 const mod = libc.b.createModule(.{
89 .target = target,
90 .optimize = optimize,
91 .link_libc = true,
92 });
93 mod.addIncludePath(common);
94 if (target.result.isWasiLibC())
95 mod.addCMacro("_WASI_EMULATED_SIGNAL", "");
104 if (test_case.additional_src_file) |additional_src_file| {
96105 mod.addCSourceFile(.{
97 .file = test_case.src_file,
106 .file = additional_src_file,
98107 .flags = &.{"-fno-builtin"},
99108 });
100 if (test_case.additional_src_file) |additional_src_file| {
101 mod.addCSourceFile(.{
102 .file = additional_src_file,
103 .flags = &.{"-fno-builtin"},
104 });
105 }
106 mod.linkLibrary(libtest);
107
108 const exe = libc.b.addExecutable(.{
109 .name = test_case.name,
110 .root_module = mod,
111 .max_rss = libc.options.max_rss,
112 });
109 }
110 mod.linkLibrary(libtest);
113111
114 const run = libc.b.addRunArtifact(exe);
115 run.setName(annotated_case_name);
116 run.skip_foreign_checks = true;
117 run.disable_zig_progress = true; // can interfere with fd count assumptions
118 run.expectStdErrEqual("");
119 run.expectStdOutEqual("");
120 run.expectExitCode(0);
121 run.step.max_rss = libc.options.max_rss;
112 const exe = libc.b.addExecutable(.{
113 .name = test_case.name,
114 .root_module = mod,
115 .max_rss = libc.options.max_rss,
116 });
122117
123 libc.root_step.dependOn(&run.step);
124 }
118 const run = libc.b.addRunArtifact(exe);
119 run.setName(annotated_case_name);
120 run.skip_foreign_checks = true;
121 run.disable_zig_progress = true; // can interfere with fd count assumptions
122 run.expectStdErrEqual("");
123 run.expectStdOutEqual("");
124 run.expectExitCode(0);
125 run.step.max_rss = libc.options.max_rss;
126
127 libc.root_step.dependOn(&run.step);
125128 }
126129}
127130