Commit 3816dbf8 authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Jim Harris
Browse files

test/unit: remove unnecessary mock definitions



Added -ffunction-sections / --gc-sections to allow the linker to remove
unused functions when linking test executables. This reduces the number
of required mock definitions to those actually required by tested code.

Change-Id: I22725ce82e22675a7c2d28c8227e586f2cd65023
Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Reviewed-on: https://review.gerrithub.io/c/436319


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent eecc6dc8
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ C_SRCS = $(TEST_FILE)

CFLAGS += -I$(SPDK_ROOT_DIR)/lib
CFLAGS += -I$(SPDK_ROOT_DIR)/test
CFLAGS += -ffunction-sections
LDFLAGS += -Wl,--gc-sections

SPDK_LIB_LIST += thread util log sock

+3 −14
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@
 */
#include "rte_crypto.h"
#include "rte_cryptodev.h"
DEFINE_STUB_V(rte_crypto_op_free, (struct rte_crypto_op *op));
#include "bdev/crypto/vbdev_crypto.c"

/* SPDK stubs */
@@ -59,7 +58,6 @@ DEFINE_STUB(spdk_bdev_io_type_supported, bool, (struct spdk_bdev *bdev,
DEFINE_STUB_V(spdk_bdev_module_release_bdev, (struct spdk_bdev *bdev));
DEFINE_STUB_V(spdk_bdev_close, (struct spdk_bdev_desc *desc));
DEFINE_STUB(spdk_bdev_get_name, const char *, (const struct spdk_bdev *bdev), 0);
DEFINE_STUB(spdk_env_get_current_core, uint32_t, (void), 0);
DEFINE_STUB(spdk_bdev_get_io_channel, struct spdk_io_channel *, (struct spdk_bdev_desc *desc), 0);
DEFINE_STUB_V(spdk_bdev_unregister, (struct spdk_bdev *bdev, spdk_bdev_unregister_cb cb_fn,
				     void *cb_arg));
@@ -71,7 +69,6 @@ DEFINE_STUB(spdk_bdev_module_claim_bdev, int, (struct spdk_bdev *bdev, struct sp
DEFINE_STUB_V(spdk_bdev_module_examine_done, (struct spdk_bdev_module *module));
DEFINE_STUB(spdk_vbdev_register, int, (struct spdk_bdev *vbdev, struct spdk_bdev **base_bdevs,
				       int base_bdev_count), 0);
DEFINE_STUB(spdk_bdev_get_by_name, struct spdk_bdev *, (const char *bdev_name), NULL);
DEFINE_STUB(spdk_env_get_socket_id, uint32_t, (uint32_t core), 0);

/* DPDK stubs */
@@ -83,22 +80,20 @@ DEFINE_STUB(rte_crypto_op_pool_create, struct rte_mempool *,
	    (const char *name, enum rte_crypto_op_type type, unsigned nb_elts,
	     unsigned cache_size, uint16_t priv_size, int socket_id), (struct rte_mempool *)1);
DEFINE_STUB(rte_cryptodev_device_count_by_driver, uint8_t, (uint8_t driver_id), 0);
DEFINE_STUB(rte_cryptodev_socket_id, int, (uint8_t dev_id), 0);
DEFINE_STUB(rte_cryptodev_configure, int, (uint8_t dev_id, struct rte_cryptodev_config *config), 0);
DEFINE_STUB(rte_cryptodev_queue_pair_setup, int, (uint8_t dev_id, uint16_t queue_pair_id,
		const struct rte_cryptodev_qp_conf *qp_conf,
		int socket_id, struct rte_mempool *session_pool), 0);
DEFINE_STUB(rte_cryptodev_start, int, (uint8_t dev_id), 0)
DEFINE_STUB(rte_cryptodev_start, int, (uint8_t dev_id), 0);
DEFINE_STUB_V(rte_cryptodev_stop, (uint8_t dev_id));
DEFINE_STUB(rte_cryptodev_sym_session_create, struct rte_cryptodev_sym_session *,
	    (struct rte_mempool *mempool), (struct rte_cryptodev_sym_session *)1);
DEFINE_STUB(rte_cryptodev_sym_session_clear, int, (uint8_t dev_id,
		struct rte_cryptodev_sym_session *sess), 0);
DEFINE_STUB(rte_cryptodev_sym_session_free, int, (struct rte_cryptodev_sym_session *sess), 0);
DEFINE_STUB(rte_cryptodev_sym_session_init, int, (uint8_t dev_id,
		struct rte_cryptodev_sym_session *sess,
		struct rte_crypto_sym_xform *xforms, struct rte_mempool *mempool), 0);
DEFINE_STUB(rte_vdev_init, int, (const char *name, const char *args), 0);
DEFINE_STUB(rte_cryptodev_sym_session_free, int, (struct rte_cryptodev_sym_session *sess), 0);

void __attribute__((noreturn)) __rte_panic(const char *funcname, const char *format, ...)
{
	abort();
@@ -285,12 +280,6 @@ rte_mempool_put_bulk(struct rte_mempool *mp, void *const *obj_table,
	return;
}

static inline void *rte_mempool_get_priv(struct rte_mempool *mp)
{
	return NULL;
}


static inline int
rte_crypto_op_attach_sym_session(struct rte_crypto_op *op,
				 struct rte_cryptodev_sym_session *sess)
+0 −3
Original line number Diff line number Diff line
@@ -44,9 +44,6 @@

#define BDEV_UT_NUM_THREADS 3

DEFINE_STUB_V(spdk_scsi_nvme_translate, (const struct spdk_bdev_io *bdev_io,
		int *sc, int *sk, int *asc, int *ascq));

DEFINE_STUB(spdk_conf_find_section, struct spdk_conf_section *, (struct spdk_conf *cp,
		const char *name), NULL);
DEFINE_STUB(spdk_conf_section_get_nmval, char *,
+0 −12
Original line number Diff line number Diff line
@@ -39,23 +39,11 @@

#define test_argc 6

DEFINE_STUB_V(spdk_rpc_initialize, (const char *listen_addr));
DEFINE_STUB_V(spdk_rpc_finish, (void));
DEFINE_STUB_V(spdk_event_call, (struct spdk_event *event));
DEFINE_STUB_V(spdk_reactors_start, (void));
DEFINE_STUB_V(spdk_reactors_stop, (void *arg1, void *arg2));
DEFINE_STUB(spdk_reactors_init, int, (unsigned int max_delay_us), 0);
DEFINE_STUB_V(spdk_reactors_fini, (void));
DEFINE_STUB(spdk_event_allocate, struct spdk_event *, (uint32_t core, spdk_event_fn fn, void *arg1,
		void *arg2), NULL);
DEFINE_STUB(spdk_env_get_current_core, uint32_t, (void), 0);
DEFINE_STUB(spdk_app_get_core_mask, struct spdk_cpuset *, (void), NULL);
DEFINE_STUB_V(spdk_subsystem_config, (FILE *fp));
DEFINE_STUB_V(spdk_subsystem_init, (struct spdk_event *app_start_event));
DEFINE_STUB_V(spdk_subsystem_fini, (struct spdk_event *app_stop_event));
DEFINE_STUB(spdk_env_init, int, (const struct spdk_env_opts *opts), 0);
DEFINE_STUB_V(spdk_env_opts_init, (struct spdk_env_opts *opts));
DEFINE_STUB(spdk_env_get_core_count, uint32_t, (void), 1);
DEFINE_STUB_V(spdk_rpc_register_method, (const char *method, spdk_rpc_method_handler func,
		uint32_t state_mask));
DEFINE_STUB_V(spdk_rpc_set_state, (uint32_t state));
+8 −36
Original line number Diff line number Diff line
@@ -41,52 +41,24 @@

#include "common/lib/test_env.c"

DEFINE_STUB_V(nvme_ctrlr_fail,
	      (struct spdk_nvme_ctrlr *ctrlr, bool hot_remove))

DEFINE_STUB_V(nvme_ctrlr_proc_get_ref, (struct spdk_nvme_ctrlr *ctrlr))

DEFINE_STUB_V(nvme_ctrlr_proc_put_ref, (struct spdk_nvme_ctrlr *ctrlr))

DEFINE_STUB(spdk_pci_nvme_enumerate, int,
	    (spdk_pci_enum_cb enum_cb, void *enum_ctx), -1)

DEFINE_STUB(spdk_pci_device_get_id, struct spdk_pci_id,
	    (struct spdk_pci_device *pci_dev),
	    MOCK_STRUCT_INIT(.vendor_id = 0xffff, .device_id = 0xffff,
			     .subvendor_id = 0xffff, .subdevice_id = 0xffff))

DEFINE_STUB_V(nvme_ctrlr_proc_get_ref, (struct spdk_nvme_ctrlr *ctrlr));
DEFINE_STUB_V(nvme_ctrlr_proc_put_ref, (struct spdk_nvme_ctrlr *ctrlr));
DEFINE_STUB(spdk_nvme_transport_available, bool,
	    (enum spdk_nvme_transport_type trtype), true)

	    (enum spdk_nvme_transport_type trtype), true);
/* return anything non-NULL, this won't be deferenced anywhere in this test */
DEFINE_STUB(spdk_nvme_ctrlr_get_current_process, struct spdk_nvme_ctrlr_process *,
	    (struct spdk_nvme_ctrlr *ctrlr), (struct spdk_nvme_ctrlr_process *)(uintptr_t)0x1)

DEFINE_STUB(nvme_ctrlr_add_process, int,
	    (struct spdk_nvme_ctrlr *ctrlr, void *devhandle), 0)

	    (struct spdk_nvme_ctrlr *ctrlr), (struct spdk_nvme_ctrlr_process *)(uintptr_t)0x1);
DEFINE_STUB(nvme_ctrlr_process_init, int,
	    (struct spdk_nvme_ctrlr *ctrlr), 0)

DEFINE_STUB(spdk_pci_device_get_addr, struct spdk_pci_addr,
	    (struct spdk_pci_device *pci_dev), {0})

	    (struct spdk_nvme_ctrlr *ctrlr), 0);
DEFINE_STUB(nvme_ctrlr_get_ref_count, int,
	    (struct spdk_nvme_ctrlr *ctrlr), 0)

	    (struct spdk_nvme_ctrlr *ctrlr), 0);
DEFINE_STUB(dummy_probe_cb, bool,
	    (void *cb_ctx, const struct spdk_nvme_transport_id *trid,
	     struct spdk_nvme_ctrlr_opts *opts), false)

	     struct spdk_nvme_ctrlr_opts *opts), false);
DEFINE_STUB(nvme_transport_ctrlr_construct, struct spdk_nvme_ctrlr *,
	    (const struct spdk_nvme_transport_id *trid,
	     const struct spdk_nvme_ctrlr_opts *opts,
	     void *devhandle), NULL)

DEFINE_STUB(spdk_nvme_qpair_process_completions, int32_t,
	    (struct spdk_nvme_qpair *qpair,
	     uint32_t max_completions), 0);
	     void *devhandle), NULL);

static bool ut_destruct_called = false;
void
Loading