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 {...@@ -442,7 +442,7 @@ pub fn build(b: *std.Build) !void {
442 test_step.dependOn(check_fmt);442 test_step.dependOn(check_fmt);
443443
444 const test_cases_step = b.step("test-cases", "Run the main compiler test cases");444 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, .{
446 .skip_translate_c = skip_translate_c,446 .skip_translate_c = skip_translate_c,
447 .skip_run_translated_c = skip_run_translated_c,447 .skip_run_translated_c = skip_run_translated_c,
448 }, .{448 }, .{
test/src/Cases.zig+12-2
...@@ -539,13 +539,14 @@ pub fn lowerToTranslateCSteps(...@@ -539,13 +539,14 @@ pub fn lowerToTranslateCSteps(
539 b: *std.Build,539 b: *std.Build,
540 parent_step: *std.Build.Step,540 parent_step: *std.Build.Step,
541 test_filters: []const []const u8,541 test_filters: []const []const u8,
542 test_target_filters: []const []const u8,
542 target: std.Build.ResolvedTarget,543 target: std.Build.ResolvedTarget,
543 translate_c_options: TranslateCOptions,544 translate_c_options: TranslateCOptions,
544) void {545) void {
545 const tests = @import("../tests.zig");546 const tests = @import("../tests.zig");
546 const test_translate_c_step = b.step("test-translate-c", "Run the C translation tests");547 const test_translate_c_step = b.step("test-translate-c", "Run the C translation tests");
547 if (!translate_c_options.skip_translate_c) {548 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);
549 parent_step.dependOn(test_translate_c_step);550 parent_step.dependOn(test_translate_c_step);
550 }551 }
551552
...@@ -620,6 +621,7 @@ pub fn lowerToBuildSteps(...@@ -620,6 +621,7 @@ pub fn lowerToBuildSteps(
620 b: *std.Build,621 b: *std.Build,
621 parent_step: *std.Build.Step,622 parent_step: *std.Build.Step,
622 test_filters: []const []const u8,623 test_filters: []const []const u8,
624 test_target_filters: []const []const u8,
623) void {625) void {
624 const host = std.zig.system.resolveTargetQuery(.{}) catch |err|626 const host = std.zig.system.resolveTargetQuery(.{}) catch |err|
625 std.debug.panic("unable to detect native host: {s}\n", .{@errorName(err)});627 std.debug.panic("unable to detect native host: {s}\n", .{@errorName(err)});
...@@ -648,6 +650,14 @@ pub fn lowerToBuildSteps(...@@ -648,6 +650,14 @@ pub fn lowerToBuildSteps(
648 if (std.mem.indexOf(u8, case.name, test_filter)) |_| break;650 if (std.mem.indexOf(u8, case.name, test_filter)) |_| break;
649 } else if (test_filters.len > 0) continue;651 } 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
651 const writefiles = b.addWriteFiles();661 const writefiles = b.addWriteFiles();
652 var file_sources = std.StringHashMap(std.Build.LazyPath).init(b.allocator);662 var file_sources = std.StringHashMap(std.Build.LazyPath).init(b.allocator);
653 defer file_sources.deinit();663 defer file_sources.deinit();
...@@ -740,7 +750,7 @@ pub fn lowerToBuildSteps(...@@ -740,7 +750,7 @@ pub fn lowerToBuildSteps(
740 "--",750 "--",
741 "-lc",751 "-lc",
742 "-target",752 "-target",
743 case.target.result.zigTriple(b.allocator) catch @panic("OOM"),753 triple_txt,
744 });754 });
745 run_c.addArtifactArg(artifact);755 run_c.addArtifactArg(artifact);
746 break :run_step run_c;756 break :run_step run_c;
test/src/TranslateC.zig+12-1
...@@ -2,6 +2,7 @@ b: *std.Build,...@@ -2,6 +2,7 @@ b: *std.Build,
2step: *std.Build.Step,2step: *std.Build.Step,
3test_index: usize,3test_index: usize,
4test_filters: []const []const u8,4test_filters: []const []const u8,
5test_target_filters: []const []const u8,
56
6const TestCase = struct {7const TestCase = struct {
7 name: []const u8,8 name: []const u8,
...@@ -92,6 +93,16 @@ pub fn addCase(self: *TranslateCContext, case: *const TestCase) void {...@@ -92,6 +93,16 @@ pub fn addCase(self: *TranslateCContext, case: *const TestCase) void {
92 if (mem.indexOf(u8, annotated_case_name, test_filter)) |_| break;93 if (mem.indexOf(u8, annotated_case_name, test_filter)) |_| break;
93 } else if (self.test_filters.len > 0) return;94 } 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
95 const write_src = b.addWriteFiles();106 const write_src = b.addWriteFiles();
96 const first_src = case.sources.items[0];107 const first_src = case.sources.items[0];
97 const root_source_file = write_src.add(first_src.filename, first_src.source);108 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 {...@@ -101,7 +112,7 @@ pub fn addCase(self: *TranslateCContext, case: *const TestCase) void {
101112
102 const translate_c = b.addTranslateC(.{113 const translate_c = b.addTranslateC(.{
103 .root_source_file = root_source_file,114 .root_source_file = root_source_file,
104 .target = b.resolveTargetQuery(case.target),115 .target = target,
105 .optimize = .Debug,116 .optimize = .Debug,
106 });117 });
107118
test/tests.zig+10-6
...@@ -1237,18 +1237,22 @@ pub fn addAssembleAndLinkTests(b: *std.Build, test_filters: []const []const u8,...@@ -1237,18 +1237,22 @@ pub fn addAssembleAndLinkTests(b: *std.Build, test_filters: []const []const u8,
1237 return cases.step;1237 return cases.step;
1238}1238}
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 {
1241 const cases = b.allocator.create(TranslateCContext) catch @panic("OOM");1246 const cases = b.allocator.create(TranslateCContext) catch @panic("OOM");
1242 cases.* = TranslateCContext{1247 cases.* = TranslateCContext{
1243 .b = b,1248 .b = b,
1244 .step = parent_step,1249 .step = parent_step,
1245 .test_index = 0,1250 .test_index = 0,
1246 .test_filters = test_filters,1251 .test_filters = test_filters,
1252 .test_target_filters = test_target_filters,
1247 };1253 };
12481254
1249 translate_c.addCases(cases);1255 translate_c.addCases(cases);
1250
1251 return;
1252}1256}
12531257
1254pub fn addRunTranslatedCTests(1258pub fn addRunTranslatedCTests(
...@@ -1267,8 +1271,6 @@ pub fn addRunTranslatedCTests(...@@ -1267,8 +1271,6 @@ pub fn addRunTranslatedCTests(
1267 };1271 };
12681272
1269 run_translated_c.addCases(cases);1273 run_translated_c.addCases(cases);
1270
1271 return;
1272}1274}
12731275
1274const ModuleTestOptions = struct {1276const ModuleTestOptions = struct {
...@@ -1565,6 +1567,7 @@ pub fn addCases(...@@ -1565,6 +1567,7 @@ pub fn addCases(
1565 b: *std.Build,1567 b: *std.Build,
1566 parent_step: *Step,1568 parent_step: *Step,
1567 test_filters: []const []const u8,1569 test_filters: []const []const u8,
1570 test_target_filters: []const []const u8,
1568 target: std.Build.ResolvedTarget,1571 target: std.Build.ResolvedTarget,
1569 translate_c_options: @import("src/Cases.zig").TranslateCOptions,1572 translate_c_options: @import("src/Cases.zig").TranslateCOptions,
1570 build_options: @import("cases.zig").BuildOptions,1573 build_options: @import("cases.zig").BuildOptions,
...@@ -1580,12 +1583,13 @@ pub fn addCases(...@@ -1580,12 +1583,13 @@ pub fn addCases(
1580 cases.addFromDir(dir, b);1583 cases.addFromDir(dir, b);
1581 try @import("cases.zig").addCases(&cases, build_options, b);1584 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
1585 cases.lowerToBuildSteps(1588 cases.lowerToBuildSteps(
1586 b,1589 b,
1587 parent_step,1590 parent_step,
1588 test_filters,1591 test_filters,
1592 test_target_filters,
1589 );1593 );
1590}1594}
15911595