1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz> 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 exited(int status)14const char *exited(int status) 15 { 16 snprintf(buf, sizeof(buf), "exited with %i", WEXITSTATUS(status)); 17 18 return buf; 19 } 20 signaled(int status)21const char *signaled(int status) 22 { 23 snprintf(buf, sizeof(buf), "killed by %s", tst_strsig(status)); 24 25 return buf; 26 } 27 invalid(int status)28const char *invalid(int status) 29 { 30 snprintf(buf, sizeof(buf), "invalid status 0x%x", status); 31 32 return buf; 33 } 34 tst_strstatus(int status)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 } 51