diff --git a/tests/Makefile.am b/tests/Makefile.am index ad3207d..495bc5a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,214 +1,216 @@ # Copyright (c) 2010 Red Hat, Inc. # # Authors: Angus Salkeld # # This file is part of libqb. # # libqb 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 # (at your option) any later version. # # libqb 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 libqb. If not, see . # -MAINTAINERCLEANFILES = Makefile.in -EXTRA_DIST = -CLEANFILES = +MAINTAINERCLEANFILES = Makefile.in auto_write_logs.c +EXTRA_DIST = make-log-test.sh all_ipcs.test blackbox-segfault.sh +CLEANFILES = $(auto_c_files) ${auto_c_files:.c=.opp} auto_write_logs.c export SOCKETDIR AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include noinst_PROGRAMS = bmc bmcpt bms rbreader rbwriter \ bench-log format_compare_speed loop print_ver \ $(check_PROGRAMS) noinst_HEADERS = check_common.h format_compare_speed_SOURCES = format_compare_speed.c $(top_builddir)/include/qb/qbutil.h format_compare_speed_LDADD = $(top_builddir)/lib/libqb.la bmc_SOURCES = bmc.c bmc_LDADD = $(top_builddir)/lib/libqb.la bmcpt_SOURCES = bmcpt.c bmcpt_CFLAGS = $(PTHREAD_CFLAGS) bmcpt_LDADD = $(PTHREAD_LIBS) $(top_builddir)/lib/libqb.la bms_SOURCES = bms.c bms_CFLAGS = $(GLIB_CFLAGS) bms_LDADD = $(top_builddir)/lib/libqb.la $(GLIB_LIBS) rbwriter_SOURCES = rbwriter.c rbwriter_LDADD = $(top_builddir)/lib/libqb.la rbreader_SOURCES = rbreader.c rbreader_LDADD = $(top_builddir)/lib/libqb.la loop_SOURCES = loop.c loop_LDADD = $(top_builddir)/lib/libqb.la inc_dir = $(top_srcdir)/include/qb public_headers = $(sort $(patsubst %.in,%,$(subst $(inc_dir)/,,$(shell \ printf 'include $(inc_dir)/Makefile.am\n\n%%.var:\n\t@echo $$($$*)' \ | MAKEFLAGS= ${MAKE} --no-print-directory -f- inst_HEADERS.var \ || echo $(inc_dir)/qb*.h*)))) auto_c_files = $(patsubst %.h,auto_check_header_%.c,$(public_headers)) -CLEANFILES += $(auto_c_files) # this works for both non/generated headers thanks to VPATH being # automatically set to $(top_srcdir)/tests and $(top_builddir) # being resolved to ".." by automake # ($(top_srcdir)/tests/../include/qb/%.h = $(top_srcdir)/include/qb/%.h) auto_check_header_%.c: $(top_builddir)/include/qb/%.h @name=$$(echo "$<" | sed "s|.*qb/qb||" | sed "s|\.h||") ;\ NAME=$$(echo $$name | tr [:lower:] [:upper:]) ;\ echo "#include " > $@_ ;\ echo "#ifndef QB_$${NAME}_H_DEFINED" >> $@_ ;\ echo "#error no header protector in file qb$$name.h" >> $@_ ;\ echo "#endif" >> $@_ ;\ echo "int main(void) {return 0;}" >> $@_ $(AM_V_GEN)mv $@_ $@ check: check-headers # rely on implicit automake rule to include right (local) includes .PHONY: check-headers check-headers: $(auto_c_files:.c=.o) $(auto_c_files:.c=.opp) # this is to check basic sanity of using libqb from C++ code, if possible %.opp: %.c if HAVE_GXX $(AM_V_GEN)$(CXX) $(AM_CPPFLAGS) -c $(CPPFLAGS) $(CXXFLAGS) -o $@ $< else @echo "C++ compatibility tests not run" endif -CLEANFILES += ${auto_c_files:.c=.opp} - -distclean-local: - rm -rf auto_*.c - rm -rf .deps - if HAVE_DICT_WORDS if HAVE_SLOW_TESTS -EXTRA_DIST += make-log-test.sh -CLEANFILES += auto_write_logs.c -MAINTAINERCLEANFILES += auto_write_logs.c - nodist_bench_log_SOURCES = auto_write_logs.c bench_log: auto_write_logs.c $(builddir)/auto_write_logs.c: make-log-test.sh @$(srcdir)/make-log-test.sh > $(builddir)/write_logs-tmp.c $(AM_V_GEN)mv $(builddir)/write_logs-tmp.c $(builddir)/auto_write_logs.c endif endif bench_log_SOURCES = bench-log.c bench_log_LDADD = $(top_builddir)/lib/libqb.la libdir= $(TESTDIR) if HAVE_CHECK -libstat_wrapper_la_SOURCES = libstat_wrapper.c -libstat_wrapper_la_LIBADD = -ldl - -EXTRA_DIST += all_ipcs.test -EXTRA_DIST += blackbox-segfault.sh - TESTS = array.test map.test rb.test list.test log.test blackbox-segfault.sh loop.test all_ipcs.test TESTS_ENVIRONMENT = export PATH=.:../tools:$$PATH; resources.log: rb.log log.log all_ipcs.log -check_PROGRAMS = array.test ipc.test list.test log.test loop.test \ +check_PROGRAMS = array.test ipc.test ipc_sock.test list.test log.test loop.test \ map.test rb.test util.test tlist.test \ crash_test_dummy file_change_bytes dist_check_SCRIPTS = all_ipcs.test blackbox-segfault.sh check_LTLIBRARIES = if HAVE_SLOW_TESTS TESTS += util.test check_PROGRAMS += util.test endif if INSTALL_TESTS testsuitedir = $(TESTDIR) testsuite_PROGRAMS = $(check_PROGRAMS) testsuite_SCRIPTS = $(dist_check_SCRIPTS) test.conf -lib_LTLIBRARIES = libstat_wrapper.la -else -noinst_LTLIBRARIES = libstat_wrapper.la endif file_change_bytes_SOURCES = file_change_bytes.c crash_test_dummy_SOURCES = crash_test_dummy.c crash_test_dummy_CFLAGS = @CHECK_CFLAGS@ crash_test_dummy_LDADD = $(top_builddir)/lib/libqb.la @CHECK_LIBS@ array_test_SOURCES = check_array.c array_test_CFLAGS = @CHECK_CFLAGS@ array_test_LDADD = $(top_builddir)/lib/libqb.la @CHECK_LIBS@ map_test_SOURCES = check_map.c map_test_CFLAGS = @CHECK_CFLAGS@ map_test_LDADD = $(top_builddir)/lib/libqb.la @CHECK_LIBS@ rb_test_SOURCES = check_rb.c rb_test_CFLAGS = @CHECK_CFLAGS@ rb_test_LDADD = $(top_builddir)/lib/libqb.la @CHECK_LIBS@ loop_test_SOURCES = check_loop.c loop_test_CFLAGS = @CHECK_CFLAGS@ loop_test_LDADD = $(top_builddir)/lib/libqb.la @CHECK_LIBS@ tlist_test_SOURCES = check_tlist.c tlist_test_CFLAGS = @CHECK_CFLAGS@ tlist_test_LDADD = $(top_builddir)/lib/libqb.la @CHECK_LIBS@ +if HAVE_FAILURE_INJECTION +check_LTLIBRARIES += _failure_injection.la +_failure_injection_la_SOURCES = _failure_injection.c _failure_injection.h +_failure_injection_la_LDFLAGS = -module +_failure_injection_la_LIBADD = $(dlopen_LIBS) +endif + +check_LTLIBRARIES += _libstat_wrapper.la +_libstat_wrapper_la_SOURCES = _libstat_wrapper.c +_libstat_wrapper_la_LDFLAGS = -module +_libstat_wrapper_la_LIBADD = $(dlopen_LIBS) + ipc_test_SOURCES = check_ipc.c ipc_test_CFLAGS = @CHECK_CFLAGS@ ipc_test_LDADD = $(top_builddir)/lib/libqb.la @CHECK_LIBS@ -if HAVE_FAILURE_INJECTION -ipc_test_LDADD += _failure_injection.la - if HAVE_GLIB ipc_test_CFLAGS += $(GLIB_CFLAGS) ipc_test_LDADD += $(GLIB_LIBS) endif +if HAVE_FAILURE_INJECTION +ipc_test_LDADD += _failure_injection.la +endif -check_LTLIBRARIES += _failure_injection.la -_failure_injection_la_SOURCES = _failure_injection.c _failure_injection.h -_failure_injection_la_LDFLAGS = -module -_failure_injection_la_LIBADD = $(dlopen_LIBS) +ipc_sock_test_SOURCES = check_ipc.c +ipc_sock_test_CFLAGS = @CHECK_CFLAGS@ +ipc_sock_test_LDADD = $(top_builddir)/lib/libqb.la @CHECK_LIBS@ +if HAVE_GLIB +ipc_sock_test_CFLAGS += $(GLIB_CFLAGS) +ipc_sock_test_LDADD += $(GLIB_LIBS) +endif +ipc_sock_test_LDADD += _libstat_wrapper.la +if HAVE_FAILURE_INJECTION +ipc_sock_test_LDADD += _failure_injection.la endif check_LTLIBRARIES += _syslog_override.la _syslog_override_la_SOURCES = _syslog_override.c _syslog_override.h _syslog_override_la_LDFLAGS = -module log_test_SOURCES = check_log.c log_test_CFLAGS = @CHECK_CFLAGS@ log_test_LDADD = $(top_builddir)/lib/libqb.la @CHECK_LIBS@ log_test_LDADD += _syslog_override.la util_test_SOURCES = check_util.c util_test_CFLAGS = @CHECK_CFLAGS@ util_test_LDADD = $(top_builddir)/lib/libqb.la @CHECK_LIBS@ list_test_SOURCES = check_list.c list_test_CFLAGS = @CHECK_CFLAGS@ list_test_LDADD = $(top_builddir)/lib/libqb.la @CHECK_LIBS@ endif clean-local: rm -f *.log rm -f *.fdata + +distclean-local: + rm -rf auto_*.c + rm -rf .deps diff --git a/tests/libstat_wrapper.c b/tests/_libstat_wrapper.c similarity index 100% rename from tests/libstat_wrapper.c rename to tests/_libstat_wrapper.c diff --git a/tests/all_ipcs.test b/tests/all_ipcs.test index fd9052f..d2810e4 100755 --- a/tests/all_ipcs.test +++ b/tests/all_ipcs.test @@ -1,137 +1,130 @@ #!/bin/sh # Run all of the IPC tests in one script. This is needed because # make check could run with -j and the start and resource 'tests' # need to run first and last respectively. # Clean-up params SOCKS_PER_PROCESS=3 EXPECTED_DLOCK=6 EXPECTED_LEFTOVER=2 tidy_qb_dirs() { for dd in "$@"; do rm $dd rmdir $(dirname $dd) 2> /dev/null done } run_shm_ipcs() { echo "======================= Running SHM IPC tests =======================" ./ipc.test } generate_sockname() { # # Generate a unique(ish) name for the IPCs we will use in the tests and # save it in a file for all of the tests to use. This way we know for sure # which sockets are our and which we can ignore. # The test programs all add "qb-test--" to the front of this. # NAME="$$-$(date +%s)" printf "$NAME" > ipc-test-name if [ ! -d $SOCKETDIR ] then mkdir -p $SOCKETDIR fi } run_sock_ipcs() { # filesystem socket IPC test if [ "$(uname -s)" = "Linux" ] && [ "`id -u`" = "0" ] then echo "======================= Running socket IPC tests =======================" - if [ -f "$(pwd)/.libs/libstat_wrapper.so" ] - then - export "LD_PRELOAD=$(pwd)/.libs/libstat_wrapper.so" - else - export "LD_PRELOAD=$(pwd)/libstat_wrapper.so" - fi - - ./ipc.test + ./ipc_sock.test RES=$? if [ "$RES" = "0" ] then EXPECTED_DLOCK=12 EXPECTED_LEFTOVER=4 fi fi return $RES } generate_sockname # Normal IPC test run_shm_ipcs RESULT=$? # Socket IPC test run_sock_ipcs # Don't override previous failure status if [ $? != 0 ] then RESULT=$? fi # Tidy up and check leftovers IPC_NAME=$(cat ipc-test-name 2>/dev/null) for d in /dev/shm /var/run $SOCKETDIR; do # Tidy up the deadlock checker sockets first dlocks=$(find $d -name "qb-*-test_*dlock*${IPC_NAME}*" -size +0c 2>/dev/null) if [ "$(echo $dlocks|wc -w)" -eq $(($SOCKS_PER_PROCESS * $EXPECTED_DLOCK)) ]; then tidy_qb_dirs $dlocks rm $dlocks elif [ -n "${dlocks}" ]; then echo echo "Error: dlock shared memory segments not closed/unlinked" echo RETURN=1 fi # Now look for other expected leftovers leftovers=$(find $d -name "qb-*-test_*${IPC_NAME}*" -size +0c 2>/dev/null | wc -l) if [ "${leftovers}" -gt 0 ]; then echo echo "Error: shared memory segments not closed/unlinked" echo RETURN=1 fi leftovers="$(find $d -name "qb-*-test_*${IPC_NAME}*" -size 0c 2>/dev/null)" if [ "$(printf '%s\n' "${leftovers}" | wc -l)" -eq $(($SOCKS_PER_PROCESS * $EXPECTED_LEFTOVER)) ]; then echo echo "There were some empty leftovers (expected), removing them" echo "${leftovers}" echo tidy_qb_dirs $leftovers elif [ -n "${leftovers}" ]; then echo echo "Error: unexpected number of empty leftovers" echo "${leftovers}" echo RETURN=1 fi done # Clean up empty /dev/shm directories left over by some tests DIRS=$(grep "Free'ing ringbuffer" all_ipcs.log | cut -f4 -d ' '|cut -f-4 -d'/'|sort|uniq) for i in $DIRS do rmdir $i 2>/dev/null done ps aux | grep -v grep | grep -E 'lt-.*\.test' if [ $? -eq 0 ]; then echo "test program frozen" RETURN=1 fi # Keep it tidy - distcheck checks we have not left a mess rm -f ipc-test-name rm -f crash_test_dummy.core exit $RETURN diff --git a/tests/ipc_sock.test b/tests/ipc_sock.test deleted file mode 100755 index 0f77111..0000000 --- a/tests/ipc_sock.test +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh -# -# Run the IPC tests under the stat wrapper, -# this simulates /etc/libqb/use-filesystem-sockets existing -# so we can test both options without breaking other things -# that might be running on this system. -# -# This creates sockets in /var/run so needs to be root -# -if [ "$(uname -s)" = "Linux" ] && [ "`id -u`" = "0" ] -then - if [ -f "$(pwd)/.libs/libstat_wrapper.so" ] - then - export "LD_PRELOAD=$(pwd)/.libs/libstat_wrapper.so" - else - export "LD_PRELOAD=$(pwd)/libstat_wrapper.so" - fi - ./ipc.test -else - exit 0 -fi diff --git a/tests/resources.test b/tests/resources.test deleted file mode 100755 index 25dbf54..0000000 --- a/tests/resources.test +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/sh -RETURN=0 -SOCKS_PER_PROCESS=3 -EXPECTED_DLOCK=6 -EXPECTED_LEFTOVER=2 - -# Linux also runs filesystem socket tests -if [ "$(uname -s)" = "Linux" ] && [ "`id -u`" = "0" ] -then - EXPECTED_DLOCK=12 - EXPECTED_LEFTOVER=4 -fi - -tidy_qb_dirs() -{ - for dd in "$@"; do - rm $dd - rmdir $(dirname $dd) 2> /dev/null - done -} - - -IPC_NAME=$(cat ipc-test-name 2>/dev/null) -for d in /dev/shm /var/run $SOCKETDIR; do - - # Tidy up the deadlock checker sockets first - dlocks=$(find $d -name "qb-*-test_*dlock*${IPC_NAME}*" -size +0c 2>/dev/null) - if [ "$(echo $dlocks|wc -w)" -eq $(($SOCKS_PER_PROCESS * $EXPECTED_DLOCK)) ]; then - tidy_qb_dirs $dlocks - rm $dlocks - elif [ -n "${dlocks}" ]; then - echo - echo "Error: dlock shared memory segments not closed/unlinked" - echo - RETURN=1 - fi - - # Now look for other expected leftovers - leftovers=$(find $d -name "qb-*-test_*${IPC_NAME}*" -size +0c 2>/dev/null | wc -l) - if [ "${leftovers}" -gt 0 ]; then - echo - echo "Error: shared memory segments not closed/unlinked" - echo - RETURN=1 - fi - leftovers="$(find $d -name "qb-*-test_*${IPC_NAME}*" -size 0c 2>/dev/null)" - if [ "$(printf '%s\n' "${leftovers}" | wc -l)" -eq $(($SOCKS_PER_PROCESS * $EXPECTED_LEFTOVER)) ]; then - echo - echo "There were some empty leftovers (expected), removing them" - echo "${leftovers}" - echo - tidy_qb_dirs $leftovers - elif [ -n "${leftovers}" ]; then - echo - echo "Error: unexpected number of empty leftovers" - echo "${leftovers}" - echo - RETURN=1 - fi -done - -# Clean up empty /dev/shm directories left over by some tests -DIRS=$(grep "Free'ing ringbuffer" ipc.log ipc_sock.log| cut -f4 -d ' '|cut -f-4 -d'/'|sort|uniq) -for i in $DIRS -do - rmdir $i 2>/dev/null -done - - -ps aux | grep -v grep | grep -E 'lt-.*\.test' -if [ $? -eq 0 ]; then - echo "test program frozen" - RETURN=1 -fi - -# Keep it tidy - distcheck checks we have not left a mess -rm -f ipc-test-name -rm -f crash_test_dummy.core -exit $RETURN diff --git a/tests/start.test b/tests/start.test deleted file mode 100755 index 7f63540..0000000 --- a/tests/start.test +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -# -# Generate a unique(ish) name for the IPCs we will use in the tests and -# save it in a file for all of the tests to use. This way we know for sure -# which sockets are our and which we can ignore. -# The test programs all add "qb-test--" to the front of this. -# - -NAME="$$-$(date +%s)" - -printf "$NAME" > ipc-test-name -mkdir -p $SOCKETDIR