summaryrefslogtreecommitdiffstats
path: root/src/vat2
diff options
context:
space:
mode:
Diffstat (limited to 'src/vat2')
-rw-r--r--src/vat2/CMakeLists.txt37
-rw-r--r--src/vat2/test/vat2_test.api11
-rw-r--r--src/vat2/test/vat2_test.c44
3 files changed, 77 insertions, 15 deletions
diff --git a/src/vat2/CMakeLists.txt b/src/vat2/CMakeLists.txt
index 73538b4a2dd..9069d8f6b62 100644
--- a/src/vat2/CMakeLists.txt
+++ b/src/vat2/CMakeLists.txt
@@ -54,6 +54,43 @@ add_vpp_executable(test_vat2 ENABLE_EXPORTS NO_INSTALL
rt m dl crypto
)
#target_link_options(test_vat2 PUBLIC "LINKER:-fsanitize=address")
+
+if("${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.13" AND "${CMAKE_C_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
+ set(TARGET_NAME test_vat2)
+ set(COV_SOURCES ${CMAKE_SOURCE_DIR}/vat2/jsonconvert.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()
+
+
+
##############################################################################
# vat2 headers
##############################################################################
diff --git a/src/vat2/test/vat2_test.api b/src/vat2/test/vat2_test.api
index 6a2c94d182e..fe96dd75784 100644
--- a/src/vat2/test/vat2_test.api
+++ b/src/vat2/test/vat2_test.api
@@ -28,3 +28,14 @@ enumflag test_enumflags {
autoreply define test_enum {
vl_api_test_enumflags_t flags;
};
+
+typedef test_stringtype {
+ string str[];
+};
+
+autoreply define test_string {
+ vl_api_test_stringtype_t str;
+};
+autoreply define test_string2 {
+ string str[];
+};
diff --git a/src/vat2/test/vat2_test.c b/src/vat2/test/vat2_test.c
index fe788f127c6..b5346eeea47 100644
--- a/src/vat2/test/vat2_test.c
+++ b/src/vat2/test/vat2_test.c
@@ -96,24 +96,38 @@ runtest (char *s, bool should_fail)
}
struct msgs msgs[] = {
-{
- .name = "test_prefix",
- .tojson = (tojson_fn_t)vl_api_test_prefix_t_tojson,
- .fromjson = (fromjson_fn_t)vl_api_test_prefix_t_fromjson,
-},
-{
- .name = "test_enum",
- .tojson = (tojson_fn_t)vl_api_test_enum_t_tojson,
- .fromjson = (fromjson_fn_t)vl_api_test_enum_t_fromjson,
-},
+ {
+ .name = "test_prefix",
+ .tojson = (tojson_fn_t) vl_api_test_prefix_t_tojson,
+ .fromjson = (fromjson_fn_t) vl_api_test_prefix_t_fromjson,
+ },
+ {
+ .name = "test_enum",
+ .tojson = (tojson_fn_t) vl_api_test_enum_t_tojson,
+ .fromjson = (fromjson_fn_t) vl_api_test_enum_t_fromjson,
+ },
+ {
+ .name = "test_string",
+ .tojson = (tojson_fn_t) vl_api_test_string_t_tojson,
+ .fromjson = (fromjson_fn_t) vl_api_test_string_t_fromjson,
+ },
+ {
+ .name = "test_string2",
+ .tojson = (tojson_fn_t) vl_api_test_string2_t_tojson,
+ .fromjson = (fromjson_fn_t) vl_api_test_string2_t_fromjson,
+ },
};
struct tests tests[] = {
- {.s = "{\"_msgname\": \"test_prefix\", \"pref\": \"2001:db8::/64\"}"},
- {.s = "{\"_msgname\": \"test_prefix\", \"pref\": \"192.168.10.0/24\"}"},
- {.s = "{\"_msgname\": \"test_enum\", \"flags\": [\"RED\", \"BLUE\"]}"},
- {.s = "{\"_msgname\": \"test_enum\", \"flags\": [\"BLACK\", \"BLUE\"]}",
- .should_fail = 1},
+ { .s = "{\"_msgname\": \"test_prefix\", \"pref\": \"2001:db8::/64\"}" },
+ { .s = "{\"_msgname\": \"test_prefix\", \"pref\": \"192.168.10.0/24\"}" },
+ { .s = "{\"_msgname\": \"test_enum\", \"flags\": [\"RED\", \"BLUE\"]}" },
+ { .s = "{\"_msgname\": \"test_enum\", \"flags\": [\"BLACK\", \"BLUE\"]}",
+ .should_fail = 1 },
+ { .s = "{\"_msgname\": \"test_string\", \"str\": {\"str\": \"Test string "
+ "type\"}}" },
+ { .s =
+ "{\"_msgname\": \"test_string2\", \"str\": \"Test string toplevel\"}" },
};
int main (int argc, char **argv)