[PATCH 2/2] A common test subdirectory

From: steffen.schwigon
Date: Tue Oct 23 2012 - 04:05:02 EST


From: Steffen Schwigon <steffen.schwigon@xxxxxxx>

This commit introduces t/ as a subdirectory for placing
tests that can be run via the existing Linux tool
'prove' (available in all major Linux distributions).

Tests in there are assumed to produce TAP, the "Test
Anything Protocol" (see http://testanything.org).

A library with special utilities to write TAP tests for
Linux (inclusive KVM and Xen support) is provided in the
previous commit ('bash-test-utils'). TAP libraries are
available for many programming languages. The autotest
project already provides TAP support.

Signed-off-by: Steffen Schwigon <steffen.schwigon@xxxxxxx>
---
t/examples/basic.t | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
create mode 100755 t/examples/basic.t

diff --git a/t/examples/basic.t b/t/examples/basic.t
new file mode 100755
index 0000000..d776108
--- /dev/null
+++ b/t/examples/basic.t
@@ -0,0 +1,49 @@
+#!/bin/bash
+
+############################################################
+#
+# t/examples/basic.t
+#
+# An example test script for bash-test-utils
+#
+# Run it with:
+#
+# $ cd $LINUX_SRC_DIR
+# $ prove -v t/examples/basic.t
+#
+############################################################
+
+. ./tools/testing/tap/bash-test-utils
+
+uname -a | grep -q Linux # example for ok exit code
+ok $? "we run on Linux"
+
+# require_* functions gracefully exit if requirements not met
+require_cpufeature "msr"
+require_cpufeature "fpu"
+
+# store success in variables and make complex tests
+if grep -q sse2 /proc/cpuinfo ; then
+ success=0
+else
+ success=1
+fi
+
+# ok() evaluates arg 1 with exit code shell boolean semantics
+# and creates TAP
+ok $success "SSE2 in cpuinfo"
+
+# negate_ok() reverses the success semantics of ok()
+grep -q impossible-value /proc/cpuinfo
+negate_ok $? "no impossible-value in cpuinfo"
+
+# mark tests with "# TODO" at end of description
+# for test driven development
+grep -q not-yet-implemented-detail /proc/cpuinfo
+ok $? "example that fails expectedly # TODO some todo explanation"
+
+# append key:value lines to track values
+bogomips=$(grep -i bogomips /proc/cpuinfo | head -1 | cut -d: -f2)
+append_tapdata "bogomips: $(echo $bogomips)"
+
+done_testing
--
1.7.10.4


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/