Skip to content

Commit faa0e52

Browse files
committed
Prefix test build option and update CI
1 parent 66faa7f commit faa0e52

File tree

44 files changed

+64
-92
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+64
-92
lines changed

.github/workflows/Tests_Linux.yml

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Module Tests (Linux)
1+
name: C2Core Tests (Linux)
22

33
on: workflow_dispatch
44

@@ -11,34 +11,13 @@ jobs:
1111
uses: actions/checkout@v3
1212

1313
- name: Install dependencies
14-
run: sudo apt-get update && sudo apt-get install -y cmake g++ curl make
15-
16-
- name: Fetch base64.cpp
17-
run: |
18-
mkdir -p thirdParty/base64
19-
curl -L https://raw.githubusercontent.com/ReneNyffenegger/cpp-base64/82147d6d89636217b870f54ec07ddd3e544d5f69/base64.cpp \
20-
-o thirdParty/base64/base64.cpp
21-
22-
- name: Fetch module dependencies
23-
run: |
24-
cd modules
25-
mkdir -p ModuleCmd/nlohmann
26-
curl -o ModuleCmd/nlohmann/json.hpp https://raw.githubusercontent.com/maxDcb/C2TeamServer/refs/heads/master/thirdParty/nlohmann/json.hpp
27-
curl -o ModuleCmd/base64.h https://raw.githubusercontent.com/ReneNyffenegger/cpp-base64/82147d6d89636217b870f54ec07ddd3e544d5f69/base64.h
14+
run: sudo apt-get update && sudo apt-get install -y cmake g++ curl make libssl-dev
2815

2916
- name: Configure with CMake
30-
run: |
31-
cd modules
32-
mkdir build
33-
cd build
34-
cmake -DWITH_TESTS=ON ..
17+
run: cmake -S . -B build -DC2CORE_BUILD_TESTS=ON
3518

3619
- name: Build
37-
run: |
38-
cd modules/build
39-
make -j$(nproc)
20+
run: cmake --build build -j$(nproc)
4021

4122
- name: Run tests
42-
run: |
43-
cd modules/build
44-
ctest --output-on-failure
23+
run: ctest --test-dir build --output-on-failure
Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Module Tests (Windows)
1+
name: C2Core Tests (Windows)
22

33
on: workflow_dispatch
44

@@ -15,23 +15,11 @@ jobs:
1515
with:
1616
msbuild-architecture: x64
1717

18-
- name: Fetch base64.cpp
19-
run: |
20-
mkdir thirdParty\base64
21-
curl -L https://raw.githubusercontent.com/ReneNyffenegger/cpp-base64/82147d6d89636217b870f54ec07ddd3e544d5f69/base64.cpp -o thirdParty\base64\base64.cpp
22-
23-
- name: Fetch module dependencies
24-
run: |
25-
cd modules
26-
mkdir ModuleCmd\nlohmann
27-
curl -o ModuleCmd\nlohmann\json.hpp https://raw.githubusercontent.com/maxDcb/C2TeamServer/refs/heads/master/thirdParty/nlohmann/json.hpp
28-
curl -o ModuleCmd\base64.h https://raw.githubusercontent.com/ReneNyffenegger/cpp-base64/82147d6d89636217b870f54ec07ddd3e544d5f69/base64.h
29-
3018
- name: Configure CMake for tests
31-
run: cmake -G "Visual Studio 17 2022" -S modules -B modules/build -DWITH_TESTS=ON
19+
run: cmake -G "Visual Studio 17 2022" -S . -B build -DC2CORE_BUILD_TESTS=ON
3220

33-
- name: Build modules with tests
34-
run: cmake --build modules/build --config Release --parallel
21+
- name: Build
22+
run: cmake --build build --config Release --parallel
3523

36-
- name: Run unit tests
37-
run: ctest --test-dir modules/build -C Release
24+
- name: Run tests
25+
run: ctest --test-dir build -C Release

AGENT.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ You are an expert C++/CMake contributor tasked with maintaining, and expending *
1111

