Add test cases for adding u32 value API. Cc: sta...@dpdk.org
Signed-off-by: Huisong Li <lihuis...@huawei.com> --- app/test/test_telemetry_data.c | 85 +++++++++++++++++++++++++++++++++- app/test/test_telemetry_json.c | 23 ++++++++- 2 files changed, 104 insertions(+), 4 deletions(-) diff --git a/app/test/test_telemetry_data.c b/app/test/test_telemetry_data.c index d92667a527..8ab3441cbe 100644 --- a/app/test/test_telemetry_data.c +++ b/app/test/test_telemetry_data.c @@ -278,6 +278,17 @@ test_array_with_array_string_values(void) return CHECK_OUTPUT("[[\"aaaa\"],[\"bbbb\"]]"); } +static int +test_case_array_u32(void) +{ + uint32_t i; + + rte_tel_data_start_array(&response_data, RTE_TEL_U32_VAL); + for (i = 0; i < 5; i++) + rte_tel_data_add_array_u32(&response_data, i); + return CHECK_OUTPUT("[0,1,2,3,4]"); +} + static int test_case_array_u64(void) { @@ -289,6 +300,21 @@ test_case_array_u64(void) return CHECK_OUTPUT("[0,1,2,3,4]"); } +static int +test_case_add_dict_u32(void) +{ + uint32_t i = 0; + char name_of_value[8]; + + rte_tel_data_start_dict(&response_data); + + for (i = 0; i < 5; i++) { + sprintf(name_of_value, "dict_%u", i); + rte_tel_data_add_dict_u32(&response_data, name_of_value, i); + } + return CHECK_OUTPUT("{\"dict_0\":0,\"dict_1\":1,\"dict_2\":2,\"dict_3\":3,\"dict_4\":4}"); +} + static int test_case_add_dict_u64(void) { @@ -304,6 +330,32 @@ test_case_add_dict_u64(void) return CHECK_OUTPUT("{\"dict_0\":0,\"dict_1\":1,\"dict_2\":2,\"dict_3\":3,\"dict_4\":4}"); } +static int +test_dict_with_array_u32_values(void) +{ + uint32_t i; + + struct rte_tel_data *child_data = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data, RTE_TEL_U32_VAL); + + struct rte_tel_data *child_data2 = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data2, RTE_TEL_U32_VAL); + + rte_tel_data_start_dict(&response_data); + + for (i = 0; i < 10; i++) { + rte_tel_data_add_array_u32(child_data, i); + rte_tel_data_add_array_u32(child_data2, i); + } + + rte_tel_data_add_dict_container(&response_data, "dict_0", + child_data, 0); + rte_tel_data_add_dict_container(&response_data, "dict_1", + child_data2, 0); + + return CHECK_OUTPUT("{\"dict_0\":[0,1,2,3,4,5,6,7,8,9],\"dict_1\":[0,1,2,3,4,5,6,7,8,9]}"); +} + static int test_dict_with_array_u64_values(void) { @@ -330,6 +382,29 @@ test_dict_with_array_u64_values(void) return CHECK_OUTPUT("{\"dict_0\":[0,1,2,3,4,5,6,7,8,9],\"dict_1\":[0,1,2,3,4,5,6,7,8,9]}"); } +static int +test_array_with_array_u32_values(void) +{ + uint32_t i; + + struct rte_tel_data *child_data = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data, RTE_TEL_U32_VAL); + + struct rte_tel_data *child_data2 = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data2, RTE_TEL_U32_VAL); + + rte_tel_data_start_array(&response_data, RTE_TEL_CONTAINER); + + for (i = 0; i < 5; i++) { + rte_tel_data_add_array_u32(child_data, i); + rte_tel_data_add_array_u32(child_data2, i); + } + rte_tel_data_add_array_container(&response_data, child_data, 0); + rte_tel_data_add_array_container(&response_data, child_data2, 0); + + return CHECK_OUTPUT("[[0,1,2,3,4],[0,1,2,3,4]]"); +} + static int test_array_with_array_u64_values(void) { @@ -428,14 +503,20 @@ telemetry_data_autotest(void) test_null_return, test_simple_string, test_case_array_string, - test_case_array_int, test_case_array_u64, - test_case_add_dict_int, test_case_add_dict_u64, + test_case_array_int, + test_case_array_u32, + test_case_array_u64, + test_case_add_dict_int, + test_case_add_dict_u32, + test_case_add_dict_u64, test_case_add_dict_string, test_dict_with_array_int_values, + test_dict_with_array_u32_values, test_dict_with_array_u64_values, test_dict_with_array_string_values, test_dict_with_dict_values, test_array_with_array_int_values, + test_array_with_array_u32_values, test_array_with_array_u64_values, test_array_with_array_string_values, test_string_char_escaping, diff --git a/app/test/test_telemetry_json.c b/app/test/test_telemetry_json.c index 184c3ba9f1..e25442f8f0 100644 --- a/app/test/test_telemetry_json.c +++ b/app/test/test_telemetry_json.c @@ -31,7 +31,25 @@ test_basic_array(void) } static int -test_basic_obj(void) +test_basic_obj_u32(void) +{ + const char *expected = "{\"weddings\":4,\"funerals\":1}"; + char buf[1024]; + int used = 0; + + used = rte_tel_json_add_obj_u32(buf, sizeof(buf), used, + "weddings", 4); + used = rte_tel_json_add_obj_u32(buf, sizeof(buf), used, + "funerals", 1); + + printf("%s: buf = '%s', expected = '%s'\n", __func__, buf, expected); + if (used != (int)strlen(expected)) + return -1; + return strncmp(expected, buf, sizeof(buf)); +} + +static int +test_basic_obj_u64(void) { const char *expected = "{\"weddings\":4,\"funerals\":1}"; char buf[1024]; @@ -195,7 +213,8 @@ test_telemetry_json(void) unsigned int i; test_fn fns[] = { test_basic_array, - test_basic_obj, + test_basic_obj_u32, + test_basic_obj_u64, test_overflow_array, test_overflow_obj, test_large_array_element, -- 2.33.0