[v2,1/2] examples/fips_validation: share test callback with multiple keys

Message ID 20220812115201.1032352-1-gmuthukrishn@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: akhil goyal
Headers
Series [v2,1/2] examples/fips_validation: share test callback with multiple keys |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Gowrishankar Muthukrishnan Aug. 12, 2022, 11:52 a.m. UTC
  Make use of key param in test callbacks so that, test callback
can be shared with multiple keys.

Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
---
 examples/fips_validation/fips_validation.c | 27 +++++++++++++++-------
 1 file changed, 19 insertions(+), 8 deletions(-)
  

Comments

Brian Dooley Oct. 6, 2022, 1:13 p.m. UTC | #1
> -----Original Message-----
> From: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
> Sent: Friday, August 12, 2022 12:52 PM
> To: dev@dpdk.org
> Cc: Anoob Joseph <anoobj@marvell.com>; Zhang, Roy Fan
> <roy.fan.zhang@intel.com>; Dooley, Brian <brian.dooley@intel.com>; Akhil
> Goyal <gakhil@marvell.com>; jerinj@marvell.com; Gowrishankar
> Muthukrishnan <gmuthukrishn@marvell.com>
> Subject: [PATCH v2 1/2] examples/fips_validation: share test callback with
> multiple keys
> 
> Make use of key param in test callbacks so that, test callback can be shared
> with multiple keys.
> 
> Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
> ---
>  examples/fips_validation/fips_validation.c | 27 +++++++++++++++-------
>  1 file changed, 19 insertions(+), 8 deletions(-)
> 
> diff --git a/examples/fips_validation/fips_validation.c
> b/examples/fips_validation/fips_validation.c
> index 12b9b03f56..9678aa2161 100644
> --- a/examples/fips_validation/fips_validation.c
> +++ b/examples/fips_validation/fips_validation.c
> @@ -499,11 +499,8 @@ fips_test_parse_one_json_group(void)
>  				return -EINVAL;
>  			}
> 
> -			/* 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].key, json_value,
>  				info.interim_callbacks[i].val
>  			);
>  			if (ret < 0)
> @@ -525,11 +522,8 @@ fips_test_parse_one_json_case(void)
>  		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].key, info.one_line_text,
>  				info.callbacks[i].val
>  			);
>  			if (ret < 0)
> @@ -625,7 +619,14 @@ parse_uint8_hex_str(const char *key, char *src,
> struct fips_val *val)  {
>  	uint32_t len, j;
> 
> +#ifdef USE_JANSSON
> +	/*
> +	 * Offset not applicable in case of JSON test vectors.
> +	 */
> +	RTE_SET_USED(key);
> +#else
>  	src += strlen(key);
> +#endif
> 
>  	len = strlen(src) / 2;
> 
> @@ -653,6 +654,15 @@ parse_uint8_hex_str(const char *key, char *src,
> struct fips_val *val)
>  	return 0;
>  }
> 
> +#ifdef USE_JANSSON
> +int
> +parser_read_uint32_val(const char *key, char *src, struct fips_val
> +*val) {
> +	RTE_SET_USED(key);
> +
> +	return parser_read_uint32(&val->len, src); } #else
>  int
>  parser_read_uint32_val(const char *key, char *src, struct fips_val *val)  {
> @@ -676,6 +686,7 @@ parser_read_uint32_val(const char *key, char *src,
> struct fips_val *val)
> 
>  	return ret;
>  }
> +#endif
> 
>  int
>  parser_read_uint32_bit_val(const char *key, char *src, struct fips_val *val)
> --
> 2.25.1

Acked-by: Brian Dooley <brian.dooley@intel.com>
  

Patch

diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c
index 12b9b03f56..9678aa2161 100644
--- a/examples/fips_validation/fips_validation.c
+++ b/examples/fips_validation/fips_validation.c
@@ -499,11 +499,8 @@  fips_test_parse_one_json_group(void)
 				return -EINVAL;
 			}
 
-			/* 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].key, json_value,
 				info.interim_callbacks[i].val
 			);
 			if (ret < 0)
@@ -525,11 +522,8 @@  fips_test_parse_one_json_case(void)
 		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].key, info.one_line_text,
 				info.callbacks[i].val
 			);
 			if (ret < 0)
@@ -625,7 +619,14 @@  parse_uint8_hex_str(const char *key, char *src, struct fips_val *val)
 {
 	uint32_t len, j;
 
+#ifdef USE_JANSSON
+	/*
+	 * Offset not applicable in case of JSON test vectors.
+	 */
+	RTE_SET_USED(key);
+#else
 	src += strlen(key);
+#endif
 
 	len = strlen(src) / 2;
 
@@ -653,6 +654,15 @@  parse_uint8_hex_str(const char *key, char *src, struct fips_val *val)
 	return 0;
 }
 
+#ifdef USE_JANSSON
+int
+parser_read_uint32_val(const char *key, char *src, struct fips_val *val)
+{
+	RTE_SET_USED(key);
+
+	return parser_read_uint32(&val->len, src);
+}
+#else
 int
 parser_read_uint32_val(const char *key, char *src, struct fips_val *val)
 {
@@ -676,6 +686,7 @@  parser_read_uint32_val(const char *key, char *src, struct fips_val *val)
 
 	return ret;
 }
+#endif
 
 int
 parser_read_uint32_bit_val(const char *key, char *src, struct fips_val *val)