1212
```bash
1313
mkdir -p build && cd build
14-
cmake -DWITH_TESTS=ON ..
14+
cmake -DC2CORE_BUILD_TESTS=ON ..
1515
cmake --build . -j
1616

1717
ctest --output-on-failure
18-
```
18+
```

CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,15 @@ find_package(OpenSSL REQUIRED)
9090
add_library(openssl::openssl INTERFACE IMPORTED)
9191
target_link_libraries(openssl::openssl INTERFACE OpenSSL::SSL OpenSSL::Crypto)
9292

93-
option(BUILD_TESTING "Build unit tests" ON)
94-
if(BUILD_TESTING)
93+
# Build tests only when explicitly enabled. Default to ON when C2Core is the
94+
# top-level project and OFF when included from another build.
95+
option(C2CORE_BUILD_TESTS "Build C2Core unit tests" OFF)
96+
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
97+
set(C2CORE_BUILD_TESTS ON CACHE BOOL "Build C2Core unit tests" FORCE)
98+
endif()
99+
100+
if(C2CORE_BUILD_TESTS)
95101
enable_testing()
96-
set(WITH_TESTS ON CACHE BOOL "" FORCE)
97102

98103
FetchContent_Declare(
99104
Catch2

modules/AssemblyExec/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ endif()
88

99
set_property(TARGET AssemblyExec PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded")
1010

11-
if(WITH_TESTS)
11+
if(C2CORE_BUILD_TESTS)
1212
message(STATUS "[+] AssemblyExec Tests are enable.")
1313
target_link_libraries(AssemblyExec ${Donut})
1414
else()
@@ -19,7 +19,7 @@ endif()
1919
add_custom_command(TARGET AssemblyExec POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
2020
$<TARGET_FILE:AssemblyExec> "${CMAKE_SOURCE_DIR}/Release/Modules/$<TARGET_FILE_NAME:AssemblyExec>")
2121

22-
if(WITH_TESTS)
22+
if(C2CORE_BUILD_TESTS)
2323
if(WIN32)
2424
add_executable(testsAssemblyExec tests/testsAssemblyExec.cpp AssemblyExec.cpp ../ModuleCmd/syscall.cpp ../ModuleCmd/syscall.x64.obj ../ModuleCmd/peb.cpp ../ModuleCmd/hwbp.cpp)
2525
target_link_libraries(testsAssemblyExec ${Donut} )

modules/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
set(CMAKE_CXX_STANDARD 17)
22
set(CMAKE_CXX_STANDARD_REQUIRED ON)
33

4-
if(WITH_TESTS)
4+
if(C2CORE_BUILD_TESTS)
55
enable_testing()
66
endif()
77

modules/Cat/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ target_link_libraries(Cat )
55
add_custom_command(TARGET Cat POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
66
$<TARGET_FILE:Cat> "${CMAKE_SOURCE_DIR}/Release/Modules/$<TARGET_FILE_NAME:Cat>")
77

8-
if(WITH_TESTS)
8+
if(C2CORE_BUILD_TESTS)
99
add_executable(testsCat tests/testsCat.cpp Cat.cpp)
1010
target_link_libraries(testsCat )
1111
add_custom_command(TARGET testsCat POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy

modules/ChangeDirectory/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ target_link_libraries(ChangeDirectory )
55
add_custom_command(TARGET ChangeDirectory POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
66
$<TARGET_FILE:ChangeDirectory> "${CMAKE_SOURCE_DIR}/Release/Modules/$<TARGET_FILE_NAME:ChangeDirectory>")
77

8-
if(WITH_TESTS)
8+
if(C2CORE_BUILD_TESTS)
99
add_executable(testsChangeDirectory tests/testsChangeDirectory.cpp ChangeDirectory.cpp)
1010
target_link_libraries(testsChangeDirectory )
1111
add_custom_command(TARGET testsChangeDirectory POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy

modules/Chisel/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
include_directories(../)
22
add_library(Chisel SHARED Chisel.cpp)
33
set_property(TARGET Chisel PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded")
4-
if(WITH_TESTS)
4+
if(C2CORE_BUILD_TESTS)
55
message(STATUS "[+] Chisel Tests are enable.")
66
target_link_libraries(Chisel ${Donut} )
77
else()
@@ -11,7 +11,7 @@ endif()
1111
add_custom_command(TARGET Chisel POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
1212
$<TARGET_FILE:Chisel> "${CMAKE_SOURCE_DIR}/Release/Modules/$<TARGET_FILE_NAME:Chisel>")
1313

14-
if(WITH_TESTS)
14+
if(C2CORE_BUILD_TESTS)
1515
add_executable(testsChisel tests/testsChisel.cpp Chisel.cpp)
1616

1717
if(WIN32)

modules/CoffLoader/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ endif()
88
add_custom_command(TARGET Coff POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
99
$<TARGET_FILE:Coff> "${CMAKE_SOURCE_DIR}/Release/Modules/$<TARGET_FILE_NAME:Coff>")
1010

11-
if(WITH_TESTS)
11+
if(C2CORE_BUILD_TESTS)
1212
add_executable(testsCoffLoader tests/testsCoffLoader.cpp CoffLoader.cpp)
1313

1414
if(WIN32)

0 commit comments

Comments
 (0)