Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use gtest to execute tests with aarch64-x64-mingw changes #44

Merged
merged 3 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
40 changes: 20 additions & 20 deletions tests/test-iostream.cpp → examples/test-iostream.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#include <iostream>
#include <windows.h>
#include <iomanip>
int main()
{
std::cout << "Hello World!" << std::endl;
std::cout << "==" << -17 << "==" << std::endl;
std::cout << "==" << std::setw(6) << -17 << "==" << std::endl;
std::cout << std::left;
std::cout << "==" << std::setw(6) << -17 << "==" << std::endl << std::endl;
std::cout << "==" << "hello" << "==" << std::endl;
std::cout << "==" << std::setw(20) << "hello" << "==" << std::endl;
std::cout << std::right;
std::cout << "==" << std::setw(20) << "hello" << "==" << std::endl;
std::cout << "ok" << std::endl;
return 0;
#include <iostream>
#include <windows.h>
#include <iomanip>

int main()
{
std::cout << "Hello World!" << std::endl;

std::cout << "==" << -17 << "==" << std::endl;
std::cout << "==" << std::setw(6) << -17 << "==" << std::endl;
std::cout << std::left;
std::cout << "==" << std::setw(6) << -17 << "==" << std::endl << std::endl;

std::cout << "==" << "hello" << "==" << std::endl;
std::cout << "==" << std::setw(20) << "hello" << "==" << std::endl;
std::cout << std::right;
std::cout << "==" << std::setw(20) << "hello" << "==" << std::endl;

std::cout << "ok" << std::endl;
return 0;
}
File renamed without changes.
File renamed without changes.
42 changes: 21 additions & 21 deletions tests/test-openblas.c → examples/test-openblas.c
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
// This is a small test app for openblas.
// git clone https://github.com/xianyi/OpenBLAS.git
// cd OpenBLAS
// make BINARY=64 CC=~/cross/bin/aarch64-w64-mingw32-gcc HOSTCC=gcc TARGET=ARMV8
// ~/cross/bin/aarch64-w64-mingw32-gcc -I. -L. test-openblas.c -lopenblas -o test-openblas.exe
#include <cblas.h>
#include <stdio.h>
void main()
{
int i=0;
double A[6] = {1.0,2.0,1.0,-3.0,4.0,-1.0};
double B[6] = {1.0,2.0,1.0,-3.0,4.0,-1.0};
double C[9] = {.5,.5,.5,.5,.5,.5,.5,.5,.5};
cblas_dgemm(CblasColMajor, CblasNoTrans, CblasTrans,3,3,2,1,A, 3, B, 3,2,C,3);
for(i=0; i<9; i++)
printf("%lf ", C[i]);
printf("\n");
printf("ok\n");
// This is a small test app for openblas.
// git clone https://github.com/xianyi/OpenBLAS.git
// cd OpenBLAS
// make BINARY=64 CC=~/cross/bin/aarch64-w64-mingw32-gcc HOSTCC=gcc TARGET=ARMV8
// ~/cross/bin/aarch64-w64-mingw32-gcc -I. -L. test-openblas.c -lopenblas -o test-openblas.exe

#include <cblas.h>
#include <stdio.h>

void main()
{
int i=0;
double A[6] = {1.0,2.0,1.0,-3.0,4.0,-1.0};
double B[6] = {1.0,2.0,1.0,-3.0,4.0,-1.0};
double C[9] = {.5,.5,.5,.5,.5,.5,.5,.5,.5};
cblas_dgemm(CblasColMajor, CblasNoTrans, CblasTrans,3,3,2,1,A, 3, B, 3,2,C,3);

for(i=0; i<9; i++)
printf("%lf ", C[i]);
printf("\n");
printf("ok\n");
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
7 changes: 7 additions & 0 deletions tests/BUILD.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Building aarch64-w64-mingw32 tests on Linux or WSL

cmake -S . -B build
cmake --build build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be handy to add the build folder to .gitignore.


It generates Arm64 Windows executable.
build/bin/aarch64_mingw_tests.exe
55 changes: 55 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
set(CMAKE_VERBOSE_MAKEFILE ON)

if (NOT DEFINED ENV{TARGET})
set(ENV{TARGET} "aarch64-w64-mingw32")
endif()
if (NOT DEFINED ENV{INSTALL_PATH})
set(ENV{INSTALL_PATH} "$ENV{HOME}/cross")
endif()

set(CMAKE_C_COMPILER "$ENV{INSTALL_PATH}/bin/$ENV{TARGET}-gcc")
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_COMPILER "$ENV{INSTALL_PATH}/bin/$ENV{TARGET}-c++")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fopenmp")
set(CMAKE_RANLIB "$ENV{INSTALL_PATH}/bin/$ENV{TARGET}-ranlib")

include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/b10fad38c4026a29ea6561ab15fc4818170d1c10.zip
)

FetchContent_MakeAvailable(googletest)

cmake_minimum_required(VERSION 3.14)
project(aarch64_mingw_tests)

enable_testing()

add_executable(
aarch64-mingw-tests.exe
bigdata-test.cpp
iostream-test.cpp
math-test.c
math-test.cpp
omp-test.c
omp-test.cpp
pdata-test.c
pdata-test.cpp
sjlj-test.c
sjlj-test.cpp
struct-test.c
struct-test.cpp
throw-test.cpp
varargs-test.c
varargs-test.cpp
)

target_link_libraries(
aarch64-mingw-tests.exe
GTest::gtest_main
dbghelp
)

set_target_properties(aarch64-mingw-tests.exe PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
127 changes: 127 additions & 0 deletions tests/bigdata-test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <gtest/gtest.h>


#define MAX_SAMPLES 0x1000000


static void big_text()
{
// Print out more than one page of text.
puts("The Commodore 64, also known as the C64, is an 8-bit home");
puts("computer introduced in January 1982 by Commodore");
puts("International (first shown at the Consumer Electronics");
puts("Show, January 7-10, 1982, in Las Vegas). It has been");
puts("listed in the Guinness World Records as the");
puts("highest-selling single computer model of all time, with");
puts("independent estimates placing the number sold between");
puts("12.5 and 17 million units. Volume production started in");
puts("early 1982, marketing in August for US$595 (equivalent to");
puts("$1,800 in 2022). Preceded by the VIC-20 and Commodore");
puts("PET, the C64 took its name from its 64 kilobytes (65,536");
puts("bytes) of RAM. With support for multicolor sprites and a");
puts("custom chip for waveform generation, the C64 could create");
puts("superior visuals and audio compared to systems without");
puts("such custom hardware.");
puts("");
puts("The C64 dominated the low-end computer market (except in");
puts("the UK and Japan, lasting only about six months in Japan)");
puts("for most of the later years of the 1980s. For a");
puts("substantial period (1983-1986), the C64 had between 30%");
puts("and 40% share of the US market and two million units sold");
puts("per year, outselling IBM PC compatibles, Apple computers,");
puts("and the Atari 8-bit family of computers. Sam Tramiel, a");
puts("later Atari president and the son of Commodore's founder,");
puts("said in a 1989 interview, When I was at Commodore we");
puts("were building 400,000 C64s a month for a couple of");
puts("years. In the UK market, the C64 faced competition from");
puts("the BBC Micro, the ZX Spectrum, and later the Amstrad CPC");
puts("464. but the C64 was still the second-most-popular");
puts("computer in the UK after the ZX Spectrum. The Commodore");
puts("64 failed to make any impact in Japan, as their market");
puts("was dominated by Japanese computers, such as the NEC");
puts("PC-8801, Sharp X1, Fujitsu FM-7, and MSX.");
puts("");
puts("Part of the Commodore 64's success was its sale in");
puts("regular retail stores instead of only electronics or");
puts("computer hobbyist specialty stores. Commodore produced");
puts("many of its parts in-house to control costs, including");
puts("custom integrated circuit chips from MOS Technology. In");
puts("the United States, it has been compared to the Ford Model");
puts("T automobile for its role in bringing a new technology to");
puts("middle-class households via creative and affordable");
puts("mass-production. Approximately 10,000 commercial software");
puts("titles have been made for the Commodore 64, including");
puts("development tools, office productivity applications, and");
puts("video games. C64 emulators allow anyone with a modern");
puts("computer, or a compatible video game console, to run");
puts("these programs today. The C64 is also credited with");
puts("popularizing the computer demoscene and is still used");
puts("today by some computer hobbyists. In 2011, 17 years after");
puts("it was taken off the market, research showed that brand");
puts("recognition for the model was still at 87%.");
}

void big_bss()
{
static size_t values[MAX_SAMPLES];
static size_t sorted[MAX_SAMPLES];
static size_t ref[MAX_SAMPLES];

printf("bigger %lx %d\n", MAX_SAMPLES, 0x1919);
printf("1 %lx\n", values);
printf("2 %lx\n", sorted);
printf("3 %lx\n", ref);

memset(values, 0, sizeof(values));
memset(sorted, 0, sizeof(sorted));
memset(ref, 0, sizeof(ref));
}

int get_len()
{
return 100;
}

int calc_func2(int x, int y)
{
printf("calc-func\n");
int i = x;
int j = y;
return i + j;
}

int throw_func1(void)
{
printf("throw-func\n");
int x = calc_func2(13, 19);
return x;
}

void big_stack_func(void)
{
printf("big-stack-func\n");
char sz[0x4000] ="";
strcpy(sz,"hello");

int num = get_len();

{
int scopes[num];
int temps[num];

throw_func1();
}
}

TEST(Aarch64MinGW, BigDataTest)
{
printf("main\n");
big_stack_func();
big_bss();
big_text();
printf("ok\n");
}
27 changes: 27 additions & 0 deletions tests/dll-test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Tests using the function imported from a DLL
IMPORT_API must be defined externally
*/

#include <stdlib.h>
#include <stdio.h>

/* Declare imported function so that we can actually use it. */
IMPORT_API int __cdecl funcc(int a, int b);
IMPORT_API int __stdcall funcstd(int a, int b);

int test_func_pointer( int __cdecl (*f)(int , int), int marker)
{
printf("test_func_pointer start %lx\n", test_func_pointer);
printf("f address %lx\n", f);
f(6, 23);
}

void dll_test()
{
printf("%d\n", funcc(6, 23));
printf("%d\n", funcstd(6, 23));

test_func_pointer(funcc, 0x1919);
printf("ok\n");
}
10 changes: 10 additions & 0 deletions tests/dll-test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <gtest/gtest.h>

extern "C" void dll_test();

TEST(Aarch64MinGW, DllTest)
{
dll_test();
}


22 changes: 22 additions & 0 deletions tests/iostream-test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <iostream>
#include <windows.h>
#include <iomanip>

#include <gtest/gtest.h>

TEST(Aarch64MinGW, IOStreamTest)
{
std::cout << "Hello World!" << std::endl;

std::cout << "==" << -17 << "==" << std::endl;
std::cout << "==" << std::setw(6) << -17 << "==" << std::endl;
std::cout << std::left;
std::cout << "==" << std::setw(6) << -17 << "==" << std::endl << std::endl;

std::cout << "==" << "hello" << "==" << std::endl;
std::cout << "==" << std::setw(20) << "hello" << "==" << std::endl;
std::cout << std::right;
std::cout << "==" << std::setw(20) << "hello" << "==" << std::endl;

std::cout << "ok" << std::endl;
}
38 changes: 38 additions & 0 deletions tests/math-test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <stdio.h>


_Float128 foo (_Float128 x)
{
_Complex _Float128 z1, z2;

z1 = x;
z2 = x / 7.F128;
z2 /= z1;

return (_Float128) z2;
}

_Float128 bar (_Float128 x)
{
return x * __builtin_huge_valf128 ();
}

_Float128 baz (_Float128 x)
{
return x * __builtin_huge_valf128 ();
}


void math_test()
{
foo (1.2Q);
bar (1.2Q);
foo (1.2F128);
bar (1.2F128);
baz (1.2F128);
foo (1.2Q);
bar (1.2Q);
baz (1.2Q);

printf("ok\n");
}
10 changes: 10 additions & 0 deletions tests/math-test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <gtest/gtest.h>

extern "C" void math_test();

TEST(Aarch64MinGW, MathTest)
{
math_test();
}


Loading