Skip to content

Commit

Permalink
Add unit tests of C++ static constructor initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackhex committed Oct 15, 2024
1 parent 7b6ba44 commit 3273959
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/scripts/tests/execute-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

source `dirname ${BASH_SOURCE[0]}`/../config.sh

PATH="$TOOLCHAIN_PATH/lib/gcc/aarch64-w64-mingw32/:$TOOLCHAIN_PATH/lib/gcc/$TARGET/$GCC_VERSION/"

echo "::group::Execute AArch64 tests"
pushd $ROOT_PATH/tests
WSLENV=$WSLENV:PATH/p ./build/bin/aarch64-mingw-tests.exe
popd
echo "::endgroup::"
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ add_executable(
pdata-test.c
sjlj-test.c
sscanf-double.c
static-constructor.cpp
static-constructor.c
static-function-test.c
static-function.c
struct-test.c
Expand Down
2 changes: 2 additions & 0 deletions tests/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ TEST(Aarch64MinGW, PrintfDoubleTest);
TEST(Aarch64MinGW, TestUnwindStack);
TEST(Aarch64MinGW, SJLJTest);
TEST(Aarch64MinGW, SscanfDoubleTest);
TEST(Aarch64MinGW, StaticConstructorTest);
TEST(Aarch64MinGW, StaticFunctionTest);
TEST(Aarch64MinGW, StructTest);
TEST(Aarch64MinGW, TestVaList);
Expand Down Expand Up @@ -56,6 +57,7 @@ int main(int argc, char **argv) {
DECLARE_TEST(Aarch64MinGW, TestUnwindStack),
DECLARE_TEST(Aarch64MinGW, SJLJTest),
DECLARE_TEST(Aarch64MinGW, SscanfDoubleTest),
DECLARE_TEST(Aarch64MinGW, StaticConstructorTest),
DECLARE_TEST(Aarch64MinGW, StaticFunctionTest),
DECLARE_TEST(Aarch64MinGW, StructTest),
DECLARE_TEST(Aarch64MinGW, TestVaList),
Expand Down
10 changes: 10 additions & 0 deletions tests/static-constructor.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "gtest_like_c.h"

#include <stdbool.h>

bool static_construtor();

TEST(Aarch64MinGW, StaticConstructorTest)
{
ASSERT_TRUE(static_construtor());
}
40 changes: 40 additions & 0 deletions tests/static-constructor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "gtest_like_c.h"

#include <cstdio>

constexpr int RESULTS_SIZE = 4;
static bool results[RESULTS_SIZE] = {false, false, false, false};

class C {
public:
C(int index) {
results[index] = true;
}
};

static C b(0);

namespace N {
static C d(1);
}

extern "C" {

bool static_construtor() {
static C c(2);
C a(3);

for (int i = 0; i < RESULTS_SIZE; i++) {
if (!results[i]) {
return false;
}
}
return true;
}

}

TEST(Aarch64MinGW, StaticConstructorTest)
{
ASSERT_TRUE(static_construtor());
}

0 comments on commit 3273959

Please sign in to comment.