1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) 2017 Cyril Hrubis <[email protected]>
4*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) 2019-2021 Petr Vorel <[email protected]>
5*49cdfc7eSAndroid Build Coastguard Worker */
6*49cdfc7eSAndroid Build Coastguard Worker
7*49cdfc7eSAndroid Build Coastguard Worker /*
8*49cdfc7eSAndroid Build Coastguard Worker * Basic unit test for the tst_strstatus() function.
9*49cdfc7eSAndroid Build Coastguard Worker */
10*49cdfc7eSAndroid Build Coastguard Worker
11*49cdfc7eSAndroid Build Coastguard Worker #include <string.h>
12*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
13*49cdfc7eSAndroid Build Coastguard Worker
14*49cdfc7eSAndroid Build Coastguard Worker static struct tcase {
15*49cdfc7eSAndroid Build Coastguard Worker int status;
16*49cdfc7eSAndroid Build Coastguard Worker const char *str;
17*49cdfc7eSAndroid Build Coastguard Worker } tcases[] = {
18*49cdfc7eSAndroid Build Coastguard Worker {0x0100, "exited with 1"},
19*49cdfc7eSAndroid Build Coastguard Worker {0x0001, "killed by SIGHUP"},
20*49cdfc7eSAndroid Build Coastguard Worker {0x137f, "is stopped"},
21*49cdfc7eSAndroid Build Coastguard Worker {0xffff, "is resumed"},
22*49cdfc7eSAndroid Build Coastguard Worker {0x1ff, "invalid status 0x1ff"},
23*49cdfc7eSAndroid Build Coastguard Worker };
24*49cdfc7eSAndroid Build Coastguard Worker
do_test(unsigned int n)25*49cdfc7eSAndroid Build Coastguard Worker static void do_test(unsigned int n)
26*49cdfc7eSAndroid Build Coastguard Worker {
27*49cdfc7eSAndroid Build Coastguard Worker const char *str_status = tst_strstatus(tcases[n].status);
28*49cdfc7eSAndroid Build Coastguard Worker
29*49cdfc7eSAndroid Build Coastguard Worker if (strcmp(str_status, tcases[n].str))
30*49cdfc7eSAndroid Build Coastguard Worker tst_res(TFAIL, "%s != %s", str_status, tcases[n].str);
31*49cdfc7eSAndroid Build Coastguard Worker else
32*49cdfc7eSAndroid Build Coastguard Worker tst_res(TPASS, "%s", str_status);
33*49cdfc7eSAndroid Build Coastguard Worker }
34*49cdfc7eSAndroid Build Coastguard Worker
35*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
36*49cdfc7eSAndroid Build Coastguard Worker .test = do_test,
37*49cdfc7eSAndroid Build Coastguard Worker .tcnt = ARRAY_SIZE(tcases),
38*49cdfc7eSAndroid Build Coastguard Worker };
39