| 1 | const std = @import("std"); |
| 2 | const expect = std.testing.expect; |
| 3 | const expectEqualSlices = std.testing.expectEqualSlices; |
| 4 | const expectEqualStrings = std.testing.expectEqualStrings; |
| 5 | const mem = std.mem; |
| 6 | const builtin = @import("builtin"); |
| 7 | |
| 8 | // can't really run this test but we can make sure it has no compile error |
| 9 | // and generates code |
| 10 | const vram = @as([*]volatile u8, @ptrFromInt(0x20000000))[0..0x8000]; |
| 11 | export fn writeToVRam() void { |
| 12 | if (builtin.zig_backend == .stage2_riscv64) return; |
| 13 | |
| 14 | vram[0] = 'X'; |
| 15 | } |
| 16 | |
| 17 | const PackedStruct = packed struct { |
| 18 | a: u8, |
| 19 | b: u8, |
| 20 | }; |
| 21 | const PackedUnion = packed union { |
| 22 | a: packed struct(u32) { |
| 23 | a: u8, |
| 24 | b: u24 = 0, |
| 25 | }, |
| 26 | b: u32, |
| 27 | }; |
| 28 | |
| 29 | test "packed struct, enum, union parameters in extern function" { |
| 30 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 31 | |
| 32 | testPackedStuff(&(PackedStruct{ |
| 33 | .a = 1, |
| 34 | .b = 2, |
| 35 | }), &(PackedUnion{ .a = .{ .a = 1 } })); |
| 36 | } |
| 37 | |
| 38 | export fn testPackedStuff(a: *const PackedStruct, b: *const PackedUnion) void { |
| 39 | if (false) { |
| 40 | a; |
| 41 | b; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | test "export function alias" { |
| 46 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 47 | |
| 48 | _ = struct { |
| 49 | fn foo_internal() callconv(.c) u32 { |
| 50 | return 123; |
| 51 | } |
| 52 | export const foo_exported = foo_internal; |
| 53 | }; |
| 54 | const Import = struct { |
| 55 | extern fn foo_exported() u32; |
| 56 | }; |
| 57 | try expect(Import.foo_exported() == 123); |
| 58 | } |