| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "exit-status.h" |
| 4 |
#include "tests.h" |
| 5 |
|
| 6 |
TEST(exit_status_to_string) { |
| 7 |
for (int i = -1; i <= 256; i++) { |
| 8 |
const char *s, *class; |
| 9 |
|
| 10 |
s = exit_status_to_string(i, EXIT_STATUS_FULL); |
| 11 |
class = exit_status_class(i); |
| 12 |
log_info("%d: %s%s%s%s", |
| 13 |
i, s ?: "-", |
| 14 |
class ? " (" : "", strempty(class), class ? ")" : ""); |
| 15 |
|
| 16 |
if (s) |
| 17 |
assert_se(exit_status_from_string(s) == i); |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
TEST(exit_status_from_string) { |
| 22 |
assert_se(exit_status_from_string("11") == 11); |
| 23 |
assert_se(exit_status_from_string("-1") == -ERANGE); |
| 24 |
assert_se(exit_status_from_string("256") == -ERANGE); |
| 25 |
assert_se(exit_status_from_string("foo") == -EINVAL); |
| 26 |
assert_se(exit_status_from_string("SUCCESS") == 0); |
| 27 |
assert_se(exit_status_from_string("FAILURE") == 1); |
| 28 |
} |
| 29 |
|
| 30 |
TEST(exit_status_NUMA_POLICY) { |
| 31 |
ASSERT_STREQ(exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_FULL), "NUMA_POLICY"); |
| 32 |
ASSERT_STREQ(exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_SYSTEMD), "NUMA_POLICY"); |
| 33 |
assert_se(!exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_BSD)); |
| 34 |
assert_se(!exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_LSB)); |
| 35 |
} |
| 36 |
|
| 37 |
DEFINE_TEST_MAIN(LOG_DEBUG); |