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
This commit is contained in:
parent
92f8e97892
commit
00d27e5dd7
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue