authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-26 18:26:23-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-01 19:49:07-07:00
logc8c32a056989cc669008f1fc295a29d55b753cc0
treed4543479180184bd3bd9ff2fdaf10dd97aecb3ab
parentbeed47e8c3792abf87529c705726d9745546648e

update stack trace tests to account for new defaults

ReleaseSafe optimization mode now defaults error tracing to false.

2 files changed, 59 insertions(+), 66 deletions(-)

test/src/StackTrace.zig+29-49
......@@ -5,44 +5,33 @@ test_filter: ?[]const u8,
55optimize_modes: []const OptimizeMode,
66check_exe: *std.Build.Step.Compile,
77
8const Expect = [@typeInfo(OptimizeMode).Enum.fields.len][]const u8;
8const Config = struct {
9 name: []const u8,
10 source: []const u8,
11 Debug: ?PerMode = null,
12 ReleaseSmall: ?PerMode = null,
13 ReleaseSafe: ?PerMode = null,
14 ReleaseFast: ?PerMode = null,
915
10pub fn addCase(self: *StackTrace, config: anytype) void {
11 if (@hasField(@TypeOf(config), "exclude")) {
12 if (config.exclude.exclude()) return;
13 }
14 if (@hasField(@TypeOf(config), "exclude_arch")) {
15 const exclude_arch: []const std.Target.Cpu.Arch = &config.exclude_arch;
16 for (exclude_arch) |arch| if (arch == builtin.cpu.arch) return;
17 }
18 if (@hasField(@TypeOf(config), "exclude_os")) {
19 const exclude_os: []const std.Target.Os.Tag = &config.exclude_os;
20 for (exclude_os) |os| if (os == builtin.os.tag) return;
21 }
22 for (self.optimize_modes) |optimize_mode| {
23 switch (optimize_mode) {
24 .Debug => {
25 if (@hasField(@TypeOf(config), "Debug")) {
26 self.addExpect(config.name, config.source, optimize_mode, config.Debug);
27 }
28 },
29 .ReleaseSafe => {
30 if (@hasField(@TypeOf(config), "ReleaseSafe")) {
31 self.addExpect(config.name, config.source, optimize_mode, config.ReleaseSafe);
32 }
33 },
34 .ReleaseFast => {
35 if (@hasField(@TypeOf(config), "ReleaseFast")) {
36 self.addExpect(config.name, config.source, optimize_mode, config.ReleaseFast);
37 }
38 },
39 .ReleaseSmall => {
40 if (@hasField(@TypeOf(config), "ReleaseSmall")) {
41 self.addExpect(config.name, config.source, optimize_mode, config.ReleaseSmall);
42 }
43 },
44 }
45 }
16 const PerMode = struct {
17 expect: []const u8,
18 exclude_os: []const std.Target.Os.Tag = &.{},
19 error_tracing: ?bool = null,
20 };
21};
22
23pub fn addCase(self: *StackTrace, config: Config) void {
24 if (config.Debug) |per_mode|
25 self.addExpect(config.name, config.source, .Debug, per_mode);
26
27 if (config.ReleaseSmall) |per_mode|
28 self.addExpect(config.name, config.source, .ReleaseSmall, per_mode);
29
30 if (config.ReleaseFast) |per_mode|
31 self.addExpect(config.name, config.source, .ReleaseFast, per_mode);
32
33 if (config.ReleaseSafe) |per_mode|
34 self.addExpect(config.name, config.source, .ReleaseSafe, per_mode);
4635}
4736
4837fn addExpect(
......@@ -50,19 +39,9 @@ fn addExpect(
5039 name: []const u8,
5140 source: []const u8,
5241 optimize_mode: OptimizeMode,
53 mode_config: anytype,
42 mode_config: Config.PerMode,
5443) void {
55 if (@hasField(@TypeOf(mode_config), "exclude")) {
56 if (mode_config.exclude.exclude()) return;
57 }
58 if (@hasField(@TypeOf(mode_config), "exclude_arch")) {
59 const exclude_arch: []const std.Target.Cpu.Arch = &mode_config.exclude_arch;
60 for (exclude_arch) |arch| if (arch == builtin.cpu.arch) return;
61 }
62 if (@hasField(@TypeOf(mode_config), "exclude_os")) {
63 const exclude_os: []const std.Target.Os.Tag = &mode_config.exclude_os;
64 for (exclude_os) |os| if (os == builtin.os.tag) return;
65 }
44 for (mode_config.exclude_os) |tag| if (tag == builtin.os.tag) return;
6645
6746 const b = self.b;
6847 const annotated_case_name = fmt.allocPrint(b.allocator, "check {s} ({s})", .{
......@@ -78,6 +57,7 @@ fn addExpect(
7857 .root_source_file = write_src.files.items[0].getPath(),
7958 .optimize = optimize_mode,
8059 .target = b.host,
60 .error_tracing = mode_config.error_tracing,
8161 });
8262
8363 const run = b.addRunArtifact(exe);
test/stack_traces.zig+30-17
......@@ -20,7 +20,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
2020 ,
2121 },
2222 .ReleaseSafe = .{
23 .exclude_os = .{
23 .exclude_os = &.{
2424 .windows, // TODO
2525 .linux, // defeated by aggressive inlining
2626 },
......@@ -31,6 +31,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
3131 \\ ^
3232 \\
3333 ,
34 .error_tracing = true,
3435 },
3536 .ReleaseFast = .{
3637 .expect =
......@@ -70,7 +71,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
7071 ,
7172 },
7273 .ReleaseSafe = .{
73 .exclude_os = .{
74 .exclude_os = &.{
7475 .windows, // TODO
7576 },
7677 .expect =
......@@ -83,6 +84,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
8384 \\ ^
8485 \\
8586 ,
87 .error_tracing = true,
8688 },
8789 .ReleaseFast = .{
8890 .expect =
......@@ -125,7 +127,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
125127 ,
126128 },
127129 .ReleaseSafe = .{
128 .exclude_os = .{
130 .exclude_os = &.{
129131 .windows, // TODO
130132 .linux, // defeated by aggressive inlining
131133 },
......@@ -136,6 +138,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
136138 \\ ^
137139 \\
138140 ,
141 .error_tracing = true,
139142 },
140143 .ReleaseFast = .{
141144 .expect =
......@@ -176,7 +179,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
176179 ,
177180 },
178181 .ReleaseSafe = .{
179 .exclude_os = .{
182 .exclude_os = &.{
180183 .windows, // TODO
181184 .linux, // defeated by aggressive inlining
182185 },
......@@ -187,6 +190,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
187190 \\ ^
188191 \\
189192 ,
193 .error_tracing = true,
190194 },
191195 .ReleaseFast = .{
192196 .expect =
......@@ -230,7 +234,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
230234 ,
231235 },
232236 .ReleaseSafe = .{
233 .exclude_os = .{
237 .exclude_os = &.{
234238 .windows, // TODO
235239 .linux, // defeated by aggressive inlining
236240 },
......@@ -244,6 +248,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
244248 \\ ^
245249 \\
246250 ,
251 .error_tracing = true,
247252 },
248253 .ReleaseFast = .{
249254 .expect =
......@@ -286,7 +291,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
286291 ,
287292 },
288293 .ReleaseSafe = .{
289 .exclude_os = .{
294 .exclude_os = &.{
290295 .windows, // TODO
291296 .linux, // defeated by aggressive inlining
292297 },
......@@ -297,6 +302,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
297302 \\ ^
298303 \\
299304 ,
305 .error_tracing = true,
300306 },
301307 .ReleaseFast = .{
302308 .expect =
......@@ -336,7 +342,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
336342 ,
337343 },
338344 .ReleaseSafe = .{
339 .exclude_os = .{
345 .exclude_os = &.{
340346 .windows, // TODO
341347 .linux, // defeated by aggressive inlining
342348 },
......@@ -350,6 +356,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
350356 \\ ^
351357 \\
352358 ,
359 .error_tracing = true,
353360 },
354361 .ReleaseFast = .{
355362 .expect =
......@@ -391,7 +398,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
391398 ,
392399 },
393400 .ReleaseSafe = .{
394 .exclude_os = .{
401 .exclude_os = &.{
395402 .windows, // TODO
396403 .linux, // defeated by aggressive inlining
397404 },
......@@ -402,6 +409,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
402409 \\ ^
403410 \\
404411 ,
412 .error_tracing = true,
405413 },
406414 .ReleaseFast = .{
407415 .expect =
......@@ -461,7 +469,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
461469 ,
462470 },
463471 .ReleaseSafe = .{
464 .exclude_os = .{
472 .exclude_os = &.{
465473 .windows, // TODO
466474 .linux, // defeated by aggressive inlining
467475 },
......@@ -478,6 +486,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
478486 \\ ^
479487 \\
480488 ,
489 .error_tracing = true,
481490 },
482491 .ReleaseFast = .{
483492 .expect =
......@@ -531,7 +540,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
531540 ,
532541 },
533542 .ReleaseSafe = .{
534 .exclude_os = .{
543 .exclude_os = &.{
535544 .windows, // TODO
536545 },
537546 .expect =
......@@ -547,6 +556,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
547556 \\ ^
548557 \\
549558 ,
559 .error_tracing = true,
550560 },
551561 .ReleaseFast = .{
552562 .expect =
......@@ -595,7 +605,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
595605 ,
596606 },
597607 .ReleaseSafe = .{
598 .exclude_os = .{
608 .exclude_os = &.{
599609 .windows, // TODO
600610 },
601611 .expect =
......@@ -611,6 +621,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
611621 \\ ^
612622 \\
613623 ,
624 .error_tracing = true,
614625 },
615626 .ReleaseFast = .{
616627 .expect =
......@@ -659,7 +670,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
659670 ,
660671 },
661672 .ReleaseSafe = .{
662 .exclude_os = .{
673 .exclude_os = &.{
663674 .windows, // TODO
664675 },
665676 .expect =
......@@ -675,6 +686,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
675686 \\ ^
676687 \\
677688 ,
689 .error_tracing = true,
678690 },
679691 .ReleaseFast = .{
680692 .expect =
......@@ -728,7 +740,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
728740 ,
729741 },
730742 .ReleaseSafe = .{
731 .exclude_os = .{
743 .exclude_os = &.{
732744 .windows, // TODO
733745 },
734746 .expect =
......@@ -747,6 +759,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
747759 \\ ^
748760 \\
749761 ,
762 .error_tracing = true,
750763 },
751764 .ReleaseFast = .{
752765 .expect =
......@@ -763,10 +776,6 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
763776 });
764777
765778 cases.addCase(.{
766 .exclude_os = .{
767 .openbsd, // integer overflow
768 .windows, // TODO intermittent failures
769 },
770779 .name = "dumpCurrentStackTrace",
771780 .source =
772781 \\const std = @import("std");
......@@ -783,6 +792,10 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
783792 \\}
784793 ,
785794 .Debug = .{
795 .exclude_os = &.{
796 .openbsd, // integer overflow
797 .windows, // TODO intermittent failures
798 },
786799 .expect =
787800 \\source.zig:7:8: [address] in foo (test)
788801 \\ bar();