From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C1C50A00C2; Fri, 9 Dec 2022 12:05:22 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4FA6842D45; Fri, 9 Dec 2022 12:04:56 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id BB15242BAC for ; Fri, 9 Dec 2022 12:04:49 +0100 (CET) Received: from kwepemm600004.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NT7SG06w7zJqRk; Fri, 9 Dec 2022 19:03:57 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by kwepemm600004.china.huawei.com (7.193.23.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 9 Dec 2022 19:04:47 +0800 From: Huisong Li To: CC: , , , , , , Subject: [PATCH V2 10/11] test: add test cases for adding hex integer values API Date: Fri, 9 Dec 2022 19:04:49 +0800 Message-ID: <20221209110450.62456-11-lihuisong@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20221209110450.62456-1-lihuisong@huawei.com> References: <20221208080540.62913-1-lihuisong@huawei.com> <20221209110450.62456-1-lihuisong@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600004.china.huawei.com (7.193.23.242) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add test cases for adding hexadecimal u32 and u64 values API. Signed-off-by: Huisong Li --- app/test/test_telemetry_data.c | 164 +++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) diff --git a/app/test/test_telemetry_data.c b/app/test/test_telemetry_data.c index 8ab3441cbe..7ce905c503 100644 --- a/app/test/test_telemetry_data.c +++ b/app/test/test_telemetry_data.c @@ -278,6 +278,89 @@ test_array_with_array_string_values(void) return CHECK_OUTPUT("[[\"aaaa\"],[\"bbbb\"]]"); } +static int +test_case_array_with_array_hex_u32_values(void) +{ + struct rte_tel_data *child_data = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data, RTE_TEL_STRING_VAL); + + struct rte_tel_data *child_data2 = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data2, RTE_TEL_STRING_VAL); + + rte_tel_data_start_array(&response_data, RTE_TEL_CONTAINER); + + rte_tel_data_add_array_hex_u32_str(child_data, 0xfffffff0); + rte_tel_data_add_array_hex_u32_str(child_data, 0xfffffff1); + rte_tel_data_add_array_hex_u32_str(child_data2, 0x8ffff2); + + 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("[[\"0xfffffff0\",\"0xfffffff1\"],[\"0x8ffff2\"]]"); +} + +static int +test_case_array_with_array_hex_u64_values(void) +{ + struct rte_tel_data *child_data = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data, RTE_TEL_STRING_VAL); + + rte_tel_data_start_array(&response_data, RTE_TEL_CONTAINER); + rte_tel_data_add_array_hex_u64_str(child_data, 0xfffffffffffffff0); + rte_tel_data_add_array_hex_u64_str(child_data, 0xfffffffffffffff2); + + rte_tel_data_add_array_container(&response_data, child_data, 0); + + return CHECK_OUTPUT("[[\"0xfffffffffffffff0\",\"0xfffffffffffffff2\"]]"); +} + +static int +test_case_dict_with_array_hex_u32_values(void) +{ + struct rte_tel_data *child_data = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data, RTE_TEL_STRING_VAL); + + struct rte_tel_data *child_data2 = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data2, RTE_TEL_STRING_VAL); + + rte_tel_data_start_dict(&response_data); + + rte_tel_data_add_array_hex_u32_str(child_data, 0xfffffff0); + rte_tel_data_add_array_hex_u32_str(child_data, 0xfffffff1); + rte_tel_data_add_array_hex_u32_str(child_data2, 0x8ffffff0); + rte_tel_data_add_array_hex_u32_str(child_data2, 0x8ffffff1); + + 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\":[\"0xfffffff0\",\"0xfffffff1\"],\"dict_1\":[\"0x8ffffff0\",\"0x8ffffff1\"]}"); +} + +static int +test_case_dict_with_array_hex_u64_values(void) +{ + struct rte_tel_data *child_data = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data, RTE_TEL_STRING_VAL); + + struct rte_tel_data *child_data2 = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data2, RTE_TEL_STRING_VAL); + + rte_tel_data_start_dict(&response_data); + + rte_tel_data_add_array_hex_u64_str(child_data, 0xfffffffffffffff0); + rte_tel_data_add_array_hex_u64_str(child_data, 0xfffffffffffffff1); + rte_tel_data_add_array_hex_u64_str(child_data2, 0x8ffffffffffffff0); + + 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\":[\"0xfffffffffffffff0\",\"0xfffffffffffffff1\"],\"dict_1\":[\"0x8ffffffffffffff0\"]}"); +} + static int test_case_array_u32(void) { @@ -300,6 +383,47 @@ test_case_array_u64(void) return CHECK_OUTPUT("[0,1,2,3,4]"); } +static int +test_case_array_hex_u32_str(void) +{ + struct rte_tel_data *child_data = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data, RTE_TEL_STRING_VAL); + + struct rte_tel_data *child_data2 = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data2, RTE_TEL_STRING_VAL); + + rte_tel_data_start_array(&response_data, RTE_TEL_CONTAINER); + + rte_tel_data_add_array_hex_u32_str(child_data, 0xfffffff0); + rte_tel_data_add_array_hex_u32_str(child_data, 0xfffffff1); + rte_tel_data_add_array_hex_u32_str(child_data2, 0x8ffff2); + + 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("[[\"0xfffffff0\",\"0xfffffff1\"],[\"0x8ffff2\"]]"); +} + +static int +test_case_array_hex_u64_str(void) +{ + struct rte_tel_data *child_data = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data, RTE_TEL_STRING_VAL); + + struct rte_tel_data *child_data2 = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data2, RTE_TEL_STRING_VAL); + + rte_tel_data_start_array(&response_data, RTE_TEL_CONTAINER); + + rte_tel_data_add_array_hex_u64_str(child_data, 0xfffffffffffffff0); + rte_tel_data_add_array_hex_u64_str(child_data2, 0x8ffffffffff2); + + 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("[[\"0xfffffffffffffff0\"],[\"0x8ffffffffff2\"]]"); +} + static int test_case_add_dict_u32(void) { @@ -330,6 +454,38 @@ 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_case_add_dict_hex_u32_values(void) +{ + int i = 0; + char name_of_value[8]; + + rte_tel_data_start_dict(&response_data); + + for (i = 0; i < 3; i++) { + sprintf(name_of_value, "dict_%d", i); + rte_tel_data_add_dict_hex_u32_str(&response_data, name_of_value, + 0xfffffff0 + i); + } + return CHECK_OUTPUT("{\"dict_0\":\"0xfffffff0\",\"dict_1\":\"0xfffffff1\",\"dict_2\":\"0xfffffff2\"}"); +} + +static int +test_case_add_dict_hex_u64_values(void) +{ + int i = 0; + char name_of_value[8]; + + rte_tel_data_start_dict(&response_data); + + for (i = 0; i < 2; i++) { + sprintf(name_of_value, "dict_%d", i); + rte_tel_data_add_dict_hex_u64_str(&response_data, name_of_value, + 0xfffffffff0 + i); + } + return CHECK_OUTPUT("{\"dict_0\":\"0xfffffffff0\",\"dict_1\":\"0xfffffffff1\"}"); +} + static int test_dict_with_array_u32_values(void) { @@ -509,16 +665,24 @@ telemetry_data_autotest(void) test_case_add_dict_int, test_case_add_dict_u32, test_case_add_dict_u64, + test_case_array_hex_u32_str, + test_case_array_hex_u64_str, test_case_add_dict_string, + test_case_add_dict_hex_u32_values, + test_case_add_dict_hex_u64_values, 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_case_dict_with_array_hex_u32_values, + test_case_dict_with_array_hex_u64_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_case_array_with_array_hex_u32_values, + test_case_array_with_array_hex_u64_values, test_string_char_escaping, test_array_char_escaping, test_dict_char_escaping, -- 2.33.0