authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-21 23:55:56-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-22 11:22:17-04:00
logffef5d26b6bbaf52d80c74ac3879a233a7a1a513
tree76a7301501472e7689ed0adb9da985b32479ad0d
parentc5716715d5e7d7a5eae76df77ed538a48d22f0ba
signature Commit is signed but in an unrecognized format.

significantly increase test coverage

* add zig build option `-Dskip-libc` to skip tests that build libc (e.g. if you don't want to wait for musl to build) * add `-Denable-wine` option which uses wine to run cross compiled windows tests on non-windows hosts * add `-Denable-qemu` option which uses qemu to run cross compiled foreign architecture tests * add `-Denable-foreign-glibc=path` option which combined with `-Denable-qemu` enables running cross compiled tests that link against glibc. See https://github.com/ziglang/zig/wiki/Updating-libc#glibc for how to produce this directory. * the test matrix is done manually. release test builds are only enabled by default for the native target. this should save us some CI time, while still providing decent coverage of release builds. - add test coverage for `x86_64-linux-musl -lc` (building musl libc) - add test coverage for `x86_64-linux-gnu -lc` (building glibc) - add test coverage for `aarch64v8_5a-linux-none` - add test coverage for `aarch64v8_5a-linux-musl -lc` (building musl libc) - add test coverage for `aarch64v8_5a-linux-gnu -lc` (building glibc) - add test coverage for `arm-linux-none` - test coverage for `arm-linux-musleabihf -lc` (building musl libc) is disabled due to #3286 - test coverage for `arm-linux-gnueabihf -lc` (building glibc) is disabled due to #3287 - test coverage for `x86_64-windows-gnu -lc` (building mingw-w64) is disabled due to #3285 * enable qemu testing on the Linux CI job. There's not really a good reason to enable wine, since we have a Windows CI job as well. * remove the no longer needed `--build-file ../build.zig` from CI scripts * fix bug in glibc compilation where it wasn't properly reading the abi list txt files, resulting in "key not found" error. * std.build.Target gains: - isNetBSD - isLinux - osRequiresLibC - getArchPtrBitWidth - getExternalExecutor * zig build system gains support for enabling wine and enabling qemu. `artifact.enable_wine = true;`, `artifact.enable_qemu = true;`. This communicates that the system has these tools installed and the build system will use them to run tests. * zig build system gains support for overriding the dynamic linker of an executable artifact. * fix std.c.lseek prototype. makes behavior tests for arm-linux-musleabihf pass. * disable std lib tests that are failing on ARM. See #3288, #3289 * provide `std.os.off_t`. * disable some of the compiler_rt symbols for arm 32 bit. Fixes compiler_rt tests for arm 32 bit * add __stack_chk_guard when linking against glibc. Fixes std lib tests for aarch64-linux-gnu * workaround for "unable to inline function" using `@inlineCall`. Fixes compiler_rt tests for arm 32 bit.

22 files changed, 479 insertions(+), 89 deletions(-)

build.zig+8-6
......@@ -70,6 +70,7 @@ pub fn build(b: *Builder) !void {
7070 const skip_release_fast = b.option(bool, "skip-release-fast", "Main test suite skips release-fast builds") orelse skip_release;
7171 const skip_release_safe = b.option(bool, "skip-release-safe", "Main test suite skips release-safe builds") orelse skip_release;
7272 const skip_non_native = b.option(bool, "skip-non-native", "Main test suite skips non-native builds") orelse false;
73 const skip_libc = b.option(bool, "skip-libc", "Main test suite skips tests that link libc") orelse false;
7374 const skip_self_hosted = b.option(bool, "skip-self-hosted", "Main test suite skips building self hosted compiler") orelse false;
7475 if (!skip_self_hosted) {
7576 // TODO re-enable this after https://github.com/ziglang/zig/issues/2377
......@@ -96,6 +97,10 @@ pub fn build(b: *Builder) !void {
9697
9798 const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");
9899
100 const is_wine_enabled = b.option(bool, "enable-wine", "Use Wine to run cross compiled Windows tests") orelse false;
101 const is_qemu_enabled = b.option(bool, "enable-qemu", "Use QEMU to run cross compiled foreign architecture tests") orelse false;
102 const glibc_multi_dir = b.option([]const u8, "enable-foreign-glibc", "Provide directory with glibc installations to run cross compiled tests that link glibc");
103
99104 const test_stage2_step = b.step("test-stage2", "Run the stage2 compiler tests");
100105 test_stage2_step.dependOn(&test_stage2.step);
101106
......@@ -122,19 +127,16 @@ pub fn build(b: *Builder) !void {
122127 }
123128 const modes = chosen_modes[0..chosen_mode_index];
124129
125 const multi_and_single = [_]bool{ false, true };
126 const just_multi = [_]bool{false};
127
128130 // run stage1 `zig fmt` on this build.zig file just to make sure it works
129131 test_step.dependOn(&fmt_build_zig.step);
130132 const fmt_step = b.step("test-fmt", "Run zig fmt against build.zig to make sure it works");
131133 fmt_step.dependOn(&fmt_build_zig.step);
132134
133 test_step.dependOn(tests.addPkgTests(b, test_filter, "test/stage1/behavior.zig", "behavior", "Run the behavior tests", modes, multi_and_single, skip_non_native));
135 test_step.dependOn(tests.addPkgTests(b, test_filter, "test/stage1/behavior.zig", "behavior", "Run the behavior tests", modes, false, skip_non_native, skip_libc, is_wine_enabled, is_qemu_enabled, glibc_multi_dir));
134136
135 test_step.dependOn(tests.addPkgTests(b, test_filter, "std/std.zig", "std", "Run the standard library tests", modes, multi_and_single, skip_non_native));
137 test_step.dependOn(tests.addPkgTests(b, test_filter, "std/std.zig", "std", "Run the standard library tests", modes, false, skip_non_native, skip_libc, is_wine_enabled, is_qemu_enabled, glibc_multi_dir));
136138
137 test_step.dependOn(tests.addPkgTests(b, test_filter, "std/special/compiler_rt.zig", "compiler-rt", "Run the compiler_rt tests", modes, just_multi, skip_non_native));
139 test_step.dependOn(tests.addPkgTests(b, test_filter, "std/special/compiler_rt.zig", "compiler-rt", "Run the compiler_rt tests", modes, true, skip_non_native, true, is_wine_enabled, is_qemu_enabled, glibc_multi_dir));
138140
139141 test_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));
140142 test_step.dependOn(tests.addStandaloneTests(b, test_filter, modes));
ci/azure/linux_script+2-2
......@@ -12,7 +12,7 @@ sudo apt-get update -q
1212
1313sudo apt-get remove -y llvm-*
1414sudo rm -rf /usr/local/*
15sudo apt-get install -y libxml2-dev libclang-9-dev llvm-9 llvm-9-dev cmake s3cmd gcc-7 g++-7
15sudo apt-get install -y libxml2-dev libclang-9-dev llvm-9 llvm-9-dev cmake s3cmd gcc-7 g++-7 qemu
1616
1717export CC=gcc-7
1818export CXX=g++-7
......@@ -20,7 +20,7 @@ mkdir build
2020cd build
2121cmake .. -DCMAKE_BUILD_TYPE=Release
2222make -j2 install
23./zig build --build-file ../build.zig test
23./zig build test -Denable-qemu
2424
2525if [ "${BUILD_REASON}" != "PullRequest" ]; then
2626 ARTIFACTSDIR="$BUILDDIR/artifacts"
ci/azure/macos_script+1-1
......@@ -70,7 +70,7 @@ mkdir build
7070cd build
7171cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$PREFIX -DCMAKE_INSTALL_PREFIX=$(pwd)/release -DZIG_STATIC=ON
7272make $JOBS install
73release/bin/zig build --build-file ../build.zig test
73release/bin/zig build test
7474
7575if [ "${BUILD_REASON}" != "PullRequest" ]; then
7676 mv ../LICENSE release/
ci/azure/windows_script.bat+1-1
......@@ -20,7 +20,7 @@ cd %ZIGBUILDDIR%
2020cmake.exe .. -Thost=x64 -G"Visual Studio 15 2017 Win64" "-DCMAKE_INSTALL_PREFIX=%ZIGINSTALLDIR%" "-DCMAKE_PREFIX_PATH=%ZIGPREFIXPATH%" -DCMAKE_BUILD_TYPE=Release || exit /b
2121msbuild /p:Configuration=Release INSTALL.vcxproj || exit /b
2222
23"%ZIGINSTALLDIR%\bin\zig.exe" build --build-file ..\build.zig test || exit /b
23"%ZIGINSTALLDIR%\bin\zig.exe" build test || exit /b
2424
2525set "PATH=%CD:~0,2%\msys64\usr\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem"
2626SET "MSYSTEM=MINGW64"
src/glibc.cpp+1-1
......@@ -99,9 +99,9 @@ Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbo
9999 if (!opt_line.is_some) break;
100100
101101 ver_list_base = allocate<ZigGLibCVerList>(glibc_abi->all_functions.length);
102 ZigTarget *target = allocate<ZigTarget>(1);
103102 SplitIterator line_it = memSplit(opt_line.value, str(" "));
104103 for (;;) {
104 ZigTarget *target = allocate<ZigTarget>(1);
105105 Optional<Slice<uint8_t>> opt_target = SplitIterator_next(&line_it);
106106 if (!opt_target.is_some) break;
107107
std/build.zig+174-1
......@@ -1175,6 +1175,13 @@ pub const Target = union(enum) {
11751175 };
11761176 }
11771177
1178 pub fn isLinux(self: Target) bool {
1179 return switch (self.getOs()) {
1180 .linux => true,
1181 else => false,
1182 };
1183 }
1184
11781185 pub fn isUefi(self: Target) bool {
11791186 return switch (self.getOs()) {
11801187 .uefi => true,
......@@ -1196,9 +1203,125 @@ pub const Target = union(enum) {
11961203 };
11971204 }
11981205
1206 pub fn isNetBSD(self: Target) bool {
1207 return switch (self.getOs()) {
1208 .netbsd => true,
1209 else => false,
1210 };
1211 }
1212
11991213 pub fn wantSharedLibSymLinks(self: Target) bool {
12001214 return !self.isWindows();
12011215 }
1216
1217 pub fn osRequiresLibC(self: Target) bool {
1218 return self.isDarwin() or self.isFreeBSD() or self.isNetBSD();
1219 }
1220
1221 pub fn getArchPtrBitWidth(self: Target) u32 {
1222 switch (self.getArch()) {
1223 .avr,
1224 .msp430,
1225 => return 16,
1226
1227 .arc,
1228 .arm,
1229 .armeb,
1230 .hexagon,
1231 .le32,
1232 .mips,
1233 .mipsel,
1234 .powerpc,
1235 .r600,
1236 .riscv32,
1237 .sparc,
1238 .sparcel,
1239 .tce,
1240 .tcele,
1241 .thumb,
1242 .thumbeb,
1243 .i386,
1244 .xcore,
1245 .nvptx,
1246 .amdil,
1247 .hsail,
1248 .spir,
1249 .kalimba,
1250 .shave,
1251 .lanai,
1252 .wasm32,
1253 .renderscript32,
1254 .aarch64_32,
1255 => return 32,
1256
1257 .aarch64,
1258 .aarch64_be,
1259 .mips64,
1260 .mips64el,
1261 .powerpc64,
1262 .powerpc64le,
1263 .riscv64,
1264 .x86_64,
1265 .nvptx64,
1266 .le64,
1267 .amdil64,
1268 .hsail64,
1269 .spir64,
1270 .wasm64,
1271 .renderscript64,
1272 .amdgcn,
1273 .bpfel,
1274 .bpfeb,
1275 .sparcv9,
1276 .s390x,
1277 => return 64,
1278 }
1279 }
1280
1281 pub const Executor = union(enum) {
1282 native,
1283 qemu: []const u8,
1284 wine: []const u8,
1285 unavailable,
1286 };
1287
1288 pub fn getExternalExecutor(self: Target) Executor {
1289 if (@TagType(Target)(self) == .Native) return .native;
1290
1291 // If the target OS matches the host OS, we can use QEMU to emulate a foreign architecture.
1292 if (self.getOs() == builtin.os) {
1293 return switch (self.getArch()) {
1294 .aarch64 => Executor{ .qemu = "qemu-aarch64" },
1295 .aarch64_be => Executor{ .qemu = "qemu-aarch64_be" },
1296 .arm => Executor{ .qemu = "qemu-arm" },
1297 .armeb => Executor{ .qemu = "qemu-armeb" },
1298 .i386 => Executor{ .qemu = "qemu-i386" },
1299 .mips => Executor{ .qemu = "qemu-mips" },
1300 .mipsel => Executor{ .qemu = "qemu-mipsel" },
1301 .mips64 => Executor{ .qemu = "qemu-mips64" },
1302 .mips64el => Executor{ .qemu = "qemu-mips64el" },
1303 .powerpc => Executor{ .qemu = "qemu-ppc" },
1304 .powerpc64 => Executor{ .qemu = "qemu-ppc64" },
1305 .powerpc64le => Executor{ .qemu = "qemu-ppc64le" },
1306 .riscv32 => Executor{ .qemu = "qemu-riscv32" },
1307 .riscv64 => Executor{ .qemu = "qemu-riscv64" },
1308 .s390x => Executor{ .qemu = "qemu-s390x" },
1309 .sparc => Executor{ .qemu = "qemu-sparc" },
1310 .x86_64 => Executor{ .qemu = "qemu-x86_64" },
1311 else => return .unavailable,
1312 };
1313 }
1314
1315 if (self.isWindows()) {
1316 switch (self.getArchPtrBitWidth()) {
1317 32 => return Executor{ .wine = "wine" },
1318 64 => return Executor{ .wine = "wine64" },
1319 else => return .unavailable,
1320 }
1321 }
1322
1323 return .unavailable;
1324 }
12021325};
12031326
12041327const Pkg = struct {
......@@ -1266,6 +1389,7 @@ pub const LibExeObjStep = struct {
12661389 include_dirs: ArrayList(IncludeDir),
12671390 output_dir: ?[]const u8,
12681391 need_system_paths: bool,
1392 is_linking_libc: bool = false,
12691393
12701394 installed_path: ?[]const u8,
12711395 install_step: ?*InstallArtifactStep,
......@@ -1275,6 +1399,20 @@ pub const LibExeObjStep = struct {
12751399
12761400 valgrind_support: ?bool = null,
12771401
1402 /// Uses system Wine installation to run cross compiled Windows build artifacts.
1403 enable_wine: bool = false,
1404
1405 /// Uses system QEMU installation to run cross compiled foreign architecture build artifacts.
1406 enable_qemu: bool = false,
1407
1408 /// After following the steps in https://github.com/ziglang/zig/wiki/Updating-libc#glibc,
1409 /// this will be the directory $glibc-build-dir/install/glibcs
1410 /// Given the example of the aarch64 target, this is the directory
1411 /// that contains the path `aarch64-linux-gnu/lib/ld-linux-aarch64.so.1`.
1412 glibc_multi_install_dir: ?[]const u8 = null,
1413
1414 dynamic_linker: ?[]const u8 = null,
1415
12781416 const LinkObject = union(enum) {
12791417 StaticPath: []const u8,
12801418 OtherStep: *LibExeObjStep,
......@@ -1504,7 +1642,9 @@ pub const LibExeObjStep = struct {
15041642
15051643 pub fn linkSystemLibrary(self: *LibExeObjStep, name: []const u8) void {
15061644 self.link_objects.append(LinkObject{ .SystemLib = self.builder.dupe(name) }) catch unreachable;
1507 if (!isLibCLibrary(name)) {
1645 if (isLibCLibrary(name)) {
1646 self.is_linking_libc = true;
1647 } else {
15081648 self.need_system_paths = true;
15091649 }
15101650 }
......@@ -1840,6 +1980,11 @@ pub const LibExeObjStep = struct {
18401980 zig_args.append(builder.pathFromRoot(linker_script)) catch unreachable;
18411981 }
18421982
1983 if (self.dynamic_linker) |dynamic_linker| {
1984 try zig_args.append("--dynamic-linker");
1985 try zig_args.append(dynamic_linker);
1986 }
1987
18431988 if (self.version_script) |version_script| {
18441989 try zig_args.append("--version-script");
18451990 try zig_args.append(builder.pathFromRoot(version_script));
......@@ -1854,6 +1999,34 @@ pub const LibExeObjStep = struct {
18541999 try zig_args.append("--test-cmd-bin");
18552000 }
18562001 }
2002 } else switch (self.target.getExternalExecutor()) {
2003 .native, .unavailable => {},
2004 .qemu => |bin_name| if (self.enable_qemu) qemu: {
2005 const need_cross_glibc = self.target.isGnu() and self.target.isLinux() and self.is_linking_libc;
2006 const glibc_dir_arg = if (need_cross_glibc)
2007 self.glibc_multi_install_dir orelse break :qemu
2008 else
2009 null;
2010 try zig_args.append("--test-cmd");
2011 try zig_args.append(bin_name);
2012 if (glibc_dir_arg) |dir| {
2013 const full_dir = try fs.path.join(builder.allocator, [_][]const u8{
2014 dir,
2015 try self.target.linuxTriple(builder.allocator),
2016 });
2017
2018 try zig_args.append("--test-cmd");
2019 try zig_args.append("-L");
2020 try zig_args.append("--test-cmd");
2021 try zig_args.append(full_dir);
2022 }
2023 try zig_args.append("--test-cmd-bin");
2024 },
2025 .wine => |bin_name| if (self.enable_wine) {
2026 try zig_args.append("--test-cmd");
2027 try zig_args.append(bin_name);
2028 try zig_args.append("--test-cmd-bin");
2029 },
18572030 }
18582031 for (self.packages.toSliceConst()) |pkg| {
18592032 zig_args.append("--pkg-begin") catch unreachable;
std/c.zig+1-1
......@@ -63,7 +63,7 @@ pub extern "c" fn close(fd: fd_t) c_int;
6363pub extern "c" fn @"close$NOCANCEL"(fd: fd_t) c_int;
6464pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
6565pub extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *Stat) c_int;
66pub extern "c" fn lseek(fd: fd_t, offset: isize, whence: c_int) isize;
66pub extern "c" fn lseek(fd: fd_t, offset: off_t, whence: c_int) off_t;
6767pub extern "c" fn open(path: [*]const u8, oflag: c_uint, ...) c_int;
6868pub extern "c" fn openat(fd: c_int, path: [*]const u8, oflag: c_uint, ...) c_int;
6969pub extern "c" fn raise(sig: c_int) c_int;
std/fmt/parse_float.zig+4
......@@ -382,6 +382,10 @@ pub fn parseFloat(comptime T: type, s: []const u8) !T {
382382}
383383
384384test "fmt.parseFloat" {
385 if (@import("builtin").arch == .arm) {
386 // TODO https://github.com/ziglang/zig/issues/3289
387 return error.SkipZigTest;
388 }
385389 const testing = std.testing;
386390 const expect = testing.expect;
387391 const expectEqual = testing.expectEqual;
std/fs/path.zig+8
......@@ -646,6 +646,10 @@ test "resolve" {
646646}
647647
648648test "resolveWindows" {
649 if (@import("builtin").arch == .aarch64) {
650 // TODO https://github.com/ziglang/zig/issues/3288
651 return error.SkipZigTest;
652 }
649653 if (windows.is_the_target) {
650654 const cwd = try process.getCwdAlloc(debug.global_allocator);
651655 const parsed_cwd = windowsParsePath(cwd);
......@@ -1086,6 +1090,10 @@ pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![
10861090}
10871091
10881092test "relative" {
1093 if (@import("builtin").arch == .aarch64) {
1094 // TODO https://github.com/ziglang/zig/issues/3288
1095 return error.SkipZigTest;
1096 }
10891097 testRelativeWindows("c:/blah\\blah", "d:/games", "D:\\games");
10901098 testRelativeWindows("c:/aaaa/bbbb", "c:/aaaa", "..");
10911099 testRelativeWindows("c:/aaaa/bbbb", "c:/cccc", "..\\..\\cccc");
std/io/test.zig+4
......@@ -11,6 +11,10 @@ const fs = std.fs;
1111const File = std.fs.File;
1212
1313test "write a file, read it, then delete it" {
14 if (builtin.arch == .aarch64 and builtin.glibc_version != null) {
15 // TODO https://github.com/ziglang/zig/issues/3288
16 return error.SkipZigTest;
17 }
1418 var raw_bytes: [200 * 1024]u8 = undefined;
1519 var allocator = &std.heap.FixedBufferAllocator.init(raw_bytes[0..]).allocator;
1620
std/os/bits/darwin.zig+3-1
......@@ -43,6 +43,8 @@ pub const mach_timebase_info_data = extern struct {
4343 denom: u32,
4444};
4545
46pub const off_t = i64;
47
4648/// Renamed to Stat to not conflict with the stat function.
4749/// atime, mtime, and ctime have functions to return `timespec`,
4850/// because although this is a POSIX API, the layout and names of
......@@ -65,7 +67,7 @@ pub const Stat = extern struct {
6567 ctimensec: isize,
6668 birthtimesec: isize,
6769 birthtimensec: isize,
68 size: i64,
70 size: off_t,
6971 blocks: i64,
7072 blksize: i32,
7173 flags: u32,
std/os/bits/freebsd.zig+3-1
......@@ -73,6 +73,8 @@ pub const msghdr_const = extern struct {
7373 msg_flags: i32,
7474};
7575
76pub const off_t = i64;
77
7678/// Renamed to Stat to not conflict with the stat function.
7779/// atime, mtime, and ctime have functions to return `timespec`,
7880/// because although this is a POSIX API, the layout and names of
......@@ -96,7 +98,7 @@ pub const Stat = extern struct {
9698 ctim: timespec,
9799 birthtim: timespec,
98100
99 size: i64,
101 size: off_t,
100102 blocks: i64,
101103 blksize: isize,
102104 flags: u32,
std/os/bits/linux/arm-eabi.zig+3-1
......@@ -511,6 +511,8 @@ pub const msghdr_const = extern struct {
511511 msg_flags: i32,
512512};
513513
514pub const off_t = i64;
515
514516/// Renamed to Stat to not conflict with the stat function.
515517/// atime, mtime, and ctime have functions to return `timespec`,
516518/// because although this is a POSIX API, the layout and names of
......@@ -527,7 +529,7 @@ pub const Stat = extern struct {
527529 gid: u32,
528530 rdev: u64,
529531 __rdev_padding: u32,
530 size: i64,
532 size: off_t,
531533 blksize: i32,
532534 blocks: u64,
533535 atim: timespec,
std/os/bits/linux/arm64.zig+3-1
......@@ -382,6 +382,8 @@ pub const msghdr_const = extern struct {
382382 msg_flags: i32,
383383};
384384
385pub const off_t = i64;
386
385387/// Renamed to Stat to not conflict with the stat function.
386388/// atime, mtime, and ctime have functions to return `timespec`,
387389/// because although this is a POSIX API, the layout and names of
......@@ -398,7 +400,7 @@ pub const Stat = extern struct {
398400 gid: u32,
399401 __pad0: u32,
400402 rdev: u64,
401 size: i64,
403 size: off_t,
402404 blksize: isize,
403405 blocks: i64,
404406
std/os/bits/linux/x86_64.zig+3-1
......@@ -479,6 +479,8 @@ pub const msghdr_const = extern struct {
479479 msg_flags: i32,
480480};
481481
482pub const off_t = i64;
483
482484/// Renamed to Stat to not conflict with the stat function.
483485/// atime, mtime, and ctime have functions to return `timespec`,
484486/// because although this is a POSIX API, the layout and names of
......@@ -495,7 +497,7 @@ pub const Stat = extern struct {
495497 gid: u32,
496498 __pad0: u32,
497499 rdev: u64,
498 size: i64,
500 size: off_t,
499501 blksize: isize,
500502 blocks: i64,
501503
std/os/bits/netbsd.zig+3-1
......@@ -73,6 +73,8 @@ pub const msghdr_const = extern struct {
7373 msg_flags: i32,
7474};
7575
76pub const off_t = i64;
77
7678/// Renamed to Stat to not conflict with the stat function.
7779/// atime, mtime, and ctime have functions to return `timespec`,
7880/// because although this is a POSIX API, the layout and names of
......@@ -94,7 +96,7 @@ pub const Stat = extern struct {
9496 ctim: timespec,
9597 birthtim: timespec,
9698
97 size: i64,
99 size: off_t,
98100 blocks: i64,
99101 blksize: isize,
100102 flags: u32,
std/os/test.zig+4
......@@ -95,6 +95,10 @@ test "cpu count" {
9595}
9696
9797test "AtomicFile" {
98 if (builtin.arch == .aarch64 and builtin.glibc_version != null) {
99 // TODO https://github.com/ziglang/zig/issues/3288
100 return error.SkipZigTest;
101 }
98102 var buffer: [1024]u8 = undefined;
99103 const allocator = &std.heap.FixedBufferAllocator.init(buffer[0..]).allocator;
100104 const test_out_file = "tmp_atomic_file_test_dest.txt";
std/rb.zig+9
......@@ -511,6 +511,11 @@ fn testCompare(l: *Node, r: *Node) mem.Compare {
511511}
512512
513513test "rb" {
514 if (@import("builtin").arch == .aarch64) {
515 // TODO https://github.com/ziglang/zig/issues/3288
516 return error.SkipZigTest;
517 }
518
514519 var tree: Tree = undefined;
515520 var ns: [10]testNumber = undefined;
516521 ns[0].value = 42;
......@@ -571,6 +576,10 @@ test "inserting and looking up" {
571576}
572577
573578test "multiple inserts, followed by calling first and last" {
579 if (@import("builtin").arch == .aarch64) {
580 // TODO https://github.com/ziglang/zig/issues/3288
581 return error.SkipZigTest;
582 }
574583 var tree: Tree = undefined;
575584 tree.init(testCompare);
576585 var zeroth: testNumber = undefined;
std/special/compiler_rt.zig+4-1
......@@ -143,7 +143,7 @@ comptime {
143143 @export("__negsf2", @import("compiler_rt/negXf2.zig").__negsf2, linkage);
144144 @export("__negdf2", @import("compiler_rt/negXf2.zig").__negdf2, linkage);
145145
146 if (is_arm_arch and !is_arm_64) {
146 if (is_arm_arch and !is_arm_64 and !is_test) {
147147 @export("__aeabi_unwind_cpp_pr0", __aeabi_unwind_cpp_pr0, strong_linkage);
148148 @export("__aeabi_unwind_cpp_pr1", __aeabi_unwind_cpp_pr1, linkage);
149149 @export("__aeabi_unwind_cpp_pr2", __aeabi_unwind_cpp_pr2, linkage);
......@@ -264,6 +264,9 @@ comptime {
264264 else => {},
265265 }
266266 } else {
267 if (builtin.glibc_version != null) {
268 @export("__stack_chk_guard", __stack_chk_guard, linkage);
269 }
267270 @export("__divti3", @import("compiler_rt/divti3.zig").__divti3, linkage);
268271 @export("__modti3", @import("compiler_rt/modti3.zig").__modti3, linkage);
269272 @export("__multi3", @import("compiler_rt/multi3.zig").__multi3, linkage);
std/special/compiler_rt/arm/aeabi_dcmp.zig+6-6
......@@ -14,31 +14,31 @@ const ConditionalOperator = enum {
1414
1515pub nakedcc fn __aeabi_dcmpeq() noreturn {
1616 @setRuntimeSafety(false);
17 aeabi_dcmp(.Eq);
17 @inlineCall(aeabi_dcmp, .Eq);
1818 unreachable;
1919}
2020
2121pub nakedcc fn __aeabi_dcmplt() noreturn {
2222 @setRuntimeSafety(false);
23 aeabi_dcmp(.Lt);
23 @inlineCall(aeabi_dcmp, .Lt);
2424 unreachable;
2525}
2626
2727pub nakedcc fn __aeabi_dcmple() noreturn {
2828 @setRuntimeSafety(false);
29 aeabi_dcmp(.Le);
29 @inlineCall(aeabi_dcmp, .Le);
3030 unreachable;
3131}
3232
3333pub nakedcc fn __aeabi_dcmpge() noreturn {
3434 @setRuntimeSafety(false);
35 aeabi_dcmp(.Ge);
35 @inlineCall(aeabi_dcmp, .Ge);
3636 unreachable;
3737}
3838
3939pub nakedcc fn __aeabi_dcmpgt() noreturn {
4040 @setRuntimeSafety(false);
41 aeabi_dcmp(.Gt);
41 @inlineCall(aeabi_dcmp, .Gt);
4242 unreachable;
4343}
4444
......@@ -49,7 +49,7 @@ inline fn convert_dcmp_args_to_df2_args() void {
4949 );
5050}
5151
52inline fn aeabi_dcmp(comptime cond: ConditionalOperator) void {
52fn aeabi_dcmp(comptime cond: ConditionalOperator) void {
5353 @setRuntimeSafety(false);
5454 asm volatile (
5555 \\ push { r4, lr }
std/special/compiler_rt/arm/aeabi_fcmp.zig+6-6
......@@ -14,31 +14,31 @@ const ConditionalOperator = enum {
1414
1515pub nakedcc fn __aeabi_fcmpeq() noreturn {
1616 @setRuntimeSafety(false);
17 aeabi_fcmp(.Eq);
17 @inlineCall(aeabi_fcmp, .Eq);
1818 unreachable;
1919}
2020
2121pub nakedcc fn __aeabi_fcmplt() noreturn {
2222 @setRuntimeSafety(false);
23 aeabi_fcmp(.Lt);
23 @inlineCall(aeabi_fcmp, .Lt);
2424 unreachable;
2525}
2626
2727pub nakedcc fn __aeabi_fcmple() noreturn {
2828 @setRuntimeSafety(false);
29 aeabi_fcmp(.Le);
29 @inlineCall(aeabi_fcmp, .Le);
3030 unreachable;
3131}
3232
3333pub nakedcc fn __aeabi_fcmpge() noreturn {
3434 @setRuntimeSafety(false);
35 aeabi_fcmp(.Ge);
35 @inlineCall(aeabi_fcmp, .Ge);
3636 unreachable;
3737}
3838
3939pub nakedcc fn __aeabi_fcmpgt() noreturn {
4040 @setRuntimeSafety(false);
41 aeabi_fcmp(.Gt);
41 @inlineCall(aeabi_fcmp, .Gt);
4242 unreachable;
4343}
4444
......@@ -49,7 +49,7 @@ inline fn convert_fcmp_args_to_sf2_args() void {
4949 );
5050}
5151
52inline fn aeabi_fcmp(comptime cond: ConditionalOperator) void {
52fn aeabi_fcmp(comptime cond: ConditionalOperator) void {
5353 @setRuntimeSafety(false);
5454 asm volatile (
5555 \\ push { r4, lr }
test/tests.zig+228-57
......@@ -23,22 +23,181 @@ const runtime_safety = @import("runtime_safety.zig");
2323const translate_c = @import("translate_c.zig");
2424const gen_h = @import("gen_h.zig");
2525
26const cross_targets = [_]CrossTarget{
27 CrossTarget{
28 .os = .linux,
29 .arch = .x86_64,
30 .abi = .gnu,
26const TestTarget = struct {
27 target: Target = .Native,
28 mode: builtin.Mode = .Debug,
29 link_libc: bool = false,
30 single_threaded: bool = false,
31};
32
33const test_targets = [_]TestTarget{
34 TestTarget{},
35 TestTarget{
36 .link_libc = true,
37 },
38 TestTarget{
39 .single_threaded = true,
40 },
41
42 TestTarget{
43 .mode = .ReleaseFast,
44 },
45 TestTarget{
46 .link_libc = true,
47 .mode = .ReleaseFast,
48 },
49 TestTarget{
50 .mode = .ReleaseFast,
51 .single_threaded = true,
52 },
53
54 TestTarget{
55 .mode = .ReleaseSafe,
56 },
57 TestTarget{
58 .link_libc = true,
59 .mode = .ReleaseSafe,
60 },
61 TestTarget{
62 .mode = .ReleaseSafe,
63 .single_threaded = true,
64 },
65
66 TestTarget{
67 .mode = .ReleaseSmall,
3168 },
32 CrossTarget{
33 .os = .macosx,
34 .arch = .x86_64,
35 .abi = .gnu,
69 TestTarget{
70 .link_libc = true,
71 .mode = .ReleaseSmall,
3672 },
37 CrossTarget{
38 .os = .windows,
39 .arch = .x86_64,
40 .abi = .msvc,
73 TestTarget{
74 .mode = .ReleaseSmall,
75 .single_threaded = true,
4176 },
77
78 TestTarget{
79 .target = Target{
80 .Cross = CrossTarget{
81 .os = .linux,
82 .arch = .x86_64,
83 .abi = .none,
84 },
85 },
86 },
87 TestTarget{
88 .target = Target{
89 .Cross = CrossTarget{
90 .os = .linux,
91 .arch = .x86_64,
92 .abi = .gnu,
93 },
94 },
95 .link_libc = true,
96 },
97 TestTarget{
98 .target = Target{
99 .Cross = CrossTarget{
100 .os = .linux,
101 .arch = .x86_64,
102 .abi = .musl,
103 },
104 },
105 .link_libc = true,
106 },
107
108 TestTarget{
109 .target = Target{
110 .Cross = CrossTarget{
111 .os = .linux,
112 .arch = builtin.Arch{ .aarch64 = builtin.Arch.Arm64.v8_5a },
113 .abi = .none,
114 },
115 },
116 },
117 TestTarget{
118 .target = Target{
119 .Cross = CrossTarget{
120 .os = .linux,
121 .arch = builtin.Arch{ .aarch64 = builtin.Arch.Arm64.v8_5a },
122 .abi = .musl,
123 },
124 },
125 .link_libc = true,
126 },
127 TestTarget{
128 .target = Target{
129 .Cross = CrossTarget{
130 .os = .linux,
131 .arch = builtin.Arch{ .aarch64 = builtin.Arch.Arm64.v8_5a },
132 .abi = .gnu,
133 },
134 },
135 .link_libc = true,
136 },
137
138 TestTarget{
139 .target = Target{
140 .Cross = CrossTarget{
141 .os = .linux,
142 .arch = builtin.Arch{ .arm = builtin.Arch.Arm32.v8_5a },
143 .abi = .none,
144 },
145 },
146 },
147 // TODO https://github.com/ziglang/zig/issues/3286
148 //TestTarget{
149 // .target = Target{
150 // .Cross = CrossTarget{
151 // .os = .linux,
152 // .arch = builtin.Arch{ .arm = builtin.Arch.Arm32.v8_5a },
153 // .abi = .musleabihf,
154 // },
155 // },
156 // .link_libc = true,
157 //},
158 // TODO https://github.com/ziglang/zig/issues/3287
159 //TestTarget{
160 // .target = Target{
161 // .Cross = CrossTarget{
162 // .os = .linux,
163 // .arch = builtin.Arch{ .arm = builtin.Arch.Arm32.v8_5a },
164 // .abi = .gnueabihf,
165 // },
166 // },
167 // .link_libc = true,
168 //},
169
170 TestTarget{
171 .target = Target{
172 .Cross = CrossTarget{
173 .os = .macosx,
174 .arch = .x86_64,
175 .abi = .gnu,
176 },
177 },
178 },
179
180 TestTarget{
181 .target = Target{
182 .Cross = CrossTarget{
183 .os = .windows,
184 .arch = .x86_64,
185 .abi = .msvc,
186 },
187 },
188 },
189
190 // TODO https://github.com/ziglang/zig/issues/3285
191 //TestTarget{
192 // .target = Target{
193 // .Cross = CrossTarget{
194 // .os = .windows,
195 // .arch = .x86_64,
196 // .abi = .gnu,
197 // },
198 // },
199 // .link_libc = true,
200 //},
42201};
43202
44203const max_stdout_size = 1 * 1024 * 1024; // 1 MB
......@@ -182,57 +341,69 @@ pub fn addPkgTests(
182341 name: []const u8,
183342 desc: []const u8,
184343 modes: []const Mode,
185 single_threaded_list: []const bool,
344 skip_single_threaded: bool,
186345 skip_non_native: bool,
346 skip_libc: bool,
347 is_wine_enabled: bool,
348 is_qemu_enabled: bool,
349 glibc_dir: ?[]const u8,
187350) *build.Step {
188351 const step = b.step(b.fmt("test-{}", name), desc);
189352
190 var targets = std.ArrayList(*const CrossTarget).init(b.allocator);
191 defer targets.deinit();
192 const host = CrossTarget{ .os = builtin.os, .arch = builtin.arch, .abi = builtin.abi };
193 targets.append(&host) catch unreachable;
194 for (cross_targets) |*t| {
195 if (t.os == builtin.os and t.arch == builtin.arch and t.abi == builtin.abi) continue;
196 targets.append(t) catch unreachable;
197 }
353 for (test_targets) |test_target| {
354 if (skip_non_native and test_target.target != .Native)
355 continue;
198356
199 for (targets.toSliceConst()) |test_target| {
200 const is_native = (test_target.os == builtin.os and test_target.arch == builtin.arch);
201 if (skip_non_native and !is_native)
357 if (skip_libc and test_target.link_libc)
202358 continue;
203 for (modes) |mode| {
204 for ([_]bool{ false, true }) |link_libc| {
205 for (single_threaded_list) |single_threaded| {
206 if (link_libc and !is_native) {
207 // don't assume we have a cross-compiling libc set up
208 continue;
209 }
210 const these_tests = b.addTest(root_src);
211 these_tests.setNamePrefix(b.fmt(
212 "{}-{}-{}-{}-{}-{} ",
213 name,
214 @tagName(test_target.os),
215 @tagName(test_target.arch),
216 @tagName(mode),
217 if (link_libc) "c" else "bare",
218 if (single_threaded) "single" else "multi",
219 ));
220 these_tests.single_threaded = single_threaded;
221 these_tests.setFilter(test_filter);
222 these_tests.setBuildMode(mode);
223 if (!is_native) {
224 these_tests.setTarget(test_target.arch, test_target.os, test_target.abi);
225 }
226 if (link_libc) {
227 these_tests.linkSystemLibrary("c");
228 }
229 if (mem.eql(u8, name, "std")) {
230 these_tests.overrideStdDir("std");
231 }
232 step.dependOn(&these_tests.step);
233 }
234 }
359
360 if (test_target.link_libc and test_target.target.osRequiresLibC()) {
361 // This would be a redundant test.
362 continue;
363 }
364
365 if (skip_single_threaded and test_target.single_threaded)
366 continue;
367
368 const want_this_mode = for (modes) |m| {
369 if (m == test_target.mode) break true;
370 } else false;
371 if (!want_this_mode) continue;
372
373 const libc_prefix = if (test_target.target.osRequiresLibC())
374 ""
375 else if (test_target.link_libc)
376 "c"
377 else
378 "bare";
379
380 const triple_prefix = if (test_target.target == .Native)
381 ([]const u8)("native")
382 else
383 test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable;
384
385 const these_tests = b.addTest(root_src);
386 these_tests.setNamePrefix(b.fmt(
387 "{}-{}-{}-{}-{} ",
388 name,
389 triple_prefix,
390 @tagName(test_target.mode),
391 libc_prefix,
392 if (test_target.single_threaded) "single" else "multi",
393 ));
394 these_tests.single_threaded = test_target.single_threaded;
395 these_tests.setFilter(test_filter);
396 these_tests.setBuildMode(test_target.mode);
397 these_tests.setTheTarget(test_target.target);
398 if (test_target.link_libc) {
399 these_tests.linkSystemLibrary("c");
235400 }
401 these_tests.overrideStdDir("std");
402 these_tests.enable_wine = is_wine_enabled;
403 these_tests.enable_qemu = is_qemu_enabled;
404 these_tests.glibc_multi_install_dir = glibc_dir;
405
406 step.dependOn(&these_tests.step);
236407 }
237408 return step;
238409}