chiark / gitweb /
macro: use unique variable names for math-macros
[elogind.git] / src / test / test-util.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4   This file is part of systemd.
5
6   Copyright 2010 Lennart Poettering
7   Copyright 2013 Thomas H.P. Andersen
8
9   systemd is free software; you can redistribute it and/or modify it
10   under the terms of the GNU Lesser General Public License as published by
11   the Free Software Foundation; either version 2.1 of the License, or
12   (at your option) any later version.
13
14   systemd is distributed in the hope that it will be useful, but
15   WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   Lesser General Public License for more details.
18
19   You should have received a copy of the GNU Lesser General Public License
20   along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 ***/
22
23 #include <string.h>
24 #include <unistd.h>
25 #include <fcntl.h>
26 #include <locale.h>
27 #include <errno.h>
28 #include <signal.h>
29 #include <math.h>
30 #include <sys/wait.h>
31
32 #include "util.h"
33 #include "mkdir.h"
34 #include "strv.h"
35 #include "def.h"
36 #include "fileio.h"
37 #include "conf-parser.h"
38
39 static void test_streq_ptr(void) {
40         assert_se(streq_ptr(NULL, NULL));
41         assert_se(!streq_ptr("abc", "cdef"));
42 }
43
44 static void test_align_power2(void) {
45         unsigned long i, p2;
46
47         assert_se(ALIGN_POWER2(0) == 0);
48         assert_se(ALIGN_POWER2(1) == 1);
49         assert_se(ALIGN_POWER2(2) == 2);
50         assert_se(ALIGN_POWER2(3) == 4);
51         assert_se(ALIGN_POWER2(12) == 16);
52
53         assert_se(ALIGN_POWER2(ULONG_MAX) == 0);
54         assert_se(ALIGN_POWER2(ULONG_MAX - 1) == 0);
55         assert_se(ALIGN_POWER2(ULONG_MAX - 1024) == 0);
56         assert_se(ALIGN_POWER2(ULONG_MAX / 2) == ULONG_MAX / 2 + 1);
57         assert_se(ALIGN_POWER2(ULONG_MAX + 1) == 0);
58
59         for (i = 1; i < 131071; ++i) {
60                 for (p2 = 1; p2 < i; p2 <<= 1)
61                         /* empty */ ;
62
63                 assert_se(ALIGN_POWER2(i) == p2);
64         }
65
66         for (i = ULONG_MAX - 1024; i < ULONG_MAX; ++i) {
67                 for (p2 = 1; p2 && p2 < i; p2 <<= 1)
68                         /* empty */ ;
69
70                 assert_se(ALIGN_POWER2(i) == p2);
71         }
72 }
73
74 static void test_max(void) {
75         static const struct {
76                 int a;
77                 int b[CONST_MAX(10, 100)];
78         } val1 = {
79                 .a = CONST_MAX(10, 100),
80         };
81         int d = 0;
82
83         assert_cc(sizeof(val1.b) == sizeof(int) * 100);
84
85         /* CONST_MAX returns (void) instead of a value if the passed arguments
86          * are not of the same type or not constant expressions. */
87         assert_cc(__builtin_types_compatible_p(typeof(CONST_MAX(1, 10)), int));
88         assert_cc(__builtin_types_compatible_p(typeof(CONST_MAX(1, 1U)), void));
89
90         assert_se(val1.a == 100);
91         assert_se(MAX(++d, 0) == 1);
92         assert_se(d == 1);
93
94         assert_cc(MAXSIZE(char[3], uint16_t) == 3);
95         assert_cc(MAXSIZE(char[3], uint32_t) == 4);
96         assert_cc(MAXSIZE(char, long) == sizeof(long));
97
98         assert_se(MAX(-5, 5) == 5);
99         assert_se(MAX(5, 5) == 5);
100         assert_se(MAX(MAX(1, MAX(2, MAX(3, 4))), 5) == 5);
101         assert_se(MAX(MAX(1, MAX(2, MAX(3, 2))), 1) == 3);
102         assert_se(MAX(MIN(1, MIN(2, MIN(3, 4))), 5) == 5);
103         assert_se(MAX(MAX(1, MIN(2, MIN(3, 2))), 1) == 2);
104         assert_se(LESS_BY(8, 4) == 4);
105         assert_se(LESS_BY(8, 8) == 0);
106         assert_se(LESS_BY(4, 8) == 0);
107         assert_se(LESS_BY(16, LESS_BY(8, 4)) == 12);
108         assert_se(LESS_BY(4, LESS_BY(8, 4)) == 0);
109         assert_se(CLAMP(-5, 0, 1) == 0);
110         assert_se(CLAMP(5, 0, 1) == 1);
111         assert_se(CLAMP(5, -10, 1) == 1);
112         assert_se(CLAMP(5, -10, 10) == 5);
113         assert_se(CLAMP(CLAMP(0, -10, 10), CLAMP(-5, 10, 20), CLAMP(100, -5, 20)) == 10);
114 }
115
116 static void test_container_of(void) {
117         struct mytype {
118                 uint8_t pad1[3];
119                 uint64_t v1;
120                 uint8_t pad2[2];
121                 uint32_t v2;
122         } _packed_ myval = { };
123
124         assert_cc(sizeof(myval) == 17);
125         assert_se(container_of(&myval.v1, struct mytype, v1) == &myval);
126         assert_se(container_of(&myval.v2, struct mytype, v2) == &myval);
127         assert_se(container_of(&container_of(&myval.v2,
128                                              struct mytype,
129                                              v2)->v1,
130                                struct mytype,
131                                v1) == &myval);
132 }
133
134 static void test_first_word(void) {
135         assert_se(first_word("Hello", ""));
136         assert_se(first_word("Hello", "Hello"));
137         assert_se(first_word("Hello world", "Hello"));
138         assert_se(first_word("Hello\tworld", "Hello"));
139         assert_se(first_word("Hello\nworld", "Hello"));
140         assert_se(first_word("Hello\rworld", "Hello"));
141         assert_se(first_word("Hello ", "Hello"));
142
143         assert_se(!first_word("Hello", "Hellooo"));
144         assert_se(!first_word("Hello", "xxxxx"));
145         assert_se(!first_word("Hellooo", "Hello"));
146 }
147
148 static void test_close_many(void) {
149         int fds[3];
150         char name0[] = "/tmp/test-close-many.XXXXXX";
151         char name1[] = "/tmp/test-close-many.XXXXXX";
152         char name2[] = "/tmp/test-close-many.XXXXXX";
153
154         fds[0] = mkostemp_safe(name0, O_RDWR|O_CLOEXEC);
155         fds[1] = mkostemp_safe(name1, O_RDWR|O_CLOEXEC);
156         fds[2] = mkostemp_safe(name2, O_RDWR|O_CLOEXEC);
157
158         close_many(fds, 2);
159
160         assert_se(fcntl(fds[0], F_GETFD) == -1);
161         assert_se(fcntl(fds[1], F_GETFD) == -1);
162         assert_se(fcntl(fds[2], F_GETFD) >= 0);
163
164         safe_close(fds[2]);
165
166         unlink(name0);
167         unlink(name1);
168         unlink(name2);
169 }
170
171 static void test_parse_boolean(void) {
172         assert_se(parse_boolean("1") == 1);
173         assert_se(parse_boolean("y") == 1);
174         assert_se(parse_boolean("Y") == 1);
175         assert_se(parse_boolean("yes") == 1);
176         assert_se(parse_boolean("YES") == 1);
177         assert_se(parse_boolean("true") == 1);
178         assert_se(parse_boolean("TRUE") == 1);
179         assert_se(parse_boolean("on") == 1);
180         assert_se(parse_boolean("ON") == 1);
181
182         assert_se(parse_boolean("0") == 0);
183         assert_se(parse_boolean("n") == 0);
184         assert_se(parse_boolean("N") == 0);
185         assert_se(parse_boolean("no") == 0);
186         assert_se(parse_boolean("NO") == 0);
187         assert_se(parse_boolean("false") == 0);
188         assert_se(parse_boolean("FALSE") == 0);
189         assert_se(parse_boolean("off") == 0);
190         assert_se(parse_boolean("OFF") == 0);
191
192         assert_se(parse_boolean("garbage") < 0);
193         assert_se(parse_boolean("") < 0);
194         assert_se(parse_boolean("full") < 0);
195 }
196
197 static void test_parse_pid(void) {
198         int r;
199         pid_t pid;
200
201         r = parse_pid("100", &pid);
202         assert_se(r == 0);
203         assert_se(pid == 100);
204
205         r = parse_pid("0x7FFFFFFF", &pid);
206         assert_se(r == 0);
207         assert_se(pid == 2147483647);
208
209         pid = 65; /* pid is left unchanged on ERANGE. Set to known arbitrary value. */
210         r = parse_pid("0", &pid);
211         assert_se(r == -ERANGE);
212         assert_se(pid == 65);
213
214         pid = 65; /* pid is left unchanged on ERANGE. Set to known arbitrary value. */
215         r = parse_pid("-100", &pid);
216         assert_se(r == -ERANGE);
217         assert_se(pid == 65);
218
219         pid = 65; /* pid is left unchanged on ERANGE. Set to known arbitrary value. */
220         r = parse_pid("0xFFFFFFFFFFFFFFFFF", &pid);
221         assert(r == -ERANGE);
222         assert_se(pid == 65);
223 }
224
225 static void test_parse_uid(void) {
226         int r;
227         uid_t uid;
228
229         r = parse_uid("100", &uid);
230         assert_se(r == 0);
231         assert_se(uid == 100);
232 }
233
234 static void test_safe_atolli(void) {
235         int r;
236         long long l;
237
238         r = safe_atolli("12345", &l);
239         assert_se(r == 0);
240         assert_se(l == 12345);
241
242         r = safe_atolli("junk", &l);
243         assert_se(r == -EINVAL);
244 }
245
246 static void test_safe_atod(void) {
247         int r;
248         double d;
249         char *e;
250
251         r = safe_atod("junk", &d);
252         assert_se(r == -EINVAL);
253
254         r = safe_atod("0.2244", &d);
255         assert_se(r == 0);
256         assert_se(fabs(d - 0.2244) < 0.000001);
257
258         r = safe_atod("0,5", &d);
259         assert_se(r == -EINVAL);
260
261         errno = 0;
262         strtod("0,5", &e);
263         assert_se(*e == ',');
264
265         /* Check if this really is locale independent */
266         if (setlocale(LC_NUMERIC, "de_DE.utf8")) {
267
268                 r = safe_atod("0.2244", &d);
269                 assert_se(r == 0);
270                 assert_se(fabs(d - 0.2244) < 0.000001);
271
272                 r = safe_atod("0,5", &d);
273                 assert_se(r == -EINVAL);
274
275                 errno = 0;
276                 assert_se(fabs(strtod("0,5", &e) - 0.5) < 0.00001);
277         }
278
279         /* And check again, reset */
280         assert_se(setlocale(LC_NUMERIC, "C"));
281
282         r = safe_atod("0.2244", &d);
283         assert_se(r == 0);
284         assert_se(fabs(d - 0.2244) < 0.000001);
285
286         r = safe_atod("0,5", &d);
287         assert_se(r == -EINVAL);
288
289         errno = 0;
290         strtod("0,5", &e);
291         assert_se(*e == ',');
292 }
293
294 static void test_strappend(void) {
295         _cleanup_free_ char *t1, *t2, *t3, *t4;
296
297         t1 = strappend(NULL, NULL);
298         assert_se(streq(t1, ""));
299
300         t2 = strappend(NULL, "suf");
301         assert_se(streq(t2, "suf"));
302
303         t3 = strappend("pre", NULL);
304         assert_se(streq(t3, "pre"));
305
306         t4 = strappend("pre", "suf");
307         assert_se(streq(t4, "presuf"));
308 }
309
310 static void test_strstrip(void) {
311         char *r;
312         char input[] = "   hello, waldo.   ";
313
314         r = strstrip(input);
315         assert_se(streq(r, "hello, waldo."));
316 }
317
318 static void test_delete_chars(void) {
319         char *r;
320         char input[] = "   hello, waldo.   abc";
321
322         r = delete_chars(input, WHITESPACE);
323         assert_se(streq(r, "hello,waldo.abc"));
324 }
325
326 static void test_in_charset(void) {
327         assert_se(in_charset("dddaaabbbcccc", "abcd"));
328         assert_se(!in_charset("dddaaabbbcccc", "abc f"));
329 }
330
331 static void test_hexchar(void) {
332         assert_se(hexchar(0xa) == 'a');
333         assert_se(hexchar(0x0) == '0');
334 }
335
336 static void test_unhexchar(void) {
337         assert_se(unhexchar('a') == 0xA);
338         assert_se(unhexchar('A') == 0xA);
339         assert_se(unhexchar('0') == 0x0);
340 }
341
342 static void test_octchar(void) {
343         assert_se(octchar(00) == '0');
344         assert_se(octchar(07) == '7');
345 }
346
347 static void test_unoctchar(void) {
348         assert_se(unoctchar('0') == 00);
349         assert_se(unoctchar('7') == 07);
350 }
351
352 static void test_decchar(void) {
353         assert_se(decchar(0) == '0');
354         assert_se(decchar(9) == '9');
355 }
356
357 static void test_undecchar(void) {
358         assert_se(undecchar('0') == 0);
359         assert_se(undecchar('9') == 9);
360 }
361
362 static void test_cescape(void) {
363         _cleanup_free_ char *escaped;
364
365         assert_se(escaped = cescape("abc\\\"\b\f\n\r\t\v\a\003\177\234\313"));
366         assert_se(streq(escaped, "abc\\\\\\\"\\b\\f\\n\\r\\t\\v\\a\\003\\177\\234\\313"));
367 }
368
369 static void test_cunescape(void) {
370         _cleanup_free_ char *unescaped;
371
372         assert_se(unescaped = cunescape("abc\\\\\\\"\\b\\f\\a\\n\\r\\t\\v\\003\\177\\234\\313\\000\\x00"));
373         assert_se(streq(unescaped, "abc\\\"\b\f\a\n\r\t\v\003\177\234\313\\000\\x00"));
374 }
375
376 static void test_foreach_word(void) {
377         const char *word, *state;
378         size_t l;
379         int i = 0;
380         const char test[] = "test abc d\te   f   ";
381         const char * const expected[] = {
382                 "test",
383                 "abc",
384                 "d",
385                 "e",
386                 "f",
387                 "",
388                 NULL
389         };
390
391         FOREACH_WORD(word, l, test, state)
392                 assert_se(strneq(expected[i++], word, l));
393 }
394
395 static void test_foreach_word_quoted(void) {
396         const char *word, *state;
397         size_t l;
398         int i = 0;
399         const char test[] = "test a b c 'd' e '' '' hhh '' '' \"a b c\"";
400         const char * const expected[] = {
401                 "test",
402                 "a",
403                 "b",
404                 "c",
405                 "d",
406                 "e",
407                 "",
408                 "",
409                 "hhh",
410                 "",
411                 "",
412                 "a b c",
413                 NULL
414         };
415
416         printf("<%s>\n", test);
417         FOREACH_WORD_QUOTED(word, l, test, state) {
418                 _cleanup_free_ char *t = NULL;
419
420                 assert_se(t = strndup(word, l));
421                 assert_se(strneq(expected[i++], word, l));
422                 printf("<%s>\n", t);
423         }
424         assert(isempty(state));
425 }
426
427 static void test_default_term_for_tty(void) {
428         puts(default_term_for_tty("/dev/tty23"));
429         puts(default_term_for_tty("/dev/ttyS23"));
430         puts(default_term_for_tty("/dev/tty0"));
431         puts(default_term_for_tty("/dev/pty0"));
432         puts(default_term_for_tty("/dev/pts/0"));
433         puts(default_term_for_tty("/dev/console"));
434         puts(default_term_for_tty("tty23"));
435         puts(default_term_for_tty("ttyS23"));
436         puts(default_term_for_tty("tty0"));
437         puts(default_term_for_tty("pty0"));
438         puts(default_term_for_tty("pts/0"));
439         puts(default_term_for_tty("console"));
440 }
441
442 static void test_memdup_multiply(void) {
443         int org[] = {1, 2, 3};
444         int *dup;
445
446         dup = (int*)memdup_multiply(org, sizeof(int), 3);
447
448         assert_se(dup);
449         assert_se(dup[0] == 1);
450         assert_se(dup[1] == 2);
451         assert_se(dup[2] == 3);
452         free(dup);
453 }
454
455 static void test_hostname_is_valid(void) {
456         assert(hostname_is_valid("foobar"));
457         assert(hostname_is_valid("foobar.com"));
458         assert(!hostname_is_valid("fööbar"));
459         assert(!hostname_is_valid(""));
460         assert(!hostname_is_valid("."));
461         assert(!hostname_is_valid(".."));
462         assert(!hostname_is_valid("foobar."));
463         assert(!hostname_is_valid(".foobar"));
464         assert(!hostname_is_valid("foo..bar"));
465         assert(!hostname_is_valid("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
466 }
467
468 static void test_u64log2(void) {
469         assert(u64log2(0) == 0);
470         assert(u64log2(8) == 3);
471         assert(u64log2(9) == 3);
472         assert(u64log2(15) == 3);
473         assert(u64log2(16) == 4);
474         assert(u64log2(1024*1024) == 20);
475         assert(u64log2(1024*1024+5) == 20);
476 }
477
478 static void test_get_process_comm(void) {
479         struct stat st;
480         _cleanup_free_ char *a = NULL, *c = NULL, *d = NULL, *f = NULL, *i = NULL;
481         unsigned long long b;
482         pid_t e;
483         uid_t u;
484         gid_t g;
485         dev_t h;
486         int r;
487
488         if (stat("/proc/1/comm", &st) == 0) {
489                 assert_se(get_process_comm(1, &a) >= 0);
490                 log_info("pid1 comm: '%s'", a);
491         } else {
492                 log_warning("/proc/1/comm does not exist.");
493         }
494
495         assert_se(get_starttime_of_pid(1, &b) >= 0);
496         log_info("pid1 starttime: '%llu'", b);
497
498         assert_se(get_process_cmdline(1, 0, true, &c) >= 0);
499         log_info("pid1 cmdline: '%s'", c);
500
501         assert_se(get_process_cmdline(1, 8, false, &d) >= 0);
502         log_info("pid1 cmdline truncated: '%s'", d);
503
504         assert_se(get_parent_of_pid(1, &e) >= 0);
505         log_info("pid1 ppid: "PID_FMT, e);
506         assert_se(e == 0);
507
508         assert_se(is_kernel_thread(1) == 0);
509
510         r = get_process_exe(1, &f);
511         assert_se(r >= 0 || r == -EACCES);
512         log_info("pid1 exe: '%s'", strna(f));
513
514         assert_se(get_process_uid(1, &u) == 0);
515         log_info("pid1 uid: "UID_FMT, u);
516         assert_se(u == 0);
517
518         assert_se(get_process_gid(1, &g) == 0);
519         log_info("pid1 gid: "GID_FMT, g);
520         assert_se(g == 0);
521
522         assert(get_ctty_devnr(1, &h) == -ENOENT);
523
524         getenv_for_pid(1, "PATH", &i);
525         log_info("pid1 $PATH: '%s'", strna(i));
526 }
527
528 static void test_protect_errno(void) {
529         errno = 12;
530         {
531                 PROTECT_ERRNO;
532                 errno = 11;
533         }
534         assert(errno == 12);
535 }
536
537 static void test_parse_size(void) {
538         off_t bytes;
539
540         assert_se(parse_size("111", 1024, &bytes) == 0);
541         assert_se(bytes == 111);
542
543         assert_se(parse_size("111.4", 1024, &bytes) == 0);
544         assert_se(bytes == 111);
545
546         assert_se(parse_size(" 112 B", 1024, &bytes) == 0);
547         assert_se(bytes == 112);
548
549         assert_se(parse_size(" 112.6 B", 1024, &bytes) == 0);
550         assert_se(bytes == 112);
551
552         assert_se(parse_size("3.5 K", 1024, &bytes) == 0);
553         assert_se(bytes == 3*1024 + 512);
554
555         assert_se(parse_size("3. K", 1024, &bytes) == 0);
556         assert_se(bytes == 3*1024);
557
558         assert_se(parse_size("3.0 K", 1024, &bytes) == 0);
559         assert_se(bytes == 3*1024);
560
561         assert_se(parse_size("3. 0 K", 1024, &bytes) == -EINVAL);
562
563         assert_se(parse_size(" 4 M 11.5K", 1024, &bytes) == 0);
564         assert_se(bytes == 4*1024*1024 + 11 * 1024 + 512);
565
566         assert_se(parse_size("3B3.5G", 1024, &bytes) == -EINVAL);
567
568         assert_se(parse_size("3.5G3B", 1024, &bytes) == 0);
569         assert_se(bytes == 3ULL*1024*1024*1024 + 512*1024*1024 + 3);
570
571         assert_se(parse_size("3.5G 4B", 1024, &bytes) == 0);
572         assert_se(bytes == 3ULL*1024*1024*1024 + 512*1024*1024 + 4);
573
574         assert_se(parse_size("3B3G4T", 1024, &bytes) == -EINVAL);
575
576         assert_se(parse_size("4T3G3B", 1024, &bytes) == 0);
577         assert_se(bytes == (4ULL*1024 + 3)*1024*1024*1024 + 3);
578
579         assert_se(parse_size(" 4 T 3 G 3 B", 1024, &bytes) == 0);
580         assert_se(bytes == (4ULL*1024 + 3)*1024*1024*1024 + 3);
581
582         assert_se(parse_size("12P", 1024, &bytes) == 0);
583         assert_se(bytes == 12ULL * 1024*1024*1024*1024*1024);
584
585         assert_se(parse_size("12P12P", 1024, &bytes) == -EINVAL);
586
587         assert_se(parse_size("3E 2P", 1024, &bytes) == 0);
588         assert_se(bytes == (3 * 1024 + 2ULL) * 1024*1024*1024*1024*1024);
589
590         assert_se(parse_size("12X", 1024, &bytes) == -EINVAL);
591
592         assert_se(parse_size("12.5X", 1024, &bytes) == -EINVAL);
593
594         assert_se(parse_size("12.5e3", 1024, &bytes) == -EINVAL);
595
596         assert_se(parse_size("1024E", 1024, &bytes) == -ERANGE);
597         assert_se(parse_size("-1", 1024, &bytes) == -ERANGE);
598         assert_se(parse_size("-1024E", 1024, &bytes) == -ERANGE);
599
600         assert_se(parse_size("-1024P", 1024, &bytes) == -ERANGE);
601
602         assert_se(parse_size("-10B 20K", 1024, &bytes) == -ERANGE);
603 }
604
605 static void test_config_parse_iec_off(void) {
606         off_t offset = 0;
607         assert_se(config_parse_iec_off(NULL, "/this/file", 11, "Section", 22, "Size", 0, "4M", &offset, NULL) == 0);
608         assert_se(offset == 4 * 1024 * 1024);
609
610         assert_se(config_parse_iec_off(NULL, "/this/file", 11, "Section", 22, "Size", 0, "4.5M", &offset, NULL) == 0);
611 }
612
613 static void test_strextend(void) {
614         _cleanup_free_ char *str = strdup("0123");
615         strextend(&str, "456", "78", "9", NULL);
616         assert_se(streq(str, "0123456789"));
617 }
618
619 static void test_strrep(void) {
620         _cleanup_free_ char *one, *three, *zero;
621         one = strrep("waldo", 1);
622         three = strrep("waldo", 3);
623         zero = strrep("waldo", 0);
624
625         assert_se(streq(one, "waldo"));
626         assert_se(streq(three, "waldowaldowaldo"));
627         assert_se(streq(zero, ""));
628 }
629
630 static void test_split_pair(void) {
631         _cleanup_free_ char *a = NULL, *b = NULL;
632
633         assert_se(split_pair("", "", &a, &b) == -EINVAL);
634         assert_se(split_pair("foo=bar", "", &a, &b) == -EINVAL);
635         assert_se(split_pair("", "=", &a, &b) == -EINVAL);
636         assert_se(split_pair("foo=bar", "=", &a, &b) >= 0);
637         assert_se(streq(a, "foo"));
638         assert_se(streq(b, "bar"));
639         free(a);
640         free(b);
641         assert_se(split_pair("==", "==", &a, &b) >= 0);
642         assert_se(streq(a, ""));
643         assert_se(streq(b, ""));
644         free(a);
645         free(b);
646
647         assert_se(split_pair("===", "==", &a, &b) >= 0);
648         assert_se(streq(a, ""));
649         assert_se(streq(b, "="));
650 }
651
652 static void test_fstab_node_to_udev_node(void) {
653         char *n;
654
655         n = fstab_node_to_udev_node("LABEL=applé/jack");
656         puts(n);
657         assert_se(streq(n, "/dev/disk/by-label/applé\\x2fjack"));
658         free(n);
659
660         n = fstab_node_to_udev_node("PARTLABEL=pinkié pie");
661         puts(n);
662         assert_se(streq(n, "/dev/disk/by-partlabel/pinkié\\x20pie"));
663         free(n);
664
665         n = fstab_node_to_udev_node("UUID=037b9d94-148e-4ee4-8d38-67bfe15bb535");
666         puts(n);
667         assert_se(streq(n, "/dev/disk/by-uuid/037b9d94-148e-4ee4-8d38-67bfe15bb535"));
668         free(n);
669
670         n = fstab_node_to_udev_node("PARTUUID=037b9d94-148e-4ee4-8d38-67bfe15bb535");
671         puts(n);
672         assert_se(streq(n, "/dev/disk/by-partuuid/037b9d94-148e-4ee4-8d38-67bfe15bb535"));
673         free(n);
674
675         n = fstab_node_to_udev_node("PONIES=awesome");
676         puts(n);
677         assert_se(streq(n, "PONIES=awesome"));
678         free(n);
679
680         n = fstab_node_to_udev_node("/dev/xda1");
681         puts(n);
682         assert_se(streq(n, "/dev/xda1"));
683         free(n);
684 }
685
686 static void test_get_files_in_directory(void) {
687         _cleanup_strv_free_ char **l = NULL, **t = NULL;
688
689         assert_se(get_files_in_directory("/tmp", &l) >= 0);
690         assert_se(get_files_in_directory(".", &t) >= 0);
691         assert_se(get_files_in_directory(".", NULL) >= 0);
692 }
693
694 static void test_in_set(void) {
695         assert_se(IN_SET(1, 1));
696         assert_se(IN_SET(1, 1, 2, 3, 4));
697         assert_se(IN_SET(2, 1, 2, 3, 4));
698         assert_se(IN_SET(3, 1, 2, 3, 4));
699         assert_se(IN_SET(4, 1, 2, 3, 4));
700         assert_se(!IN_SET(0, 1));
701         assert_se(!IN_SET(0, 1, 2, 3, 4));
702 }
703
704 static void test_writing_tmpfile(void) {
705         char name[] = "/tmp/test-systemd_writing_tmpfile.XXXXXX";
706         _cleanup_free_ char *contents = NULL;
707         size_t size;
708         int fd, r;
709         struct iovec iov[3];
710
711         IOVEC_SET_STRING(iov[0], "abc\n");
712         IOVEC_SET_STRING(iov[1], ALPHANUMERICAL "\n");
713         IOVEC_SET_STRING(iov[2], "");
714
715         fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
716         printf("tmpfile: %s", name);
717
718         r = writev(fd, iov, 3);
719         assert(r >= 0);
720
721         r = read_full_file(name, &contents, &size);
722         assert(r == 0);
723         printf("contents: %s", contents);
724         assert(streq(contents, "abc\n" ALPHANUMERICAL "\n"));
725
726         unlink(name);
727 }
728
729 static void test_hexdump(void) {
730         uint8_t data[146];
731         unsigned i;
732
733         hexdump(stdout, NULL, 0);
734         hexdump(stdout, "", 0);
735         hexdump(stdout, "", 1);
736         hexdump(stdout, "x", 1);
737         hexdump(stdout, "x", 2);
738         hexdump(stdout, "foobar", 7);
739         hexdump(stdout, "f\nobar", 7);
740         hexdump(stdout, "xxxxxxxxxxxxxxxxxxxxyz", 23);
741
742         for (i = 0; i < ELEMENTSOF(data); i++)
743                 data[i] = i*2;
744
745         hexdump(stdout, data, sizeof(data));
746 }
747
748 static void test_log2i(void) {
749         assert_se(log2i(1) == 0);
750         assert_se(log2i(2) == 1);
751         assert_se(log2i(3) == 1);
752         assert_se(log2i(4) == 2);
753         assert_se(log2i(32) == 5);
754         assert_se(log2i(33) == 5);
755         assert_se(log2i(63) == 5);
756         assert_se(log2i(INT_MAX) == sizeof(int)*8-2);
757 }
758
759 static void test_foreach_string(void) {
760         const char * const t[] = {
761                 "foo",
762                 "bar",
763                 "waldo",
764                 NULL
765         };
766         const char *x;
767         unsigned i = 0;
768
769         FOREACH_STRING(x, "foo", "bar", "waldo")
770                 assert_se(streq_ptr(t[i++], x));
771
772         assert_se(i == 3);
773
774         FOREACH_STRING(x, "zzz")
775                 assert_se(streq(x, "zzz"));
776 }
777
778 static void test_filename_is_safe(void) {
779         char foo[FILENAME_MAX+2];
780         int i;
781
782         assert_se(!filename_is_safe(""));
783         assert_se(!filename_is_safe("/bar/foo"));
784         assert_se(!filename_is_safe("/"));
785         assert_se(!filename_is_safe("."));
786         assert_se(!filename_is_safe(".."));
787
788         for (i=0; i<FILENAME_MAX+1; i++)
789                 foo[i] = 'a';
790         foo[FILENAME_MAX+1] = '\0';
791
792         assert_se(!filename_is_safe(foo));
793
794         assert_se(filename_is_safe("foo_bar-333"));
795         assert_se(filename_is_safe("o.o"));
796 }
797
798 static void test_string_has_cc(void) {
799         assert_se(string_has_cc("abc\1", NULL));
800         assert_se(string_has_cc("abc\x7f", NULL));
801         assert_se(string_has_cc("abc\x7f", NULL));
802         assert_se(string_has_cc("abc\t\x7f", "\t"));
803         assert_se(string_has_cc("abc\t\x7f", "\t"));
804         assert_se(string_has_cc("\x7f", "\t"));
805         assert_se(string_has_cc("\x7f", "\t\a"));
806
807         assert_se(!string_has_cc("abc\t\t", "\t"));
808         assert_se(!string_has_cc("abc\t\t\a", "\t\a"));
809         assert_se(!string_has_cc("a\ab\tc", "\t\a"));
810 }
811
812 static void test_ascii_strlower(void) {
813         char a[] = "AabBcC Jk Ii Od LKJJJ kkd LK";
814         assert_se(streq(ascii_strlower(a), "aabbcc jk ii od lkjjj kkd lk"));
815 }
816
817 static void test_files_same(void) {
818         _cleanup_close_ int fd = -1;
819         char name[] = "/tmp/test-files_same.XXXXXX";
820         char name_alias[] = "/tmp/test-files_same.alias";
821
822         fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
823         assert_se(fd >= 0);
824         assert_se(symlink(name, name_alias) >= 0);
825
826         assert_se(files_same(name, name));
827         assert_se(files_same(name, name_alias));
828
829         unlink(name);
830         unlink(name_alias);
831 }
832
833 static void test_is_valid_documentation_url(void) {
834         assert_se(is_valid_documentation_url("http://www.freedesktop.org/wiki/Software/systemd"));
835         assert_se(is_valid_documentation_url("https://www.kernel.org/doc/Documentation/binfmt_misc.txt"));
836         assert_se(is_valid_documentation_url("file:foo"));
837         assert_se(is_valid_documentation_url("man:systemd.special(7)"));
838         assert_se(is_valid_documentation_url("info:bar"));
839
840         assert_se(!is_valid_documentation_url("foo:"));
841         assert_se(!is_valid_documentation_url("info:"));
842         assert_se(!is_valid_documentation_url(""));
843 }
844
845 static void test_file_in_same_dir(void) {
846         assert_se(streq(file_in_same_dir("/", "a"), "/a"));
847         assert_se(streq(file_in_same_dir("/", "/a"), "/a"));
848         assert_se(streq(file_in_same_dir("", "a"), "a"));
849         assert_se(streq(file_in_same_dir("a/", "a"), "a/a"));
850         assert_se(streq(file_in_same_dir("bar/foo", "bar"), "bar/bar"));
851 }
852
853 static void test_endswith(void) {
854         assert_se(endswith("foobar", "bar"));
855         assert_se(endswith("foobar", ""));
856         assert_se(endswith("foobar", "foobar"));
857         assert_se(endswith("", ""));
858
859         assert_se(!endswith("foobar", "foo"));
860         assert_se(!endswith("foobar", "foobarfoofoo"));
861 }
862
863 static void test_close_nointr(void) {
864         char name[] = "/tmp/test-test-close_nointr.XXXXXX";
865         int fd;
866
867         fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
868         assert_se(fd >= 0);
869         assert_se(close_nointr(fd) >= 0);
870         assert_se(close_nointr(fd) < 0);
871
872         unlink(name);
873 }
874
875
876 static void test_unlink_noerrno(void) {
877         char name[] = "/tmp/test-close_nointr.XXXXXX";
878         int fd;
879
880         fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
881         assert_se(fd >= 0);
882         assert_se(close_nointr(fd) >= 0);
883
884         {
885                 PROTECT_ERRNO;
886                 errno = -42;
887                 assert_se(unlink_noerrno(name) >= 0);
888                 assert_se(errno == -42);
889                 assert_se(unlink_noerrno(name) < 0);
890                 assert_se(errno == -42);
891         }
892 }
893
894 static void test_readlink_and_make_absolute(void) {
895         char tempdir[] = "/tmp/test-readlink_and_make_absolute";
896         char name[] = "/tmp/test-readlink_and_make_absolute/original";
897         char name2[] = "test-readlink_and_make_absolute/original";
898         char name_alias[] = "/tmp/test-readlink_and_make_absolute-alias";
899         char *r = NULL;
900
901         assert_se(mkdir_safe(tempdir, 0755, getuid(), getgid()) >= 0);
902         assert_se(touch(name) >= 0);
903
904         assert_se(symlink(name, name_alias) >= 0);
905         assert_se(readlink_and_make_absolute(name_alias, &r) >= 0);
906         assert_se(streq(r, name));
907         free(r);
908         assert_se(unlink(name_alias) >= 0);
909
910         assert_se(chdir(tempdir) >= 0);
911         assert_se(symlink(name2, name_alias) >= 0);
912         assert_se(readlink_and_make_absolute(name_alias, &r) >= 0);
913         assert_se(streq(r, name));
914         free(r);
915         assert_se(unlink(name_alias) >= 0);
916
917         assert_se(rm_rf_dangerous(tempdir, false, true, false) >= 0);
918 }
919
920 static void test_read_one_char(void) {
921         char r;
922         bool need_nl;
923         char name[] = "/tmp/test-read_one_char.XXXXXX";
924         _cleanup_close_ int fd = -1;
925         FILE *file;
926
927         fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
928         assert_se(fd >= 0);
929         file = fdopen(fd, "r+");
930         assert_se(file);
931         assert_se(fputs("c\n", file) >= 0);
932         rewind(file);
933
934         assert_se(read_one_char(file, &r, 1000000, &need_nl) >= 0);
935         assert_se(!need_nl);
936         assert_se(r == 'c');
937         assert_se(read_one_char(file, &r, 1000000, &need_nl) < 0);
938
939         rewind(file);
940         assert_se(fputs("foobar\n", file) >= 0);
941         rewind(file);
942         assert_se(read_one_char(file, &r, 1000000, &need_nl) < 0);
943
944         rewind(file);
945         assert_se(fputs("\n", file) >= 0);
946         rewind(file);
947         assert_se(read_one_char(file, &r, 1000000, &need_nl) < 0);
948
949         unlink(name);
950 }
951
952 static void test_ignore_signals(void) {
953         assert_se(ignore_signals(SIGINT, -1) >= 0);
954         assert_se(kill(getpid(), SIGINT) >= 0);
955         assert_se(ignore_signals(SIGUSR1, SIGUSR2, SIGTERM, SIGPIPE, -1) >= 0);
956         assert_se(kill(getpid(), SIGUSR1) >= 0);
957         assert_se(kill(getpid(), SIGUSR2) >= 0);
958         assert_se(kill(getpid(), SIGTERM) >= 0);
959         assert_se(kill(getpid(), SIGPIPE) >= 0);
960         assert_se(default_signals(SIGINT, SIGUSR1, SIGUSR2, SIGTERM, SIGPIPE, -1) >= 0);
961 }
962
963 static void test_strshorten(void) {
964         char s[] = "foobar";
965
966         assert_se(strlen(strshorten(s, 6)) == 6);
967         assert_se(strlen(strshorten(s, 12)) == 6);
968         assert_se(strlen(strshorten(s, 2)) == 2);
969         assert_se(strlen(strshorten(s, 0)) == 0);
970 }
971
972 static void test_strappenda(void) {
973         char *actual;
974
975         actual = strappenda("", "foo", "bar");
976         assert_se(streq(actual, "foobar"));
977
978         actual = strappenda("foo", "bar", "baz");
979         assert_se(streq(actual, "foobarbaz"));
980
981         actual = strappenda("foo", "", "bar", "baz");
982         assert_se(streq(actual, "foobarbaz"));
983 }
984
985 static void test_is_symlink(void) {
986         char name[] = "/tmp/test-is_symlink.XXXXXX";
987         char name_link[] = "/tmp/test-is_symlink.link";
988         _cleanup_close_ int fd = -1;
989
990         fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
991         assert_se(fd >= 0);
992         assert_se(symlink(name, name_link) >= 0);
993
994         assert_se(is_symlink(name) == 0);
995         assert_se(is_symlink(name_link) == 1);
996         assert_se(is_symlink("/a/file/which/does/not/exist/i/guess") < 0);
997
998
999         unlink(name);
1000         unlink(name_link);
1001 }
1002
1003 static void test_pid_is_unwaited(void) {
1004         pid_t pid;
1005
1006         pid = fork();
1007         assert_se(pid >= 0);
1008         if (pid == 0) {
1009                 _exit(EXIT_SUCCESS);
1010         } else {
1011                 int status;
1012
1013                 waitpid(pid, &status, 0);
1014                 assert_se(!pid_is_unwaited(pid));
1015         }
1016         assert_se(pid_is_unwaited(getpid()));
1017         assert_se(!pid_is_unwaited(-1));
1018 }
1019
1020 static void test_pid_is_alive(void) {
1021         pid_t pid;
1022
1023         pid = fork();
1024         assert_se(pid >= 0);
1025         if (pid == 0) {
1026                 _exit(EXIT_SUCCESS);
1027         } else {
1028                 int status;
1029
1030                 waitpid(pid, &status, 0);
1031                 assert_se(!pid_is_alive(pid));
1032         }
1033         assert_se(pid_is_alive(getpid()));
1034         assert_se(!pid_is_alive(-1));
1035 }
1036
1037 static void test_search_and_fopen(void) {
1038         const char *dirs[] = {"/tmp/foo/bar", "/tmp", NULL};
1039         char name[] = "/tmp/test-search_and_fopen.XXXXXX";
1040         int fd = -1;
1041         int r;
1042         FILE *f;
1043
1044         fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
1045         assert_se(fd >= 0);
1046         close(fd);
1047
1048         r = search_and_fopen(basename(name), "r", NULL, dirs, &f);
1049         assert_se(r >= 0);
1050         fclose(f);
1051
1052         r = search_and_fopen(name, "r", NULL, dirs, &f);
1053         assert_se(r >= 0);
1054         fclose(f);
1055
1056         r = search_and_fopen(basename(name), "r", "/", dirs, &f);
1057         assert_se(r >= 0);
1058         fclose(f);
1059
1060         r = search_and_fopen("/a/file/which/does/not/exist/i/guess", "r", NULL, dirs, &f);
1061         assert_se(r < 0);
1062         r = search_and_fopen("afilewhichdoesnotexistiguess", "r", NULL, dirs, &f);
1063         assert_se(r < 0);
1064
1065         r = unlink(name);
1066         assert_se(r == 0);
1067
1068         r = search_and_fopen(basename(name), "r", NULL, dirs, &f);
1069         assert_se(r < 0);
1070 }
1071
1072
1073 static void test_search_and_fopen_nulstr(void) {
1074         const char dirs[] = "/tmp/foo/bar\0/tmp\0";
1075         char name[] = "/tmp/test-search_and_fopen.XXXXXX";
1076         int fd = -1;
1077         int r;
1078         FILE *f;
1079
1080         fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
1081         assert_se(fd >= 0);
1082         close(fd);
1083
1084         r = search_and_fopen_nulstr(basename(name), "r", NULL, dirs, &f);
1085         assert_se(r >= 0);
1086         fclose(f);
1087
1088         r = search_and_fopen_nulstr(name, "r", NULL, dirs, &f);
1089         assert_se(r >= 0);
1090         fclose(f);
1091
1092         r = search_and_fopen_nulstr("/a/file/which/does/not/exist/i/guess", "r", NULL, dirs, &f);
1093         assert_se(r < 0);
1094         r = search_and_fopen_nulstr("afilewhichdoesnotexistiguess", "r", NULL, dirs, &f);
1095         assert_se(r < 0);
1096
1097         r = unlink(name);
1098         assert_se(r == 0);
1099
1100         r = search_and_fopen_nulstr(basename(name), "r", NULL, dirs, &f);
1101         assert_se(r < 0);
1102 }
1103
1104 static void test_glob_exists(void) {
1105         char name[] = "/tmp/test-glob_exists.XXXXXX";
1106         int fd = -1;
1107         int r;
1108
1109         fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
1110         assert_se(fd >= 0);
1111         close(fd);
1112
1113         r = glob_exists("/tmp/test-glob_exists*");
1114         assert_se(r == 1);
1115
1116         r = unlink(name);
1117         assert_se(r == 0);
1118         r = glob_exists("/tmp/test-glob_exists*");
1119         assert_se(r == 0);
1120 }
1121
1122 static void test_execute_directory(void) {
1123         char name[] = "/tmp/test-execute_directory/script1";
1124         char name2[] = "/tmp/test-execute_directory/script2";
1125         char name3[] = "/tmp/test-execute_directory/useless";
1126         char tempdir[] = "/tmp/test-execute_directory/";
1127
1128         assert_se(mkdir_safe(tempdir, 0755, getuid(), getgid()) >= 0);
1129         assert_se(write_string_file(name, "#!/bin/sh\necho 'Executing '$0\ntouch /tmp/test-execute_directory/it_works") == 0);
1130         assert_se(write_string_file(name2, "#!/bin/sh\necho 'Executing '$0\ntouch /tmp/test-execute_directory/it_works2") == 0);
1131         assert_se(chmod(name, 0755) == 0);
1132         assert_se(chmod(name2, 0755) == 0);
1133         assert_se(touch(name3) >= 0);
1134
1135         execute_directory(tempdir, NULL, DEFAULT_TIMEOUT_USEC, NULL);
1136         assert_se(access("/tmp/test-execute_directory/it_works", F_OK) >= 0);
1137         assert_se(access("/tmp/test-execute_directory/it_works2", F_OK) >= 0);
1138
1139         rm_rf_dangerous(tempdir, false, true, false);
1140 }
1141
1142 static void test_unquote_first_word(void) {
1143         const char *p, *original;
1144         char *t;
1145
1146         p = original = "foobar waldo";
1147         assert_se(unquote_first_word(&p, &t) > 0);
1148         assert_se(streq(t, "foobar"));
1149         free(t);
1150         assert_se(p == original + 7);
1151
1152         assert_se(unquote_first_word(&p, &t) > 0);
1153         assert_se(streq(t, "waldo"));
1154         free(t);
1155         assert_se(p == original + 12);
1156
1157         assert_se(unquote_first_word(&p, &t) == 0);
1158         assert_se(!t);
1159         assert_se(p == original + 12);
1160
1161         p = original = "\"foobar\" \'waldo\'";
1162         assert_se(unquote_first_word(&p, &t) > 0);
1163         assert_se(streq(t, "foobar"));
1164         free(t);
1165         assert_se(p == original + 9);
1166
1167         assert_se(unquote_first_word(&p, &t) > 0);
1168         assert_se(streq(t, "waldo"));
1169         free(t);
1170         assert_se(p == original + 16);
1171
1172         assert_se(unquote_first_word(&p, &t) == 0);
1173         assert_se(!t);
1174         assert_se(p == original + 16);
1175
1176         p = original = "\"";
1177         assert_se(unquote_first_word(&p, &t) == -EINVAL);
1178         assert_se(p == original + 1);
1179
1180         p = original = "\'";
1181         assert_se(unquote_first_word(&p, &t) == -EINVAL);
1182         assert_se(p == original + 1);
1183
1184         p = original = "yay\'foo\'bar";
1185         assert_se(unquote_first_word(&p, &t) > 0);
1186         assert_se(streq(t, "yayfoobar"));
1187         free(t);
1188         assert_se(p == original + 11);
1189
1190         p = original = "   foobar   ";
1191         assert_se(unquote_first_word(&p, &t) > 0);
1192         assert_se(streq(t, "foobar"));
1193         free(t);
1194         assert_se(p == original + 12);
1195 }
1196
1197 static void test_unquote_many_words(void) {
1198         const char *p, *original;
1199         char *a, *b, *c;
1200
1201         p = original = "foobar waldi piep";
1202         assert_se(unquote_many_words(&p, &a, &b, &c, NULL) == 3);
1203         assert_se(p == original + 17);
1204         assert_se(streq_ptr(a, "foobar"));
1205         assert_se(streq_ptr(b, "waldi"));
1206         assert_se(streq_ptr(c, "piep"));
1207         free(a);
1208         free(b);
1209         free(c);
1210
1211         p = original = "'foobar' wa\"ld\"i   ";
1212         assert_se(unquote_many_words(&p, &a, &b, &c, NULL) == 2);
1213         assert_se(p == original + 19);
1214         assert_se(streq_ptr(a, "foobar"));
1215         assert_se(streq_ptr(b, "waldi"));
1216         assert_se(streq_ptr(c, NULL));
1217         free(a);
1218         free(b);
1219
1220         p = original = "";
1221         assert_se(unquote_many_words(&p, &a, &b, &c, NULL) == 0);
1222         assert_se(p == original);
1223         assert_se(streq_ptr(a, NULL));
1224         assert_se(streq_ptr(b, NULL));
1225         assert_se(streq_ptr(c, NULL));
1226
1227         p = original = "  ";
1228         assert_se(unquote_many_words(&p, &a, &b, &c, NULL) == 0);
1229         assert_se(p == original+2);
1230         assert_se(streq_ptr(a, NULL));
1231         assert_se(streq_ptr(b, NULL));
1232         assert_se(streq_ptr(c, NULL));
1233
1234         p = original = "foobar";
1235         assert_se(unquote_many_words(&p, NULL) == 0);
1236         assert_se(p == original);
1237
1238         p = original = "foobar waldi";
1239         assert_se(unquote_many_words(&p, &a, NULL) == 1);
1240         assert_se(p == original+7);
1241         assert_se(streq_ptr(a, "foobar"));
1242
1243         p = original = "     foobar    ";
1244         assert_se(unquote_many_words(&p, &a, NULL) == 1);
1245         assert_se(p == original+15);
1246         assert_se(streq_ptr(a, "foobar"));
1247 }
1248
1249 int main(int argc, char *argv[]) {
1250         log_parse_environment();
1251         log_open();
1252
1253         test_streq_ptr();
1254         test_align_power2();
1255         test_max();
1256         test_container_of();
1257         test_first_word();
1258         test_close_many();
1259         test_parse_boolean();
1260         test_parse_pid();
1261         test_parse_uid();
1262         test_safe_atolli();
1263         test_safe_atod();
1264         test_strappend();
1265         test_strstrip();
1266         test_delete_chars();
1267         test_in_charset();
1268         test_hexchar();
1269         test_unhexchar();
1270         test_octchar();
1271         test_unoctchar();
1272         test_decchar();
1273         test_undecchar();
1274         test_cescape();
1275         test_cunescape();
1276         test_foreach_word();
1277         test_foreach_word_quoted();
1278         test_default_term_for_tty();
1279         test_memdup_multiply();
1280         test_hostname_is_valid();
1281         test_u64log2();
1282         test_get_process_comm();
1283         test_protect_errno();
1284         test_parse_size();
1285         test_config_parse_iec_off();
1286         test_strextend();
1287         test_strrep();
1288         test_split_pair();
1289         test_fstab_node_to_udev_node();
1290         test_get_files_in_directory();
1291         test_in_set();
1292         test_writing_tmpfile();
1293         test_hexdump();
1294         test_log2i();
1295         test_foreach_string();
1296         test_filename_is_safe();
1297         test_string_has_cc();
1298         test_ascii_strlower();
1299         test_files_same();
1300         test_is_valid_documentation_url();
1301         test_file_in_same_dir();
1302         test_endswith();
1303         test_close_nointr();
1304         test_unlink_noerrno();
1305         test_readlink_and_make_absolute();
1306         test_read_one_char();
1307         test_ignore_signals();
1308         test_strshorten();
1309         test_strappenda();
1310         test_is_symlink();
1311         test_pid_is_unwaited();
1312         test_pid_is_alive();
1313         test_search_and_fopen();
1314         test_search_and_fopen_nulstr();
1315         test_glob_exists();
1316         test_execute_directory();
1317         test_unquote_first_word();
1318         test_unquote_many_words();
1319
1320         return 0;
1321 }