authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-11-24 20:43:11+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-11-24 22:11:17+01:00
logfefcdc56735744efaa53d26adc44b2c4ab1c8abb
tree5e358d14a329a7f62cf59d8b8bec3f110b1e7392
parent9d10246a809752be6952ba3d9021e8cbfc1931a1
signature Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

test: Allow setting PIC/PIE in test cases.


1 files changed, 20 insertions(+), 1 deletions(-)

test/src/Cases.zig+20-1
......@@ -88,6 +88,8 @@ pub const Case = struct {
8888 expect_exact: bool = false,
8989 backend: Backend = .stage2,
9090 link_libc: bool = false,
91 pic: ?bool = null,
92 pie: ?bool = null,
9193
9294 deps: std.ArrayList(DepModule),
9395
......@@ -425,6 +427,8 @@ fn addFromDirInner(
425427 const is_test = try manifest.getConfigForKeyAssertSingle("is_test", bool);
426428 const link_libc = try manifest.getConfigForKeyAssertSingle("link_libc", bool);
427429 const output_mode = try manifest.getConfigForKeyAssertSingle("output_mode", std.builtin.OutputMode);
430 const pic = try manifest.getConfigForKeyAssertSingle("pic", ?bool);
431 const pie = try manifest.getConfigForKeyAssertSingle("pie", ?bool);
428432
429433 if (manifest.type == .translate_c) {
430434 for (c_frontends) |c_frontend| {
......@@ -488,6 +492,8 @@ fn addFromDirInner(
488492 .is_test = is_test,
489493 .output_mode = output_mode,
490494 .link_libc = link_libc,
495 .pic = pic,
496 .pie = pie,
491497 .deps = std.ArrayList(DepModule).init(ctx.cases.allocator),
492498 });
493499 try cases.append(next);
......@@ -695,6 +701,8 @@ pub fn lowerToBuildSteps(
695701 };
696702
697703 if (case.link_libc) artifact.linkLibC();
704 if (case.pic) |pic| artifact.root_module.pic = pic;
705 if (case.pie) |pie| artifact.pie = pie;
698706
699707 switch (case.backend) {
700708 .stage1 => continue,
......@@ -958,6 +966,10 @@ const TestManifestConfigDefaults = struct {
958966 return "false";
959967 } else if (std.mem.eql(u8, key, "c_frontend")) {
960968 return "clang";
969 } else if (std.mem.eql(u8, key, "pic")) {
970 return "null";
971 } else if (std.mem.eql(u8, key, "pie")) {
972 return "null";
961973 } else unreachable;
962974 }
963975};
......@@ -991,6 +1003,8 @@ const TestManifest = struct {
9911003 .{ "c_frontend", {} },
9921004 .{ "link_libc", {} },
9931005 .{ "backend", {} },
1006 .{ "pic", {} },
1007 .{ "pie", {} },
9941008 });
9951009
9961010 const Type = enum {
......@@ -1219,7 +1233,12 @@ const TestManifest = struct {
12191233 };
12201234 }
12211235 }.parse,
1222 .@"struct" => @compileError("no default parser for " ++ @typeName(T)),
1236 .optional => |o| return struct {
1237 fn parse(str: []const u8) anyerror!T {
1238 if (std.mem.eql(u8, str, "null")) return null;
1239 return try getDefaultParser(o.child)(str);
1240 }
1241 }.parse,
12231242 else => @compileError("no default parser for " ++ @typeName(T)),
12241243 }
12251244 }