Skip to content

Commit

Permalink
[Feature] add cicd on github action (#10)
Browse files Browse the repository at this point in the history
* enable ctest control by CICD_ENABLE
* add run_ctest.py to start all test exe
* modify cmakepreset to adapte to github action
* update cmakepreset
  • Loading branch information
endingly authored Sep 30, 2024
1 parent 7847223 commit bb74c56
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.vscode
build
out
.idea
.idea
log
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
option(BUILD_TESTS "Build tests" ON)
option(INTEL_MKL_BACKEND "Use Intel MKL backend" OFF)
option(CUDA_BACKEND "Enable CUDA backend" OFF)
option(CICD_ENABLE "Enable CICD" ON)

if(CICD_ENABLE)
enable_testing()
add_test(
NAME ctest_all
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/scripts/run_ctest.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
else()
message(STATUS "CICD_ENABLE is off, tests will not be run on CI/CD")
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
option(PLASMA_DEBUG "Enable plasma debug messages, NOT FOR PRODUCTION USE" ON)
Expand Down
54 changes: 53 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
},
{
"name": "MSVC_x64_debug",
"description": "Visual Studio Community 2022 Release - amd64",
"description": "use MSVC 2022 (x64) debug mode",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"architecture": "x64",
"toolset": "host=x64",
"generator": "Visual Studio 17 2022",
"cacheVariables": {
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"CMAKE_C_COMPILER": "cl.exe",
Expand All @@ -44,6 +45,14 @@
},
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
},
{
"name": "MSVC_x64_release",
"description": "use MSVC 2022 (x64) release mode",
"inherits": "MSVC_x64_debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "mingw_x64_windows_debug",
"displayName": "GCC 14.1.0 x86_64-w64-mingw32 (ucrt64) debug mode",
Expand All @@ -68,5 +77,48 @@
"CMAKE_BUILD_TYPE": "Release"
}
}
],
"buildPresets": [
{
"name": "msvc_x64_build_release",
"configurePreset": "MSVC_x64_release",
"configuration": "Release"
},
{
"name": "linux_x64_build_release",
"configurePreset": "linux_gcc_x64_release",
"configuration": "Release"
}
],
"testPresets": [
{
"name": "checkin_windows",
"configurePreset": "MSVC_x64_release",
"configuration": "Release"
},
{
"name": "checkin_linux",
"configurePreset": "linux_gcc_x64_release",
"configuration": "Release"
}
],
"workflowPresets": [
{
"name": "cicd_on_windows",
"steps": [
{
"type": "configure",
"name": "MSVC_x64_release"
},
{
"type": "build",
"name": "msvc_x64_build_release"
},
{
"type": "test",
"name": "checkin_windows"
}
]
}
]
}
29 changes: 29 additions & 0 deletions scripts/run_ctest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
import subprocess
import os
import sys
import platform

def run_binary_test(top_path, cmakeprest_name, submod_name) -> bool:
path_name = ""
if platform.system() == "Linux":
path_name = f"{top_path}/out/build/{cmakeprest_name}/submod/{submod_name}/test/{submod_name}_test"
elif platform.system() == "Windows":
path_name = f"{top_path}/out/build/{cmakeprest_name}/submod/{submod_name}/test/Release/{submod_name}_test.exe"
result = subprocess.run(args=[path_name],shell=True,check=True,capture_output=True)
return result.returncode == 0

# main function def
if __name__ == '__main__':
top_path = os.getcwd().replace("\\", "/")
cmakeprest_name = ""
if platform.system() == "Windows":
cmakeprest_name = "MSVC_x64_release"
elif platform.system() == "Linux":
cmakeprest_name = "linux_gcc_x64_release"

R0 = run_binary_test(top_path, cmakeprest_name, "common")
R0 &= run_binary_test(top_path, cmakeprest_name, "chempars")
R0 &= run_binary_test(top_path, cmakeprest_name, "core")

sys.exit(0 if R0 else 1)
2 changes: 1 addition & 1 deletion submod/chempars/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
find_package(GTest CONFIG REQUIRED)
file(GLOB_RECURSE SOURCES *.cpp)
add_executable(chempars_test ${SOURCES})
target_link_libraries(chempars_test chempars GTest::gtest GTest::gtest_main)
target_link_libraries(chempars_test chempars GTest::gtest GTest::gtest_main)
2 changes: 1 addition & 1 deletion submod/core/test/test_units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ TEST(UnitsTest, TestConfig) {
TEST(UnitsTest, Test_Extend_To_string) {
gds::physic_constant::cubic_centimeter_per_second_t ccs(1.0);
auto s = units::extend::to_string(ccs);
std::cout << s << std::endl;
EXPECT_EQ(s, "1e+06 m^-3 s^-1");
}

0 comments on commit bb74c56

Please sign in to comment.