| ... | ... | @@ -1,271 +0,0 @@ |
| 1 | | const std = @import("std"); |
| 2 | | const CrossTarget = std.zig.CrossTarget; |
| 3 | | const TestContext = @import("../../src/test.zig").TestContext; |
| 4 | | |
| 5 | | const linux_aarch64 = CrossTarget{ |
| 6 | | .cpu_arch = .aarch64, |
| 7 | | .os_tag = .linux, |
| 8 | | }; |
| 9 | | const macos_aarch64 = CrossTarget{ |
| 10 | | .cpu_arch = .aarch64, |
| 11 | | .os_tag = .macos, |
| 12 | | }; |
| 13 | | |
| 14 | | pub fn addCases(ctx: *TestContext) !void { |
| 15 | | // Linux tests |
| 16 | | { |
| 17 | | var case = ctx.exe("linux_aarch64 hello world", linux_aarch64); |
| 18 | | // Regular old hello world |
| 19 | | case.addCompareOutput( |
| 20 | | \\pub fn main() void { |
| 21 | | \\ print(); |
| 22 | | \\} |
| 23 | | \\ |
| 24 | | \\fn print() void { |
| 25 | | \\ asm volatile ("svc #0" |
| 26 | | \\ : |
| 27 | | \\ : [number] "{x8}" (64), |
| 28 | | \\ [arg1] "{x0}" (1), |
| 29 | | \\ [arg2] "{x1}" (@ptrToInt("Hello, World!\n")), |
| 30 | | \\ [arg3] "{x2}" ("Hello, World!\n".len) |
| 31 | | \\ : "memory", "cc" |
| 32 | | \\ ); |
| 33 | | \\} |
| 34 | | , |
| 35 | | "Hello, World!\n", |
| 36 | | ); |
| 37 | | } |
| 38 | | |
| 39 | | { |
| 40 | | var case = ctx.exe("exit fn taking argument", linux_aarch64); |
| 41 | | |
| 42 | | case.addCompareOutput( |
| 43 | | \\pub export fn _start() noreturn { |
| 44 | | \\ exit(0); |
| 45 | | \\} |
| 46 | | \\ |
| 47 | | \\fn exit(ret: usize) noreturn { |
| 48 | | \\ asm volatile ("svc #0" |
| 49 | | \\ : |
| 50 | | \\ : [number] "{x8}" (93), |
| 51 | | \\ [arg1] "{x0}" (ret) |
| 52 | | \\ : "memory", "cc" |
| 53 | | \\ ); |
| 54 | | \\ unreachable; |
| 55 | | \\} |
| 56 | | , |
| 57 | | "", |
| 58 | | ); |
| 59 | | } |
| 60 | | |
| 61 | | { |
| 62 | | var case = ctx.exe("conditional branches", linux_aarch64); |
| 63 | | |
| 64 | | case.addCompareOutput( |
| 65 | | \\pub fn main() void { |
| 66 | | \\ foo(123); |
| 67 | | \\} |
| 68 | | \\ |
| 69 | | \\fn foo(x: u64) void { |
| 70 | | \\ if (x > 42) { |
| 71 | | \\ print(); |
| 72 | | \\ } |
| 73 | | \\} |
| 74 | | \\ |
| 75 | | \\fn print() void { |
| 76 | | \\ asm volatile ("svc #0" |
| 77 | | \\ : |
| 78 | | \\ : [number] "{x8}" (64), |
| 79 | | \\ [arg1] "{x0}" (1), |
| 80 | | \\ [arg2] "{x1}" (@ptrToInt("Hello, World!\n")), |
| 81 | | \\ [arg3] "{x2}" ("Hello, World!\n".len), |
| 82 | | \\ : "memory", "cc" |
| 83 | | \\ ); |
| 84 | | \\} |
| 85 | | , |
| 86 | | "Hello, World!\n", |
| 87 | | ); |
| 88 | | |
| 89 | | case.addCompareOutput( |
| 90 | | \\pub fn main() void { |
| 91 | | \\ foo(true); |
| 92 | | \\} |
| 93 | | \\ |
| 94 | | \\fn foo(x: bool) void { |
| 95 | | \\ if (x) { |
| 96 | | \\ print(); |
| 97 | | \\ } |
| 98 | | \\} |
| 99 | | \\ |
| 100 | | \\fn print() void { |
| 101 | | \\ asm volatile ("svc #0" |
| 102 | | \\ : |
| 103 | | \\ : [number] "{x8}" (64), |
| 104 | | \\ [arg1] "{x0}" (1), |
| 105 | | \\ [arg2] "{x1}" (@ptrToInt("Hello, World!\n")), |
| 106 | | \\ [arg3] "{x2}" ("Hello, World!\n".len), |
| 107 | | \\ : "memory", "cc" |
| 108 | | \\ ); |
| 109 | | \\} |
| 110 | | , |
| 111 | | "Hello, World!\n", |
| 112 | | ); |
| 113 | | } |
| 114 | | |
| 115 | | { |
| 116 | | var case = ctx.exe("large add function", linux_aarch64); |
| 117 | | |
| 118 | | case.addCompareOutput( |
| 119 | | \\pub fn main() void { |
| 120 | | \\ assert(add(3, 4) == 791); |
| 121 | | \\} |
| 122 | | \\ |
| 123 | | \\fn add(a: u32, b: u32) u32 { |
| 124 | | \\ const x: u32 = blk: { |
| 125 | | \\ const c = a + b; // 7 |
| 126 | | \\ const d = a + c; // 10 |
| 127 | | \\ const e = d + b; // 14 |
| 128 | | \\ const f = d + e; // 24 |
| 129 | | \\ const g = e + f; // 38 |
| 130 | | \\ const h = f + g; // 62 |
| 131 | | \\ const i = g + h; // 100 |
| 132 | | \\ const j = i + d; // 110 |
| 133 | | \\ const k = i + j; // 210 |
| 134 | | \\ const l = k + c; // 217 |
| 135 | | \\ const m = l + d; // 227 |
| 136 | | \\ const n = m + e; // 241 |
| 137 | | \\ const o = n + f; // 265 |
| 138 | | \\ const p = o + g; // 303 |
| 139 | | \\ const q = p + h; // 365 |
| 140 | | \\ const r = q + i; // 465 |
| 141 | | \\ const s = r + j; // 575 |
| 142 | | \\ const t = s + k; // 785 |
| 143 | | \\ break :blk t; |
| 144 | | \\ }; |
| 145 | | \\ const y = x + a; // 788 |
| 146 | | \\ const z = y + a; // 791 |
| 147 | | \\ return z; |
| 148 | | \\} |
| 149 | | \\ |
| 150 | | \\fn assert(ok: bool) void { |
| 151 | | \\ if (!ok) unreachable; |
| 152 | | \\} |
| 153 | | , |
| 154 | | "", |
| 155 | | ); |
| 156 | | } |
| 157 | | |
| 158 | | // macOS tests |
| 159 | | { |
| 160 | | var case = ctx.exe("hello world with updates", macos_aarch64); |
| 161 | | case.addError("", &[_][]const u8{ |
| 162 | | ":109:9: error: struct 'tmp.tmp' has no member named 'main'", |
| 163 | | }); |
| 164 | | |
| 165 | | // Incorrect return type |
| 166 | | case.addError( |
| 167 | | \\pub export fn main() noreturn { |
| 168 | | \\} |
| 169 | | , &[_][]const u8{ |
| 170 | | ":2:1: error: expected noreturn, found void", |
| 171 | | }); |
| 172 | | |
| 173 | | // Regular old hello world |
| 174 | | case.addCompareOutput( |
| 175 | | \\extern "c" fn write(usize, usize, usize) usize; |
| 176 | | \\extern "c" fn exit(usize) noreturn; |
| 177 | | \\ |
| 178 | | \\pub export fn main() noreturn { |
| 179 | | \\ print(); |
| 180 | | \\ |
| 181 | | \\ exit(0); |
| 182 | | \\} |
| 183 | | \\ |
| 184 | | \\fn print() void { |
| 185 | | \\ const msg = @ptrToInt("Hello, World!\n"); |
| 186 | | \\ const len = 14; |
| 187 | | \\ _ = write(1, msg, len); |
| 188 | | \\} |
| 189 | | , |
| 190 | | "Hello, World!\n", |
| 191 | | ); |
| 192 | | |
| 193 | | // Now using start.zig without an explicit extern exit fn |
| 194 | | case.addCompareOutput( |
| 195 | | \\extern "c" fn write(usize, usize, usize) usize; |
| 196 | | \\ |
| 197 | | \\pub fn main() void { |
| 198 | | \\ print(); |
| 199 | | \\} |
| 200 | | \\ |
| 201 | | \\fn print() void { |
| 202 | | \\ const msg = @ptrToInt("Hello, World!\n"); |
| 203 | | \\ const len = 14; |
| 204 | | \\ _ = write(1, msg, len); |
| 205 | | \\} |
| 206 | | , |
| 207 | | "Hello, World!\n", |
| 208 | | ); |
| 209 | | |
| 210 | | // Print it 4 times and force growth and realloc. |
| 211 | | case.addCompareOutput( |
| 212 | | \\extern "c" fn write(usize, usize, usize) usize; |
| 213 | | \\ |
| 214 | | \\pub fn main() void { |
| 215 | | \\ print(); |
| 216 | | \\ print(); |
| 217 | | \\ print(); |
| 218 | | \\ print(); |
| 219 | | \\} |
| 220 | | \\ |
| 221 | | \\fn print() void { |
| 222 | | \\ const msg = @ptrToInt("Hello, World!\n"); |
| 223 | | \\ const len = 14; |
| 224 | | \\ _ = write(1, msg, len); |
| 225 | | \\} |
| 226 | | , |
| 227 | | \\Hello, World! |
| 228 | | \\Hello, World! |
| 229 | | \\Hello, World! |
| 230 | | \\Hello, World! |
| 231 | | \\ |
| 232 | | ); |
| 233 | | |
| 234 | | // Print it once, and change the message. |
| 235 | | case.addCompareOutput( |
| 236 | | \\extern "c" fn write(usize, usize, usize) usize; |
| 237 | | \\ |
| 238 | | \\pub fn main() void { |
| 239 | | \\ print(); |
| 240 | | \\} |
| 241 | | \\ |
| 242 | | \\fn print() void { |
| 243 | | \\ const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n"); |
| 244 | | \\ const len = 104; |
| 245 | | \\ _ = write(1, msg, len); |
| 246 | | \\} |
| 247 | | , |
| 248 | | "What is up? This is a longer message that will force the data to be relocated in virtual address space.\n", |
| 249 | | ); |
| 250 | | |
| 251 | | // Now we print it twice. |
| 252 | | case.addCompareOutput( |
| 253 | | \\extern "c" fn write(usize, usize, usize) usize; |
| 254 | | \\ |
| 255 | | \\pub fn main() void { |
| 256 | | \\ print(); |
| 257 | | \\ print(); |
| 258 | | \\} |
| 259 | | \\ |
| 260 | | \\fn print() void { |
| 261 | | \\ const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n"); |
| 262 | | \\ const len = 104; |
| 263 | | \\ _ = write(1, msg, len); |
| 264 | | \\} |
| 265 | | , |
| 266 | | \\What is up? This is a longer message that will force the data to be relocated in virtual address space. |
| 267 | | \\What is up? This is a longer message that will force the data to be relocated in virtual address space. |
| 268 | | \\ |
| 269 | | ); |
| 270 | | } |
| 271 | | } |