DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] examples/fips_validation: fix link to libjansson
@ 2022-06-07 10:02 David Marchand
  2022-06-07 12:28 ` [EXT] " Gowrishankar Muthukrishnan
  0 siblings, 1 reply; 3+ messages in thread
From: David Marchand @ 2022-06-07 10:02 UTC (permalink / raw)
  To: dev
  Cc: thomas, Fan Zhang, Brian Dooley, Gowrishankar Muthukrishnan, Brandon Lo

When compiling this example out of DPDK, linking the executable fails
with:

  ## Building fips_validation
  /usr/bin/ld: /tmp/ccQjeHBg.o: in function `fips_test_init':
  fips_validation.c:(.text+0x7ab): undefined reference to `json_loadf'
  /usr/bin/ld: /tmp/ccQjeHBg.o: in function
     `fips_test_parse_one_json_vector_set':
  fips_validation.c:(.text+0xc2e): undefined reference to `json_object_get'
  /usr/bin/ld: fips_validation.c:(.text+0xc36): undefined reference to
     `json_string_value'
  /usr/bin/ld: /tmp/ccQjeHBg.o: in function `fips_test_parse_one_json_group':
  fips_validation.c:(.text+0xd00): undefined reference to `json_object_get'
  /usr/bin/ld: fips_validation.c:(.text+0xd14): undefined reference to
     `json_integer_value'
  ...

Code in an example can't rely on RTE_HAS_JANSSON, because it only
indicates that the jansson library was available at the time of dpdk
compilation.

Prefer a local build flag (like what is done in vm_power_manager).
And add linking to libjansson, if available.

Fixes: f556293fd58e ("examples/fips_validation: add JSON info to header")

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 examples/fips_validation/Makefile             |  6 +++++
 examples/fips_validation/fips_validation.c    | 10 ++++----
 examples/fips_validation/fips_validation.h    | 16 ++++++-------
 .../fips_validation/fips_validation_aes.c     |  4 ++--
 .../fips_validation/fips_validation_cmac.c    |  4 ++--
 .../fips_validation/fips_validation_gcm.c     | 12 +++++-----
 .../fips_validation/fips_validation_hmac.c    |  8 +++----
 examples/fips_validation/main.c               | 24 +++++++++----------
 examples/fips_validation/meson.build          |  1 +
 9 files changed, 46 insertions(+), 39 deletions(-)

diff --git a/examples/fips_validation/Makefile b/examples/fips_validation/Makefile
index ff3cd4a87a..bca6647f55 100644
--- a/examples/fips_validation/Makefile
+++ b/examples/fips_validation/Makefile
@@ -36,6 +36,12 @@ CFLAGS += -O3 $(shell $(PKGCONF) --cflags libdpdk)
 LDFLAGS_SHARED = $(shell $(PKGCONF) --libs libdpdk)
 LDFLAGS_STATIC = $(shell $(PKGCONF) --static --libs libdpdk)
 
+JANSSON := $(shell $(PKGCONF) --exists jansson; echo $$?)
+ifeq ($(JANSSON), 0)
+LDFLAGS += $(shell $(PKGCONF) --libs jansson)
+CFLAGS += -DUSE_JANSSON
+endif
+
 ifeq ($(MAKECMDGOALS),static)
 # check for broken pkg-config
 ifeq ($(shell echo $(LDFLAGS_STATIC) | grep 'whole-archive.*l:lib.*no-whole-archive'),)
diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c
index 8cec172a5f..94e31abf83 100644
--- a/examples/fips_validation/fips_validation.c
+++ b/examples/fips_validation/fips_validation.c
@@ -314,7 +314,7 @@ fips_test_init(const char *req_file_path, const char *rsp_file_path,
 	}
 
 	if (info.file_type == FIPS_TYPE_JSON) {
-#ifdef RTE_HAS_JANSSON
+#ifdef USE_JANSSON
 		json_error_t error;
 		json_info.json_root = json_loadf(info.fp_rd, 0, &error);
 		if (!json_info.json_root) {
@@ -322,10 +322,10 @@ fips_test_init(const char *req_file_path, const char *rsp_file_path,
 				req_file_path, error.line, error.column);
 			return -EINVAL;
 		}
-#else /* RTE_HAS_JANSSON */
+#else /* USE_JANSSON */
 		RTE_LOG(ERR, USER1, "No json library configured.\n");
 		return -EINVAL;
-#endif /* RTE_HAS_JANSSON */
+#endif /* USE_JANSSON */
 	}
 
 	info.fp_wr = fopen(rsp_file_path, "w");
@@ -448,7 +448,7 @@ fips_test_write_one_case(void)
 		fprintf(info.fp_wr, "%s\n", info.vec[i]);
 }
 
-#ifdef RTE_HAS_JANSSON
+#ifdef USE_JANSSON
 int
 fips_test_parse_one_json_vector_set(void)
 {
@@ -535,7 +535,7 @@ fips_test_parse_one_json_case(void)
 
 	return 0;
 }
-#endif /* RTE_HAS_JANSSON */
+#endif /* USE_JANSSON */
 
 static int
 parser_read_uint64_hex(uint64_t *value, const char *p)
diff --git a/examples/fips_validation/fips_validation.h b/examples/fips_validation/fips_validation.h
index 6385ec4d8d..69d738b718 100644
--- a/examples/fips_validation/fips_validation.h
+++ b/examples/fips_validation/fips_validation.h
@@ -5,9 +5,9 @@
 #ifndef _FIPS_VALIDATION_H_
 #define _FIPS_VALIDATION_H_
 
-#ifdef RTE_HAS_JANSSON
+#ifdef USE_JANSSON
 #include <jansson.h>
-#endif /* RTE_HAS_JANSSON */
+#endif /* USE_JANSSON */
 
 #define FIPS_PARSE_ERR(fmt, args)					\
 	RTE_LOG(ERR, USER1, "FIPS parse error" ## fmt ## "\n", ## args)
@@ -170,7 +170,7 @@ struct gcm_interim_data {
 	uint8_t gen_iv;
 };
 
-#ifdef RTE_HAS_JANSSON
+#ifdef USE_JANSSON
 struct fips_test_json_info {
 	/* Information used for reading from json */
 	json_t *json_root;
@@ -185,7 +185,7 @@ struct fips_test_json_info {
 	/* Other info */
 	uint8_t is_sample;
 };
-#endif /* RTE_HAS_JANSSON */
+#endif /* USE_JANSSON */
 
 struct fips_test_interim_info {
 	FILE *fp_rd;
@@ -222,9 +222,9 @@ struct fips_test_interim_info {
 extern struct fips_test_vector vec;
 extern struct fips_test_interim_info info;
 
-#ifdef RTE_HAS_JANSSON
+#ifdef USE_JANSSON
 extern struct fips_test_json_info json_info;
-#endif /* RTE_HAS_JANSSON */
+#endif /* USE_JANSSON */
 
 int
 fips_test_init(const char *req_file_path, const char *rsp_file_path,
@@ -242,7 +242,7 @@ fips_test_parse_one_case(void);
 void
 fips_test_write_one_case(void);
 
-#ifdef RTE_HAS_JANSSON
+#ifdef USE_JANSSON
 int
 fips_test_parse_one_json_vector_set(void);
 
@@ -266,7 +266,7 @@ parse_test_cmac_json_init(void);
 
 int
 parse_test_aes_json_init(void);
-#endif /* RTE_HAS_JANSSON */
+#endif /* USE_JANSSON */
 
 int
 parse_test_aes_init(void);
diff --git a/examples/fips_validation/fips_validation_aes.c b/examples/fips_validation/fips_validation_aes.c
index 8db6f4fa31..4f61505bb3 100644
--- a/examples/fips_validation/fips_validation_aes.c
+++ b/examples/fips_validation/fips_validation_aes.c
@@ -107,7 +107,7 @@ struct fips_test_callback aes_writeback_callbacks[] = {
 		{NULL, NULL, NULL} /**< end pointer */
 };
 
-#ifdef RTE_HAS_JANSSON
+#ifdef USE_JANSSON
 struct fips_test_callback aes_dec_json_vectors[] = {
 		{KEY_JSON_STR, parse_uint8_known_len_hex_str, &vec.cipher_auth.key},
 		{IV_JSON_STR, parse_uint8_hex_str, &vec.iv},
@@ -313,7 +313,7 @@ parse_test_aes_json_init(void)
 
 	return 0;
 }
-#endif /* RTE_HAS_JANSSON */
+#endif /* USE_JANSSON */
 
 static int
 parse_test_aes_writeback(struct fips_val *val)
diff --git a/examples/fips_validation/fips_validation_cmac.c b/examples/fips_validation/fips_validation_cmac.c
index 094e3922a4..a54744714b 100644
--- a/examples/fips_validation/fips_validation_cmac.c
+++ b/examples/fips_validation/fips_validation_cmac.c
@@ -51,7 +51,7 @@ struct hash_algo_conversion {
 		{"AES", FIPS_TEST_ALGO_AES_CMAC},
 };
 
-#ifdef RTE_HAS_JANSSON
+#ifdef USE_JANSSON
 static int
 parser_read_cmac_direction_str(__rte_unused const char *key, char *src,
 		__rte_unused struct fips_val *val)
@@ -117,7 +117,7 @@ parse_test_cmac_json_init(void)
 
 	return 0;
 }
-#endif /* RTE_HAS_JANSSON */
+#endif /* USE_JANSSON */
 
 static int
 parse_test_cmac_writeback(struct fips_val *val)
diff --git a/examples/fips_validation/fips_validation_gcm.c b/examples/fips_validation/fips_validation_gcm.c
index 1b7bd0b729..28ef04c817 100644
--- a/examples/fips_validation/fips_validation_gcm.c
+++ b/examples/fips_validation/fips_validation_gcm.c
@@ -6,9 +6,9 @@
 #include <time.h>
 #include <stdio.h>
 
-#ifdef RTE_HAS_JANSSON
+#ifdef USE_JANSSON
 #include <jansson.h>
-#endif /* RTE_HAS_JANSSON */
+#endif /* USE_JANSSON */
 
 #include <rte_cryptodev.h>
 #include <rte_malloc.h>
@@ -161,7 +161,7 @@ struct fips_test_callback gcm_enc_vectors[] = {
 		{NULL, NULL, NULL} /**< end pointer */
 };
 
-#ifdef RTE_HAS_JANSSON
+#ifdef USE_JANSSON
 struct fips_test_callback gcm_dec_json_vectors[] = {
 		{KEY_JSON_STR, parse_uint8_known_len_hex_str, &vec.aead.key},
 		{IV_JSON_STR, parse_uint8_known_len_hex_str, &vec.iv},
@@ -193,7 +193,7 @@ struct fips_test_callback gcm_enc_json_vectors[] = {
 		{AAD_JSON_STR, parse_gcm_aad_str, &vec.aead.aad},
 		{NULL, NULL, NULL} /**< end pointer */
 };
-#endif /* RTE_HAS_JANSSON */
+#endif /* USE_JANSSON */
 
 static int
 parse_test_gcm_writeback(struct fips_val *val)
@@ -277,7 +277,7 @@ parse_test_gcm_init(void)
 	return 0;
 }
 
-#ifdef RTE_HAS_JANSSON
+#ifdef USE_JANSSON
 static int
 parse_test_gcm_json_writeback(struct fips_val *val)
 {
@@ -367,4 +367,4 @@ parse_test_gcm_json_init(void)
 	return 0;
 }
 
-#endif /* RTE_HAS_JANSSON */
+#endif /* USE_JANSSON */
diff --git a/examples/fips_validation/fips_validation_hmac.c b/examples/fips_validation/fips_validation_hmac.c
index 4cd1b1ac07..e0721ef028 100644
--- a/examples/fips_validation/fips_validation_hmac.c
+++ b/examples/fips_validation/fips_validation_hmac.c
@@ -74,7 +74,7 @@ struct fips_test_callback hmac_tests_interim_vectors[] = {
 		{NULL, NULL, NULL} /**< end pointer */
 };
 
-#ifdef RTE_HAS_JANSSON
+#ifdef USE_JANSSON
 struct hash_size_conversion json_algorithms[] = {
 		{"HMAC-SHA-1", RTE_CRYPTO_AUTH_SHA1_HMAC},
 		{"HMAC-SHA2-224", RTE_CRYPTO_AUTH_SHA224_HMAC},
@@ -95,7 +95,7 @@ struct fips_test_callback hmac_tests_interim_json_vectors[] = {
 		{TAGLEN_JSON_STR, parser_read_uint32_bit_val, &vec.cipher_auth.digest},
 		{NULL, NULL, NULL} /**< end pointer */
 };
-#endif /* RTE_HAS_JANSSON */
+#endif /* USE_JANSSON */
 
 static int
 parse_test_hmac_writeback(struct fips_val *val)
@@ -136,7 +136,7 @@ parse_test_hmac_init(void)
 	return 0;
 }
 
-#ifdef RTE_HAS_JANSSON
+#ifdef USE_JANSSON
 static int
 parse_test_hmac_json_writeback(struct fips_val *val)
 {
@@ -195,4 +195,4 @@ parse_test_hmac_json_init(void)
 
 	return 0;
 }
-#endif /* RTE_HAS_JANSSON */
+#endif /* USE_JANSSON */
diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c
index 332a4110e3..ceabea788e 100644
--- a/examples/fips_validation/main.c
+++ b/examples/fips_validation/main.c
@@ -41,9 +41,9 @@ enum {
 struct fips_test_vector vec;
 struct fips_test_interim_info info;
 
-#ifdef RTE_HAS_JANSSON
+#ifdef USE_JANSSON
 struct fips_test_json_info json_info;
-#endif /* RTE_HAS_JANSSON */
+#endif /* USE_JANSSON */
 
 struct cryptodev_fips_validate_env {
 	const char *req_path;
@@ -172,10 +172,10 @@ cryptodev_fips_validate_app_uninit(void)
 static int
 fips_test_one_file(void);
 
-#ifdef RTE_HAS_JANSSON
+#ifdef USE_JANSSON
 static int
 fips_test_one_json_file(void);
-#endif /* RTE_HAS_JANSSON */
+#endif /* USE_JANSSON */
 
 static int
 parse_cryptodev_arg(char *arg)
@@ -436,16 +436,16 @@ main(int argc, char *argv[])
 			goto exit;
 		}
 
-#ifdef RTE_HAS_JANSSON
+#ifdef USE_JANSSON
 		if (info.file_type == FIPS_TYPE_JSON) {
 			ret = fips_test_one_json_file();
 			json_decref(json_info.json_root);
 		}  else {
 			ret = fips_test_one_file();
 		}
-#else /* RTE_HAS_JANSSON */
+#else /* USE_JANSSON */
 		ret = fips_test_one_file();
-#endif /* RTE_HAS_JANSSON */
+#endif /* USE_JANSSON */
 
 		if (ret < 0) {
 			RTE_LOG(ERR, USER1, "Error %i: Failed test %s\n",
@@ -501,16 +501,16 @@ main(int argc, char *argv[])
 				break;
 			}
 
-#ifdef RTE_HAS_JANSSON
+#ifdef USE_JANSSON
 			if (info.file_type == FIPS_TYPE_JSON) {
 				ret = fips_test_one_json_file();
 				json_decref(json_info.json_root);
 			} else {
 				ret = fips_test_one_file();
 			}
-#else /* RTE_HAS_JANSSON */
+#else /* USE_JANSSON */
 			ret = fips_test_one_file();
-#endif /* RTE_HAS_JANSSON */
+#endif /* USE_JANSSON */
 
 			if (ret < 0) {
 				RTE_LOG(ERR, USER1, "Error %i: Failed test %s\n",
@@ -1920,7 +1920,7 @@ fips_test_one_file(void)
 	return ret;
 }
 
-#ifdef RTE_HAS_JANSSON
+#ifdef USE_JANSSON
 static int
 fips_test_json_init_writeback(void)
 {
@@ -2084,4 +2084,4 @@ fips_test_one_json_file(void)
 
 	return 0;
 }
-#endif /* RTE_HAS_JANSSON */
+#endif /* USE_JANSSON */
diff --git a/examples/fips_validation/meson.build b/examples/fips_validation/meson.build
index 8cd63066b5..8bca26a095 100644
--- a/examples/fips_validation/meson.build
+++ b/examples/fips_validation/meson.build
@@ -24,4 +24,5 @@ sources = files(
 
 if dpdk_conf.has('RTE_HAS_JANSSON')
     ext_deps += jansson_dep
+    cflags += '-DUSE_JANSSON'
 endif
-- 
2.36.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-21 10:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-07 10:02 [PATCH] examples/fips_validation: fix link to libjansson David Marchand
2022-06-07 12:28 ` [EXT] " Gowrishankar Muthukrishnan
2022-06-21 10:22   ` Akhil Goyal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).