authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-08-13 23:59:50+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-08-14 07:03:23+02:00
log3b51b43dc890dd8df17cb647ff7e1d3a53c438e7
tree26011c47529b304a95d71ea95e7e8ebe0acbf8ab
parent4a2b23c2beb043c1e5368d3737893494d61d4060
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

build/test: Add -Dtest-target-filter for filtering module tests by target triple.

This is useful during porting work where you're not interested in running all targets all the time while iterating on changes.

2 files changed, 14 insertions(+), 1 deletions(-)

build.zig+6
...@@ -379,6 +379,7 @@ pub fn build(b: *std.Build) !void {...@@ -379,6 +379,7 @@ pub fn build(b: *std.Build) !void {
379 }379 }
380380
381 const test_filters = b.option([]const []const u8, "test-filter", "Skip tests that do not match any filter") orelse &[0][]const u8{};381 const test_filters = b.option([]const []const u8, "test-filter", "Skip tests that do not match any filter") orelse &[0][]const u8{};
382 const test_target_filters = b.option([]const []const u8, "test-target-filter", "Skip tests whose target triple do not match any filter") orelse &[0][]const u8{};
382383
383 const test_cases_options = b.addOptions();384 const test_cases_options = b.addOptions();
384385
...@@ -457,6 +458,7 @@ pub fn build(b: *std.Build) !void {...@@ -457,6 +458,7 @@ pub fn build(b: *std.Build) !void {
457458
458 test_step.dependOn(tests.addModuleTests(b, .{459 test_step.dependOn(tests.addModuleTests(b, .{
459 .test_filters = test_filters,460 .test_filters = test_filters,
461 .test_target_filters = test_target_filters,
460 .root_src = "test/behavior.zig",462 .root_src = "test/behavior.zig",
461 .name = "behavior",463 .name = "behavior",
462 .desc = "Run the behavior tests",464 .desc = "Run the behavior tests",
...@@ -470,6 +472,7 @@ pub fn build(b: *std.Build) !void {...@@ -470,6 +472,7 @@ pub fn build(b: *std.Build) !void {
470472
471 test_step.dependOn(tests.addModuleTests(b, .{473 test_step.dependOn(tests.addModuleTests(b, .{
472 .test_filters = test_filters,474 .test_filters = test_filters,
475 .test_target_filters = test_target_filters,
473 .root_src = "test/c_import.zig",476 .root_src = "test/c_import.zig",
474 .name = "c-import",477 .name = "c-import",
475 .desc = "Run the @cImport tests",478 .desc = "Run the @cImport tests",
...@@ -482,6 +485,7 @@ pub fn build(b: *std.Build) !void {...@@ -482,6 +485,7 @@ pub fn build(b: *std.Build) !void {
482485
483 test_step.dependOn(tests.addModuleTests(b, .{486 test_step.dependOn(tests.addModuleTests(b, .{
484 .test_filters = test_filters,487 .test_filters = test_filters,
488 .test_target_filters = test_target_filters,
485 .root_src = "lib/compiler_rt.zig",489 .root_src = "lib/compiler_rt.zig",
486 .name = "compiler-rt",490 .name = "compiler-rt",
487 .desc = "Run the compiler_rt tests",491 .desc = "Run the compiler_rt tests",
...@@ -495,6 +499,7 @@ pub fn build(b: *std.Build) !void {...@@ -495,6 +499,7 @@ pub fn build(b: *std.Build) !void {
495499
496 test_step.dependOn(tests.addModuleTests(b, .{500 test_step.dependOn(tests.addModuleTests(b, .{
497 .test_filters = test_filters,501 .test_filters = test_filters,
502 .test_target_filters = test_target_filters,
498 .root_src = "lib/c.zig",503 .root_src = "lib/c.zig",
499 .name = "universal-libc",504 .name = "universal-libc",
500 .desc = "Run the universal libc tests",505 .desc = "Run the universal libc tests",
...@@ -521,6 +526,7 @@ pub fn build(b: *std.Build) !void {...@@ -521,6 +526,7 @@ pub fn build(b: *std.Build) !void {
521 test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filters, optimization_modes));526 test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filters, optimization_modes));
522 test_step.dependOn(tests.addModuleTests(b, .{527 test_step.dependOn(tests.addModuleTests(b, .{
523 .test_filters = test_filters,528 .test_filters = test_filters,
529 .test_target_filters = test_target_filters,
524 .root_src = "lib/std/std.zig",530 .root_src = "lib/std/std.zig",
525 .name = "std",531 .name = "std",
526 .desc = "Run the standard library tests",532 .desc = "Run the standard library tests",
test/tests.zig+8-1
...@@ -965,6 +965,7 @@ pub fn addRunTranslatedCTests(...@@ -965,6 +965,7 @@ pub fn addRunTranslatedCTests(
965965
966const ModuleTestOptions = struct {966const ModuleTestOptions = struct {
967 test_filters: []const []const u8,967 test_filters: []const []const u8,
968 test_target_filters: []const []const u8,
968 root_src: []const u8,969 root_src: []const u8,
969 name: []const u8,970 name: []const u8,
970 desc: []const u8,971 desc: []const u8,
...@@ -986,6 +987,13 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {...@@ -986,6 +987,13 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
986987
987 const resolved_target = b.resolveTargetQuery(test_target.target);988 const resolved_target = b.resolveTargetQuery(test_target.target);
988 const target = resolved_target.result;989 const target = resolved_target.result;
990 const triple_txt = target.zigTriple(b.allocator) catch @panic("OOM");
991
992 if (options.test_target_filters.len > 0) {
993 for (options.test_target_filters) |filter| {
994 if (std.mem.indexOf(u8, triple_txt, filter) != null) break;
995 } else continue;
996 }
989997
990 if (options.skip_libc and test_target.link_libc == true)998 if (options.skip_libc and test_target.link_libc == true)
991 continue;999 continue;
...@@ -1034,7 +1042,6 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {...@@ -1034,7 +1042,6 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
1034 if (!want_this_mode) continue;1042 if (!want_this_mode) continue;
10351043
1036 const libc_suffix = if (test_target.link_libc == true) "-libc" else "";1044 const libc_suffix = if (test_target.link_libc == true) "-libc" else "";
1037 const triple_txt = target.zigTriple(b.allocator) catch @panic("OOM");
1038 const model_txt = target.cpu.model.name;1045 const model_txt = target.cpu.model.name;
10391046
1040 // wasm32-wasi builds need more RAM, idk why1047 // wasm32-wasi builds need more RAM, idk why