From 31b1255663a37f879d009b48151511a8361eb6d8 Mon Sep 17 00:00:00 2001 From: Andrew Burks Date: Tue, 30 Jun 2015 15:24:39 -0700 Subject: [PATCH 1/2] Fixes #3: unity_fixture tests don't build. unity.c and unity_fixture_malloc_overrides.h neglected to include even though the reference 'size_t' and 'NULL'. --- extras/fixture/src/unity_fixture_malloc_overrides.h | 2 ++ src/unity.c | 1 + 2 files changed, 3 insertions(+) diff --git a/extras/fixture/src/unity_fixture_malloc_overrides.h b/extras/fixture/src/unity_fixture_malloc_overrides.h index 1e10014..a19c1ea 100644 --- a/extras/fixture/src/unity_fixture_malloc_overrides.h +++ b/extras/fixture/src/unity_fixture_malloc_overrides.h @@ -8,6 +8,8 @@ #ifndef UNITY_FIXTURE_MALLOC_OVERRIDES_H_ #define UNITY_FIXTURE_MALLOC_OVERRIDES_H_ +#include + #define malloc unity_malloc #define calloc unity_calloc #define realloc unity_realloc diff --git a/src/unity.c b/src/unity.c index 4da60f8..b79f27a 100644 --- a/src/unity.c +++ b/src/unity.c @@ -5,6 +5,7 @@ ============================================================================ */ #include "unity.h" +#include #define UNITY_FAIL_AND_BAIL { Unity.CurrentTestFailed = 1; longjmp(Unity.AbortFrame, 1); } #define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; longjmp(Unity.AbortFrame, 1); } From 7737fee444c227a81d6e841947a7af6a34ea9818 Mon Sep 17 00:00:00 2001 From: Andrew Burks Date: Tue, 30 Jun 2015 15:32:57 -0700 Subject: [PATCH 2/2] Fixes #116: Allow overrides of the Unity Fixture's memory functions. This enables custom heap implementations to be used with the Unity Fixture. --- extras/fixture/src/unity_fixture.c | 4 ++-- .../src/unity_fixture_malloc_overrides.h | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/extras/fixture/src/unity_fixture.c b/extras/fixture/src/unity_fixture.c index 575f9e9..01d3ae6 100644 --- a/extras/fixture/src/unity_fixture.c +++ b/extras/fixture/src/unity_fixture.c @@ -196,7 +196,7 @@ void * unity_malloc(size_t size) malloc_count++; - guard = (Guard*)malloc(size + sizeof(Guard) + 4); + guard = (Guard*)UNITY_FIXTURE_MALLOC(size + sizeof(Guard) + 4); guard->size = size; mem = (char*)&(guard[1]); memcpy(&mem[size], end, strlen(end) + 1); @@ -219,7 +219,7 @@ static void release_memory(void * mem) guard--; malloc_count--; - free(guard); + UNITY_FIXTURE_FREE(guard); } void unity_free(void * mem) diff --git a/extras/fixture/src/unity_fixture_malloc_overrides.h b/extras/fixture/src/unity_fixture_malloc_overrides.h index a19c1ea..27b9884 100644 --- a/extras/fixture/src/unity_fixture_malloc_overrides.h +++ b/extras/fixture/src/unity_fixture_malloc_overrides.h @@ -10,6 +10,28 @@ #include +// This function is used by the Unity Fixture to allocate memory on +// the heap and can be overridden with platform-specific heap +// implementations. For example, when using FreeRTOS +// UNITY_FIXTURE_MALLOC becomes pvPortMalloc(). + +#ifndef UNITY_FIXTURE_MALLOC + #define UNITY_FIXTURE_MALLOC( SIZE ) malloc( ( SIZE ) ) +#else + extern void * UNITY_FIXTURE_MALLOC(size_t size); +#endif + +// This function is used by the Unity Fixture to release memory in the +// heap and can be overridden with platform-specific heap +// implementations. For example, when using FreeRTOS +// UNITY_FIXTURE_FREE becomes vPortFree(). + +#ifndef UNITY_FIXTURE_FREE + #define UNITY_FIXTURE_FREE( PTR ) free( ( PTR ) ) +#else + extern void UNITY_FIXTURE_FREE(void *ptr); +#endif + #define malloc unity_malloc #define calloc unity_calloc #define realloc unity_realloc