Skip to content

Commit

Permalink
improve test coverage of edge cases for powerpc abi
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Jun 1, 2016
1 parent 3a2c430 commit 9b8a7d4
Show file tree
Hide file tree
Showing 2 changed files with 215 additions and 0 deletions.
138 changes: 138 additions & 0 deletions src/ccalltest.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,125 @@ typedef struct {
char z;
} struct_big;

typedef struct {
int64_t r1;
int64_t r2;
int64_t r3;
int64_t r4;
int64_t r5;
int64_t r6;
int64_t r7;
int64_t r8;
} struct_huge1a;

typedef struct {
int64_t r1;
int64_t r2;
int64_t r3;
int64_t r4;
int64_t r5;
int64_t r6;
int64_t r7;
int64_t r8;
int64_t r9;
} struct_huge1b;

typedef struct {
double f1;
double f2;
double f3;
double f4;
double f5;
double f6;
double f7;
double f8;
} struct_huge2a;

typedef struct {
double f1;
double f2;
double f3;
double f4;
double f5;
double f6;
double f7;
double f8;
double f9;
} struct_huge2b;

typedef struct {
complex float f12;
complex float f34;
complex float f56;
float f7;
float f8;
} struct_huge3a;

typedef struct {
complex float r1;
complex float r2;
complex float r3;
complex float r4;
complex float r5;
complex float r6;
complex float r7;
float r8a;
float r8b;
} struct_huge3b;

typedef struct {
complex float r1;
complex float r2;
complex float r3;
complex float r4;
complex float r5;
complex float r6;
complex float r7;
float r8a;
float r8b;
float r9;
} struct_huge3c;

typedef struct {
complex double r12;
complex double r34;
complex float r5;
complex double r67;
double r8;
} struct_huge4a;

typedef struct {
complex double r12;
complex double r34;
complex float r5;
complex double r67;
complex double r89;
} struct_huge4b;

typedef struct {
complex int r1;

This comment has been minimized.

Copy link
@andreasnoack

andreasnoack Aug 3, 2016

Member

@vtjnash This is not C99 and icc errors because of this. Any specific reason to use complex int here?

This comment has been minimized.

Copy link
@vtjnash

vtjnash Aug 3, 2016

Author Member

Saved me a bit of typing to declare all these structs. Eventually, we need to replace all usage of 'complex' with a macro so we can use different definitions by compiler

This comment has been minimized.

Copy link
@andreasnoack

andreasnoack Aug 3, 2016

Member

Would it be okay just to test complex float and complex double. At least for now since it breaks the build.

This comment has been minimized.

Copy link
@andreasnoack

andreasnoack Aug 5, 2016

Member

Ping. Is it necessary that they fields are complex ints? It would be great to be able to build with Intel compilers without errors.

complex int r2;
complex int r3;
complex int r4;
complex int r5;
complex int r6;
complex int r7;
complex int r8;
} struct_huge5a;

typedef struct {
complex int r1;
complex int r2;
complex int r3;
complex int r4;
complex int r5;
complex int r6;
complex int r7;
complex int r8;
complex int r9;
} struct_huge5b;


JL_DLLEXPORT struct1 test_1(struct1 a, float b) {
//Unpack a "small" struct { float, double }
if (verbose) fprintf(stderr,"%g + %g i & %g\n", a.x, a.y, b);
Expand Down Expand Up @@ -367,6 +486,25 @@ JL_DLLEXPORT struct_big test_big(struct_big a) {
return a;
}

#define test_huge(suffix, reg) \
JL_DLLEXPORT struct_huge##suffix test_huge##suffix(char a, struct_huge##suffix b, char c) { \
if (verbose) fprintf(stderr,"%c-%c\n", a, c); \
b.reg *= 39; \
return b; \
}

test_huge(1a, r1);
test_huge(1b, r1);
test_huge(2a, f1);
test_huge(2b, f1);
test_huge(3a, f12);
test_huge(3b, r1);
test_huge(3c, r1);
test_huge(4a, r12);
test_huge(4b, r12);
test_huge(5a, r1);
test_huge(5b, r1);

