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 55093A00C5; Mon, 19 Dec 2022 08:07:24 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4711D42D2D; Mon, 19 Dec 2022 08:06:59 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id D473940695 for ; Mon, 19 Dec 2022 08:06:51 +0100 (CET) Received: from kwepemm600004.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Nb9hk42lszRq73; Mon, 19 Dec 2022 15:05:42 +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; Mon, 19 Dec 2022 15:06:50 +0800 From: Huisong Li To: CC: , , , , , , Subject: [PATCH V8 7/8] test: add test cases for adding hex integer value API Date: Mon, 19 Dec 2022 15:06:47 +0800 Message-ID: <20221219070648.33817-8-lihuisong@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20221219070648.33817-1-lihuisong@huawei.com> References: <20221208080540.62913-1-lihuisong@huawei.com> <20221219070648.33817-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: dggems704-chm.china.huawei.com (10.3.19.181) 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 Acked-by: Bruce Richardson --- app/test/test_telemetry_data.c | 150 +++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) diff --git a/app/test/test_telemetry_data.c b/app/test/test_telemetry_data.c index d92667a527..5b6c801599 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, 8); + rte_tel_data_add_dict_uint_hex(&response_data, "dict_1", + (uint16_t)0x88, 16); + rte_tel_data_add_dict_uint_hex(&response_data, "dict_2", + (uint32_t)0x888, 32); + rte_tel_data_add_dict_uint_hex(&response_data, "dict_3", + (uint64_t)0x8888, 64); + + 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,50 @@ 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, 32); + rte_tel_data_add_array_uint_hex(child_data2, (uint64_t)0x8888, 64); + + 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 +355,47 @@ 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, 32); + rte_tel_data_add_array_uint_hex(child_data2, (uint64_t)0x8888, 64); + + 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 +407,30 @@ 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, 8); + rte_tel_data_add_array_uint_hex(&response_data, (uint16_t)0x88, 16); + rte_tel_data_add_array_uint_hex(&response_data, (uint32_t)0x888, 32); + rte_tel_data_add_array_uint_hex(&response_data, (uint64_t)0x8888, 64); + + 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 +571,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