diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-19 10:09:39 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-19 10:09:39 +0100 |
| commit | 87a30d95dddc0cfcdf77e9d7406c1eea717865ff (patch) | |
| tree | ca52b9e425046e137aea267515b32149d22c4545 /test | |
| parent | 228479a454d325340326f4fd23e13d780884fd2a (diff) | |
chore: new LibC++ version, updated file structure.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'test')
| -rw-r--r-- | test/.gitkeep | 0 | ||||
| -rw-r--r-- | test/test_01_codegen/.gitkeep | 0 | ||||
| -rw-r--r-- | test/test_01_codegen/CMakeLists.txt | 23 | ||||
| -rw-r--r-- | test/test_01_codegen/codegen_test.cc | 15 | ||||
| -rw-r--r-- | test/test_02_linker/.gitkeep | 0 | ||||
| -rw-r--r-- | test/test_02_linker/CMakeLists.txt | 23 | ||||
| -rw-r--r-- | test/test_02_linker/linker_test.cc | 29 | ||||
| -rw-r--r-- | test/test_samples/sample.asm | 4 | ||||
| -rw-r--r-- | test/test_samples/sample.cc | 3 |
9 files changed, 97 insertions, 0 deletions
diff --git a/test/.gitkeep b/test/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/.gitkeep diff --git a/test/test_01_codegen/.gitkeep b/test/test_01_codegen/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/test_01_codegen/.gitkeep diff --git a/test/test_01_codegen/CMakeLists.txt b/test/test_01_codegen/CMakeLists.txt new file mode 100644 index 0000000..8b782d5 --- /dev/null +++ b/test/test_01_codegen/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.10) +project(NeCTICodeGen) + +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip +) + +# For Windows: Prevent overriding the parent project's compiler/linker settings +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googletest) + +enable_testing() + +add_executable(CodegenTestBasic linker_test.cc) +target_link_libraries(CodegenTestBasic gtest_main) + +set_property(TARGET CodegenTestBasic PROPERTY CXX_STANDARD 20) +target_include_directories(CodegenTestBasic PUBLIC ../../) + +include(GoogleTest) +gtest_discover_tests(CodegenTestBasic) diff --git a/test/test_01_codegen/codegen_test.cc b/test/test_01_codegen/codegen_test.cc new file mode 100644 index 0000000..06c8e25 --- /dev/null +++ b/test/test_01_codegen/codegen_test.cc @@ -0,0 +1,15 @@ +/* ======================================== + + Copyright (C) 2024-2025 Amlal El Mahrouss, licensed under the Apache 2.0 license. + + ======================================== */ + +/// @brief Codegen Unit test, from the C++ unit to the final executable. +/// @author Amlal El Mahrouss + +#include <gtest/gtest.h> + +TEST(CodegenTest, BasicCodegenTest) { + auto expr = std::system("asm -asm-x64 test_samples/sample.asm"); + EXPECT_TRUE(expr == 0) << "ASM Driver did not compile the easy ASM unit."; +} diff --git a/test/test_02_linker/.gitkeep b/test/test_02_linker/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/test_02_linker/.gitkeep diff --git a/test/test_02_linker/CMakeLists.txt b/test/test_02_linker/CMakeLists.txt new file mode 100644 index 0000000..f3493fc --- /dev/null +++ b/test/test_02_linker/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.10) +project(NeCTILinkerTest) + +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip +) + +# For Windows: Prevent overriding the parent project's compiler/linker settings +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googletest) + +enable_testing() + +add_executable(LinkerTestBasic linker_test.cc) +target_link_libraries(LinkerTestBasic gtest_main) + +set_property(TARGET LinkerTestBasic PROPERTY CXX_STANDARD 20) +target_include_directories(LinkerTestBasic PUBLIC ../../) + +include(GoogleTest) +gtest_discover_tests(LinkerTestBasic) diff --git a/test/test_02_linker/linker_test.cc b/test/test_02_linker/linker_test.cc new file mode 100644 index 0000000..617327f --- /dev/null +++ b/test/test_02_linker/linker_test.cc @@ -0,0 +1,29 @@ +/* ======================================== + + Copyright (C) 2024-2025 Amlal El Mahrouss, licensed under the Apache 2.0 license. + + ======================================== */ + +/// @brief Linker Unit test, from the C++ unit to the final executable. +/// @author Amlal El Mahrouss + +#include <gtest/gtest.h> + +/// compile +TEST(LinkerTest, BasicLinkTestCompile) { + auto expr = std::system("pef-amd64-cxxdrv test_samples/sample.cc"); + EXPECT_TRUE(expr == 0) << "C++ Driver did not compile the easy C++ unit."; +} + +/// assemble +TEST(LinkerTest, BasicLinkTestAssemble) { + auto expr = std::system("asm -asm:x64 test_samples/sample.cc.pp.masm"); + EXPECT_TRUE(expr == 0) << "Assembler did not assemble the easy asm unit."; +} + +/// link +TEST(LinkerTest, BasicLinkTestLink) { + auto expr = std::system( + "ld64 -amd64 test_samples/sample.cc.pp.obj -start __NECTAR_main -output main.exec"); + EXPECT_TRUE(expr == 0) << "Linker did not link the easy object."; +} diff --git a/test/test_samples/sample.asm b/test/test_samples/sample.asm new file mode 100644 index 0000000..82c0320 --- /dev/null +++ b/test/test_samples/sample.asm @@ -0,0 +1,4 @@ +public_segment .code64 __ImageStart + ;; rax is the return value register. + mov rax, 5 + ret
\ No newline at end of file diff --git a/test/test_samples/sample.cc b/test/test_samples/sample.cc new file mode 100644 index 0000000..4cce7f6 --- /dev/null +++ b/test/test_samples/sample.cc @@ -0,0 +1,3 @@ +int main() { + return 0; +} |
