From 4a2dc90817d61b502746d74a02b71f66b523b962 Mon Sep 17 00:00:00 2001 From: Ralph Hempel Date: Sat, 21 Aug 2021 15:37:55 +0200 Subject: [PATCH] [UMM-54] Add multitest.sh for testing builds --- multitest.sh | 12 ++++++ project.yml | 9 +---- src/.umm_malloc_cfg.h.swo | Bin 16384 -> 0 bytes src/umm_info.c | 37 ++++++++++++++----- src/umm_malloc_cfg.h | 28 +++++++++----- test/options/default.yml | 11 ++++++ test/options/enable_critical_depth_check.yml | 12 ++++++ test/options/enable_info.yml | 12 ++++++ test/options/enable_inline_metrics.yml | 12 ++++++ test/options/enable_integrity_check.yml | 12 ++++++ test/options/enable_poison_check.yml | 12 ++++++ test/options/first_fit.yml | 12 ++++++ test/test_Metrics.c | 16 ++++++++ 13 files changed, 158 insertions(+), 27 deletions(-) create mode 100755 multitest.sh delete mode 100644 src/.umm_malloc_cfg.h.swo create mode 100644 test/options/default.yml create mode 100644 test/options/enable_critical_depth_check.yml create mode 100644 test/options/enable_info.yml create mode 100644 test/options/enable_inline_metrics.yml create mode 100644 test/options/enable_integrity_check.yml create mode 100644 test/options/enable_poison_check.yml create mode 100644 test/options/first_fit.yml 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 574272d6e37d3f8cbec1d52979c2c7ab0d212991..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeHNO>87b6>i8MKM5OlQ6vsXW%j_vvd7sUMXP`i{u$e?*fT48oRx{9*_!U^>599% zI@Q%Xo)v@>Kamg@Bo2sh3dcwYi35mSa#%zZDY?P{#EBaxB%~xHe6PC3Gxj?es^tZU(OeuY5lUbSm;vWOU}tPsNM) zfLBHoXATQqbOx7hX!X2^Otn9YBQ8H|$XPfh9Jp-PBkIF!8lEvVW z;OdpjPtcT$U!G$Z&hLHH*?yd7z%$?(@C0*)Y z`x7U=KX9LKyW`KFIRCyopS$CKJ8}L#_xpbL-E$Y1T*n>uU!DQafM>un;2H1?cm_NJ zo&nE*XTUSy8So5z3=Hr%2)+ut@6wGp{{KI@|NqyyAov~d8=wMi0zKeiAOPO`9OeLj z1%40Q1%3tm9C!)%0q|YmI&dC12i$!m2<`v}KnlzOe|$IyUIu;&Yy%GgZ+sRufjhtm zm7@I7D^_#*Ha@Ybh-;D^9Vz#&ir*MKho zp9lW=P!RkB_ysTm3=jdgfJcEhAB1h-HQ=|vw}3Ga0k?n)z~3K$Z$JtNU<(L=2Y}b{ z(BnlQ0&W4{02uHk;6dO%;MaISk^=j{W55OA13Z*@4|o;m1LuKr!28G*q=BKOdJ}`*>yG;8yqNwo=lXgSin?67h*$U zFipUjLL|~Km5{Yv9Bn*dBVJ&H!hj=JGr@1;7b}&lRN=f}T&uc>ncz`6b0u<)EbeV@ z_iuE=-EOD9y4hZR+8y4_)Tn~1BB~AiVliUoMn;HnY<-NliBkA4v{t%eTG%r$)G|8A z#y0Yt9|%^7q7wG!KqN{FrVwsoDClC$Qo&26KmknSB8%i7B5eZ4YcU5*7BQTt@NEy$ zg#XOLZJ}i{#suDQXfJ~dR3ZmyE{I5Jjl|B-5O#X)jh(Q!e~bynEJvHmosE9D-rwtl zov;@!Z-w7%uaPV6JRLplJPjeCh(b8ubFMGaP0GVXNF-wHba!GSzk?=Z$W-3-FhJ-~2Ew&GN<$Me}EInl6Y+ZdA zpAuy9Ox_VOYYvBUX~f!glkIfq|N!| zDMw9p=KN6RbZF$Nk%ZX6y@=5Z zC_8T9s?eDx^1+CPVDjK1_B0|{gzn=xXKyOQW*iM8@$(G36X@rt4BbuyMWJQf_%kz? zws`b@t_w~z!{9$HG**7LfZ(PRD$#X#cnB}1GJeXEN|9iRqK3_|;t966h9#O301DAR zXoqAQF*IFjN&R%ZU^fabq^m94`s#8*h}{WM8-_2m8AC}=-y){hhD)UlULA%nS6b`_ zWINe9(UgK?nM_qiL9?U49I16hN8usGv%0>q9@-r-yL{Zv$!S=U?g{glsfHTz2x^@~ zNk3^?T~-F!$tR?@SXf{U@7m~y~G zjLNcNJyIj>c+fW@tc^qJpIYV3wt*5s+Xq=V(&;j}$Q3#+7*<#Zpj^ATXtr0)ezu1; zffbQ3)BGEaRY%U#2IS;ErD>4O`joouK}qu!+$ZFv8PCm8t~Ai=V1$+#sOe6u1L& z7g;^tc#x(UuNK)_*NUONh8<9EGu&k)X|}S@u$f<*Bi`x${{`I7zfAY_xc|qksQvr} zzh49B833L88Q?#j0ndPEz%$?(@CTogr&|G+HG-~04} lo?RS0^>F{gUGMI!wlCo+BmVufz*?==<0nVZe@c!I_&1d~9WDR> 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 }