stage2: converge x86_64 and aarch64 tests on macOS

This commit is contained in:
Jakub Konka 2021-01-19 22:38:18 +01:00
parent 5d4401ceec
commit 0e56d4cc02
3 changed files with 116 additions and 220 deletions

View File

@ -1,84 +1,12 @@
const std = @import("std");
const TestContext = @import("../../src/test.zig").TestContext;
const macos_aarch64 = std.zig.CrossTarget{
.cpu_arch = .aarch64,
.os_tag = .macos,
};
const linux_aarch64 = std.zig.CrossTarget{
.cpu_arch = .aarch64,
.os_tag = .linux,
};
pub fn addCases(ctx: *TestContext) !void {
{
var case = ctx.exe("hello world with updates", macos_aarch64);
// Regular old hello world
case.addCompareOutput(
\\extern "c" fn write(usize, usize, usize) void;
\\extern "c" fn exit(usize) noreturn;
\\
\\export fn _start() noreturn {
\\ print();
\\
\\ exit(0);
\\}
\\
\\fn print() void {
\\ const msg = @ptrToInt("Hello, World!\n");
\\ const len = 14;
\\ write(1, msg, len);
\\}
,
"Hello, World!\n",
);
// Now change the message only
case.addCompareOutput(
\\extern "c" fn write(usize, usize, usize) void;
\\extern "c" fn exit(usize) noreturn;
\\
\\export fn _start() noreturn {
\\ print();
\\
\\ exit(0);
\\}
\\
\\fn print() void {
\\ const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n");
\\ const len = 104;
\\ write(1, msg, len);
\\}
,
"What is up? This is a longer message that will force the data to be relocated in virtual address space.\n",
);
// Now we print it twice.
case.addCompareOutput(
\\extern "c" fn write(usize, usize, usize) void;
\\extern "c" fn exit(usize) noreturn;
\\
\\export fn _start() noreturn {
\\ print();
\\ print();
\\
\\ exit(0);
\\}
\\
\\fn print() void {
\\ const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n");
\\ const len = 104;
\\ write(1, msg, len);
\\}
,
\\What is up? This is a longer message that will force the data to be relocated in virtual address space.
\\What is up? This is a longer message that will force the data to be relocated in virtual address space.
\\
);
}
{
var case = ctx.exe("linux_aarch64 hello world", linux_aarch64);
// Regular old hello world
@ -119,28 +47,6 @@ pub fn addCases(ctx: *TestContext) !void {
);
}
{
var case = ctx.exe("exit fn taking argument", macos_aarch64);
case.addCompareOutput(
\\export fn _start() noreturn {
\\ exit(0);
\\}
\\
\\fn exit(ret: usize) noreturn {
\\ asm volatile ("svc #0x80"
\\ :
\\ : [number] "{x16}" (1),
\\ [arg1] "{x0}" (ret)
\\ : "memory"
\\ );
\\ unreachable;
\\}
,
"",
);
}
{
var case = ctx.exe("exit fn taking argument", linux_aarch64);
@ -162,20 +68,4 @@ pub fn addCases(ctx: *TestContext) !void {
"",
);
}
{
var case = ctx.exe("only libc exit", macos_aarch64);
// This test case covers an infrequent scenarion where the string table *may* be relocated
// into the position preceeding the symbol table which results in a dyld error.
case.addCompareOutput(
\\extern "c" fn exit(usize) noreturn;
\\
\\export fn _start() noreturn {
\\ exit(0);
\\}
,
"",
);
}
}

115
test/stage2/darwin.zig Normal file
View File

@ -0,0 +1,115 @@
const std = @import("std");
const TestContext = @import("../../src/test.zig").TestContext;
const archs = [2]std.Target.Cpu.Arch{
.aarch64, .x86_64,
};
pub fn addCases(ctx: *TestContext) !void {
for (archs) |arch| {
const target: std.zig.CrossTarget = .{
.cpu_arch = arch,
.os_tag = .macos,
};
{
var case = ctx.exe("hello world with updates", target);
case.addError("", &[_][]const u8{"error: no entry point found"});
// Incorrect return type
case.addError(
\\export fn _start() noreturn {
\\}
, &[_][]const u8{":2:1: error: expected noreturn, found void"});
// Regular old hello world
case.addCompareOutput(
\\extern "c" fn write(usize, usize, usize) usize;
\\extern "c" fn exit(usize) noreturn;
\\
\\export fn _start() noreturn {
\\ print();
\\
\\ exit(0);
\\}
\\
\\fn print() void {
\\ const msg = @ptrToInt("Hello, World!\n");
\\ const len = 14;
\\ _ = write(1, msg, len);
\\}
,
"Hello, World!\n",
);
// Now change the message only
case.addCompareOutput(
\\extern "c" fn write(usize, usize, usize) usize;
\\extern "c" fn exit(usize) noreturn;
\\
\\export fn _start() noreturn {
\\ print();
\\
\\ exit(0);
\\}
\\
\\fn print() void {
\\ const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n");
\\ const len = 104;
\\ _ = write(1, msg, len);
\\}
,
"What is up? This is a longer message that will force the data to be relocated in virtual address space.\n",
);
// Now we print it twice.
case.addCompareOutput(
\\extern "c" fn write(usize, usize, usize) usize;
\\extern "c" fn exit(usize) noreturn;
\\
\\export fn _start() noreturn {
\\ print();
\\ print();
\\
\\ exit(0);
\\}
\\
\\fn print() void {
\\ const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n");
\\ const len = 104;
\\ _ = write(1, msg, len);
\\}
,
\\What is up? This is a longer message that will force the data to be relocated in virtual address space.
\\What is up? This is a longer message that will force the data to be relocated in virtual address space.
\\
);
}
{
var case = ctx.exe("corner case - update existing, singular TextBlock", target);
// This test case also covers an infrequent scenarion where the string table *may* be relocated
// into the position preceeding the symbol table which results in a dyld error.
case.addCompareOutput(
\\extern "c" fn exit(usize) noreturn;
\\
\\export fn _start() noreturn {
\\ exit(0);
\\}
,
"",
);
case.addCompareOutput(
\\extern "c" fn exit(usize) noreturn;
\\extern "c" fn write(usize, usize, usize) usize;
\\
\\export fn _start() noreturn {
\\ _ = write(1, @ptrToInt("Hey!\n"), 5);
\\ exit(0);
\\}
,
"Hey!\n",
);
}
}
}

