Skip to content

Commit

Permalink
feat:add lcov and codecov support (#352)
Browse files Browse the repository at this point in the history
* feat:add lcov support for test

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update
  • Loading branch information
kenlig authored Sep 28, 2024
1 parent 8ccbea3 commit f9a3c24
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 13 deletions.
60 changes: 56 additions & 4 deletions .github/workflows/test-attach.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
68 changes: 64 additions & 4 deletions .github/workflows/test-runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)

11 changes: 10 additions & 1 deletion .github/workflows/test-verifier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 11 additions & 1 deletion attach/frida_uprobe_attach_impl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion attach/syscall_trace_attach_impl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
14 changes: 13 additions & 1 deletion bpftime-verifier/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
15 changes: 14 additions & 1 deletion runtime/unit-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit f9a3c24

Please sign in to comment.