This commit is contained in:
VilhoRaatikka 2014-10-07 18:25:31 +03:00
commit 93dc40bcb9
11 changed files with 489 additions and 12 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 2.6)
message(STATUS "CMake version: ${CMAKE_VERSION}")
include(macros.cmake)
enable_testing()

View File

@ -1,6 +1,11 @@
file(COPY ${ERRMSG} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
if(${ERRMSG} MATCHES "ERRMSG-NOTFOUND")
message(FATAL_ERROR "The errmsg.sys file was not found, please define the path with -DERRMSG=<path>")
else()
if(${CMAKE_VERSION} VERSION_LESS 2.8)
execute_process(COMMAND cp ${ERRMSG} ${CMAKE_CURRENT_BINARY_DIR})
else()
file(COPY ${ERRMSG} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
endif()
endif()
add_executable(canonizer canonizer.c)
target_link_libraries(canonizer pthread query_classifier z dl ssl aio crypt crypto rt m ${EMBEDDED_LIB} fullcore stdc++)

View File

@ -257,7 +257,7 @@ poll_add_dcb(DCB *dcb)
dcb,
STRDCBSTATE(dcb->state))));
}
ss_dassert(rc == 0); /*< trap in debug */
ss_info_dassert(rc == 0, "Unable to add poll"); /*< trap in debug */
} else {
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,

View File

@ -0,0 +1,155 @@
/*
* 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
* 29-08-2014 Martin Brampton Initial implementation
*
* @endverbatim
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <buffer.h>
/**
* test1 Allocate a buffer and do lots of things
*
*/
static int
test1()
{
GWBUF *buffer, *extra, *clone, *partclone, *transform;
int size = 100;
int bite1 = 35;
int bite2 = 60;
int bite3 = 10;
int buflen;
/* Single buffer tests */
ss_dfprintf(stderr,
"testbuffer : creating buffer with data size %d bytes",
size);
buffer = gwbuf_alloc(size);
ss_dfprintf(stderr, "\t..done\nAllocated buffer of size %d.", size);
buflen = GWBUF_LENGTH(buffer);
ss_dfprintf(stderr, "\nBuffer length is now %d", buflen);
ss_info_dassert(size == buflen, "Incorrect buffer size");
ss_info_dassert(0 == GWBUF_EMPTY(buffer), "Buffer should not be empty");
ss_info_dassert(GWBUF_IS_TYPE_UNDEFINED(buffer), "Buffer type should be undefined");
strcpy(GWBUF_DATA(buffer), "The quick brown fox jumps over the lazy dog");
ss_dfprintf(stderr, "\t..done\nLoad some data into the buffer");
ss_info_dassert('q' == GWBUF_DATA_CHAR(buffer, 4), "Fourth character of buffer must be 'q'");
ss_info_dassert(-1 == GWBUF_DATA_CHAR(buffer, 105), "Hundred and fifth character of buffer must return -1");
ss_info_dassert(0 == GWBUF_IS_SQL(buffer), "Must say buffer is not SQL, as it does not have marker");
strcpy(GWBUF_DATA(buffer), "1234\x03SELECT * FROM sometable");
ss_dfprintf(stderr, "\t..done\nLoad SQL data into the buffer");
ss_info_dassert(1 == GWBUF_IS_SQL(buffer), "Must say buffer is SQL, as it does have marker");
transform = gwbuf_clone_transform(buffer, GWBUF_TYPE_PLAINSQL);
ss_dfprintf(stderr, "\t..done\nAttempt to transform buffer to plain SQL - should fail");
ss_info_dassert(NULL == transform, "Buffer cannot be transformed to plain SQL");
gwbuf_set_type(buffer, GWBUF_TYPE_MYSQL);
ss_dfprintf(stderr, "\t..done\nChanged buffer type to MySQL");
ss_info_dassert(GWBUF_IS_TYPE_MYSQL(buffer), "Buffer type changed to MySQL");
transform = gwbuf_clone_transform(buffer, GWBUF_TYPE_PLAINSQL);
ss_dfprintf(stderr, "\t..done\nAttempt to transform buffer to plain SQL - should succeed");
ss_info_dassert((NULL != transform) && (GWBUF_IS_TYPE_PLAINSQL(transform)), "Transformed buffer is plain SQL");
clone = gwbuf_clone(buffer);
ss_dfprintf(stderr, "\t..done\nCloned buffer");
buflen = GWBUF_LENGTH(clone);
ss_dfprintf(stderr, "\nCloned buffer length is now %d", buflen);
ss_info_dassert(size == buflen, "Incorrect buffer size");
ss_info_dassert(0 == GWBUF_EMPTY(clone), "Cloned buffer should not be empty");
ss_dfprintf(stderr, "\t..done\n");
gwbuf_free(clone);
ss_dfprintf(stderr, "Freed cloned buffer");
ss_dfprintf(stderr, "\t..done\n");
partclone = gwbuf_clone_portion(buffer, 25, 50);
buflen = GWBUF_LENGTH(partclone);
ss_dfprintf(stderr, "Part cloned buffer length is now %d", buflen);
ss_info_dassert(50 == buflen, "Incorrect buffer size");
ss_info_dassert(0 == GWBUF_EMPTY(partclone), "Part cloned buffer should not be empty");
ss_dfprintf(stderr, "\t..done\n");
gwbuf_free(partclone);
ss_dfprintf(stderr, "Freed part cloned buffer");
ss_dfprintf(stderr, "\t..done\n");
buffer = gwbuf_consume(buffer, bite1);
ss_info_dassert(NULL != buffer, "Buffer should not be null");
buflen = GWBUF_LENGTH(buffer);
ss_dfprintf(stderr, "Consumed %d bytes, now have %d, should have %d", bite1, buflen, size-bite1);
ss_info_dassert((size - bite1) == buflen, "Incorrect buffer size");
ss_info_dassert(0 == GWBUF_EMPTY(buffer), "Buffer should not be empty");
ss_dfprintf(stderr, "\t..done\n");
buffer = gwbuf_consume(buffer, bite2);
ss_info_dassert(NULL != buffer, "Buffer should not be null");
buflen = GWBUF_LENGTH(buffer);
ss_dfprintf(stderr, "Consumed %d bytes, now have %d, should have %d", bite2, buflen, size-bite1-bite2);
ss_info_dassert((size-bite1-bite2) == buflen, "Incorrect buffer size");
ss_info_dassert(0 == GWBUF_EMPTY(buffer), "Buffer should not be empty");
ss_dfprintf(stderr, "\t..done\n");
buffer = gwbuf_consume(buffer, bite3);
ss_dfprintf(stderr, "Consumed %d bytes, should have null buffer", bite3);
ss_info_dassert(NULL == buffer, "Buffer should be null");
/* Buffer list tests */
size = 100000;
buffer = gwbuf_alloc(size);
ss_dfprintf(stderr, "\t..done\nAllocated buffer of size %d.", size);
buflen = GWBUF_LENGTH(buffer);
ss_dfprintf(stderr, "\nBuffer length is now %d", buflen);
ss_info_dassert(size == buflen, "Incorrect buffer size");
ss_info_dassert(0 == GWBUF_EMPTY(buffer), "Buffer should not be empty");
ss_info_dassert(GWBUF_IS_TYPE_UNDEFINED(buffer), "Buffer type should be undefined");
extra = gwbuf_alloc(size);
buflen = GWBUF_LENGTH(buffer);
ss_dfprintf(stderr, "\t..done\nAllocated extra buffer of size %d.", size);
ss_info_dassert(size == buflen, "Incorrect buffer size");
buffer = gwbuf_append(buffer, extra);
buflen = gwbuf_length(buffer);
ss_dfprintf(stderr, "\t..done\nAppended extra buffer to original buffer to create list of size %d", buflen);
ss_info_dassert((size*2) == gwbuf_length(buffer), "Incorrect size for set of buffers");
buffer = gwbuf_rtrim(buffer, 60000);
buflen = GWBUF_LENGTH(buffer);
ss_dfprintf(stderr, "\t..done\nTrimmed 60 bytes from buffer, now size is %d.", buflen);
ss_info_dassert((size-60000) == buflen, "Incorrect buffer size");
buffer = gwbuf_rtrim(buffer, 60000);
buflen = GWBUF_LENGTH(buffer);
ss_dfprintf(stderr, "\t..done\nTrimmed another 60 bytes from buffer, now size is %d.", buflen);
ss_info_dassert(100000 == buflen, "Incorrect buffer size");
ss_info_dassert(buffer == extra, "The buffer pointer should now point to the extra buffer");
ss_dfprintf(stderr, "\t..done\n");
return 0;
}
int main(int argc, char **argv)
{
int result = 0;
result += test1();
exit(result);
}

View File

@ -0,0 +1,87 @@
/*
* 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
* 05-09-2014 Martin Brampton Initial implementation
*
* @endverbatim
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dcb.h>
/**
* test1 Allocate a dcb and do lots of other things
*
*/
static int
test1()
{
DCB *dcb, *extra, *clone;
int size = 100;
int bite1 = 35;
int bite2 = 60;
int bite3 = 10;
int buflen;
/* Single buffer tests */
ss_dfprintf(stderr,
"testdcb : creating buffer with type DCB_ROLE_SERVICE_LISTENER");
dcb = dcb_alloc(DCB_ROLE_SERVICE_LISTENER);
ss_info_dassert(dcb_isvalid(dcb), "New DCB must be valid");
ss_dfprintf(stderr, "\t..done\nAllocated dcb.");
clone = dcb_clone(dcb);
ss_dfprintf(stderr, "\t..done\nCloned dcb");
printAllDCBs();
ss_info_dassert(true, "Something is true");
ss_dfprintf(stderr, "\t..done\n");
dcb_free(dcb);
ss_dfprintf(stderr, "Freed original dcb");
ss_info_dassert(!dcb_isvalid(dcb), "Freed DCB must not be valid");
ss_dfprintf(stderr, "\t..done\nMake clone DCB a zombie");
clone->state = DCB_STATE_NOPOLLING;
dcb_add_to_zombieslist(clone);
ss_info_dassert(dcb_get_zombies() == clone, "Clone DCB must be start of zombie list now");
ss_dfprintf(stderr, "\t..done\nProcess the zombies list");
dcb_process_zombies(0);
ss_dfprintf(stderr, "\t..done\nCheck clone no longer valid");
ss_info_dassert(!dcb_isvalid(clone), "After zombie processing, clone DCB must not be valid");
ss_dfprintf(stderr, "\t..done\n");
return 0;
}
int main(int argc, char **argv)
{
int result = 0;
result += test1();
exit(result);
}

View File

@ -0,0 +1,78 @@
/*
* 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
* 17-09-2014 Martin Brampton Initial implementation
*
* @endverbatim
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <modutil.h>
#include <buffer.h>
/**
* test1 Allocate a service and do lots of other things
*
*/
static int
test1()
{
GWBUF *buffer;
char *(sql[100]);
int result, length, residual;
/* Poll tests */
ss_dfprintf(stderr,
"testmodutil : Rudimentary tests.");
buffer = gwbuf_alloc(100);
ss_info_dassert(0 == modutil_is_SQL(buffer), "Default buffer should be diagnosed as not SQL");
/* There would ideally be some straightforward way to create a SQL buffer? */
ss_dfprintf(stderr, "\t..done\nExtract SQL from buffer");
ss_info_dassert(0 == modutil_extract_SQL(buffer, sql, &length), "Default buffer should fail");
ss_dfprintf(stderr, "\t..done\nExtract SQL from buffer different way?");
ss_info_dassert(0 == modutil_MySQL_Query(buffer, sql, &length, &residual), "Default buffer should fail");
ss_dfprintf(stderr, "\t..done\nReplace SQL in buffer");
ss_info_dassert(0 == modutil_replace_SQL(buffer, "select * from some_table;"), "Default buffer should fail");
ss_dfprintf(stderr, "\t..done\nTidy up.");
gwbuf_free(buffer);
ss_dfprintf(stderr, "\t..done\n");
return 0;
}
int main(int argc, char **argv)
{
int result = 0;
result += test1();
exit(result);
}

View File

@ -0,0 +1,77 @@
/*
* 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
* 11-09-2014 Martin Brampton Initial implementation
*
* @endverbatim
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <poll.h>
#include <dcb.h>
/**
* test1 Allocate a service and do lots of other things
*
*/
static int
test1()
{
DCB *dcb;
int result;
/* Poll tests */
ss_dfprintf(stderr,
"testpoll : Initialise the polling system.");
poll_init();
ss_dfprintf(stderr, "\t..done\nAdd a DCB");
dcb = dcb_alloc(DCB_ROLE_SERVICE_LISTENER);
dcb->fd = socket(AF_UNIX, SOCK_STREAM, 0);
poll_add_dcb(dcb);
poll_remove_dcb(dcb);
poll_add_dcb(dcb);
ss_dfprintf(stderr, "\t..done\nStart wait for events.");
sleep(10);
poll_shutdown();
ss_dfprintf(stderr, "\t..done\nTidy up.");
dcb_free(dcb);
ss_dfprintf(stderr, "\t..done\n");
return 0;
}
int main(int argc, char **argv)
{
int result = 0;
result += test1();
exit(result);
}

View File

@ -0,0 +1,80 @@
/*
* 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
* 08-09-2014 Martin Brampton Initial implementation
*
* @endverbatim
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <service.h>
/**
* test1 Allocate a service and do lots of other things
*
*/
static int
test1()
{
SERVICE *service;
int result;
/* Service tests */
ss_dfprintf(stderr,
"testservice : creating service called MyService with router nonexistent");
service = service_alloc("MyService", "nonexistent");
ss_info_dassert(NULL == service, "New service with invalid router should be null");
ss_info_dassert(0 == service_isvalid(service), "Service must not be valid after incorrect creation");
ss_dfprintf(stderr, "\t..done\nValid service creation, router testroute.");
service = service_alloc("MyService", "testroute");
ss_info_dassert(NULL != service, "New service with valid router must not be null");
ss_info_dassert(0 != service_isvalid(service), "Service must be valid after creation");
ss_info_dassert(0 == strcmp("MyService", service_get_name(service)), "Service must have given name");
ss_dfprintf(stderr, "\t..done\nAdding protocol HTTPD.");
ss_info_dassert(0 != serviceAddProtocol(service, "HTTPD", "localhost", 9876), "Add Protocol should succeed");
ss_info_dassert(0 != serviceHasProtocol(service, "HTTPD", 9876), "Service should have new protocol as requested");
ss_dfprintf(stderr, "\t..done\nStarting Service.");
result = serviceStart(service);
ss_info_dassert(0 != result, "Start should succeed");
ss_dfprintf(stderr, "\t..done\nStopping Service.");
ss_info_dassert(0 != serviceStop(service), "Stop should succeed");
ss_dfprintf(stderr, "\t..done\nFreeing Service.");
ss_info_dassert(0 != service_free(service), "Free should succeed");
ss_dfprintf(stderr, "\t..done\n");
return 0;
}
int main(int argc, char **argv)
{
int result = 0;
result += test1();
exit(result);
}

View File

@ -1,3 +1,2 @@
add_test(NAME ReadWriteSplitTest COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/rwsplit.sh testrwsplit.log ${TEST_HOST} ${TEST_PORT_RW} ${TEST_MASTER_ID} ${TEST_USER} ${TEST_PASSWORD} ${CMAKE_CURRENT_SOURCE_DIR})
set_tests_properties(ReadWriteSplitTest PROPERTIES DEPENDS RunExecutable)
add_subdirectory(test_hints)

View File

@ -1,7 +1,3 @@
file(COPY MaxScale_test.cnf DESTINATION ${CMAKE_BINARY_DIR}/etc)
file(RENAME ${CMAKE_BINARY_DIR}/etc/MaxScale_test.cnf ${CMAKE_BINARY_DIR}/etc/MaxScale.cnf)
#add_test(NAME RunExecutable COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/startmaxscale.sh "${CMAKE_BINARY_DIR}/bin/" "-c ${CMAKE_BINARY_DIR}")
#set_tests_properties(RunExecutable PROPERTIES TIMEOUT 2)
#add_test(NAME KillExecutable COMMAND killall -KILL maxscale)
#set_tests_properties(KillExecutable PROPERTIES DEPENDS StackHintTest ) #this needs to be the last test that requires a running maxscale
if(BUILD_TESTS)
install(FILES MaxScale_test.cnf DESTINATION etc RENAME MaxScale.cnf)
endif()

View File

@ -1918,7 +1918,7 @@ char* replace_literal(
}
rc = regcomp(&re, search_re, REG_EXTENDED|REG_ICASE);
ss_dassert(rc == 0);
ss_info_dassert(rc == 0, "Regex check");
if (rc != 0)
{