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 AC404A0C41; Tue, 3 Aug 2021 10:06:08 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D896C411AD; Tue, 3 Aug 2021 10:06:01 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 0D829411BE for ; Tue, 3 Aug 2021 10:05:59 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 173818EG013720; Tue, 3 Aug 2021 01:05:59 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=kMWbBNxH5HnOTeWycfDu8I2QFch0wA/xanrsUbMdyzc=; b=hAUP+Ew26GGO0ZGyyEtn9xZh4trzmNB7b1AGt7jR+mc10Nwg8SeCvTXw2+sOKILDgV4r 1VDreSEu8UkFIsktezeRXkYvDOsxh5Mw1Wtg5LVYG8L+Lat71mENSL4kQxU5bpm85sEb iVjydgqhSKJtcSOSUvl+FjlJ0wyTzF2LaEMU8WU85uve5XbzDgcy7vf9+kCuursbEWI4 koOk/D4pubIncvaAs/iwBni7hJ8NQC4IXuKmKoHa6B/M+aZamQuEXaUioRLsgnUCX7s1 7rmwkKTk3q19WWfsnxkZjMvmUj4Ev7a+TXcGMxwKAJF83/NtyTBQgioF7UyRj+6EG02I gA== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com with ESMTP id 3a6sfu9eb5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 03 Aug 2021 01:05:59 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 3 Aug 2021 01:05:57 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Tue, 3 Aug 2021 01:05:57 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id 01BD95B6944; Tue, 3 Aug 2021 01:05:54 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: , , , , , , , Gowrishankar Muthukrishnan Date: Tue, 3 Aug 2021 13:35:45 +0530 Message-ID: <6fc65455ac6cdbc1bdb4691a2c743d2889efde89.1627967359.git.gmuthukrishn@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: 7Swk94XQGLPs72vmyShUyryk728jKv3o X-Proofpoint-GUID: 7Swk94XQGLPs72vmyShUyryk728jKv3o X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-08-03_02:2021-08-03, 2021-08-03 signatures=0 Subject: [dpdk-dev] [v3, 2/3] test/telemetry: add unit tests for pointer value 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 Sender: "dev" Adding tests to evaluate pointer value in array and dict. Signed-off-by: Gowrishankar Muthukrishnan --- app/test/test_telemetry_data.c | 125 +++++++++++++++++++++++++++++++++ app/test/test_telemetry_json.c | 29 ++++++-- 2 files changed, 147 insertions(+), 7 deletions(-) diff --git a/app/test/test_telemetry_data.c b/app/test/test_telemetry_data.c index f34d691265..2351ae5193 100644 --- a/app/test/test_telemetry_data.c +++ b/app/test/test_telemetry_data.c @@ -301,6 +301,127 @@ test_array_with_array_u64_values(void) return TEST_OUTPUT("{\"/test\":[[0,1,2,3,4],[0,1,2,3,4]]}"); } +static int +test_case_array_ptr(void) +{ + int *p, i, j, a[] = {1, 2, 3, 4, 5}; + char exp[120]; + + memset(&response_data, 0, sizeof(response_data)); + memset(exp, 0, sizeof(exp)); + rte_tel_data_start_array(&response_data, RTE_TEL_PTR_VAL); + + i = sprintf(exp, "{\"/test\":["); + for (j = 0; j < 5; j++) { + p = &a[j]; + i += sprintf(exp + i, "%" PRIuPTR ",", (uintptr_t)p); + rte_tel_data_add_array_ptr(&response_data, p); + } + + sprintf(exp + i - 1, "]}"); + return TEST_OUTPUT(exp); +} + +static int +test_case_add_dict_ptr(void) +{ + int *p, i, j, a[] = {1, 2, 3, 4, 5}; + char name[8], exp[160]; + + memset(&response_data, 0, sizeof(response_data)); + memset(exp, 0, sizeof(exp)); + rte_tel_data_start_dict(&response_data); + + i = sprintf(exp, "{\"/test\":{"); + for (j = 0; j < 5; j++) { + p = &a[j]; + sprintf(name, "dict_%d", j); + i += sprintf(exp + i, "\"%s\":%" PRIuPTR ",", name, + (uintptr_t)p); + rte_tel_data_add_dict_ptr(&response_data, name, p); + } + + sprintf(exp + i - 1, "}}"); + return TEST_OUTPUT(exp); +} + +static int +test_dict_with_array_ptr_values(void) +{ + int *p, i, j, a[] = {1, 2, 3, 4, 5}; + char exp[256]; + + struct rte_tel_data *child_data = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data, RTE_TEL_PTR_VAL); + + struct rte_tel_data *child_data2 = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data2, RTE_TEL_PTR_VAL); + + memset(&response_data, 0, sizeof(response_data)); + memset(exp, 0, sizeof(exp)); + rte_tel_data_start_dict(&response_data); + + i = sprintf(exp, "{\"/test\":{\"dict_0\":["); + for (j = 0; j < 5; j++) { + p = &a[j]; + i += sprintf(exp + i, "%" PRIuPTR ",", (uintptr_t)p); + rte_tel_data_add_array_ptr(child_data, p); + } + + i += sprintf(exp + i - 1, "],\"dict_1\":["); + for (j = 5; j > 0; j--) { + p = &a[j - 1]; + i += sprintf(exp + i - 1, "%" PRIuPTR ",", (uintptr_t)p); + rte_tel_data_add_array_ptr(child_data2, p); + } + + sprintf(exp + i - 2, "]}}"); + 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 TEST_OUTPUT(exp); +} + +static int +test_array_with_array_ptr_values(void) +{ + int *p, i, j, a[] = {1, 2, 3, 4, 5}; + char exp[256]; + + struct rte_tel_data *child_data = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data, RTE_TEL_PTR_VAL); + + struct rte_tel_data *child_data2 = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data2, RTE_TEL_PTR_VAL); + + memset(&response_data, 0, sizeof(response_data)); + memset(exp, 0, sizeof(exp)); + rte_tel_data_start_array(&response_data, RTE_TEL_CONTAINER); + + i = sprintf(exp, "{\"/test\":[["); + for (j = 0; j < 5; j++) { + p = &a[j]; + i += sprintf(exp + i, "%" PRIuPTR ",", (uintptr_t)p); + rte_tel_data_add_array_ptr(child_data, p); + } + + i += sprintf(exp + i - 1, "],["); + for (j = 5; j > 0; j--) { + p = &a[j - 1]; + i += sprintf(exp + i - 1, "%" PRIuPTR ",", (uintptr_t)p); + rte_tel_data_add_array_ptr(child_data2, p); + } + + sprintf(exp + i - 2, "]]}"); + + rte_tel_data_add_array_container(&response_data, child_data, 0); + rte_tel_data_add_array_container(&response_data, child_data2, 0); + + return TEST_OUTPUT(exp); +} + static int connect_to_socket(void) { @@ -350,13 +471,17 @@ test_telemetry_data(void) test_case test_cases[] = {test_case_array_string, test_case_array_int, test_case_array_u64, + test_case_array_ptr, test_case_add_dict_int, test_case_add_dict_u64, + test_case_add_dict_ptr, test_case_add_dict_string, test_dict_with_array_int_values, test_dict_with_array_u64_values, + test_dict_with_array_ptr_values, test_dict_with_array_string_values, test_array_with_array_int_values, test_array_with_array_u64_values, + test_array_with_array_ptr_values, test_array_with_array_string_values }; rte_telemetry_register_cmd(REQUEST_CMD, test_cb, "Test"); diff --git a/app/test/test_telemetry_json.c b/app/test/test_telemetry_json.c index 790181d316..68dc81c9cd 100644 --- a/app/test/test_telemetry_json.c +++ b/app/test/test_telemetry_json.c @@ -11,18 +11,23 @@ static int test_basic_array(void) { - const char *expected = "[\"meaning of life\",42]"; - char buf[1024]; - int used = 0; + char buf[1024], expected[80]; + int used = 0, n = 42, *p; printf("%s: ", __func__); used = rte_tel_json_empty_array(buf, sizeof(buf), used); if (used != 2 || strcmp(buf, "[]")) return -1; + p = &n; + memset(expected, 0, sizeof(expected)); + sprintf(expected, "[\"meaning of life\",42,%" PRIuPTR "]", + (uintptr_t)p); + used = rte_tel_json_add_array_string(buf, sizeof(buf), used, "meaning of life"); - used = rte_tel_json_add_array_int(buf, sizeof(buf), used, 42); + used = rte_tel_json_add_array_int(buf, sizeof(buf), used, n); + used = rte_tel_json_add_array_ptr(buf, sizeof(buf), used, p); printf("buf = '%s', expected = '%s'\n", buf, expected); if (used != (int)strlen(expected)) @@ -33,14 +38,24 @@ test_basic_array(void) static int test_basic_obj(void) { - const char *expected = "{\"weddings\":4,\"funerals\":1}"; - char buf[1024]; - int used = 0; + char buf[1024], expected[80]; + int used = 0, n = 42, *p; + + p = &n; + memset(expected, 0, sizeof(expected)); + sprintf(expected, + "{\"weddings\":4,\"funerals\":1," + "\"address\":%" PRIuPTR ",\"reset\":0}", (uintptr_t)p); used = rte_tel_json_add_obj_u64(buf, sizeof(buf), used, "weddings", 4); used = rte_tel_json_add_obj_u64(buf, sizeof(buf), used, "funerals", 1); + used = rte_tel_json_add_obj_ptr(buf, sizeof(buf), used, + "address", p); + p = NULL; + used = rte_tel_json_add_obj_ptr(buf, sizeof(buf), used, + "reset", p); printf("%s: buf = '%s', expected = '%s'\n", __func__, buf, expected); if (used != (int)strlen(expected)) -- 2.25.1