make C ABI tests compile on arm, mips and riscv
x86_64 24/25 x86 15/25 aarch64 25/25 - all arm 18/25 mips 10/24 riscv64 13/25 wasm32 25/25 - all
This commit is contained in:
@@ -16,10 +16,22 @@ static void assert_or_panic(bool ok) {
|
||||
# define ZIG_NO_I128
|
||||
#endif
|
||||
|
||||
#ifdef __arm__
|
||||
# define ZIG_NO_I128
|
||||
#endif
|
||||
|
||||
#ifdef __mips__
|
||||
# define ZIG_NO_I128
|
||||
#endif
|
||||
|
||||
#ifdef __i386__
|
||||
# define ZIG_NO_COMPLEX
|
||||
#endif
|
||||
|
||||
#ifdef __mips__
|
||||
# define ZIG_NO_COMPLEX
|
||||
#endif
|
||||
|
||||
#ifndef ZIG_NO_I128
|
||||
struct i128 {
|
||||
__int128 value;
|
||||
@@ -237,12 +249,14 @@ void run_c_tests(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined __mips__ && !defined __riscv
|
||||
{
|
||||
struct BigStruct s = {1, 2, 3, 4, 5};
|
||||
zig_big_struct(s);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef __i386__
|
||||
#if !defined __i386__ && !defined __arm__ && !defined __mips__ && !defined __riscv
|
||||
{
|
||||
struct SmallStructInts s = {1, 2, 3, 4};
|
||||
zig_small_struct_ints(s);
|
||||
@@ -267,25 +281,28 @@ void run_c_tests(void) {
|
||||
zig_small_packed_struct(s);
|
||||
}
|
||||
|
||||
#ifndef __i386__
|
||||
#if !defined __i386__ && !defined __arm__ && !defined __mips__ && !defined __riscv
|
||||
{
|
||||
struct SplitStructInts s = {1234, 100, 1337};
|
||||
zig_split_struct_ints(s);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined __arm__ && !defined __riscv
|
||||
{
|
||||
struct MedStructMixed s = {1234, 100.0f, 1337.0f};
|
||||
zig_med_struct_mixed(s);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef __i386__
|
||||
#if !defined __i386__ && !defined __arm__ && !defined __mips__ && !defined __riscv
|
||||
{
|
||||
struct SplitStructMixed s = {1234, 100, 1337.0f};
|
||||
zig_split_struct_mixed(s);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined __mips__ && !defined __riscv
|
||||
{
|
||||
struct BigStruct s = {30, 31, 32, 33, 34};
|
||||
struct BigStruct res = zig_big_struct_both(s);
|
||||
@@ -295,25 +312,32 @@ void run_c_tests(void) {
|
||||
assert_or_panic(res.d == 23);
|
||||
assert_or_panic(res.e == 24);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef __riscv
|
||||
{
|
||||
struct Rect r1 = {1, 21, 16, 4};
|
||||
struct Rect r2 = {178, 189, 21, 15};
|
||||
zig_multiple_struct_ints(r1, r2);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined __mips__ && !defined __riscv
|
||||
{
|
||||
struct FloatRect r1 = {1, 21, 16, 4};
|
||||
struct FloatRect r2 = {178, 189, 21, 15};
|
||||
zig_multiple_struct_floats(r1, r2);
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
assert_or_panic(zig_ret_bool() == 1);
|
||||
|
||||
assert_or_panic(zig_ret_u8() == 0xff);
|
||||
assert_or_panic(zig_ret_u16() == 0xffff);
|
||||
#ifndef __riscv
|
||||
assert_or_panic(zig_ret_u32() == 0xffffffff);
|
||||
#endif
|
||||
assert_or_panic(zig_ret_u64() == 0xffffffffffffffff);
|
||||
|
||||
assert_or_panic(zig_ret_i8() == -1);
|
||||
|
||||
@@ -2,7 +2,8 @@ const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const print = std.debug.print;
|
||||
const expect = std.testing.expect;
|
||||
const has_i128 = builtin.cpu.arch != .i386;
|
||||
const has_i128 = builtin.cpu.arch != .i386 and !builtin.cpu.arch.isARM() and
|
||||
!builtin.cpu.arch.isMIPS();
|
||||
|
||||
extern fn run_c_tests() void;
|
||||
|
||||
@@ -111,7 +112,6 @@ test "C ABI floats" {
|
||||
}
|
||||
|
||||
test "C ABI long double" {
|
||||
if (!builtin.cpu.arch.isWasm() and !builtin.cpu.arch.isAARCH64()) return error.SkipZigTest;
|
||||
c_long_double(12.34);
|
||||
}
|
||||
|
||||
@@ -167,8 +167,11 @@ extern fn c_cmultd_comp(a_r: f64, a_i: f64, b_r: f64, b_i: f64) ComplexDouble;
|
||||
extern fn c_cmultf(a: ComplexFloat, b: ComplexFloat) ComplexFloat;
|
||||
extern fn c_cmultd(a: ComplexDouble, b: ComplexDouble) ComplexDouble;
|
||||
|
||||
const complex_abi_compatible = builtin.cpu.arch != .i386 and !builtin.cpu.arch.isMIPS();
|
||||
|
||||
test "C ABI complex float" {
|
||||
if (true) return error.SkipZigTest; // See https://github.com/ziglang/zig/issues/8465
|
||||
if (!complex_abi_compatible) return error.SkipZigTest;
|
||||
if (builtin.cpu.arch == .x86_64) return error.SkipZigTest; // See https://github.com/ziglang/zig/issues/8465
|
||||
|
||||
const a = ComplexFloat{ .real = 1.25, .imag = 2.6 };
|
||||
const b = ComplexFloat{ .real = 11.3, .imag = -1.5 };
|
||||
@@ -179,7 +182,7 @@ test "C ABI complex float" {
|
||||
}
|
||||
|
||||
test "C ABI complex float by component" {
|
||||
if (builtin.cpu.arch == .i386) return error.SkipZigTest;
|
||||
if (!complex_abi_compatible) return error.SkipZigTest;
|
||||
|
||||
const a = ComplexFloat{ .real = 1.25, .imag = 2.6 };
|
||||
const b = ComplexFloat{ .real = 11.3, .imag = -1.5 };
|
||||
@@ -190,7 +193,7 @@ test "C ABI complex float by component" {
|
||||
}
|
||||
|
||||
test "C ABI complex double" {
|
||||
if (builtin.cpu.arch == .i386) return error.SkipZigTest;
|
||||
if (!complex_abi_compatible) return error.SkipZigTest;
|
||||
|
||||
const a = ComplexDouble{ .real = 1.25, .imag = 2.6 };
|
||||
const b = ComplexDouble{ .real = 11.3, .imag = -1.5 };
|
||||
@@ -201,7 +204,7 @@ test "C ABI complex double" {
|
||||
}
|
||||
|
||||
test "C ABI complex double by component" {
|
||||
if (builtin.cpu.arch == .i386) return error.SkipZigTest;
|
||||
if (!complex_abi_compatible) return error.SkipZigTest;
|
||||
|
||||
const a = ComplexDouble{ .real = 1.25, .imag = 2.6 };
|
||||
const b = ComplexDouble{ .real = 11.3, .imag = -1.5 };
|
||||
@@ -257,6 +260,9 @@ const BigStruct = extern struct {
|
||||
extern fn c_big_struct(BigStruct) void;
|
||||
|
||||
test "C ABI big struct" {
|
||||
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
|
||||
var s = BigStruct{
|
||||
.a = 1,
|
||||
.b = 2,
|
||||
@@ -281,6 +287,8 @@ const BigUnion = extern union {
|
||||
extern fn c_big_union(BigUnion) void;
|
||||
|
||||
test "C ABI big union" {
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
|
||||
var x = BigUnion{
|
||||
.a = BigStruct{
|
||||
.a = 1,
|
||||
@@ -312,6 +320,9 @@ extern fn c_ret_med_struct_mixed() MedStructMixed;
|
||||
|
||||
test "C ABI medium struct of ints and floats" {
|
||||
if (builtin.cpu.arch == .i386) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isARM()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
|
||||
var s = MedStructMixed{
|
||||
.a = 1234,
|
||||
@@ -342,6 +353,9 @@ extern fn c_ret_small_struct_ints() SmallStructInts;
|
||||
|
||||
test "C ABI small struct of ints" {
|
||||
if (builtin.cpu.arch == .i386) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isARM()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
|
||||
var s = SmallStructInts{
|
||||
.a = 1,
|
||||
@@ -421,6 +435,9 @@ extern fn c_split_struct_ints(SplitStructInt) void;
|
||||
|
||||
test "C ABI split struct of ints" {
|
||||
if (builtin.cpu.arch == .i386) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isARM()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
|
||||
var s = SplitStructInt{
|
||||
.a = 1234,
|
||||
@@ -446,6 +463,9 @@ extern fn c_ret_split_struct_mixed() SplitStructMixed;
|
||||
|
||||
test "C ABI split struct of ints and floats" {
|
||||
if (builtin.cpu.arch == .i386) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isARM()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
|
||||
var s = SplitStructMixed{
|
||||
.a = 1234,
|
||||
@@ -471,6 +491,9 @@ extern fn c_multiple_struct_ints(Rect, Rect) void;
|
||||
extern fn c_multiple_struct_floats(FloatRect, FloatRect) void;
|
||||
|
||||
test "C ABI sret and byval together" {
|
||||
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
|
||||
var s = BigStruct{
|
||||
.a = 1,
|
||||
.b = 2,
|
||||
@@ -520,6 +543,10 @@ const Vector5 = extern struct {
|
||||
extern fn c_big_struct_floats(Vector5) void;
|
||||
|
||||
test "C ABI structs of floats as parameter" {
|
||||
if (comptime builtin.cpu.arch.isARM()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
|
||||
var v3 = Vector3{
|
||||
.x = 3.0,
|
||||
.y = 6.0,
|
||||
@@ -557,6 +584,8 @@ export fn zig_multiple_struct_ints(x: Rect, y: Rect) void {
|
||||
}
|
||||
|
||||
test "C ABI structs of ints as multiple parameters" {
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
|
||||
var r1 = Rect{
|
||||
.left = 1,
|
||||
.right = 21,
|
||||
@@ -591,6 +620,9 @@ export fn zig_multiple_struct_floats(x: FloatRect, y: FloatRect) void {
|
||||
}
|
||||
|
||||
test "C ABI structs of floats as multiple parameters" {
|
||||
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
|
||||
var r1 = FloatRect{
|
||||
.left = 1,
|
||||
.right = 21,
|
||||
@@ -693,6 +725,9 @@ extern fn c_ret_struct_with_array() StructWithArray;
|
||||
|
||||
test "Struct with array as padding." {
|
||||
if (builtin.cpu.arch == .i386) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isARM()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
|
||||
c_struct_with_array(.{ .a = 1, .padding = undefined, .b = 2 });
|
||||
|
||||
@@ -716,6 +751,9 @@ extern fn c_float_array_struct(FloatArrayStruct) void;
|
||||
extern fn c_ret_float_array_struct() FloatArrayStruct;
|
||||
|
||||
test "Float array like struct" {
|
||||
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
|
||||
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
|
||||
|
||||
c_float_array_struct(.{
|
||||
.origin = .{
|
||||
.x = 5,
|
||||
|
||||
Reference in New Issue
Block a user