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", 24 tst_strsig(WTERMSIG(status))); 25 26 return buf; 27 } 28 invalid(int status)29const char *invalid(int status) 30 { 31 snprintf(buf, sizeof(buf), "invalid status 0x%x", status); 32 33 return buf; 34 } 35 tst_strstatus(int status)36const char *tst_strstatus(int status) 37 { 38 if (WIFEXITED(status)) 39 return exited(status); 40 41 if (WIFSIGNALED(status)) 42 return signaled(status); 43 44 if (WIFSTOPPED(status)) 45 return "is stopped"; 46 47 if (WIFCONTINUED(status)) 48 return "is resumed"; 49 50 return invalid(status); 51 } 52