Petr Vorel | acc16bc | 2019-06-13 19:25:30 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Cyril Hrubis | 37587b3 | 2017-10-12 17:00:52 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz> |
Cyril Hrubis | 37587b3 | 2017-10-12 17:00:52 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <sys/types.h> |
| 7 | #include <sys/wait.h> |
| 8 | #include <stdio.h> |
| 9 | #define TST_NO_DEFAULT_MAIN |
| 10 | #include "tst_test.h" |
| 11 | |
| 12 | static char buf[32]; |
| 13 | |
| 14 | const char *exited(int status) |
| 15 | { |
Petr Vorel | f885348 | 2017-10-31 09:40:38 +0100 | [diff] [blame] | 16 | snprintf(buf, sizeof(buf), "exited with %i", WEXITSTATUS(status)); |
Cyril Hrubis | 37587b3 | 2017-10-12 17:00:52 +0200 | [diff] [blame] | 17 | |
| 18 | return buf; |
| 19 | } |
| 20 | |
| 21 | const char *signaled(int status) |
| 22 | { |
| 23 | snprintf(buf, sizeof(buf), "killed by %s", tst_strsig(status)); |
| 24 | |
| 25 | return buf; |
| 26 | } |
| 27 | |
| 28 | const char *invalid(int status) |
| 29 | { |
| 30 | snprintf(buf, sizeof(buf), "invalid status 0x%x", status); |
| 31 | |
| 32 | return buf; |
| 33 | } |
| 34 | |
| 35 | const char *tst_strstatus(int status) |
| 36 | { |
| 37 | if (WIFEXITED(status)) |
| 38 | return exited(status); |
| 39 | |
| 40 | if (WIFSIGNALED(status)) |
| 41 | return signaled(status); |
| 42 | |
| 43 | if (WIFSTOPPED(status)) |
| 44 | return "is stopped"; |
| 45 | |
| 46 | if (WIFCONTINUED(status)) |
| 47 | return "is resumed"; |
| 48 | |
| 49 | return invalid(status); |
| 50 | } |