Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to build tests #100

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
strategy:
matrix:
configurations: [Debug, Release]
build_tests: [true, false]
runs-on: ubuntu-latest
env:
# Configuration type to build. For documentation on how build matrices work, see
Expand All @@ -37,13 +38,15 @@ jobs:
- name: Build
run: |
mkdir build
cmake -B build -DCMAKE_BUILD_TYPE=${{env.BUILD_CONFIGURATION}}
cmake -B build -DCMAKE_BUILD_TYPE=${{env.BUILD_CONFIGURATION}} -DVERIFIER_ENABLE_TESTS=${{matrix.build_tests}}
cmake --build build -j $(nproc)

- name: Run unit tests
if: matrix.build_tests
run: ./tests -d yes

- name: Test for memory leaks
if: matrix.build_tests
# Any memory leaks will cause the test to fail
# This BPF program was chosen because it is the largest one in the repo
run: valgrind --leak-check=full --errors-for-leak-kinds=all --show-leak-kinds=all --error-exitcode=1 ./check ebpf-samples/cilium/bpf_xdp_snat_linux_v1.o 2/1
Expand All @@ -52,6 +55,7 @@ jobs:
strategy:
matrix:
configurations: [Debug, Release]
build_tests: [true, false]
runs-on: windows-2022
env:
# Configuration type to build. For documentation on how build matrices work, see
Expand All @@ -66,8 +70,9 @@ jobs:
- name: Build
run: |
mkdir build
cmake -B build
cmake -B build -DVERIFIER_ENABLE_TESTS=${{matrix.build_tests}}
cmake --build build -j $(nproc) --config ${{env.BUILD_CONFIGURATION}}

- name: Run unit tests
if: matrix.build_tests
run: ./${{env.BUILD_CONFIGURATION}}/tests -d yes
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ project(ebpf_verifier)

include(FetchContent)

option(VERIFIER_ENABLE_TESTS "Build tests" ON)

FetchContent_Declare(GSL
GIT_REPOSITORY "https://github.com/microsoft/GSL"
GIT_TAG "v4.0.0"
Expand All @@ -13,12 +15,14 @@ FetchContent_Declare(GSL
FetchContent_MakeAvailable(GSL)
get_target_property(GSL_INCLUDE_DIRS Microsoft.GSL::GSL INTERFACE_INCLUDE_DIRECTORIES)

if (VERIFIER_ENABLE_TESTS)
FetchContent_Declare(Catch2
GIT_REPOSITORY "https://github.com/catchorg/Catch2.git"
GIT_TAG "v3.7.1"
GIT_SHALLOW ON
)
FetchContent_MakeAvailable(Catch2)
endif()

if (IS_DIRECTORY "${PROJECT_SOURCE_DIR}/.git")
# Install Git pre-commit hook
Expand Down Expand Up @@ -91,6 +95,7 @@ file(GLOB LIB_SRC
"./src/linux/linux_platform.cpp"
)

if(VERIFIER_ENABLE_TESTS)
file(GLOB ALL_TEST
"./src/test/test_conformance.cpp"
"./src/test/test_marshal.cpp"
Expand All @@ -99,6 +104,7 @@ file(GLOB ALL_TEST
"./src/test/test_wto.cpp"
"./src/test/test_yaml.cpp"
)
endif()

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
Expand All @@ -115,13 +121,16 @@ endif ()

add_library(ebpfverifier ${LIB_SRC})

if(VERIFIER_ENABLE_TESTS)
add_executable(check src/main/check.cpp src/main/linux_verifier.cpp)
add_executable(tests ${ALL_TEST})
add_executable(run_yaml src/main/run_yaml.cpp)
add_executable(conformance_check src/test/conformance_check.cpp)
endif()

target_include_directories(ebpfverifier PRIVATE ${GSL_INCLUDE_DIRS})

if(VERIFIER_ENABLE_TESTS)
set_target_properties(check
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/..")
Expand All @@ -139,14 +148,17 @@ set_target_properties(conformance_check
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/..")

add_dependencies(tests conformance_check)
endif()

target_compile_options(ebpfverifier PRIVATE ${COMMON_FLAGS})
target_compile_options(ebpfverifier PUBLIC "$<$<CONFIG:DEBUG>:${DEBUG_FLAGS}>")
target_compile_options(ebpfverifier PUBLIC "$<$<CONFIG:RELEASE>:${RELEASE_FLAGS}>")
target_compile_options(ebpfverifier PUBLIC "$<$<CONFIG:SANITIZE>:${SANITIZE_FLAGS}>")

add_subdirectory("external/bpf_conformance/external/elfio")
if(VERIFIER_ENABLE_TESTS)
add_subdirectory("external/bpf_conformance/src")
endif()
add_subdirectory("external/libbtf")

# CMake derives a Visual Studio project GUID from the file path but can be overridden via a property
Expand All @@ -164,6 +176,7 @@ target_link_libraries(ebpfverifier PRIVATE libbtf)
target_link_libraries(ebpfverifier PRIVATE Microsoft.GSL::GSL)
target_compile_options(ebpfverifier PRIVATE ${COMMON_FLAGS})

if(VERIFIER_ENABLE_TESTS)
target_compile_options(check PRIVATE ${COMMON_FLAGS})
target_compile_options(check PUBLIC "$<$<CONFIG:DEBUG>:${DEBUG_FLAGS}>")
target_compile_options(check PUBLIC "$<$<CONFIG:RELEASE>:${RELEASE_FLAGS}>")
Expand All @@ -184,3 +197,4 @@ target_link_libraries(tests PRIVATE Catch2::Catch2WithMain)
target_link_libraries(run_yaml PRIVATE ebpfverifier)

target_link_libraries(conformance_check PRIVATE ebpfverifier)
endif()
Loading