DPDK patches and discussions
 help / color / mirror / Atom feed
From: Huisong Li <lihuisong@huawei.com>
To: <dev@dpdk.org>
Cc: <ciara.power@intel.com>, <liudongdong3@huawei.com>,
	<huangdaode@huawei.com>, <fengchengwen@huawei.com>,
	<lihuisong@huawei.com>
Subject: [PATCH 3/8] test: add test cases for u32 telemetry data API
Date: Thu, 8 Dec 2022 16:05:35 +0800	[thread overview]
Message-ID: <20221208080540.62913-4-lihuisong@huawei.com> (raw)
In-Reply-To: <20221208080540.62913-1-lihuisong@huawei.com>

Add test cases for u32 telemetry data API.

Cc: stable@dpdk.org

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 app/test/test_telemetry_data.c | 86 +++++++++++++++++++++++++++++++++-
 app/test/test_telemetry_json.c | 23 ++++++++-
 2 files changed, 105 insertions(+), 4 deletions(-)

diff --git a/app/test/test_telemetry_data.c b/app/test/test_telemetry_data.c
index d92667a527..6c500f2e34 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,30 @@ 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 +504,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


  parent reply	other threads:[~2022-12-08  8:06 UTC|newest]

Thread overview: 122+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-08  8:05 [PATCH 0/8] fix possible data truncation and conversion error Huisong Li
2022-12-08  8:05 ` [PATCH 1/8] telemetry: move to header to controllable range Huisong Li
2022-12-08  8:05 ` [PATCH 2/8] telemetry: add u32 telemetry data type API Huisong Li
2022-12-08  8:05 ` Huisong Li [this message]
2022-12-08  8:05 ` [PATCH 4/8] ethdev: fix possible data truncation and conversion error Huisong Li
2022-12-08  8:05 ` [PATCH 5/8] mempool: " Huisong Li
2022-12-08  8:05 ` [PATCH 6/8] cryptodev: fix possible data " Huisong Li
2022-12-08  8:05 ` [PATCH 7/8] mem: possible data truncation and " Huisong Li
2022-12-08  8:05 ` [PATCH 8/8] ethdev: telemetry convert capability related variable to hex Huisong Li
2022-12-08 10:55   ` Morten Brørup
2022-12-08 11:20     ` Bruce Richardson
2022-12-09  3:07       ` lihuisong (C)
2022-12-09 11:04 ` [PATCH V2 00/11] telemetry: add u32 value type and hex integer string API Huisong Li
2022-12-09 11:04   ` [PATCH V2 01/11] telemetry: move to header to controllable range Huisong Li
2022-12-09 11:04   ` [PATCH V2 02/11] telemetry: add u32 value type Huisong Li
2022-12-09 11:04   ` [PATCH V2 03/11] test: add test cases for adding u32 value API Huisong Li
2022-12-09 11:04   ` [PATCH V2 04/11] ethdev: fix possible data truncation and conversion error Huisong Li
2022-12-09 11:04   ` [PATCH V2 05/11] mempool: " Huisong Li
2022-12-09 11:04   ` [PATCH V2 06/11] cryptodev: fix possible data " Huisong Li
2022-12-09 11:04   ` [PATCH V2 07/11] mem: possible data truncation and " Huisong Li
2022-12-09 11:04   ` [PATCH V2 08/11] telemetry: refactor mapping betwween value and array type Huisong Li
2022-12-09 11:04   ` [PATCH V2 09/11] telemetry: support adding integer value as hexadecimal Huisong Li
2022-12-09 11:04   ` [PATCH V2 10/11] test: add test cases for adding hex integer values API Huisong Li
2022-12-09 11:04   ` [PATCH V2 11/11] ethdev: display capability values in hexadecimal format Huisong Li
2022-12-09 18:24   ` [PATCH V2 00/11] telemetry: add u32 value type and hex integer string API Morten Brørup
2022-12-12  6:23     ` lihuisong (C)
2022-12-11  9:02   ` fengchengwen
2022-12-12  6:42 ` [PATCH V3 " Huisong Li
2022-12-12  6:42   ` [PATCH V3 01/11] telemetry: move to header to controllable range Huisong Li
2022-12-12  6:42   ` [PATCH V3 02/11] telemetry: add u32 value type Huisong Li
2022-12-12  6:42   ` [PATCH V3 03/11] test: add test cases for adding u32 value API Huisong Li
2022-12-12  6:42   ` [PATCH V3 04/11] ethdev: fix possible data truncation and conversion error Huisong Li
2022-12-12  6:43   ` [PATCH V3 05/11] mempool: " Huisong Li
2022-12-12  6:43   ` [PATCH V3 06/11] cryptodev: fix possible data " Huisong Li
2022-12-12  6:43   ` [PATCH V3 07/11] mem: possible data truncation and " Huisong Li
2022-12-12  6:43   ` [PATCH V3 08/11] telemetry: refactor mapping betwween value and array type Huisong Li
2022-12-12  6:43   ` [PATCH V3 09/11] telemetry: support adding integer value as hexadecimal Huisong Li
2022-12-12  6:43   ` [PATCH V3 10/11] test: add test cases for adding hex integer values API Huisong Li
2022-12-12  6:43   ` [PATCH V3 11/11] ethdev: display capability values in hexadecimal format Huisong Li
2022-12-12 10:31   ` [PATCH V3 00/11] telemetry: add u32 value type and hex integer string API Bruce Richardson
2022-12-12 11:02     ` Morten Brørup
2022-12-12 11:20       ` Bruce Richardson
2022-12-12 12:03         ` Morten Brørup
2022-12-12 12:16           ` Bruce Richardson
2022-12-13 11:00             ` Morten Brørup
2022-12-13 17:12             ` Bruce Richardson
2022-12-13  3:02           ` lihuisong (C)
2022-12-13 10:15 ` [PATCH V4 0/9] telemetry: fix data truncation and conversion error and add hex integer API Huisong Li
2022-12-13 10:15   ` [PATCH V4 1/9] telemetry: move to header to controllable range Huisong Li
2022-12-13 17:10     ` Bruce Richardson
2022-12-14  2:44       ` lihuisong (C)
2022-12-13 10:15   ` [PATCH V4 2/9] ethdev: fix possible data truncation and conversion error Huisong Li
2022-12-13 10:15   ` [PATCH V4 3/9] mempool: " Huisong Li
2022-12-13 10:15   ` [PATCH V4 4/9] cryptodev: fix possible data " Huisong Li
2022-12-13 10:15   ` [PATCH V4 5/9] mem: possible data truncation and " Huisong Li
2022-12-13 10:15   ` [PATCH V4 6/9] telemetry: refactor mapping between value and array type Huisong Li
2022-12-13 16:57     ` Bruce Richardson
2022-12-14  2:46       ` lihuisong (C)
2022-12-13 10:15   ` [PATCH V4 7/9] telemetry: support adding integer value as hexadecimal Huisong Li
2022-12-13 17:09     ` Bruce Richardson
2022-12-14  2:44       ` lihuisong (C)
2022-12-14  7:28         ` Morten Brørup
2022-12-14 12:17           ` lihuisong (C)
2022-12-13 10:15   ` [PATCH V4 8/9] test: add test cases for adding hex integer value API Huisong Li
2022-12-13 10:15   ` [PATCH V4 9/9] ethdev: display capability values in hexadecimal format Huisong Li
2022-12-14 12:32 ` [PATCH V5 0/8] telemetry: fix data truncation and conversion error and add hex integer API Huisong Li
2022-12-14 12:32   ` [PATCH V5 1/8] telemetry: move to header to controllable range Huisong Li
2022-12-14 12:32   ` [PATCH V5 2/8] ethdev: fix possible data truncation and conversion error Huisong Li
2022-12-14 12:32   ` [PATCH V5 3/8] mempool: " Huisong Li
2022-12-14 12:32   ` [PATCH V5 4/8] cryptodev: fix possible data " Huisong Li
2022-12-14 12:32   ` [PATCH V5 5/8] mem: possible data truncation and " Huisong Li
2022-12-14 13:00     ` Morten Brørup
2022-12-15  1:11       ` lihuisong (C)
2022-12-15  7:04         ` Morten Brørup
2022-12-15  7:56           ` lihuisong (C)
2022-12-14 12:32   ` [PATCH V5 6/8] telemetry: support adding integer value as hexadecimal Huisong Li
2022-12-14 15:38     ` Bruce Richardson
2022-12-15  1:32       ` lihuisong (C)
2022-12-14 12:32   ` [PATCH V5 7/8] test: add test cases for adding hex integer value API Huisong Li
2022-12-14 12:32   ` [PATCH V5 8/8] ethdev: display capability values in hexadecimal format Huisong Li
2022-12-15 10:31 ` [PATCH V6 0/8] telemetry: fix data truncation and conversion error and add hex integer API Huisong Li
2022-12-15 10:31   ` [PATCH V6 1/8] telemetry: move to header to controllable range Huisong Li
2022-12-15 10:31   ` [PATCH V6 2/8] ethdev: fix possible data truncation and conversion error Huisong Li
2022-12-15 10:31   ` [PATCH V6 3/8] mempool: " Huisong Li
2022-12-15 10:31   ` [PATCH V6 4/8] cryptodev: fix possible data " Huisong Li
2022-12-15 10:31   ` [PATCH V6 5/8] mem: possible data truncation and " Huisong Li
2022-12-15 10:31   ` [PATCH V6 6/8] telemetry: support adding integer value as hexadecimal Huisong Li
2022-12-15 10:46     ` Bruce Richardson
2022-12-15 11:27       ` lihuisong (C)
2022-12-15 12:00         ` Morten Brørup
2022-12-15 12:15           ` Bruce Richardson
2022-12-15 12:24             ` Morten Brørup
2022-12-15 12:45               ` lihuisong (C)
2022-12-15 12:52                 ` Morten Brørup
2022-12-15 13:08                   ` Bruce Richardson
2022-12-16  1:15                     ` lihuisong (C)
2022-12-15 10:31   ` [PATCH V6 7/8] test: add test cases for adding hex integer value API Huisong Li
2022-12-15 10:31   ` [PATCH V6 8/8] ethdev: display capability values in hexadecimal format Huisong Li
2022-12-16  1:54 ` [PATCH V7 0/8] telemetry: fix data truncation and conversion error and add hex integer API Huisong Li
2022-12-16  1:54   ` [PATCH V7 1/8] telemetry: move to header to controllable range Huisong Li
2022-12-16  1:54   ` [PATCH V7 2/8] ethdev: fix possible data truncation and conversion error Huisong Li
2022-12-16  1:54   ` [PATCH V7 3/8] mempool: " Huisong Li
2022-12-16  1:54   ` [PATCH V7 4/8] cryptodev: fix possible data " Huisong Li
2022-12-16  1:54   ` [PATCH V7 5/8] mem: possible data truncation and " Huisong Li
2022-12-16  1:54   ` [PATCH V7 6/8] telemetry: support adding integer value as hexadecimal Huisong Li
2022-12-16  1:54   ` [PATCH V7 7/8] test: add test cases for adding hex integer value API Huisong Li
2022-12-16  9:31     ` Bruce Richardson
2022-12-19  7:04       ` lihuisong (C)
2022-12-16  1:54   ` [PATCH V7 8/8] ethdev: display capability values in hexadecimal format Huisong Li
2022-12-19  7:06 ` [PATCH V8 0/8] telemetry: fix data truncation and conversion error and add hex integer API Huisong Li
2022-12-19  7:06   ` [PATCH V8 1/8] telemetry: move to header to controllable range Huisong Li
2022-12-19  7:06   ` [PATCH V8 2/8] ethdev: fix possible data truncation and conversion error Huisong Li
2022-12-19  7:06   ` [PATCH V8 3/8] mempool: " Huisong Li
2022-12-19  7:06   ` [PATCH V8 4/8] cryptodev: fix possible data " Huisong Li
2022-12-19  7:06   ` [PATCH V8 5/8] mem: possible data truncation and " Huisong Li
2022-12-19  7:06   ` [PATCH V8 6/8] telemetry: support adding integer value as hexadecimal Huisong Li
2022-12-19  9:19     ` Bruce Richardson
2022-12-19  7:06   ` [PATCH V8 7/8] test: add test cases for adding hex integer value API Huisong Li
2022-12-19  7:06   ` [PATCH V8 8/8] ethdev: display capability values in hexadecimal format Huisong Li
2023-01-16 12:06   ` [PATCH V8 0/8] telemetry: fix data truncation and conversion error and add hex integer API lihuisong (C)
2023-01-30 10:39     ` lihuisong (C)
2023-02-05 20:43   ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221208080540.62913-4-lihuisong@huawei.com \
    --to=lihuisong@huawei.com \
    --cc=ciara.power@intel.com \
    --cc=dev@dpdk.org \
    --cc=fengchengwen@huawei.com \
    --cc=huangdaode@huawei.com \
    --cc=liudongdong3@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).