File indexing completed on 2025-05-11 08:24:35
0001 #include <rtems/test.h>
0002
0003 T_TEST_CASE(time_to_string)
0004 {
0005 T_time_string ts;
0006 T_time t;
0007 uint32_t s;
0008 uint32_t ns;
0009
0010 t = T_seconds_and_nanoseconds_to_time(0, 123456789);
0011 T_eq_str(T_time_to_string_ns(t, ts), "0.123456789");
0012 T_eq_str(T_time_to_string_us(t, ts), "0.123456");
0013 T_eq_str(T_time_to_string_ms(t, ts), "0.123");
0014 T_eq_str(T_time_to_string_s(t, ts), "0");
0015
0016 T_time_to_seconds_and_nanoseconds(t, &s, &ns);
0017 T_eq_u32(s, 0);
0018 T_eq_u32(ns, 123456789);
0019 }
0020
0021 T_TEST_CASE(now)
0022 {
0023 T_time_string ts;
0024 T_time t0;
0025 T_time t1;
0026
0027 t0 = T_now();
0028 t1 = T_now();
0029 T_log(T_QUIET, "%s", T_time_to_string_ns(t1 - t0, ts));
0030 }
0031
0032 T_TEST_CASE(tick)
0033 {
0034 T_ticks t;
0035 uint64_t i;
0036
0037 t = T_tick();
0038 i = 0;
0039
0040 do {
0041 ++i;
0042 } while (T_tick() == t);
0043
0044 T_gt_u64(i, 0);
0045 }
0046
0047 T_TEST_CASE(time)
0048 {
0049 T_time_string ts;
0050 T_time t;
0051 uint32_t s;
0052 uint32_t ns;
0053
0054 t = T_seconds_and_nanoseconds_to_time(1, 123456789);
0055 T_eq_str(T_time_to_string_ns(t, ts), "1.123456789");
0056 T_eq_str(T_time_to_string_us(t, ts), "1.123456");
0057 T_eq_str(T_time_to_string_ms(t, ts), "1.123");
0058 T_eq_str(T_time_to_string_s(t, ts), "1");
0059
0060 t = T_seconds_and_nanoseconds_to_time(1, 0);
0061 T_eq_str(T_time_to_string_ns(t, ts), "1.000000000");
0062 T_time_to_seconds_and_nanoseconds(t, &s, &ns);
0063 T_eq_u32(s, 1);
0064 T_eq_u32(ns, 0);
0065
0066 t = T_seconds_and_nanoseconds_to_time(1, 1);
0067 T_eq_str(T_time_to_string_ns(t, ts), "1.000000001");
0068 T_time_to_seconds_and_nanoseconds(t, &s, &ns);
0069 T_eq_u32(s, 1);
0070 T_eq_u32(ns, 1);
0071
0072 t = T_seconds_and_nanoseconds_to_time(1, 2);
0073 T_eq_str(T_time_to_string_ns(t, ts), "1.000000002");
0074 T_time_to_seconds_and_nanoseconds(t, &s, &ns);
0075 T_eq_u32(s, 1);
0076 T_eq_u32(ns, 2);
0077
0078 t = T_seconds_and_nanoseconds_to_time(1, 3);
0079 T_eq_str(T_time_to_string_ns(t, ts), "1.000000003");
0080 T_time_to_seconds_and_nanoseconds(t, &s, &ns);
0081 T_eq_u32(s, 1);
0082 T_eq_u32(ns, 3);
0083
0084 t = T_seconds_and_nanoseconds_to_time(1, 4);
0085 T_eq_str(T_time_to_string_ns(t, ts), "1.000000004");
0086 T_time_to_seconds_and_nanoseconds(t, &s, &ns);
0087 T_eq_u32(s, 1);
0088 T_eq_u32(ns, 4);
0089
0090 t = T_seconds_and_nanoseconds_to_time(1, 5);
0091 T_eq_str(T_time_to_string_ns(t, ts), "1.000000005");
0092 T_time_to_seconds_and_nanoseconds(t, &s, &ns);
0093 T_eq_u32(s, 1);
0094 T_eq_u32(ns, 5);
0095
0096 t = T_seconds_and_nanoseconds_to_time(1, 6);
0097 T_eq_str(T_time_to_string_ns(t, ts), "1.000000006");
0098 T_time_to_seconds_and_nanoseconds(t, &s, &ns);
0099 T_eq_u32(s, 1);
0100 T_eq_u32(ns, 6);
0101
0102 t = T_seconds_and_nanoseconds_to_time(1, 7);
0103 T_eq_str(T_time_to_string_ns(t, ts), "1.000000007");
0104 T_time_to_seconds_and_nanoseconds(t, &s, &ns);
0105 T_eq_u32(s, 1);
0106 T_eq_u32(ns, 7);
0107
0108 t = T_seconds_and_nanoseconds_to_time(1, 8);
0109 T_eq_str(T_time_to_string_ns(t, ts), "1.000000008");
0110 T_time_to_seconds_and_nanoseconds(t, &s, &ns);
0111 T_eq_u32(s, 1);
0112 T_eq_u32(ns, 8);
0113
0114 t = T_seconds_and_nanoseconds_to_time(1, 9);
0115 T_eq_str(T_time_to_string_ns(t, ts), "1.000000009");
0116 T_time_to_seconds_and_nanoseconds(t, &s, &ns);
0117 T_eq_u32(s, 1);
0118 T_eq_u32(ns, 9);
0119
0120 t = T_seconds_and_nanoseconds_to_time(1, 10);
0121 T_eq_str(T_time_to_string_ns(t, ts), "1.000000010");
0122 T_time_to_seconds_and_nanoseconds(t, &s, &ns);
0123 T_eq_u32(s, 1);
0124 T_eq_u32(ns, 10);
0125
0126 t = T_seconds_and_nanoseconds_to_time(1, 999999999);
0127 T_eq_str(T_time_to_string_ns(t, ts), "1.999999999");
0128 T_time_to_seconds_and_nanoseconds(t, &s, &ns);
0129 T_eq_u32(s, 1);
0130 T_eq_u32(ns, 999999999);
0131 }
0132
0133 T_TEST_CASE(ticks)
0134 {
0135 T_time_string ts;
0136 T_time t;
0137 T_time r;
0138 T_ticks k;
0139 uint64_t f;
0140 uint32_t s;
0141 uint32_t ns;
0142 uint32_t m;
0143 size_t n;
0144
0145 t = T_seconds_and_nanoseconds_to_time(1, 0);
0146 f = T_time_to_ticks(t);
0147 T_gt_u64(f, 0);
0148
0149 r = T_ticks_to_time(1);
0150 T_time_to_seconds_and_nanoseconds(r, &s, &ns);
0151 T_eq_u32(s, 0);
0152 T_ne_u32(ns, 0);
0153
0154 n = 1;
0155 m = 10;
0156
0157 do {
0158 if ((ns + m / 2) / m == 0) {
0159 break;
0160 }
0161
0162 ++n;
0163 m *= 10;
0164 } while (n < 10);
0165
0166 n = 10 - n;
0167
0168 t = T_seconds_and_nanoseconds_to_time(1, 100000000);
0169 k = T_time_to_ticks(t);
0170
0171 n += 2;
0172 T_eq_nstr(T_ticks_to_string_ns(k, ts), "1.100000000", n);
0173 T_eq_nstr(T_ticks_to_string_us(k, ts), "1.100000", n);
0174 T_eq_nstr(T_ticks_to_string_ms(k, ts), "1.100", n);
0175 T_eq_str(T_ticks_to_string_s(k, ts), "1");
0176 }
0177
0178 T_TEST_CASE(begin_time)
0179 {
0180 T_time_string ts;
0181 T_time t0;
0182 T_time t1;
0183 T_time d;
0184
0185 t1 = T_now();
0186 t0 = T_case_begin_time();
0187 d = t1 - t0;
0188 T_log(T_QUIET, "time at test case begin %s",
0189 T_time_to_string_ns(d, ts));
0190 }
0191
0192 #include "t-self-test.h"
0193
0194 T_TEST_OUTPUT(time_to_string,
0195 "B:time_to_string\n"
0196 "P:0:0:UI1:test-time.c:11\n"
0197 "P:1:0:UI1:test-time.c:12\n"
0198 "P:2:0:UI1:test-time.c:13\n"
0199 "P:3:0:UI1:test-time.c:14\n"
0200 "P:4:0:UI1:test-time.c:17\n"
0201 "P:5:0:UI1:test-time.c:18\n"
0202 "E:time_to_string:N:6:F:0:D:0.001000\n");
0203
0204 T_TEST_OUTPUT(now,
0205 "B:now\n"
0206 "L:0.001000000\n"
0207 "E:now:N:0:F:0:D:0.003000\n");
0208
0209 T_TEST_OUTPUT(tick,
0210 "B:tick\n"
0211 "P:0:0:UI1:test-time.c:44\n"
0212 "E:tick:N:1:F:0:D:0.001000\n");
0213
0214 T_TEST_OUTPUT(time,
0215 "B:time\n"
0216 "P:0:0:UI1:test-time.c:55\n"
0217 "P:1:0:UI1:test-time.c:56\n"
0218 "P:2:0:UI1:test-time.c:57\n"
0219 "P:3:0:UI1:test-time.c:58\n"
0220 "P:4:0:UI1:test-time.c:61\n"
0221 "P:5:0:UI1:test-time.c:63\n"
0222 "P:6:0:UI1:test-time.c:64\n"
0223 "P:7:0:UI1:test-time.c:67\n"
0224 "P:8:0:UI1:test-time.c:69\n"
0225 "P:9:0:UI1:test-time.c:70\n"
0226 "P:10:0:UI1:test-time.c:73\n"
0227 "P:11:0:UI1:test-time.c:75\n"
0228 "P:12:0:UI1:test-time.c:76\n"
0229 "P:13:0:UI1:test-time.c:79\n"
0230 "P:14:0:UI1:test-time.c:81\n"
0231 "P:15:0:UI1:test-time.c:82\n"
0232 "P:16:0:UI1:test-time.c:85\n"
0233 "P:17:0:UI1:test-time.c:87\n"
0234 "P:18:0:UI1:test-time.c:88\n"
0235 "P:19:0:UI1:test-time.c:91\n"
0236 "P:20:0:UI1:test-time.c:93\n"
0237 "P:21:0:UI1:test-time.c:94\n"
0238 "P:22:0:UI1:test-time.c:97\n"
0239 "P:23:0:UI1:test-time.c:99\n"
0240 "P:24:0:UI1:test-time.c:100\n"
0241 "P:25:0:UI1:test-time.c:103\n"
0242 "P:26:0:UI1:test-time.c:105\n"
0243 "P:27:0:UI1:test-time.c:106\n"
0244 "P:28:0:UI1:test-time.c:109\n"
0245 "P:29:0:UI1:test-time.c:111\n"
0246 "P:30:0:UI1:test-time.c:112\n"
0247 "P:31:0:UI1:test-time.c:115\n"
0248 "P:32:0:UI1:test-time.c:117\n"
0249 "P:33:0:UI1:test-time.c:118\n"
0250 "P:34:0:UI1:test-time.c:121\n"
0251 "P:35:0:UI1:test-time.c:123\n"
0252 "P:36:0:UI1:test-time.c:124\n"
0253 "P:37:0:UI1:test-time.c:127\n"
0254 "P:38:0:UI1:test-time.c:129\n"
0255 "P:39:0:UI1:test-time.c:130\n"
0256 "E:time:N:40:F:0:D:0.001000\n");
0257
0258 T_TEST_OUTPUT(ticks,
0259 "B:ticks\n"
0260 "P:0:0:UI1:test-time.c:147\n"
0261 "P:1:0:UI1:test-time.c:151\n"
0262 "P:2:0:UI1:test-time.c:152\n"
0263 "P:3:0:UI1:test-time.c:172\n"
0264 "P:4:0:UI1:test-time.c:173\n"
0265 "P:5:0:UI1:test-time.c:174\n"
0266 "P:6:0:UI1:test-time.c:175\n"
0267 "E:ticks:N:7:F:0:D:0.001000\n");
0268
0269 T_TEST_OUTPUT(begin_time,
0270 "B:begin_time\n"
0271 "L:time at test case begin 0.001000000\n"
0272 "E:begin_time:N:0:F:0:D:0.002000\n");
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310