Skip to content

Commit 123ea86

Browse files
github-actionsBlackhex
authored andcommitted
Add complex math tests
1 parent 634ad0d commit 123ea86

File tree

5 files changed

+81
-3
lines changed

5 files changed

+81
-3
lines changed

.github/scripts/tests/build.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ source `dirname ${BASH_SOURCE[0]}`/../config.sh
44

55
echo "::group::Build Aarch64 tests"
66
cd $ROOT_PATH/tests
7-
cmake -S . -B build
7+
if [ $RUN_CONFIG = 1 ] || [ ! -f build/CMakeCache.txt ] ; then
8+
cmake -S . -B build
9+
fi
810
cmake --build build
911
echo "::endgroup::"

tests/dll-test.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77

88
#include <stdlib.h>
99
#include <stdio.h>
10+
#include <complex.h>
1011

1112
// Declare imported function.
1213
// These functions were exported from the dll using __declspec( dllexport )
1314
__declspec(dllimport) int __cdecl add_c_export(int a, int b);
1415
__declspec(dllimport) int __stdcall add_std_export(int a, int b);
16+
__declspec(dllimport) _Complex double __cdecl complex_add_c_export(_Complex double a, _Complex double b);
17+
__declspec(dllimport) _Complex double __stdcall complex_add_std_export(_Complex double a, _Complex double b);
1518

1619
// These functions were exported via a def file.
1720
int __cdecl add_c_def(int a, int b);
@@ -40,6 +43,19 @@ int check_dll()
4043
return 5;
4144
if (test_func_pointer(add_c_def) != 29)
4245
return 6;
46+
47+
_Complex double a = 1.0 + 2.0 * I;
48+
_Complex double b = 3.0 + 4.0 * I;
49+
_Complex double c = complex_add_c_export(a, b);
50+
if (c != 4.000000 + 6.000000 * I) {
51+
return 7;
52+
}
53+
54+
_Complex double d = complex_add_std_export(a, b);
55+
if (c != 4.000000 + 6.000000 * I) {
56+
return 8;
57+
}
58+
4359
return 0;
4460
}
4561

tests/dll.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,14 @@ __declspec(dllexport) int __cdecl add_c_export(int a, int b)
2121
__declspec(dllexport) int __stdcall add_std_export(int a, int b)
2222
{
2323
return a + b;
24-
}
24+
}
25+
26+
__declspec(dllexport) _Complex double __cdecl complex_add_c_export(_Complex double a, _Complex double b)
27+
{
28+
return a + b;
29+
}
30+
31+
__declspec(dllexport) _Complex double __stdcall complex_add_std_export(_Complex double a, _Complex double b)
32+
{
33+
return a + b;
34+
}

tests/math-test.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "gtest_like_c.h"
22

33
#include <stdio.h>
4+
#include <complex.h>
45

56
_Float128 foo(_Float128 x)
67
{
@@ -23,6 +24,11 @@ _Float128 baz(_Float128 x)
2324
return x * __builtin_huge_valf128();
2425
}
2526

27+
_Complex double complex_func(_Complex double a, _Complex double b)
28+
{
29+
return a + b;
30+
}
31+
2632
void math_test()
2733
{
2834
foo(1.2Q);
@@ -37,7 +43,33 @@ void math_test()
3743
printf("ok\n");
3844
}
3945

46+
void complex_func_test()
47+
{
48+
_Complex double a = 1.0 + 2.0 * I;
49+
_Complex double b = 3.0 + 4.0 * I;
50+
_Complex double c = complex_func(a, b);
51+
52+
printf("%f + %f * I\n", creal(c), cimag(c));
53+
}
54+
55+
void cexp_test()
56+
{
57+
_Complex double z = 1.0 + 2.0 * I;
58+
_Complex double w = __builtin_cexp(z);
59+
60+
printf("%f + %f * I\n", creal(w), cimag(w));
61+
}
62+
63+
64+
void ccos_test()
65+
{
66+
_Complex double z = 1.0 + 2.0 * I;
67+
_Complex double w = __builtin_ccos(z);
68+
69+
printf("%f + %f * I\n", creal(w), cimag(w));
70+
}
71+
4072
TEST(Aarch64MinGW, MathTest)
4173
{
4274
math_test();
43-
}
75+
}

tests/math-test.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
#include <gtest/gtest.h>
22

33
extern "C" void math_test();
4+
extern "C" void complex_func_test();
5+
extern "C" void cexp_test();
6+
extern "C" void ccos_test();
47

58
TEST(Aarch64MinGW, MathTest)
69
{
710
math_test();
811
}
12+
13+
TEST(Aarch64MinGW, ComplexFuncTest)
14+
{
15+
complex_func_test();
16+
}
17+
18+
TEST(Aarch64MinGW, CexpTest)
19+
{
20+
cexp_test();
21+
}
22+
23+
TEST(Aarch64MinGW, CcosTest)
24+
{
25+
ccos_test();
26+
}

0 commit comments

Comments
 (0)