authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-26 20:09:48-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-26 20:09:48-07:00
log4e53249d769346683d45d4a4cb4a437388f9e186
treed3b2fa77951f91e3936cbfd473d0638da2df5f59
parentea3db3274d890b7d00c907c037ffe203f41adbd3

test-cases harness: improve stage2 compatibility

* proper skip_stage1 mechanism that doesn't get side-stepped with manually added test cases. * avoid runtime-known function pointers. * check for type equality more simply without checking the type name.

1 files changed, 17 insertions(+), 30 deletions(-)

src/test.zig+17-30
......@@ -20,7 +20,7 @@ const enable_wasmtime: bool = build_options.enable_wasmtime;
2020const enable_darling: bool = build_options.enable_darling;
2121const enable_rosetta: bool = build_options.enable_rosetta;
2222const glibc_runtimes_dir: ?[]const u8 = build_options.glibc_runtimes_dir;
23const skip_stage1 = build_options.skip_stage1;
23const skip_stage1 = builtin.zig_backend != .stage1 or build_options.skip_stage1;
2424
2525const hr = "=" ** 80;
2626
......@@ -233,11 +233,11 @@ const TestManifest = struct {
233233 fn ConfigValueIterator(comptime T: type) type {
234234 return struct {
235235 inner: std.mem.SplitIterator(u8),
236 parse_fn: ParseFn(T),
237236
238237 fn next(self: *@This()) !?T {
239238 const next_raw = self.inner.next() orelse return null;
240 return try self.parse_fn(next_raw);
239 const parseFn = getDefaultParser(T);
240 return try parseFn(next_raw);
241241 }
242242 };
243243 }
......@@ -313,27 +313,17 @@ const TestManifest = struct {
313313 return manifest;
314314 }
315315
316 fn getConfigForKeyCustomParser(
316 fn getConfigForKey(
317317 self: TestManifest,
318318 key: []const u8,
319319 comptime T: type,
320 parse_fn: ParseFn(T),
321320 ) ConfigValueIterator(T) {
322321 const bytes = self.config_map.get(key) orelse TestManifestConfigDefaults.get(self.@"type", key);
323322 return ConfigValueIterator(T){
324323 .inner = std.mem.split(u8, bytes, ","),
325 .parse_fn = parse_fn,
326324 };
327325 }
328326
329 fn getConfigForKey(
330 self: TestManifest,
331 key: []const u8,
332 comptime T: type,
333 ) ConfigValueIterator(T) {
334 return self.getConfigForKeyCustomParser(key, T, getDefaultParser(T));
335 }
336
337327 fn getConfigForKeyAlloc(
338328 self: TestManifest,
339329 allocator: Allocator,
......@@ -377,6 +367,15 @@ const TestManifest = struct {
377367 }
378368
379369 fn getDefaultParser(comptime T: type) ParseFn(T) {
370 if (T == CrossTarget) return struct {
371 fn parse(str: []const u8) anyerror!T {
372 var opts = CrossTarget.ParseOptions{
373 .arch_os_abi = str,
374 };
375 return try CrossTarget.parse(opts);
376 }
377 }.parse;
378
380379 switch (@typeInfo(T)) {
381380 .Int => return struct {
382381 fn parse(str: []const u8) anyerror!T {
......@@ -397,14 +396,7 @@ const TestManifest = struct {
397396 };
398397 }
399398 }.parse,
400 .Struct => if (comptime std.mem.eql(u8, @typeName(T), "CrossTarget")) return struct {
401 fn parse(str: []const u8) anyerror!T {
402 var opts = CrossTarget.ParseOptions{
403 .arch_os_abi = str,
404 };
405 return try CrossTarget.parse(opts);
406 }
407 }.parse else @compileError("no default parser for " ++ @typeName(T)),
399 .Struct => @compileError("no default parser for " ++ @typeName(T)),
408400 else => @compileError("no default parser for " ++ @typeName(T)),
409401 }
410402 }
......@@ -884,8 +876,6 @@ pub const TestContext = struct {
884876 src: [:0]const u8,
885877 expected_errors: []const []const u8,
886878 ) void {
887 if (skip_stage1) return;
888
889879 const case = ctx.addObj(name, .{});
890880 case.backend = .stage1;
891881 case.addError(src, expected_errors);
......@@ -897,8 +887,6 @@ pub const TestContext = struct {
897887 src: [:0]const u8,
898888 expected_errors: []const []const u8,
899889 ) void {
900 if (skip_stage1) return;
901
902890 const case = ctx.addTest(name, .{});
903891 case.backend = .stage1;
904892 case.addError(src, expected_errors);
......@@ -910,8 +898,6 @@ pub const TestContext = struct {
910898 src: [:0]const u8,
911899 expected_errors: []const []const u8,
912900 ) void {
913 if (skip_stage1) return;
914
915901 const case = ctx.addExe(name, .{});
916902 case.backend = .stage1;
917903 case.addError(src, expected_errors);
......@@ -1143,8 +1129,6 @@ pub const TestContext = struct {
11431129
11441130 // Cross-product to get all possible test combinations
11451131 for (backends) |backend| {
1146 if (backend == .stage1 and skip_stage1) continue;
1147
11481132 for (targets) |target| {
11491133 const name = try std.fmt.allocPrint(ctx.arena, "{s} ({s}, {s})", .{
11501134 name_prefix,
......@@ -1276,6 +1260,9 @@ pub const TestContext = struct {
12761260 if (!build_options.have_llvm and case.backend == .llvm)
12771261 continue;
12781262
1263 if (skip_stage1 and case.backend == .stage1)
1264 continue;
1265
12791266 if (build_options.test_filter) |test_filter| {
12801267 if (std.mem.indexOf(u8, case.name, test_filter) == null) continue;
12811268 }