From a4215c3632c13218bb389d1f066549ab783028e3 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Fri, 11 Sep 2020 11:48:48 +0200 Subject: Added testcases from the Linux testing project (LTP) --- kernel/tests/lib/tst_status.c | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 kernel/tests/lib/tst_status.c (limited to 'kernel/tests/lib/tst_status.c') diff --git a/kernel/tests/lib/tst_status.c b/kernel/tests/lib/tst_status.c new file mode 100644 index 0000000..f1affea --- /dev/null +++ b/kernel/tests/lib/tst_status.c @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2017 Cyril Hrubis + */ + +#include +#include +#include +#define TST_NO_DEFAULT_MAIN +#include "tst_test.h" + +static char buf[32]; + +const char *exited(int status) +{ + snprintf(buf, sizeof(buf), "exited with %i", WEXITSTATUS(status)); + + return buf; +} + +const char *signaled(int status) +{ + snprintf(buf, sizeof(buf), "killed by %s", tst_strsig(status)); + + return buf; +} + +const char *invalid(int status) +{ + snprintf(buf, sizeof(buf), "invalid status 0x%x", status); + + return buf; +} + +const char *tst_strstatus(int status) +{ + if (WIFEXITED(status)) + return exited(status); + + if (WIFSIGNALED(status)) + return signaled(status); + + if (WIFSTOPPED(status)) + return "is stopped"; + + if (WIFCONTINUED(status)) + return "is resumed"; + + return invalid(status); +} -- cgit v1.2.3-55-g7522