[LTP] [PATCH v2 1/2] tst_taint: print readable error instead of numerical codes

Kushal Chand kushalkataria5@gmail.com
Tue Jan 18 06:57:45 CET 2022


Fixes: #776

This patch prints human readable messages when kernel is tainted instead of numerical codes.

Git Hub Issue link  - https://github.com/linux-test-project/ltp/issues/776

---
 lib/tst_taint.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/lib/tst_taint.c b/lib/tst_taint.c
index 49146aacb..3289c115c 100644
--- a/lib/tst_taint.c
+++ b/lib/tst_taint.c
@@ -8,6 +8,32 @@
 
 static unsigned int taint_mask = -1;
 
+const char *tst_strtaint(int err)
+{
+	static const struct pair taint_pairs[] = {
+		STRPAIR(TST_TAINT_A, "A (ACPI table overridden)")
+		STRPAIR(TST_TAINT_B, "B (Bad page reference)")
+		STRPAIR(TST_TAINT_C, "C (Staging driver loaded)")
+		STRPAIR(TST_TAINT_D, "D (OOPS/BUG)")
+		STRPAIR(TST_TAINT_E, "E (Unsigned module loaded)")
+		STRPAIR(TST_TAINT_F, "F (Module force loaded)")
+		STRPAIR(TST_TAINT_G, "G (Propriety module loaded)")
+		STRPAIR(TST_TAINT_I, "I (Workaround BIOS/FW bug)")
+		STRPAIR(TST_TAINT_K, "K (Live patched)")
+		STRPAIR(TST_TAINT_L, "L (Soft lock up occured)")
+		STRPAIR(TST_TAINT_M, "M (Machine check exception)")
+		STRPAIR(TST_TAINT_O, "O (Out of tree module loaded)")
+		STRPAIR(TST_TAINT_R, "R (Module force unloaded)")
+		STRPAIR(TST_TAINT_S, "S (Running on out of spec system)")
+		STRPAIR(TST_TAINT_T, "T (Built with struct randomization)")
+		STRPAIR(TST_TAINT_U, "U (User request)")
+		STRPAIR(TST_TAINT_W, "W (Warning)")
+		STRPAIR(TST_TAINT_X, "X (Auxilary)")
+	};
+
+	PAIR_LOOKUP(taint_pairs, err);
+}
+
 static unsigned int tst_taint_read(void)
 {
 	unsigned int val;
@@ -90,7 +116,8 @@ void tst_taint_init(unsigned int mask)
 	}
 
 	if ((taint & taint_mask) != 0)
-		tst_brk(TBROK, "Kernel is already tainted: %u", taint);
+		tst_brk(TBROK, "Kernel is already tainted: %s",
+			tst_strtaint(taint));
 }
 
 
-- 
2.25.1



More information about the ltp mailing list