aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/nat/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/nat/CMakeLists.txt')
-rw-r--r--src/plugins/nat/CMakeLists.txt56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/plugins/nat/CMakeLists.txt b/src/plugins/nat/CMakeLists.txt
index 83c148f9658..d3f3eac3c05 100644
--- a/src/plugins/nat/CMakeLists.txt
+++ b/src/plugins/nat/CMakeLists.txt
@@ -139,3 +139,59 @@ add_vpp_plugin(nat64
LINK_LIBRARIES nat
)
+
+add_vpp_plugin(pnat
+ SOURCES
+ pnat/pnat.c
+ pnat/pnat_cli.c
+ pnat/pnat_api.c
+ pnat/pnat_node.c
+
+ API_FILES
+ pnat/pnat.api
+)
+
+# Unit tests
+add_vpp_executable(test_pnat
+ SOURCES
+ pnat/pnat_test.c
+ pnat/pnat_node.c
+ pnat/pnat.c
+ ../../vnet/ip/ip_checksum.c
+ LINK_LIBRARIES vppinfra vlib
+ NO_INSTALL
+)
+
+if("${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.13" AND "${CMAKE_C_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
+ set(TARGET_NAME test_pnat)
+ set(COV_SOURCES ${CMAKE_SOURCE_DIR}/plugins/nat/pnat/pnat.c ${CMAKE_SOURCE_DIR}/plugins/nat/pnat/pnat_node.h ${CMAKE_SOURCE_DIR}/plugins/nat/pnat/pnat_node.c)
+
+ message("Building with llvm Code Coverage Tools ${TARGET_NAME}")
+ target_compile_options(${TARGET_NAME} PRIVATE -fprofile-instr-generate -fcoverage-mapping)
+ target_link_options(${TARGET_NAME} PRIVATE -fprofile-instr-generate -fcoverage-mapping)
+ target_compile_options(${TARGET_NAME} PRIVATE -fsanitize=address)
+ target_link_options(${TARGET_NAME} PRIVATE -fsanitize=address)
+
+ # llvm-cov
+ add_custom_target(${TARGET_NAME}-ccov-preprocessing
+ COMMAND LLVM_PROFILE_FILE=${TARGET_NAME}.profraw $<TARGET_FILE:${TARGET_NAME}>
+ COMMAND llvm-profdata merge -sparse ${TARGET_NAME}.profraw -o ${TARGET_NAME}.profdata
+ DEPENDS ${TARGET_NAME})
+
+ add_custom_target(${TARGET_NAME}-ccov-show
+ COMMAND llvm-cov show $<TARGET_FILE:${TARGET_NAME}> -instr-profile=${TARGET_NAME}.profdata -show-line-counts-or-regions ${COV_SOURCES}
+ DEPENDS ${TARGET_NAME}-ccov-preprocessing)
+
+ add_custom_target(${TARGET_NAME}-ccov-report
+ COMMAND llvm-cov report -show-functions $<TARGET_FILE:${TARGET_NAME}> -instr-profile=${TARGET_NAME}.profdata ${COV_SOURCES}
+ DEPENDS ${TARGET_NAME}-ccov-preprocessing)
+
+ add_custom_target(${TARGET_NAME}-ccov
+ COMMAND llvm-cov show $<TARGET_FILE:${TARGET_NAME}> -instr-profile=${TARGET_NAME}.profdata -show-line-counts-or-regions -output-dir=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET_NAME}-llvm-cov -format="html" ${COV_SOURCES}
+ DEPENDS ${TARGET_NAME}-ccov-preprocessing)
+
+ add_custom_command(TARGET ${TARGET_NAME}-ccov POST_BUILD
+ COMMAND ;
+ COMMENT "Open ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET_NAME}-llvm-cov/index.html in your browser to view the coverage report."
+)
+endif()