]> git.droids-corp.org - dpdk.git/commitdiff
examples/fips_validation: fix link to libjansson
authorDavid Marchand <david.marchand@redhat.com>
Tue, 7 Jun 2022 10:02:02 +0000 (12:02 +0200)
committerAkhil Goyal <gakhil@marvell.com>
Tue, 21 Jun 2022 18:04:50 +0000 (20:04 +0200)
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>
Acked-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
examples/fips_validation/Makefile
examples/fips_validation/fips_validation.c
examples/fips_validation/fips_validation.h
examples/fips_validation/fips_validation_aes.c
examples/fips_validation/fips_validation_cmac.c
examples/fips_validation/fips_validation_gcm.c
examples/fips_validation/fips_validation_hmac.c
examples/fips_validation/main.c
examples/fips_validation/meson.build

index ff3cd4a87a619938d8374262dd85591525238de8..bca6647f5500071b0df84ce6a43ccb95e3886b78 100644 (file)
@@ -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'),)
index 8cec172a5f9f452deb32d7a23ed0b63180686ef2..94e31abf83d018b2306a014514ca76e77cd07ce0 100644 (file)
@@ -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)
index 6385ec4d8dd05919e2916c02b873fa7348a45cc7..69d738b718dd61881f24e45f6672648ff424b93b 100644 (file)
@@ -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);
index 8db6f4fa312cdd08c6f5f154227a5f86a7ad1bbf..4f61505bb38a984cada14af5f0fd7402abff5b4a 100644 (file)
@@ -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)
index 094e3922a494f1df109498d5281b24ec1f3e0f4c..a54744714b1db71ecba7eedac979e6e75946ac96 100644 (file)
@@ -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)
index 1b7bd0b72944feee8c008fe399424c2b24025a38..28ef04c81737d964d7d8ef31d236ba0a3848dab3 100644 (file)
@@ -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 */
index 4cd1b1ac074b54aac78cdc113eeda3fd08274390..e0721ef028e9bd5174913134e12e8ecb88cb32c2 100644 (file)
@@ -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 */
index 332a4110e35c014e253891527ca9a55beea11dbe..ceabea788e662aef00dd408299a7e95ca493fe11 100644 (file)
@@ -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 @@ error_one_case:
        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 */
index 8cd63066b51b6e4b17677c40e9c054eb1aa68643..8bca26a0955fe8d53d1d1dd9d24d76de488d207a 100644 (file)
@@ -24,4 +24,5 @@ sources = files(
 
 if dpdk_conf.has('RTE_HAS_JANSSON')
     ext_deps += jansson_dep
+    cflags += '-DUSE_JANSSON'
 endif