public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selftests: Add a taint selftest
@ 2022-08-23 21:19 Andrew Delgadilo
  2022-08-24  5:06 ` Greg KH
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Delgadilo @ 2022-08-23 21:19 UTC (permalink / raw)
  To: Shuah Khan
  Cc: linux-kernel, linux-kselftest, dylanbhatch, sashalevin, gthelen,
	adelg

From: Andrew Delgadillo <adelg@google.com>

When testing a kernel, one of the earliest signals one can get is if a
kernel has become tainted. For example, an organization might be
interested in mass testing commits on their hardware. An obvious first
step would be to make sure every commit boots, and a next step would be
to make sure there are no warnings/crashes/lockups, hence the utility of
a taint test.

Signed-off-by: Andrew Delgadillo <adelg@google.com>
---
 tools/testing/selftests/core/Makefile |  1 +
 tools/testing/selftests/core/taint.sh | 28 +++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)
 create mode 100755 tools/testing/selftests/core/taint.sh

diff --git a/tools/testing/selftests/core/Makefile b/tools/testing/selftests/core/Makefile
index f6f2d6f473c6a..695bdbfb02f90 100644
--- a/tools/testing/selftests/core/Makefile
+++ b/tools/testing/selftests/core/Makefile
@@ -2,6 +2,7 @@
 CFLAGS += -g -I../../../../usr/include/
 
 TEST_GEN_PROGS := close_range_test
+TEST_PROGS := taint.sh
 
 include ../lib.mk
 
diff --git a/tools/testing/selftests/core/taint.sh b/tools/testing/selftests/core/taint.sh
new file mode 100755
index 0000000000000..661c2cb8cd9bf
--- /dev/null
+++ b/tools/testing/selftests/core/taint.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+set -oue pipefail
+
+# By default, we only want to check if our system has:
+# - seen an oops or bug
+# - a warning occurred
+# - a lockup occurred
+# The bit values for these, and more, can be found at
+# Documentation/admin-guide/tainted-kernels.html
+# This value can be overridden by passing a mask as the
+# first positional argument.
+taint_bitmask=$(( 128 + 512 + 16384 ))
+
+# If we have a positional argument, then override our
+# default bitmask.
+if [[ -n "${1-}" ]]; then
+	taint_bitmask=$1
+fi
+
+taint_bits=$(cat /proc/sys/kernel/tainted)
+
+result=$(( taint_bitmask & taint_bits ))
+if [[ "$result" -ne 0 ]]; then
+	exit 1
+fi
+
+exit 0
-- 
2.37.1.595.g718a3a8f04-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-08-24  6:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-23 21:19 [PATCH] selftests: Add a taint selftest Andrew Delgadilo
2022-08-24  5:06 ` Greg KH
2022-08-24  5:50   ` Andrew Delgadillo
2022-08-24  6:22     ` Greg KH
2022-08-24  5:51   ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox