From 6d5bba1fe6e97ccb7a8cd5c1f5135deefc8c9bd2 Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Sun, 4 Sep 2016 20:24:07 +0300 Subject: [PATCH] Basic support for functional/regression testing. --- .gitignore | 2 ++ Makefile.am | 5 ++++- configure.ac | 1 + tests/1st.t | 1 + tests/Makefile.am | 55 +++++++++++++++++++++++++++++++++++++++++++++++ tests/README.org | 25 +++++++++++++++++++++ tests/test_run.sh | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 tests/1st.t create mode 100644 tests/Makefile.am create mode 100644 tests/README.org create mode 100755 tests/test_run.sh diff --git a/.gitignore b/.gitignore index 2b2513c..e130de4 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,5 @@ GTAGS /sysbench/drivers/attachsql/.deps/ /config/test-driver *.DS_Store +/tests/*.log +/tests/*.trs diff --git a/Makefile.am b/Makefile.am index aaa09f3..3a9898b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -17,6 +17,9 @@ ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = doc sysbench +SUBDIRS = doc sysbench tests EXTRA_DIST = autogen.sh README.md README-WIN.txt ChangeLog + +test: + cd tests && $(MAKE) test diff --git a/configure.ac b/configure.ac index 26e68b3..d3204bb 100644 --- a/configure.ac +++ b/configure.ac @@ -461,5 +461,6 @@ sysbench/tests/db/Makefile sysbench/scripting/Makefile sysbench/scripting/lua/Makefile sysbench/scripting/lua/src/Makefile +tests/Makefile ]) AC_OUTPUT diff --git a/tests/1st.t b/tests/1st.t new file mode 100644 index 0000000..1cb3d28 --- /dev/null +++ b/tests/1st.t @@ -0,0 +1 @@ + $ sysbench help >/dev/null 2>&1 diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..4eb5e43 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,55 @@ +# Copyright (C) 2016 Alexey Kopytov +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +TESTS = test_run.sh + +test_SCRIPTS = test_run.sh + +EXTRA_DIST = $(test_SCRIPTS) \ + README.org + +testroot = $(datadir) +testdir = $(testroot)/sysbench/tests +test_dirs= . + +# Used by dist-hook and install-data-local to copy all +# test files into either dist or install directory +install_test_files: + @if test -z "$(INSTALL_TO_DIR)"; then \ + echo "Set INSTALL_TO_DIR!" && exit 1; \ + fi + @for dir in $(test_dirs); do \ + from_dir="$(srcdir)/$$dir"; \ + to_dir="$(INSTALL_TO_DIR)/$$dir"; \ + $(mkinstalldirs) "$$to_dir"; \ + for f in `(cd $$from_dir && ls *.t)`; do \ + if test -f "$$from_dir/$$f"; then \ + $(INSTALL_DATA) "$$from_dir/$$f" "$$to_dir/$$f" ; \ + fi; \ + done \ + done + +dist-hook: + $(MAKE) INSTALL_TO_DIR="$(distdir)" install_test_files + +install-data-local: + $(MAKE) INSTALL_TO_DIR="$(DESTDIR)$(testdir)" install_test_files + +uninstall-local: + rm -f -r $(DESTDIR)$(testdir) + +test: + ./test_run.sh diff --git a/tests/README.org b/tests/README.org new file mode 100644 index 0000000..4332a3e --- /dev/null +++ b/tests/README.org @@ -0,0 +1,25 @@ +* sysbench Test Suite + +sysbench uses the [[https://bitheap.org/cram/][Cram]] framework for functional and regression +testing. If your system has Python 2.7.9 or later, or Python 3.4 or +later, installing Cram is as simple as executing =pip install cram=. + +If you use an older Python version, you may need to [[https://pip.pypa.io/en/latest/installing/][install pip]] first: + +#+BEGIN_EXAMPLE +curl https://bootstrap.pypa.io/get-pip.py | python +#+END_EXAMPLE + +To run the sysbench test suite, invoke the =test_run.sh= script in the +=tests= directory like this: + +#+BEGIN_EXAMPLE +./test_run.sh [test_name]... +#+END_EXAMPLE + +Each =test_name= argument is name of a test case file. Functional and +regression tests are located in the same directory in files with the +=.t= suffix. + +If no tests are named on the =test_run.sh= command line, it will execute +all files with the =.t= suffix in the current directory. diff --git a/tests/test_run.sh b/tests/test_run.sh new file mode 100755 index 0000000..2efbce2 --- /dev/null +++ b/tests/test_run.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + +# Copyright (C) 2016 Alexey Kopytov +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +set -eu + +if [ -x "$PWD/../sysbench/sysbench" ] +then + # Invoked from a source directory? + export PATH=$PWD/../sysbench:$PATH +elif [ -x "$PWD/../bin" ] +then + # Invoked from a standalone install root directory? + export PATH=$PWD/../bin:$PATH +elif [ -x "$PWD/../../../bin/sysbench" ] +then + # Invoked from a system-wide install (e.g. /usr/local/share/sysbench/tests)? + export PATH=$PWD/../../../bin:$PATH +fi + +if ! which sysbench >/dev/null 2>&1 +then + echo "Cannot find sysbench in PATH=$PATH" + exit 1 +fi + +if [ $# -lt 1 ] +then + # Automake defines $srcdir where test datafiles are located on 'make check' + if [ -z ${srcdir+x} ] + then + testroot="." + else + testroot="$srcdir" + fi + tests="${testroot}/*.t" +else + tests="$*" +fi + +cram --shell=/bin/bash --verbose $tests