| ... | ... | @@ -4,7 +4,7 @@ |
| 4 | 4 | //! To run all the tests on the tier 1 architecture you can use: |
| 5 | 5 | //! zig build test-c-abi -fqemu |
| 6 | 6 | //! To run the tests on a specific architecture: |
| 7 | | //! zig test -fno-stage1 -lc main.zig cfuncs.c -target mips-linux --test-cmd qemu-mips --test-cmd-bin |
| 7 | //! zig test -lc main.zig cfuncs.c -target mips-linux --test-cmd qemu-mips --test-cmd-bin |
| 8 | 8 | const std = @import("std"); |
| 9 | 9 | const builtin = @import("builtin"); |
| 10 | 10 | const print = std.debug.print; |
| ... | ... | @@ -764,6 +764,7 @@ extern fn c_float_array_struct(FloatArrayStruct) void; |
| 764 | 764 | extern fn c_ret_float_array_struct() FloatArrayStruct; |
| 765 | 765 | |
| 766 | 766 | test "Float array like struct" { |
| 767 | if (builtin.cpu.arch == .x86 and builtin.mode != .Debug) return error.SkipZigTest; |
| 767 | 768 | if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; |
| 768 | 769 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; |
| 769 | 770 | |
| ... | ... | @@ -824,7 +825,9 @@ extern fn c_big_vec(BigVec) void; |
| 824 | 825 | extern fn c_ret_big_vec() BigVec; |
| 825 | 826 | |
| 826 | 827 | test "big simd vector" { |
| 828 | if (comptime builtin.cpu.arch.isMIPS() and builtin.mode != .Debug) return error.SkipZigTest; |
| 827 | 829 | if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; |
| 830 | if (builtin.cpu.arch == .x86_64 and builtin.os.tag == .macos and builtin.mode != .Debug) return error.SkipZigTest; |
| 828 | 831 | |
| 829 | 832 | c_big_vec(.{ 1, 2, 3, 4, 5, 6, 7, 8 }); |
| 830 | 833 | |
| ... | ... | @@ -875,6 +878,8 @@ test "DC: Zig passes to C" { |
| 875 | 878 | try expectOk(c_assert_DC(.{ .v1 = -0.25, .v2 = 15 })); |
| 876 | 879 | } |
| 877 | 880 | test "DC: Zig returns to C" { |
| 881 | if (builtin.cpu.arch == .x86 and builtin.mode != .Debug) return error.SkipZigTest; |
| 882 | if (comptime builtin.cpu.arch.isMIPS() and builtin.mode != .Debug) return error.SkipZigTest; |
| 878 | 883 | if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest; |
| 879 | 884 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; |
| 880 | 885 | if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; |
| ... | ... | @@ -888,6 +893,8 @@ test "DC: C passes to Zig" { |
| 888 | 893 | try expectOk(c_send_DC()); |
| 889 | 894 | } |
| 890 | 895 | test "DC: C returns to Zig" { |
| 896 | if (builtin.cpu.arch == .x86 and builtin.mode != .Debug) return error.SkipZigTest; |
| 897 | if (comptime builtin.cpu.arch.isMIPS() and builtin.mode != .Debug) return error.SkipZigTest; |
| 891 | 898 | if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest; |
| 892 | 899 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; |
| 893 | 900 | if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; |
| ... | ... | @@ -920,13 +927,17 @@ test "CFF: Zig passes to C" { |
| 920 | 927 | try expectOk(c_assert_CFF(.{ .v1 = 39, .v2 = 0.875, .v3 = 1.0 })); |
| 921 | 928 | } |
| 922 | 929 | test "CFF: Zig returns to C" { |
| 930 | if (builtin.cpu.arch == .x86 and builtin.mode != .Debug) return error.SkipZigTest; |
| 923 | 931 | if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; |
| 924 | 932 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; |
| 925 | 933 | if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; |
| 926 | 934 | try expectOk(c_assert_ret_CFF()); |
| 927 | 935 | } |
| 928 | 936 | test "CFF: C passes to Zig" { |
| 937 | if (builtin.cpu.arch == .x86_64 and builtin.mode != .Debug) return error.SkipZigTest; |
| 929 | 938 | if (builtin.target.cpu.arch == .x86) return error.SkipZigTest; |
| 939 | if (comptime builtin.cpu.arch.isRISCV() and builtin.mode != .Debug) return error.SkipZigTest; |
| 940 | if (builtin.cpu.arch == .aarch64 and builtin.mode != .Debug) return error.SkipZigTest; |
| 930 | 941 | if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; |
| 931 | 942 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; |
| 932 | 943 | if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; |
| ... | ... | @@ -934,6 +945,10 @@ test "CFF: C passes to Zig" { |
| 934 | 945 | try expectOk(c_send_CFF()); |
| 935 | 946 | } |
| 936 | 947 | test "CFF: C returns to Zig" { |
| 948 | if (builtin.cpu.arch == .x86_64 and builtin.mode != .Debug) return error.SkipZigTest; |
| 949 | if (builtin.cpu.arch == .x86 and builtin.mode != .Debug) return error.SkipZigTest; |
| 950 | if (builtin.cpu.arch == .aarch64 and builtin.mode != .Debug) return error.SkipZigTest; |
| 951 | if (comptime builtin.cpu.arch.isRISCV() and builtin.mode != .Debug) return error.SkipZigTest; |
| 937 | 952 | if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest; |
| 938 | 953 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; |
| 939 | 954 | if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; |
| ... | ... | @@ -967,6 +982,7 @@ test "PD: Zig passes to C" { |
| 967 | 982 | } |
| 968 | 983 | test "PD: Zig returns to C" { |
| 969 | 984 | if (builtin.target.cpu.arch == .x86) return error.SkipZigTest; |
| 985 | if (comptime builtin.cpu.arch.isMIPS() and builtin.mode != .Debug) return error.SkipZigTest; |
| 970 | 986 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; |
| 971 | 987 | if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; |
| 972 | 988 | try expectOk(c_assert_ret_PD()); |
| ... | ... | @@ -980,6 +996,7 @@ test "PD: C passes to Zig" { |
| 980 | 996 | } |
| 981 | 997 | test "PD: C returns to Zig" { |
| 982 | 998 | if (builtin.target.cpu.arch == .x86) return error.SkipZigTest; |
| 999 | if (comptime builtin.cpu.arch.isMIPS() and builtin.mode != .Debug) return error.SkipZigTest; |
| 983 | 1000 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; |
| 984 | 1001 | if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest; |
| 985 | 1002 | try expectEqual(c_ret_PD(), .{ .v1 = null, .v2 = 0.5 }); |
| ... | ... | @@ -1014,6 +1031,7 @@ extern fn c_modify_by_ref_param(ByRef) ByRef; |
| 1014 | 1031 | |
| 1015 | 1032 | test "C function modifies by ref param" { |
| 1016 | 1033 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; |
| 1034 | if (builtin.cpu.arch == .x86_64 and builtin.os.tag == .windows and builtin.mode != .Debug) return error.SkipZigTest; |
| 1017 | 1035 | |
| 1018 | 1036 | const res = c_modify_by_ref_param(.{ .val = 1, .arr = undefined }); |
| 1019 | 1037 | try expect(res.val == 42); |
| ... | ... | @@ -1034,6 +1052,8 @@ const ByVal = extern struct { |
| 1034 | 1052 | |
| 1035 | 1053 | extern fn c_func_ptr_byval(*anyopaque, *anyopaque, ByVal, c_ulong, *anyopaque, c_ulong) void; |
| 1036 | 1054 | test "C function that takes byval struct called via function pointer" { |
| 1055 | if (builtin.cpu.arch == .x86 and builtin.mode != .Debug) return error.SkipZigTest; |
| 1056 | if (comptime builtin.cpu.arch.isMIPS() and builtin.mode != .Debug) return error.SkipZigTest; |
| 1037 | 1057 | if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest; |
| 1038 | 1058 | |
| 1039 | 1059 | var fn_ptr = &c_func_ptr_byval; |