authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-11-23 18:00:00+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-11-24 22:11:17+01:00
log2a29381117be7196378229d1c4e797f704675c61
treec6b6767e78a6c79315dc4a9d9dd774079f42ccb1
parent9c7776a9389f2c752c9cc66b653844a7d935f719
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

test: Enable -Dtest-target-filter=... to work for test-cases and test-translate-c.


4 files changed, 35 insertions(+), 10 deletions(-)

build.zig+1-1
......@@ -442,7 +442,7 @@ pub fn build(b: *std.Build) !void {
442442 test_step.dependOn(check_fmt);
443443
444444 const test_cases_step = b.step("test-cases", "Run the main compiler test cases");
445 try tests.addCases(b, test_cases_step, test_filters, target, .{
445 try tests.addCases(b, test_cases_step, test_filters, test_target_filters, target, .{
446446 .skip_translate_c = skip_translate_c,
447447 .skip_run_translated_c = skip_run_translated_c,
448448 }, .{
test/src/Cases.zig+12-2
......@@ -539,13 +539,14 @@ pub fn lowerToTranslateCSteps(
539539 b: *std.Build,
540540 parent_step: *std.Build.Step,
541541 test_filters: []const []const u8,
542 test_target_filters: []const []const u8,
542543 target: std.Build.ResolvedTarget,
543544 translate_c_options: TranslateCOptions,
544545) void {
545546 const tests = @import("../tests.zig");
546547 const test_translate_c_step = b.step("test-translate-c", "Run the C translation tests");
547548 if (!translate_c_options.skip_translate_c) {
548 tests.addTranslateCTests(b, test_translate_c_step, test_filters);
549 tests.addTranslateCTests(b, test_translate_c_step, test_filters, test_target_filters);
549550 parent_step.dependOn(test_translate_c_step);
550551 }
551552
......@@ -620,6 +621,7 @@ pub fn lowerToBuildSteps(
620621 b: *std.Build,
621622 parent_step: *std.Build.Step,
622623 test_filters: []const []const u8,
624 test_target_filters: []const []const u8,
623625) void {
624626 const host = std.zig.system.resolveTargetQuery(.{}) catch |err|
625627 std.debug.panic("unable to detect native host: {s}\n", .{@errorName(err)});
......@@ -648,6 +650,14 @@ pub fn lowerToBuildSteps(
648650 if (std.mem.indexOf(u8, case.name, test_filter)) |_| break;
649651 } else if (test_filters.len > 0) continue;
650652
653 const triple_txt = case.target.result.zigTriple(b.allocator) catch @panic("OOM");
654
655 if (test_target_filters.len > 0) {
656 for (test_target_filters) |filter| {
657 if (std.mem.indexOf(u8, triple_txt, filter) != null) break;
658 } else continue;
659 }
660
651661 const writefiles = b.addWriteFiles();
652662 var file_sources = std.StringHashMap(std.Build.LazyPath).init(b.allocator);
653663 defer file_sources.deinit();
......@@ -740,7 +750,7 @@ pub fn lowerToBuildSteps(
740750 "--",
741751 "-lc",
742752 "-target",
743 case.target.result.zigTriple(b.allocator) catch @panic("OOM"),
753 triple_txt,
744754 });
745755 run_c.addArtifactArg(artifact);
746756 break :run_step run_c;
test/src/TranslateC.zig+12-1
......@@ -2,6 +2,7 @@ b: *std.Build,
22step: *std.Build.Step,
33test_index: usize,
44test_filters: []const []const u8,
5test_target_filters: []const []const u8,
56
67const TestCase = struct {
78 name: []const u8,
......@@ -92,6 +93,16 @@ pub fn addCase(self: *TranslateCContext, case: *const TestCase) void {
9293 if (mem.indexOf(u8, annotated_case_name, test_filter)) |_| break;
9394 } else if (self.test_filters.len > 0) return;
9495
96 const target = b.resolveTargetQuery(case.target);
97
98 if (self.test_target_filters.len > 0) {
99 const triple_txt = target.result.zigTriple(b.allocator) catch @panic("OOM");
100
101 for (self.test_target_filters) |filter| {
102 if (std.mem.indexOf(u8, triple_txt, filter) != null) break;
103 } else return;
104 }
105
95106 const write_src = b.addWriteFiles();
96107 const first_src = case.sources.items[0];
97108 const root_source_file = write_src.add(first_src.filename, first_src.source);
......@@ -101,7 +112,7 @@ pub fn addCase(self: *TranslateCContext, case: *const TestCase) void {
101112
102113 const translate_c = b.addTranslateC(.{
103114 .root_source_file = root_source_file,
104 .target = b.resolveTargetQuery(case.target),
115 .target = target,
105116 .optimize = .Debug,
106117 });
107118
test/tests.zig+10-6
......@@ -1237,18 +1237,22 @@ pub fn addAssembleAndLinkTests(b: *std.Build, test_filters: []const []const u8,
12371237 return cases.step;
12381238}
12391239
1240pub fn addTranslateCTests(b: *std.Build, parent_step: *std.Build.Step, test_filters: []const []const u8) void {
1240pub fn addTranslateCTests(
1241 b: *std.Build,
1242 parent_step: *std.Build.Step,
1243 test_filters: []const []const u8,
1244 test_target_filters: []const []const u8,
1245) void {
12411246 const cases = b.allocator.create(TranslateCContext) catch @panic("OOM");
12421247 cases.* = TranslateCContext{
12431248 .b = b,
12441249 .step = parent_step,
12451250 .test_index = 0,
12461251 .test_filters = test_filters,
1252 .test_target_filters = test_target_filters,
12471253 };
12481254
12491255 translate_c.addCases(cases);
1250
1251 return;
12521256}
12531257
12541258pub fn addRunTranslatedCTests(
......@@ -1267,8 +1271,6 @@ pub fn addRunTranslatedCTests(
12671271 };
12681272
12691273 run_translated_c.addCases(cases);
1270
1271 return;
12721274}
12731275
12741276const ModuleTestOptions = struct {
......@@ -1565,6 +1567,7 @@ pub fn addCases(
15651567 b: *std.Build,
15661568 parent_step: *Step,
15671569 test_filters: []const []const u8,
1570 test_target_filters: []const []const u8,
15681571 target: std.Build.ResolvedTarget,
15691572 translate_c_options: @import("src/Cases.zig").TranslateCOptions,
15701573 build_options: @import("cases.zig").BuildOptions,
......@@ -1580,12 +1583,13 @@ pub fn addCases(
15801583 cases.addFromDir(dir, b);
15811584 try @import("cases.zig").addCases(&cases, build_options, b);
15821585
1583 cases.lowerToTranslateCSteps(b, parent_step, test_filters, target, translate_c_options);
1586 cases.lowerToTranslateCSteps(b, parent_step, test_filters, test_target_filters, target, translate_c_options);
15841587
15851588 cases.lowerToBuildSteps(
15861589 b,
15871590 parent_step,
15881591 test_filters,
1592 test_target_filters,
15891593 );
15901594}
15911595