Skip to content

Commit

Permalink
add ChangeMemPoolTeardownOption to allow a single test to exclude mem…
Browse files Browse the repository at this point in the history
…ory pool leak detection.

Typically needed when testing an assert associated with a dynamic event. The assert will interrupt all event processing resulting in a false-leak detection event.
  • Loading branch information
mattheweshleman committed Jun 22, 2024
1 parent 566fc02 commit d770883
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cpputest-for-qpc-lib/include/cms_cpputest_qf_ctrl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ void Setup(enum_t maxPubSubSignalValue, uint32_t ticksPerSecond,
const MemPoolConfigs& pubSubEventMemPoolConfigs = {},
MemPoolTeardownOption memPoolOpt = MemPoolTeardownOption::CHECK_FOR_LEAKS);

void ChangeMemPoolTeardownOption(MemPoolTeardownOption memPoolOpt);

/// Teardown the QP/QF subsystem after completing a unit test.
void Teardown();

Expand Down
5 changes: 5 additions & 0 deletions cpputest-for-qpc-lib/src/cms_cpputest_qf_ctrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ void Teardown()
}
}

void ChangeMemPoolTeardownOption(MemPoolTeardownOption memPoolOpt)
{
l_memPoolOption = memPoolOpt;
}

void ProcessEvents()
{
QF_runUntilNoReadyActiveObjects();
Expand Down
18 changes: 18 additions & 0 deletions cpputest-for-qpc-lib/tests/cms_cpputest_qf_ctrlTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ TEST(qf_ctrlTests, setup_provides_option_to_skip_memory_pool_leak_detection)
// teardown.
}

TEST(qf_ctrlTests, provides_modify_memory_pool_leak_detection)
{
//Do a setup with leak detection.
qf_ctrl::Setup(10, 1000, qf_ctrl::MemPoolConfigs {},
qf_ctrl::MemPoolTeardownOption::CHECK_FOR_LEAKS);

//but, this test only wants to disable leak detection, likely because of ASSERT
//testing which may interrupt normal event processing, resulting in false leaks.
qf_ctrl::ChangeMemPoolTeardownOption(qf_ctrl::MemPoolTeardownOption::IGNORE);

// purposeful leak of an allocated QEvt
QEvt* volatile e = Q_NEW(QEvt, 5);
(void)e;

// test should pass, as we disabled the memory pool leak detection during
// teardown.
}

TEST(qf_ctrlTests,
qf_ctrl_provides_for_ability_to_move_time_forward_firing_active_object_timers_as_expected)
{
Expand Down

0 comments on commit d770883

Please sign in to comment.