Problem:
The automake 1.15+ move distcheck folder from "_build" to "_build/sub"
https://lists.gnu.org/archive/html/automake/2015-01/msg00005.html
which cause runtest.sh failed to locate the build folder.
Fix:
* Move "make check" to the top folder.
* Let automake generate runtests.sh from runtests.sh.in
by filling in the @abs_top_srcdir@
* Changed the runtests.sh.in to use build folder and source folder.
Extra changes:
* Improved memory leak check test.
* Memory check in c unit test (valgrind) will fail the test.
# Still have no way to check daemon and plugin memory leak by script.
* Don't remove tmp folder when got error, help developer to debug.
Signed-off-by: Gris Ge <***@redhat.com>
---
.gitignore | 1 +
Makefile.am | 2 +
configure.ac | 2 +
test/Makefile.am | 2 -
test/runtests.sh | 189 --------------------------------------------
test/runtests.sh.in | 224 ++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 229 insertions(+), 191 deletions(-)
delete mode 100755 test/runtests.sh
create mode 100755 test/runtests.sh.in
diff --git a/.gitignore b/.gitignore
index 4147f96..720b637 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,3 +33,4 @@ daemon/lsmd
*.pyc
test/tester
tools/udev/scan-scsi-target
+test/runtests.sh
diff --git a/Makefile.am b/Makefile.am
index 2393c33..7d3d41b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -28,4 +28,6 @@ docs:
rpm: clean
@(unset CDPATH ; $(MAKE) dist && rpmbuild -ta $(distdir).tar.gz)
+TESTS = test/runtests.sh
+
MAINTAINERCLEANFILES = .git-module-status
diff --git a/configure.ac b/configure.ac
index d99952b..b273ff7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -308,4 +308,6 @@ AC_OUTPUT(libstoragemgmt.pc \
packaging/daemon/Makefile \
packaging/libstoragemgmt.spec \
doc/man/Makefile \
+ test/runtests.sh \
test/Makefile)
+chmod +x test/runtests.sh
diff --git a/test/Makefile.am b/test/Makefile.am
index 872e8e0..1eb984a 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -5,8 +5,6 @@ AM_CPPFLAGS = \
EXTRA_DIST=cmdtest.py runtests.sh plugin_test.py
-TESTS = runtests.sh
-
check_PROGRAMS = tester
tester_CFLAGS = $(LIBCHECK_CFLAGS)
tester_LDADD = ../c_binding/libstoragemgmt.la $(LIBCHECK_LIBS)
diff --git a/test/runtests.sh b/test/runtests.sh
deleted file mode 100755
index bf3f95f..0000000
--- a/test/runtests.sh
+++ /dev/null
@@ -1,189 +0,0 @@
-#!/bin/bash
-
-# Copyright (C) 2011-2015 Red Hat, Inc.
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or any later version.
-#
-# This library 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
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; If not, see <http://www.gnu.org/licenses/>.
-#
-# Author: tasleson
-# Gris Ge <***@redhat.com>
-#
-# Unit test case driver
-
-# Make sure these are available in the envirnoment before we start lsmd
-export G_SLICE=always-malloc
-export G_DEBUG=gc-friendly
-export CK_DEFAULT_TIMEOUT=600
-export CK_FORK=no
-
-rundir=$RANDOM
-base=/tmp/$rundir
-
-LSMD_PID=65535
-
-export LSM_TEST_RUNDIR=$rundir
-export LSM_UDS_PATH=$base/lsm/ipc/
-
-LSMD_TMP_LOG_FILE="$base/lsmd.log"
-
-cleanup() {
- #Clean up the daemon if it is running
- if [ "CHK$LSMD_PID" != "CHK" ] && [ "CHK$LSMD_PID" != "CHK65535" ]
- then
- kill -s KILL $LSMD_PID
- fi
-
- cat $LSMD_TMP_LOG_FILE
- if [ -e $LSM_UDS_PATH ]
- then
- chmod +w -R $base
- rm -rf $base
- fi
-}
-
-good() {
- echo "executing: $1"
- eval $1
- ec=$?
- if [ $ec -ne 0 ]; then
- echo "Fail exit[$ec]: $1"
- cleanup
- exit 1
- fi
-}
-
-# Add a signal handler to clean-up
-trap "cleanup; exit 1" INT
-
-# Unset these as they can cause the test case to fail
-# specifically the password one, but remove both.
-unset LSMCLI_PASSWORD
-unset LSMCLI_URI
-
-#Put us in a consistent spot
-cd "$(dirname "$0")"
-
-#Get base root directory
-testdir=`pwd`
-rootdir=${testdir%/*}
-
-#Are we running within distcheck?
-c_unit=$rootdir/test/tester
-LSMD_DAEMON=$rootdir/daemon/lsmd
-shared_libs=$rootdir/c_binding/.libs/
-bin_plugin=$rootdir/plugin/simc/.libs/
-lsm_py_folder=$rootdir/python_binding
-lsm_plugin_py_folder=$rootdir/plugin
-lsmcli_py_folder=$rootdir/tools/lsmcli
-py_scsi_folder=$rootdir/python_binding/lsm/.libs/
-
-if [ -e $rootdir/_build ]
-then
- c_unit=$rootdir/_build/test/tester
- LSMD_DAEMON=$rootdir/_build/daemon/lsmd
- shared_libs=$rootdir/_build/c_binding/.libs/
- bin_plugin=$rootdir/_build/plugin/simc/.libs/
- py_scsi_folder=$rootdir/_build/python_binding/lsm/.libs/
- # In distcheck, all folder is read only(except _build and _inst).
- # which prevent us from linking plugin and lsmcli into python/lsm folder.
- chmod +w $rootdir/python_binding/lsm
-fi
-
-#With a distcheck you cannot muck with the source file system, so we will copy
-#plugins somewhere else.
-plugins=$base/plugins
-
-#Export needed vars
-export PYTHONPATH=$base/python
-export LD_LIBRARY_PATH=$base/lib
-export LSM_SIM_DATA="$base/lsm_sim_data"
-
-echo "testdir= $testdir"
-echo "rootdir= $rootdir"
-echo "c_unit= $c_unit"
-
-#Create the directory for the unix domain sockets
-good "mkdir -p $LSM_UDS_PATH"
-good "mkdir -p $plugins"
-good "mkdir -p $LD_LIBRARY_PATH"
-good "mkdir -p $PYTHONPATH"
-
-good "chmod 777 $base"
-good "chmod 777 $LSM_UDS_PATH"
-good "chmod 777 $plugins"
-good "chmod 777 $LD_LIBRARY_PATH"
-good "chmod 777 $PYTHONPATH"
-
-#Copy shared libraries
-good "cp $shared_libs/*.so.* $LD_LIBRARY_PATH"
-
-# Copy python modules as libstoragemgmt user might not able to access
-# code in other path. This is common when compile as root with libstoragemgmt
-# user account exists.
-good "cp -av $lsm_py_folder/lsm $PYTHONPATH/"
-# In case the plugin and lsmcli link also copyed.
-if [ -e "$PYTHONPATH/lsm/plugin" ] || [ -L "$PYTHONPATH/lsm/plugin" ];then
- good "rm $PYTHONPATH/lsm/plugin"
-fi
-good "cp -av $lsm_plugin_py_folder $PYTHONPATH/lsm/"
-if [ -e "$PYTHONPATH/lsm/lsmcli" ] || [ -L "$PYTHONPATH/lsm/lsmcli" ];then
- good "rm $PYTHONPATH/lsm/lsmcli"
-fi
-good "cp -av $lsmcli_py_folder $PYTHONPATH/lsm/"
-
-#Copy Python shared library _scsi.so
-good "cp -av $py_scsi_folder/*.so* $PYTHONPATH/lsm/"
-
-#Copy plugins to one directory.
-good "find $rootdir/ \( ! -regex '.*/\..*' \) -type f -name \*_lsmplugin -exec cp {} $plugins \;"
-
-#Copy the actual binary, not the shell script pointing to binary otherwise
-#valgrind does not work.
-good "cp $bin_plugin/*_lsmplugin $plugins"
-good "ls -lh $plugins"
-
-#Check to make sure that constants are correct
-good "perl ../tools/utility/check_const.pl"
-
-#Start daemon
-$LSMD_DAEMON \
- --plugindir $plugins \
- --socketdir $LSM_UDS_PATH \
- -d >$LSMD_TMP_LOG_FILE &
-
-# Let the daemon get settled before running the tests
-sleep 2
-
-LSMD_PID=$(ps aux | grep $LSM_UDS_PATH | grep -v grep | awk '{print $2}')
-
-#Run C unit test
-if [ -z "$LSM_VALGRIND" ]; then
- good "$c_unit"
-else
- good "valgrind --leak-check=full --show-reachable=no --log-file=/tmp/leaking_client $rootdir/test/.libs/tester"
-fi
-
-#Run cmdline against the simulator if we are not checking for leaks
-if [ -z "$LSM_VALGRIND" ]; then
- export LSMCLI_URI='sim://'
- good "$rootdir/test/cmdtest.py -c $plugins/sim_lsmplugin"
- good "$rootdir/test/cmdtest.py -c $rootdir/tools/lsmcli/lsmcli"
-
- #Run the plug-in test against the python simulator
- good "$rootdir/test/plugin_test.py -v --uri sim://"
-fi
-
-#Run the plug-in test against the C simulator"
-good "$rootdir/test/plugin_test.py -v --uri simc://"
-
-#Pretend we were never here
-cleanup
diff --git a/test/runtests.sh.in b/test/runtests.sh.in
new file mode 100755
index 0000000..58060eb
--- /dev/null
+++ b/test/runtests.sh.in
@@ -0,0 +1,224 @@
+#!/bin/bash
+
+# Copyright (C) 2011-2015 Red Hat, Inc.
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or any later version.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; If not, see <http://www.gnu.org/licenses/>.
+#
+# Author: tasleson
+# Gris Ge <***@redhat.com>
+#
+# Unit test case driver
+
+# Make sure these are available in the envirnoment before we start lsmd
+export G_SLICE=always-malloc
+export G_DEBUG=gc-friendly
+export CK_DEFAULT_TIMEOUT=600
+export CK_FORK=no
+
+rundir=$RANDOM
+base=/tmp/$rundir
+leak_log_folder="${base}/leak_logs"
+
+LSMD_PID=65535
+MEM_LEAK_ERROR_CODE=9
+VALGRIND_OPTIONS="
+ --quiet --leak-check=full --show-reachable=no --show-possibly-lost=no
+ --errors-for-leak-kinds=definite --error-exitcode=$MEM_LEAK_ERROR_CODE "
+
+export LSM_TEST_RUNDIR=$rundir
+export LSM_UDS_PATH=$base/lsm/ipc/
+
+LSMD_TMP_LOG_FILE="$base/lsmd.log"
+
+cleanup() {
+ keep_base=$1
+ #Clean up the daemon if it is running
+ if [ "CHK$LSMD_PID" != "CHK" ] && [ "CHK$LSMD_PID" != "CHK65535" ]
+ then
+ kill -s KILL $LSMD_PID
+ fi
+
+ cat $LSMD_TMP_LOG_FILE
+ if [ -e $LSM_UDS_PATH ]
+ then
+ if [ "CHK$keep_base" != "CHKkeep_base" ];then
+ chmod +w -R $base
+ rm -rf $base
+ else
+ echo "Base folder $base is kept for investigation"
+ fi
+ fi
+}
+
+good() {
+ echo "executing: $1"
+ eval $1
+ ec=$?
+ if [ $ec -ne 0 ]; then
+ if [ $ec -eq $MEM_LEAK_ERROR_CODE ];then
+ echo "Found memory leak, logs are stored in $leak_log_folder"
+ else
+ echo "Fail exit[$ec]: $1"
+ fi
+ # We don't do clean on error in case we need to investigate.
+ echo "Base folder is $base, please investigate"
+ cleanup 'keep_base'
+ exit 1
+ fi
+}
+
+# Add a signal handler to clean-up
+trap "cleanup 'keep_base'; exit 1" INT
+
+# Unset these as they can cause the test case to fail
+# specifically the password one, but remove both.
+unset LSMCLI_PASSWORD
+unset LSMCLI_URI
+
+#Put us in a consistent spot
+if [ ! -e "./test" ];then
+ echo "We are running from test folder directly."
+ cd ..
+fi
+
+#Get base root directory
+builddir=$(readlink -f "`pwd`")
+srcdir=$(readlink -f "@abs_top_srcdir@")
+
+c_unit="${builddir}/test/tester"
+LSMD_DAEMON="${builddir}/daemon/lsmd"
+shared_libs="${builddir}/c_binding/.libs/"
+bin_plugin="${builddir}/plugin/simc/.libs/"
+lsm_py_folder="${srcdir}/python_binding"
+lsm_plugin_py_folder="${srcdir}/plugin"
+lsmcli_py_folder="${srcdir}/tools/lsmcli"
+py_scsi_folder="${builddir}/python_binding/lsm/.libs/"
+
+if [ ! -w "$lsm_py_folder/lsm" ]
+then
+ # In distcheck, all folder is read only(except _build and _inst).
+ # which prevent us from linking plugin and lsmcli into python/lsm folder.
+ chmod +w "${lsm_py_folder}/lsm"
+fi
+
+#With a distcheck you cannot muck with the source file system, so we will copy
+#plugins somewhere else.
+plugins=$base/plugins
+
+#Export needed vars
+export PYTHONPATH=$base/python
+export LD_LIBRARY_PATH=$base/lib
+export LSM_SIM_DATA="$base/lsm_sim_data"
+
+echo "srcdir= $srcdir"
+echo "builddir= $builddir"
+echo "c_unit= $c_unit"
+
+#Create the directory for the unix domain sockets
+good "mkdir -p $LSM_UDS_PATH"
+good "mkdir -p $plugins"
+good "mkdir -p $LD_LIBRARY_PATH"
+good "mkdir -p $PYTHONPATH"
+good "mkdir -p $leak_log_folder"
+
+good "chmod 777 $base"
+good "chmod 777 $LSM_UDS_PATH"
+good "chmod 777 $plugins"
+good "chmod 777 $LD_LIBRARY_PATH"
+good "chmod 777 $PYTHONPATH"
+
+#Copy shared libraries
+good "cp $shared_libs/*.so.* $LD_LIBRARY_PATH"
+
+# Copy python modules as libstoragemgmt user might not able to access
+# code in other path. This is common when compile as root with libstoragemgmt
+# user account exists.
+good "cp -av $lsm_py_folder/lsm $PYTHONPATH/"
+# In case the plugin and lsmcli link also copyed.
+if [ -e "$PYTHONPATH/lsm/plugin" ] || [ -L "$PYTHONPATH/lsm/plugin" ];then
+ good "rm $PYTHONPATH/lsm/plugin"
+fi
+good "cp -av $lsm_plugin_py_folder $PYTHONPATH/lsm/"
+if [ -e "$PYTHONPATH/lsm/lsmcli" ] || [ -L "$PYTHONPATH/lsm/lsmcli" ];then
+ good "rm $PYTHONPATH/lsm/lsmcli"
+fi
+good "cp -av $lsmcli_py_folder $PYTHONPATH/lsm/"
+
+#Copy Python shared library _scsi.so
+good "cp -av $py_scsi_folder/*.so* $PYTHONPATH/lsm/"
+
+#Copy python plugins to plugin directory.
+good "find $lsm_plugin_py_folder \( ! -regex '.*/\..*' \)
+ -type f -name \*_lsmplugin -exec cp {} $plugins \;"
+
+#Copy C plugins to plugin directly
+good "find $bin_plugin -type f -name \*_lsmplugin -exec cp {} $plugins \;"
+good "ls -lh $plugins"
+
+#Check to make sure that constants are correct
+good "perl ${srcdir}/tools/utility/check_const.pl"
+
+if [ ! -z "$LSM_VALGRIND" ]; then
+ # Unset the LSM_VALGRIND via env command to skip duplicate memory check
+ # in lsmd.
+ LSMD_DAEMON="libtool --mode execute env --unset=LSM_VALGRIND
+ valgrind ${VALGRIND_OPTIONS}
+ --trace-children=yes --log-file=${leak_log_folder}/lsmd_leaking_%p
+ ${LSMD_DAEMON}"
+fi
+
+#Start daemon
+$LSMD_DAEMON \
+ --plugindir $plugins \
+ --socketdir $LSM_UDS_PATH \
+ -d >$LSMD_TMP_LOG_FILE &
+
+# Let the daemon get settled before running the tests
+sleep 2
+
+LSMD_PID=$(ps aux | grep $LSM_UDS_PATH | grep -v grep | awk '{print $2}')
+
+#Run C unit test
+if [ -z "$LSM_VALGRIND" ]; then
+ good "$c_unit"
+else
+ good "libtool --mode execute valgrind ${VALGRIND_OPTIONS}
+ --trace-children=yes
+ --log-file=${leak_log_folder}/leaking_client
+ $c_unit"
+fi
+
+#Run cmdline against the simulator if we are not checking for leaks
+if [ -z "$LSM_VALGRIND" ]; then
+ export LSMCLI_URI='sim://'
+ good "${srcdir}/test/cmdtest.py -c ${plugins}/sim_lsmplugin"
+ good "${srcdir}/test/cmdtest.py -c ${srcdir}/tools/lsmcli/lsmcli"
+
+ #Run the plug-in test against the python simulator
+ good "${srcdir}/test/plugin_test.py -v --uri sim://"
+fi
+
+#Run the plug-in test against the C simulator"
+good "${srcdir}/test/plugin_test.py -v --uri simc://"
+
+#Check whether we got memory leak.
+if [ ! -z "$LSM_VALGRIND" ];then
+ if [ "CHK$(cat $leak_log_folder/* | wc -l)" != "CHK0" ];then
+ echo "Found memory leak. Failing test"
+ cleanup 'keep_base'
+ exit $MEM_LEAK_ERROR_CODE
+ fi
+fi
+
+#Pretend we were never here
+cleanup
--
2.6.2