diff --git a/.github/workflows/test-attach.yml b/.github/workflows/test-attach.yml index 4a556fc6..a925f767 100644 --- a/.github/workflows/test-attach.yml +++ b/.github/workflows/test-attach.yml @@ -26,24 +26,76 @@ jobs: - uses: actions/checkout@v2 with: submodules: 'recursive' - + - name: Install dependencies + if: "matrix.container == 'ubuntu-2204'" + run: | + apt-get install -y lcov libzstd-dev libboost-all-dev gpg + - name: Install lcov + if: "matrix.container == 'fedora-39'" + run: | + dnf install -y lcov + - name: Build for frida uprobe attach tests run: | - cmake -B build + cmake -DTEST_LCOV=ON -B build cmake --build build --config Debug --target bpftime_frida_uprobe_attach_tests -j$(nproc) - name: Run frida uprobe attach tests run: | ./build/attach/frida_uprobe_attach_impl/bpftime_frida_uprobe_attach_tests - + - name: Generate frida uprobe attach test coverage (Fedora) + if: "matrix.container == 'fedora-39'" + run: | + lcov --capture --directory . --output-file coverage-uprobe.info + lcov --remove coverage-uprobe.info '/usr/*' --output-file coverage-uprobe.info + lcov --list coverage-uprobe.info + - name: Generate frida uprobe attach test coverage (Ubuntu) + if: "matrix.container == 'ubuntu-2204'" + run: | + lcov --capture --directory . --output-file coverage-uprobe.info --gcov-tool $(which gcov-12) + lcov --remove coverage-uprobe.info '/usr/*' --output-file coverage-uprobe.info + lcov --list coverage-uprobe.info + - name: Upload uprobe coverage + uses: actions/upload-artifact@v4 + with: + name: coverage-uprobe-${{matrix.container}} + include-hidden-files: false + path: | + ./coverage-uprobe.info - name: Remove the build run: rm -rf build - name: Build syscall trace uprobe attach tests run: | - cmake -B build + cmake -DTEST_LCOV=ON -B build cmake --build build --config Debug --target bpftime_syscall_trace_attach_tests -j$(nproc) - name: Run syscall trace uprobe attach tests run: | ./build/attach/syscall_trace_attach_impl/bpftime_syscall_trace_attach_tests + - name: Generate syscall trace uprobe attach coverage (Ubuntu) + if: "matrix.container == 'ubuntu-2204'" + run: | + lcov --capture --directory . --output-file coverage-syscall-trace.info --gcov-tool $(which gcov-12) + lcov --remove coverage-syscall-trace.info '/usr/*' --output-file coverage-syscall-trace.info + lcov --list coverage-syscall-trace.info + - name: Generate syscall trace uprobe attach coverage (Fedora) + if: "matrix.container == 'fedora-39'" + run: | + lcov --capture --directory . --output-file coverage-syscall-trace.info + lcov --remove coverage-syscall-trace.info '/usr/*' --output-file coverage-syscall-trace.info + lcov --list coverage-syscall-trace.info + - name: Upload uprobe coverage + uses: actions/upload-artifact@v4 + with: + name: coverage-syscall-trace-${{matrix.container}} + include-hidden-files: false + path: | + ./coverage-syscall-trace.info + - uses: codecov/codecov-action@v4 + with: + fail_ci_if_error: true # optional (default = false) + files: ./coverage-syscall-trace.info, ./coverage-uprobe.info # optional + flags: attach tests (uprobe & syscall trace) + token: ${{ secrets.CODECOV_TOKEN }} # required + verbose: true # optional (default = false) diff --git a/.github/workflows/test-runtime.yml b/.github/workflows/test-runtime.yml index eafcf6a1..a2ce689c 100644 --- a/.github/workflows/test-runtime.yml +++ b/.github/workflows/test-runtime.yml @@ -24,19 +24,79 @@ jobs: - uses: actions/checkout@v2 with: submodules: 'recursive' + - name: Install lcov + if: "matrix.container == 'ubuntu-2204'" + run: | + apt-get install -y lcov libzstd-dev libboost-all-dev + - name: Install lcov + if: "matrix.container == 'fedora-39'" + run: | + dnf install -y lcov + - name: Build run: | - cmake -DBPFTIME_LLVM_JIT=YES -DBPFTIME_ENABLE_UNIT_TESTING=YES -DCMAKE_BUILD_TYPE=Debug -B build + cmake -DTEST_LCOV=ON -DBPFTIME_LLVM_JIT=YES -DBPFTIME_ENABLE_UNIT_TESTING=YES -DCMAKE_BUILD_TYPE=Debug -B build cmake --build build --config Debug --target bpftime_runtime_tests -j$(nproc) - name: Test Runtime run: ./build/runtime/unit-test/bpftime_runtime_tests + - name: Generate runtime coverage (Ubuntu) + if: "matrix.container == 'ubuntu-2204'" + run: | + lcov --capture --directory . --output-file coverage-runtime.info --gcov-tool $(which gcov-12) + lcov --remove coverage-runtime.info '/usr/*' --output-file coverage-runtime.info + lcov --list coverage-runtime.info + - name: Generate runtime coverage (Fedora) + if: "matrix.container == 'fedora-39'" + run: | + lcov --capture --directory . --output-file coverage-runtime.info + lcov --remove coverage-runtime.info '/usr/*' --output-file coverage-runtime.info + lcov --list coverage-runtime.info + - name: Generate runtime coverage + run: | + lcov --capture --directory . --output-file coverage-runtime.info --gcov-tool $(which gcov-12) + lcov --remove coverage-runtime.info '/usr/*' --output-file coverage-runtime.info + lcov --list coverage-runtime.info + - name: Upload runtime coverage + uses: actions/upload-artifact@v4 + with: + name: coverage-runtime-${{matrix.container}} + include-hidden-files: false + path: | + ./coverage-runtime.info + - name: build runtime with mpk enable run: | rm -rf build - cmake -Bbuild -DBPFTIME_LLVM_JIT=YES -DBPFTIME_ENABLE_UNIT_TESTING=YES -DBPFTIME_ENABLE_MPK=YES -DCMAKE_BUILD_TYPE=Debug + cmake -Bbuild -DTEST_LCOV=ON -DBPFTIME_LLVM_JIT=YES -DBPFTIME_ENABLE_UNIT_TESTING=YES -DBPFTIME_ENABLE_MPK=YES -DCMAKE_BUILD_TYPE=Debug cmake --build build --config Debug --target bpftime_runtime_tests -j$(nproc) - - - name: test runtime with mpk run: ./build/runtime/unit-test/bpftime_runtime_tests + - name: Generate runtime with mpk enable coverage (Ubuntu) + if: "matrix.container == 'ubuntu-2204'" + run: | + lcov --capture --directory . --output-file coverage-runtime-mpk.info --gcov-tool $(which gcov-12) + lcov --remove coverage-runtime-mpk.info '/usr/*' --output-file coverage-runtime-mpk.info + lcov --list coverage-runtime-mpk.info + - name: Generate runtime with mpk enable coverage (Fedora) + if: "matrix.container == 'fedora-39'" + run: | + lcov --capture --directory . --output-file coverage-runtime-mpk.info + lcov --remove coverage-runtime-mpk.info '/usr/*' --output-file coverage-runtime-mpk.info + lcov --list coverage-runtime-mpk.info + - name: Upload runtime-mpk coverage + uses: actions/upload-artifact@v4 + with: + name: coverage-runtime-mpk-${{matrix.container}} + include-hidden-files: false + path: | + ./coverage-runtime-mpk.info + + - uses: codecov/codecov-action@v4 + with: + fail_ci_if_error: true # optional (default = false) + files: ./coverage-runtime.info + flags: runtime tests + token: ${{ secrets.CODECOV_TOKEN }} # required + verbose: true # optional (default = false) + \ No newline at end of file diff --git a/.github/workflows/test-verifier.yml b/.github/workflows/test-verifier.yml index 66862ebf..b2d2d602 100644 --- a/.github/workflows/test-verifier.yml +++ b/.github/workflows/test-verifier.yml @@ -19,10 +19,19 @@ jobs: run: | sudo apt-get update -y sudo apt-get install binutils-dev libboost1.74-all-dev libelf-dev zlib1g-dev ninja-build libyaml-cpp-dev -y + - name: Install lcov + run: | + sudo apt install -y lcov libzstd-dev - name: Build test target run: | - cmake -DBPFTIME_ENABLE_UNIT_TESTING=YES -DBPFTIME_LLVM_JIT=NO -DENABLE_EBPF_VERIFIER=YES -DCMAKE_BUILD_TYPE:STRING=Release -S . -B build -G Ninja + cmake -DTEST_LCOV=ON -DBPFTIME_ENABLE_UNIT_TESTING=YES -DBPFTIME_LLVM_JIT=NO -DENABLE_EBPF_VERIFIER=YES -DCMAKE_BUILD_TYPE:STRING=Release -S . -B build -G Ninja cmake --build build --config Release --target bpftime_verifier_tests - name: Run tests run: | ./build/bpftime-verifier/bpftime_verifier_tests + - name: upload runtime coverage + run: | + lcov --capture --directory . --output-file coverage.info + lcov --remove coverage.info '/usr/*' --output-file coverage.info + lcov --list coverage.info + diff --git a/attach/frida_uprobe_attach_impl/CMakeLists.txt b/attach/frida_uprobe_attach_impl/CMakeLists.txt index 258c0893..ccb44b4c 100644 --- a/attach/frida_uprobe_attach_impl/CMakeLists.txt +++ b/attach/frida_uprobe_attach_impl/CMakeLists.txt @@ -23,8 +23,13 @@ set(TEST_SOURCES test/test_replace_attach_with_override.cpp test/test_attach_with_unified_interface.cpp ) +option(TEST_LCOV "option for lcov" OFF) add_executable(bpftime_frida_uprobe_attach_tests ${TEST_SOURCES}) +if (${TEST_LCOV}) + target_compile_options(bpftime_frida_uprobe_attach_tests PRIVATE -fprofile-arcs -ftest-coverage) +endif() + if(${ENABLE_EBPF_VERIFIER} AND NOT TARGET Catch2) message(STATUS "Adding Catch2 by FetchContent for frida_uprobe_attach_impl") Include(FetchContent) @@ -39,7 +44,12 @@ if(${ENABLE_EBPF_VERIFIER} AND NOT TARGET Catch2) endif() add_dependencies(bpftime_frida_uprobe_attach_tests Catch2 bpftime_frida_uprobe_attach_impl spdlog::spdlog) -target_link_libraries(bpftime_frida_uprobe_attach_tests PRIVATE Catch2::Catch2WithMain bpftime_frida_uprobe_attach_impl spdlog::spdlog) +if (${TEST_LCOV}) + target_link_options(bpftime_frida_uprobe_attach_tests PRIVATE -lgcov) + target_link_libraries(bpftime_frida_uprobe_attach_tests PRIVATE Catch2::Catch2WithMain bpftime_frida_uprobe_attach_impl spdlog::spdlog gcov) +else () + target_link_libraries(bpftime_frida_uprobe_attach_tests PRIVATE Catch2::Catch2WithMain bpftime_frida_uprobe_attach_impl spdlog::spdlog) +endif() target_include_directories(bpftime_frida_uprobe_attach_tests PRIVATE ${FRIDA_UPROBE_ATTACH_IMPL_INCLUDE} ${Catch2_INCLUDE} ${SPDLOG_INCLUDE}) add_test(NAME bpftime_frida_uprobe_attach_tests COMMAND bpftime_frida_uprobe_attach_tests) diff --git a/attach/syscall_trace_attach_impl/CMakeLists.txt b/attach/syscall_trace_attach_impl/CMakeLists.txt index e94da71e..2241cab2 100644 --- a/attach/syscall_trace_attach_impl/CMakeLists.txt +++ b/attach/syscall_trace_attach_impl/CMakeLists.txt @@ -28,8 +28,13 @@ set(TEST_SOURCES test/test_private_data_parsing.cpp test/test_syscall_dispatch.cpp ) +option(TEST_LCOV "option for lcov" OFF) add_executable(bpftime_syscall_trace_attach_tests ${TEST_SOURCES}) +if (${TEST_LCOV}) + target_compile_options(bpftime_syscall_trace_attach_tests PRIVATE -fprofile-arcs -ftest-coverage) +endif() + if(${ENABLE_EBPF_VERIFIER} AND NOT TARGET Catch2) message(STATUS "Adding Catch2 by FetchContent at syscall_trace_attach_impl") Include(FetchContent) @@ -44,7 +49,12 @@ if(${ENABLE_EBPF_VERIFIER} AND NOT TARGET Catch2) endif() add_dependencies(bpftime_syscall_trace_attach_tests Catch2 bpftime_syscall_trace_attach_impl spdlog::spdlog) -target_link_libraries(bpftime_syscall_trace_attach_tests PRIVATE Catch2::Catch2WithMain bpftime_syscall_trace_attach_impl spdlog::spdlog) +if (${TEST_LCOV}) + target_link_options(bpftime_syscall_trace_attach_tests PRIVATE -lgcov) + target_link_libraries(bpftime_syscall_trace_attach_tests PRIVATE Catch2::Catch2WithMain bpftime_syscall_trace_attach_impl spdlog::spdlog gcov) +else () + target_link_libraries(bpftime_syscall_trace_attach_tests PRIVATE Catch2::Catch2WithMain bpftime_syscall_trace_attach_impl spdlog::spdlog) +endif() target_include_directories(bpftime_syscall_trace_attach_tests PRIVATE ${SYSCALL_TRACE_ATTACH_IMPL_INCLUDE} ${Catch2_INCLUDE} ${SPDLOG_INCLUDE}) add_test(NAME bpftime_syscall_trace_attach_tests COMMAND bpftime_syscall_trace_attach_tests) diff --git a/bpftime-verifier/CMakeLists.txt b/bpftime-verifier/CMakeLists.txt index 2b93d5d4..5ab5be9e 100644 --- a/bpftime-verifier/CMakeLists.txt +++ b/bpftime-verifier/CMakeLists.txt @@ -34,8 +34,20 @@ if(NOT TARGET Catch2) FetchContent_MakeAvailable(Catch2) endif() +option(TEST_LCOV "option for lcov" OFF) add_executable(bpftime_verifier_tests ${TEST_SOURCES}) + +if (${TEST_LCOV}) + target_compile_options(bpftime_verifier_tests PRIVATE -fprofile-arcs -ftest-coverage) +endif() + add_dependencies(bpftime_verifier_tests bpftime-verifier) -target_link_libraries(bpftime_verifier_tests PRIVATE bpftime-verifier Catch2::Catch2WithMain) + +if (${TEST_LCOV}) + target_link_options(bpftime_verifier_tests PRIVATE -lgcov) + target_link_libraries(bpftime_verifier_tests PRIVATE bpftime-verifier Catch2::Catch2WithMain gcov) +else () + target_link_libraries(bpftime_verifier_tests PRIVATE bpftime-verifier Catch2::Catch2WithMain) +endif() target_include_directories(bpftime_verifier_tests PRIVATE ${BPFTIME_VERIFIER_INCLUDE}) add_test(NAME bpftime_verifier_tests COMMAND bpftime_verifier_tests) diff --git a/runtime/unit-test/CMakeLists.txt b/runtime/unit-test/CMakeLists.txt index 95560844..6f7bf94c 100644 --- a/runtime/unit-test/CMakeLists.txt +++ b/runtime/unit-test/CMakeLists.txt @@ -31,10 +31,23 @@ set(TEST_SOURCES tailcall/test_user_to_kernel_tailcall.cpp ) +option(TEST_LCOV "option for lcov" OFF) add_executable(bpftime_runtime_tests ${TEST_SOURCES}) + +if (${TEST_LCOV}) + target_compile_options(bpftime_runtime_tests PRIVATE -fprofile-arcs -ftest-coverage) +endif() + set_property(TARGET bpftime_runtime_tests PROPERTY CXX_STANDARD 20) add_dependencies(bpftime_runtime_tests runtime bpftime-object bpftime_frida_uprobe_attach_impl) -target_link_libraries(bpftime_runtime_tests PRIVATE runtime bpftime-object Catch2::Catch2WithMain bpftime_frida_uprobe_attach_impl) + +if (${TEST_LCOV}) + target_link_options(bpftime_runtime_tests PRIVATE -lgcov) + target_link_libraries(bpftime_runtime_tests PRIVATE runtime bpftime-object Catch2::Catch2WithMain bpftime_frida_uprobe_attach_impl gcov) +else () + target_link_libraries(bpftime_runtime_tests PRIVATE runtime bpftime-object Catch2::Catch2WithMain bpftime_frida_uprobe_attach_impl) +endif() + target_include_directories(bpftime_runtime_tests PRIVATE ${BPFTIME_RUNTIME_INCLUDE} ${BPFTIME_OBJECT_INCLUDE_DIRS} ${Catch2_INCLUDE} ${Boost_INCLUDE} ${FRIDA_UPROBE_ATTACH_IMPL_INCLUDE}) add_test(NAME bpftime_runtime_tests COMMAND bpftime_runtime_tests)