Commit 0e7077ac authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

test/unit: use posix_memalign() to allocate reactor



As mentioned in 771a7b87, there seems to be a bug with gcc and asan
where it doesn't properly align structures declared on the stack.

It also looks like declaring the variable with the aligned attribute
doesn't work either, so just use posix_memalign() to work around this.

Fixes #3004.

Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I4af902af0384cbd429334433c291ead23eba8293
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/18855


Community-CI: Mellanox Build Bot
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Reviewed-by: default avatarKamil Godzwon <kamilx.godzwon@intel.com>
parent 3e41e37d
Loading
Loading
Loading
Loading
+13 −8
Original line number Diff line number Diff line
@@ -16,20 +16,25 @@
static void
test_create_reactor(void)
{
	/* See SPDK issue #3004.  Seems like a bug with gcc + asan on Fedora 38, so
	 * we need to explicitly align the variable here.
	struct spdk_reactor *reactor;
	int rc;

	/* See SPDK issue #3004.  Seems like a bug with gcc + asan on Fedora 38, so we can't
	 * allocate g_reactors on the stack and need to explicitly used aligned allocation here.
	 */
	struct spdk_reactor reactor __attribute__((aligned(SPDK_CACHE_LINE_SIZE))) = {};
	rc = posix_memalign((void **)&reactor, SPDK_CACHE_LINE_SIZE, sizeof(*reactor));
	SPDK_CU_ASSERT_FATAL(rc == 0);

	g_reactors = &reactor;
	g_reactors = reactor;
	g_reactor_count = 1;

	reactor_construct(&reactor, 0);
	reactor_construct(reactor, 0);

	CU_ASSERT(spdk_reactor_get(0) == &reactor);
	CU_ASSERT(spdk_reactor_get(0) == reactor);

	spdk_ring_free(reactor.events);
	reactor_interrupt_fini(&reactor);
	spdk_ring_free(reactor->events);
	reactor_interrupt_fini(reactor);
	free(reactor);
	g_reactors = NULL;
}