From 36244e9c7bfe9f6b9170f0536fca39829d8dc55c Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Fri, 20 Mar 2020 14:11:44 +0200 Subject: [PATCH] MXS-2900 Move test description array to a .cc-file The array is now compiled into the maxtest-library. Also cleaned up the array handling a bit. --- maxscale-system-test/CMakeLists.txt | 8 ++--- .../maxtest/include/maxtest/test_dir.hh | 4 +++ .../maxtest/include/maxtest/test_info.hh | 14 ++++++++ .../maxtest/include/maxtest/testconnections.h | 4 +-- .../maxtest/src/CMakeLists.txt | 1 + .../maxtest/src/mariadb_func.cpp | 2 +- .../maxtest/src/test_info.cc.in | 11 +++++++ .../maxtest/src/testconnections.cpp | 33 +++++++++++-------- maxscale-system-test/templates.h.in | 18 ---------- maxscale-system-test/utilities.cmake | 2 +- 10 files changed, 58 insertions(+), 39 deletions(-) create mode 100644 maxscale-system-test/maxtest/include/maxtest/test_dir.hh create mode 100644 maxscale-system-test/maxtest/include/maxtest/test_info.hh create mode 100644 maxscale-system-test/maxtest/src/test_info.cc.in delete mode 100644 maxscale-system-test/templates.h.in diff --git a/maxscale-system-test/CMakeLists.txt b/maxscale-system-test/CMakeLists.txt index dba217eaa..a2364b562 100644 --- a/maxscale-system-test/CMakeLists.txt +++ b/maxscale-system-test/CMakeLists.txt @@ -13,6 +13,7 @@ # BREAKS_REPL # BREAKS_GALERA set(CTEST_BUILD_NAME "${BUILDNAME}") +set(CNF_TEMPLATES "" CACHE INTERNAL "") set(CMAKE_CXX_FLAGS "-std=c++11 -ggdb -Wall -Wextra -Werror -Wno-format-overflow -Wno-unused-function -Wno-unused-parameter -Werror=format-security") set(CMAKE_CXX_FLAGS_DEBUG "-std=c++11 -ggdb -Wall -Werror -Wno-format-overflow -Wno-unused-function") @@ -29,9 +30,6 @@ include_directories(${CMAKE_SOURCE_DIR}/connectors/cdc-connector) include_directories(${CMAKE_BINARY_DIR}) # Include the CDC connector headers include_directories(${CMAKE_SOURCE_DIR}/../connectors/cdc-connector/) - -# The core testing library -add_subdirectory(maxtest) include_directories(maxtest/include/maxtest) # Tool used to check backend state @@ -1158,4 +1156,6 @@ set_tests_properties(bug471_big PROPERTIES TIMEOUT 3600) # DO NOT ADD TESTS AFTER THIS # ############################### -configure_file(templates.h.in ${CMAKE_CURRENT_BINARY_DIR}/templates.h @ONLY) +# The core testing library +configure_file(maxtest/src/test_info.cc.in maxtest/src/test_info.cc @ONLY) +add_subdirectory(maxtest) diff --git a/maxscale-system-test/maxtest/include/maxtest/test_dir.hh b/maxscale-system-test/maxtest/include/maxtest/test_dir.hh new file mode 100644 index 000000000..4c9a37dbe --- /dev/null +++ b/maxscale-system-test/maxtest/include/maxtest/test_dir.hh @@ -0,0 +1,4 @@ +#pragma once +/** This is the working directory for all tests */ +extern const char* test_dir; + diff --git a/maxscale-system-test/maxtest/include/maxtest/test_info.hh b/maxscale-system-test/maxtest/include/maxtest/test_info.hh new file mode 100644 index 000000000..7eb5ad61a --- /dev/null +++ b/maxscale-system-test/maxtest/include/maxtest/test_info.hh @@ -0,0 +1,14 @@ +#pragma once +#include "test_dir.hh" + +struct TestDefinition +{ + const char* name; + const char* config_template; + const char* labels; +}; + +extern const TestDefinition* test_definitions; + +/** The default template to use */ +extern const char* default_template; diff --git a/maxscale-system-test/maxtest/include/maxtest/testconnections.h b/maxscale-system-test/maxtest/include/maxtest/testconnections.h index 6b14dff5c..ca18be335 100644 --- a/maxscale-system-test/maxtest/include/maxtest/testconnections.h +++ b/maxscale-system-test/maxtest/include/maxtest/testconnections.h @@ -2,7 +2,7 @@ #include "mariadb_nodes.h" #include "maxscales.h" -#include "templates.h" +#include "test_dir.hh" #include #include #include @@ -736,7 +736,7 @@ std::string dump_status(const StringSet& current, const StringSet& expected); * @param labels pointer to string for storing all test labels * @return Name of maxscale.cnf file template */ -const char *get_template_name(char * test_name, const char **labels); +const char* get_template_name(char* test_name, const char**labels); /** * @brief readenv_and_set_default Read enviromental variable and set default values if diff --git a/maxscale-system-test/maxtest/src/CMakeLists.txt b/maxscale-system-test/maxtest/src/CMakeLists.txt index e70b30026..3b001ae84 100644 --- a/maxscale-system-test/maxtest/src/CMakeLists.txt +++ b/maxscale-system-test/maxtest/src/CMakeLists.txt @@ -23,6 +23,7 @@ add_library(maxtest SHARED tcp_connection.cpp test_binlog_fnc.cpp testconnections.cpp + ${CMAKE_CURRENT_BINARY_DIR}/test_info.cc # Include the CDC connector in the core library ${CMAKE_SOURCE_DIR}/connectors/cdc-connector/cdc_connector.cpp) target_link_libraries(maxtest ${MARIADB_CONNECTOR_LIBRARIES} ${JANSSON_LIBRARIES} z m pthread ssl dl rt crypto crypt maxbase) diff --git a/maxscale-system-test/maxtest/src/mariadb_func.cpp b/maxscale-system-test/maxtest/src/mariadb_func.cpp index 3c97c14bb..af0cb8148 100644 --- a/maxscale-system-test/maxtest/src/mariadb_func.cpp +++ b/maxscale-system-test/maxtest/src/mariadb_func.cpp @@ -12,7 +12,7 @@ #include "mariadb_func.h" -#include "templates.h" +#include "test_dir.hh" #include #include diff --git a/maxscale-system-test/maxtest/src/test_info.cc.in b/maxscale-system-test/maxtest/src/test_info.cc.in new file mode 100644 index 000000000..ed4947e58 --- /dev/null +++ b/maxscale-system-test/maxtest/src/test_info.cc.in @@ -0,0 +1,11 @@ +#include "test_info.hh" + +const TestDefinition test_definitions_arr[] = +{ +@CNF_TEMPLATES@{nullptr, nullptr, nullptr} +}; + +const TestDefinition* test_definitions = test_definitions_arr; +const char* default_template = "replication"; +const char* test_dir = "@CMAKE_CURRENT_SOURCE_DIR@"; + diff --git a/maxscale-system-test/maxtest/src/testconnections.cpp b/maxscale-system-test/maxtest/src/testconnections.cpp index c39d4cae1..902cf9e83 100644 --- a/maxscale-system-test/maxtest/src/testconnections.cpp +++ b/maxscale-system-test/maxtest/src/testconnections.cpp @@ -19,6 +19,7 @@ #include "maxadmin_operations.h" #include "sql_t1.h" #include "testconnections.h" +#include "test_info.hh" #include "labels_table.h" #include "envv.h" @@ -266,7 +267,7 @@ TestConnections::TestConnections(int argc, char* argv[]) test_name = basename(argv[0]); } - const char * labels_string = NULL; + const char* labels_string = ""; template_name = get_template_name(test_name, &labels_string); tprintf("testname: '%s', template: '%s'", test_name, template_name); labels = strstr(labels_string, "LABELS;"); @@ -699,25 +700,31 @@ void TestConnections::print_env() } } -const char * get_template_name(char * test_name, const char ** labels) +const char* get_template_name(char* test_name, const char** labels) { - int i = 0; - *labels = NULL; - while (cnf_templates[i].test_name && strcmp(cnf_templates[i].test_name, test_name) != 0) + const TestDefinition* found = nullptr; + for (int i = 0; test_definitions[i].name; i++) { - i++; + auto* test = &test_definitions[i]; + if (strcmp(test->name, test_name) == 0) + { + found = test; + break; + } } - if (cnf_templates[i].test_name) + if (found) { - *labels = (char *) cnf_templates[i].test_labels; - return cnf_templates[i].test_template; + *labels = found->labels; + return found->config_template; + } + else + { + printf("Failed to find configuration template for test '%s', using default template '%s'.\n", + test_name, default_template); + return default_template; } - printf("Failed to find configuration template for test '%s', using default template '%s'.\n", - test_name, - default_template); - return default_template; } void TestConnections::process_template(int m, const char* template_name, const char* dest) diff --git a/maxscale-system-test/templates.h.in b/maxscale-system-test/templates.h.in deleted file mode 100644 index 0caabb8c8..000000000 --- a/maxscale-system-test/templates.h.in +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef TEMPLATES_H -#define TEMPLATES_H - -static struct -{ - const char* test_name; - const char* test_template; - const char* test_labels; -} cnf_templates[] __attribute__((unused)) = { -@CNF_TEMPLATES@ {NULL, NULL, NULL}}; - -/** The default template to use */ -static const char * default_template __attribute__((unused)) = "replication"; - -/** This is the working directory for all tests */ -static const char *test_dir __attribute__((unused)) = "@CMAKE_CURRENT_SOURCE_DIR@"; - -#endif diff --git a/maxscale-system-test/utilities.cmake b/maxscale-system-test/utilities.cmake index 87be4445a..9925b9b5b 100644 --- a/maxscale-system-test/utilities.cmake +++ b/maxscale-system-test/utilities.cmake @@ -1,7 +1,7 @@ # Helper function to add a configuration template function(add_template name template labels) - set(CNF_TEMPLATES "${CNF_TEMPLATES}{\"${name}\",\"${template}\", \"${labels}\"}," CACHE INTERNAL "") + set(CNF_TEMPLATES "${CNF_TEMPLATES}{\"${name}\", \"${template}\", \"${labels}\"}," CACHE INTERNAL "") endfunction()