summaryrefslogtreecommitdiffstats
path: root/testsuites/sptests/sp2038
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2014-04-27 18:11:09 +1000
committerChris Johns <chrisj@rtems.org>2014-05-22 16:38:01 +1000
commiteae0863a1cf09d5f2f6f6af5df405dc9b727fac5 (patch)
treecc3bc828b32b96ab52a3af260e4e411209a5a488 /testsuites/sptests/sp2038
parentrtems: Simplify rtems_semaphore_obtain() (diff)
downloadrtems-eae0863a1cf09d5f2f6f6af5df405dc9b727fac5.tar.bz2
rtems: Fix sp2038 test.
Avoid using newlib's gmtime_r call which fails with a max signed int. Add an RTEMS specific version for 1/1/1988 to 31/12/2100. Update sp2038 to test every day from 1/1/1988 to 31/12/2100. Only days need be tested as the code splits the seconds based on days.
Diffstat (limited to 'testsuites/sptests/sp2038')
-rw-r--r--testsuites/sptests/sp2038/init.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/testsuites/sptests/sp2038/init.c b/testsuites/sptests/sp2038/init.c
index 9fac38a23c..e5a3906ee6 100644
--- a/testsuites/sptests/sp2038/init.c
+++ b/testsuites/sptests/sp2038/init.c
@@ -283,12 +283,49 @@ static void test_leap_year(void)
rtems_test_assert(test_status == false);
}
+static bool test_year_is_leap_year(uint32_t year)
+{
+ return (((year % 4) == 0) && ((year % 100) != 0)) || ((year % 400) == 0);
+}
+
+static void test_every_day(void)
+{
+ rtems_time_of_day every_day = {
+ .year = 1970,
+ .month = 1,
+ .day = 1,
+ .hour = 0,
+ .minute = 1,
+ .second = 2
+ };
+ const int days_per_month[2][12] = {
+ { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
+ { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
+ };
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_time_of_day now;
+
+ for (every_day.year = 1988; every_day.year <= 2100; ++every_day.year) {
+ int leap_year = test_year_is_leap_year(every_day.year) ? 1 : 0;
+ for (every_day.month = 1; every_day.month <= 12; ++every_day.month) {
+ int days = days_per_month[leap_year][every_day.month - 1];
+ for (every_day.day = 1; every_day.day <= days; ++every_day.day) {
+ sc = rtems_clock_set(&every_day);
+ ASSERT_SC(sc);
+ sc = rtems_clock_get_tod(&now);
+ ASSERT_SC(sc);
+ rtems_test_assert(memcmp(&now, &every_day, sizeof(now)) == 0);
+ }
+ }
+ }
+}
rtems_task Init(rtems_task_argument argument)
{
TEST_BEGIN();
test_tod_to_seconds();
+ test_every_day();
test_problem_year();
test_leap_year();