diff --git a/unittest/libmariadb/CMakeLists.txt b/unittest/libmariadb/CMakeLists.txt index 876e5cfcb..6166d4733 100644 --- a/unittest/libmariadb/CMakeLists.txt +++ b/unittest/libmariadb/CMakeLists.txt @@ -26,7 +26,7 @@ INCLUDE_DIRECTORIES(${CC_SOURCE_DIR}/include ${CC_SOURCE_DIR}/unittest/libmariadb) ADD_DEFINITIONS(-DLIBMARIADB) -SET(API_TESTS "conc336" "bulk1" "performance" "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs" "sp" "result" "connection" "misc" "ps_new" "thread" "features-10_2") +SET(API_TESTS "conc336" "bulk1" "performance" "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs" "sp" "result" "connection" "misc" "ps_new" "thread" "features-10_2" "context") IF(WITH_DYNCOL) SET(API_TESTS ${API_TESTS} "dyncol") ENDIF() diff --git a/unittest/libmariadb/context.c b/unittest/libmariadb/context.c new file mode 100644 index 000000000..e4a8a6673 --- /dev/null +++ b/unittest/libmariadb/context.c @@ -0,0 +1,44 @@ +/* + * Tests for ma_context functions. + */ + +#include "my_test.h" +#include "mysql.h" +#include "ma_context.h" +#include +#include +#include + +/* + * Ensures the context system aligns the stack correctly for i386 and x86_64 + */ +void async_task(__attribute__((unused)) void *v) { +#if defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) ) + /* + * The compiler assumes the stack is correctly aligned on a 16-byte + * boundary on entry to the function (actually, with a return address + * popped on top of the aligned address). Creating an object with a + * max_align_t type should also be aligned at that boundary, so we should + * be able to use movaps to move the first 128 bits into xmm0. + */ + union { + max_align_t aligned; + uint64_t data[2]; + } aligned; + __asm__("movaps %0, %%xmm0" : : "m" (aligned.data) : "xmm0" ); +#endif +} + +static int test_stack_align() { + struct my_context ctx; + my_context_init(&ctx, 65536); + my_context_spawn(&ctx, async_task, &ctx); + my_context_destroy(&ctx); + return 0; +} + +int main() +{ + plan(1); + ok( test_stack_align() == 0, "stack alignment check" ); +}