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