Skip to content

Commit

Permalink
#45: Better runtime tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aul12 committed Dec 27, 2022
1 parent 0032131 commit 3d6b3ad
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions Tests/LowLevel/Components/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ TEST(TEST_NAME, post_init) {
EXPECT_TRUE(wdtHandle.functionGotCalled<wdt_enable>(WDTO_30MS));
}

TEST(TEST_NAME, timer_runtime_normal) {
TEST(TEST_NAME, timer_runtime_0) {
auto interruptHandle = mock::interrupt.getHandle();
auto wdtHandle = mock::wdt.getHandle();
auto timerHandle = mock::timer8bit.getHandle();
Expand All @@ -80,7 +80,7 @@ TEST(TEST_NAME, timer_runtime_normal) {
EXPECT_TRUE(timerHandle.functionGotCalled<timer_8bit_get_count>());
}

TEST(TEST_NAME, timer_runtime_exception) {
TEST(TEST_NAME, timer_runtime_max) {
auto interruptHandle = mock::interrupt.getHandle();
auto wdtHandle = mock::wdt.getHandle();
auto timerHandle = mock::timer8bit.getHandle();
Expand All @@ -103,6 +103,52 @@ TEST(TEST_NAME, timer_runtime_exception) {
EXPECT_TRUE(errorHandlerHandle.functionGotCalled<error_handler_handle_warning>(SYSTEM, SYSTEM_ERROR_TIMER_RUNTIME));
}

TEST(TEST_NAME, timer_runtime_under_limit) {
auto interruptHandle = mock::interrupt.getHandle();
auto wdtHandle = mock::wdt.getHandle();
auto timerHandle = mock::timer8bit.getHandle();

timer_8bit_callback_t internalCallback = nullptr;
timerHandle.overrideFunc<timer_8bit_init>(
[&internalCallback](timer_8bit_clock_option_t /*clock_option*/, system_timer_callback_t timerCallback) {
internalCallback = timerCallback;
});
// 12/16,384*255=186.767578125
timerHandle.overrideFunc<timer_8bit_get_count>([]() { return 186; });

system_pre_init(timer_callback);
system_post_init();

timer_got_called = false;
internalCallback();
EXPECT_TRUE(timer_got_called);
EXPECT_TRUE(timerHandle.functionGotCalled<timer_8bit_get_count>());
}

TEST(TEST_NAME, timer_runtime_over_limit) {
auto interruptHandle = mock::interrupt.getHandle();
auto wdtHandle = mock::wdt.getHandle();
auto timerHandle = mock::timer8bit.getHandle();
auto errorHandlerHandle = mock::error_handler.getHandle();

timer_8bit_callback_t internalCallback = nullptr;
timerHandle.overrideFunc<timer_8bit_init>(
[&internalCallback](timer_8bit_clock_option_t /*clock_option*/, system_timer_callback_t timerCallback) {
internalCallback = timerCallback;
});
// 12/16,384*255=186.767578125
timerHandle.overrideFunc<timer_8bit_get_count>([]() { return 187; });

system_pre_init(timer_callback);
system_post_init();

timer_got_called = false;
internalCallback();
EXPECT_TRUE(timer_got_called);
EXPECT_TRUE(timerHandle.functionGotCalled<timer_8bit_get_count>());
EXPECT_TRUE(errorHandlerHandle.functionGotCalled<error_handler_handle_warning>(SYSTEM, SYSTEM_ERROR_TIMER_RUNTIME));
}

TEST(TEST_NAME, timer_reset_watchdog) {
auto wdtHandle = mock::wdt.getHandle();
system_reset_watchdog();
Expand Down

0 comments on commit 3d6b3ad

Please sign in to comment.