summaryrefslogtreecommitdiffstats
path: root/kernel/tests/lib/tst_status.c
diff options
context:
space:
mode:
authorManuel Bentele2020-09-11 11:48:48 +0200
committerManuel Bentele2020-09-16 07:37:56 +0200
commita4215c3632c13218bb389d1f066549ab783028e3 (patch)
tree0468836ef5303f6eb94b876189ccaa60a7a2b453 /kernel/tests/lib/tst_status.c
parentUpdated README with documentation of general information and build options (diff)
downloadxloop-a4215c3632c13218bb389d1f066549ab783028e3.tar.gz
xloop-a4215c3632c13218bb389d1f066549ab783028e3.tar.xz
xloop-a4215c3632c13218bb389d1f066549ab783028e3.zip
Added testcases from the Linux testing project (LTP)
Diffstat (limited to 'kernel/tests/lib/tst_status.c')
-rw-r--r--kernel/tests/lib/tst_status.c50
1 files changed, 50 insertions, 0 deletions
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 <chrubis@suse.cz>
+ */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <stdio.h>
+#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);
+}