| ... | @@ -44,6 +44,11 @@ pub fn addLibcTestCase( | ... | @@ -44,6 +44,11 @@ pub fn addLibcTestCase( |
| 44 | } | 44 | } |
| 45 | | 45 | |
| 46 | pub fn addTarget(libc: *const Libc, target: std.Build.ResolvedTarget) void { | 46 | pub 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 | |
| 47 | if (libc.options.skip_wasm and target.query.cpu_arch != null and target.query.cpu_arch.?.isWasm()) return; | 52 | if (libc.options.skip_wasm and target.query.cpu_arch != null and target.query.cpu_arch.?.isWasm()) return; |
| 48 | | 53 | |
| 49 | if (libc.options.test_target_filters.len > 0) { | 54 | if (libc.options.test_target_filters.len > 0) { |
| ... | @@ -55,73 +60,71 @@ pub fn addTarget(libc: *const Libc, target: std.Build.ResolvedTarget) void { | ... | @@ -55,73 +60,71 @@ pub fn addTarget(libc: *const Libc, target: std.Build.ResolvedTarget) void { |
| 55 | | 60 | |
| 56 | const common = libc.libc_test_src_path.path(libc.b, "common"); | 61 | const common = libc.libc_test_src_path.path(libc.b, "common"); |
| 57 | | 62 | |
| 58 | for (libc.options.optimize_modes) |optimize| { | 63 | const libtest_mod = libc.b.createModule(.{ |
| 59 | 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(.{ |
| 60 | .target = target, | 93 | .target = target, |
| 61 | .optimize = optimize, | 94 | .optimize = .debug, |
| 62 | .link_libc = true, | 95 | .link_libc = true, |
| 63 | }); | 96 | }); |
| 64 | | 97 | mod.addIncludePath(common); |
| 65 | var libtest_c_source_files: []const []const u8 = &.{ | 98 | if (target.result.isWasiLibC()) |
| 66 | "print.c", "rand.c", "mtest.c", "setrlim.c", "memfill.c", "vmfill.c", "fdfill.c", "utf8.c", | 99 | mod.addCMacro("_WASI_EMULATED_SIGNAL", ""); |
| 67 | }; | 100 | mod.addCSourceFile(.{ |
| 68 | libtest_mod.addCSourceFiles(.{ | 101 | .file = test_case.src_file, |
| 69 | .root = common, | | |
| 70 | .files = libtest_c_source_files[0..if (target.result.isMuslLibC()) 8 else 3], | | |
| 71 | .flags = &.{"-fno-builtin"}, | 102 | .flags = &.{"-fno-builtin"}, |
| 72 | }); | 103 | }); |
| 73 | | 104 | if (test_case.additional_src_file) |additional_src_file| { |
| 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", ""); | | |
| 96 | mod.addCSourceFile(.{ | 105 | mod.addCSourceFile(.{ |
| 97 | .file = test_case.src_file, | 106 | .file = additional_src_file, |
| 98 | .flags = &.{"-fno-builtin"}, | 107 | .flags = &.{"-fno-builtin"}, |
| 99 | }); | 108 | }); |
| 100 | if (test_case.additional_src_file) |additional_src_file| { | 109 | } |
| 101 | mod.addCSourceFile(.{ | 110 | mod.linkLibrary(libtest); |
| 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 | }); | | |
| 113 | | 111 | |
| 114 | const run = libc.b.addRunArtifact(exe); | 112 | const exe = libc.b.addExecutable(.{ |
| 115 | run.setName(annotated_case_name); | 113 | .name = test_case.name, |
| 116 | run.skip_foreign_checks = true; | 114 | .root_module = mod, |
| 117 | run.disable_zig_progress = true; // can interfere with fd count assumptions | 115 | .max_rss = libc.options.max_rss, |
| 118 | run.expectStdErrEqual(""); | 116 | }); |
| 119 | run.expectStdOutEqual(""); | | |
| 120 | run.expectExitCode(0); | | |
| 121 | run.step.max_rss = libc.options.max_rss; | | |
| 122 | | 117 | |
| 123 | libc.root_step.dependOn(&run.step); | 118 | const run = libc.b.addRunArtifact(exe); |
| 124 | } | 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); |
| 125 | } | 128 | } |
| 126 | } | 129 | } |
| 127 | | 130 | |