mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: <steffen.schwigon@amd.com>
To: <linux-kernel@vger.kernel.org>
Cc: <ss5@renormalist.net>, <srostedt@redhat.com>,
	<Dariusz.Filipski@comarch.com>,
	<yoshitake.kobayashi@toshiba.co.jp>, <sassmann@redhat.com>,
	<andre.przywara@amd.com>, <frank.arnold@amd.com>,
	<conny.seidel@amd.com>, <csd@broadcom.com>,
	Steffen Schwigon <steffen.schwigon@amd.com>
Subject: [PATCH 2/2] A common test subdirectory
Date: Tue, 23 Oct 2012 10:03:02 +0200	[thread overview]
Message-ID: <1350979382-19983-3-git-send-email-steffen.schwigon@amd.com> (raw)
In-Reply-To: <1350979382-19983-1-git-send-email-steffen.schwigon@amd.com>

From: Steffen Schwigon <steffen.schwigon@amd.com>

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@amd.com>
---
 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



      parent reply	other threads:[~2012-10-23  8:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-23  8:03 [PATCH 0/2] RFC: A common test container steffen.schwigon
2012-10-23  8:03 ` [PATCH 1/2] bash-test-utils: support writing functional tests steffen.schwigon
2012-10-23  8:03 ` steffen.schwigon [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1350979382-19983-3-git-send-email-steffen.schwigon@amd.com \
    --to=steffen.schwigon@amd.com \
    --cc=Dariusz.Filipski@comarch.com \
    --cc=andre.przywara@amd.com \
    --cc=conny.seidel@amd.com \
    --cc=csd@broadcom.com \
    --cc=frank.arnold@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sassmann@redhat.com \
    --cc=srostedt@redhat.com \
    --cc=ss5@renormalist.net \
    --cc=yoshitake.kobayashi@toshiba.co.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®