Skip to content

Commit d770883

Browse files
add ChangeMemPoolTeardownOption to allow a single test to exclude memory 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.
1 parent 566fc02 commit d770883

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

cpputest-for-qpc-lib/include/cms_cpputest_qf_ctrl.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ void Setup(enum_t maxPubSubSignalValue, uint32_t ticksPerSecond,
6262
const MemPoolConfigs& pubSubEventMemPoolConfigs = {},
6363
MemPoolTeardownOption memPoolOpt = MemPoolTeardownOption::CHECK_FOR_LEAKS);
6464

65+
void ChangeMemPoolTeardownOption(MemPoolTeardownOption memPoolOpt);
66+
6567
/// Teardown the QP/QF subsystem after completing a unit test.
6668
void Teardown();
6769

cpputest-for-qpc-lib/src/cms_cpputest_qf_ctrl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ void Teardown()
113113
}
114114
}
115115

116+
void ChangeMemPoolTeardownOption(MemPoolTeardownOption memPoolOpt)
117+
{
118+
l_memPoolOption = memPoolOpt;
119+
}
120+
116121
void ProcessEvents()
117122
{
118123
QF_runUntilNoReadyActiveObjects();

cpputest-for-qpc-lib/tests/cms_cpputest_qf_ctrlTests.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,24 @@ TEST(qf_ctrlTests, setup_provides_option_to_skip_memory_pool_leak_detection)
105105
// teardown.
106106
}
107107

108+
TEST(qf_ctrlTests, provides_modify_memory_pool_leak_detection)
109+
{
110+
//Do a setup with leak detection.
111+
qf_ctrl::Setup(10, 1000, qf_ctrl::MemPoolConfigs {},
112+
qf_ctrl::MemPoolTeardownOption::CHECK_FOR_LEAKS);
113+
114+
//but, this test only wants to disable leak detection, likely because of ASSERT
115+
//testing which may interrupt normal event processing, resulting in false leaks.
116+
qf_ctrl::ChangeMemPoolTeardownOption(qf_ctrl::MemPoolTeardownOption::IGNORE);
117+
118+
// purposeful leak of an allocated QEvt
119+
QEvt* volatile e = Q_NEW(QEvt, 5);
120+
(void)e;
121+
122+
// test should pass, as we disabled the memory pool leak detection during
123+
// teardown.
124+
}
125+
108126
TEST(qf_ctrlTests,
109127
qf_ctrl_provides_for_ability_to_move_time_forward_firing_active_object_timers_as_expected)
110128
{

0 commit comments

Comments
 (0)