[31be416] | 1 | /* |
---|
| 2 | * Copyright (c) 2015 embedded brains GmbH. All rights reserved. |
---|
| 3 | * |
---|
| 4 | * embedded brains GmbH |
---|
| 5 | * Dornierstr. 4 |
---|
| 6 | * 82178 Puchheim |
---|
| 7 | * Germany |
---|
| 8 | * <rtems@embedded-brains.de> |
---|
| 9 | * |
---|
| 10 | * The license and distribution terms for this file may be |
---|
| 11 | * found in the file LICENSE in this distribution or at |
---|
| 12 | * http://www.rtems.org/license/LICENSE. |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #ifdef HAVE_CONFIG_H |
---|
| 16 | #include "config.h" |
---|
| 17 | #endif |
---|
| 18 | |
---|
[24d0ee57] | 19 | #include "tmacros.h" |
---|
| 20 | |
---|
[31be416] | 21 | #include <assert.h> |
---|
| 22 | |
---|
| 23 | #include <bsp/bootcard.h> |
---|
| 24 | |
---|
| 25 | #include <rtems/score/timecounterimpl.h> |
---|
[599d71f] | 26 | #include <rtems/score/todimpl.h> |
---|
[31be416] | 27 | #include <rtems/timecounter.h> |
---|
| 28 | #include <rtems/bsd.h> |
---|
| 29 | |
---|
[599d71f] | 30 | const char rtems_test_name[] = "SPTIMECOUNTER 1"; |
---|
[31be416] | 31 | |
---|
| 32 | typedef struct { |
---|
| 33 | struct timecounter tc_soft; |
---|
| 34 | u_int tc_soft_counter; |
---|
| 35 | } test_context; |
---|
| 36 | |
---|
| 37 | static test_context test_instance; |
---|
| 38 | |
---|
| 39 | static uint32_t test_get_timecount_soft(struct timecounter *tc) |
---|
| 40 | { |
---|
| 41 | test_context *ctx = tc->tc_priv; |
---|
| 42 | |
---|
| 43 | ++ctx->tc_soft_counter; |
---|
| 44 | |
---|
| 45 | return ctx->tc_soft_counter; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | void boot_card(const char *cmdline) |
---|
| 49 | { |
---|
| 50 | test_context *ctx = &test_instance; |
---|
| 51 | struct timecounter *tc_soft = &ctx->tc_soft; |
---|
| 52 | uint64_t soft_freq = 1000000; |
---|
| 53 | struct bintime bt; |
---|
[599d71f] | 54 | struct timeval tv; |
---|
| 55 | struct timespec ts; |
---|
[31be416] | 56 | |
---|
[24d0ee57] | 57 | TEST_BEGIN(); |
---|
[31be416] | 58 | |
---|
[599d71f] | 59 | assert(time(NULL) == TOD_SECONDS_1970_THROUGH_1988); |
---|
| 60 | |
---|
| 61 | rtems_bsd_bintime(&bt); |
---|
| 62 | assert(bt.sec == TOD_SECONDS_1970_THROUGH_1988); |
---|
| 63 | assert(bt.frac == 0); |
---|
| 64 | |
---|
| 65 | rtems_bsd_getbintime(&bt); |
---|
| 66 | assert(bt.sec == TOD_SECONDS_1970_THROUGH_1988); |
---|
| 67 | assert(bt.frac == 0); |
---|
| 68 | |
---|
| 69 | rtems_bsd_microtime(&tv); |
---|
| 70 | assert(tv.tv_sec == TOD_SECONDS_1970_THROUGH_1988); |
---|
| 71 | assert(tv.tv_usec == 0); |
---|
| 72 | |
---|
| 73 | rtems_bsd_getmicrotime(&tv); |
---|
| 74 | assert(tv.tv_sec == TOD_SECONDS_1970_THROUGH_1988); |
---|
| 75 | assert(tv.tv_usec == 0); |
---|
| 76 | |
---|
| 77 | rtems_bsd_nanotime(&ts); |
---|
| 78 | assert(ts.tv_sec == TOD_SECONDS_1970_THROUGH_1988); |
---|
| 79 | assert(ts.tv_nsec == 0); |
---|
| 80 | |
---|
| 81 | rtems_bsd_getnanotime(&ts); |
---|
| 82 | assert(ts.tv_sec == TOD_SECONDS_1970_THROUGH_1988); |
---|
| 83 | assert(ts.tv_nsec == 0); |
---|
| 84 | |
---|
| 85 | assert(rtems_clock_get_uptime_seconds() == 0); |
---|
| 86 | assert(rtems_clock_get_uptime_nanoseconds() == 0); |
---|
| 87 | |
---|
[31be416] | 88 | rtems_bsd_binuptime(&bt); |
---|
| 89 | assert(bt.sec == 1); |
---|
[599d71f] | 90 | assert(bt.frac == 0); |
---|
| 91 | |
---|
| 92 | rtems_bsd_getbinuptime(&bt); |
---|
| 93 | assert(bt.sec == 1); |
---|
| 94 | assert(bt.frac == 0); |
---|
| 95 | |
---|
| 96 | rtems_bsd_microuptime(&tv); |
---|
| 97 | assert(tv.tv_sec == 1); |
---|
| 98 | assert(tv.tv_usec == 0); |
---|
| 99 | |
---|
| 100 | rtems_bsd_getmicrouptime(&tv); |
---|
| 101 | assert(tv.tv_sec == 1); |
---|
| 102 | assert(tv.tv_usec == 0); |
---|
| 103 | |
---|
| 104 | rtems_bsd_nanouptime(&ts); |
---|
| 105 | assert(ts.tv_sec == 1); |
---|
| 106 | assert(ts.tv_nsec == 0); |
---|
| 107 | |
---|
| 108 | rtems_bsd_getnanouptime(&ts); |
---|
| 109 | assert(ts.tv_sec == 1); |
---|
| 110 | assert(ts.tv_nsec == 0); |
---|
[31be416] | 111 | |
---|
[599d71f] | 112 | /* On RTEMS time does not advance using the dummy timecounter */ |
---|
[31be416] | 113 | rtems_bsd_binuptime(&bt); |
---|
| 114 | assert(bt.sec == 1); |
---|
| 115 | assert(bt.frac == 0); |
---|
| 116 | |
---|
| 117 | rtems_timecounter_tick(); |
---|
| 118 | rtems_bsd_binuptime(&bt); |
---|
| 119 | assert(bt.sec == 1); |
---|
| 120 | assert(bt.frac == 0); |
---|
| 121 | |
---|
| 122 | ctx->tc_soft_counter = 0; |
---|
| 123 | tc_soft->tc_get_timecount = test_get_timecount_soft; |
---|
| 124 | tc_soft->tc_counter_mask = 0x0fffffff; |
---|
| 125 | tc_soft->tc_frequency = soft_freq; |
---|
| 126 | tc_soft->tc_quality = 1234; |
---|
| 127 | tc_soft->tc_priv = ctx; |
---|
| 128 | _Timecounter_Install(tc_soft); |
---|
| 129 | assert(ctx->tc_soft_counter == 3); |
---|
| 130 | |
---|
| 131 | rtems_bsd_binuptime(&bt); |
---|
| 132 | assert(ctx->tc_soft_counter == 4); |
---|
| 133 | |
---|
| 134 | assert(bt.sec == 1); |
---|
| 135 | assert(bt.frac == 18446744073708); |
---|
| 136 | |
---|
| 137 | ctx->tc_soft_counter = 0xf0000000 | 3; |
---|
| 138 | rtems_bsd_binuptime(&bt); |
---|
| 139 | assert(ctx->tc_soft_counter == (0xf0000000 | 4)); |
---|
| 140 | |
---|
| 141 | assert(bt.sec == 1); |
---|
| 142 | assert(bt.frac == 18446744073708); |
---|
| 143 | |
---|
| 144 | /* Ensure that the fraction overflows and the second remains constant */ |
---|
| 145 | ctx->tc_soft_counter = (0xf0000000 | 3) + soft_freq; |
---|
| 146 | rtems_bsd_binuptime(&bt); |
---|
| 147 | assert(ctx->tc_soft_counter == (0xf0000000 | 4) + soft_freq); |
---|
| 148 | assert(bt.sec == 1); |
---|
| 149 | assert(bt.frac == 18446742522092); |
---|
| 150 | |
---|
[24d0ee57] | 151 | TEST_END(); |
---|
[31be416] | 152 | |
---|
[b6606e8] | 153 | _Terminate(RTEMS_FATAL_SOURCE_EXIT, 0); |
---|
[31be416] | 154 | } |
---|
| 155 | |
---|
| 156 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
| 157 | |
---|
| 158 | #define CONFIGURE_APPLICATION_DISABLE_FILESYSTEM |
---|
| 159 | |
---|
| 160 | #define CONFIGURE_DISABLE_NEWLIB_REENTRANCY |
---|
| 161 | |
---|
| 162 | #define CONFIGURE_SCHEDULER_USER |
---|
| 163 | |
---|
[6fadb7af] | 164 | #define CONFIGURE_SCHEDULER |
---|
[31be416] | 165 | |
---|
[6fadb7af] | 166 | #define CONFIGURE_SCHEDULER_TABLE_ENTRIES { } |
---|
[31be416] | 167 | |
---|
| 168 | #define CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER 0 |
---|
| 169 | |
---|
| 170 | #define CONFIGURE_TASK_STACK_ALLOCATOR NULL |
---|
| 171 | |
---|
| 172 | #define CONFIGURE_TASK_STACK_DEALLOCATOR NULL |
---|
| 173 | |
---|
| 174 | #define CONFIGURE_IDLE_TASK_INITIALIZES_APPLICATION |
---|
| 175 | |
---|
| 176 | #define CONFIGURE_IDLE_TASK_BODY NULL |
---|
| 177 | |
---|
| 178 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
| 179 | |
---|
| 180 | #define CONFIGURE_INIT |
---|
| 181 | |
---|
| 182 | #include <rtems/confdefs.h> |
---|