Skip to content

Commit 968e270

Browse files
Filip Jagodzinski0xc0170
authored andcommitted
Watchdog: Fix unittests
Compare get_timeout against the last timeout successfully set. Merge most of the test cases into one. Do not rely on the tests execution order. Fix the watchdog_api_stub to keep timeout value set by init function.
1 parent dc4d4a3 commit 968e270

File tree

2 files changed

+8
-24
lines changed

2 files changed

+8
-24
lines changed

UNITTESTS/drivers/Watchdog/test_watchdog.cpp

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,16 @@ class TestWatchdog : public testing::Test {
3535
};
3636
// *INDENT-ON*
3737

38-
TEST_F(TestWatchdog, test_watchdog_start_pass)
39-
{
40-
EXPECT_TRUE(Watchdog::get_instance().start());
41-
}
42-
43-
TEST_F(TestWatchdog, test_watchdog_start_fail)
44-
{
45-
EXPECT_FALSE(Watchdog::get_instance().start());
46-
}
47-
48-
TEST_F(TestWatchdog, test_watchdog_stop_pass)
38+
TEST_F(TestWatchdog, test_watchdog_start_stop_get_timeout)
4939
{
40+
EXPECT_TRUE(Watchdog::get_instance().start(500));
41+
EXPECT_FALSE(Watchdog::get_instance().start(2000));
5042
EXPECT_TRUE(Watchdog::get_instance().stop());
51-
}
52-
53-
TEST_F(TestWatchdog, test_watchdog_stop_fail)
54-
{
5543
EXPECT_FALSE(Watchdog::get_instance().stop());
44+
EXPECT_EQ(500, Watchdog::get_instance().get_timeout());
5645
}
5746

5847
TEST_F(TestWatchdog, test_watchdog_get_max_timeout)
5948
{
6049
EXPECT_EQ(0xFFFFFFFF, Watchdog::get_instance().get_max_timeout());
6150
}
62-
63-
64-
TEST_F(TestWatchdog, test_watchdog_get_timeout)
65-
{
66-
EXPECT_EQ(Watchdog::watchdog_timeout, Watchdog::get_instance().get_timeout());
67-
}
68-

UNITTESTS/stubs/watchdog_api_stub.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@
1717

1818
#if DEVICE_WATCHDOG
1919

20+
static uint32_t _timeout = 0;
21+
2022
watchdog_status_t hal_watchdog_init(const watchdog_config_t *config)
2123
{
24+
_timeout = config->timeout_ms;
2225
return WATCHDOG_STATUS_OK;
2326
}
2427

@@ -34,10 +37,9 @@ watchdog_status_t hal_watchdog_stop(void)
3437

3538
uint32_t hal_watchdog_get_reload_value(void)
3639
{
37-
return (500);
40+
return _timeout;
3841
}
3942

40-
4143
watchdog_features_t hal_watchdog_get_platform_features(void)
4244
{
4345
watchdog_features_t features;

0 commit comments

Comments
 (0)