authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-30 14:55:26-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-30 14:55:26-04:00
log0e9bdb44a6ca022558ed703749353c76e796dc35
treeaeedbc3a20024875139cf892fa6dbdf4f08e35d0
parent052b4ae9415596e0b6b6c32b9b4f2d3ff8c9e953

test suite cross-compile builds tests for other targets


5 files changed, 83 insertions(+), 12 deletions(-)

src/link.cpp+3
......@@ -573,6 +573,9 @@ static void get_darwin_platform(LinkJob *lj, DarwinPlatform *platform) {
573573 platform->kind = MacOS;
574574 } else if (g->mios_version_min) {
575575 platform->kind = IPhoneOS;
576 } else if (g->zig_target.os == ZigLLVM_MacOSX) {
577 platform->kind = MacOS;
578 g->mmacosx_version_min = buf_create_from_str("10.10");
576579 } else {
577580 zig_panic("unable to infer -mmacosx-version-min or -mios-version-min");
578581 }
src/main.cpp+10
......@@ -676,6 +676,16 @@ int main(int argc, char **argv) {
676676 } else if (cmd == CmdTest) {
677677 codegen_build(g);
678678 codegen_link(g, "./test");
679
680 ZigTarget native;
681 get_native_target(&native);
682 bool is_native_target = target == nullptr || (target->os == native.os &&
683 target->arch.arch == native.arch.arch && target->arch.sub_arch == native.arch.sub_arch);
684 if (!is_native_target) {
685 fprintf(stderr, "Skipping execution of non-native test binary.\n");
686 return 0;
687 }
688
679689 ZigList<const char *> args = {0};
680690 Termination term;
681691 os_spawn_process("./test", args, &term);
src/target.cpp+1-1
......@@ -482,6 +482,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
482482 }
483483 case ZigLLVM_Linux:
484484 case ZigLLVM_Darwin:
485 case ZigLLVM_MacOSX:
485486 switch (id) {
486487 case CIntTypeShort:
487488 case CIntTypeUShort:
......@@ -521,7 +522,6 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
521522 case ZigLLVM_IOS:
522523 case ZigLLVM_KFreeBSD:
523524 case ZigLLVM_Lv2:
524 case ZigLLVM_MacOSX:
525525 case ZigLLVM_NetBSD:
526526 case ZigLLVM_OpenBSD:
527527 case ZigLLVM_Solaris:
std/build.zig+28
......@@ -1027,6 +1027,7 @@ pub const TestStep = struct {
10271027 link_libs: BufSet,
10281028 name_prefix: []const u8,
10291029 filter: ?[]const u8,
1030 target: Target,
10301031
10311032 pub fn init(builder: &Builder, root_src: []const u8) -> TestStep {
10321033 const step_name = builder.fmt("test {}", root_src);
......@@ -1039,6 +1040,7 @@ pub const TestStep = struct {
10391040 .name_prefix = "",
10401041 .filter = null,
10411042 .link_libs = BufSet.init(builder.allocator),
1043 .target = Target.Native,
10421044 }
10431045 }
10441046
......@@ -1062,6 +1064,18 @@ pub const TestStep = struct {
10621064 self.filter = text;
10631065 }
10641066
1067 pub fn setTarget(self: &TestStep, target_arch: builtin.Arch, target_os: builtin.Os,
1068 target_environ: builtin.Environ)
1069 {
1070 self.target = Target.Cross {
1071 CrossTarget {
1072 .arch = target_arch,
1073 .os = target_os,
1074 .environ = target_environ,
1075 }
1076 };
1077 }
1078
10651079 fn make(step: &Step) -> %void {
10661080 const self = @fieldParentPtr(TestStep, "step", step);
10671081 const builder = self.builder;
......@@ -1082,6 +1096,20 @@ pub const TestStep = struct {
10821096 builtin.Mode.ReleaseFast => %%zig_args.append("--release-fast"),
10831097 }
10841098
1099 switch (self.target) {
1100 Target.Native => {},
1101 Target.Cross => |cross_target| {
1102 %%zig_args.append("--target-arch");
1103 %%zig_args.append(@enumTagName(cross_target.arch));
1104
1105 %%zig_args.append("--target-os");
1106 %%zig_args.append(@enumTagName(cross_target.os));
1107
1108 %%zig_args.append("--target-environ");
1109 %%zig_args.append(@enumTagName(cross_target.environ));
1110 },
1111 }
1112
10851113 if (self.filter) |filter| {
10861114 %%zig_args.append("--test-filter");
10871115 %%zig_args.append(filter);
test/tests.zig+41-11
......@@ -9,7 +9,8 @@ const io = std.io;
99const mem = std.mem;
1010const fmt = std.fmt;
1111const ArrayList = std.ArrayList;
12const Mode = @import("builtin").Mode;
12const builtin = @import("builtin");
13const Mode = builtin.Mode;
1314
1415const compare_output = @import("compare_output.zig");
1516const build_examples = @import("build_examples.zig");
......@@ -18,6 +19,25 @@ const assemble_and_link = @import("assemble_and_link.zig");
1819const debug_safety = @import("debug_safety.zig");
1920const parseh = @import("parseh.zig");
2021
22const TestTarget = struct {
23 os: builtin.Os,
24 arch: builtin.Arch,
25 environ: builtin.Environ,
26};
27
28const test_targets = []TestTarget {
29 TestTarget {
30 .os = builtin.Os.linux,
31 .arch = builtin.Arch.x86_64,
32 .environ = builtin.Environ.gnu,
33 },
34 TestTarget {
35 .os = builtin.Os.macosx,
36 .arch = builtin.Arch.x86_64,
37 .environ = builtin.Environ.unknown,
38 },
39};
40
2141error TestFailed;
2242
2343pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
......@@ -121,17 +141,27 @@ pub fn addPkgTestsRaw(b: &build.Builder, test_filter: ?[]const u8, root_src: []c
121141{
122142 const libc_bools = if (always_link_libc) []bool{true} else []bool{false, true};
123143 const step = b.step(b.fmt("test-{}", name), desc);
124 for ([]Mode{Mode.Debug, Mode.ReleaseFast}) |mode| {
125 for (libc_bools) |link_libc| {
126 const these_tests = b.addTest(root_src);
127 these_tests.setNamePrefix(b.fmt("{}-{}-{} ", name, @enumTagName(mode),
128 if (link_libc) "c" else "bare"));
129 these_tests.setFilter(test_filter);
130 these_tests.setBuildMode(mode);
131 if (link_libc) {
132 these_tests.linkSystemLibrary("c");
144 for (test_targets) |test_target| {
145 const is_native = (test_target.os == builtin.os and test_target.arch == builtin.arch);
146 for ([]Mode{Mode.Debug, Mode.ReleaseFast}) |mode| {
147 for (libc_bools) |link_libc| {
148 if (link_libc and !is_native) {
149 // don't assume we have a cross-compiling libc set up
150 continue;
151 }
152 const these_tests = b.addTest(root_src);
153 these_tests.setNamePrefix(b.fmt("{}-{}-{}-{}-{} ", name, @enumTagName(test_target.os),
154 @enumTagName(test_target.arch), @enumTagName(mode), if (link_libc) "c" else "bare"));
155 these_tests.setFilter(test_filter);
156 these_tests.setBuildMode(mode);
157 if (!is_native) {
158 these_tests.setTarget(test_target.arch, test_target.os, test_target.environ);
159 }
160 if (link_libc) {
161 these_tests.linkSystemLibrary("c");
162 }
163 step.dependOn(&these_tests.step);
133164 }
134 step.dependOn(&these_tests.step);
135165 }
136166 }
137167 return step;