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 73DCCA0544; Tue, 7 Jun 2022 12:02:24 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 584B14021D; Tue, 7 Jun 2022 12:02:24 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 0999440156 for ; Tue, 7 Jun 2022 12:02:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654596141; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Wk0qI5L08FoVwm2F48oERnte1NsVUAnD8X2+2971rfc=; b=ZlSvDFKdWuCvqK+BQSMPC/xmcXxNDUUvlqQr3tckDr2lzxfNPEP0DPgtOzwjcOAXSa6SSr xwSLdTENYL6T9jzkP4XgwLHmUZ2681D/PqQ4gvK8HmVdwLQ3jP1bPsQXmIit+RvWa8EIF4 yDMuMYESJ0kV6LapgPpg9DC4KSzVJOo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-601-klpdlq5qP1iggTGyh61oWg-1; Tue, 07 Jun 2022 06:02:16 -0400 X-MC-Unique: klpdlq5qP1iggTGyh61oWg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CF0A2803D5B; Tue, 7 Jun 2022 10:02:15 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57CFCC15E71; Tue, 7 Jun 2022 10:02:14 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: thomas@monjalon.net, Fan Zhang , Brian Dooley , Gowrishankar Muthukrishnan , Brandon Lo Subject: [PATCH] examples/fips_validation: fix link to libjansson Date: Tue, 7 Jun 2022 12:02:02 +0200 Message-Id: <20220607100203.1611166-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david.marchand@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 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 --- 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 -#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 #include -#ifdef RTE_HAS_JANSSON +#ifdef USE_JANSSON #include -#endif /* RTE_HAS_JANSSON */ +#endif /* USE_JANSSON */ #include #include @@ -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