crt: tests: update t_aligned_alloc [2/2] On aarch64, due to buggy `_aligned_realloc`, some subtests were skipped (when `BROKEN_REALLOC_SHRINK` is defined to non-zero). Instead of entirely skipping those subtests, do the test, and in case if it fails, exit only if that test was not expected to fail. This is achieved by extening `TEST` and `TEST_MEM` macros to take an extra argument which indicates whether this subtest is expected to fail. For subtests which were previously skipped when `BROKEN_REALLOC_SHRINK` is defined to non-zero, the extra argument to `TEST` and `TEST_MEM` is `BROKEN_REALLOC_SHRINK` itself; subtest is expected to fail when `BROKEN_REALLOC_SHRINK` is non-zero. For other subtests, the extra argument is zero; subtest is not expected to fail. Signed-off-by: Kirill Makurin <maiddaisuki@outlook.com> Signed-off-by: LIU Hao <lh_mouse@126.com>
diff --git a/mingw-w64-crt/testcases/t_aligned_alloc.c b/mingw-w64-crt/testcases/t_aligned_alloc.c index 16de738..c29b920 100644 --- a/mingw-w64-crt/testcases/t_aligned_alloc.c +++ b/mingw-w64-crt/testcases/t_aligned_alloc.c
@@ -4,23 +4,27 @@ #include <stdio.h> #include <string.h> -#define TEST(a, b, msg, ...) do { \ +#define TEST(xfail, a, b, msg, ...) do { \ if ((a) != (b)) { \ fprintf(stderr, "%s:%d: ", __FILE__, __LINE__); \ fprintf(stderr, msg, ##__VA_ARGS__); \ fputc('\n', stderr); \ - return 1; \ + if (!xfail) { \ + return 1; \ + } \ } \ } while (0) -#define TEST_MEM(ptr, byte, size, msg, ...) do { \ +#define TEST_MEM(xfail, ptr, byte, size, msg, ...) do { \ size_t i; \ for (i = 0; i < size; i++) { \ if (((unsigned char *)ptr)[i] != (unsigned char)byte) { \ fprintf(stderr, "%s:%d: ", __FILE__, __LINE__); \ fprintf(stderr, msg, ##__VA_ARGS__); \ fputc('\n', stderr); \ - return 1; \ + if (!xfail) { \ + return 1; \ + } \ } \ } \ } while (0) @@ -60,7 +64,7 @@ ptr = malloc(231); assert(ptr != NULL); size = _msize(ptr); - TEST(size, 231, "_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); + TEST(0, size, 231, "_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); free(ptr); @@ -68,7 +72,7 @@ assert(ptr != NULL); size = _msize(ptr); - TEST(size, 1000, "_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); + TEST(0, size, 1000, "_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); memset(ptr, 0x01, 1000); @@ -76,105 +80,99 @@ assert(ptr != NULL); size = _msize(ptr); - TEST(size, 100, "_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); + TEST(0, size, 100, "_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); ptr = _recalloc(ptr, 200, 1); assert(ptr != NULL); size = _msize(ptr); - TEST(size, 200, "_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); + TEST(0, size, 200, "_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); - TEST_MEM(ptr, 0x01, 100, "_recalloc: 0x%p has incorrect byte 0x%02x at %lu", ptr, ((unsigned char *)ptr)[i], (unsigned long)i); - TEST_MEM(ptr+100, 0x00, 100, "_recalloc: 0x%p has incorrect byte 0x%02x at %lu", ptr, ((unsigned char *)ptr)[i+100], (unsigned long)i+100); + TEST_MEM(0, ptr, 0x01, 100, "_recalloc: 0x%p has incorrect byte 0x%02x at %lu", ptr, ((unsigned char *)ptr)[i], (unsigned long)i); + TEST_MEM(0, ptr+100, 0x00, 100, "_recalloc: 0x%p has incorrect byte 0x%02x at %lu", ptr, ((unsigned char *)ptr)[i+100], (unsigned long)i+100); free(ptr); ptr = _aligned_malloc(100, 128); assert(ptr != NULL); - TEST((uintptr_t)ptr % 128, 0, "_aligned_malloc: ptr 0x%p is not aligned", ptr); + TEST(0, (uintptr_t)ptr % 128, 0, "_aligned_malloc: ptr 0x%p is not aligned", ptr); size = _aligned_msize(ptr, 128, 0); - TEST(size, 100, "_aligned_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); + TEST(0, size, 100, "_aligned_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); memset(ptr, 0x01, 100); ptr = _aligned_realloc(ptr, 2000, 128); assert(ptr != NULL); - TEST((uintptr_t)ptr % 128, 0, "_aligned_realloc: ptr 0x%p is not aligned", ptr); + TEST(0, (uintptr_t)ptr % 128, 0, "_aligned_realloc: ptr 0x%p is not aligned", ptr); size = _aligned_msize(ptr, 128, 0); - TEST(size, 2000, "_aligned_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); + TEST(0, size, 2000, "_aligned_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); - TEST_MEM(ptr, 0x01, 100, "_aligned_realloc: 0x%p has incorrect byte 0x%02x at %lu", ptr, ((unsigned char *)ptr)[i], (unsigned long)i); + TEST_MEM(0, ptr, 0x01, 100, "_aligned_realloc: 0x%p has incorrect byte 0x%02x at %lu", ptr, ((unsigned char *)ptr)[i], (unsigned long)i); memset(ptr, 0x02, 2000); ptr = _aligned_realloc(ptr, 10, 128); assert(ptr != NULL); - TEST((uintptr_t)ptr % 128, 0, "_aligned_realloc: ptr 0x%p is not aligned", ptr); + TEST(0, (uintptr_t)ptr % 128, 0, "_aligned_realloc: ptr 0x%p is not aligned", ptr); size = _aligned_msize(ptr, 128, 0); - if (!BROKEN_REALLOC_SHRINK) - TEST(size, 10, "_aligned_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); + TEST(BROKEN_REALLOC_SHRINK, size, 10, "_aligned_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); ptr = _aligned_recalloc(ptr, 20, 1, 128); assert(ptr != NULL); - TEST((uintptr_t)ptr % 128, 0, "_aligned_recalloc: ptr 0x%p is not aligned", ptr); + TEST(0, (uintptr_t)ptr % 128, 0, "_aligned_recalloc: ptr 0x%p is not aligned", ptr); size = _aligned_msize(ptr, 128, 0); - if (!BROKEN_REALLOC_SHRINK) - TEST(size, 20, "_aligned_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); + TEST(BROKEN_REALLOC_SHRINK, size, 20, "_aligned_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); - TEST_MEM(ptr, 0x02, 10, "_aligned_recalloc: 0x%p has incorrect byte 0x%02x at %lu", ptr, ((unsigned char *)ptr)[i], (unsigned long)i); - if (!BROKEN_REALLOC_SHRINK) - TEST_MEM(ptr+10, 0x00, 10, "_aligned_recalloc: 0x%p has incorrect byte 0x%02x at %lu", ptr, ((unsigned char *)ptr)[i+10], (unsigned long)i+10); + TEST_MEM(0, ptr, 0x02, 10, "_aligned_recalloc: 0x%p has incorrect byte 0x%02x at %lu", ptr, ((unsigned char *)ptr)[i], (unsigned long)i); + TEST_MEM(BROKEN_REALLOC_SHRINK, ptr+10, 0x00, 10, "_aligned_recalloc: 0x%p has incorrect byte 0x%02x at %lu", ptr, ((unsigned char *)ptr)[i+10], (unsigned long)i+10); ptr = _aligned_recalloc(ptr, 3, 2, 128); assert(ptr != NULL); - TEST((uintptr_t)ptr % 128, 0, "_aligned_recalloc: ptr 0x%p is not aligned", ptr); + TEST(0, (uintptr_t)ptr % 128, 0, "_aligned_recalloc: ptr 0x%p is not aligned", ptr); - TEST_MEM(ptr, 0x02, 6, "_aligned_recalloc: 0x%p has incorrect byte 0x%02x at %lu", ptr, ((unsigned char *)ptr)[i], (unsigned long)i); + TEST_MEM(0, ptr, 0x02, 6, "_aligned_recalloc: 0x%p has incorrect byte 0x%02x at %lu", ptr, ((unsigned char *)ptr)[i], (unsigned long)i); _aligned_free(ptr); ptr = _aligned_offset_malloc(300, 128, 7); - TEST((uintptr_t)(ptr+7) % 128, 0, "_aligned_offset_malloc: ptr 0x%p is not aligned", ptr); + TEST(0, (uintptr_t)(ptr+7) % 128, 0, "_aligned_offset_malloc: ptr 0x%p is not aligned", ptr); size = _aligned_msize(ptr, 128, 7); - TEST(size, 300, "_aligned_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); + TEST(0, size, 300, "_aligned_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); ptr = _aligned_offset_realloc(ptr, 3000, 128, 7); assert(ptr != NULL); - TEST((uintptr_t)(ptr+7) % 128, 0, "_aligned_offset_realloc: ptr 0x%p is not aligned", ptr); + TEST(0, (uintptr_t)(ptr+7) % 128, 0, "_aligned_offset_realloc: ptr 0x%p is not aligned", ptr); size = _aligned_msize(ptr, 128, 7); - TEST(size, 3000, "_aligned_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); + TEST(0, size, 3000, "_aligned_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); memset(ptr, 0x01, 3000); ptr = _aligned_offset_recalloc(ptr, 100, 1, 128, 7); assert(ptr != NULL); - TEST((uintptr_t)(ptr+7) % 128, 0, "_aligned_offset_recalloc: ptr 0x%p is not aligned", ptr); + TEST(0, (uintptr_t)(ptr+7) % 128, 0, "_aligned_offset_recalloc: ptr 0x%p is not aligned", ptr); size = _aligned_msize(ptr, 128, 7); - if (!BROKEN_REALLOC_SHRINK) - TEST(size, 100, "_aligned_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); + TEST(BROKEN_REALLOC_SHRINK, size, 100, "_aligned_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); memset(ptr, 0x02, 100); ptr = _aligned_offset_recalloc(ptr, 110, 1, 128, 7); assert(ptr != NULL); - TEST((uintptr_t)(ptr+7) % 128, 0, "_aligned_offset_recalloc: ptr 0x%p is not aligned", ptr); + TEST(0, (uintptr_t)(ptr+7) % 128, 0, "_aligned_offset_recalloc: ptr 0x%p is not aligned", ptr); size = _aligned_msize(ptr, 128, 7); - if (!BROKEN_REALLOC_SHRINK) - TEST(size, 110, "_aligned_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); + TEST(BROKEN_REALLOC_SHRINK, size, 110, "_aligned_msize: ptr 0x%p has incorrect size %lu", ptr, (unsigned long)size); - TEST_MEM(ptr, 0x02, 100, "_aligned_offset_recalloc: 0x%p has incorrect byte 0x%02x at %lu", ptr, ((unsigned char *)ptr)[i], (unsigned long)i); - if (!BROKEN_REALLOC_SHRINK) - TEST_MEM(ptr+100, 0x00, 10, "_aligned_offset_recalloc: 0x%p has incorrect byte 0x%02x at %lu", ptr, ((unsigned char *)ptr)[i+100], (unsigned long)i+100); + TEST_MEM(0, ptr, 0x02, 100, "_aligned_offset_recalloc: 0x%p has incorrect byte 0x%02x at %lu", ptr, ((unsigned char *)ptr)[i], (unsigned long)i); + TEST_MEM(BROKEN_REALLOC_SHRINK, ptr+100, 0x00, 10, "_aligned_offset_recalloc: 0x%p has incorrect byte 0x%02x at %lu", ptr, ((unsigned char *)ptr)[i+100], (unsigned long)i+100); _aligned_free(ptr);