From 1054ad3b6ac2e53b9470f6f64e49ce094c3431c6 Mon Sep 17 00:00:00 2001 From: Jeroen van der Heijden Date: Tue, 25 Sep 2018 15:25:45 +0200 Subject: [PATCH] test files --- .gitignore | 2 + .splintrc | 10 ++++ .travis.yml | 26 ++++++++ Release/src/imap32/subdir.mk | 24 -------- Release/src/imap64/subdir.mk | 24 -------- include/qpack/qpack.h | 2 +- {test => itest}/data_google_finance.py | 0 {test => itest}/run_all.py | 0 {test => itest}/siridb-random-data.py | 0 {test => itest}/slow_connection_test.sh | 0 {test => itest}/test_cluster.py | 0 {test => itest}/test_compression.py | 0 {test => itest}/test_group.py | 0 {test => itest}/test_insert.py | 0 {test => itest}/test_list.py | 0 {test => itest}/test_log.py | 0 {test => itest}/test_pipe.c | 0 {test => itest}/test_pipe_support.py | 0 {test => itest}/test_pool.py | 0 {test => itest}/test_select.py | 0 {test => itest}/test_series.py | 0 {test => itest}/test_server.py | 0 {test => itest}/test_syslog.py | 0 {test => itest}/test_user.py | 0 {test => itest}/testing/__init__.py | 0 {test => itest}/testing/client.py | 0 {test => itest}/testing/constants.py | 0 {test => itest}/testing/helpers.py | 0 {test => itest}/testing/pipe_client.py | 0 {test => itest}/testing/series.py | 0 {test => itest}/testing/server.py | 0 {test => itest}/testing/siridb.py | 0 {test => itest}/testing/testbase.py | 0 main.c | 17 ++---- makefile.init | 2 + test/test.h | 45 ++++++++++++++ test/test.sh | 26 ++++++++ test/test_ctree/sources | 2 + test/test_ctree/test_ctree.c | 79 +++++++++++++++++++++++++ test/test_imap/sources | 3 + test/test_imap/test_imap.c | 27 +++++++++ 41 files changed, 228 insertions(+), 61 deletions(-) create mode 100644 .splintrc create mode 100644 .travis.yml delete mode 100644 Release/src/imap32/subdir.mk delete mode 100644 Release/src/imap64/subdir.mk rename {test => itest}/data_google_finance.py (100%) rename {test => itest}/run_all.py (100%) rename {test => itest}/siridb-random-data.py (100%) rename {test => itest}/slow_connection_test.sh (100%) rename {test => itest}/test_cluster.py (100%) rename {test => itest}/test_compression.py (100%) rename {test => itest}/test_group.py (100%) rename {test => itest}/test_insert.py (100%) rename {test => itest}/test_list.py (100%) rename {test => itest}/test_log.py (100%) rename {test => itest}/test_pipe.c (100%) rename {test => itest}/test_pipe_support.py (100%) rename {test => itest}/test_pool.py (100%) rename {test => itest}/test_select.py (100%) rename {test => itest}/test_series.py (100%) rename {test => itest}/test_server.py (100%) rename {test => itest}/test_syslog.py (100%) rename {test => itest}/test_user.py (100%) rename {test => itest}/testing/__init__.py (100%) rename {test => itest}/testing/client.py (100%) rename {test => itest}/testing/constants.py (100%) rename {test => itest}/testing/helpers.py (100%) rename {test => itest}/testing/pipe_client.py (100%) rename {test => itest}/testing/series.py (100%) rename {test => itest}/testing/server.py (100%) rename {test => itest}/testing/siridb.py (100%) rename {test => itest}/testing/testbase.py (100%) create mode 100644 makefile.init create mode 100644 test/test.h create mode 100755 test/test.sh create mode 100755 test/test_ctree/sources create mode 100644 test/test_ctree/test_ctree.c create mode 100644 test/test_imap/sources create mode 100644 test/test_imap/test_imap.c diff --git a/.gitignore b/.gitignore index 2a22e1ca..54fa6de6 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ *.i*86 *.x86_64 *.hex +*.out # Debug files *.dSYM/ @@ -70,4 +71,5 @@ grammar/javagrammar/ .vscode/ # Test +itest/testdir test/testdir diff --git a/.splintrc b/.splintrc new file mode 100644 index 00000000..f51cbeaa --- /dev/null +++ b/.splintrc @@ -0,0 +1,10 @@ +-I ./include/ +-posix-lib +-redef +-syntax +-fcnuse +-unrecog +-exitarg +-boolops ++boolint ++matchanyintegral diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..8ba2e880 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,26 @@ +matrix: + include: + - language: c + os: linux + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-7 + before_script: + - cd Release + script: + - make test + - language: c + os: linux + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-7 + - splint + script: + - splint *.c + diff --git a/Release/src/imap32/subdir.mk b/Release/src/imap32/subdir.mk deleted file mode 100644 index 691cc9f2..00000000 --- a/Release/src/imap32/subdir.mk +++ /dev/null @@ -1,24 +0,0 @@ -################################################################################ -# Automatically-generated file. Do not edit! -################################################################################ - -# Add inputs and outputs from these tool invocations to the build variables -C_SRCS += \ -../src/imap32/imap32.c - -OBJS += \ -./src/imap32/imap32.o - -C_DEPS += \ -./src/imap32/imap32.d - - -# Each subdirectory must supply rules for building sources it contributes -src/imap32/%.o: ../src/imap32/%.c - @echo 'Building file: $<' - @echo 'Invoking: GCC C Compiler' - gcc -I../include -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" - @echo 'Finished building: $<' - @echo ' ' - - diff --git a/Release/src/imap64/subdir.mk b/Release/src/imap64/subdir.mk deleted file mode 100644 index 3f36d7ab..00000000 --- a/Release/src/imap64/subdir.mk +++ /dev/null @@ -1,24 +0,0 @@ -################################################################################ -# Automatically-generated file. Do not edit! -################################################################################ - -# Add inputs and outputs from these tool invocations to the build variables -C_SRCS += \ -../src/imap64/imap64.c - -OBJS += \ -./src/imap64/imap64.o - -C_DEPS += \ -./src/imap64/imap64.d - - -# Each subdirectory must supply rules for building sources it contributes -src/imap64/%.o: ../src/imap64/%.c - @echo 'Building file: $<' - @echo 'Invoking: GCC C Compiler' - gcc -I../include -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" - @echo 'Finished building: $<' - @echo ' ' - - diff --git a/include/qpack/qpack.h b/include/qpack/qpack.h index f385beb2..a432e702 100644 --- a/include/qpack/qpack.h +++ b/include/qpack/qpack.h @@ -172,7 +172,7 @@ static inline int qp_is_raw_term(qp_obj_t * qp_obj) { return (qp_obj->tp == QP_RAW && qp_obj->len && - qp_obj->via.raw[qp_obj->len - 1] == '\0'); + (char) qp_obj->via.raw[qp_obj->len - 1] == '\0'); } /* Add to packer functions */ diff --git a/test/data_google_finance.py b/itest/data_google_finance.py similarity index 100% rename from test/data_google_finance.py rename to itest/data_google_finance.py diff --git a/test/run_all.py b/itest/run_all.py similarity index 100% rename from test/run_all.py rename to itest/run_all.py diff --git a/test/siridb-random-data.py b/itest/siridb-random-data.py similarity index 100% rename from test/siridb-random-data.py rename to itest/siridb-random-data.py diff --git a/test/slow_connection_test.sh b/itest/slow_connection_test.sh similarity index 100% rename from test/slow_connection_test.sh rename to itest/slow_connection_test.sh diff --git a/test/test_cluster.py b/itest/test_cluster.py similarity index 100% rename from test/test_cluster.py rename to itest/test_cluster.py diff --git a/test/test_compression.py b/itest/test_compression.py similarity index 100% rename from test/test_compression.py rename to itest/test_compression.py diff --git a/test/test_group.py b/itest/test_group.py similarity index 100% rename from test/test_group.py rename to itest/test_group.py diff --git a/test/test_insert.py b/itest/test_insert.py similarity index 100% rename from test/test_insert.py rename to itest/test_insert.py diff --git a/test/test_list.py b/itest/test_list.py similarity index 100% rename from test/test_list.py rename to itest/test_list.py diff --git a/test/test_log.py b/itest/test_log.py similarity index 100% rename from test/test_log.py rename to itest/test_log.py diff --git a/test/test_pipe.c b/itest/test_pipe.c similarity index 100% rename from test/test_pipe.c rename to itest/test_pipe.c diff --git a/test/test_pipe_support.py b/itest/test_pipe_support.py similarity index 100% rename from test/test_pipe_support.py rename to itest/test_pipe_support.py diff --git a/test/test_pool.py b/itest/test_pool.py similarity index 100% rename from test/test_pool.py rename to itest/test_pool.py diff --git a/test/test_select.py b/itest/test_select.py similarity index 100% rename from test/test_select.py rename to itest/test_select.py diff --git a/test/test_series.py b/itest/test_series.py similarity index 100% rename from test/test_series.py rename to itest/test_series.py diff --git a/test/test_server.py b/itest/test_server.py similarity index 100% rename from test/test_server.py rename to itest/test_server.py diff --git a/test/test_syslog.py b/itest/test_syslog.py similarity index 100% rename from test/test_syslog.py rename to itest/test_syslog.py diff --git a/test/test_user.py b/itest/test_user.py similarity index 100% rename from test/test_user.py rename to itest/test_user.py diff --git a/test/testing/__init__.py b/itest/testing/__init__.py similarity index 100% rename from test/testing/__init__.py rename to itest/testing/__init__.py diff --git a/test/testing/client.py b/itest/testing/client.py similarity index 100% rename from test/testing/client.py rename to itest/testing/client.py diff --git a/test/testing/constants.py b/itest/testing/constants.py similarity index 100% rename from test/testing/constants.py rename to itest/testing/constants.py diff --git a/test/testing/helpers.py b/itest/testing/helpers.py similarity index 100% rename from test/testing/helpers.py rename to itest/testing/helpers.py diff --git a/test/testing/pipe_client.py b/itest/testing/pipe_client.py similarity index 100% rename from test/testing/pipe_client.py rename to itest/testing/pipe_client.py diff --git a/test/testing/series.py b/itest/testing/series.py similarity index 100% rename from test/testing/series.py rename to itest/testing/series.py diff --git a/test/testing/server.py b/itest/testing/server.py similarity index 100% rename from test/testing/server.py rename to itest/testing/server.py diff --git a/test/testing/siridb.py b/itest/testing/siridb.py similarity index 100% rename from test/testing/siridb.py rename to itest/testing/siridb.py diff --git a/test/testing/testbase.py b/itest/testing/testbase.py similarity index 100% rename from test/testing/testbase.py rename to itest/testing/testbase.py diff --git a/main.c b/main.c index 991715ab..d6a99d7d 100644 --- a/main.c +++ b/main.c @@ -21,9 +21,6 @@ #include #include -#if DEBUG -#include -#endif int main(int argc, char * argv[]) { @@ -31,7 +28,7 @@ int main(int argc, char * argv[]) * set local to LC_ALL * more info at: http://www.cprogramming.com/tutorial/unicode.html */ - setlocale(LC_ALL, ""); + (void) setlocale(LC_ALL, ""); /* initialize random */ srand(time(NULL)); @@ -53,13 +50,6 @@ int main(int argc, char * argv[]) siridb_points_init(); #if DEBUG - int rc; - /* run tests when we are in debug mode */ - rc = run_tests(); - if (rc) - { - exit(1); - } log_warning("Starting SiriDB Server (%s-DEBUG-RELEASE-%s)", SIRIDB_VERSION, SIRIDB_BUILD_DATE); @@ -69,7 +59,10 @@ int main(int argc, char * argv[]) log_info("Starting SiriDB Server (version: %s)", SIRIDB_VERSION); #endif /* initialize SiriDB mutex (used for the siridb_list) */ - uv_mutex_init(&siri.siridb_mutex); + if (uv_mutex_init(&siri.siridb_mutex)) + { + exit(1); + } /* read siridb main application configuration */ siri_cfg_init(&siri); diff --git a/makefile.init b/makefile.init new file mode 100644 index 00000000..de39f397 --- /dev/null +++ b/makefile.init @@ -0,0 +1,2 @@ +test: + @cd ../test && ./test.sh diff --git a/test/test.h b/test/test.h new file mode 100644 index 00000000..2ee19354 --- /dev/null +++ b/test/test.h @@ -0,0 +1,45 @@ +#ifndef SIRIDB_TEST_H_ +#define SIRIDB_TEST_H_ + +#include +#include +#include +#include + +#define TEST_OK 0 +#define TEST_FAILED 1 +#define TEST_MSG_OK "....\x1B[32mOK\x1B[0m" +#define TEST_MSG_FAILED "\x1B[31mFAILED\x1B[0m" + +static struct timeval start; +static struct timeval end; + +static int status = TEST_OK; + +const char * padding = + ".............................." + ".............................."; + +static void test_start(char * test_name) +{ + int padlen = 60 - strlen(test_name); + printf("Testing %s%*.*s", test_name, padlen, padlen, padding); + gettimeofday(&start, 0); +} + +static int test_end(void) +{ + gettimeofday(&end, 0); + float t = (end.tv_sec - start.tv_sec) * 1000.0f + + (end.tv_usec - start.tv_usec) / 1000.0f; + + printf("%s (%.3f ms)\n", + (status == TEST_OK) ? TEST_MSG_OK : TEST_MSG_FAILED, + t); + + return status; +} + +#define _assert(e) (void)((e)?0:(status = TEST_FAILED) && printf("\n\x1B[33mAssertion failed (%s:%d):\x1B[0m %s\n\n", __FILE__, __LINE__, #e)) + +#endif /* SIRIDB_TEST_H_ */ \ No newline at end of file diff --git a/test/test.sh b/test/test.sh new file mode 100755 index 00000000..d38d7ec1 --- /dev/null +++ b/test/test.sh @@ -0,0 +1,26 @@ +#!/bin/bash +RET=0 + +run () { + C_SRC=$(cat $1/sources) + + SOURCE=$1/$1.c + OUT=$1.out + rm "$OUT" 2> /dev/null + + gcc -I"../include" -O0 -g3 -Wall -Wextra -Winline -std=gnu99 $SOURCE $C_SRC -o "$OUT" + if hash valgrind 2>/dev/null; then + echo -n "(memtest) " + valgrind --tool=memcheck --error-exitcode=1 --leak-check=full -q ./$OUT + else + ./$OUT + fi + rc=$?; if [[ $rc != 0 ]]; then RET=$((RET+1)); fi + rm "$OUT" 2> /dev/null +} + +for d in test_*/ ; do + run "${d%?}" +done + +exit $RET \ No newline at end of file diff --git a/test/test_ctree/sources b/test/test_ctree/sources new file mode 100755 index 00000000..049d2b92 --- /dev/null +++ b/test/test_ctree/sources @@ -0,0 +1,2 @@ +../src/ctree/ctree.c +../src/logger/logger.c \ No newline at end of file diff --git a/test/test_ctree/test_ctree.c b/test/test_ctree/test_ctree.c new file mode 100644 index 00000000..1c86bdb8 --- /dev/null +++ b/test/test_ctree/test_ctree.c @@ -0,0 +1,79 @@ +/* + * test_smap.c + * + * Created on: Sep 30, 2017 + * Author: Jeroen van der Heijden + */ + + +#include "../test.h" +#include + +const unsigned int num_entries = 14; +char * entries[] = { + "Zero", + "First entry", + "Second entry", + "Third entry", + "Fourth entry", + "Fifth entry", + "Sixth entry", + "Seventh entry", + "8", + "9", + "entry 10", + "entry 11", + "entry 12", + "entry-last" +}; + +int main() +{ + test_start("ctree"); + + ct_t * ctree = ct_new(); + + /* test adding values */ + { + _assert (ctree->len == 0); + for (unsigned int i = 0; i < num_entries; i++) + { + _assert (ct_add(ctree, entries[i], entries[i]) == 0); + } + } + + /* test is the length is correct */ + { + _assert (ctree->len == num_entries); + } + + /* test adding duplicated values */ + { + for (unsigned int i = 0; i < num_entries; i++) + { + _assert (ct_add(ctree, entries[i], entries[i]) == CT_EXISTS); + } + } + + /* test adding empty value */ + { + _assert (ct_add(ctree, "", entries[0]) == CT_EXISTS); + } + + /* test pop value */ + { + for (unsigned int i = 0; i < num_entries; i++) + { + _assert (ct_pop(ctree, entries[i]) == entries[i]); + } + } + + /* test is the length is correct */ + { + _assert (ctree->len == 0); + } + + ct_free(ctree, NULL); + + return test_end(); +} diff --git a/test/test_imap/sources b/test/test_imap/sources new file mode 100644 index 00000000..3157e571 --- /dev/null +++ b/test/test_imap/sources @@ -0,0 +1,3 @@ +../src/imap/imap.c +../src/slist/slist.c +../src/logger/logger.c \ No newline at end of file diff --git a/test/test_imap/test_imap.c b/test/test_imap/test_imap.c new file mode 100644 index 00000000..24d3f064 --- /dev/null +++ b/test/test_imap/test_imap.c @@ -0,0 +1,27 @@ +/* + * test_smap.c + * + * Created on: Sep 30, 2017 + * Author: Jeroen van der Heijden + */ + + +#include "../test.h" +#include + + +int main() +{ + test_start("imap"); + + imap_t * imap = imap_new(); + + /* test is the length is correct */ + { + _assert (imap->len == 0); + } + + imap_free(imap, NULL); + + return test_end(); +} -- 2.39.5