From e8305a4210ac8dcf0fa754df0e01474dd136cf9a Mon Sep 17 00:00:00 2001 From: RFulchiero Date: Tue, 11 Sep 2018 17:27:19 -0500 Subject: [PATCH] Add a protected HAL set_time() test When DEVICE_LPTICKER is defined set_time() only works correctly on the first call. This test calls set_time() twice and ensures the time set by both calls is correct. This test only runs if DEVICE_RTC or DEVICE_LPTICKER is defined. --- TESTS/mbed_hal/rtc_time/main.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/TESTS/mbed_hal/rtc_time/main.cpp b/TESTS/mbed_hal/rtc_time/main.cpp index 857d033cd8..c537b02fc6 100644 --- a/TESTS/mbed_hal/rtc_time/main.cpp +++ b/TESTS/mbed_hal/rtc_time/main.cpp @@ -169,6 +169,31 @@ void test_local_time_invalid_param() TEST_ASSERT_EQUAL(false, _rtc_localtime(1, NULL, RTC_4_YEAR_LEAP_YEAR_SUPPORT)); } +/* Test set_time() function called a few seconds apart. + * + * Given is set_time() function. + * When set_time() is used to set the system time two times. + * Then if the value returned from time() is always correct return true, otherwise return false. + */ +#define NEW_TIME 15 +void test_set_time_twice() +{ + time_t current_time; + + /* Set the time to NEW_TIME and check it */ + set_time(NEW_TIME); + current_time = time(NULL); + TEST_ASSERT_EQUAL (true, (current_time == NEW_TIME)); + + /* Wait 2 seconds */ + wait_ms(2000); + + /* set the time to NEW_TIME again and check it */ + set_time(NEW_TIME); + current_time = time(NULL); + TEST_ASSERT_EQUAL (true, (current_time == NEW_TIME)); +} + Case cases[] = { Case("test is leap year - RTC leap years full support", test_is_leap_year), Case("test is leap year - RTC leap years partial support", test_is_leap_year), @@ -176,6 +201,9 @@ Case cases[] = { Case("test make time boundary values - RTC leap years partial support", test_mk_time_boundary), Case("test make time - invalid param", test_mk_time_invalid_param), Case("test local time - invalid param", test_local_time_invalid_param), +#if DEVICE_RTC || DEVICE_LPTICKER + Case("test set_time twice", test_set_time_twice), +#endif }; utest::v1::status_t greentea_test_setup(const size_t number_of_cases)