diff --git a/multitest.sh b/multitest.sh new file mode 100755 index 0000000..92d5414 --- /dev/null +++ b/multitest.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Iterate through the files in test/options and pass them to ceedling + +for filename in test/options/*; do + [ -e "$filename" ] || continue + name=$(basename $filename) + printf "# ---------------------------------------------\n" + printf "# ceedling options:%s clean test\n" ${name%.yml} + printf "# ---------------------------------------------\n" + ceedling options:${name%.yml} clean test +done diff --git a/project.yml b/project.yml index 774bd45..ffaa781 100644 --- a/project.yml +++ b/project.yml @@ -14,7 +14,8 @@ :test_file_prefix: test_ :default_tasks: - test:all - + :options_paths: + - test/options #:test_build: # :use_assembly: TRUE @@ -41,12 +42,6 @@ # 1) remove the trailing [] from the :common: section # 2) add entries to the :common: section (e.g. :test: has TEST defined) :common: &common_defines - - TEST - - UMM_INFO - - UMM_TEST_BUILD - - UMM_INTEGRITY_CHECK - - UMM_POISON_CHECK - - UMM_CFGFILE="" :test: - *common_defines diff --git a/src/.umm_malloc_cfg.h.swo b/src/.umm_malloc_cfg.h.swo deleted file mode 100644 index 574272d..0000000 Binary files a/src/.umm_malloc_cfg.h.swo and /dev/null differ diff --git a/src/umm_info.c b/src/umm_info.c index 0139501..b49999a 100644 --- a/src/umm_info.c +++ b/src/umm_info.c @@ -23,6 +23,24 @@ UMM_HEAP_INFO ummHeapInfo; +void compute_usage_metric(void) +{ + if (0 == ummHeapInfo.freeBlocks) { + ummHeapInfo.usage_metric = -1; // No free blocks! + } else { + ummHeapInfo.usage_metric = (int)((ummHeapInfo.usedBlocks * 100) / (ummHeapInfo.freeBlocks)); + } +} + +void compute_fragmentation_metric(void) +{ + if (0 == ummHeapInfo.freeBlocks) { + ummHeapInfo.fragmentation_metric = 0; // No free blocks ... so no fragmentation either! + } else { + ummHeapInfo.fragmentation_metric = 100 - (((uint32_t)(sqrtf(ummHeapInfo.freeBlocksSquared)) * 100) / (ummHeapInfo.freeBlocks)); + } +} + void *umm_info(void *ptr, bool force) { uint16_t blockNo = 0; @@ -136,15 +154,10 @@ void *umm_info(void *ptr, bool force) { DBGLOG_FORCE(force, "+--------------------------------------------------------------+\n"); - if (0 == ummHeapInfo.freeBlocks) { - ummHeapInfo.usage_metric = -1; // No free blocks! - ummHeapInfo.fragmentation_metric = 0; // ... so no fragmentation either! - } else { - ummHeapInfo.usage_metric = (int)((ummHeapInfo.usedBlocks * 100) / (ummHeapInfo.freeBlocks)); - ummHeapInfo.fragmentation_metric = 100 - (((uint32_t)(sqrtf(ummHeapInfo.freeBlocksSquared)) * 100) / (ummHeapInfo.freeBlocks)); - } - + compute_usage_metric(); DBGLOG_FORCE(force, "Usage Metric: %5i\n", ummHeapInfo.usage_metric); + + compute_fragmentation_metric(); DBGLOG_FORCE(force, "Fragmentation Metric: %5i\n", ummHeapInfo.fragmentation_metric); DBGLOG_FORCE(force, "+--------------------------------------------------------------+\n"); @@ -170,7 +183,9 @@ size_t umm_max_free_block_size(void) { } int umm_usage_metric(void) { - #ifndef UMM_INLINE_METRICS + #ifdef UMM_INLINE_METRICS + compute_usage_metric(); + #else umm_info(NULL, false); #endif DBGLOG_DEBUG("usedBlocks %i totalBlocks %i\n", ummHeapInfo.usedBlocks, ummHeapInfo.totalBlocks); @@ -179,7 +194,9 @@ int umm_usage_metric(void) { } int umm_fragmentation_metric(void) { - #ifndef UMM_INLINE_METRICS + #ifdef UMM_INLINE_METRICS + compute_fragmentation_metric(); + #else umm_info(NULL, false); #endif DBGLOG_DEBUG("freeBlocks %i freeBlocksSquared %i\n", ummHeapInfo.freeBlocks, ummHeapInfo.freeBlocksSquared); diff --git a/src/umm_malloc_cfg.h b/src/umm_malloc_cfg.h index dffb4fa..1c273b5 100644 --- a/src/umm_malloc_cfg.h +++ b/src/umm_malloc_cfg.h @@ -112,10 +112,14 @@ * Set n to a value from 0 to 6 depending on how verbose you want the debug * log to be * - * UMM_TEST_BUILD + * UMM_MAX_CRITICAL_DEPTH_CHECK=n * - * Set this if you want to compile in the test suite - * ---------------------------------------------------------------------------- + * Set this if you want to compile in code to verify that the critical + * section maximum depth is not exceeded. If set, the value must be greater + * than 0. + * + * The critical depth checking is only needed if your target environment + * does not support reading and writing the current interrupt enable state. * * Support for this library in a multitasking environment is provided when * you add bodies to the UMM_CRITICAL_ENTRY and UMM_CRITICAL_EXIT macros @@ -247,7 +251,7 @@ extern int umm_fragmentation_metric(void); * called from within umm_malloc() */ -#ifdef UMM_TEST_BUILD +#ifdef UMM_MAX_CRITICAL_DEPTH_CHECK extern int umm_critical_depth; extern int umm_max_critical_depth; #define UMM_CRITICAL_ENTRY() { \ @@ -258,8 +262,12 @@ extern int umm_max_critical_depth; } #define UMM_CRITICAL_EXIT() (umm_critical_depth--) #else - #define UMM_CRITICAL_ENTRY() - #define UMM_CRITICAL_EXIT() + #ifndef UMM_CRITICAL_ENTRY + #define UMM_CRITICAL_ENTRY() + #endif + #ifndef UMM_CRITICAL_EXIT + #define UMM_CRITICAL_EXIT() + #endif #endif /* @@ -311,9 +319,9 @@ extern void umm_corruption(void); */ #ifdef UMM_POISON_CHECK - #define UMM_POISON_SIZE_BEFORE (4) - #define UMM_POISON_SIZE_AFTER (4) - #define UMM_POISONED_BLOCK_LEN_TYPE uint16_t + #define UMM_POISON_SIZE_BEFORE (4) + #define UMM_POISON_SIZE_AFTER (4) + #define UMM_POISONED_BLOCK_LEN_TYPE uint16_t extern void *umm_poison_malloc(size_t size); extern void *umm_poison_calloc(size_t num, size_t size); @@ -321,7 +329,7 @@ extern void *umm_poison_realloc(void *ptr, size_t size); extern void umm_poison_free(void *ptr); extern bool umm_poison_check(void); - #define POISON_CHECK() umm_poison_check() + #define POISON_CHECK() umm_poison_check() #else #define POISON_CHECK() (1) #endif diff --git a/test/options/default.yml b/test/options/default.yml new file mode 100644 index 0000000..d0cd4c1 --- /dev/null +++ b/test/options/default.yml @@ -0,0 +1,11 @@ +:defines: + # in order to add common defines: + # 1) remove the trailing [] from the :common: section + # 2) add entries to the :common: section (e.g. :test: has TEST defined) + :common: &common_defines + + :test: + - *common_defines + + :test_preprocess: + - *common_defines diff --git a/test/options/enable_critical_depth_check.yml b/test/options/enable_critical_depth_check.yml new file mode 100644 index 0000000..313028e --- /dev/null +++ b/test/options/enable_critical_depth_check.yml @@ -0,0 +1,12 @@ +:defines: + # in order to add common defines: + # 1) remove the trailing [] from the :common: section + # 2) add entries to the :common: section (e.g. :test: has TEST defined) + :common: &common_defines + - UMM_MAX_CRITICAL_DEPTH_CHECK + + :test: + - *common_defines + + :test_preprocess: + - *common_defines diff --git a/test/options/enable_info.yml b/test/options/enable_info.yml new file mode 100644 index 0000000..88d600e --- /dev/null +++ b/test/options/enable_info.yml @@ -0,0 +1,12 @@ +:defines: + # in order to add common defines: + # 1) remove the trailing [] from the :common: section + # 2) add entries to the :common: section (e.g. :test: has TEST defined) + :common: &common_defines + - UMM_INFO + + :test: + - *common_defines + + :test_preprocess: + - *common_defines diff --git a/test/options/enable_inline_metrics.yml b/test/options/enable_inline_metrics.yml new file mode 100644 index 0000000..0263ed7 --- /dev/null +++ b/test/options/enable_inline_metrics.yml @@ -0,0 +1,12 @@ +:defines: + # in order to add common defines: + # 1) remove the trailing [] from the :common: section + # 2) add entries to the :common: section (e.g. :test: has TEST defined) + :common: &common_defines + - UMM_INLINE_METRICS + + :test: + - *common_defines + + :test_preprocess: + - *common_defines diff --git a/test/options/enable_integrity_check.yml b/test/options/enable_integrity_check.yml new file mode 100644 index 0000000..f4f0eba --- /dev/null +++ b/test/options/enable_integrity_check.yml @@ -0,0 +1,12 @@ +:defines: + # in order to add common defines: + # 1) remove the trailing [] from the :common: section + # 2) add entries to the :common: section (e.g. :test: has TEST defined) + :common: &common_defines + - UMM_INTEGRITY_CHECK + + :test: + - *common_defines + + :test_preprocess: + - *common_defines diff --git a/test/options/enable_poison_check.yml b/test/options/enable_poison_check.yml new file mode 100644 index 0000000..a707f55 --- /dev/null +++ b/test/options/enable_poison_check.yml @@ -0,0 +1,12 @@ +:defines: + # in order to add common defines: + # 1) remove the trailing [] from the :common: section + # 2) add entries to the :common: section (e.g. :test: has TEST defined) + :common: &common_defines + - UMM_POISON_CHECK + + :test: + - *common_defines + + :test_preprocess: + - *common_defines diff --git a/test/options/first_fit.yml b/test/options/first_fit.yml new file mode 100644 index 0000000..43e14ee --- /dev/null +++ b/test/options/first_fit.yml @@ -0,0 +1,12 @@ +:defines: + # in order to add common defines: + # 1) remove the trailing [] from the :common: section + # 2) add entries to the :common: section (e.g. :test: has TEST defined) + :common: &common_defines + - UMM_FIRST_FIT + + :test: + - *common_defines + + :test_preprocess: + - *common_defines diff --git a/test/test_Metrics.c b/test/test_Metrics.c index 568b5dd..f4f3220 100644 --- a/test/test_Metrics.c +++ b/test/test_Metrics.c @@ -49,8 +49,10 @@ void testMetricsEmpty(void) { #ifdef UMM_INLINE_METRICS TEST_ASSERT_EQUAL(0, umm_fragmentation_metric()); #endif + #ifdef UMM_INFO umm_info(0, false); TEST_ASSERT_EQUAL(0, umm_fragmentation_metric()); + #endif } void testMetricsFull(void) { @@ -66,8 +68,10 @@ void testMetricsFull(void) { #ifdef UMM_INLINE_METRICS TEST_ASSERT_EQUAL(0, umm_fragmentation_metric()); #endif + #ifdef UMM_INFO umm_info(0, false); TEST_ASSERT_EQUAL(0, umm_fragmentation_metric()); + #endif } void testMetricsSparseFull(void) { @@ -87,8 +91,10 @@ void testMetricsSparseFull(void) { #ifdef UMM_INLINE_METRICS TEST_ASSERT_EQUAL(99, umm_fragmentation_metric()); #endif + #ifdef UMM_INFO umm_info(0, false); TEST_ASSERT_EQUAL(99, umm_fragmentation_metric()); + #endif } void testMetricsSparse7of8(void) { @@ -108,8 +114,10 @@ void testMetricsSparse7of8(void) { #ifdef UMM_INLINE_METRICS TEST_ASSERT_EQUAL(78, umm_fragmentation_metric()); #endif + #ifdef UMM_INFO umm_info(0, false); TEST_ASSERT_EQUAL(78, umm_fragmentation_metric()); + #endif } void testMetricsSparse3of4(void) { @@ -129,8 +137,10 @@ void testMetricsSparse3of4(void) { #ifdef UMM_INLINE_METRICS TEST_ASSERT_EQUAL(61, umm_fragmentation_metric()); #endif + #ifdef UMM_INFO umm_info(0, false); TEST_ASSERT_EQUAL(61, umm_fragmentation_metric()); + #endif } void testMetricsSparse1of2(void) { @@ -150,8 +160,10 @@ void testMetricsSparse1of2(void) { #ifdef UMM_INLINE_METRICS TEST_ASSERT_EQUAL(34, umm_fragmentation_metric()); #endif + #ifdef UMM_INFO umm_info(0, false); TEST_ASSERT_EQUAL(34, umm_fragmentation_metric()); + #endif } void testMetricsSparse1of4(void) { @@ -171,8 +183,10 @@ void testMetricsSparse1of4(void) { #ifdef UMM_INLINE_METRICS TEST_ASSERT_EQUAL(15, umm_fragmentation_metric()); #endif + #ifdef UMM_INFO umm_info(0, false); TEST_ASSERT_EQUAL(15, umm_fragmentation_metric()); + #endif } void testMetricsSparse1of8(void) { @@ -192,6 +206,8 @@ void testMetricsSparse1of8(void) { #ifdef UMM_INLINE_METRICS TEST_ASSERT_EQUAL(7, umm_fragmentation_metric()); #endif + #ifdef UMM_INFO umm_info(0, false); TEST_ASSERT_EQUAL(7, umm_fragmentation_metric()); + #endif }