git » libjio » commit b3b87af

Add some scripts and make targets to make testing easier

author Alberto Bertogli
2011-02-22 23:03:57 UTC
committer Alberto Bertogli
2011-02-22 23:03:57 UTC
parent 13d64ea3908eac5e5686992e081e99897060142d

Add some scripts and make targets to make testing easier

This commit adds some scripts that are used by two make targets, "tests" and
"tests-fi", to run a reasonable set of tests against the built library (as
opposed to using the installed version, which is what the tests do if run
without a special environment).

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

INSTALL +11 -0
Makefile +10 -1
tests/util/README +6 -0
tests/util/build_lib_env.sh +26 -0
tests/util/quick-test-run.sh +54 -0
tests/util/wrap-python +37 -0

diff --git a/INSTALL b/INSTALL
index 13e479c..08ac159 100644
--- a/INSTALL
+++ b/INSTALL
@@ -37,3 +37,14 @@ them, you should have libjio already installed.
  - To build the Python 3 bindings, run "make python3". To install them, run
    "make python3_install".
 
+
+Tests
+-----
+
+Several tests can be found in the "tests/" directory. For practical purposes,
+there are two make targets that run a reasonable set of tests against the
+built version of the library:
+
+ - To run the standard tests, run "make tests".
+ - To run the tests with fault injection support, run "make FI=1 tests-fi".
+
diff --git a/Makefile b/Makefile
index c5c046d..2a02f2d 100644
--- a/Makefile
+++ b/Makefile
@@ -30,6 +30,15 @@ preload:
 preload_install: preload
 	$(MAKE) -C bindings/preload/ install
 
+tests: all python2 python3
+	tests/util/quick-test-run.sh normal
+
+tests-fi: all python2 python3
+	@if [ "$(FI)" != "1" ]; then \
+		echo "Error: $@ has to be run using:  make FI=1 $@"; \
+		exit 1; \
+	fi
+	tests/util/quick-test-run.sh fiu
 
 clean:
 	$(MAKE) -C libjio/ clean
@@ -40,5 +49,5 @@ clean:
 .PHONY: default all libjio install \
 	python2 python2_install python3 python3_install \
 	preload preload_install \
-	clean
+	tests tests-fiu clean
 
diff --git a/tests/util/README b/tests/util/README
new file mode 100644
index 0000000..9d105fa
--- /dev/null
+++ b/tests/util/README
@@ -0,0 +1,6 @@
+These are useful scripts for running the tests against the built library
+(instead of running them against the installed version).
+
+The most user-friendly script is the quick-test-run.sh, which is safe to run
+after building the library.
+
diff --git a/tests/util/build_lib_env.sh b/tests/util/build_lib_env.sh
new file mode 100755
index 0000000..f3f3234
--- /dev/null
+++ b/tests/util/build_lib_env.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+# Apply the environment changes needed to use the built (and not the
+# installed) versions of the library and Python bindings.
+#
+# They are useful for running tests before installing.
+#
+# Is intended use is to be sourced in the shell, for example:
+#
+#   $ source build_lib_env.sh
+#   $ ./some-binary-using-the-library
+#
+# Although the most common users will be the other test scripts.
+
+# We assume we're in the tests/util directory of the libjio source tree.
+OURDIR=$(readlink -f $(dirname $0))
+
+LIBBIN=$(readlink -f "$OURDIR"/../../libjio/build/libjio.so)
+
+if ! [ -x "$LIBBIN" ]; then
+	echo "Can't find library (run make)"
+	exit 1
+fi
+
+export "LD_LIBRARY_PATH=$(dirname $LIBBIN):$LD_LIBRARY_PATH"
+
diff --git a/tests/util/quick-test-run.sh b/tests/util/quick-test-run.sh
new file mode 100755
index 0000000..474a477
--- /dev/null
+++ b/tests/util/quick-test-run.sh
@@ -0,0 +1,54 @@
+#!/bin/bash
+
+# This is a convenience script for running some of the other tests without
+# manual intervention, as a means of a fast and easy correctness test.
+#
+# If you are making an intrusive or risky change, please take the time to run
+# the other tests by hand with more intensive parameters, and check the
+# coverage and use the other tools mentioned in the README.
+
+# Find our directory, which we will use to find the other tools
+OURDIR=$(readlink -f $(dirname $0))
+
+
+# Find the built versions of the library and Python bindings and add them to
+# the lookup paths, so we run against them
+. $OURDIR/build_lib_env.sh
+
+cd $OURDIR/
+
+if [ "$1" != "normal" ] && [ "$1" != "fiu" ]; then
+	echo "Usage: `basename $0` [normal|fiu]"
+	exit 1
+fi
+
+set -e
+
+case "$1" in
+	normal)
+		echo "behaviour tests (normal)"
+		./wrap-python 2 ../behaviour/runtests normal
+		echo
+		echo "stress tests (normal)"
+		./wrap-python 3 ../stress/jiostress \
+			$(tempfile -p libjio-tests) 20 -n 50 -p 3
+		;;
+	fiu)
+		echo "behaviour tests (all)"
+		./wrap-python 2 ../behaviour/runtests all
+		echo
+		echo "stress tests (normal)"
+		./wrap-python 3 ../stress/jiostress \
+			$(tempfile -p libjio-tests) 20 -n 50 -p 3
+		echo
+		echo "stress tests (fiu)"
+		./wrap-python 3 ../stress/jiostress \
+			$(tempfile -p libjio-tests) 20 -n 50 --fi
+		;;
+esac
+
+echo
+echo
+echo Tests completed successfuly
+echo
+
diff --git a/tests/util/wrap-python b/tests/util/wrap-python
new file mode 100755
index 0000000..bd75575
--- /dev/null
+++ b/tests/util/wrap-python
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+# Python 2 wrapper, which makes it able to import the build (and not the
+# installed) version of libjio.
+# The first parameter must be the python version (2 or 3)
+
+PYVER="$1"
+shift
+
+if [ "$PYVER" != 2 ] && [ "$PYVER" != 3 ]; then
+	echo "Error: the first argument must be the version (2 or 3)"
+	exit 1
+fi
+
+# Find our directory, which we will use to find the other tools
+OURDIR=$(readlink -f $(dirname $0))
+
+# Find the built versions of the library and Python bindings and add them to
+# the lookup paths, so we run against them
+. $OURDIR/build_lib_env.sh
+
+MODBIN=$(readlink -f \
+		"$OURDIR"/../../bindings/python/build/lib*-$PYVER.*/libjio.so)
+
+if ! [ -x "$MODBIN" ]; then
+	echo "Can't find python$PYVER bindings (run make python$PYVER)"
+	exit 1
+fi
+
+export "PYTHONPATH=$(dirname $MODBIN):$PYTHONPATH"
+
+if [ "$PYVER" == 2 ]; then
+	exec python "$@"
+else
+	exec python3 "$@"
+fi
+