From 00d27e5dd74a6c67759def1e958a71aae0650976 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 5 Aug 2019 16:36:45 +0200 Subject: [PATCH] shared/exit-status: fix lookup FLAGS_SET() is the wrong operator here, because we want to see if *any* bits are set. Add test. https://github.com/systemd/systemd/pull/12884#issuecomment-518238410 --- src/shared/exit-status.c | 2 +- src/test/test-exit-status.c | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/shared/exit-status.c b/src/shared/exit-status.c index 44b1c9b749..3704f5d481 100644 --- a/src/shared/exit-status.c +++ b/src/shared/exit-status.c @@ -99,7 +99,7 @@ const ExitStatusMapping exit_status_mappings[256] = { const char* exit_status_to_string(int code, ExitStatusClass class) { if (code < 0 || (size_t) code >= ELEMENTSOF(exit_status_mappings)) return NULL; - return FLAGS_SET(exit_status_mappings[code].class, class) ? exit_status_mappings[code].name : NULL; + return class & exit_status_mappings[code].class ? exit_status_mappings[code].name : NULL; } const char* exit_status_class(int code) { diff --git a/src/test/test-exit-status.c b/src/test/test-exit-status.c index 3bcebd06a4..a007bda5c4 100644 --- a/src/test/test-exit-status.c +++ b/src/test/test-exit-status.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ #include "exit-status.h" +#include "string-util.h" #include "tests.h" static void test_exit_status_to_string(void) { @@ -31,11 +32,21 @@ static void test_exit_status_from_string(void) { assert_se(exit_status_from_string("FAILURE") == 1); } +static void test_exit_status_NUMA_POLICY(void) { + log_info("/* %s */", __func__); + + assert_se(streq(exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_FULL), "NUMA_POLICY")); + assert_se(streq(exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_SYSTEMD), "NUMA_POLICY")); + assert_se(!exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_BSD)); + assert_se(!exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_LSB)); +} + int main(int argc, char *argv[]) { test_setup_logging(LOG_DEBUG); test_exit_status_to_string(); test_exit_status_from_string(); + test_exit_status_NUMA_POLICY(); return 0; } -- 2.25.1