From 24e16e97ed172909d30a6adf498e2c38dd7384dd Mon Sep 17 00:00:00 2001 From: Mark Riddoch Date: Wed, 20 Aug 2014 11:07:28 +0100 Subject: [PATCH] Updates for unit tests --- server/core/test/makefile | 36 +++++--- server/core/test/runtest.sh | 10 +++ server/core/test/testfilter.c | 153 ++++++++++++++++++++++++++++++++ server/core/test/testspinlock.c | 1 + 4 files changed, 186 insertions(+), 14 deletions(-) create mode 100755 server/core/test/runtest.sh create mode 100644 server/core/test/testfilter.c diff --git a/server/core/test/makefile b/server/core/test/makefile index 5f82b7fef..446027948 100644 --- a/server/core/test/makefile +++ b/server/core/test/makefile @@ -10,7 +10,18 @@ include ../../../test.inc CC=cc TESTLOG := $(shell pwd)/testhash.log -TESTS=testhash testspinlock +LOGPATH := $(ROOT_PATH)/log_manager +UTILSPATH := $(ROOT_PATH)/utils + +LDFLAGS=-rdynamic -L$(LOGPATH) \ + -Wl,-rpath,$(DEST)/lib \ + -Wl,-rpath,$(LOGPATH) -Wl,-rpath,$(UTILSPATH) \ + -Wl,-rpath,$(EMBEDDED_LIB) + +LIBS= -lz -lm -lcrypt -lcrypto -ldl -laio -lrt -pthread -llog_manager \ + -L../../inih/extra -linih -lssl -lstdc++ + +TESTS=testhash testspinlock testfilter cleantests: - $(DEL) *.o @@ -34,24 +45,21 @@ testspinlock: testspinlock.c -I$(ROOT_PATH)/server/include \ -I$(ROOT_PATH)/utils \ testspinlock.c ../spinlock.o ../atomic.o ../thread.o -o testspinlock +testfilter: testfilter.c libcore.a + $(CC) $(CFLAGS) $(LDFLAGS) \ + -I$(ROOT_PATH)/server/include \ + -I$(ROOT_PATH)/utils \ + testfilter.c libcore.a $(UTILSPATH)/skygw_utils.o $(LIBS) -o testfilter -runtests: +libcore.a: ../*.o + ar rv libcore.a ../*.o + +runtests: $(TESTS) @echo "" > $(TESTLOG) @echo "-------------------------------" >> $(TESTLOG) @echo $(shell date) >> $(TESTLOG) @echo "Test MaxScale core" >> $(TESTLOG) @echo "-------------------------------" >> $(TESTLOG) - @ -./testhash 2>> $(TESTLOG) -ifeq ($?,0) - @echo "MaxScale hashtable PASSED" >> $(TESTLOG) -else - @echo "MaxScale hashtable FAILED" >> $(TESTLOG) -endif - @ -./testspinlock 2>> $(TESTLOG) -ifeq ($?,0) - @echo "MaxScale spinlock PASSED" >> $(TESTLOG) -else - @echo "MaxScale spinlock FAILED" >> $(TESTLOG) -endif + $(foreach var,$(TESTS),./runtest.sh $(var) $(TESTLOG);) @echo "" >> $(TESTLOG) @cat $(TESTLOG) >> $(TEST_MAXSCALE_LOG) diff --git a/server/core/test/runtest.sh b/server/core/test/runtest.sh new file mode 100755 index 000000000..434d45701 --- /dev/null +++ b/server/core/test/runtest.sh @@ -0,0 +1,10 @@ +#!/bin/bash +test=$1 +log=$2 +echo Running test $test >> $log +./$test 2>> $log +if [ $? -ne 0 ]; then + echo $test " " FAILED >> $log +else + echo $test " " PASSED >> $log +fi diff --git a/server/core/test/testfilter.c b/server/core/test/testfilter.c new file mode 100644 index 000000000..eefc8ecfa --- /dev/null +++ b/server/core/test/testfilter.c @@ -0,0 +1,153 @@ +/* + * This file is distributed as part of MaxScale. It 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, + * version 2. + * + * 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. + * + * Copyright SkySQL Ab 2014 + */ + +/** + * + * @verbatim + * Revision History + * + * Date Who Description + * 19-08-2014 Mark Riddoch Initial implementation + * + * @endverbatim + */ + +#include +#include +#include + +#include + + +/** + * test1 Filter creation, finding and deletion + * + */ +static int +test1() +{ +FILTER_DEF *f1, *f2; + + if ((f1 = filter_alloc("test1", "module")) == NULL) + { + fprintf(stderr, "filter_alloc: test 1 failed.\n"); + return 1; + } + if ((f2 = filter_find("test1")) == NULL) + { + fprintf(stderr, "filter_find: test 2 failed.\n"); + return 1; + } + filter_free(f1); + if ((f2 = filter_find("test1")) != NULL) + { + fprintf(stderr, "filter_find: test 3 failed delete.\n"); + return 1; + } + + return 0; +} + + +/** + * Passive tests for filter_add_option and filter_add_parameter + * + * These tests add options and parameters to a filter, the only failure + * is related hard crashes, such as SIGSEGV etc. as there are no good hooks + * to check the creation of parameters and options currently. + */ +static int +test2() +{ +FILTER_DEF *f1; + + if ((f1 = filter_alloc("test1", "module")) == NULL) + { + fprintf(stderr, "filter_alloc: test 1 failed.\n"); + return 1; + } + filterAddOption(f1, "option1"); + filterAddOption(f1, "option2"); + filterAddOption(f1, "option3"); + filterAddParameter(f1, "name1", "value1"); + filterAddParameter(f1, "name2", "value2"); + filterAddParameter(f1, "name3", "value3"); + return 0; +} + + +/** + * test3 Filter creation, finding and deletion soak test + * + */ +static int +test3() +{ +FILTER_DEF *f1; +char name[40]; +int i, n_filters = 1000; + + for (i = 0; i < n_filters; i++) + { + sprintf(name, "filter%d", i); + if ((f1 = filter_alloc(name, "module")) == NULL) + { + fprintf(stderr, + "filter_alloc: test 3 failed with %s.\n", name); + return 1; + } + } + for (i = 0; i < n_filters; i++) + { + sprintf(name, "filter%d", i); + if ((f1 = filter_find(name)) == NULL) + { + fprintf(stderr, "filter_find: test 3 failed.\n"); + return 1; + } + } + for (i = 0; i < n_filters; i++) + { + sprintf(name, "filter%d", i); + if ((f1 = filter_find(name)) == NULL) + { + fprintf(stderr, "filter_find: test 3 failed.\n"); + return 1; + } + filter_free(f1); + if ((f1 = filter_find(name)) != NULL) + { + fprintf(stderr, + "filter_find: test 3 failed - found deleted filter.\n"); + return 1; + } + } + + return 0; +} +main(int argc, char **argv) +{ +int result = 0; + + result += test1(); + result += test2(); + result += test3(); + + exit(result); +} + diff --git a/server/core/test/testspinlock.c b/server/core/test/testspinlock.c index 5d03f0e47..bcbfa2a3f 100644 --- a/server/core/test/testspinlock.c +++ b/server/core/test/testspinlock.c @@ -125,6 +125,7 @@ main(int argc, char **argv) int result = 0; result += test1(); + result += test2(); exit(result); }