1 /*
2 * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <sys/types.h>
19 #include <sys/wait.h>
20 #include <stdio.h>
21 #define TST_NO_DEFAULT_MAIN
22 #include "tst_test.h"
23
24 static char buf[32];
25
exited(int status)26 const char *exited(int status)
27 {
28 snprintf(buf, sizeof(buf), "exited with %i", WEXITSTATUS(status));
29
30 return buf;
31 }
32
signaled(int status)33 const char *signaled(int status)
34 {
35 snprintf(buf, sizeof(buf), "killed by %s", tst_strsig(status));
36
37 return buf;
38 }
39
invalid(int status)40 const char *invalid(int status)
41 {
42 snprintf(buf, sizeof(buf), "invalid status 0x%x", status);
43
44 return buf;
45 }
46
tst_strstatus(int status)47 const char *tst_strstatus(int status)
48 {
49 if (WIFEXITED(status))
50 return exited(status);
51
52 if (WIFSIGNALED(status))
53 return signaled(status);
54
55 if (WIFSTOPPED(status))
56 return "is stopped";
57
58 if (WIFCONTINUED(status))
59 return "is resumed";
60
61 return invalid(status);
62 }
63