chiark / gitweb /
f8e42f3a550de6cd01ac2c0507100edd215b8ae6
[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         char *t;
847
848         t = file_in_same_dir("/", "a");
849         assert_se(streq(t, "/a"));
850         free(t);
851
852         t = file_in_same_dir("/", "/a");
853         assert_se(streq(t, "/a"));
854         free(t);
855
856         t = file_in_same_dir("", "a");
857         assert_se(streq(t, "a"));
858         free(t);
859
860         t = file_in_same_dir("a/", "a");
861         assert_se(streq(t, "a/a"));
862         free(t);
863
864         t = file_in_same_dir("bar/foo", "bar");
865         assert_se(streq(t, "bar/bar"));
866         free(t);
867 }
868
869 static void test_endswith(void) {
870         assert_se(endswith("foobar", "bar"));
871         assert_se(endswith("foobar", ""));
872         assert_se(endswith("foobar", "foobar"));
873         assert_se(endswith("", ""));
874
875         assert_se(!endswith("foobar", "foo"));
876         assert_se(!endswith("foobar", "foobarfoofoo"));
877 }
878
879 static void test_close_nointr(void) {
880         char name[] = "/tmp/test-test-close_nointr.XXXXXX";
881         int fd;
882
883         fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
884         assert_se(fd >= 0);
885         assert_se(close_nointr(fd) >= 0);
886         assert_se(close_nointr(fd) < 0);
887
888         unlink(name);
889 }
890
891
892 static void test_unlink_noerrno(void) {
893         char name[] = "/tmp/test-close_nointr.XXXXXX";
894         int fd;
895
896         fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
897         assert_se(fd >= 0);
898         assert_se(close_nointr(fd) >= 0);
899
900         {
901                 PROTECT_ERRNO;
902                 errno = -42;
903                 assert_se(unlink_noerrno(name) >= 0);
904                 assert_se(errno == -42);
905                 assert_se(unlink_noerrno(name) < 0);
906                 assert_se(errno == -42);
907         }
908 }
909
910 static void test_readlink_and_make_absolute(void) {
911         char tempdir[] = "/tmp/test-readlink_and_make_absolute";
912         char name[] = "/tmp/test-readlink_and_make_absolute/original";
913         char name2[] = "test-readlink_and_make_absolute/original";
914         char name_alias[] = "/tmp/test-readlink_and_make_absolute-alias";
915         char *r = NULL;
916
917         assert_se(mkdir_safe(tempdir, 0755, getuid(), getgid()) >= 0);
918         assert_se(touch(name) >= 0);
919
920         assert_se(symlink(name, name_alias) >= 0);
921         assert_se(readlink_and_make_absolute(name_alias, &r) >= 0);
922         assert_se(streq(r, name));
923         free(r);
924         assert_se(unlink(name_alias) >= 0);
925
926         assert_se(chdir(tempdir) >= 0);
927         assert_se(symlink(name2, name_alias) >= 0);
928         assert_se(readlink_and_make_absolute(name_alias, &r) >= 0);
929         assert_se(streq(r, name));
930         free(r);
931         assert_se(unlink(name_alias) >= 0);
932
933         assert_se(rm_rf_dangerous(tempdir, false, true, false) >= 0);
934 }
935
936 static void test_read_one_char(void) {
937         _cleanup_fclose_ FILE *file = NULL;
938         char r;
939         bool need_nl;
940         char name[] = "/tmp/test-read_one_char.XXXXXX";
941         int fd;
942
943         fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
944         assert_se(fd >= 0);
945         file = fdopen(fd, "r+");
946         assert_se(file);
947         assert_se(fputs("c\n", file) >= 0);
948         rewind(file);
949
950         assert_se(read_one_char(file, &r, 1000000, &need_nl) >= 0);
951         assert_se(!need_nl);
952         assert_se(r == 'c');
953         assert_se(read_one_char(file, &r, 1000000, &need_nl) < 0);
954
955         rewind(file);
956         assert_se(fputs("foobar\n", file) >= 0);
957         rewind(file);
958         assert_se(read_one_char(file, &r, 1000000, &need_nl) < 0);
959
960         rewind(file);
961         assert_se(fputs("\n", file) >= 0);
962         rewind(file);
963         assert_se(read_one_char(file, &r, 1000000, &need_nl) < 0);
964
965         unlink(name);
966 }
967
968 static void test_ignore_signals(void) {
969         assert_se(ignore_signals(SIGINT, -1) >= 0);
970         assert_se(kill(getpid(), SIGINT) >= 0);
971         assert_se(ignore_signals(SIGUSR1, SIGUSR2, SIGTERM, SIGPIPE, -1) >= 0);
972         assert_se(kill(getpid(), SIGUSR1) >= 0);
973         assert_se(kill(getpid(), SIGUSR2) >= 0);
974         assert_se(kill(getpid(), SIGTERM) >= 0);
975         assert_se(kill(getpid(), SIGPIPE) >= 0);
976         assert_se(default_signals(SIGINT, SIGUSR1, SIGUSR2, SIGTERM, SIGPIPE, -1) >= 0);
977 }
978
979 static void test_strshorten(void) {
980         char s[] = "foobar";
981
982         assert_se(strlen(strshorten(s, 6)) == 6);
983         assert_se(strlen(strshorten(s, 12)) == 6);
984         assert_se(strlen(strshorten(s, 2)) == 2);
985         assert_se(strlen(strshorten(s, 0)) == 0);
986 }
987
988 static void test_strappenda(void) {
989         char *actual;
990
991         actual = strappenda("", "foo", "bar");
992         assert_se(streq(actual, "foobar"));
993
994         actual = strappenda("foo", "bar", "baz");
995         assert_se(streq(actual, "foobarbaz"));
996
997         actual = strappenda("foo", "", "bar", "baz");
998         assert_se(streq(actual, "foobarbaz"));
999 }
1000
1001 static void test_is_symlink(void) {
1002         char name[] = "/tmp/test-is_symlink.XXXXXX";
1003         char name_link[] = "/tmp/test-is_symlink.link";
1004         _cleanup_close_ int fd = -1;
1005
1006         fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
1007         assert_se(fd >= 0);
1008         assert_se(symlink(name, name_link) >= 0);
1009
1010         assert_se(is_symlink(name) == 0);
1011         assert_se(is_symlink(name_link) == 1);
1012         assert_se(is_symlink("/a/file/which/does/not/exist/i/guess") < 0);
1013
1014
1015         unlink(name);
1016         unlink(name_link);
1017 }
1018
1019 static void test_pid_is_unwaited(void) {
1020         pid_t pid;
1021
1022         pid = fork();
1023         assert_se(pid >= 0);
1024         if (pid == 0) {
1025                 _exit(EXIT_SUCCESS);
1026         } else {
1027                 int status;
1028
1029                 waitpid(pid, &status, 0);
1030                 assert_se(!pid_is_unwaited(pid));
1031         }
1032         assert_se(pid_is_unwaited(getpid()));
1033         assert_se(!pid_is_unwaited(-1));
1034 }
1035
1036 static void test_pid_is_alive(void) {
1037         pid_t pid;
1038
1039         pid = fork();
1040         assert_se(pid >= 0);
1041         if (pid == 0) {
1042                 _exit(EXIT_SUCCESS);
1043         } else {
1044                 int status;
1045
1046                 waitpid(pid, &status, 0);
1047                 assert_se(!pid_is_alive(pid));
1048         }
1049         assert_se(pid_is_alive(getpid()));
1050         assert_se(!pid_is_alive(-1));
1051 }
1052
1053 static void test_search_and_fopen(void) {
1054         const char *dirs[] = {"/tmp/foo/bar", "/tmp", NULL};
1055         char name[] = "/tmp/test-search_and_fopen.XXXXXX";
1056         int fd = -1;
1057         int r;
1058         FILE *f;
1059
1060         fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
1061         assert_se(fd >= 0);
1062         close(fd);
1063
1064         r = search_and_fopen(basename(name), "r", NULL, dirs, &f);
1065         assert_se(r >= 0);
1066         fclose(f);
1067
1068         r = search_and_fopen(name, "r", NULL, dirs, &f);
1069         assert_se(r >= 0);
1070         fclose(f);
1071
1072         r = search_and_fopen(basename(name), "r", "/", dirs, &f);
1073         assert_se(r >= 0);
1074         fclose(f);
1075
1076         r = search_and_fopen("/a/file/which/does/not/exist/i/guess", "r", NULL, dirs, &f);
1077         assert_se(r < 0);
1078         r = search_and_fopen("afilewhichdoesnotexistiguess", "r", NULL, dirs, &f);
1079         assert_se(r < 0);
1080
1081         r = unlink(name);
1082         assert_se(r == 0);
1083
1084         r = search_and_fopen(basename(name), "r", NULL, dirs, &f);
1085         assert_se(r < 0);
1086 }
1087
1088
1089 static void test_search_and_fopen_nulstr(void) {
1090         const char dirs[] = "/tmp/foo/bar\0/tmp\0";
1091         char name[] = "/tmp/test-search_and_fopen.XXXXXX";
1092         int fd = -1;
1093         int r;
1094         FILE *f;
1095
1096         fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
1097         assert_se(fd >= 0);
1098         close(fd);
1099
1100         r = search_and_fopen_nulstr(basename(name), "r", NULL, dirs, &f);
1101         assert_se(r >= 0);
1102         fclose(f);
1103
1104         r = search_and_fopen_nulstr(name, "r", NULL, dirs, &f);
1105         assert_se(r >= 0);
1106         fclose(f);
1107
1108         r = search_and_fopen_nulstr("/a/file/which/does/not/exist/i/guess", "r", NULL, dirs, &f);
1109         assert_se(r < 0);
1110         r = search_and_fopen_nulstr("afilewhichdoesnotexistiguess", "r", NULL, dirs, &f);
1111         assert_se(r < 0);
1112
1113         r = unlink(name);
1114         assert_se(r == 0);
1115
1116         r = search_and_fopen_nulstr(basename(name), "r", NULL, dirs, &f);
1117         assert_se(r < 0);
1118 }
1119
1120 static void test_glob_exists(void) {
1121         char name[] = "/tmp/test-glob_exists.XXXXXX";
1122         int fd = -1;
1123         int r;
1124
1125         fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
1126         assert_se(fd >= 0);
1127         close(fd);
1128
1129         r = glob_exists("/tmp/test-glob_exists*");
1130         assert_se(r == 1);
1131
1132         r = unlink(name);
1133         assert_se(r == 0);
1134         r = glob_exists("/tmp/test-glob_exists*");
1135         assert_se(r == 0);
1136 }
1137
1138 static void test_execute_directory(void) {
1139         char name[] = "/tmp/test-execute_directory/script1";
1140         char name2[] = "/tmp/test-execute_directory/script2";
1141         char name3[] = "/tmp/test-execute_directory/useless";
1142         char tempdir[] = "/tmp/test-execute_directory/";
1143
1144         assert_se(mkdir_safe(tempdir, 0755, getuid(), getgid()) >= 0);
1145         assert_se(write_string_file(name, "#!/bin/sh\necho 'Executing '$0\ntouch /tmp/test-execute_directory/it_works") == 0);
1146         assert_se(write_string_file(name2, "#!/bin/sh\necho 'Executing '$0\ntouch /tmp/test-execute_directory/it_works2") == 0);
1147         assert_se(chmod(name, 0755) == 0);
1148         assert_se(chmod(name2, 0755) == 0);
1149         assert_se(touch(name3) >= 0);
1150
1151         execute_directory(tempdir, NULL, DEFAULT_TIMEOUT_USEC, NULL);
1152         assert_se(access("/tmp/test-execute_directory/it_works", F_OK) >= 0);
1153         assert_se(access("/tmp/test-execute_directory/it_works2", F_OK) >= 0);
1154
1155         rm_rf_dangerous(tempdir, false, true, false);
1156 }
1157
1158 static void test_unquote_first_word(void) {
1159         const char *p, *original;
1160         char *t;
1161
1162         p = original = "foobar waldo";
1163         assert_se(unquote_first_word(&p, &t) > 0);
1164         assert_se(streq(t, "foobar"));
1165         free(t);
1166         assert_se(p == original + 7);
1167
1168         assert_se(unquote_first_word(&p, &t) > 0);
1169         assert_se(streq(t, "waldo"));
1170         free(t);
1171         assert_se(p == original + 12);
1172
1173         assert_se(unquote_first_word(&p, &t) == 0);
1174         assert_se(!t);
1175         assert_se(p == original + 12);
1176
1177         p = original = "\"foobar\" \'waldo\'";
1178         assert_se(unquote_first_word(&p, &t) > 0);
1179         assert_se(streq(t, "foobar"));
1180         free(t);
1181         assert_se(p == original + 9);
1182
1183         assert_se(unquote_first_word(&p, &t) > 0);
1184         assert_se(streq(t, "waldo"));
1185         free(t);
1186         assert_se(p == original + 16);
1187
1188         assert_se(unquote_first_word(&p, &t) == 0);
1189         assert_se(!t);
1190         assert_se(p == original + 16);
1191
1192         p = original = "\"";
1193         assert_se(unquote_first_word(&p, &t) == -EINVAL);
1194         assert_se(p == original + 1);
1195
1196         p = original = "\'";
1197         assert_se(unquote_first_word(&p, &t) == -EINVAL);
1198         assert_se(p == original + 1);
1199
1200         p = original = "yay\'foo\'bar";
1201         assert_se(unquote_first_word(&p, &t) > 0);
1202         assert_se(streq(t, "yayfoobar"));
1203         free(t);
1204         assert_se(p == original + 11);
1205
1206         p = original = "   foobar   ";
1207         assert_se(unquote_first_word(&p, &t) > 0);
1208         assert_se(streq(t, "foobar"));
1209         free(t);
1210         assert_se(p == original + 12);
1211 }
1212
1213 static void test_unquote_many_words(void) {
1214         const char *p, *original;
1215         char *a, *b, *c;
1216
1217         p = original = "foobar waldi piep";
1218         assert_se(unquote_many_words(&p, &a, &b, &c, NULL) == 3);
1219         assert_se(p == original + 17);
1220         assert_se(streq_ptr(a, "foobar"));
1221         assert_se(streq_ptr(b, "waldi"));
1222         assert_se(streq_ptr(c, "piep"));
1223         free(a);
1224         free(b);
1225         free(c);
1226
1227         p = original = "'foobar' wa\"ld\"i   ";
1228         assert_se(unquote_many_words(&p, &a, &b, &c, NULL) == 2);
1229         assert_se(p == original + 19);
1230         assert_se(streq_ptr(a, "foobar"));
1231         assert_se(streq_ptr(b, "waldi"));
1232         assert_se(streq_ptr(c, NULL));
1233         free(a);
1234         free(b);
1235
1236         p = original = "";
1237         assert_se(unquote_many_words(&p, &a, &b, &c, NULL) == 0);
1238         assert_se(p == original);
1239         assert_se(streq_ptr(a, NULL));
1240         assert_se(streq_ptr(b, NULL));
1241         assert_se(streq_ptr(c, NULL));
1242
1243         p = original = "  ";
1244         assert_se(unquote_many_words(&p, &a, &b, &c, NULL) == 0);
1245         assert_se(p == original+2);
1246         assert_se(streq_ptr(a, NULL));
1247         assert_se(streq_ptr(b, NULL));
1248         assert_se(streq_ptr(c, NULL));
1249
1250         p = original = "foobar";
1251         assert_se(unquote_many_words(&p, NULL) == 0);
1252         assert_se(p == original);
1253
1254         p = original = "foobar waldi";
1255         assert_se(unquote_many_words(&p, &a, NULL) == 1);
1256         assert_se(p == original+7);
1257         assert_se(streq_ptr(a, "foobar"));
1258         free(a);
1259
1260         p = original = "     foobar    ";
1261         assert_se(unquote_many_words(&p, &a, NULL) == 1);
1262         assert_se(p == original+15);
1263         assert_se(streq_ptr(a, "foobar"));
1264         free(a);
1265 }
1266
1267 int main(int argc, char *argv[]) {
1268         log_parse_environment();
1269         log_open();
1270
1271         test_streq_ptr();
1272         test_align_power2();
1273         test_max();
1274         test_container_of();
1275         test_first_word();
1276         test_close_many();
1277         test_parse_boolean();
1278         test_parse_pid();
1279         test_parse_uid();
1280         test_safe_atolli();
1281         test_safe_atod();
1282         test_strappend();
1283         test_strstrip();
1284         test_delete_chars();
1285         test_in_charset();
1286         test_hexchar();
1287         test_unhexchar();
1288         test_octchar();
1289         test_unoctchar();
1290         test_decchar();
1291         test_undecchar();
1292         test_cescape();
1293         test_cunescape();
1294         test_foreach_word();
1295         test_foreach_word_quoted();
1296         test_default_term_for_tty();
1297         test_memdup_multiply();
1298         test_hostname_is_valid();
1299         test_u64log2();
1300         test_get_process_comm();
1301         test_protect_errno();
1302         test_parse_size();
1303         test_config_parse_iec_off();
1304         test_strextend();
1305         test_strrep();
1306         test_split_pair();
1307         test_fstab_node_to_udev_node();
1308         test_get_files_in_directory();
1309         test_in_set();
1310         test_writing_tmpfile();
1311         test_hexdump();
1312         test_log2i();
1313         test_foreach_string();
1314         test_filename_is_safe();
1315         test_string_has_cc();
1316         test_ascii_strlower();
1317         test_files_same();
1318         test_is_valid_documentation_url();
1319         test_file_in_same_dir();
1320         test_endswith();
1321         test_close_nointr();
1322         test_unlink_noerrno();
1323         test_readlink_and_make_absolute();
1324         test_read_one_char();
1325         test_ignore_signals();
1326         test_strshorten();
1327         test_strappenda();
1328         test_is_symlink();
1329         test_pid_is_unwaited();
1330         test_pid_is_alive();
1331         test_search_and_fopen();
1332         test_search_and_fopen_nulstr();
1333         test_glob_exists();
1334         test_execute_directory();
1335         test_unquote_first_word();
1336         test_unquote_many_words();
1337
1338         return 0;
1339 }