View File

@ -11,11 +11,6 @@ const linux_x64 = std.zig.CrossTarget{
.os_tag = .linux,
};
const macos_x64 = std.zig.CrossTarget{
.cpu_arch = .x86_64,
.os_tag = .macos,
};
const linux_riscv64 = std.zig.CrossTarget{
.cpu_arch = .riscv64,
.os_tag = .linux,
@ -28,6 +23,7 @@ pub fn addCases(ctx: *TestContext) !void {
try @import("aarch64.zig").addCases(ctx);
try @import("llvm.zig").addCases(ctx);
try @import("wasm.zig").addCases(ctx);
try @import("darwin.zig").addCases(ctx);
{
var case = ctx.exe("hello world with updates", linux_x64);
@ -141,95 +137,6 @@ pub fn addCases(ctx: *TestContext) !void {
);
}
{
var case = ctx.exe("hello world with updates", macos_x64);
case.addError("", &[_][]const u8{"error: no entry point found"});
// Incorrect return type
case.addError(
\\export fn _start() noreturn {
\\}
, &[_][]const u8{":2:1: error: expected noreturn, found void"});
// Regular old hello world
case.addCompareOutput(
\\extern "c" fn write(usize, usize, usize) usize;
\\extern "c" fn exit(usize) noreturn;
\\
\\export fn _start() noreturn {
\\ print();
\\
\\ exit(0);
\\}
\\
\\fn print() void {
\\ const msg = @ptrToInt("Hello, World!\n");
\\ const len = 14;
\\ const nwritten = write(1, msg, len);
\\ assert(nwritten == len);
\\}
\\
\\fn assert(ok: bool) void {
\\ if (!ok) unreachable; // assertion failure
\\}
,
"Hello, World!\n",
);
// Now change the message only
case.addCompareOutput(
\\extern "c" fn write(usize, usize, usize) usize;
\\extern "c" fn exit(usize) noreturn;
\\
\\export fn _start() noreturn {
\\ print();
\\
\\ exit(0);
\\}
\\
\\fn print() void {
\\ const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n");
\\ const len = 104;
\\ const nwritten = write(1, msg, len);
\\ assert(nwritten == len);
\\}
\\
\\fn assert(ok: bool) void {
\\ if (!ok) unreachable; // assertion failure
\\}
,
"What is up? This is a longer message that will force the data to be relocated in virtual address space.\n",
);
// Now we print it twice.
case.addCompareOutput(
\\extern "c" fn write(usize, usize, usize) usize;
\\extern "c" fn exit(usize) noreturn;
\\
\\export fn _start() noreturn {
\\ print();
\\ print();
\\
\\ exit(0);
\\}
\\
\\fn print() void {
\\ const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n");
\\ const len = 104;
\\ const nwritten = write(1, msg, len);
\\ assert(nwritten == len);
\\}
\\
\\fn assert(ok: bool) void {
\\ if (!ok) unreachable; // assertion failure
\\}
,
\\What is up? This is a longer message that will force the data to be relocated in virtual address space.
\\What is up? This is a longer message that will force the data to be relocated in virtual address space.
\\
);
}
{
var case = ctx.exe("riscv64 hello world", linux_riscv64);
// Regular old hello world
@ -1446,22 +1353,6 @@ pub fn addCases(ctx: *TestContext) !void {
\\}
, &[_][]const u8{":8:10: error: evaluation exceeded 1000 backwards branches"});
}
{
var case = ctx.exe("only libc exit", macos_x64);
// This test case covers an infrequent scenarion where the string table *may* be relocated
// into the position preceeding the symbol table which results in a dyld error.
case.addCompareOutput(
\\extern "c" fn exit(usize) noreturn;
\\
\\export fn _start() noreturn {
\\ exit(0);
\\}
,
"",
);
}
{
var case = ctx.exe("orelse at comptime", linux_x64);
case.addCompareOutput(