From 7bbaa213b4028bc321602f54737d3a987826b192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Mon, 13 Oct 2025 13:54:20 +0800 Subject: [PATCH] feat: add `-DBUILD=test` & test CI --- .github/workflows/test.yml | 47 ++++++++++++++++++++++++++ CMakeLists.txt | 8 +++-- README.md | 16 ++++++--- include/{test.hpp => test/kernels.hpp} | 0 libs/CMakeLists.txt | 6 ++++ libs/test_kernels.cpp | 2 +- tests/basic.cpp | 2 +- 7 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/test.yml rename include/{test.hpp => test/kernels.hpp} (100%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..dcfff23 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,47 @@ +name: test +on: [push, pull_request] + +jobs: + test_ubuntu: + name: Run CMake Test on Ubuntu (oneAPI) 🧪 + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v2 + + - name: Setup Build Tools + run: | + # download the key to system keyring + wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \ + | gpg --dearmor | sudo tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null + + # add signed entry to apt sources and configure the APT client to use Intel repository: + echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list + + sudo apt-get update + sudo apt-get install -y intel-basekit cmake + + - name: Build and Run Tests + run: | + mkdir build + cd build + cmake -DCMAKE_BUILD_TYPE=Release -DBUILD=test .. + cmake --build . || ctest --output-on-failure + + test_windows: + name: Run CMake Test on Windows (MSVC) 🧪 + runs-on: windows-latest + steps: + - name: Checkout Code + uses: actions/checkout@v2 + + - name: Setup Build Tools + run: | + Invoke-WebRequest -Uri "https://registrationcenter-download.intel.com/akdlm/IRC_NAS/f5881e61-dcdc-40f1-9bd9-717081ac623c/intel-oneapi-base-toolkit-2025.2.1.46_offline.exe" -OutFile "install.exe" + ./install.exe -s -a --silent --eula accept + + - name: Build and Run Tests + run: | + mkdir build + cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release .. + cmake --build .; if ($?) { ctest --output-on-failure } diff --git a/CMakeLists.txt b/CMakeLists.txt index d768890..a76741f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,9 +70,11 @@ endif() add_subdirectory(libs) message(STATUS "Collected libs: ${B14LIBS}") -enable_testing() -add_subdirectory(tests) -message(STATUS "Collected tests: ${B14TESTS}") +if (BUILD STREQUAL "test") + enable_testing() + add_subdirectory(tests) + message(STATUS "Collected tests: ${B14TESTS}") +endif () foreach(TARGET_NAME ${B14TESTS}) target_link_libraries(${TARGET_NAME} ${B14LIBS}) diff --git a/README.md b/README.md index f9154c4..6f8e9d4 100644 --- a/README.md +++ b/README.md @@ -39,8 +39,7 @@ Base16384-SYCL is an optimized implementation of the [Base16384 encoding algorit ### 1. Environment Setup -> [!Tip] -> **For VS Code Users**: If you're using Visual Studio Code, the environment variable setup commands will be executed automatically when you open a terminal. If this fails, it may be due to a non-standard installation path. Please modify the paths in `.vscode/settings.json` accordingly. +> [!Tip] > **For VS Code Users**: If you're using Visual Studio Code, the environment variable setup commands will be executed automatically when you open a terminal. If this fails, it may be due to a non-standard installation path. Please modify the paths in `.vscode/settings.json` accordingly. **Windows:** @@ -71,9 +70,16 @@ cd build **Configure the build system:** -```cmd -cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release .. -``` +> Add `-DBUILD=test` to enable testing. + +- Windows + ```cmd + cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release .. + ``` +- Unix-Like + ```sh + cmake -DCMAKE_BUILD_TYPE=Release .. + ``` **Compile the project:** diff --git a/include/test.hpp b/include/test/kernels.hpp similarity index 100% rename from include/test.hpp rename to include/test/kernels.hpp diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index 057638a..13a659b 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -5,6 +5,12 @@ set(LOCAL_B14LIBS "") foreach(CPP_FILE ${CPP_FILES}) # name without .cpp get_filename_component(TARGET_NAME ${CPP_FILE} NAME_WE) + + # Skip test files if BUILD is not "test" + if(NOT BUILD STREQUAL "test" AND TARGET_NAME MATCHES "^test_") + continue() + endif() + message(STATUS "Add CPP lib: ${TARGET_NAME}") add_library(${TARGET_NAME} STATIC ${CPP_FILE}) diff --git a/libs/test_kernels.cpp b/libs/test_kernels.cpp index f563c61..9a76c4c 100644 --- a/libs/test_kernels.cpp +++ b/libs/test_kernels.cpp @@ -1,7 +1,7 @@ #include #include -#include "test.hpp" +#include "test/kernels.hpp" SYCL_EXTERNAL std::uint8_t base16384::test::kernels_basic(uint8_t in) { in *= in; diff --git a/tests/basic.cpp b/tests/basic.cpp index 2fe9a49..96db315 100644 --- a/tests/basic.cpp +++ b/tests/basic.cpp @@ -14,7 +14,7 @@ #include #include "errors.hpp" -#include "test.hpp" +#include "test/kernels.hpp" #include "xeinfo.hpp" constexpr int iter_count = 65536;