]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-exit-status.c
resolve: allow configurable bind address
[thirdparty/systemd.git] / src / test / test-exit-status.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include "exit-status.h"
4 #include "string-util.h"
5 #include "tests.h"
6
7 static void test_exit_status_to_string(void) {
8 log_info("/* %s */", __func__);
9
10 for (int i = -1; i <= 256; i++) {
11 const char *s, *class;
12
13 s = exit_status_to_string(i, EXIT_STATUS_FULL);
14 class = exit_status_class(i);
15 log_info("%d: %s%s%s%s",
16 i, s ?: "-",
17 class ? " (" : "", strempty(class), class ? ")" : "");
18
19 if (s)
20 assert_se(exit_status_from_string(s) == i);
21 }
22 }
23
24 static void test_exit_status_from_string(void) {
25 log_info("/* %s */", __func__);
26
27 assert_se(exit_status_from_string("11") == 11);
28 assert_se(exit_status_from_string("-1") == -ERANGE);
29 assert_se(exit_status_from_string("256") == -ERANGE);
30 assert_se(exit_status_from_string("foo") == -EINVAL);
31 assert_se(exit_status_from_string("SUCCESS") == 0);
32 assert_se(exit_status_from_string("FAILURE") == 1);
33 }
34
35 static void test_exit_status_NUMA_POLICY(void) {
36 log_info("/* %s */", __func__);
37
38 assert_se(streq(exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_FULL), "NUMA_POLICY"));
39 assert_se(streq(exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_SYSTEMD), "NUMA_POLICY"));
40 assert_se(!exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_BSD));
41 assert_se(!exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_LSB));
42 }
43
44 int main(int argc, char *argv[]) {
45 test_setup_logging(LOG_DEBUG);
46
47 test_exit_status_to_string();
48 test_exit_status_from_string();
49 test_exit_status_NUMA_POLICY();
50
51 return 0;
52 }