]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-exit-status.c
sd-bus: Add sd_bus_message_peek_type docs
[thirdparty/systemd.git] / src / test / test-exit-status.c
CommitLineData
e1714f02
ZJS
1/* SPDX-License-Identifier: LGPL-2.1+ */
2
3#include "exit-status.h"
00d27e5d 4#include "string-util.h"
e1714f02
ZJS
5#include "tests.h"
6
7static 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 ?: "-",
38288f0b 17 class ? " (" : "", strempty(class), class ? ")" : "");
f0d67dcd
ZJS
18
19 if (s)
20 assert_se(exit_status_from_string(s) == i);
e1714f02
ZJS
21 }
22}
23
f0d67dcd
ZJS
24static 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
00d27e5d
ZJS
35static 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
e1714f02
ZJS
44int main(int argc, char *argv[]) {
45 test_setup_logging(LOG_DEBUG);
46
47 test_exit_status_to_string();
f0d67dcd 48 test_exit_status_from_string();
00d27e5d 49 test_exit_status_NUMA_POLICY();
e1714f02
ZJS
50
51 return 0;
52}