Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a HAL set_time() test #8094

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions TESTS/mbed_hal/rtc_time/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

utest::v1::status_t teardown_handler_t(const Case *const source, const size_t passed, const size_t failed,
const failure_t reason)
{
Expand Down Expand Up @@ -196,6 +221,7 @@ Case cases[] = {
Case("test make time boundary values - RTC leap years partial support", partial_leap_year_case_setup_handler_t, test_mk_time_boundary, teardown_handler_t),
Case("test make time - invalid param", test_mk_time_invalid_param, teardown_handler_t),
Case("test local time - invalid param", test_local_time_invalid_param, teardown_handler_t),
Case("test set_time twice", test_set_time_twice, teardown_handler_t),
};

utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
Expand Down