diff --git a/server/core/test/makefile b/server/core/test/makefile index 2a2856a13..db540d7b1 100644 --- a/server/core/test/makefile +++ b/server/core/test/makefile @@ -23,22 +23,18 @@ buildtests : $(CC) $(CFLAGS) \ -I$(ROOT_PATH)/server/include \ -I$(ROOT_PATH)/utils \ - testhash.c ../hashtable.o ../atomic.o ../spinlock.o -o testhash \ + testhash.c ../hashtable.o ../atomic.o ../spinlock.o -o testhash -runtests: +runtests: @echo "" >> $(TESTLOG) @echo "-------------------------------" >> $(TESTLOG) @echo $(shell date) >> $(TESTLOG) @echo "Test MaxScale core" >> $(TESTLOG) @echo "-------------------------------" >> $(TESTLOG) - @./testhash 0 1 2>> $(TESTLOG) - @./testhash 10 1 2>> $(TESTLOG) - @./testhash 1000 10 2>> $(TESTLOG) - @./testhash 10 0 2>> $(TESTLOG) - @./testhash 1500 17 2>> $(TESTLOG) - @./testhash 1 1 2>> $(TESTLOG) - @./testhash 10000 133 2>> $(TESTLOG) - @./testhash 1000 1000 2>> $(TESTLOG) - @./testhash 1000 100000 2>> $(TESTLOG) + @-./testhash 2>> $(TESTLOG) +ifeq ($?, 0) @echo "MaxScale core PASSED" >> $(TESTLOG) +else + @echo "MaxScale core FAILED" >> $(TESTLOG) +endif @echo "" >> $(TESTLOG) diff --git a/server/core/test/testhash.c b/server/core/test/testhash.c index 3e98a0b2f..6aac2d016 100644 --- a/server/core/test/testhash.c +++ b/server/core/test/testhash.c @@ -28,46 +28,18 @@ static int cmpfun( } - - -/** - * @node Simple test which creates hashtable and frees it. Size and number of entries - * sre specified by user and passed as arguments. - * - * Parameters: - * @param argc - - * - * - * @param argv - - * - * - * @return - * - * - * @details (write detailed description here) - * - */ -int main(int argc, char** argv) +static bool do_hashtest( + int argelems, + int argsize) { + bool succp = true; HASHTABLE* h; int nelems; int i; int* val_arr; - int argsize; int hsize; - int argelems; int longest; - - if (argc != 3) { - fprintf(stderr, "\nWrong number of arguments. Usage " - ":\n\n\ttesthash <# of elements> <# hash size> " - " \n\n"); - return 1; - } - - argelems = strtol(argv[1], NULL, 10); - argsize = strtol(argv[2], NULL, 10); - + ss_dfprintf(stderr, "testhash : creating hash table of size %d, including %d " "elements in total.", @@ -100,9 +72,37 @@ int main(int argc, char** argv) CHK_HASHTABLE(h); hashtable_free(h); - return 0; + +return_succp: + return succp; } +/** + * @node Simple test which creates hashtable and frees it. Size and number of entries + * sre specified by user and passed as arguments. + * + * + * @return 0 if succeed, 1 if failed. + * + * + * @details (write detailed description here) + * + */ +int main(void) +{ + int rc = 1; - - + if (!do_hashtest(0, 1)) goto return_rc; + if (!do_hashtest(10, 1)) goto return_rc; + if (!do_hashtest(1000, 10)) goto return_rc; + if (!do_hashtest(10, 0)) goto return_rc; + if (!do_hashtest(1500, 17)) goto return_rc; + if (!do_hashtest(1, 1)) goto return_rc; + if (!do_hashtest(10000, 133)) goto return_rc; + if (!do_hashtest(1000, 1000)) goto return_rc; + if (!do_hashtest(1000, 100000)) goto return_rc; + + rc = 0; +return_rc: + return rc; +}