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 6EBE2A0555; Wed, 25 May 2022 19:14:32 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1F8E1427F7; Wed, 25 May 2022 19:14:27 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 945734280C for ; Wed, 25 May 2022 19:14:25 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24P9xtN7028700; Wed, 25 May 2022 10:14:24 -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=YYeNz8+kV7SrMWkKrNoxAo9NisC1xmktOF1BbrHEOng=; b=Wm/U/cWeRvX9HaSzTM8jMA9Xhz5vTrYEKsEah2MaclJHE29iRGANW95s6tTGAYB0nh9z 5ZKgk9q+UvF0hBZptlWEVSmqgdjgCp3AXoecCV2qDjuicM0/lWKg9yLAueNFakNm76NK fT6ehx0QMkeiT1+47SC4RvPky1Zq92bYFhLIkDEJn+llMM3EmGcIKi9g4BsR+ufeJVlG FCmTNkvGqwVLd5bkSQAPoZMKB2Ofck0GUwlmPBfeNlbhJhjBKTEy66rZfLFx3tkeXuHg G/fh6N6pjE4ojwtxGc+OGDtQh/VM91IYqV7w45pg4dq7x0tXSD1fKohD6dDyl9HAtWe7 8w== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3g9jap1qwj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 25 May 2022 10:14:24 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 25 May 2022 10:14:21 -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.2 via Frontend Transport; Wed, 25 May 2022 10:14:21 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id 607353F7075; Wed, 25 May 2022 10:14:20 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: Fan Zhang , Brian Dooley , , Anoob Joseph , Archana Muniganti , Jerin Jacob , Brandon Lo Subject: [v6, 03/11] examples/fips_validation: add json parsing Date: Wed, 25 May 2022 22:43:39 +0530 Message-ID: <122eb87a0034dea2875d8d752812d76a89e6fcd5.1653498667.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-GUID: OExWHnx_m-jul8HF6w7Nc6bl3d9Wwv1o X-Proofpoint-ORIG-GUID: OExWHnx_m-jul8HF6w7Nc6bl3d9Wwv1o X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-25_04,2022-05-25_02,2022-02-23_01 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 From: Brandon Lo Added functions to parse the required information from a vector set given in the new json format. Signed-off-by: Brandon Lo --- v3: * fix checkpatch warnings v2: * fix for loop initialization --- examples/fips_validation/fips_validation.c | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c index 38c99b291c..6594a15579 100644 --- a/examples/fips_validation/fips_validation.c +++ b/examples/fips_validation/fips_validation.c @@ -276,6 +276,8 @@ parse_file_type(const char *path) info.file_type = FIPS_TYPE_RSP; else if (strstr(path, FAX_FILE_PREFIX)) info.file_type = FIPS_TYPE_FAX; + else if (strstr(path, JSON_FILE_PREFIX)) + info.file_type = FIPS_TYPE_JSON; else return -EINVAL; @@ -311,6 +313,21 @@ fips_test_init(const char *req_file_path, const char *rsp_file_path, return -EINVAL; } + if (info.file_type == FIPS_TYPE_JSON) { +#ifdef RTE_HAS_JANSSON + json_error_t error; + json_info.json_root = json_loadf(info.fp_rd, 0, &error); + if (!json_info.json_root) { + RTE_LOG(ERR, USER1, "Cannot parse json file %s (line %d, column %d)\n", + req_file_path, error.line, error.column); + return -EINVAL; + } +#else /* RTE_HAS_JANSSON */ + RTE_LOG(ERR, USER1, "No json library configured.\n"); + return -EINVAL; +#endif /* RTE_HAS_JANSSON */ + } + info.fp_wr = fopen(rsp_file_path, "w"); if (!info.fp_wr) { RTE_LOG(ERR, USER1, "Cannot open file %s\n", rsp_file_path); @@ -329,6 +346,9 @@ fips_test_init(const char *req_file_path, const char *rsp_file_path, return -EINVAL; } + if (info.file_type == FIPS_TYPE_JSON) + return 0; + if (fips_test_parse_header() < 0) { RTE_LOG(ERR, USER1, "Failed parsing header\n"); return -1; @@ -428,6 +448,78 @@ fips_test_write_one_case(void) fprintf(info.fp_wr, "%s\n", info.vec[i]); } +#ifdef RTE_HAS_JANSSON +int +fips_test_parse_one_json_vector_set(void) +{ + json_t *algo_obj = json_object_get(json_info.json_vector_set, "algorithm"); + const char *algo_str = json_string_value(algo_obj); + + /* Vector sets contain the algorithm type, and nothing else we need. */ + if (strstr(algo_str, "AES-GCM")) + info.algo = FIPS_TEST_ALGO_AES_GCM; + else + return -EINVAL; + + return 0; +} + +int +fips_test_parse_one_json_group(void) +{ + int ret, i; + json_int_t val; + json_t *param; + + if (info.interim_callbacks) { + char json_value[256]; + for (i = 0; info.interim_callbacks[i].key != NULL; i++) { + param = json_object_get(json_info.json_test_group, + info.interim_callbacks[i].key); + val = json_integer_value(param); + snprintf(json_value, 255, "%"JSON_INTEGER_FORMAT, val); + /* First argument is blank because the key + * is not included in the string being parsed. + */ + ret = info.interim_callbacks[i].cb( + "", json_value, + info.interim_callbacks[i].val + ); + if (ret < 0) + return ret; + } + } + + return 0; +} + +int +fips_test_parse_one_json_case(void) +{ + uint32_t i; + int ret = 0; + json_t *param; + + for (i = 0; info.callbacks[i].key != NULL; i++) { + param = json_object_get(json_info.json_test_case, info.callbacks[i].key); + if (param) { + strcpy(info.one_line_text, json_string_value(param)); + /* First argument is blank because the key + * is not included in the string being parsed. + */ + ret = info.callbacks[i].cb( + "", info.one_line_text, + info.callbacks[i].val + ); + if (ret < 0) + return ret; + } + } + + return 0; +} +#endif /* RTE_HAS_JANSSON */ + static int parser_read_uint64_hex(uint64_t *value, const char *p) { -- 2.25.1