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