From ed2ef8c3691811bc18faf48c6dac883faf18557c Mon Sep 17 00:00:00 2001 From: jvoisin Date: Wed, 3 Jan 2024 17:00:21 +0100 Subject: [PATCH] Add some pathological cases to the testsuite --- Makefile | 3 ++- tests/pathological.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 tests/pathological.c diff --git a/Makefile b/Makefile index c779471..01f0c52 100644 --- a/Makefile +++ b/Makefile @@ -440,7 +440,8 @@ libc_sanity_tests: clean library_debug_unit_tests $(CC) $(CFLAGS) $(EXE_CFLAGS) $(DEBUG_LOG_FLAGS) $(GDB_FLAGS) $(OS_FLAGS) tests/memcpy_sanity.c $(ISO_ALLOC_PRINTF_SRC) -o $(BUILD_DIR)/memcpy_sanity $(LDFLAGS) $(CC) $(CFLAGS) $(EXE_CFLAGS) $(DEBUG_LOG_FLAGS) $(GDB_FLAGS) $(OS_FLAGS) tests/memmove_sanity.c $(ISO_ALLOC_PRINTF_SRC) -o $(BUILD_DIR)/memmove_sanity $(LDFLAGS) $(CC) $(CFLAGS) $(EXE_CFLAGS) $(DEBUG_LOG_FLAGS) $(GDB_FLAGS) $(OS_FLAGS) tests/bzero_sanity.c $(ISO_ALLOC_PRINTF_SRC) -o $(BUILD_DIR)/bzero_sanity $(LDFLAGS) - build/memset_sanity ; build/memcpy_sanity; build/memmove_sanity; build/bzero_sanity ; + $(CC) $(CFLAGS) $(EXE_CFLAGS) $(DEBUG_LOG_FLAGS) $(GDB_FLAGS) $(OS_FLAGS) tests/pathological.c $(ISO_ALLOC_PRINTF_SRC) -o $(BUILD_DIR)/pathological $(LDFLAGS) + build/memset_sanity; build/memcpy_sanity; build/memmove_sanity; build/bzero_sanity; build/pathological; fuzz_test: clean library_debug_unit_tests @echo "make fuzz_test" diff --git a/tests/pathological.c b/tests/pathological.c new file mode 100644 index 0000000..b8e5dd0 --- /dev/null +++ b/tests/pathological.c @@ -0,0 +1,44 @@ +/* iso_alloc memset_sanity.c + * Copyright 2023 - chris.rohlf@gmail.com */ + +#include "iso_alloc.h" +#include "iso_alloc_internal.h" + +#if !MEMSET_SANITY +#error "This test intended to be run with -DMEMSET_SANITY=1" +#endif + +int main(int argc, char *argv[]) { + iso_free(iso_alloc(-1234)); + iso_free(iso_alloc(-1)); + iso_free(iso_alloc(0)); + iso_free(iso_alloc(1)); + + iso_free(iso_calloc(-1234, 1)); + iso_free(iso_calloc(-1, 1)); + iso_free(iso_calloc(0, 1)); + iso_free(iso_calloc(1, 1)); + + iso_free(iso_calloc(1, -1234)); + iso_free(iso_calloc(1, -1)); + iso_free(iso_calloc(1, 0)); + iso_free(iso_calloc(1, 1)); + + iso_free(iso_calloc(0, 0)); + iso_free(iso_calloc(0, 1)); + iso_free(iso_calloc(1, 0)); + + iso_free(iso_strdup("")); + iso_free(iso_strdup(NULL)); + + iso_free(iso_realloc(NULL, -1234)); + iso_free(iso_realloc(NULL, -1)); + iso_free(iso_realloc(NULL, 0)); + iso_free(iso_realloc(NULL, 1)); + + iso_free(iso_realloc(iso_alloc(1), 0)); + + iso_verify_zones(); + + return OK; +}