]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-time-util.c
pkgconfig: define variables relative to ${prefix}/${rootprefix}/${sysconfdir}
[thirdparty/systemd.git] / src / test / test-time-util.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include "random-util.h"
4 #include "serialize.h"
5 #include "string-util.h"
6 #include "strv.h"
7 #include "time-util.h"
8
9 static void test_parse_sec(void) {
10 usec_t u;
11
12 log_info("/* %s */", __func__);
13
14 assert_se(parse_sec("5s", &u) >= 0);
15 assert_se(u == 5 * USEC_PER_SEC);
16 assert_se(parse_sec("5s500ms", &u) >= 0);
17 assert_se(u == 5 * USEC_PER_SEC + 500 * USEC_PER_MSEC);
18 assert_se(parse_sec(" 5s 500ms ", &u) >= 0);
19 assert_se(u == 5 * USEC_PER_SEC + 500 * USEC_PER_MSEC);
20 assert_se(parse_sec(" 5.5s ", &u) >= 0);
21 assert_se(u == 5 * USEC_PER_SEC + 500 * USEC_PER_MSEC);
22 assert_se(parse_sec(" 5.5s 0.5ms ", &u) >= 0);
23 assert_se(u == 5 * USEC_PER_SEC + 500 * USEC_PER_MSEC + 500);
24 assert_se(parse_sec(" .22s ", &u) >= 0);
25 assert_se(u == 220 * USEC_PER_MSEC);
26 assert_se(parse_sec(" .50y ", &u) >= 0);
27 assert_se(u == USEC_PER_YEAR / 2);
28 assert_se(parse_sec("2.5", &u) >= 0);
29 assert_se(u == 2500 * USEC_PER_MSEC);
30 assert_se(parse_sec(".7", &u) >= 0);
31 assert_se(u == 700 * USEC_PER_MSEC);
32 assert_se(parse_sec("23us", &u) >= 0);
33 assert_se(u == 23);
34 assert_se(parse_sec("23µs", &u) >= 0);
35 assert_se(u == 23);
36 assert_se(parse_sec("infinity", &u) >= 0);
37 assert_se(u == USEC_INFINITY);
38 assert_se(parse_sec(" infinity ", &u) >= 0);
39 assert_se(u == USEC_INFINITY);
40 assert_se(parse_sec("+3.1s", &u) >= 0);
41 assert_se(u == 3100 * USEC_PER_MSEC);
42 assert_se(parse_sec("3.1s.2", &u) >= 0);
43 assert_se(u == 3300 * USEC_PER_MSEC);
44 assert_se(parse_sec("3.1 .2", &u) >= 0);
45 assert_se(u == 3300 * USEC_PER_MSEC);
46 assert_se(parse_sec("3.1 sec .2 sec", &u) >= 0);
47 assert_se(u == 3300 * USEC_PER_MSEC);
48 assert_se(parse_sec("3.1 sec 1.2 sec", &u) >= 0);
49 assert_se(u == 4300 * USEC_PER_MSEC);
50
51 assert_se(parse_sec(" xyz ", &u) < 0);
52 assert_se(parse_sec("", &u) < 0);
53 assert_se(parse_sec(" . ", &u) < 0);
54 assert_se(parse_sec(" 5. ", &u) < 0);
55 assert_se(parse_sec(".s ", &u) < 0);
56 assert_se(parse_sec("-5s ", &u) < 0);
57 assert_se(parse_sec("-0.3s ", &u) < 0);
58 assert_se(parse_sec("-0.0s ", &u) < 0);
59 assert_se(parse_sec("-0.-0s ", &u) < 0);
60 assert_se(parse_sec("0.-0s ", &u) < 0);
61 assert_se(parse_sec("3.-0s ", &u) < 0);
62 assert_se(parse_sec(" infinity .7", &u) < 0);
63 assert_se(parse_sec(".3 infinity", &u) < 0);
64 assert_se(parse_sec("3.+1s", &u) < 0);
65 assert_se(parse_sec("3. 1s", &u) < 0);
66 assert_se(parse_sec("3.s", &u) < 0);
67 assert_se(parse_sec("12.34.56", &u) < 0);
68 assert_se(parse_sec("12..34", &u) < 0);
69 assert_se(parse_sec("..1234", &u) < 0);
70 assert_se(parse_sec("1234..", &u) < 0);
71 }
72
73 static void test_parse_sec_fix_0(void) {
74 usec_t u;
75
76 log_info("/* %s */", __func__);
77
78 assert_se(parse_sec_fix_0("5s", &u) >= 0);
79 assert_se(u == 5 * USEC_PER_SEC);
80 assert_se(parse_sec_fix_0("0s", &u) >= 0);
81 assert_se(u == USEC_INFINITY);
82 assert_se(parse_sec_fix_0("0", &u) >= 0);
83 assert_se(u == USEC_INFINITY);
84 assert_se(parse_sec_fix_0(" 0", &u) >= 0);
85 assert_se(u == USEC_INFINITY);
86 }
87
88 static void test_parse_time(void) {
89 usec_t u;
90
91 log_info("/* %s */", __func__);
92
93 assert_se(parse_time("5", &u, 1) >= 0);
94 assert_se(u == 5);
95
96 assert_se(parse_time("5", &u, USEC_PER_MSEC) >= 0);
97 assert_se(u == 5 * USEC_PER_MSEC);
98
99 assert_se(parse_time("5", &u, USEC_PER_SEC) >= 0);
100 assert_se(u == 5 * USEC_PER_SEC);
101
102 assert_se(parse_time("5s", &u, 1) >= 0);
103 assert_se(u == 5 * USEC_PER_SEC);
104
105 assert_se(parse_time("5s", &u, USEC_PER_SEC) >= 0);
106 assert_se(u == 5 * USEC_PER_SEC);
107
108 assert_se(parse_time("5s", &u, USEC_PER_MSEC) >= 0);
109 assert_se(u == 5 * USEC_PER_SEC);
110
111 assert_se(parse_time("11111111111111y", &u, 1) == -ERANGE);
112 assert_se(parse_time("1.1111111111111y", &u, 1) >= 0);
113 }
114
115 static void test_parse_nsec(void) {
116 nsec_t u;
117
118 log_info("/* %s */", __func__);
119
120 assert_se(parse_nsec("5s", &u) >= 0);
121 assert_se(u == 5 * NSEC_PER_SEC);
122 assert_se(parse_nsec("5s500ms", &u) >= 0);
123 assert_se(u == 5 * NSEC_PER_SEC + 500 * NSEC_PER_MSEC);
124 assert_se(parse_nsec(" 5s 500ms ", &u) >= 0);
125 assert_se(u == 5 * NSEC_PER_SEC + 500 * NSEC_PER_MSEC);
126 assert_se(parse_nsec(" 5.5s ", &u) >= 0);
127 assert_se(u == 5 * NSEC_PER_SEC + 500 * NSEC_PER_MSEC);
128 assert_se(parse_nsec(" 5.5s 0.5ms ", &u) >= 0);
129 assert_se(u == 5 * NSEC_PER_SEC + 500 * NSEC_PER_MSEC + 500 * NSEC_PER_USEC);
130 assert_se(parse_nsec(" .22s ", &u) >= 0);
131 assert_se(u == 220 * NSEC_PER_MSEC);
132 assert_se(parse_nsec(" .50y ", &u) >= 0);
133 assert_se(u == NSEC_PER_YEAR / 2);
134 assert_se(parse_nsec("2.5", &u) >= 0);
135 assert_se(u == 2);
136 assert_se(parse_nsec(".7", &u) >= 0);
137 assert_se(u == 0);
138 assert_se(parse_nsec("infinity", &u) >= 0);
139 assert_se(u == NSEC_INFINITY);
140 assert_se(parse_nsec(" infinity ", &u) >= 0);
141 assert_se(u == NSEC_INFINITY);
142 assert_se(parse_nsec("+3.1s", &u) >= 0);
143 assert_se(u == 3100 * NSEC_PER_MSEC);
144 assert_se(parse_nsec("3.1s.2", &u) >= 0);
145 assert_se(u == 3100 * NSEC_PER_MSEC);
146 assert_se(parse_nsec("3.1 .2s", &u) >= 0);
147 assert_se(u == 200 * NSEC_PER_MSEC + 3);
148 assert_se(parse_nsec("3.1 sec .2 sec", &u) >= 0);
149 assert_se(u == 3300 * NSEC_PER_MSEC);
150 assert_se(parse_nsec("3.1 sec 1.2 sec", &u) >= 0);
151 assert_se(u == 4300 * NSEC_PER_MSEC);
152
153 assert_se(parse_nsec(" xyz ", &u) < 0);
154 assert_se(parse_nsec("", &u) < 0);
155 assert_se(parse_nsec(" . ", &u) < 0);
156 assert_se(parse_nsec(" 5. ", &u) < 0);
157 assert_se(parse_nsec(".s ", &u) < 0);
158 assert_se(parse_nsec(" infinity .7", &u) < 0);
159 assert_se(parse_nsec(".3 infinity", &u) < 0);
160 assert_se(parse_nsec("-5s ", &u) < 0);
161 assert_se(parse_nsec("-0.3s ", &u) < 0);
162 assert_se(parse_nsec("-0.0s ", &u) < 0);
163 assert_se(parse_nsec("-0.-0s ", &u) < 0);
164 assert_se(parse_nsec("0.-0s ", &u) < 0);
165 assert_se(parse_nsec("3.-0s ", &u) < 0);
166 assert_se(parse_nsec(" infinity .7", &u) < 0);
167 assert_se(parse_nsec(".3 infinity", &u) < 0);
168 assert_se(parse_nsec("3.+1s", &u) < 0);
169 assert_se(parse_nsec("3. 1s", &u) < 0);
170 assert_se(parse_nsec("3.s", &u) < 0);
171 assert_se(parse_nsec("12.34.56", &u) < 0);
172 assert_se(parse_nsec("12..34", &u) < 0);
173 assert_se(parse_nsec("..1234", &u) < 0);
174 assert_se(parse_nsec("1234..", &u) < 0);
175 assert_se(parse_nsec("1111111111111y", &u) == -ERANGE);
176 assert_se(parse_nsec("1.111111111111y", &u) >= 0);
177 }
178
179 static void test_format_timespan_one(usec_t x, usec_t accuracy) {
180 char l[FORMAT_TIMESPAN_MAX];
181 const char *t;
182 usec_t y;
183
184 log_info(USEC_FMT" (at accuracy "USEC_FMT")", x, accuracy);
185
186 assert_se(t = format_timespan(l, sizeof l, x, accuracy));
187 log_info(" = <%s>", t);
188
189 assert_se(parse_sec(t, &y) >= 0);
190 log_info(" = "USEC_FMT, y);
191
192 if (accuracy <= 0)
193 accuracy = 1;
194
195 assert_se(x / accuracy == y / accuracy);
196 }
197
198 static void test_format_timespan(usec_t accuracy) {
199 log_info("/* %s accuracy="USEC_FMT" */", __func__, accuracy);
200
201 test_format_timespan_one(0, accuracy);
202 test_format_timespan_one(1, accuracy);
203 test_format_timespan_one(1*USEC_PER_SEC, accuracy);
204 test_format_timespan_one(999*USEC_PER_MSEC, accuracy);
205 test_format_timespan_one(1234567, accuracy);
206 test_format_timespan_one(12, accuracy);
207 test_format_timespan_one(123, accuracy);
208 test_format_timespan_one(1234, accuracy);
209 test_format_timespan_one(12345, accuracy);
210 test_format_timespan_one(123456, accuracy);
211 test_format_timespan_one(1234567, accuracy);
212 test_format_timespan_one(12345678, accuracy);
213 test_format_timespan_one(1200000, accuracy);
214 test_format_timespan_one(1230000, accuracy);
215 test_format_timespan_one(1230000, accuracy);
216 test_format_timespan_one(1234000, accuracy);
217 test_format_timespan_one(1234500, accuracy);
218 test_format_timespan_one(1234560, accuracy);
219 test_format_timespan_one(1234567, accuracy);
220 test_format_timespan_one(986087, accuracy);
221 test_format_timespan_one(500 * USEC_PER_MSEC, accuracy);
222 test_format_timespan_one(9*USEC_PER_YEAR/5 - 23, accuracy);
223 test_format_timespan_one(USEC_INFINITY, accuracy);
224 }
225
226 static void test_timezone_is_valid(void) {
227 log_info("/* %s */", __func__);
228
229 assert_se(timezone_is_valid("Europe/Berlin", LOG_ERR));
230 assert_se(timezone_is_valid("Australia/Sydney", LOG_ERR));
231 assert_se(!timezone_is_valid("Europe/Do not exist", LOG_ERR));
232 }
233
234 static void test_get_timezones(void) {
235 _cleanup_strv_free_ char **zones = NULL;
236 int r;
237 char **zone;
238
239 log_info("/* %s */", __func__);
240
241 r = get_timezones(&zones);
242 assert_se(r == 0);
243
244 STRV_FOREACH(zone, zones)
245 assert_se(timezone_is_valid(*zone, LOG_ERR));
246 }
247
248 static void test_usec_add(void) {
249 log_info("/* %s */", __func__);
250
251 assert_se(usec_add(0, 0) == 0);
252 assert_se(usec_add(1, 4) == 5);
253 assert_se(usec_add(USEC_INFINITY, 5) == USEC_INFINITY);
254 assert_se(usec_add(5, USEC_INFINITY) == USEC_INFINITY);
255 assert_se(usec_add(USEC_INFINITY-5, 2) == USEC_INFINITY-3);
256 assert_se(usec_add(USEC_INFINITY-2, 2) == USEC_INFINITY);
257 assert_se(usec_add(USEC_INFINITY-1, 2) == USEC_INFINITY);
258 assert_se(usec_add(USEC_INFINITY, 2) == USEC_INFINITY);
259 }
260
261 static void test_usec_sub_unsigned(void) {
262 log_info("/* %s */", __func__);
263
264 assert_se(usec_sub_unsigned(0, 0) == 0);
265 assert_se(usec_sub_unsigned(0, 2) == 0);
266 assert_se(usec_sub_unsigned(0, USEC_INFINITY) == 0);
267 assert_se(usec_sub_unsigned(1, 0) == 1);
268 assert_se(usec_sub_unsigned(1, 1) == 0);
269 assert_se(usec_sub_unsigned(1, 2) == 0);
270 assert_se(usec_sub_unsigned(1, 3) == 0);
271 assert_se(usec_sub_unsigned(1, USEC_INFINITY) == 0);
272 assert_se(usec_sub_unsigned(USEC_INFINITY-1, 0) == USEC_INFINITY-1);
273 assert_se(usec_sub_unsigned(USEC_INFINITY-1, 1) == USEC_INFINITY-2);
274 assert_se(usec_sub_unsigned(USEC_INFINITY-1, 2) == USEC_INFINITY-3);
275 assert_se(usec_sub_unsigned(USEC_INFINITY-1, USEC_INFINITY-2) == 1);
276 assert_se(usec_sub_unsigned(USEC_INFINITY-1, USEC_INFINITY-1) == 0);
277 assert_se(usec_sub_unsigned(USEC_INFINITY-1, USEC_INFINITY) == 0);
278 assert_se(usec_sub_unsigned(USEC_INFINITY, 0) == USEC_INFINITY);
279 assert_se(usec_sub_unsigned(USEC_INFINITY, 1) == USEC_INFINITY);
280 assert_se(usec_sub_unsigned(USEC_INFINITY, 2) == USEC_INFINITY);
281 assert_se(usec_sub_unsigned(USEC_INFINITY, USEC_INFINITY) == USEC_INFINITY);
282 }
283
284 static void test_usec_sub_signed(void) {
285 log_info("/* %s */", __func__);
286
287 assert_se(usec_sub_signed(0, 0) == 0);
288 assert_se(usec_sub_signed(4, 1) == 3);
289 assert_se(usec_sub_signed(4, 4) == 0);
290 assert_se(usec_sub_signed(4, 5) == 0);
291 assert_se(usec_sub_signed(USEC_INFINITY-3, -3) == USEC_INFINITY);
292 assert_se(usec_sub_signed(USEC_INFINITY-3, -3) == USEC_INFINITY);
293 assert_se(usec_sub_signed(USEC_INFINITY-3, -4) == USEC_INFINITY);
294 assert_se(usec_sub_signed(USEC_INFINITY-3, -5) == USEC_INFINITY);
295 assert_se(usec_sub_signed(USEC_INFINITY, 5) == USEC_INFINITY);
296 }
297
298 static void test_format_timestamp(void) {
299 unsigned i;
300
301 log_info("/* %s */", __func__);
302
303 for (i = 0; i < 100; i++) {
304 char buf[MAX(FORMAT_TIMESTAMP_MAX, FORMAT_TIMESPAN_MAX)];
305 usec_t x, y;
306
307 random_bytes(&x, sizeof(x));
308 x = x % (2147483600 * USEC_PER_SEC) + 1;
309
310 assert_se(format_timestamp(buf, sizeof(buf), x));
311 log_info("%s", buf);
312 assert_se(parse_timestamp(buf, &y) >= 0);
313 assert_se(x / USEC_PER_SEC == y / USEC_PER_SEC);
314
315 assert_se(format_timestamp_utc(buf, sizeof(buf), x));
316 log_info("%s", buf);
317 assert_se(parse_timestamp(buf, &y) >= 0);
318 assert_se(x / USEC_PER_SEC == y / USEC_PER_SEC);
319
320 assert_se(format_timestamp_us(buf, sizeof(buf), x));
321 log_info("%s", buf);
322 assert_se(parse_timestamp(buf, &y) >= 0);
323 assert_se(x == y);
324
325 assert_se(format_timestamp_us_utc(buf, sizeof(buf), x));
326 log_info("%s", buf);
327 assert_se(parse_timestamp(buf, &y) >= 0);
328 assert_se(x == y);
329
330 assert_se(format_timestamp_relative(buf, sizeof(buf), x));
331 log_info("%s", buf);
332 assert_se(parse_timestamp(buf, &y) >= 0);
333
334 /* The two calls above will run with a slightly different local time. Make sure we are in the same
335 * range however, but give enough leeway that this is unlikely to explode. And of course,
336 * format_timestamp_relative() scales the accuracy with the distance from the current time up to one
337 * month, cover for that too. */
338 assert_se(y > x ? y - x : x - y <= USEC_PER_MONTH + USEC_PER_DAY);
339 }
340 }
341
342 static void test_format_timestamp_utc_one(usec_t val, const char *result) {
343 char buf[FORMAT_TIMESTAMP_MAX];
344 const char *t;
345
346 t = format_timestamp_utc(buf, sizeof(buf), val);
347 assert_se(streq_ptr(t, result));
348 }
349
350 static void test_format_timestamp_utc(void) {
351 log_info("/* %s */", __func__);
352
353 test_format_timestamp_utc_one(0, NULL);
354 test_format_timestamp_utc_one(1, "Thu 1970-01-01 00:00:00 UTC");
355 test_format_timestamp_utc_one(USEC_PER_SEC, "Thu 1970-01-01 00:00:01 UTC");
356
357 #if SIZEOF_TIME_T == 8
358 test_format_timestamp_utc_one(USEC_TIMESTAMP_FORMATTABLE_MAX, "Thu 9999-12-30 23:59:59 UTC");
359 test_format_timestamp_utc_one(USEC_TIMESTAMP_FORMATTABLE_MAX + 1, "--- XXXX-XX-XX XX:XX:XX");
360 #elif SIZEOF_TIME_T == 4
361 test_format_timestamp_utc_one(USEC_TIMESTAMP_FORMATTABLE_MAX, "Tue 2038-01-19 03:14:07 UTC");
362 test_format_timestamp_utc_one(USEC_TIMESTAMP_FORMATTABLE_MAX + 1, "--- XXXX-XX-XX XX:XX:XX");
363 #endif
364
365 test_format_timestamp_utc_one(USEC_INFINITY, NULL);
366 }
367
368 static void test_deserialize_dual_timestamp(void) {
369 int r;
370 dual_timestamp t;
371
372 log_info("/* %s */", __func__);
373
374 r = deserialize_dual_timestamp("1234 5678", &t);
375 assert_se(r == 0);
376 assert_se(t.realtime == 1234);
377 assert_se(t.monotonic == 5678);
378
379 r = deserialize_dual_timestamp("1234x 5678", &t);
380 assert_se(r == -EINVAL);
381
382 r = deserialize_dual_timestamp("1234 5678y", &t);
383 assert_se(r == -EINVAL);
384
385 r = deserialize_dual_timestamp("-1234 5678", &t);
386 assert_se(r == -EINVAL);
387
388 r = deserialize_dual_timestamp("1234 -5678", &t);
389 assert_se(r == -EINVAL);
390
391 /* Check that output wasn't modified. */
392 assert_se(t.realtime == 1234);
393 assert_se(t.monotonic == 5678);
394
395 r = deserialize_dual_timestamp("+123 567", &t);
396 assert_se(r == 0);
397 assert_se(t.realtime == 123);
398 assert_se(t.monotonic == 567);
399
400 /* Check that we get "infinity" on overflow. */
401 r = deserialize_dual_timestamp("18446744073709551617 0", &t);
402 assert_se(r == 0);
403 assert_se(t.realtime == USEC_INFINITY);
404 assert_se(t.monotonic == 0);
405 }
406
407 static void assert_similar(usec_t a, usec_t b) {
408 usec_t d;
409
410 if (a > b)
411 d = a - b;
412 else
413 d = b - a;
414
415 assert(d < 10*USEC_PER_SEC);
416 }
417
418 static void test_usec_shift_clock(void) {
419 usec_t rt, mn, bt;
420
421 log_info("/* %s */", __func__);
422
423 rt = now(CLOCK_REALTIME);
424 mn = now(CLOCK_MONOTONIC);
425 bt = now(clock_boottime_or_monotonic());
426
427 assert_se(usec_shift_clock(USEC_INFINITY, CLOCK_REALTIME, CLOCK_MONOTONIC) == USEC_INFINITY);
428
429 assert_similar(usec_shift_clock(rt + USEC_PER_HOUR, CLOCK_REALTIME, CLOCK_MONOTONIC), mn + USEC_PER_HOUR);
430 assert_similar(usec_shift_clock(rt + 2*USEC_PER_HOUR, CLOCK_REALTIME, clock_boottime_or_monotonic()), bt + 2*USEC_PER_HOUR);
431 assert_se(usec_shift_clock(rt + 3*USEC_PER_HOUR, CLOCK_REALTIME, CLOCK_REALTIME_ALARM) == rt + 3*USEC_PER_HOUR);
432
433 assert_similar(usec_shift_clock(mn + 4*USEC_PER_HOUR, CLOCK_MONOTONIC, CLOCK_REALTIME_ALARM), rt + 4*USEC_PER_HOUR);
434 assert_similar(usec_shift_clock(mn + 5*USEC_PER_HOUR, CLOCK_MONOTONIC, clock_boottime_or_monotonic()), bt + 5*USEC_PER_HOUR);
435 assert_se(usec_shift_clock(mn + 6*USEC_PER_HOUR, CLOCK_MONOTONIC, CLOCK_MONOTONIC) == mn + 6*USEC_PER_HOUR);
436
437 assert_similar(usec_shift_clock(bt + 7*USEC_PER_HOUR, clock_boottime_or_monotonic(), CLOCK_MONOTONIC), mn + 7*USEC_PER_HOUR);
438 assert_similar(usec_shift_clock(bt + 8*USEC_PER_HOUR, clock_boottime_or_monotonic(), CLOCK_REALTIME_ALARM), rt + 8*USEC_PER_HOUR);
439 assert_se(usec_shift_clock(bt + 9*USEC_PER_HOUR, clock_boottime_or_monotonic(), clock_boottime_or_monotonic()) == bt + 9*USEC_PER_HOUR);
440
441 if (mn > USEC_PER_MINUTE) {
442 assert_similar(usec_shift_clock(rt - 30 * USEC_PER_SEC, CLOCK_REALTIME_ALARM, CLOCK_MONOTONIC), mn - 30 * USEC_PER_SEC);
443 assert_similar(usec_shift_clock(rt - 50 * USEC_PER_SEC, CLOCK_REALTIME, clock_boottime_or_monotonic()), bt - 50 * USEC_PER_SEC);
444 }
445 }
446
447 static void test_in_utc_timezone(void) {
448 log_info("/* %s */", __func__);
449
450 assert_se(setenv("TZ", ":UTC", 1) >= 0);
451 assert_se(in_utc_timezone());
452 assert_se(streq(tzname[0], "UTC"));
453 assert_se(streq(tzname[1], "UTC"));
454 assert_se(timezone == 0);
455 assert_se(daylight == 0);
456
457 assert_se(setenv("TZ", "Europe/Berlin", 1) >= 0);
458 assert_se(!in_utc_timezone());
459 assert_se(streq(tzname[0], "CET"));
460 assert_se(streq(tzname[1], "CEST"));
461
462 assert_se(unsetenv("TZ") >= 0);
463 }
464
465 int main(int argc, char *argv[]) {
466 uintmax_t x;
467
468 log_info("realtime=" USEC_FMT "\n"
469 "monotonic=" USEC_FMT "\n"
470 "boottime=" USEC_FMT "\n",
471 now(CLOCK_REALTIME),
472 now(CLOCK_MONOTONIC),
473 now(clock_boottime_or_monotonic()));
474
475 test_parse_sec();
476 test_parse_sec_fix_0();
477 test_parse_time();
478 test_parse_nsec();
479 test_format_timespan(1);
480 test_format_timespan(USEC_PER_MSEC);
481 test_format_timespan(USEC_PER_SEC);
482 test_timezone_is_valid();
483 test_get_timezones();
484 test_usec_add();
485 test_usec_sub_signed();
486 test_usec_sub_unsigned();
487 test_format_timestamp();
488 test_format_timestamp_utc();
489 test_deserialize_dual_timestamp();
490 test_usec_shift_clock();
491 test_in_utc_timezone();
492
493 /* Ensure time_t is signed */
494 assert_cc((time_t) -1 < (time_t) 1);
495
496 /* Ensure TIME_T_MAX works correctly */
497 x = (uintmax_t) TIME_T_MAX;
498 x++;
499 assert((time_t) x < 0);
500
501 return 0;
502 }