diff options
author | Manuel Bentele | 2020-10-23 15:18:01 +0200 |
---|---|---|
committer | Manuel Bentele | 2020-10-23 15:18:01 +0200 |
commit | dbb41ce2b7f309d394054a6bd1e33afd578798a5 (patch) | |
tree | 6a31092063d9f2fb5ac5720ec6759040e793c3d5 /src/kernel/tests/lib/tst_status.c | |
parent | Set Linux kernel version to unknown if it is not detectable (diff) | |
download | xloop-dbb41ce2b7f309d394054a6bd1e33afd578798a5.tar.gz xloop-dbb41ce2b7f309d394054a6bd1e33afd578798a5.tar.xz xloop-dbb41ce2b7f309d394054a6bd1e33afd578798a5.zip |
Move the source code of all xloop components to the common 'src' directory
Diffstat (limited to 'src/kernel/tests/lib/tst_status.c')
-rw-r--r-- | src/kernel/tests/lib/tst_status.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/kernel/tests/lib/tst_status.c b/src/kernel/tests/lib/tst_status.c new file mode 100644 index 0000000..f1affea --- /dev/null +++ b/src/kernel/tests/lib/tst_status.c @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz> + */ + +#include <sys/types.h> +#include <sys/wait.h> +#include <stdio.h> +#define TST_NO_DEFAULT_MAIN +#include "tst_test.h" + +static char buf[32]; + +const char *exited(int status) +{ + snprintf(buf, sizeof(buf), "exited with %i", WEXITSTATUS(status)); + + return buf; +} + +const char *signaled(int status) +{ + snprintf(buf, sizeof(buf), "killed by %s", tst_strsig(status)); + + return buf; +} + +const char *invalid(int status) +{ + snprintf(buf, sizeof(buf), "invalid status 0x%x", status); + + return buf; +} + +const char *tst_strstatus(int status) +{ + if (WIFEXITED(status)) + return exited(status); + + if (WIFSIGNALED(status)) + return signaled(status); + + if (WIFSTOPPED(status)) + return "is stopped"; + + if (WIFCONTINUED(status)) + return "is resumed"; + + return invalid(status); +} |