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 8D058A0540; Tue, 13 Dec 2022 11:16:04 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0B6ED42D41; Tue, 13 Dec 2022 11:15:25 +0100 (CET) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id AC59340A89 for ; Tue, 13 Dec 2022 11:15:17 +0100 (CET) Received: from kwepemm600004.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4NWZ5y38qtzJpH0; Tue, 13 Dec 2022 18:11:34 +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.34; Tue, 13 Dec 2022 18:15:11 +0800 From: Huisong Li To: CC: , , , , , , Subject: [PATCH V4 8/9] test: add test cases for adding hex integer value API Date: Tue, 13 Dec 2022 18:15:11 +0800 Message-ID: <20221213101512.39919-9-lihuisong@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20221213101512.39919-1-lihuisong@huawei.com> References: <20221208080540.62913-1-lihuisong@huawei.com> <20221213101512.39919-1-lihuisong@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) 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 unsigned integer value API. Signed-off-by: Huisong Li Acked-by: Morten Brørup Acked-by: Chengwen Feng --- app/test/test_telemetry_data.c | 158 +++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) diff --git a/app/test/test_telemetry_data.c b/app/test/test_telemetry_data.c index d92667a527..1fd79d66e2 100644 --- a/app/test/test_telemetry_data.c +++ b/app/test/test_telemetry_data.c @@ -209,6 +209,39 @@ test_case_add_dict_string(void) return CHECK_OUTPUT("{\"dict_0\":\"aaaa\",\"dict_1\":\"bbbb\",\"dict_2\":\"cccc\",\"dict_3\":\"dddd\"}"); } +static int +test_case_add_dict_uint_hex_padding(void) +{ + rte_tel_data_start_dict(&response_data); + + rte_tel_data_add_dict_uint_hex(&response_data, "dict_0", + (uint8_t)0x8, RTE_TEL_U8_BITS); + rte_tel_data_add_dict_uint_hex(&response_data, "dict_1", + (uint16_t)0x88, RTE_TEL_U16_BITS); + rte_tel_data_add_dict_uint_hex(&response_data, "dict_2", + (uint32_t)0x888, RTE_TEL_U32_BITS); + rte_tel_data_add_dict_uint_hex(&response_data, "dict_3", + (uint64_t)0x8888, RTE_TEL_U64_BITS); + + return CHECK_OUTPUT("{\"dict_0\":\"0x08\",\"dict_1\":\"0x0088\",\"dict_2\":\"0x00000888\",\"dict_3\":\"0x0000000000008888\"}"); +} + +static int +test_case_add_dict_uint_hex_nopadding(void) +{ + rte_tel_data_start_dict(&response_data); + + rte_tel_data_add_dict_uint_hex(&response_data, "dict_0", + (uint8_t)0x8, 0); + rte_tel_data_add_dict_uint_hex(&response_data, "dict_1", + (uint16_t)0x88, 0); + rte_tel_data_add_dict_uint_hex(&response_data, "dict_2", + (uint32_t)0x888, 0); + rte_tel_data_add_dict_uint_hex(&response_data, "dict_3", + (uint64_t)0x8888, 0); + + return CHECK_OUTPUT("{\"dict_0\":\"0x8\",\"dict_1\":\"0x88\",\"dict_2\":\"0x888\",\"dict_3\":\"0x8888\"}"); +} static int test_dict_with_array_string_values(void) @@ -232,6 +265,52 @@ test_dict_with_array_string_values(void) return CHECK_OUTPUT("{\"dict_0\":[\"aaaa\"],\"dict_1\":[\"bbbb\"]}"); } +static int +test_dict_with_array_uint_hex_values_padding(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_uint_hex(child_data, + (uint32_t)0x888, RTE_TEL_U32_BITS); + rte_tel_data_add_array_uint_hex(child_data2, + (uint64_t)0x8888, RTE_TEL_U64_BITS); + + 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\":[\"0x00000888\"],\"dict_1\":[\"0x0000000000008888\"]}"); +} + +static int +test_dict_with_array_uint_hex_values_nopadding(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_uint_hex(child_data, (uint32_t)0x888, 0); + rte_tel_data_add_array_uint_hex(child_data2, (uint64_t)0x8888, 0); + + 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\":[\"0x888\"],\"dict_1\":[\"0x8888\"]}"); +} + static int test_dict_with_dict_values(void) { @@ -278,6 +357,49 @@ test_array_with_array_string_values(void) return CHECK_OUTPUT("[[\"aaaa\"],[\"bbbb\"]]"); } +static int +test_array_with_array_uint_hex_values_padding(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_uint_hex(child_data, (uint32_t)0x888, + RTE_TEL_U32_BITS); + rte_tel_data_add_array_uint_hex(child_data2, (uint64_t)0x8888, + RTE_TEL_U64_BITS); + + 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("[[\"0x00000888\"],[\"0x0000000000008888\"]]"); +} + + +static int +test_array_with_array_uint_hex_values_nopadding(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_uint_hex(child_data, (uint32_t)0x888, 0); + rte_tel_data_add_array_uint_hex(child_data2, (uint64_t)0x8888, 0); + + 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("[[\"0x888\"],[\"0x8888\"]]"); +} + static int test_case_array_u64(void) { @@ -289,6 +411,34 @@ test_case_array_u64(void) return CHECK_OUTPUT("[0,1,2,3,4]"); } +static int +test_case_array_uint_hex_padding(void) +{ + rte_tel_data_start_array(&response_data, RTE_TEL_STRING_VAL); + rte_tel_data_add_array_uint_hex(&response_data, (uint8_t)0x8, + RTE_TEL_U8_BITS); + rte_tel_data_add_array_uint_hex(&response_data, (uint16_t)0x88, + RTE_TEL_U16_BITS); + rte_tel_data_add_array_uint_hex(&response_data, (uint32_t)0x888, + RTE_TEL_U32_BITS); + rte_tel_data_add_array_uint_hex(&response_data, (uint64_t)0x8888, + RTE_TEL_U64_BITS); + + return CHECK_OUTPUT("[\"0x08\",\"0x0088\",\"0x00000888\",\"0x0000000000008888\"]"); +} + +static int +test_case_array_uint_hex_nopadding(void) +{ + rte_tel_data_start_array(&response_data, RTE_TEL_STRING_VAL); + rte_tel_data_add_array_uint_hex(&response_data, (uint8_t)0x8, 0); + rte_tel_data_add_array_uint_hex(&response_data, (uint16_t)0x88, 0); + rte_tel_data_add_array_uint_hex(&response_data, (uint32_t)0x888, 0); + rte_tel_data_add_array_uint_hex(&response_data, (uint64_t)0x8888, 0); + + return CHECK_OUTPUT("[\"0x8\",\"0x88\",\"0x888\",\"0x8888\"]"); +} + static int test_case_add_dict_u64(void) { @@ -429,15 +579,23 @@ telemetry_data_autotest(void) test_simple_string, test_case_array_string, test_case_array_int, test_case_array_u64, + test_case_array_uint_hex_padding, + test_case_array_uint_hex_nopadding, test_case_add_dict_int, test_case_add_dict_u64, test_case_add_dict_string, + test_case_add_dict_uint_hex_padding, + test_case_add_dict_uint_hex_nopadding, test_dict_with_array_int_values, test_dict_with_array_u64_values, test_dict_with_array_string_values, + test_dict_with_array_uint_hex_values_padding, + test_dict_with_array_uint_hex_values_nopadding, test_dict_with_dict_values, test_array_with_array_int_values, test_array_with_array_u64_values, test_array_with_array_string_values, + test_array_with_array_uint_hex_values_padding, + test_array_with_array_uint_hex_values_nopadding, test_string_char_escaping, test_array_char_escaping, test_dict_char_escaping, -- 2.33.0