Skip to content

Commit

Permalink
Update HostTests to show heap allocation stats and elapsed times for …
Browse files Browse the repository at this point in the history
…tests

Add `getTotal()` and `resetTotal()` to malloc count
  • Loading branch information
mikee47 committed Nov 7, 2019
1 parent 3bdf5f6 commit aa99573
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Sming/Components/malloc_count/include/malloc_count.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ size_t getPeak(void);
*/
void resetPeak(void);

/**
* @brief Get the total cumulative memory allocation
*/
size_t getTotal(void);

/**
* @brief Reset the total cumulative memory allocation to zero
*/
void resetTotal(void);

/**
* @brief Get the total number of allocations
*/
Expand Down
10 changes: 10 additions & 0 deletions Sming/Components/malloc_count/malloc_count.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ void resetPeak()
stats.peak = stats.current;
}

size_t getTotal()
{
return stats.total;
}

void resetTotal()
{
stats.total = 0;
}

/* user function to return total number of allocations */
size_t getAllocCount()
{
Expand Down
10 changes: 9 additions & 1 deletion tests/HostTests/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Vector<TestGroupFactory> groupFactories;
static SimpleTimer taskTimer;
static unsigned taskIndex;
static NanoTime::Time<uint32_t> totalTestTime(NanoTime::Milliseconds, 0);

#define XX(t) extern void REGISTER_TEST(t);
TEST_MAP(XX)
Expand All @@ -32,6 +33,10 @@ static void runNextGroup()
{
if(taskIndex >= groupFactories.count()) {
m_printf("\r\n\nTESTS COMPLETE\r\n\n");
m_printf("Heap allocations: %u, total: %u bytes, peak: %u, current: %u\r\n", MallocCount::getAllocCount(),
MallocCount::getTotal(), MallocCount::getPeak(), MallocCount::getCurrent());
m_printf("Total test time: %s\r\n\n", totalTestTime.value().toString().c_str());
totalTestTime.time = 0;
#if RESTART_DELAY == 0
System.restart();
#else
Expand All @@ -48,6 +53,7 @@ static void runNextGroup()
void TestGroup::commenceTest()
{
m_printf(_F("\r\n\r\n** Test Group: %s (%u of %u)**\r\n\r\n"), name.c_str(), taskIndex, groupFactories.count());
groupTimer.start();
state = State::running;
execute();
if(state != State::pending) {
Expand All @@ -62,10 +68,12 @@ void TestGroup::startItem(const String& tag)

void TestGroup::complete()
{
auto elapsed = groupTimer.elapsedTime();
totalTestTime += elapsed;
if(state == State::failed) {
m_printf(_F("\r\n!!!! Test Group '%s' FAILED !!!!\r\n\r\n"), name.c_str());
} else {
m_printf(_F("\r\n** Test Group '%s' OK **\r\n"), name.c_str());
m_printf(_F("\r\n** Test Group '%s' OK ** Elapsed: %s\r\n"), name.c_str(), elapsed.toString().c_str());
}
delete this;
taskTimer.setIntervalMs<TEST_GROUP_INTERVAL>();
Expand Down
1 change: 1 addition & 0 deletions tests/HostTests/app/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class TestGroup
failed,
};
State state = State::idle;
OneShotFastUs groupTimer;
};

#define startTest(s) startItem(_F(s))
Expand Down

0 comments on commit aa99573

Please sign in to comment.