Changed the way query classifier test is run.

Now the test is a single executable, which should make it easier to use with CMake.
This commit is contained in:
Markus Makela
2014-10-03 12:18:02 +03:00
parent 3b0e3d04dc
commit b22ab90d66
5 changed files with 118 additions and 204 deletions

View File

@ -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")
add_test(TestQueryClassifier classify ${CMAKE_CURRENT_SOURCE_DIR}/input.sql ${CMAKE_CURRENT_SOURCE_DIR}/expected.sql)

View File

@ -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

View File

@ -28,16 +28,24 @@ static char* server_groups[] = {
int main(int argc, char** argv)
{
if(argc < 3){
fprintf(stderr,"Usage: classify <input> <expected output>");
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;
}

View File

@ -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