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 1EF7CA0540; Fri, 9 Sep 2022 11:36:52 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AC49142B96; Fri, 9 Sep 2022 11:35:57 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id 39B7B42B7B for ; Fri, 9 Sep 2022 11:35:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662716154; x=1694252154; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=g8UYN3JsOkvVvTeql4xctvdj+f5sfV8/ScRpaKgBzyo=; b=elj0V58k19NAvtC+1j7Qp9Uu/7IPFlhu95naOYXdAhroYldqEnIZuHuo 90ZMV85kx9uQxBo7LjgKa3mPuBcA6aNSY2bJtGKugnQTtIMLPM2fxE3eJ jCDbyPgzYFM6prsTbKx46WUkRBOs9e2z16qybZPq5S/OTnP5GLJYGqccP PUXBkpMwltssh0U58H+0TP2CeGOuDzvOZc4ZklgYzBCx3ZSkzKUFzK5la qXRIhzQsJd7xoV3yu9AuYmHywr/b9lg6Prq+Op0ckLNiNBiDqXiNH+7Oo xsd4r9cFIPj79lCezF/qZGMnMUGkz4XvI7T53mD3JPv0GWhkq7QmDO78h w==; X-IronPort-AV: E=McAfee;i="6500,9779,10464"; a="297437149" X-IronPort-AV: E=Sophos;i="5.93,302,1654585200"; d="scan'208";a="297437149" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Sep 2022 02:35:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,302,1654585200"; d="scan'208";a="740996445" Received: from silpixa00401385.ir.intel.com ([10.237.214.161]) by orsmga004.jf.intel.com with ESMTP; 09 Sep 2022 02:35:51 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson , Ciara Power , =?UTF-8?q?Morten=20Br=C3=B8rup?= Subject: [PATCH v3 11/13] test/telemetry_data: add test cases for character escaping Date: Fri, 9 Sep 2022 10:35:21 +0100 Message-Id: <20220909093523.471727-12-bruce.richardson@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220909093523.471727-1-bruce.richardson@intel.com> References: <20220623164245.561371-1-bruce.richardson@intel.com> <20220909093523.471727-1-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 in some basic unit tests to validate the character escaping being done on string data values, which tests end-to-end processing of those values beyond just the json-encoding steps tested by the "telemetry_json_autotest". Signed-off-by: Bruce Richardson Acked-by: Ciara Power Acked-by: Morten Brørup --- app/test/test_telemetry_data.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/app/test/test_telemetry_data.c b/app/test/test_telemetry_data.c index 9d174dc99f..69ca8b6c6f 100644 --- a/app/test/test_telemetry_data.c +++ b/app/test/test_telemetry_data.c @@ -347,6 +347,30 @@ test_array_with_array_u64_values(void) return CHECK_OUTPUT("[[0,1,2,3,4],[0,1,2,3,4]]"); } +static int +test_string_char_escaping(void) +{ + rte_tel_data_string(&response_data, "hello,\nworld\n"); + return CHECK_OUTPUT("\"hello,\\nworld\\n\""); +} + +static int +test_array_char_escaping(void) +{ + rte_tel_data_start_array(&response_data, RTE_TEL_STRING_VAL); + rte_tel_data_add_array_string(&response_data, "\\escape\r"); + rte_tel_data_add_array_string(&response_data, "characters\n"); + return CHECK_OUTPUT("[\"\\\\escape\\r\",\"characters\\n\"]"); +} + +static int +test_dict_char_escaping(void) +{ + rte_tel_data_start_dict(&response_data); + rte_tel_data_add_dict_string(&response_data, "name", "escaped\n\tvalue"); + return CHECK_OUTPUT("{\"name\":\"escaped\\n\\tvalue\"}"); +} + static int connect_to_socket(void) { @@ -406,7 +430,11 @@ telemetry_data_autotest(void) 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_string_values, + test_string_char_escaping, + test_array_char_escaping, + test_dict_char_escaping, + }; rte_telemetry_register_cmd(REQUEST_CMD, telemetry_test_cb, "Test"); for (i = 0; i < RTE_DIM(test_cases); i++) { -- 2.34.1