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