summaryrefslogtreecommitdiff
path: root/deps/Unity/extras/memory
diff options
context:
space:
mode:
Diffstat (limited to 'deps/Unity/extras/memory')
-rw-r--r--deps/Unity/extras/memory/readme.md42
-rw-r--r--deps/Unity/extras/memory/src/meson.build9
-rw-r--r--deps/Unity/extras/memory/src/unity_memory.c179
-rw-r--r--deps/Unity/extras/memory/src/unity_memory.h60
-rw-r--r--deps/Unity/extras/memory/test/Makefile78
-rw-r--r--deps/Unity/extras/memory/test/unity_memory_Test.c325
-rw-r--r--deps/Unity/extras/memory/test/unity_memory_TestRunner.c49
-rw-r--r--deps/Unity/extras/memory/test/unity_output_Spy.c56
-rw-r--r--deps/Unity/extras/memory/test/unity_output_Spy.h16
9 files changed, 814 insertions, 0 deletions
diff --git a/deps/Unity/extras/memory/readme.md b/deps/Unity/extras/memory/readme.md
new file mode 100644
index 0000000..ea8b9cf
--- /dev/null
+++ b/deps/Unity/extras/memory/readme.md
@@ -0,0 +1,42 @@
+# Unity Memory
+
+This Framework is an optional add-on to Unity.
+By including unity.h and then unity_memory.h, you have the added ability to track malloc and free calls.
+This addon requires that the stdlib functions be overridden by its own defines.
+These defines will still malloc / realloc / free etc, but will also track the calls in order to ensure that you don't have any memory leaks in your programs.
+
+Note that this is only useful in situations where a unit is in charge of both the allocation and deallocation of memory.
+When it is not symmetric, unit testing can report a number of false failures.
+A more advanced runtime tool is required to track complete system memory handling.
+
+## Module API
+
+### `UnityMalloc_StartTest` and `UnityMalloc_EndTest`
+
+These must be called at the beginning and end of each test.
+For simplicity, they can be added to `setUp` and `tearDown` in order to do their job.
+When using the test runner generator scripts, these will be automatically added to the runner whenever unity_memory.h is included.
+
+### `UnityMalloc_MakeMallocFailAfterCount`
+
+This can be called from the tests themselves.
+Passing this function a number will force the reference counter to start keeping track of malloc calls.
+During that test, if the number of malloc calls exceeds the number given, malloc will immediately start returning `NULL`.
+This allows you to test error conditions.
+Think of it as a simplified mock.
+
+## Configuration
+
+### `UNITY_MALLOC` and `UNITY_FREE`
+
+By default, this module tries to use the real stdlib `malloc` and `free` internally.
+If you would prefer it to use something else, like FreeRTOS's `pvPortMalloc` and `pvPortFree`, then you can use these defines to make it so.
+
+### `UNITY_EXCLUDE_STDLIB_MALLOC`
+
+If you would like this library to ignore stdlib or other heap engines completely, and manage the memory on its own, then define this. All memory will be handled internally (and at likely lower overhead).
+Note that this is not a very featureful memory manager, but is sufficient for most testing purposes.
+
+### `UNITY_INTERNAL_HEAP_SIZE_BYTES`
+
+When using the built-in memory manager (see `UNITY_EXCLUDE_STDLIB_MALLOC`) this define allows you to set the heap size this library will use to manage the memory.
diff --git a/deps/Unity/extras/memory/src/meson.build b/deps/Unity/extras/memory/src/meson.build
new file mode 100644
index 0000000..650ba32
--- /dev/null
+++ b/deps/Unity/extras/memory/src/meson.build
@@ -0,0 +1,9 @@
+unity_inc += include_directories('.')
+unity_src += files('unity_memory.c')
+
+if not meson.is_subproject()
+ install_headers(
+ 'unity_memory.h',
+ subdir: meson.project_name()
+ )
+endif
diff --git a/deps/Unity/extras/memory/src/unity_memory.c b/deps/Unity/extras/memory/src/unity_memory.c
new file mode 100644
index 0000000..36526d1
--- /dev/null
+++ b/deps/Unity/extras/memory/src/unity_memory.c
@@ -0,0 +1,179 @@
+/* ==========================================
+ * Unity Project - A Test Framework for C
+ * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
+ * [Released under MIT License. Please refer to license.txt for details]
+ * ========================================== */
+
+#include "unity_memory.h"
+#include <string.h>
+#include "unity.h"
+
+#define MALLOC_DONT_FAIL -1
+static int malloc_count;
+static int malloc_fail_countdown = MALLOC_DONT_FAIL;
+
+void UnityMalloc_StartTest(void) {
+ malloc_count = 0;
+ malloc_fail_countdown = MALLOC_DONT_FAIL;
+}
+
+void UnityMalloc_EndTest(void) {
+ malloc_fail_countdown = MALLOC_DONT_FAIL;
+ if (malloc_count != 0) {
+ UNITY_TEST_FAIL(Unity.CurrentTestLineNumber, "This test leaks!");
+ }
+}
+
+void UnityMalloc_MakeMallocFailAfterCount(int countdown) { malloc_fail_countdown = countdown; }
+
+/* These definitions are always included from unity_fixture_malloc_overrides.h */
+/* We undef to use them or avoid conflict with <stdlib.h> per the C standard */
+#undef malloc
+#undef free
+#undef calloc
+#undef realloc
+
+#ifdef UNITY_EXCLUDE_STDLIB_MALLOC
+static unsigned char unity_heap[UNITY_INTERNAL_HEAP_SIZE_BYTES];
+static size_t heap_index;
+#else
+#include <stdlib.h>
+#endif
+
+typedef struct GuardBytes {
+ size_t size;
+ size_t guard_space;
+} Guard;
+
+#define UNITY_MALLOC_ALIGNMENT (UNITY_POINTER_WIDTH / 8)
+static const char end[] = "END";
+
+static size_t unity_size_round_up(size_t size) {
+ size_t rounded_size;
+
+ rounded_size =
+ ((size + UNITY_MALLOC_ALIGNMENT - 1) / UNITY_MALLOC_ALIGNMENT) * UNITY_MALLOC_ALIGNMENT;
+
+ return rounded_size;
+}
+
+void* unity_malloc(size_t size) {
+ char* mem;
+ Guard* guard;
+ size_t total_size;
+
+ total_size = sizeof(Guard) + unity_size_round_up(size + sizeof(end));
+
+ if (malloc_fail_countdown != MALLOC_DONT_FAIL) {
+ if (malloc_fail_countdown == 0) return NULL;
+ malloc_fail_countdown--;
+ }
+
+ if (size == 0) return NULL;
+#ifdef UNITY_EXCLUDE_STDLIB_MALLOC
+ if (heap_index + total_size > UNITY_INTERNAL_HEAP_SIZE_BYTES) {
+ guard = NULL;
+ } else {
+ /* We know we can get away with this cast because we aligned memory already */
+ guard = (Guard*)(void*)(&unity_heap[heap_index]);
+ heap_index += total_size;
+ }
+#else
+ guard = (Guard*)UNITY_MALLOC(total_size);
+#endif
+ if (guard == NULL) return NULL;
+ malloc_count++;
+ guard->size = size;
+ guard->guard_space = 0;
+ mem = (char*)&(guard[1]);
+ memcpy(&mem[size], end, sizeof(end));
+
+ return (void*)mem;
+}
+
+static int isOverrun(void* mem) {
+ Guard* guard = (Guard*)mem;
+ char* memAsChar = (char*)mem;
+ guard--;
+
+ return guard->guard_space != 0 || strcmp(&memAsChar[guard->size], end) != 0;
+}
+
+static void release_memory(void* mem) {
+ Guard* guard = (Guard*)mem;
+ guard--;
+
+ malloc_count--;
+#ifdef UNITY_EXCLUDE_STDLIB_MALLOC
+ {
+ size_t block_size;
+
+ block_size = unity_size_round_up(guard->size + sizeof(end));
+
+ if (mem == unity_heap + heap_index - block_size) {
+ heap_index -= (sizeof(Guard) + block_size);
+ }
+ }
+#else
+ UNITY_FREE(guard);
+#endif
+}
+
+void unity_free(void* mem) {
+ int overrun;
+
+ if (mem == NULL) {
+ return;
+ }
+
+ overrun = isOverrun(mem);
+ release_memory(mem);
+ if (overrun) {
+ UNITY_TEST_FAIL(Unity.CurrentTestLineNumber, "Buffer overrun detected during free()");
+ }
+}
+
+void* unity_calloc(size_t num, size_t size) {
+ void* mem = unity_malloc(num * size);
+ if (mem == NULL) return NULL;
+ memset(mem, 0, num * size);
+ return mem;
+}
+
+void* unity_realloc(void* oldMem, size_t size) {
+ Guard* guard = (Guard*)oldMem;
+ void* newMem;
+
+ if (oldMem == NULL) return unity_malloc(size);
+
+ guard--;
+ if (isOverrun(oldMem)) {
+ release_memory(oldMem);
+ UNITY_TEST_FAIL(Unity.CurrentTestLineNumber, "Buffer overrun detected during realloc()");
+ }
+
+ if (size == 0) {
+ release_memory(oldMem);
+ return NULL;
+ }
+
+ if (guard->size >= size) return oldMem;
+
+#ifdef UNITY_EXCLUDE_STDLIB_MALLOC /* Optimization if memory is expandable */
+ {
+ size_t old_total_size = unity_size_round_up(guard->size + sizeof(end));
+
+ if ((oldMem == unity_heap + heap_index - old_total_size) &&
+ ((heap_index - old_total_size + unity_size_round_up(size + sizeof(end))) <=
+ UNITY_INTERNAL_HEAP_SIZE_BYTES)) {
+ release_memory(oldMem); /* Not thread-safe, like unity_heap generally */
+ return unity_malloc(size); /* No memcpy since data is in place */
+ }
+ }
+#endif
+ newMem = unity_malloc(size);
+ if (newMem == NULL) return NULL; /* Do not release old memory */
+ memcpy(newMem, oldMem, guard->size);
+ release_memory(oldMem);
+ return newMem;
+}
diff --git a/deps/Unity/extras/memory/src/unity_memory.h b/deps/Unity/extras/memory/src/unity_memory.h
new file mode 100644
index 0000000..ccdb826
--- /dev/null
+++ b/deps/Unity/extras/memory/src/unity_memory.h
@@ -0,0 +1,60 @@
+/* ==========================================
+ * Unity Project - A Test Framework for C
+ * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
+ * [Released under MIT License. Please refer to license.txt for details]
+ * ========================================== */
+
+#ifndef UNITY_MEMORY_OVERRIDES_H_
+#define UNITY_MEMORY_OVERRIDES_H_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stddef.h>
+
+#ifdef UNITY_EXCLUDE_STDLIB_MALLOC
+/* Define this macro to remove the use of stdlib.h, malloc, and free.
+ * Many embedded systems do not have a heap or malloc/free by default.
+ * This internal unity_malloc() provides allocated memory deterministically from
+ * the end of an array only, unity_free() only releases from end-of-array,
+ * blocks are not coalesced, and memory not freed in LIFO order is stranded. */
+ #ifndef UNITY_INTERNAL_HEAP_SIZE_BYTES
+ #define UNITY_INTERNAL_HEAP_SIZE_BYTES 256
+ #endif
+#endif
+
+/* These functions are used by Unity to allocate and release memory
+ * on the heap and can be overridden with platform-specific implementations.
+ * For example, when using FreeRTOS UNITY_MALLOC becomes pvPortMalloc()
+ * and UNITY_FREE becomes vPortFree(). */
+#if !defined(UNITY_MALLOC) || !defined(UNITY_FREE)
+ #include <stdlib.h>
+ #define UNITY_MALLOC(size) malloc(size)
+ #define UNITY_FREE(ptr) free(ptr)
+#else
+ extern void* UNITY_MALLOC(size_t size);
+ extern void UNITY_FREE(void* ptr);
+#endif
+
+#define malloc unity_malloc
+#define calloc unity_calloc
+#define realloc unity_realloc
+#define free unity_free
+
+void* unity_malloc(size_t size);
+void* unity_calloc(size_t num, size_t size);
+void* unity_realloc(void * oldMem, size_t size);
+void unity_free(void * mem);
+
+/* You must compile with malloc replacement, as defined in unity_fixture_malloc_overrides.h */
+void UnityMalloc_StartTest(void);
+void UnityMalloc_EndTest(void);
+void UnityMalloc_MakeMallocFailAfterCount(int countdown);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/deps/Unity/extras/memory/test/Makefile b/deps/Unity/extras/memory/test/Makefile
new file mode 100644
index 0000000..f3f86ce
--- /dev/null
+++ b/deps/Unity/extras/memory/test/Makefile
@@ -0,0 +1,78 @@
+CC = gcc
+ifeq ($(shell uname -s), Darwin)
+CC = clang
+endif
+#DEBUG = -O0 -g
+CFLAGS += -std=c99 -pedantic -Wall -Wextra -Werror
+CFLAGS += $(DEBUG)
+DEFINES = -D UNITY_OUTPUT_CHAR=UnityOutputCharSpy_OutputChar
+ifeq ($(OS),Windows_NT)
+ DEFINES += -D UNITY_OUTPUT_CHAR_HEADER_DECLARATION=UnityOutputCharSpy_OutputChar(int)
+else
+ DEFINES += -D UNITY_OUTPUT_CHAR_HEADER_DECLARATION=UnityOutputCharSpy_OutputChar\(int\)
+endif
+SRC = ../src/unity_memory.c \
+ ../../../src/unity.c \
+ unity_memory_Test.c \
+ unity_memory_TestRunner.c \
+ unity_output_Spy.c \
+
+INC_DIR = -I../src -I../../../src/
+BUILD_DIR = ../build
+TARGET = ../build/memory_tests.exe
+
+all: default noStdlibMalloc 32bits
+
+default: $(BUILD_DIR)
+ $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -D UNITY_SUPPORT_64
+ @ echo "default build"
+ ./$(TARGET)
+
+32bits: $(BUILD_DIR)
+ $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -m32
+ @ echo "32bits build"
+ ./$(TARGET)
+
+noStdlibMalloc: $(BUILD_DIR)
+ $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -D UNITY_EXCLUDE_STDLIB_MALLOC
+ @ echo "build with noStdlibMalloc"
+ ./$(TARGET)
+
+C89: CFLAGS += -D UNITY_EXCLUDE_STDINT_H # C89 did not have type 'long long', <stdint.h>
+C89: $(BUILD_DIR)
+ $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -std=c89 && ./$(TARGET)
+ $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -D UNITY_EXCLUDE_STDLIB_MALLOC -std=c89
+ ./$(TARGET)
+
+$(BUILD_DIR):
+ mkdir -p $(BUILD_DIR)
+
+clean:
+ rm -f $(TARGET) $(BUILD_DIR)/*.gc*
+
+cov: $(BUILD_DIR)
+ cd $(BUILD_DIR) && \
+ $(CC) $(DEFINES) $(foreach i, $(SRC), ../test/$(i)) $(INC_DIR) -o $(TARGET) -fprofile-arcs -ftest-coverage
+ rm -f $(BUILD_DIR)/*.gcda
+ ./$(TARGET) > /dev/null ; ./$(TARGET) -v > /dev/null
+ cd $(BUILD_DIR) && \
+ gcov unity_memory.c | head -3
+ grep '###' $(BUILD_DIR)/unity_memory.c.gcov -C2 || true # Show uncovered lines
+
+# These extended flags DO get included before any target build runs
+CFLAGS += -Wbad-function-cast
+CFLAGS += -Wcast-qual
+CFLAGS += -Wconversion
+CFLAGS += -Wformat=2
+CFLAGS += -Wmissing-prototypes
+CFLAGS += -Wold-style-definition
+CFLAGS += -Wpointer-arith
+CFLAGS += -Wshadow
+CFLAGS += -Wstrict-overflow=5
+CFLAGS += -Wstrict-prototypes
+CFLAGS += -Wswitch-default
+CFLAGS += -Wundef
+CFLAGS += -Wno-error=undef # Warning only, this should not stop the build
+CFLAGS += -Wunreachable-code
+CFLAGS += -Wunused
+CFLAGS += -fstrict-aliasing
diff --git a/deps/Unity/extras/memory/test/unity_memory_Test.c b/deps/Unity/extras/memory/test/unity_memory_Test.c
new file mode 100644
index 0000000..6f832e2
--- /dev/null
+++ b/deps/Unity/extras/memory/test/unity_memory_Test.c
@@ -0,0 +1,325 @@
+/* ==========================================
+ * Unity Project - A Test Framework for C
+ * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
+ * [Released under MIT License. Please refer to license.txt for details]
+ * ========================================== */
+
+#include "unity.h"
+#include "unity_memory.h"
+#include "unity_output_Spy.h"
+#include <stdlib.h>
+#include <string.h>
+
+/* This test module includes the following tests: */
+
+void test_ForceMallocFail(void);
+void test_ReallocSmallerIsUnchanged(void);
+void test_ReallocSameIsUnchanged(void);
+void test_ReallocLargerNeeded(void);
+void test_ReallocNullPointerIsLikeMalloc(void);
+void test_ReallocSizeZeroFreesMemAndReturnsNullPointer(void);
+void test_CallocFillsWithZero(void);
+void test_FreeNULLSafety(void);
+void test_DetectsLeak(void);
+void test_BufferOverrunFoundDuringFree(void);
+void test_BufferOverrunFoundDuringRealloc(void);
+void test_BufferGuardWriteFoundDuringFree(void);
+void test_BufferGuardWriteFoundDuringRealloc(void);
+void test_MallocPastBufferFails(void);
+void test_CallocPastBufferFails(void);
+void test_MallocThenReallocGrowsMemoryInPlace(void);
+void test_ReallocFailDoesNotFreeMem(void);
+
+/* It makes use of the following features */
+void setUp(void);
+void tearDown(void);
+
+/* Let's Go! */
+void setUp(void)
+{
+#ifdef UNITY_EXCLUDE_STDLIB_MALLOC
+ UnityOutputCharSpy_Create(200);
+#else
+ UnityOutputCharSpy_Create(1000);
+#endif
+ UnityMalloc_StartTest();
+}
+
+void tearDown(void)
+{
+ UnityMalloc_EndTest();
+ UnityOutputCharSpy_Destroy();
+}
+
+void test_ForceMallocFail(void)
+{
+ void* m;
+ void* mfails;
+ UnityMalloc_MakeMallocFailAfterCount(1);
+ m = malloc(10);
+ TEST_ASSERT_NOT_NULL(m);
+ mfails = malloc(10);
+ TEST_ASSERT_EQUAL_PTR(0, mfails);
+ free(m);
+}
+
+void test_ReallocSmallerIsUnchanged(void)
+{
+ void* m1 = malloc(10);
+ void* m2 = realloc(m1, 5);
+ TEST_ASSERT_NOT_NULL(m1);
+ TEST_ASSERT_EQUAL_PTR(m1, m2);
+ free(m2);
+}
+
+void test_ReallocSameIsUnchanged(void)
+{
+ void* m1 = malloc(10);
+ void* m2 = realloc(m1, 10);
+ TEST_ASSERT_NOT_NULL(m1);
+ TEST_ASSERT_EQUAL_PTR(m1, m2);
+ free(m2);
+}
+
+void test_ReallocLargerNeeded(void)
+{
+ void* m2;
+ void* m1 = malloc(10);
+ TEST_ASSERT_NOT_NULL(m1);
+ strcpy((char*)m1, "123456789");
+ m2 = realloc(m1, 15);
+ TEST_ASSERT_EQUAL_STRING("123456789", m2);
+ free(m2);
+}
+
+void test_ReallocNullPointerIsLikeMalloc(void)
+{
+ void* m = realloc(0, 15);
+ TEST_ASSERT_NOT_NULL(m);
+ free(m);
+}
+
+void test_ReallocSizeZeroFreesMemAndReturnsNullPointer(void)
+{
+ void* m1 = malloc(10);
+ void* m2 = realloc(m1, 0);
+ TEST_ASSERT_EQUAL_PTR(0, m2);
+}
+
+void test_CallocFillsWithZero(void)
+{
+ void* m = calloc(3, sizeof(char));
+ char* s = (char*)m;
+ TEST_ASSERT_NOT_NULL(m);
+ TEST_ASSERT_EQUAL_HEX8(0, s[0]);
+ TEST_ASSERT_EQUAL_HEX8(0, s[1]);
+ TEST_ASSERT_EQUAL_HEX8(0, s[2]);
+ free(m);
+}
+
+void test_FreeNULLSafety(void)
+{
+ free(NULL);
+}
+
+/*------------------------------------------------------------ */
+
+#define EXPECT_ABORT_BEGIN \
+ { \
+ jmp_buf TestAbortFrame; \
+ memcpy(TestAbortFrame, Unity.AbortFrame, sizeof(jmp_buf)); \
+ if (TEST_PROTECT()) \
+ {
+
+#define EXPECT_ABORT_END \
+ } \
+ memcpy(Unity.AbortFrame, TestAbortFrame, sizeof(jmp_buf)); \
+ }
+
+/* This tricky set of defines lets us see if we are using the Spy, returns 1 if true */
+#ifdef __STDC_VERSION__
+
+#ifdef UNITY_SUPPORT_VARIADIC_MACROS
+#define USING_SPY_AS(a) EXPAND_AND_USE_2ND(ASSIGN_VALUE(a), 0)
+#define ASSIGN_VALUE(a) VAL_##a
+#define VAL_UnityOutputCharSpy_OutputChar 0, 1
+#define EXPAND_AND_USE_2ND(a, b) SECOND_PARAM(a, b, throwaway)
+#define SECOND_PARAM(a, b, ...) b
+#if USING_SPY_AS(UNITY_OUTPUT_CHAR)
+ #define USING_OUTPUT_SPY /* UNITY_OUTPUT_CHAR = UnityOutputCharSpy_OutputChar */
+#endif
+#endif /* UNITY_SUPPORT_VARIADIC_MACROS */
+
+#else /* __STDC_VERSION__ else */
+
+#define UnityOutputCharSpy_OutputChar 42
+#if UNITY_OUTPUT_CHAR == UnityOutputCharSpy_OutputChar /* Works if no -Wundef -Werror */
+ #define USING_OUTPUT_SPY
+#endif
+#undef UnityOutputCharSpy_OutputChar
+
+#endif /* __STDC_VERSION__ */
+
+void test_DetectsLeak(void)
+{
+#ifdef USING_OUTPUT_SPY
+ void* m = malloc(10);
+ TEST_ASSERT_NOT_NULL(m);
+ UnityOutputCharSpy_Enable(1);
+ EXPECT_ABORT_BEGIN
+ UnityMalloc_EndTest();
+ EXPECT_ABORT_END
+ UnityOutputCharSpy_Enable(0);
+ Unity.CurrentTestFailed = 0;
+ TEST_ASSERT_NOT_NULL(strstr(UnityOutputCharSpy_Get(), "This test leaks!"));
+ free(m);
+#else
+ TEST_IGNORE_MESSAGE("Enable USING_OUTPUT_SPY To Run This Test");
+#endif
+}
+
+void test_BufferOverrunFoundDuringFree(void)
+{
+#ifdef USING_OUTPUT_SPY
+ void* m = malloc(10);
+ char* s = (char*)m;
+ TEST_ASSERT_NOT_NULL(m);
+ s[10] = (char)0xFF;
+ UnityOutputCharSpy_Enable(1);
+ EXPECT_ABORT_BEGIN
+ free(m);
+ EXPECT_ABORT_END
+ UnityOutputCharSpy_Enable(0);
+ Unity.CurrentTestFailed = 0;
+ TEST_ASSERT_NOT_NULL(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during free()"));
+#else
+ TEST_IGNORE_MESSAGE("Enable USING_OUTPUT_SPY To Run This Test");
+#endif
+}
+
+void test_BufferOverrunFoundDuringRealloc(void)
+{
+#ifdef USING_OUTPUT_SPY
+ void* m = malloc(10);
+ char* s = (char*)m;
+ TEST_ASSERT_NOT_NULL(m);
+ s[10] = (char)0xFF;
+ UnityOutputCharSpy_Enable(1);
+ EXPECT_ABORT_BEGIN
+ m = realloc(m, 100);
+ EXPECT_ABORT_END
+ UnityOutputCharSpy_Enable(0);
+ Unity.CurrentTestFailed = 0;
+ TEST_ASSERT_NOT_NULL(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during realloc()"));
+#else
+ TEST_IGNORE_MESSAGE("Enable USING_OUTPUT_SPY To Run This Test");
+#endif
+}
+
+void test_BufferGuardWriteFoundDuringFree(void)
+{
+#ifdef USING_OUTPUT_SPY
+ void* m = malloc(10);
+ char* s = (char*)m;
+ TEST_ASSERT_NOT_NULL(m);
+ s[-1] = (char)0x00; /* Will not detect 0 */
+ s[-2] = (char)0x01;
+ UnityOutputCharSpy_Enable(1);
+ EXPECT_ABORT_BEGIN
+ free(m);
+ EXPECT_ABORT_END
+ UnityOutputCharSpy_Enable(0);
+ Unity.CurrentTestFailed = 0;
+ TEST_ASSERT_NOT_NULL(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during free()"));
+#else
+ TEST_IGNORE_MESSAGE("Enable USING_OUTPUT_SPY To Run This Test");
+#endif
+}
+
+void test_BufferGuardWriteFoundDuringRealloc(void)
+{
+#ifdef USING_OUTPUT_SPY
+ void* m = malloc(10);
+ char* s = (char*)m;
+ TEST_ASSERT_NOT_NULL(m);
+ s[-1] = (char)0x0A;
+ UnityOutputCharSpy_Enable(1);
+ EXPECT_ABORT_BEGIN
+ m = realloc(m, 100);
+ EXPECT_ABORT_END
+ UnityOutputCharSpy_Enable(0);
+ Unity.CurrentTestFailed = 0;
+ TEST_ASSERT_NOT_NULL(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during realloc()"));
+#else
+ TEST_IGNORE_MESSAGE("Enable USING_OUTPUT_SPY To Run This Test");
+#endif
+}
+
+/*------------------------------------------------------------ */
+
+#define TEST_ASSERT_MEMORY_ALL_FREE_LIFO_ORDER(first_mem_ptr, ptr) \
+ ptr = malloc(10); free(ptr); \
+ TEST_ASSERT_EQUAL_PTR_MESSAGE(first_mem_ptr, ptr, "Memory was stranded, free in LIFO order");
+
+void test_MallocPastBufferFails(void)
+{
+#ifdef UNITY_EXCLUDE_STDLIB_MALLOC
+ void* m = malloc(UNITY_INTERNAL_HEAP_SIZE_BYTES/2 + 1);
+ void* n = malloc(UNITY_INTERNAL_HEAP_SIZE_BYTES/2);
+ free(m);
+ TEST_ASSERT_NOT_NULL(m);
+ TEST_ASSERT_NULL(n);
+ TEST_ASSERT_MEMORY_ALL_FREE_LIFO_ORDER(m, n);
+#else
+ TEST_IGNORE_MESSAGE("Enable UNITY_EXCLUDE_STDLIB_MALLOC to Run This Test");
+#endif
+}
+
+void test_CallocPastBufferFails(void)
+{
+#ifdef UNITY_EXCLUDE_STDLIB_MALLOC
+ void* m = calloc(1, UNITY_INTERNAL_HEAP_SIZE_BYTES/2 + 1);
+ void* n = calloc(1, UNITY_INTERNAL_HEAP_SIZE_BYTES/2);
+ free(m);
+ TEST_ASSERT_NOT_NULL(m);
+ TEST_ASSERT_NULL(n);
+ TEST_ASSERT_MEMORY_ALL_FREE_LIFO_ORDER(m, n);
+#else
+ TEST_IGNORE_MESSAGE("Enable UNITY_EXCLUDE_STDLIB_MALLOC to Run This Test");
+#endif
+}
+
+void test_MallocThenReallocGrowsMemoryInPlace(void)
+{
+#ifdef UNITY_EXCLUDE_STDLIB_MALLOC
+ void* m = malloc(UNITY_INTERNAL_HEAP_SIZE_BYTES/2 + 1);
+ void* n = realloc(m, UNITY_INTERNAL_HEAP_SIZE_BYTES/2 + 9);
+ free(n);
+ TEST_ASSERT_NOT_NULL(m);
+ TEST_ASSERT_EQUAL(m, n);
+ TEST_ASSERT_MEMORY_ALL_FREE_LIFO_ORDER(m, n);
+#else
+ TEST_IGNORE_MESSAGE("Enable UNITY_EXCLUDE_STDLIB_MALLOC to Run This Test");
+#endif
+}
+
+void test_ReallocFailDoesNotFreeMem(void)
+{
+#ifdef UNITY_EXCLUDE_STDLIB_MALLOC
+ void* m = malloc(UNITY_INTERNAL_HEAP_SIZE_BYTES/2);
+ void* n1 = malloc(10);
+ void* out_of_mem = realloc(n1, UNITY_INTERNAL_HEAP_SIZE_BYTES/2 + 1);
+ void* n2 = malloc(10);
+
+ free(n2);
+ if (out_of_mem == NULL) free(n1);
+ free(m);
+
+ TEST_ASSERT_NOT_NULL(m); /* Got a real memory location */
+ TEST_ASSERT_NULL(out_of_mem); /* The realloc should have failed */
+ TEST_ASSERT_NOT_EQUAL(n2, n1); /* If n1 != n2 then realloc did not free n1 */
+ TEST_ASSERT_MEMORY_ALL_FREE_LIFO_ORDER(m, n2);
+#else
+ TEST_IGNORE_MESSAGE("Enable UNITY_EXCLUDE_STDLIB_MALLOC to Run This Test");
+#endif
+}
diff --git a/deps/Unity/extras/memory/test/unity_memory_TestRunner.c b/deps/Unity/extras/memory/test/unity_memory_TestRunner.c
new file mode 100644
index 0000000..4c91a59
--- /dev/null
+++ b/deps/Unity/extras/memory/test/unity_memory_TestRunner.c
@@ -0,0 +1,49 @@
+/* ==========================================
+ * Unity Project - A Test Framework for C
+ * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
+ * [Released under MIT License. Please refer to license.txt for details]
+ * ========================================== */
+
+#include "unity.h"
+#include "unity_memory.h"
+
+extern void test_ForceMallocFail(void);
+extern void test_ReallocSmallerIsUnchanged(void);
+extern void test_ReallocSameIsUnchanged(void);
+extern void test_ReallocLargerNeeded(void);
+extern void test_ReallocNullPointerIsLikeMalloc(void);
+extern void test_ReallocSizeZeroFreesMemAndReturnsNullPointer(void);
+extern void test_CallocFillsWithZero(void);
+extern void test_FreeNULLSafety(void);
+extern void test_DetectsLeak(void);
+extern void test_BufferOverrunFoundDuringFree(void);
+extern void test_BufferOverrunFoundDuringRealloc(void);
+extern void test_BufferGuardWriteFoundDuringFree(void);
+extern void test_BufferGuardWriteFoundDuringRealloc(void);
+extern void test_MallocPastBufferFails(void);
+extern void test_CallocPastBufferFails(void);
+extern void test_MallocThenReallocGrowsMemoryInPlace(void);
+extern void test_ReallocFailDoesNotFreeMem(void);
+
+int main(void)
+{
+ UnityBegin("unity_memory_Test.c");
+ RUN_TEST(test_ForceMallocFail);
+ RUN_TEST(test_ReallocSmallerIsUnchanged);
+ RUN_TEST(test_ReallocSameIsUnchanged);
+ RUN_TEST(test_ReallocLargerNeeded);
+ RUN_TEST(test_ReallocNullPointerIsLikeMalloc);
+ RUN_TEST(test_ReallocSizeZeroFreesMemAndReturnsNullPointer);
+ RUN_TEST(test_CallocFillsWithZero);
+ RUN_TEST(test_FreeNULLSafety);
+ RUN_TEST(test_DetectsLeak);
+ RUN_TEST(test_BufferOverrunFoundDuringFree);
+ RUN_TEST(test_BufferOverrunFoundDuringRealloc);
+ RUN_TEST(test_BufferGuardWriteFoundDuringFree);
+ RUN_TEST(test_BufferGuardWriteFoundDuringRealloc);
+ RUN_TEST(test_MallocPastBufferFails);
+ RUN_TEST(test_CallocPastBufferFails);
+ RUN_TEST(test_MallocThenReallocGrowsMemoryInPlace);
+ RUN_TEST(test_ReallocFailDoesNotFreeMem);
+ return UnityEnd();
+}
diff --git a/deps/Unity/extras/memory/test/unity_output_Spy.c b/deps/Unity/extras/memory/test/unity_output_Spy.c
new file mode 100644
index 0000000..772fe0b
--- /dev/null
+++ b/deps/Unity/extras/memory/test/unity_output_Spy.c
@@ -0,0 +1,56 @@
+/* ==========================================
+ * Unity Project - A Test Framework for C
+ * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
+ * [Released under MIT License. Please refer to license.txt for details]
+ * ========================================== */
+
+#include "unity.h"
+#include "unity_output_Spy.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+static int size;
+static int count;
+static char* buffer;
+static int spy_enable;
+
+void UnityOutputCharSpy_Create(int s)
+{
+ size = (s > 0) ? s : 0;
+ count = 0;
+ spy_enable = 0;
+ buffer = malloc((size_t)size);
+ TEST_ASSERT_NOT_NULL_MESSAGE(buffer, "Internal malloc failed in Spy Create():" __FILE__);
+ memset(buffer, 0, (size_t)size);
+}
+
+void UnityOutputCharSpy_Destroy(void)
+{
+ size = 0;
+ free(buffer);
+}
+
+void UnityOutputCharSpy_OutputChar(int c)
+{
+ if (spy_enable)
+ {
+ if (count < (size-1))
+ buffer[count++] = (char)c;
+ }
+ else
+ {
+ putchar(c);
+ }
+}
+
+const char * UnityOutputCharSpy_Get(void)
+{
+ return buffer;
+}
+
+void UnityOutputCharSpy_Enable(int enable)
+{
+ spy_enable = enable;
+}
diff --git a/deps/Unity/extras/memory/test/unity_output_Spy.h b/deps/Unity/extras/memory/test/unity_output_Spy.h
new file mode 100644
index 0000000..e2e401c
--- /dev/null
+++ b/deps/Unity/extras/memory/test/unity_output_Spy.h
@@ -0,0 +1,16 @@
+/* ==========================================
+ * Unity Project - A Test Framework for C
+ * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
+ * [Released under MIT License. Please refer to license.txt for details]
+ * ========================================== */
+
+#ifndef UNITY_OUTPUT_SPY_H
+#define UNITY_OUTPUT_SPY_H
+
+void UnityOutputCharSpy_Create(int s);
+void UnityOutputCharSpy_Destroy(void);
+void UnityOutputCharSpy_OutputChar(int c);
+const char * UnityOutputCharSpy_Get(void);
+void UnityOutputCharSpy_Enable(int enable);
+
+#endif