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) {...@@ -573,6 +573,9 @@ static void get_darwin_platform(LinkJob *lj, DarwinPlatform *platform) {
573 platform->kind = MacOS;573 platform->kind = MacOS;
574 } else if (g->mios_version_min) {574 } else if (g->mios_version_min) {
575 platform->kind = IPhoneOS;575 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");
576 } else {579 } else {
577 zig_panic("unable to infer -mmacosx-version-min or -mios-version-min");580 zig_panic("unable to infer -mmacosx-version-min or -mios-version-min");
578 }581 }
src/main.cpp+10
...@@ -676,6 +676,16 @@ int main(int argc, char **argv) {...@@ -676,6 +676,16 @@ int main(int argc, char **argv) {
676 } else if (cmd == CmdTest) {676 } else if (cmd == CmdTest) {
677 codegen_build(g);677 codegen_build(g);
678 codegen_link(g, "./test");678 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
679 ZigList<const char *> args = {0};689 ZigList<const char *> args = {0};
680 Termination term;690 Termination term;
681 os_spawn_process("./test", args, &term);691 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) {...@@ -482,6 +482,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
482 }482 }
483 case ZigLLVM_Linux:483 case ZigLLVM_Linux:
484 case ZigLLVM_Darwin:484 case ZigLLVM_Darwin:
485 case ZigLLVM_MacOSX:
485 switch (id) {486 switch (id) {
486 case CIntTypeShort:487 case CIntTypeShort:
487 case CIntTypeUShort:488 case CIntTypeUShort:
...@@ -521,7 +522,6 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {...@@ -521,7 +522,6 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
521 case ZigLLVM_IOS:522 case ZigLLVM_IOS:
522 case ZigLLVM_KFreeBSD:523 case ZigLLVM_KFreeBSD:
523 case ZigLLVM_Lv2:524 case ZigLLVM_Lv2:
524 case ZigLLVM_MacOSX:
525 case ZigLLVM_NetBSD:525 case ZigLLVM_NetBSD:
526 case ZigLLVM_OpenBSD:526 case ZigLLVM_OpenBSD:
527 case ZigLLVM_Solaris:527 case ZigLLVM_Solaris:
std/build.zig+28
...@@ -1027,6 +1027,7 @@ pub const TestStep = struct {...@@ -1027,6 +1027,7 @@ pub const TestStep = struct {
1027 link_libs: BufSet,1027 link_libs: BufSet,
1028 name_prefix: []const u8,1028 name_prefix: []const u8,
1029 filter: ?[]const u8,1029 filter: ?[]const u8,
1030 target: Target,
10301031
1031 pub fn init(builder: &Builder, root_src: []const u8) -> TestStep {1032 pub fn init(builder: &Builder, root_src: []const u8) -> TestStep {
1032 const step_name = builder.fmt("test {}", root_src);1033 const step_name = builder.fmt("test {}", root_src);
...@@ -1039,6 +1040,7 @@ pub const TestStep = struct {...@@ -1039,6 +1040,7 @@ pub const TestStep = struct {
1039 .name_prefix = "",1040 .name_prefix = "",
1040 .filter = null,1041 .filter = null,
1041 .link_libs = BufSet.init(builder.allocator),1042 .link_libs = BufSet.init(builder.allocator),
1043 .target = Target.Native,
1042 }1044 }
1043 }1045 }
10441046
...@@ -1062,6 +1064,18 @@ pub const TestStep = struct {...@@ -1062,6 +1064,18 @@ pub const TestStep = struct {
1062 self.filter = text;1064 self.filter = text;
1063 }1065 }
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
1065 fn make(step: &Step) -> %void {1079 fn make(step: &Step) -> %void {
1066 const self = @fieldParentPtr(TestStep, "step", step);1080 const self = @fieldParentPtr(TestStep, "step", step);
1067 const builder = self.builder;1081 const builder = self.builder;
...@@ -1082,6 +1096,20 @@ pub const TestStep = struct {...@@ -1082,6 +1096,20 @@ pub const TestStep = struct {
1082 builtin.Mode.ReleaseFast => %%zig_args.append("--release-fast"),1096 builtin.Mode.ReleaseFast => %%zig_args.append("--release-fast"),
1083 }1097 }
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
1085 if (self.filter) |filter| {1113 if (self.filter) |filter| {
1086 %%zig_args.append("--test-filter");1114 %%zig_args.append("--test-filter");
1087 %%zig_args.append(filter);1115 %%zig_args.append(filter);
test/tests.zig+41-11
...@@ -9,7 +9,8 @@ const io = std.io;...@@ -9,7 +9,8 @@ const io = std.io;
9const mem = std.mem;9const mem = std.mem;
10const fmt = std.fmt;10const fmt = std.fmt;
11const ArrayList = std.ArrayList;11const ArrayList = std.ArrayList;
12const Mode = @import("builtin").Mode;12const builtin = @import("builtin");
13const Mode = builtin.Mode;
1314
14const compare_output = @import("compare_output.zig");15const compare_output = @import("compare_output.zig");
15const build_examples = @import("build_examples.zig");16const build_examples = @import("build_examples.zig");
...@@ -18,6 +19,25 @@ const assemble_and_link = @import("assemble_and_link.zig");...@@ -18,6 +19,25 @@ const assemble_and_link = @import("assemble_and_link.zig");
18const debug_safety = @import("debug_safety.zig");19const debug_safety = @import("debug_safety.zig");
19const parseh = @import("parseh.zig");20const 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
21error TestFailed;41error TestFailed;
2242
23pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {43pub 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...@@ -121,17 +141,27 @@ pub fn addPkgTestsRaw(b: &build.Builder, test_filter: ?[]const u8, root_src: []c
121{141{
122 const libc_bools = if (always_link_libc) []bool{true} else []bool{false, true};142 const libc_bools = if (always_link_libc) []bool{true} else []bool{false, true};
123 const step = b.step(b.fmt("test-{}", name), desc);143 const step = b.step(b.fmt("test-{}", name), desc);
124 for ([]Mode{Mode.Debug, Mode.ReleaseFast}) |mode| {144 for (test_targets) |test_target| {
125 for (libc_bools) |link_libc| {145 const is_native = (test_target.os == builtin.os and test_target.arch == builtin.arch);
126 const these_tests = b.addTest(root_src);146 for ([]Mode{Mode.Debug, Mode.ReleaseFast}) |mode| {
127 these_tests.setNamePrefix(b.fmt("{}-{}-{} ", name, @enumTagName(mode),147 for (libc_bools) |link_libc| {
128 if (link_libc) "c" else "bare"));148 if (link_libc and !is_native) {
129 these_tests.setFilter(test_filter);149 // don't assume we have a cross-compiling libc set up
130 these_tests.setBuildMode(mode);150 continue;
131 if (link_libc) {151 }
132 these_tests.linkSystemLibrary("c");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);
133 }164 }
134 step.dependOn(&these_tests.step);
135 }165 }
136 }166 }
137 return step;167 return step;