blob: f1affeac501688e5f3014abd06f74b7e9d9ef206 [file] [log] [blame]
Petr Vorelacc16bc2019-06-13 19:25:30 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Cyril Hrubis37587b32017-10-12 17:00:52 +02002/*
3 * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
Cyril Hrubis37587b32017-10-12 17:00:52 +02004 */
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
12static char buf[32];
13
14const char *exited(int status)
15{
Petr Vorelf8853482017-10-31 09:40:38 +010016 snprintf(buf, sizeof(buf), "exited with %i", WEXITSTATUS(status));
Cyril Hrubis37587b32017-10-12 17:00:52 +020017
18 return buf;
19}
20
21const char *signaled(int status)
22{
23 snprintf(buf, sizeof(buf), "killed by %s", tst_strsig(status));
24
25 return buf;
26}
27
28const char *invalid(int status)
29{
30 snprintf(buf, sizeof(buf), "invalid status 0x%x", status);
31
32 return buf;
33}
34
35const 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}