From fc4fbfe8e1689417da8130f02045e5cc9e120a1a Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Wed, 27 Apr 2022 23:36:29 +0200 Subject: [PATCH] test: migrate aarch64 incremental tests --- test/cases.zig | 1 - .../aarch64-linux/conditional_branches.0.zig | 26 ++ .../aarch64-linux/conditional_branches.1.zig | 25 ++ .../hello_world_with_updates.0.zig | 31 ++ .../hello_world_with_updates.1.zig | 36 +++ .../hello_world_with_updates.2.zig | 21 ++ .../hello_world_with_updates.0.zig | 5 + .../hello_world_with_updates.1.zig | 5 + .../hello_world_with_updates.2.zig | 19 ++ .../hello_world_with_updates.3.zig | 16 ++ .../hello_world_with_updates.4.zig | 22 ++ .../hello_world_with_updates.5.zig | 16 ++ .../hello_world_with_updates.6.zig | 18 ++ test/incremental/large_add_function.zig | 38 +++ test/stage2/aarch64.zig | 271 ------------------ 15 files changed, 278 insertions(+), 272 deletions(-) create mode 100644 test/incremental/aarch64-linux/conditional_branches.0.zig create mode 100644 test/incremental/aarch64-linux/conditional_branches.1.zig create mode 100644 test/incremental/aarch64-linux/hello_world_with_updates.0.zig create mode 100644 test/incremental/aarch64-linux/hello_world_with_updates.1.zig create mode 100644 test/incremental/aarch64-linux/hello_world_with_updates.2.zig create mode 100644 test/incremental/aarch64-macos/hello_world_with_updates.0.zig create mode 100644 test/incremental/aarch64-macos/hello_world_with_updates.1.zig create mode 100644 test/incremental/aarch64-macos/hello_world_with_updates.2.zig create mode 100644 test/incremental/aarch64-macos/hello_world_with_updates.3.zig create mode 100644 test/incremental/aarch64-macos/hello_world_with_updates.4.zig create mode 100644 test/incremental/aarch64-macos/hello_world_with_updates.5.zig create mode 100644 test/incremental/aarch64-macos/hello_world_with_updates.6.zig create mode 100644 test/incremental/large_add_function.zig delete mode 100644 test/stage2/aarch64.zig diff --git a/test/cases.zig b/test/cases.zig index fc38794cdd..c615d84099 100644 --- a/test/cases.zig +++ b/test/cases.zig @@ -10,7 +10,6 @@ pub fn addCases(ctx: *TestContext) !void { try @import("compile_errors.zig").addCases(ctx); try @import("stage2/cbe.zig").addCases(ctx); try @import("stage2/arm.zig").addCases(ctx); - try @import("stage2/aarch64.zig").addCases(ctx); try @import("stage2/llvm.zig").addCases(ctx); try @import("stage2/plan9.zig").addCases(ctx); try @import("stage2/x86_64.zig").addCases(ctx); diff --git a/test/incremental/aarch64-linux/conditional_branches.0.zig b/test/incremental/aarch64-linux/conditional_branches.0.zig new file mode 100644 index 0000000000..28435b9d4a --- /dev/null +++ b/test/incremental/aarch64-linux/conditional_branches.0.zig @@ -0,0 +1,26 @@ +pub fn main() void { + foo(123); +} + +fn foo(x: u64) void { + if (x > 42) { + print(); + } +} + +fn print() void { + asm volatile ("svc #0" + : + : [number] "{x8}" (64), + [arg1] "{x0}" (1), + [arg2] "{x1}" (@ptrToInt("Hello, World!\n")), + [arg3] "{x2}" ("Hello, World!\n".len), + : "memory", "cc" + ); +} + +// run +// target=aarch64-linux +// +// Hello, World! +// diff --git a/test/incremental/aarch64-linux/conditional_branches.1.zig b/test/incremental/aarch64-linux/conditional_branches.1.zig new file mode 100644 index 0000000000..e03758fcb7 --- /dev/null +++ b/test/incremental/aarch64-linux/conditional_branches.1.zig @@ -0,0 +1,25 @@ +pub fn main() void { + foo(true); +} + +fn foo(x: bool) void { + if (x) { + print(); + } +} + +fn print() void { + asm volatile ("svc #0" + : + : [number] "{x8}" (64), + [arg1] "{x0}" (1), + [arg2] "{x1}" (@ptrToInt("Hello, World!\n")), + [arg3] "{x2}" ("Hello, World!\n".len), + : "memory", "cc" + ); +} + +// run +// +// Hello, World! +// diff --git a/test/incremental/aarch64-linux/hello_world_with_updates.0.zig b/test/incremental/aarch64-linux/hello_world_with_updates.0.zig new file mode 100644 index 0000000000..7a87d74dc3 --- /dev/null +++ b/test/incremental/aarch64-linux/hello_world_with_updates.0.zig @@ -0,0 +1,31 @@ +pub export fn _start() noreturn { + print(); + exit(0); +} + +fn print() void { + asm volatile ("svc #0" + : + : [number] "{x8}" (64), + [arg1] "{x0}" (1), + [arg2] "{x1}" (@ptrToInt("Hello, World!\n")), + [arg3] "{x2}" ("Hello, World!\n".len), + : "memory", "cc" + ); +} + +fn exit(ret: usize) noreturn { + asm volatile ("svc #0" + : + : [number] "{x8}" (93), + [arg1] "{x0}" (ret), + : "memory", "cc" + ); + unreachable; +} + +// run +// target=aarch64-linux +// +// Hello, World! +// diff --git a/test/incremental/aarch64-linux/hello_world_with_updates.1.zig b/test/incremental/aarch64-linux/hello_world_with_updates.1.zig new file mode 100644 index 0000000000..a5ca0d9926 --- /dev/null +++ b/test/incremental/aarch64-linux/hello_world_with_updates.1.zig @@ -0,0 +1,36 @@ +pub export fn _start() noreturn { + print(); + print(); + print(); + print(); + exit(0); +} + +fn print() void { + asm volatile ("svc #0" + : + : [number] "{x8}" (64), + [arg1] "{x0}" (1), + [arg2] "{x1}" (@ptrToInt("Hello, World!\n")), + [arg3] "{x2}" ("Hello, World!\n".len), + : "memory", "cc" + ); +} + +fn exit(ret: usize) noreturn { + asm volatile ("svc #0" + : + : [number] "{x8}" (93), + [arg1] "{x0}" (ret), + : "memory", "cc" + ); + unreachable; +} + +// run +// +// Hello, World! +// Hello, World! +// Hello, World! +// Hello, World! +// diff --git a/test/incremental/aarch64-linux/hello_world_with_updates.2.zig b/test/incremental/aarch64-linux/hello_world_with_updates.2.zig new file mode 100644 index 0000000000..71f0f160bc --- /dev/null +++ b/test/incremental/aarch64-linux/hello_world_with_updates.2.zig @@ -0,0 +1,21 @@ +pub fn main() void { + print(); + print(); +} + +fn print() void { + asm volatile ("svc #0" + : + : [number] "{x8}" (64), + [arg1] "{x0}" (1), + [arg2] "{x1}" (@ptrToInt("Hello, World!\n")), + [arg3] "{x2}" ("Hello, World!\n".len), + : "memory", "cc" + ); +} + +// run +// +// Hello, World! +// Hello, World! +// diff --git a/test/incremental/aarch64-macos/hello_world_with_updates.0.zig b/test/incremental/aarch64-macos/hello_world_with_updates.0.zig new file mode 100644 index 0000000000..11a379a9a9 --- /dev/null +++ b/test/incremental/aarch64-macos/hello_world_with_updates.0.zig @@ -0,0 +1,5 @@ +// error +// output_mode=Exe +// target=aarch64-macos +// +// :109:9: error: struct 'tmp.tmp' has no member named 'main' diff --git a/test/incremental/aarch64-macos/hello_world_with_updates.1.zig b/test/incremental/aarch64-macos/hello_world_with_updates.1.zig new file mode 100644 index 0000000000..909fc9ccfb --- /dev/null +++ b/test/incremental/aarch64-macos/hello_world_with_updates.1.zig @@ -0,0 +1,5 @@ +pub export fn main() noreturn {} + +// error +// +// :1:32: error: expected noreturn, found void diff --git a/test/incremental/aarch64-macos/hello_world_with_updates.2.zig b/test/incremental/aarch64-macos/hello_world_with_updates.2.zig new file mode 100644 index 0000000000..fb8cb39edd --- /dev/null +++ b/test/incremental/aarch64-macos/hello_world_with_updates.2.zig @@ -0,0 +1,19 @@ +extern "c" fn write(usize, usize, usize) usize; +extern "c" fn exit(usize) noreturn; + +pub export fn main() noreturn { + print(); + + exit(0); +} + +fn print() void { + const msg = @ptrToInt("Hello, World!\n"); + const len = 14; + _ = write(1, msg, len); +} + +// run +// +// Hello, World! +// diff --git a/test/incremental/aarch64-macos/hello_world_with_updates.3.zig b/test/incremental/aarch64-macos/hello_world_with_updates.3.zig new file mode 100644 index 0000000000..f6e233886b --- /dev/null +++ b/test/incremental/aarch64-macos/hello_world_with_updates.3.zig @@ -0,0 +1,16 @@ +extern "c" fn write(usize, usize, usize) usize; + +pub fn main() void { + print(); +} + +fn print() void { + const msg = @ptrToInt("Hello, World!\n"); + const len = 14; + _ = write(1, msg, len); +} + +// run +// +// Hello, World! +// diff --git a/test/incremental/aarch64-macos/hello_world_with_updates.4.zig b/test/incremental/aarch64-macos/hello_world_with_updates.4.zig new file mode 100644 index 0000000000..f89cef7354 --- /dev/null +++ b/test/incremental/aarch64-macos/hello_world_with_updates.4.zig @@ -0,0 +1,22 @@ +extern "c" fn write(usize, usize, usize) usize; + +pub fn main() void { + print(); + print(); + print(); + print(); +} + +fn print() void { + const msg = @ptrToInt("Hello, World!\n"); + const len = 14; + _ = write(1, msg, len); +} + +// run +// +// Hello, World! +// Hello, World! +// Hello, World! +// Hello, World! +// diff --git a/test/incremental/aarch64-macos/hello_world_with_updates.5.zig b/test/incremental/aarch64-macos/hello_world_with_updates.5.zig new file mode 100644 index 0000000000..0d7f97578a --- /dev/null +++ b/test/incremental/aarch64-macos/hello_world_with_updates.5.zig @@ -0,0 +1,16 @@ +extern "c" fn write(usize, usize, usize) usize; + +pub fn main() void { + print(); +} + +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); +} + +// run +// +// What is up? This is a longer message that will force the data to be relocated in virtual address space. +// diff --git a/test/incremental/aarch64-macos/hello_world_with_updates.6.zig b/test/incremental/aarch64-macos/hello_world_with_updates.6.zig new file mode 100644 index 0000000000..3ce2cb7176 --- /dev/null +++ b/test/incremental/aarch64-macos/hello_world_with_updates.6.zig @@ -0,0 +1,18 @@ +extern "c" fn write(usize, usize, usize) usize; + +pub fn main() void { + print(); + print(); +} + +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); +} + +// run +// +// 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. +// diff --git a/test/incremental/large_add_function.zig b/test/incremental/large_add_function.zig new file mode 100644 index 0000000000..8b0e9b879b --- /dev/null +++ b/test/incremental/large_add_function.zig @@ -0,0 +1,38 @@ +pub fn main() void { + assert(add(3, 4) == 791); +} + +fn add(a: u32, b: u32) u32 { + const x: u32 = blk: { + const c = a + b; // 7 + const d = a + c; // 10 + const e = d + b; // 14 + const f = d + e; // 24 + const g = e + f; // 38 + const h = f + g; // 62 + const i = g + h; // 100 + const j = i + d; // 110 + const k = i + j; // 210 + const l = k + c; // 217 + const m = l + d; // 227 + const n = m + e; // 241 + const o = n + f; // 265 + const p = o + g; // 303 + const q = p + h; // 365 + const r = q + i; // 465 + const s = r + j; // 575 + const t = s + k; // 785 + break :blk t; + }; + const y = x + a; // 788 + const z = y + a; // 791 + return z; +} + +fn assert(ok: bool) void { + if (!ok) unreachable; +} + +// run +// target=aarch64-linux,aarch64-macos +// diff --git a/test/stage2/aarch64.zig b/test/stage2/aarch64.zig deleted file mode 100644 index 84334c2a29..0000000000 --- a/test/stage2/aarch64.zig +++ /dev/null @@ -1,271 +0,0 @@ -const std = @import("std"); -const CrossTarget = std.zig.CrossTarget; -const TestContext = @import("../../src/test.zig").TestContext; - -const linux_aarch64 = CrossTarget{ - .cpu_arch = .aarch64, - .os_tag = .linux, -}; -const macos_aarch64 = CrossTarget{ - .cpu_arch = .aarch64, - .os_tag = .macos, -}; - -pub fn addCases(ctx: *TestContext) !void { - // Linux tests - { - var case = ctx.exe("linux_aarch64 hello world", linux_aarch64); - // Regular old hello world - case.addCompareOutput( - \\pub fn main() void { - \\ print(); - \\} - \\ - \\fn print() void { - \\ asm volatile ("svc #0" - \\ : - \\ : [number] "{x8}" (64), - \\ [arg1] "{x0}" (1), - \\ [arg2] "{x1}" (@ptrToInt("Hello, World!\n")), - \\ [arg3] "{x2}" ("Hello, World!\n".len) - \\ : "memory", "cc" - \\ ); - \\} - , - "Hello, World!\n", - ); - } - - { - var case = ctx.exe("exit fn taking argument", linux_aarch64); - - case.addCompareOutput( - \\pub export fn _start() noreturn { - \\ exit(0); - \\} - \\ - \\fn exit(ret: usize) noreturn { - \\ asm volatile ("svc #0" - \\ : - \\ : [number] "{x8}" (93), - \\ [arg1] "{x0}" (ret) - \\ : "memory", "cc" - \\ ); - \\ unreachable; - \\} - , - "", - ); - } - - { - var case = ctx.exe("conditional branches", linux_aarch64); - - case.addCompareOutput( - \\pub fn main() void { - \\ foo(123); - \\} - \\ - \\fn foo(x: u64) void { - \\ if (x > 42) { - \\ print(); - \\ } - \\} - \\ - \\fn print() void { - \\ asm volatile ("svc #0" - \\ : - \\ : [number] "{x8}" (64), - \\ [arg1] "{x0}" (1), - \\ [arg2] "{x1}" (@ptrToInt("Hello, World!\n")), - \\ [arg3] "{x2}" ("Hello, World!\n".len), - \\ : "memory", "cc" - \\ ); - \\} - , - "Hello, World!\n", - ); - - case.addCompareOutput( - \\pub fn main() void { - \\ foo(true); - \\} - \\ - \\fn foo(x: bool) void { - \\ if (x) { - \\ print(); - \\ } - \\} - \\ - \\fn print() void { - \\ asm volatile ("svc #0" - \\ : - \\ : [number] "{x8}" (64), - \\ [arg1] "{x0}" (1), - \\ [arg2] "{x1}" (@ptrToInt("Hello, World!\n")), - \\ [arg3] "{x2}" ("Hello, World!\n".len), - \\ : "memory", "cc" - \\ ); - \\} - , - "Hello, World!\n", - ); - } - - { - var case = ctx.exe("large add function", linux_aarch64); - - case.addCompareOutput( - \\pub fn main() void { - \\ assert(add(3, 4) == 791); - \\} - \\ - \\fn add(a: u32, b: u32) u32 { - \\ const x: u32 = blk: { - \\ const c = a + b; // 7 - \\ const d = a + c; // 10 - \\ const e = d + b; // 14 - \\ const f = d + e; // 24 - \\ const g = e + f; // 38 - \\ const h = f + g; // 62 - \\ const i = g + h; // 100 - \\ const j = i + d; // 110 - \\ const k = i + j; // 210 - \\ const l = k + c; // 217 - \\ const m = l + d; // 227 - \\ const n = m + e; // 241 - \\ const o = n + f; // 265 - \\ const p = o + g; // 303 - \\ const q = p + h; // 365 - \\ const r = q + i; // 465 - \\ const s = r + j; // 575 - \\ const t = s + k; // 785 - \\ break :blk t; - \\ }; - \\ const y = x + a; // 788 - \\ const z = y + a; // 791 - \\ return z; - \\} - \\ - \\fn assert(ok: bool) void { - \\ if (!ok) unreachable; - \\} - , - "", - ); - } - - // macOS tests - { - var case = ctx.exe("hello world with updates", macos_aarch64); - case.addError("", &[_][]const u8{ - ":109:9: error: struct 'tmp.tmp' has no member named 'main'", - }); - - // Incorrect return type - case.addError( - \\pub export fn main() 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; - \\ - \\pub export fn main() noreturn { - \\ print(); - \\ - \\ exit(0); - \\} - \\ - \\fn print() void { - \\ const msg = @ptrToInt("Hello, World!\n"); - \\ const len = 14; - \\ _ = write(1, msg, len); - \\} - , - "Hello, World!\n", - ); - - // Now using start.zig without an explicit extern exit fn - case.addCompareOutput( - \\extern "c" fn write(usize, usize, usize) usize; - \\ - \\pub fn main() void { - \\ print(); - \\} - \\ - \\fn print() void { - \\ const msg = @ptrToInt("Hello, World!\n"); - \\ const len = 14; - \\ _ = write(1, msg, len); - \\} - , - "Hello, World!\n", - ); - - // Print it 4 times and force growth and realloc. - case.addCompareOutput( - \\extern "c" fn write(usize, usize, usize) usize; - \\ - \\pub fn main() void { - \\ print(); - \\ print(); - \\ print(); - \\ print(); - \\} - \\ - \\fn print() void { - \\ const msg = @ptrToInt("Hello, World!\n"); - \\ const len = 14; - \\ _ = write(1, msg, len); - \\} - , - \\Hello, World! - \\Hello, World! - \\Hello, World! - \\Hello, World! - \\ - ); - - // Print it once, and change the message. - case.addCompareOutput( - \\extern "c" fn write(usize, usize, usize) usize; - \\ - \\pub fn main() void { - \\ print(); - \\} - \\ - \\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; - \\ - \\pub fn main() void { - \\ print(); - \\ print(); - \\} - \\ - \\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. - \\ - ); - } -}