From 07d1265acf1efc21e7bdb10b7deff252de1f1a56 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 22 Sep 2014 14:32:18 +0300 Subject: [PATCH 1/5] test implementation --- query_classifier/test/classify.c | 59 ++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 query_classifier/test/classify.c diff --git a/query_classifier/test/classify.c b/query_classifier/test/classify.c new file mode 100644 index 000000000..aaf9900e7 --- /dev/null +++ b/query_classifier/test/classify.c @@ -0,0 +1,59 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +static char* server_options[] = { + "SkySQL Gateway", + "--datadir=./", + "--language=./", + "--skip-innodb", + "--default-storage-engine=myisam", + NULL +}; + +const int num_elements = (sizeof(server_options) / sizeof(char *)) - 1; + +static char* server_groups[] = { + "embedded", + "server", + "server", + NULL +}; + +int main(int argc, char** argv) +{ + GWBUF* gwbuff; + int rd = 0,buffsz = getpagesize(),strsz = buffsz; + char buffer[buffsz], *strbuff = (char*)calloc(buffsz,sizeof(char)); + + while((rd = fread(buffer,sizeof(char),buffsize,stdin))){ + + if(strsz + rd >= buffsz){ + char* tmp = (char*)calloc((buffsz*2),sizeof(char)); + + if(!tmp){ + fprintf(stderr,"Error: Cannot allocate enough memory."); + return 1; + } + memcpy(tmp,strbuff,buffsz); + free(strbuff); + strbuff = tmp; + buffsz *= 2; + } + + memcpy(strbuff+strsz,buffer,rd); + querysz += rd; + } + + if(querysz > 0){ + printf("%s",strbuff); + free(strbuff); + } + + return 0; +} From 1cf3fa367cec39ee77874b1b019f89199ba8a946 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Wed, 24 Sep 2014 12:25:53 +0300 Subject: [PATCH 2/5] test executable now works --- query_classifier/test/classify.c | 122 +++++++++++++++++++++++++++---- 1 file changed, 107 insertions(+), 15 deletions(-) diff --git a/query_classifier/test/classify.c b/query_classifier/test/classify.c index aaf9900e7..5fb995918 100644 --- a/query_classifier/test/classify.c +++ b/query_classifier/test/classify.c @@ -8,11 +8,12 @@ #include static char* server_options[] = { - "SkySQL Gateway", - "--datadir=./", - "--language=./", - "--skip-innodb", - "--default-storage-engine=myisam", + "SkySQL Gateway", + "--no-defaults", + "--datadir=.", + "--language=.", + "--skip-innodb", + "--default-storage-engine=myisam", NULL }; @@ -27,12 +28,14 @@ static char* server_groups[] = { int main(int argc, char** argv) { - GWBUF* gwbuff; - int rd = 0,buffsz = getpagesize(),strsz = buffsz; + int rd = 0,buffsz = getpagesize(),strsz = 0; char buffer[buffsz], *strbuff = (char*)calloc(buffsz,sizeof(char)); - - while((rd = fread(buffer,sizeof(char),buffsize,stdin))){ + + mysql_library_init(num_elements, server_options, server_groups); + + while((rd = fread(buffer,sizeof(char),buffsz,stdin))){ + /**Fill the read buffer*/ if(strsz + rd >= buffsz){ char* tmp = (char*)calloc((buffsz*2),sizeof(char)); @@ -47,13 +50,102 @@ int main(int argc, char** argv) } memcpy(strbuff+strsz,buffer,rd); - querysz += rd; - } + strsz += rd; - if(querysz > 0){ - printf("%s",strbuff); - free(strbuff); - } + char *tok,*nlptr; + /**Remove newlines*/ + while((nlptr = strpbrk(strbuff,"\n")) != NULL && (nlptr - strbuff) < strsz){ + memmove(nlptr,nlptr+1,strsz - (nlptr + 1 - strbuff)); + strsz -= 1; + } + + + /**Parse read buffer for full queries*/ + + while(strpbrk(strbuff,";") != NULL){ + tok = strpbrk(strbuff,";"); + int qlen = tok - strbuff; + GWBUF* buff = gwbuf_alloc(qlen+5); + *((unsigned char*)(buff->start)) = qlen; + *((unsigned char*)(buff->start + 1)) = (qlen >> 8); + *((unsigned char*)(buff->start + 2)) = (qlen >> 16); + *((unsigned char*)(buff->start + 3)) = 0x00; + *((unsigned char*)(buff->start + 4)) = 0x03; + memcpy(buff->start+5, strbuff, qlen); + memmove(strbuff,tok + 1, strsz - qlen); + strsz -= qlen; + memset(strbuff + strsz,0,buffsz - strsz); + skygw_query_type_t type = query_classifier_get_type(buff); + + + + if(type == QUERY_TYPE_UNKNOWN){ + printf("QUERY_TYPE_UNKNOWN "); + } + if(type & QUERY_TYPE_LOCAL_READ){ + printf("QUERY_TYPE_LOCAL_READ "); + } + if(type & QUERY_TYPE_READ){ + printf("QUERY_TYPE_READ "); + } + if(type & QUERY_TYPE_WRITE){ + printf("QUERY_TYPE_WRITE "); + } + if(type & QUERY_TYPE_MASTER_READ){ + printf("QUERY_TYPE_MASTER_READ "); + } + if(type & QUERY_TYPE_SESSION_WRITE){ + printf("QUERY_TYPE_SESSION_WRITE "); + } + if(type & QUERY_TYPE_USERVAR_READ){ + printf("QUERY_TYPE_USERVAR_READ "); + } + if(type & QUERY_TYPE_SYSVAR_READ){ + printf("QUERY_TYPE_SYSVAR_READ "); + } + if(type & QUERY_TYPE_GSYSVAR_READ){ + printf("QUERY_TYPE_GSYSVAR_READ "); + } + if(type & QUERY_TYPE_GSYSVAR_WRITE){ + printf("QUERY_TYPE_GSYSVAR_WRITE "); + } + if(type & QUERY_TYPE_BEGIN_TRX){ + printf("QUERY_TYPE_BEGIN_TRX "); + } + if(type & QUERY_TYPE_ENABLE_AUTOCOMMIT){ + printf("QUERY_TYPE_ENABLE_AUTOCOMMIT "); + } + if(type & QUERY_TYPE_DISABLE_AUTOCOMMIT){ + printf("QUERY_TYPE_DISABLE_AUTOCOMMIT "); + } + if(type & QUERY_TYPE_ROLLBACK){ + printf("QUERY_TYPE_ROLLBACK "); + } + if(type & QUERY_TYPE_COMMIT){ + printf("QUERY_TYPE_COMMIT "); + } + if(type & QUERY_TYPE_PREPARE_NAMED_STMT){ + printf("QUERY_TYPE_PREPARE_NAMED_STMT "); + } + if(type & QUERY_TYPE_PREPARE_STMT){ + printf("QUERY_TYPE_PREPARE_STMT "); + } + if(type & QUERY_TYPE_EXEC_STMT){ + printf("QUERY_TYPE_EXEC_STMT "); + } + if(type & QUERY_TYPE_CREATE_TMP_TABLE){ + printf("QUERY_TYPE_CREATE_TMP_TABLE "); + } + if(type & QUERY_TYPE_READ_TMP_TABLE){ + printf("QUERY_TYPE_READ_TMP_TABLE "); + } + + printf("\n"); + gwbuf_free(buff); + } + + } + free(strbuff); return 0; } From 25850c056f6fd7fe933daf8db7ca5501980a89c5 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 25 Sep 2014 10:14:42 +0300 Subject: [PATCH 3/5] Added tests to cmake --- README | 5 + etc/ubuntu/init.d/maxscale | 0 macros.cmake | 32 +-- query_classifier/test/CMakeLists.txt | 19 +- .../test/canonical_tests/Makefile | 198 +++++++++++++----- query_classifier/test/classify.c | 8 +- query_classifier/test/expected.sql | 19 ++ query_classifier/test/input.sql | 19 ++ 8 files changed, 233 insertions(+), 67 deletions(-) mode change 100755 => 100644 etc/ubuntu/init.d/maxscale create mode 100644 query_classifier/test/expected.sql create mode 100644 query_classifier/test/input.sql diff --git a/README b/README index 3affd5b85..e44ccfd09 100644 --- a/README +++ b/README @@ -195,6 +195,11 @@ If you have your headers and libraries in non-standard locations, you can define By default, MaxScale installs to '/usr/local/skysql/maxscale' and places init.d scripts and ldconfig files into their folders. Change the INSTALL_DIR variable to your desired installation directory and set INSTALL_SYSTEM_FILES=N to prevent the init.d script and ldconfig file installation. +If you run into any trouble while configuring CMake, you can always remove the 'CMakeCache.txt' file to clear CMake's +internal cache. This resets all values to their defaults and can be used to fix a 'stuck' configuration of CMake. This +is also a good reason why you should always build into a separate directory, because you can safely wipe the build directory clean without the +danger of deleting important files. + All the parameters affecting CMake can be found in 'macros.cmake'. This file also has the parameters CMake uses for testing. All the variables that control the CMake build process: diff --git a/etc/ubuntu/init.d/maxscale b/etc/ubuntu/init.d/maxscale old mode 100755 new mode 100644 diff --git a/macros.cmake b/macros.cmake index 7c5109925..d5e87ae48 100644 --- a/macros.cmake +++ b/macros.cmake @@ -69,28 +69,30 @@ macro(check_deps) endforeach() if(DEPS_ERROR) - message(FATAL_ERROR "Cannot find dependencies: ${FAILED_DEPS}") set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.") + message(FATAL_ERROR "Cannot find dependencies: ${FAILED_DEPS}") endif() endmacro() macro(check_dirs) + # Find the MySQL headers if they were not defined if(DEFINED MYSQL_DIR) message(STATUS "Searching for MySQL headers at: ${MYSQL_DIR}") find_path(MYSQL_DIR_LOC mysql.h PATHS ${MYSQL_DIR} PATH_SUFFIXES mysql mariadb NO_DEFAULT_PATH) - else() - find_path(MYSQL_DIR_LOC mysql.h PATH_SUFFIXES mysql mariadb) endif() + find_path(MYSQL_DIR_LOC mysql.h PATH_SUFFIXES mysql mariadb) message(STATUS "Search returned: ${MYSQL_DIR_LOC}") - set(MYSQL_DIR ${MYSQL_DIR_LOC} CACHE PATH "Path to MySQL headers" FORCE) - if(${MYSQL_DIR} STREQUAL "MYSQL_DIR-NOTFOUND") - message(FATAL_ERROR "Fatal Error: MySQL headers were not found.") + + if(${MYSQL_DIR_LOC} STREQUAL "MYSQL_DIR_LOC-NOTFOUND") set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.") + message(FATAL_ERROR "Fatal Error: MySQL headers were not found.") else() message(STATUS "Using MySQL headers found at: ${MYSQL_DIR}") + set(MYSQL_DIR ${MYSQL_DIR_LOC} CACHE PATH "Path to MySQL headers" FORCE) endif() + set(MYSQL_DIR_LOC "" INTERNAL) # Find the errmsg.sys file if it was not defied if( DEFINED ERRMSG ) @@ -98,12 +100,13 @@ macro(check_dirs) endif() find_file(ERRMSG_FILE errmsg.sys PATHS /usr/share/mysql /usr/local/share/mysql PATH_SUFFIXES english) if(${ERRMSG_FILE} MATCHES "ERRMSG_FILE-NOTFOUND") - message(FATAL_ERROR "Fatal Error: The errmsg.sys file was not found, please define the path to it by using -DERRMSG=") set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.") + message(FATAL_ERROR "Fatal Error: The errmsg.sys file was not found, please define the path to it by using -DERRMSG=") else() message(STATUS "Using errmsg.sys found at: ${ERRMSG_FILE}") endif() set(ERRMSG ${ERRMSG_FILE} CACHE FILEPATH "Path to the errmsg.sys file." FORCE) + set(ERRMSG_FILE "" INTERNAL) # Find the embedded mysql library if(STATIC_EMBEDDED) @@ -119,12 +122,12 @@ macro(check_dirs) message(STATUS "Search returned: ${EMBEDDED_LIB_STATIC}") set(EMBEDDED_LIB ${EMBEDDED_LIB_STATIC} CACHE FILEPATH "Path to libmysqld" FORCE) set(CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_SUFFIXES}) + set(OLD_SUFFIXES "" INTERNAL) else() if (DEFINED EMBEDDED_LIB) message(STATUS "Searching for libmysqld.so at: ${EMBEDDED_LIB}") find_library(EMBEDDED_LIB_DYNAMIC mysqld PATHS ${EMBEDDED_LIB} PATH_SUFFIXES mysql mariadb NO_DEFAULT_PATH) - else() find_library(EMBEDDED_LIB_DYNAMIC mysqld PATH_SUFFIXES mysql mariadb) endif() @@ -132,12 +135,13 @@ macro(check_dirs) set(EMBEDDED_LIB ${EMBEDDED_LIB_DYNAMIC} CACHE FILEPATH "Path to libmysqld" FORCE) endif() - + set(EMBEDDED_LIB_DYNAMIC "" INTERNAL) + set(EMBEDDED_LIB_STATIC "" INTERNAL) # Inform the user about the embedded library if( (${EMBEDDED_LIB} STREQUAL "EMBEDDED_LIB_STATIC-NOTFOUND") OR (${EMBEDDED_LIB} STREQUAL "EMBEDDED_LIB_DYNAMIC-NOTFOUND")) - message(FATAL_ERROR "Library not found: libmysqld. If your install of MySQL is in a non-default location, please provide the location with -DEMBEDDED_LIB=") set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.") + message(FATAL_ERROR "Library not found: libmysqld. If your install of MySQL is in a non-default location, please provide the location with -DEMBEDDED_LIB=") else() get_filename_component(EMBEDDED_LIB ${EMBEDDED_LIB} REALPATH) message(STATUS "Using embedded library: ${EMBEDDED_LIB}") @@ -149,14 +153,16 @@ macro(check_dirs) if(${RPM_FNC} MATCHES "RPM_FNC-NOTFOUND") find_file(DEB_FNC init-functions PATHS /lib/lsb) if(${DEB_FNC} MATCHES "DEB_FNC-NOTFOUND") - message(FATAL_ERROR "Cannot find required init-functions in /lib/lsb/ or /etc/rc.d/init.d/, please confirm that your system files are OK.") set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.") + message(FATAL_ERROR "Cannot find required init-functions in /lib/lsb/ or /etc/rc.d/init.d/, please confirm that your system files are OK.") else() set(DEB_BASED TRUE CACHE BOOL "If init.d script uses /lib/lsb/init-functions instead of /etc/rc.d/init.d/functions.") endif() else() set(DEB_BASED FALSE CACHE BOOL "If init.d script uses /lib/lsb/init-functions instead of /etc/rc.d/init.d/functions.") endif() + set(DEB_FNC "" INTERNAL) + set(RPM_FNC "" INTERNAL) #Check RabbitMQ headers and libraries if(BUILD_RABBITMQ) @@ -166,8 +172,8 @@ macro(check_dirs) endif() find_library(RMQ_LIB rabbitmq) if(RMQ_LIB STREQUAL "RMQ_LIB-NOTFOUND") - message(FATAL_ERROR "Cannot find RabbitMQ libraries, please define the path to the libraries with -DRABBITMQ_LIB=") set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.") + message(FATAL_ERROR "Cannot find RabbitMQ libraries, please define the path to the libraries with -DRABBITMQ_LIB=") else() set(RABBITMQ_LIB ${RMQ_LIB} CACHE PATH "Path to RabbitMQ libraries" FORCE) message(STATUS "Using RabbitMQ libraries found at: ${RABBITMQ_LIB}") @@ -178,8 +184,8 @@ macro(check_dirs) endif() find_file(RMQ_HEADERS amqp.h) if(RMQ_HEADERS STREQUAL "RMQ_HEADERS-NOTFOUND") - message(FATAL_ERROR "Cannot find RabbitMQ headers, please define the path to the headers with -DRABBITMQ_HEADERS=") set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.") + message(FATAL_ERROR "Cannot find RabbitMQ headers, please define the path to the headers with -DRABBITMQ_HEADERS=") else() set(RABBITMQ_HEADERS ${RMQ_HEADERS} CACHE PATH "Path to RabbitMQ headers" FORCE) message(STATUS "Using RabbitMQ headers found at: ${RABBITMQ_HEADERS}") diff --git a/query_classifier/test/CMakeLists.txt b/query_classifier/test/CMakeLists.txt index 9f6a1f120..5836a5a00 100644 --- a/query_classifier/test/CMakeLists.txt +++ b/query_classifier/test/CMakeLists.txt @@ -1,3 +1,20 @@ +if(${ERRMSG} MATCHES "NOTFOUND") + message(FATAL_ERROR "The errmsg.sys file was not found, please define the path with -DERRMSG=") +else() + file(COPY ${ERRMSG} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +endif() + add_subdirectory(canonical_tests) add_executable(classify classify.c) -target_link_libraries(classify fullcore) \ No newline at end of file +target_link_libraries(classify query_classifier fullcore) +add_test(NAME TestQueryClassifier + COMMAND /bin/sh -c "${CMAKE_CURRENT_BINARY_DIR}/classify < ${CMAKE_CURRENT_SOURCE_DIR}/input.sql > ${CMAKE_CURRENT_BINARY_DIR}/output.sql && + diff ${CMAKE_CURRENT_BINARY_DIR}/output.sql ${CMAKE_CURRENT_SOURCE_DIR}/expected.sql; +if [[ $? -eq 1 ]]; + then + echo \"TEST FAILED\"; + exit 1; + else + echo\"TEST PASSED\"; + exit 0; +fi") \ No newline at end of file diff --git a/query_classifier/test/canonical_tests/Makefile b/query_classifier/test/canonical_tests/Makefile index c5fe44fe9..8468f9f7a 100644 --- a/query_classifier/test/canonical_tests/Makefile +++ b/query_classifier/test/canonical_tests/Makefile @@ -1,62 +1,158 @@ -# cleantests - clean local and subdirectories' tests -# buildtests - build all local and subdirectories' tests -# runtests - run all local tests -# testall - clean, build and run local and subdirectories' tests +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 2.8 -include ../../../build_gateway.inc -include ../../../makefile.inc -include ../../../test.inc +# Default target executed when no arguments are given to make. +default_target: all +.PHONY : default_target -CC = gcc -CPP = g++ +#============================================================================= +# Special targets provided by cmake. -TESTPATH := $(shell pwd) -TESTLOG := $(TESTPATH)/testqclass.log -QUERY_CLASSIFIER_PATH := $(ROOT_PATH)/query_classifier -LOG_MANAGER_PATH := $(ROOT_PATH)/log_manager -UTILS_PATH := $(ROOT_PATH)/utils -CORE_PATH := $(ROOT_PATH)/server/core -TESTAPP = $(TESTPATH)/canonizer +# Disable implicit rules so canonical targets will work. +.SUFFIXES: -LDFLAGS=-L$(QUERY_CLASSIFIER_PATH) \ - -L$(LOG_MANAGER_PATH) \ - -L$(EMBEDDED_LIB) \ - -Wl,-rpath,$(DEST)/lib \ - -Wl,-rpath,$(EMBEDDED_LIB) \ - -Wl,-rpath,$(LOG_MANAGER_PATH) \ - -Wl,-rpath,$(QUERY_CLASSIFIER_PATH) +# Remove some rules from gmake that .SUFFIXES does not remove. +SUFFIXES = -LIBS=-lstdc++ -lpthread -lquery_classifier -lz -ldl -lssl -laio -lcrypt -lcrypto -lrt -lm \ - -llog_manager $(UTILS_PATH)/skygw_utils.o $(CORE_PATH)/buffer.o $(CORE_PATH)/atomic.o $(CORE_PATH)/spinlock.o $(CORE_PATH)/hint.o +.SUFFIXES: .hpux_make_needs_suffix_list -CFLAGS=-g $(MYSQL_HEADERS) \ - -I$(QUERY_CLASSIFIER_PATH) \ - $(MYSQL_HEADERS) \ - -I$(ROOT_PATH)/server/include \ - -I$(UTILS_PATH) +# Suppress display of executed commands. +$(VERBOSE).SILENT: + +# A target that is always out of date. +cmake_force: +.PHONY : cmake_force + +#============================================================================= +# Set environment variables for the build. + +# The shell in which to execute make rules. +SHELL = /bin/sh + +# The CMake executable. +CMAKE_COMMAND = /usr/bin/cmake + +# The command to remove a file. +RM = /usr/bin/cmake -E remove -f + +# Escaping for special characters. +EQUALS = = + +# The program to use to edit the cache. +CMAKE_EDIT_COMMAND = /usr/bin/ccmake + +# The top-level source directory on which CMake was run. +CMAKE_SOURCE_DIR = /home/markus/max_origin/MaxScale/query_classifier/test + +# The top-level build directory on which CMake was run. +CMAKE_BINARY_DIR = /home/markus/max_origin/MaxScale/query_classifier/test + +#============================================================================= +# Targets provided globally by CMake. + +# Special rule for the target edit_cache +edit_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..." + /usr/bin/ccmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) +.PHONY : edit_cache + +# Special rule for the target edit_cache +edit_cache/fast: edit_cache +.PHONY : edit_cache/fast + +# Special rule for the target rebuild_cache +rebuild_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." + /usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) +.PHONY : rebuild_cache + +# Special rule for the target rebuild_cache +rebuild_cache/fast: rebuild_cache +.PHONY : rebuild_cache/fast + +# The main all target +all: cmake_check_build_system + cd /home/markus/max_origin/MaxScale/query_classifier/test && $(CMAKE_COMMAND) -E cmake_progress_start /home/markus/max_origin/MaxScale/query_classifier/test/CMakeFiles /home/markus/max_origin/MaxScale/query_classifier/test/canonical_tests/CMakeFiles/progress.marks + cd /home/markus/max_origin/MaxScale/query_classifier/test && $(MAKE) -f CMakeFiles/Makefile2 canonical_tests/all + $(CMAKE_COMMAND) -E cmake_progress_start /home/markus/max_origin/MaxScale/query_classifier/test/CMakeFiles 0 +.PHONY : all + +# The main clean target +clean: + cd /home/markus/max_origin/MaxScale/query_classifier/test && $(MAKE) -f CMakeFiles/Makefile2 canonical_tests/clean +.PHONY : clean + +# The main clean target +clean/fast: clean +.PHONY : clean/fast + +# Prepare targets for installation. +preinstall: all + cd /home/markus/max_origin/MaxScale/query_classifier/test && $(MAKE) -f CMakeFiles/Makefile2 canonical_tests/preinstall +.PHONY : preinstall + +# Prepare targets for installation. +preinstall/fast: + cd /home/markus/max_origin/MaxScale/query_classifier/test && $(MAKE) -f CMakeFiles/Makefile2 canonical_tests/preinstall +.PHONY : preinstall/fast + +# clear depends +depend: + cd /home/markus/max_origin/MaxScale/query_classifier/test && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 +.PHONY : depend + +# Convenience name for target. +canonical_tests/CMakeFiles/canonizer.dir/rule: + cd /home/markus/max_origin/MaxScale/query_classifier/test && $(MAKE) -f CMakeFiles/Makefile2 canonical_tests/CMakeFiles/canonizer.dir/rule +.PHONY : canonical_tests/CMakeFiles/canonizer.dir/rule + +# Convenience name for target. +canonizer: canonical_tests/CMakeFiles/canonizer.dir/rule +.PHONY : canonizer + +# fast build rule for target. +canonizer/fast: + cd /home/markus/max_origin/MaxScale/query_classifier/test && $(MAKE) -f canonical_tests/CMakeFiles/canonizer.dir/build.make canonical_tests/CMakeFiles/canonizer.dir/build +.PHONY : canonizer/fast + +# target to build an object file +canonizer.o: + cd /home/markus/max_origin/MaxScale/query_classifier/test && $(MAKE) -f canonical_tests/CMakeFiles/canonizer.dir/build.make canonical_tests/CMakeFiles/canonizer.dir/canonizer.o +.PHONY : canonizer.o + +# target to preprocess a source file +canonizer.i: + cd /home/markus/max_origin/MaxScale/query_classifier/test && $(MAKE) -f canonical_tests/CMakeFiles/canonizer.dir/build.make canonical_tests/CMakeFiles/canonizer.dir/canonizer.i +.PHONY : canonizer.i + +# target to generate assembly for a file +canonizer.s: + cd /home/markus/max_origin/MaxScale/query_classifier/test && $(MAKE) -f canonical_tests/CMakeFiles/canonizer.dir/build.make canonical_tests/CMakeFiles/canonizer.dir/canonizer.s +.PHONY : canonizer.s + +# Help Target +help: + @echo "The following are some of the valid targets for this Makefile:" + @echo "... all (the default if no target is provided)" + @echo "... clean" + @echo "... depend" + @echo "... canonizer" + @echo "... edit_cache" + @echo "... rebuild_cache" + @echo "... canonizer.o" + @echo "... canonizer.i" + @echo "... canonizer.s" +.PHONY : help -testall: - $(MAKE) cleantests - $(MAKE) buildtests - $(MAKE) runtests -cleantests: - - $(DEL) *.o - - $(DEL) *~ - - $(DEL) canonizer - - $(DEL) aria_log* - - $(DEL) ib* +#============================================================================= +# Special targets to cleanup operation of make. -buildtests: $(OBJS) - cp $(ERRMSG)/errmsg.sys . - $(CC) $(CFLAGS) $(LDFLAGS) $(LIBS) canonizer.c -o $(TESTAPP) $(LDLIBS) $(LDMYSQL) +# Special rule to run CMake to check the build system integrity. +# No rule that depends on this can have commands that come from listfiles +# because they might be regenerated. +cmake_check_build_system: + cd /home/markus/max_origin/MaxScale/query_classifier/test && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 +.PHONY : cmake_check_build_system -runtests: - @echo "" > $(TESTLOG) - @echo "-------------------------------" >> $(TESTLOG) - @echo $(shell date) >> $(TESTLOG) - @echo "Canonical Query Tests" >> $(TESTLOG) - @echo "-------------------------------" >> $(TESTLOG) - @echo "" >> $(TESTLOG) - ./canontest.sh $(TESTLOG) input.sql output.sql expected.sql diff --git a/query_classifier/test/classify.c b/query_classifier/test/classify.c index 5fb995918..3c5b73a97 100644 --- a/query_classifier/test/classify.c +++ b/query_classifier/test/classify.c @@ -31,8 +31,12 @@ int main(int argc, char** argv) int rd = 0,buffsz = getpagesize(),strsz = 0; char buffer[buffsz], *strbuff = (char*)calloc(buffsz,sizeof(char)); - mysql_library_init(num_elements, server_options, server_groups); - + if(mysql_library_init(num_elements, server_options, server_groups)) + { + printf("Error: Cannot initialize Embedded Library."); + return 1; + } + while((rd = fread(buffer,sizeof(char),buffsz,stdin))){ /**Fill the read buffer*/ diff --git a/query_classifier/test/expected.sql b/query_classifier/test/expected.sql new file mode 100644 index 000000000..07ba0751d --- /dev/null +++ b/query_classifier/test/expected.sql @@ -0,0 +1,19 @@ +QUERY_TYPE_UNKNOWN +QUERY_TYPE_UNKNOWN +QUERY_TYPE_READ +QUERY_TYPE_UNKNOWN +QUERY_TYPE_READ +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_UNKNOWN diff --git a/query_classifier/test/input.sql b/query_classifier/test/input.sql new file mode 100644 index 000000000..657797cc0 --- /dev/null +++ b/query_classifier/test/input.sql @@ -0,0 +1,19 @@ +select sleep(2); +select * from tst where lname='Doe'; +select 1,2,3,4,5,6 from tst; +select * from tst where fname like '%a%'; +select * from tst where lname like '%e%' order by fname; +insert into tst values ("John"," Doe"),("Donald","Duck"),("Plato",""),("Richard","Stallman"); +insert into tst values ("Jane"," Doe"),("Daisy","Duck"),("Marie","Curie"); +insert into tst values ("John","Doe"),("Donald","Duck"),("Plato",""),("Richard","Stallman"); +insert into tst values ("Jane","Doe"),("Daisy","Duck"),("Marie","Curie"); +insert into tst values ("John","Doe"),("Donald","Duck"),("Plato",""),("Richard","Stallman"); +insert into tst values ("Jane","Doe"),("Daisy","Duck"),("Marie","Curie"); +update tst set fname="Farmer", lname="McDonald" where lname="%Doe" and fname="John"; +update tst set fname="John" where lname="Doe"; +update tst set lname="Philosopher" where fname="Plato"; +update tst set fname="Human" where fname like 'Richard%'; +update tst set lname="Creature" where lname like '%man%'; +update tst set fname="Jane" where lname="%Doe"; +update tst set lname="Human" where fname like '%a%' or lname like '%a%'; + From b22ab90d66875e5766f5f8c623f06cb8b3bfc899 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Fri, 3 Oct 2014 12:18:02 +0300 Subject: [PATCH 4/5] Changed the way query classifier test is run. Now the test is a single executable, which should make it easier to use with CMake. --- etc/ubuntu/init.d/maxscale | 0 query_classifier/test/CMakeLists.txt | 12 +- .../test/canonical_tests/Makefile | 198 +++++------------- query_classifier/test/classify.c | 74 ++++--- query_classifier/test/expected.sql | 38 ++-- 5 files changed, 118 insertions(+), 204 deletions(-) mode change 100644 => 100755 etc/ubuntu/init.d/maxscale diff --git a/etc/ubuntu/init.d/maxscale b/etc/ubuntu/init.d/maxscale old mode 100644 new mode 100755 diff --git a/query_classifier/test/CMakeLists.txt b/query_classifier/test/CMakeLists.txt index 5836a5a00..e8e4736f7 100644 --- a/query_classifier/test/CMakeLists.txt +++ b/query_classifier/test/CMakeLists.txt @@ -7,14 +7,4 @@ endif() add_subdirectory(canonical_tests) add_executable(classify classify.c) target_link_libraries(classify query_classifier fullcore) -add_test(NAME TestQueryClassifier - COMMAND /bin/sh -c "${CMAKE_CURRENT_BINARY_DIR}/classify < ${CMAKE_CURRENT_SOURCE_DIR}/input.sql > ${CMAKE_CURRENT_BINARY_DIR}/output.sql && - diff ${CMAKE_CURRENT_BINARY_DIR}/output.sql ${CMAKE_CURRENT_SOURCE_DIR}/expected.sql; -if [[ $? -eq 1 ]]; - then - echo \"TEST FAILED\"; - exit 1; - else - echo\"TEST PASSED\"; - exit 0; -fi") \ No newline at end of file +add_test(TestQueryClassifier classify ${CMAKE_CURRENT_SOURCE_DIR}/input.sql ${CMAKE_CURRENT_SOURCE_DIR}/expected.sql) \ No newline at end of file diff --git a/query_classifier/test/canonical_tests/Makefile b/query_classifier/test/canonical_tests/Makefile index 8468f9f7a..c5fe44fe9 100644 --- a/query_classifier/test/canonical_tests/Makefile +++ b/query_classifier/test/canonical_tests/Makefile @@ -1,158 +1,62 @@ -# CMAKE generated file: DO NOT EDIT! -# Generated by "Unix Makefiles" Generator, CMake Version 2.8 +# cleantests - clean local and subdirectories' tests +# buildtests - build all local and subdirectories' tests +# runtests - run all local tests +# testall - clean, build and run local and subdirectories' tests -# Default target executed when no arguments are given to make. -default_target: all -.PHONY : default_target +include ../../../build_gateway.inc +include ../../../makefile.inc +include ../../../test.inc -#============================================================================= -# Special targets provided by cmake. +CC = gcc +CPP = g++ -# Disable implicit rules so canonical targets will work. -.SUFFIXES: +TESTPATH := $(shell pwd) +TESTLOG := $(TESTPATH)/testqclass.log +QUERY_CLASSIFIER_PATH := $(ROOT_PATH)/query_classifier +LOG_MANAGER_PATH := $(ROOT_PATH)/log_manager +UTILS_PATH := $(ROOT_PATH)/utils +CORE_PATH := $(ROOT_PATH)/server/core +TESTAPP = $(TESTPATH)/canonizer -# Remove some rules from gmake that .SUFFIXES does not remove. -SUFFIXES = +LDFLAGS=-L$(QUERY_CLASSIFIER_PATH) \ + -L$(LOG_MANAGER_PATH) \ + -L$(EMBEDDED_LIB) \ + -Wl,-rpath,$(DEST)/lib \ + -Wl,-rpath,$(EMBEDDED_LIB) \ + -Wl,-rpath,$(LOG_MANAGER_PATH) \ + -Wl,-rpath,$(QUERY_CLASSIFIER_PATH) -.SUFFIXES: .hpux_make_needs_suffix_list +LIBS=-lstdc++ -lpthread -lquery_classifier -lz -ldl -lssl -laio -lcrypt -lcrypto -lrt -lm \ + -llog_manager $(UTILS_PATH)/skygw_utils.o $(CORE_PATH)/buffer.o $(CORE_PATH)/atomic.o $(CORE_PATH)/spinlock.o $(CORE_PATH)/hint.o -# Suppress display of executed commands. -$(VERBOSE).SILENT: - -# A target that is always out of date. -cmake_force: -.PHONY : cmake_force - -#============================================================================= -# Set environment variables for the build. - -# The shell in which to execute make rules. -SHELL = /bin/sh - -# The CMake executable. -CMAKE_COMMAND = /usr/bin/cmake - -# The command to remove a file. -RM = /usr/bin/cmake -E remove -f - -# Escaping for special characters. -EQUALS = = - -# The program to use to edit the cache. -CMAKE_EDIT_COMMAND = /usr/bin/ccmake - -# The top-level source directory on which CMake was run. -CMAKE_SOURCE_DIR = /home/markus/max_origin/MaxScale/query_classifier/test - -# The top-level build directory on which CMake was run. -CMAKE_BINARY_DIR = /home/markus/max_origin/MaxScale/query_classifier/test - -#============================================================================= -# Targets provided globally by CMake. - -# Special rule for the target edit_cache -edit_cache: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..." - /usr/bin/ccmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) -.PHONY : edit_cache - -# Special rule for the target edit_cache -edit_cache/fast: edit_cache -.PHONY : edit_cache/fast - -# Special rule for the target rebuild_cache -rebuild_cache: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." - /usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) -.PHONY : rebuild_cache - -# Special rule for the target rebuild_cache -rebuild_cache/fast: rebuild_cache -.PHONY : rebuild_cache/fast - -# The main all target -all: cmake_check_build_system - cd /home/markus/max_origin/MaxScale/query_classifier/test && $(CMAKE_COMMAND) -E cmake_progress_start /home/markus/max_origin/MaxScale/query_classifier/test/CMakeFiles /home/markus/max_origin/MaxScale/query_classifier/test/canonical_tests/CMakeFiles/progress.marks - cd /home/markus/max_origin/MaxScale/query_classifier/test && $(MAKE) -f CMakeFiles/Makefile2 canonical_tests/all - $(CMAKE_COMMAND) -E cmake_progress_start /home/markus/max_origin/MaxScale/query_classifier/test/CMakeFiles 0 -.PHONY : all - -# The main clean target -clean: - cd /home/markus/max_origin/MaxScale/query_classifier/test && $(MAKE) -f CMakeFiles/Makefile2 canonical_tests/clean -.PHONY : clean - -# The main clean target -clean/fast: clean -.PHONY : clean/fast - -# Prepare targets for installation. -preinstall: all - cd /home/markus/max_origin/MaxScale/query_classifier/test && $(MAKE) -f CMakeFiles/Makefile2 canonical_tests/preinstall -.PHONY : preinstall - -# Prepare targets for installation. -preinstall/fast: - cd /home/markus/max_origin/MaxScale/query_classifier/test && $(MAKE) -f CMakeFiles/Makefile2 canonical_tests/preinstall -.PHONY : preinstall/fast - -# clear depends -depend: - cd /home/markus/max_origin/MaxScale/query_classifier/test && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 -.PHONY : depend - -# Convenience name for target. -canonical_tests/CMakeFiles/canonizer.dir/rule: - cd /home/markus/max_origin/MaxScale/query_classifier/test && $(MAKE) -f CMakeFiles/Makefile2 canonical_tests/CMakeFiles/canonizer.dir/rule -.PHONY : canonical_tests/CMakeFiles/canonizer.dir/rule - -# Convenience name for target. -canonizer: canonical_tests/CMakeFiles/canonizer.dir/rule -.PHONY : canonizer - -# fast build rule for target. -canonizer/fast: - cd /home/markus/max_origin/MaxScale/query_classifier/test && $(MAKE) -f canonical_tests/CMakeFiles/canonizer.dir/build.make canonical_tests/CMakeFiles/canonizer.dir/build -.PHONY : canonizer/fast - -# target to build an object file -canonizer.o: - cd /home/markus/max_origin/MaxScale/query_classifier/test && $(MAKE) -f canonical_tests/CMakeFiles/canonizer.dir/build.make canonical_tests/CMakeFiles/canonizer.dir/canonizer.o -.PHONY : canonizer.o - -# target to preprocess a source file -canonizer.i: - cd /home/markus/max_origin/MaxScale/query_classifier/test && $(MAKE) -f canonical_tests/CMakeFiles/canonizer.dir/build.make canonical_tests/CMakeFiles/canonizer.dir/canonizer.i -.PHONY : canonizer.i - -# target to generate assembly for a file -canonizer.s: - cd /home/markus/max_origin/MaxScale/query_classifier/test && $(MAKE) -f canonical_tests/CMakeFiles/canonizer.dir/build.make canonical_tests/CMakeFiles/canonizer.dir/canonizer.s -.PHONY : canonizer.s - -# Help Target -help: - @echo "The following are some of the valid targets for this Makefile:" - @echo "... all (the default if no target is provided)" - @echo "... clean" - @echo "... depend" - @echo "... canonizer" - @echo "... edit_cache" - @echo "... rebuild_cache" - @echo "... canonizer.o" - @echo "... canonizer.i" - @echo "... canonizer.s" -.PHONY : help +CFLAGS=-g $(MYSQL_HEADERS) \ + -I$(QUERY_CLASSIFIER_PATH) \ + $(MYSQL_HEADERS) \ + -I$(ROOT_PATH)/server/include \ + -I$(UTILS_PATH) +testall: + $(MAKE) cleantests + $(MAKE) buildtests + $(MAKE) runtests -#============================================================================= -# Special targets to cleanup operation of make. +cleantests: + - $(DEL) *.o + - $(DEL) *~ + - $(DEL) canonizer + - $(DEL) aria_log* + - $(DEL) ib* -# Special rule to run CMake to check the build system integrity. -# No rule that depends on this can have commands that come from listfiles -# because they might be regenerated. -cmake_check_build_system: - cd /home/markus/max_origin/MaxScale/query_classifier/test && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 -.PHONY : cmake_check_build_system +buildtests: $(OBJS) + cp $(ERRMSG)/errmsg.sys . + $(CC) $(CFLAGS) $(LDFLAGS) $(LIBS) canonizer.c -o $(TESTAPP) $(LDLIBS) $(LDMYSQL) +runtests: + @echo "" > $(TESTLOG) + @echo "-------------------------------" >> $(TESTLOG) + @echo $(shell date) >> $(TESTLOG) + @echo "Canonical Query Tests" >> $(TESTLOG) + @echo "-------------------------------" >> $(TESTLOG) + @echo "" >> $(TESTLOG) + ./canontest.sh $(TESTLOG) input.sql output.sql expected.sql diff --git a/query_classifier/test/classify.c b/query_classifier/test/classify.c index 3c5b73a97..f18493c05 100644 --- a/query_classifier/test/classify.c +++ b/query_classifier/test/classify.c @@ -28,16 +28,24 @@ static char* server_groups[] = { int main(int argc, char** argv) { + if(argc < 3){ + fprintf(stderr,"Usage: classify "); + return 1; + } int rd = 0,buffsz = getpagesize(),strsz = 0; char buffer[buffsz], *strbuff = (char*)calloc(buffsz,sizeof(char)); + FILE *input,*expected; if(mysql_library_init(num_elements, server_options, server_groups)) { printf("Error: Cannot initialize Embedded Library."); return 1; } - - while((rd = fread(buffer,sizeof(char),buffsz,stdin))){ + + input = fopen(argv[1],"rb"); + expected = fopen(argv[2],"rb"); + + while((rd = fread(buffer,sizeof(char),buffsz,input))){ /**Fill the read buffer*/ if(strsz + rd >= buffsz){ @@ -69,8 +77,8 @@ int main(int argc, char** argv) while(strpbrk(strbuff,";") != NULL){ tok = strpbrk(strbuff,";"); - int qlen = tok - strbuff; - GWBUF* buff = gwbuf_alloc(qlen+5); + unsigned int qlen = tok - strbuff + 1; + GWBUF* buff = gwbuf_alloc(qlen+6); *((unsigned char*)(buff->start)) = qlen; *((unsigned char*)(buff->start + 1)) = (qlen >> 8); *((unsigned char*)(buff->start + 2)) = (qlen >> 16); @@ -81,75 +89,87 @@ int main(int argc, char** argv) strsz -= qlen; memset(strbuff + strsz,0,buffsz - strsz); skygw_query_type_t type = query_classifier_get_type(buff); + char qtypestr[64]; + char expbuff[256]; + int expos = 0; + while((rd = fgetc(expected)) != '\n' && !feof(expected)){ + expbuff[expos++] = rd; + } + expbuff[expos] = '\0'; - if(type == QUERY_TYPE_UNKNOWN){ - printf("QUERY_TYPE_UNKNOWN "); + sprintf(qtypestr,"QUERY_TYPE_UNKNOWN"); } if(type & QUERY_TYPE_LOCAL_READ){ - printf("QUERY_TYPE_LOCAL_READ "); + sprintf(qtypestr,"QUERY_TYPE_LOCAL_READ"); } if(type & QUERY_TYPE_READ){ - printf("QUERY_TYPE_READ "); + sprintf(qtypestr,"QUERY_TYPE_READ"); } if(type & QUERY_TYPE_WRITE){ - printf("QUERY_TYPE_WRITE "); + sprintf(qtypestr,"QUERY_TYPE_WRITE"); } if(type & QUERY_TYPE_MASTER_READ){ - printf("QUERY_TYPE_MASTER_READ "); + sprintf(qtypestr,"QUERY_TYPE_MASTER_READ"); } if(type & QUERY_TYPE_SESSION_WRITE){ - printf("QUERY_TYPE_SESSION_WRITE "); + sprintf(qtypestr,"QUERY_TYPE_SESSION_WRITE"); } if(type & QUERY_TYPE_USERVAR_READ){ - printf("QUERY_TYPE_USERVAR_READ "); + sprintf(qtypestr,"QUERY_TYPE_USERVAR_READ"); } if(type & QUERY_TYPE_SYSVAR_READ){ - printf("QUERY_TYPE_SYSVAR_READ "); + sprintf(qtypestr,"QUERY_TYPE_SYSVAR_READ"); } if(type & QUERY_TYPE_GSYSVAR_READ){ - printf("QUERY_TYPE_GSYSVAR_READ "); + sprintf(qtypestr,"QUERY_TYPE_GSYSVAR_READ"); } if(type & QUERY_TYPE_GSYSVAR_WRITE){ - printf("QUERY_TYPE_GSYSVAR_WRITE "); + sprintf(qtypestr,"QUERY_TYPE_GSYSVAR_WRITE"); } if(type & QUERY_TYPE_BEGIN_TRX){ - printf("QUERY_TYPE_BEGIN_TRX "); + sprintf(qtypestr,"QUERY_TYPE_BEGIN_TRX"); } if(type & QUERY_TYPE_ENABLE_AUTOCOMMIT){ - printf("QUERY_TYPE_ENABLE_AUTOCOMMIT "); + sprintf(qtypestr,"QUERY_TYPE_ENABLE_AUTOCOMMIT"); } if(type & QUERY_TYPE_DISABLE_AUTOCOMMIT){ - printf("QUERY_TYPE_DISABLE_AUTOCOMMIT "); + sprintf(qtypestr,"QUERY_TYPE_DISABLE_AUTOCOMMIT"); } if(type & QUERY_TYPE_ROLLBACK){ - printf("QUERY_TYPE_ROLLBACK "); + sprintf(qtypestr,"QUERY_TYPE_ROLLBACK"); } if(type & QUERY_TYPE_COMMIT){ - printf("QUERY_TYPE_COMMIT "); + sprintf(qtypestr,"QUERY_TYPE_COMMIT"); } if(type & QUERY_TYPE_PREPARE_NAMED_STMT){ - printf("QUERY_TYPE_PREPARE_NAMED_STMT "); + sprintf(qtypestr,"QUERY_TYPE_PREPARE_NAMED_STMT"); } if(type & QUERY_TYPE_PREPARE_STMT){ - printf("QUERY_TYPE_PREPARE_STMT "); + sprintf(qtypestr,"QUERY_TYPE_PREPARE_STMT"); } if(type & QUERY_TYPE_EXEC_STMT){ - printf("QUERY_TYPE_EXEC_STMT "); + sprintf(qtypestr,"QUERY_TYPE_EXEC_STMT"); } if(type & QUERY_TYPE_CREATE_TMP_TABLE){ - printf("QUERY_TYPE_CREATE_TMP_TABLE "); + sprintf(qtypestr,"QUERY_TYPE_CREATE_TMP_TABLE"); } if(type & QUERY_TYPE_READ_TMP_TABLE){ - printf("QUERY_TYPE_READ_TMP_TABLE "); + sprintf(qtypestr,"QUERY_TYPE_READ_TMP_TABLE"); } - - printf("\n"); + + if(strcmp(qtypestr,expbuff) != 0){ + printf("Error in output: '%s' was expected but got '%s'",expbuff,qtypestr); + //return 1; + } + gwbuf_free(buff); } } + fclose(input); + fclose(expected); free(strbuff); return 0; } diff --git a/query_classifier/test/expected.sql b/query_classifier/test/expected.sql index 07ba0751d..c5e5ebb7e 100644 --- a/query_classifier/test/expected.sql +++ b/query_classifier/test/expected.sql @@ -1,19 +1,19 @@ -QUERY_TYPE_UNKNOWN -QUERY_TYPE_UNKNOWN -QUERY_TYPE_READ -QUERY_TYPE_UNKNOWN -QUERY_TYPE_READ -QUERY_TYPE_WRITE -QUERY_TYPE_WRITE -QUERY_TYPE_WRITE -QUERY_TYPE_WRITE -QUERY_TYPE_WRITE -QUERY_TYPE_WRITE -QUERY_TYPE_WRITE -QUERY_TYPE_WRITE -QUERY_TYPE_WRITE -QUERY_TYPE_WRITE -QUERY_TYPE_WRITE -QUERY_TYPE_WRITE -QUERY_TYPE_WRITE -QUERY_TYPE_UNKNOWN +QUERY_TYPE_READ +QUERY_TYPE_READ +QUERY_TYPE_READ +QUERY_TYPE_READ +QUERY_TYPE_READ +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE +QUERY_TYPE_WRITE From 3d7c23cf0b7919b839c286f4d130db154418b6d2 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 6 Oct 2014 14:03:13 +0300 Subject: [PATCH 5/5] added more test cases --- query_classifier/test/classify.c | 6 +++--- query_classifier/test/expected.sql | 24 +++++++++--------------- query_classifier/test/input.sql | 24 +++++++++--------------- 3 files changed, 21 insertions(+), 33 deletions(-) diff --git a/query_classifier/test/classify.c b/query_classifier/test/classify.c index f18493c05..8eafbdc5c 100644 --- a/query_classifier/test/classify.c +++ b/query_classifier/test/classify.c @@ -32,7 +32,7 @@ int main(int argc, char** argv) fprintf(stderr,"Usage: classify "); return 1; } - int rd = 0,buffsz = getpagesize(),strsz = 0; + int rd = 0,buffsz = getpagesize(),strsz = 0,ex_val = 0; char buffer[buffsz], *strbuff = (char*)calloc(buffsz,sizeof(char)); FILE *input,*expected; @@ -161,7 +161,7 @@ int main(int argc, char** argv) if(strcmp(qtypestr,expbuff) != 0){ printf("Error in output: '%s' was expected but got '%s'",expbuff,qtypestr); - //return 1; + ex_val = 1; } gwbuf_free(buff); @@ -171,5 +171,5 @@ int main(int argc, char** argv) fclose(input); fclose(expected); free(strbuff); - return 0; + return ex_val; } diff --git a/query_classifier/test/expected.sql b/query_classifier/test/expected.sql index c5e5ebb7e..23b7c9465 100644 --- a/query_classifier/test/expected.sql +++ b/query_classifier/test/expected.sql @@ -1,19 +1,13 @@ QUERY_TYPE_READ QUERY_TYPE_READ -QUERY_TYPE_READ -QUERY_TYPE_READ -QUERY_TYPE_READ -QUERY_TYPE_WRITE -QUERY_TYPE_WRITE -QUERY_TYPE_WRITE -QUERY_TYPE_WRITE -QUERY_TYPE_WRITE -QUERY_TYPE_WRITE -QUERY_TYPE_WRITE -QUERY_TYPE_WRITE -QUERY_TYPE_WRITE -QUERY_TYPE_WRITE -QUERY_TYPE_WRITE -QUERY_TYPE_WRITE QUERY_TYPE_WRITE QUERY_TYPE_WRITE +QUERY_TYPE_CREATE_TMP_TABLE +QUERY_TYPE_GSYSVAR_WRITE +QUERY_TYPE_SYSVAR_READ +QUERY_TYPE_USERVAR_READ +QUERY_TYPE_COMMIT +QUERY_TYPE_DISABLE_AUTOCOMMIT +QUERY_TYPE_BEGIN_TRX +QUERY_TYPE_ROLLBACK +QUERY_TYPE_COMMIT diff --git a/query_classifier/test/input.sql b/query_classifier/test/input.sql index 657797cc0..1b297b423 100644 --- a/query_classifier/test/input.sql +++ b/query_classifier/test/input.sql @@ -1,19 +1,13 @@ select sleep(2); -select * from tst where lname='Doe'; -select 1,2,3,4,5,6 from tst; -select * from tst where fname like '%a%'; select * from tst where lname like '%e%' order by fname; -insert into tst values ("John"," Doe"),("Donald","Duck"),("Plato",""),("Richard","Stallman"); -insert into tst values ("Jane"," Doe"),("Daisy","Duck"),("Marie","Curie"); -insert into tst values ("John","Doe"),("Donald","Duck"),("Plato",""),("Richard","Stallman"); -insert into tst values ("Jane","Doe"),("Daisy","Duck"),("Marie","Curie"); -insert into tst values ("John","Doe"),("Donald","Duck"),("Plato",""),("Richard","Stallman"); insert into tst values ("Jane","Doe"),("Daisy","Duck"),("Marie","Curie"); update tst set fname="Farmer", lname="McDonald" where lname="%Doe" and fname="John"; -update tst set fname="John" where lname="Doe"; -update tst set lname="Philosopher" where fname="Plato"; -update tst set fname="Human" where fname like 'Richard%'; -update tst set lname="Creature" where lname like '%man%'; -update tst set fname="Jane" where lname="%Doe"; -update tst set lname="Human" where fname like '%a%' or lname like '%a%'; - +create temporary table tmp as select * from t1; +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +select @@server_id; +select @OLD_SQL_NOTES; +SET autocommit=1; +SET autocommit=0; +BEGIN; +ROLLBACK; +COMMIT;