Skip to content

Commit

Permalink
[UMM-54] Add multitest.sh for testing builds
Browse files Browse the repository at this point in the history
  • Loading branch information
rhempel committed Aug 21, 2021
1 parent 7405db5 commit 4a2dc90
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 27 deletions.
12 changes: 12 additions & 0 deletions multitest.sh
Original file line number Diff line number Diff line change
@@ -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
9 changes: 2 additions & 7 deletions project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
:test_file_prefix: test_
:default_tasks:
- test:all

:options_paths:
- test/options
#:test_build:
# :use_assembly: TRUE

Expand All @@ -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="<umm_malloc_cfgport.h>"

:test:
- *common_defines
Expand Down
Binary file removed src/.umm_malloc_cfg.h.swo
Binary file not shown.
37 changes: 27 additions & 10 deletions src/umm_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand All @@ -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);
Expand Down
28 changes: 18 additions & 10 deletions src/umm_malloc_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() { \
Expand All @@ -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

/*
Expand Down Expand Up @@ -311,17 +319,17 @@ 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);
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
Expand Down
11 changes: 11 additions & 0 deletions test/options/default.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions test/options/enable_critical_depth_check.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions test/options/enable_info.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions test/options/enable_inline_metrics.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions test/options/enable_integrity_check.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions test/options/enable_poison_check.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions test/options/first_fit.yml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions test/test_Metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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
}

0 comments on commit 4a2dc90

Please sign in to comment.