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 C4BFCA00C4; Mon, 25 Jul 2022 18:37:03 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C1F7C42B8D; Mon, 25 Jul 2022 18:36:34 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id 11F5342B89 for ; Mon, 25 Jul 2022 18:36:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658766993; x=1690302993; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ulk7dfNr+IpskgW6mtTN0ffCvjyImwIkl400BPLel7g=; b=P/Y4lDzFLP0oO2uvqTgqsBy8YF3vbkJ9LiCZXkEnxAzO9zb6iliT019B uYVappPqpAr+Y9Ug8i+QMki7OLZvbdYsU9/XivJ8u/HE4NvfLJBWKUxAT 3/MJstcsNxx2RACm6XmBQmsI6NY81K8cFqAJY6Rk438hfZE/hEs43JMH+ Y32WqIOlkKpvYa7mOxIe7deSY9R/ktuBB3KHLnKeDQkPAwyKLWUPjmUjp DQHG+wc5oZOURm+ZDP4nyRo7tVzBHP5YXBMMjdjE/zWeg6p1A6/VSuuRg F4fbSHh6G8PZjyl7O/rpWaeS7n/+Gy1vKIHZE/hfPuy9xUws86R/k1fhC A==; X-IronPort-AV: E=McAfee;i="6400,9594,10419"; a="288499134" X-IronPort-AV: E=Sophos;i="5.93,193,1654585200"; d="scan'208";a="288499134" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2022 09:36:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,193,1654585200"; d="scan'208";a="575122755" Received: from silpixa00401385.ir.intel.com (HELO silpixa00401385.ger.corp.intel.com.) ([10.237.223.47]) by orsmga006.jf.intel.com with ESMTP; 25 Jul 2022 09:36:31 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson , Ciara Power Subject: [PATCH v2 11/13] test/telemetry_data: add test cases for character escaping Date: Mon, 25 Jul 2022 17:35:40 +0100 Message-Id: <20220725163543.875775-12-bruce.richardson@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220725163543.875775-1-bruce.richardson@intel.com> References: <20220623164245.561371-1-bruce.richardson@intel.com> <20220725163543.875775-1-bruce.richardson@intel.com> MIME-Version: 1.0 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 --- 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 5a85e790d3..cfa4d636f0 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