test/common: Mock CPU core operations for unit tests
Mock DPDK lcore operations for unit tests. Remove duplicated stup from unit tests for NVMe-oF FC transport. The next patch will use them. Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Change-Id: I4f6fbd8f45942ca13fcf10ba1740a9fe8e573063 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/478153 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Community-CI: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
0bc0463e3e
commit
f74107fb85
@ -39,16 +39,109 @@
|
||||
#include "spdk/queue.h"
|
||||
#include "spdk/util.h"
|
||||
|
||||
static uint32_t g_ut_num_cores;
|
||||
static bool *g_ut_cores;
|
||||
|
||||
void allocate_cores(uint32_t num_cores);
|
||||
void free_cores(void);
|
||||
|
||||
DEFINE_STUB(spdk_process_is_primary, bool, (void), true)
|
||||
DEFINE_STUB(spdk_memzone_lookup, void *, (const char *name), NULL)
|
||||
DEFINE_STUB(spdk_pci_nvme_get_driver, struct spdk_pci_driver *, (void), NULL)
|
||||
DEFINE_STUB(spdk_pci_ioat_get_driver, struct spdk_pci_driver *, (void), NULL)
|
||||
DEFINE_STUB(spdk_pci_virtio_get_driver, struct spdk_pci_driver *, (void), NULL)
|
||||
DEFINE_STUB(spdk_env_get_first_core, uint32_t, (void), UINT32_MAX);
|
||||
DEFINE_STUB(spdk_env_get_next_core, uint32_t, (uint32_t prev_core), UINT32_MAX);
|
||||
DEFINE_STUB(spdk_env_get_last_core, uint32_t, (void), UINT32_MAX);
|
||||
DEFINE_STUB(spdk_env_get_current_core, uint32_t, (void), UINT32_MAX);
|
||||
DEFINE_STUB(spdk_env_get_socket_id, uint32_t, (uint32_t core), SPDK_ENV_SOCKET_ID_ANY);
|
||||
|
||||
void
|
||||
allocate_cores(uint32_t num_cores)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
g_ut_num_cores = num_cores;
|
||||
|
||||
g_ut_cores = calloc(num_cores, sizeof(bool));
|
||||
assert(g_ut_cores != NULL);
|
||||
|
||||
for (i = 0; i < num_cores; i++) {
|
||||
g_ut_cores[i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
free_cores(void)
|
||||
{
|
||||
free(g_ut_cores);
|
||||
g_ut_cores = NULL;
|
||||
g_ut_num_cores = 0;
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
ut_get_next_core(uint32_t i)
|
||||
{
|
||||
i++;
|
||||
|
||||
while (i < g_ut_num_cores) {
|
||||
if (!g_ut_cores[i]) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (i < g_ut_num_cores) {
|
||||
return i;
|
||||
} else {
|
||||
return UINT32_MAX;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t
|
||||
spdk_env_get_first_core(void)
|
||||
{
|
||||
return ut_get_next_core(-1);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
spdk_env_get_next_core(uint32_t prev_core)
|
||||
{
|
||||
return ut_get_next_core(prev_core);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
spdk_env_get_core_count(void)
|
||||
{
|
||||
return g_ut_num_cores;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
spdk_env_get_last_core(void)
|
||||
{
|
||||
uint32_t i;
|
||||
uint32_t last_core = UINT32_MAX;
|
||||
|
||||
SPDK_ENV_FOREACH_CORE(i) {
|
||||
last_core = i;
|
||||
}
|
||||
|
||||
return last_core;
|
||||
}
|
||||
|
||||
DEFINE_RETURN_MOCK(spdk_env_get_current_core, uint32_t);
|
||||
uint32_t
|
||||
spdk_env_get_current_core(void)
|
||||
{
|
||||
HANDLE_RETURN_MOCK(spdk_env_get_current_core);
|
||||
|
||||
return UINT32_MAX;
|
||||
}
|
||||
|
||||
DEFINE_RETURN_MOCK(spdk_env_get_socket_id, uint32_t);
|
||||
uint32_t
|
||||
spdk_env_get_socket_id(uint32_t core)
|
||||
{
|
||||
HANDLE_RETURN_MOCK(spdk_env_get_socket_id);
|
||||
|
||||
return SPDK_ENV_SOCKET_ID_ANY;
|
||||
}
|
||||
|
||||
/*
|
||||
* These mocks don't use the DEFINE_STUB macros because
|
||||
|
@ -95,7 +95,6 @@ struct spdk_trace_histories *g_trace_histories;
|
||||
|
||||
DEFINE_STUB_V(_spdk_trace_record, (uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id,
|
||||
uint32_t size, uint64_t object_id, uint64_t arg1));
|
||||
DEFINE_STUB(spdk_env_get_core_count, uint32_t, (void), 4);
|
||||
DEFINE_STUB(spdk_nvme_transport_id_compare, int,
|
||||
(const struct spdk_nvme_transport_id *trid1,
|
||||
const struct spdk_nvme_transport_id *trid2), 0);
|
||||
|
Loading…
Reference in New Issue
Block a user