Commit cfb65ba6 authored by Jim Harris's avatar Jim Harris Committed by Tomasz Zawadzki
Browse files

test: add generic unlink wrapper



reduce library uses unlink, but the unit tests need to
override it in a specific way.

But linking unit tests with LTO requires the wrapper
definitions be in objects/libraries listed *after*
the object/library that refers to it.  So we need to
make the unlink wrapper somewhat generic.  We do this
by exporting a string and callback function that the
user can set to enable a user-defined function to be
called when unlink() is called with a specific file
name.

Also revert 3ef6d061 as part of this patch, since we
no longer require the workaround that it implemented.

Fixes issue #1357.

Signed-off-by: default avatarJim Harris <james.r.harris@intel.com>
Change-Id: I1ee4c424ad31fe7d91d7b524ed47aedd279e5b5c
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1948


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent c4868f30
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ fi
timing_enter build_release

if [ $(uname -s) = Linux ]; then
	./configure $(get_config_params) --disable-debug --enable-lto --disable-unit-tests
	./configure $(get_config_params) --disable-debug --enable-lto
else
	# LTO needs a special compiler to work on BSD.
	./configure $(get_config_params) --disable-debug
+0 −5
Original line number Diff line number Diff line
@@ -499,11 +499,6 @@ if [[ "${CONFIG[ISAL]}" = "n" ]] && [[ "${CONFIG[REDUCE]}" = "y" ]]; then
		exit 1
fi

if [[ "${CONFIG[LTO]}" = "y" ]] && [[ "${CONFIG[UNIT_TESTS]}" = "y"  ]]; then
		echo "ERROR Conflicting options: --enable-lto is not compatible with --enable-unit-tests."
		exit 1
fi

if [ -z "${CONFIG[ENV]}" ]; then
	CONFIG[ENV]=$rootdir/lib/env_dpdk
	echo "Using default SPDK env in ${CONFIG[ENV]}"
+10 −0
Original line number Diff line number Diff line
@@ -122,4 +122,14 @@ DECLARE_WRAPPER(sendmsg, ssize_t, (int sockfd, const struct msghdr *msg, int fla

DECLARE_WRAPPER(writev, ssize_t, (int fd, const struct iovec *iov, int iovcnt));

/* unlink is done a bit differently. */
extern char *g_unlink_path;
extern void (*g_unlink_callback)(void);
/* If g_unlink_path is NULL, __wrap_unlink will return ENOENT.
 * If the __wrap_unlink() parameter does not match g_unlink_path, it will return ENOENT.
 * If g_unlink_path does match, and g_unlink_callback has been set, g_unlink_callback will
 * be called before returning 0.
 */
int __wrap_unlink(const char *path);

#endif /* SPDK_INTERNAL_MOCK_H */
+21 −0
Original line number Diff line number Diff line
@@ -48,3 +48,24 @@ DEFINE_WRAPPER(sendmsg, ssize_t, (int sockfd, const struct msghdr *msg, int flag
		flags))

DEFINE_WRAPPER(writev, ssize_t, (int fd, const struct iovec *iov, int iovcnt), (fd, iov, iovcnt))

char *g_unlink_path;
void (*g_unlink_callback)(void);

int
__attribute__((used))
__wrap_unlink(const char *path)
{
	if (g_unlink_path == NULL) {
		return ENOENT;
	}

	if (strcmp(g_unlink_path, path) != 0) {
		return ENOENT;
	}

	if (g_unlink_callback) {
		g_unlink_callback();
	}
	return 0;
}
+5 −9
Original line number Diff line number Diff line
@@ -176,17 +176,10 @@ persistent_pm_buf_destroy(void)
	g_persistent_pm_buf_len = 0;
}

int __wrap_unlink(const char *path);

int
__wrap_unlink(const char *path)
static void
unlink_cb(void)
{
	if (strcmp(g_path, path) != 0) {
		return ENOENT;
	}

	persistent_pm_buf_destroy();
	return 0;
}

static void
@@ -1296,6 +1289,9 @@ main(int argc, char **argv)
	CU_ADD_TEST(suite, overlapped);
	CU_ADD_TEST(suite, compress_algorithm);

	g_unlink_path = g_path;
	g_unlink_callback = unlink_cb;

	CU_basic_set_mode(CU_BRM_VERBOSE);
	CU_basic_run_tests();
	num_failures = CU_get_number_of_failures();