JL_DLLEXPORT int get_c_int(void)
{
return c_int;
Expand Down
77 changes: 77 additions & 0 deletions test/ccall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,83 @@ let
@test x.z == a.z - Int('A')
end

const Struct_huge1a = NTuple{8, Int64}
const Struct_huge1b = NTuple{9, Int64}
const Struct_huge2a = NTuple{8, Cdouble}
const Struct_huge2b = NTuple{9, Cdouble}
type Struct_huge3a
cf::NTuple{3, Complex{Cfloat}}
f7::Cfloat
f8::Cfloat
end
type Struct_huge3b
cf::NTuple{7, Complex{Cfloat}}
r8a::Cfloat
r8b::Cfloat
end
type Struct_huge3c
cf::NTuple{7, Complex{Cfloat}}
r8a::Cfloat
r8b::Cfloat
r9::Cfloat
end
type Struct_huge4a
r12::Complex{Cdouble}
r34::Complex{Cdouble}
r5::Complex{Cfloat}
r67::Complex{Cdouble}
r8::Cdouble
end
type Struct_huge4b
r12::Complex{Cdouble}
r34::Complex{Cdouble}
r5::Complex{Cfloat}
r67::Complex{Cdouble}
r89::Complex{Cdouble}
end
const Struct_huge5a = NTuple{8, Complex{Cint}}
const Struct_huge5b = NTuple{9, Complex{Cint}}

function verify_huge(init, a, b)
@test typeof(init) === typeof(a) === typeof(b)
verbose && @show (a, b)
# make sure a was unmodified
for i = 1:nfields(a)
@test getfield(init, i) === getfield(a, i)
end
# make sure b was modifed as expected
a1, b1 = getfield(a, 1), getfield(b, 1)
if isa(a1, Tuple)
@test oftype(a1[1], a1[1] * 39) === b1[1]
@test a1[2:end] === b1[2:end]
else
@test oftype(a1, a1 * 39) === b1
end
for i = 2:nfields(a)
@test getfield(a, i) === getfield(b, i)
end
end
macro test_huge(i, b, init)
f = QuoteNode(Symbol("test_huge", i, b))
ty = Symbol("Struct_huge", i, b)
return quote
let a = $ty($(esc(init))...), f
f(b) = ccall(($f, libccalltest), $ty, (Cchar, $ty, Cchar), '0' + $i, a, $b)
verify_huge($ty($(esc(init))...), a, f(a))
end
end
end
@test_huge 1 'a' ((1, 2, 3, 4, 5, 6, 7, 8),)
@test_huge 1 'b' ((1, 2, 3, 4, 5, 6, 7, 8, 9),)
@test_huge 2 'a' ((1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0),)
@test_huge 2 'b' ((1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0),)
@test_huge 3 'a' ((1.0 + 2.0im, 3.0 + 4.0im, 5.0 + 6.0im), 7.0, 8.0)
@test_huge 3 'b' ((1.0 + 2.0im, 3.0 + 4.0im, 5.0 + 6.0im, 7.0 + 8.0im, 9.0 + 10.0im, 11.0 + 12.0im, 13.0 + 14.0im), 7.0, 8.0)
@test_huge 3 'c' ((1.0 + 2.0im, 3.0 + 4.0im, 5.0 + 6.0im, 7.0 + 8.0im, 9.0 + 10.0im, 11.0 + 12.0im, 13.0 + 14.0im), 7.0, 8.0, 9.0)
@test_huge 4 'a' (1.0 + 2.0im, 3.0 + 4.0im, 5.0f0 + 6.0f0im, 7.0 + 8.0im, 9.0)
@test_huge 4 'b' (1.0 + 2.0im, 3.0 + 4.0im, 5.0f0 + 6.0f0im, 7.0 + 8.0im, 9.0 + 10.0im)
@test_huge 5 'a' ((1 + 2im, 3 + 4im, 5 + 6im, 7 + 8im, 9 + 10im, 11 + 12im, 13 + 14im, 15 + 16im),)
@test_huge 5 'b' ((1 + 2im, 3 + 4im, 5 + 6im, 7 + 8im, 9 + 10im, 11 + 12im, 13 + 14im, 15 + 16im, 17 + 17im),)

## cfunction roundtrip

Expand Down

0 comments on commit 9b8a7d4

Please sign in to comment.