diff --git a/projects/rocshmem/CMakeLists.txt b/projects/rocshmem/CMakeLists.txt index 4bf64c5435..abf710ee9d 100644 --- a/projects/rocshmem/CMakeLists.txt +++ b/projects/rocshmem/CMakeLists.txt @@ -62,6 +62,7 @@ option(BUILD_UNIT_TESTS "Build the unit tests" ON) option(BUILD_TESTS_ONLY "Build only tests. Used to link agains rocSHMEM in a ROCm Release" OFF) option(BUILD_LOCAL_GPU_TARGET_ONLY "Build only for GPUs detected on this machine" OFF) +option(BUILD_CODE_COVERAGE "Build with code coverage flags (gcc only)" OFF) configure_file(cmake/rocshmem_config.h.in rocshmem_config.h) diff --git a/projects/rocshmem/README.md b/projects/rocshmem/README.md index 2a615af785..5c744141fb 100644 --- a/projects/rocshmem/README.md +++ b/projects/rocshmem/README.md @@ -154,6 +154,20 @@ To run the tests, you may use the driver scripts provided in the `./scripts/` di ./scripts/unit_tests/driver.sh ./build/tests/unit_tests/rocshmem_unit_tests all ``` +## Code Coverage +rocSHMEM targets 80% code coverage in both unit and functional tests. To check the coverage report for your +changes, we have a helper script you can use to build, test and generate the coverage report in a single step. + +Because we need to build all 3 of `ipc`, `ro_net` and `ro_ipc`, the `codecov` script is run from the context of +the `build/` directory and will create and build to the 3 directories, with instrumented code. It will then start +a python http server where you can navigate to the link to view the coverage report. + +``` +cd rocSHMEM +mkdir build && cd build +../scripts/build_configs/codecov +``` + ## Building the Dependencies rocSHMEM requires a ROCm-Aware Open MPI and UCX. diff --git a/projects/rocshmem/scripts/build_configs/codecov b/projects/rocshmem/scripts/build_configs/codecov new file mode 100755 index 0000000000..9a742b2761 --- /dev/null +++ b/projects/rocshmem/scripts/build_configs/codecov @@ -0,0 +1,61 @@ +#!/bin/bash + +set -e + +export CODE_COV="ON" + +src_path=$(dirname "$(realpath $0)") + +mkdir -p ipc && pushd ipc +$src_path/ipc_single +popd + +mkdir -p ro_net && pushd ro_net +$src_path/ro_net +popd + +mkdir -p ro_ipc && pushd ro_ipc +$src_path/ro_ipc +popd + +mkdir -p ./test_output +export PROFRAW_DIR=./coverage-report/profraw +mkdir -p $PROFRAW_DIR + +# Unit Tests +LLVM_PROFILE_FILE="$PROFRAW_DIR/ipc_unit-%p.profraw" ../scripts/unit_tests/driver.sh ./ipc/tests/unit_tests/rocshmem_unit_tests all + +LLVM_PROFILE_FILE="$PROFRAW_DIR/ro_net-unit-%p.profraw" ../scripts/unit_tests/driver.sh ./ro_net/tests/unit_tests/rocshmem_unit_tests all + +LLVM_PROFILE_FILE="$PROFRAW_DIR/ro_ipc-unit-%p.profraw" ../scripts/unit_tests/driver.sh ./ro_ipc/tests/unit_tests/rocshmem_unit_tests all + +# Functional Tests +LLVM_PROFILE_FILE="$PROFRAW_DIR/ipc-functional-%p.profraw" ../scripts/functional_tests/driver.sh ./ipc/tests/functional_tests/rocshmem_example_driver all ./test_output/ +LLVM_PROFILE_FILE="$PROFRAW_DIR/ro_net-functional-%p.profraw" ../scripts/functional_tests/driver.sh ./ro_net/tests/functional_tests/rocshmem_example_driver all ./test_output/ +LLVM_PROFILE_FILE="$PROFRAW_DIR/ro_ipc-functional-%p.profraw" ../scripts/functional_tests/driver.sh ./ro_ipc/tests/functional_tests/rocshmem_example_driver all ./test_output/ + +# Coverage Report +/opt/rocm/llvm/bin/llvm-profdata merge -sparse $PROFRAW_DIR/*.profraw -o ./coverage-report/rocshmem.profdata +/opt/rocm/llvm/bin/llvm-cov report \ + -object ./ipc/tests/unit_tests/rocshmem_unit_tests \ + -object ./ipc/tests/functional_tests/rocshmem_example_driver \ + -object ./ro_net/tests/unit_tests/rocshmem_unit_tests \ + -object ./ro_net/tests/functional_tests/rocshmem_example_driver \ + -object ./ro_ipc/tests/unit_tests/rocshmem_unit_tests \ + -object ./ro_ipc/tests/functional_tests/rocshmem_example_driver \ + -instr-profile=./coverage-report/rocshmem.profdata \ + --ignore-filename-regex=".*test.*" + +/opt/rocm/llvm/bin/llvm-cov show \ + -object ./ipc/tests/unit_tests/rocshmem_unit_tests \ + -object ./ipc/tests/functional_tests/rocshmem_example_driver \ + -object ./ro_net/tests/unit_tests/rocshmem_unit_tests \ + -object ./ro_net/tests/functional_tests/rocshmem_example_driver \ + -object ./ro_ipc/tests/unit_tests/rocshmem_unit_tests \ + -object ./ro_ipc/tests/functional_tests/rocshmem_example_driver \ + -instr-profile=./coverage-report/rocshmem.profdata \ + --ignore-filename-regex=".*test.*" + -format=html \ + -output-dir=coverage-report +cd coverage-report && python3 -m http.server + diff --git a/projects/rocshmem/scripts/build_configs/ipc_single b/projects/rocshmem/scripts/build_configs/ipc_single index c45bfc1f5a..55fb55b4a0 100755 --- a/projects/rocshmem/scripts/build_configs/ipc_single +++ b/projects/rocshmem/scripts/build_configs/ipc_single @@ -36,6 +36,7 @@ fi src_path=$(dirname "$(realpath $0)")/../../ cmake \ + -DBUILD_CODE_COVERAGE=${CODE_COV:-OFF} \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=$install_path \ -DCMAKE_VERBOSE_MAKEFILE=OFF \ diff --git a/projects/rocshmem/scripts/build_configs/ro_ipc b/projects/rocshmem/scripts/build_configs/ro_ipc index ff4d7d3eb5..3b54fce159 100755 --- a/projects/rocshmem/scripts/build_configs/ro_ipc +++ b/projects/rocshmem/scripts/build_configs/ro_ipc @@ -36,6 +36,7 @@ fi src_path=$(dirname "$(realpath $0)")/../../ cmake \ + -DBUILD_CODE_COVERAGE=${CODE_COV:-OFF} \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=$install_path \ -DCMAKE_VERBOSE_MAKEFILE=OFF \ diff --git a/projects/rocshmem/scripts/build_configs/ro_net b/projects/rocshmem/scripts/build_configs/ro_net index 9676b66203..f252d31751 100755 --- a/projects/rocshmem/scripts/build_configs/ro_net +++ b/projects/rocshmem/scripts/build_configs/ro_net @@ -36,6 +36,7 @@ fi src_path=$(dirname "$(realpath $0)")/../../ cmake \ + -DBUILD_CODE_COVERAGE=${CODE_COV:-OFF} \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=$install_path \ -DCMAKE_VERBOSE_MAKEFILE=OFF \ diff --git a/projects/rocshmem/src/CMakeLists.txt b/projects/rocshmem/src/CMakeLists.txt index f2dabd4876..41cec7ded1 100644 --- a/projects/rocshmem/src/CMakeLists.txt +++ b/projects/rocshmem/src/CMakeLists.txt @@ -42,15 +42,18 @@ target_sources( ipc_policy.cpp ) -target_compile_options( - ${PROJECT_NAME} - PUBLIC - -fgpu-rdc -# xnack allows address translation fault recovery -# required option for managed heap configs -# -mxnack +set( + ROCSHMEM_COMPILE_FLAGS + -fgpu-rdc + # xnack allows address translation fault recovery + # required option for managed heap configs + # -mxnack ) - +if (BUILD_CODE_COVERAGE) + set(ROCSHMEM_COMPILE_FLAGS ${ROCSHMEM_COMPILE_FLAGS} -fprofile-instr-generate -fcoverage-mapping) + target_link_options(${PROJECT_NAME} PUBLIC -fprofile-instr-generate) +endif() +target_compile_options(${PROJECT_NAME} PUBLIC ${ROCSHMEM_COMPILE_FLAGS}) #target_link_options( #${PROJECT_NAME} #PUBLIC