From c6a9c8bb0f9cae8e5c1e72c924699317aaa02fab Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Wed, 25 Mar 2020 13:37:41 +0200 Subject: [PATCH] MXS-2900 Cleanup system test information generation The system test information array now has the full path to the MaxScale configuration file. The array now only contains labels given in CMakeLists.txt. The resulting .cc-file has linebreaks for readability. --- maxscale-system-test/CMakeLists.txt | 3 +- maxscale-system-test/config_test.cpp | 7 +- .../maxtest/include/maxtest/testconnections.h | 26 +++--- .../maxtest/src/test_info.cc.in | 4 +- .../maxtest/src/testconnections.cpp | 41 ++++----- maxscale-system-test/utilities.cmake | 84 +++++++++---------- 6 files changed, 82 insertions(+), 83 deletions(-) diff --git a/maxscale-system-test/CMakeLists.txt b/maxscale-system-test/CMakeLists.txt index a2364b562..9d0c0473e 100644 --- a/maxscale-system-test/CMakeLists.txt +++ b/maxscale-system-test/CMakeLists.txt @@ -13,7 +13,7 @@ # BREAKS_REPL # BREAKS_GALERA set(CTEST_BUILD_NAME "${BUILDNAME}") -set(CNF_TEMPLATES "" CACHE INTERNAL "") +set(TEST_DEFINITIONS "" 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") @@ -1157,5 +1157,6 @@ set_tests_properties(bug471_big PROPERTIES TIMEOUT 3600) ############################### # The core testing library +add_linebreaks(TEST_DEFINITIONS TEST_DEFINITIONS) configure_file(maxtest/src/test_info.cc.in maxtest/src/test_info.cc @ONLY) add_subdirectory(maxtest) diff --git a/maxscale-system-test/config_test.cpp b/maxscale-system-test/config_test.cpp index b12aee71c..0a715f816 100644 --- a/maxscale-system-test/config_test.cpp +++ b/maxscale-system-test/config_test.cpp @@ -7,6 +7,8 @@ #include #include "testconnections.h" +using std::string; + const char* bad_configs[] = { "bug359", @@ -35,8 +37,9 @@ int main(int argc, char** argv) for (int i = 0; bad_configs[i]; i++) { - printf("Testing %s...\n", bad_configs[i]); - if (test->test_bad_config(0, bad_configs[i])) + string config_file_path = (string)test_dir + "/cnf/maxscale.cnf.template." + bad_configs[i]; + printf("Testing %s...\n", config_file_path.c_str()); + if (test->test_bad_config(0, config_file_path)) { printf("FAILED\n"); rval++; diff --git a/maxscale-system-test/maxtest/include/maxtest/testconnections.h b/maxscale-system-test/maxtest/include/maxtest/testconnections.h index 45b14519f..73f05aab7 100644 --- a/maxscale-system-test/maxtest/include/maxtest/testconnections.h +++ b/maxscale-system-test/maxtest/include/maxtest/testconnections.h @@ -521,14 +521,16 @@ public: * @param config Name of the config template * @return Always false, the test will time out if the loading is successful */ - bool test_bad_config(int m, const char* config); + bool test_bad_config(int m, const std::string& config); /** * @brief Process a template configuration file * + * @param cnf_template_path Config file template path * @param dest Destination file name for actual configuration file */ - void process_template(int m, const std::string& src, const char* dest = "/etc/maxscale.cnf"); + void process_template(int m, const std::string& cnf_template_path, + const char* dest = "/etc/maxscale.cnf"); /** * Execute a MaxCtrl command @@ -605,23 +607,23 @@ private: std::vector> m_on_destroy; - std::string m_test_name; /**< Test name */ - std::string m_config_template; /**< MaxScale config file template used by test */ - std::string m_labels; /**< Test labels */ - std::string m_mdbci_labels; /**< Labels for MDBCI */ + std::string m_test_name; /**< Test name */ + std::string m_cnf_template_path; /**< MaxScale config file template used by test */ + std::string m_labels; /**< Test labels */ + std::string m_mdbci_labels; /**< Labels for MDBCI */ - std::string m_mdbci_config_name; /**< Name of MDBCI VMs set */ - std::string m_mdbci_vm_path; /**< Path to directory with MDBCI VMs descriptions */ - std::string m_mdbci_template; /**< Name of mdbci VMs tempate file */ - std::string m_target; /**< Name of Maxscale repository in the CI */ + std::string m_mdbci_config_name; /**< Name of MDBCI VMs set */ + std::string m_mdbci_vm_path; /**< Path to directory with MDBCI VMs descriptions */ + std::string m_mdbci_template; /**< Name of mdbci VMs tempate file */ + std::string m_target; /**< Name of Maxscale repository in the CI */ /** * Command to copy log files from node virtual machines (should handle one parameter: IP address of * virtual machine to kill) */ std::string m_get_logs_command; - std::string m_take_snapshot_command; /**< Command line to create a snapshot of all VMs */ - std::string m_revert_snapshot_command; /**< Command line to revert a snapshot of all VMs */ + std::string m_take_snapshot_command; /**< Command line to create a snapshot of all VMs */ + std::string m_revert_snapshot_command; /**< Command line to revert a snapshot of all VMs */ bool m_enable_timeouts {true}; /**< Whether timeouts are enabled or not */ bool m_local_maxscale {false}; /**< MaxScale runs locally, specified using -l. */ diff --git a/maxscale-system-test/maxtest/src/test_info.cc.in b/maxscale-system-test/maxtest/src/test_info.cc.in index ed4947e58..23336a9ff 100644 --- a/maxscale-system-test/maxtest/src/test_info.cc.in +++ b/maxscale-system-test/maxtest/src/test_info.cc.in @@ -2,10 +2,10 @@ const TestDefinition test_definitions_arr[] = { -@CNF_TEMPLATES@{nullptr, nullptr, nullptr} +@TEST_DEFINITIONS@{nullptr, nullptr, nullptr} }; const TestDefinition* test_definitions = test_definitions_arr; -const char* default_template = "replication"; +const char* default_template = "@CMAKE_CURRENT_SOURCE_DIR@/cnf/maxscale.cnf.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 5952b3900..4e7d2bdd4 100644 --- a/maxscale-system-test/maxtest/src/testconnections.cpp +++ b/maxscale-system-test/maxtest/src/testconnections.cpp @@ -253,7 +253,8 @@ TestConnections::TestConnections(int argc, char* argv[]) m_test_name = (optind < argc) ? argv[optind] : basename(argv[0]); set_template_and_labels(); - tprintf("testname: '%s', template: '%s'", m_test_name.c_str(), m_config_template.c_str()); + tprintf("Test: '%s', config template: '%s', labels: '%s'", + m_test_name.c_str(), m_cnf_template_path.c_str(), m_labels.c_str()); set_mdbci_labels(); std::string delimiter = std::string (","); @@ -695,48 +696,40 @@ void TestConnections::set_template_and_labels() } } - string labels_string; if (found) { - labels_string = found->labels; - m_config_template = found->config_template; + m_cnf_template_path = found->config_template; + m_labels = found->labels; } else { printf("Failed to find configuration template for test '%s', using default template '%s'.\n", m_test_name.c_str(), default_template); - m_config_template = default_template; + m_cnf_template_path = default_template; } - auto labels_pos = labels_string.find("LABELS;"); - if (labels_pos != string::npos) + if (m_labels.empty()) { - m_labels = labels_string.substr(labels_pos); - } - else - { - m_labels = "LABELS;REPL_BACKEND"; + m_labels = "REPL_BACKEND"; } } -void TestConnections::process_template(int m, const string& template_name, const char* dest) +void TestConnections::process_template(int m, const string& cnf_template_path, const char* dest) { struct stat stb; char str[4096]; - char template_file[1024]; + string template_file = cnf_template_path; char extended_template_file[1024]; - - sprintf(template_file, "%s/cnf/maxscale.cnf.template.%s", test_dir, template_name.c_str()); - sprintf(extended_template_file, "%s.%03d", template_file, m); - - if (stat((char*)extended_template_file, &stb) == 0) + sprintf(extended_template_file, "%s.%03d", cnf_template_path.c_str(), m); + if (stat(extended_template_file, &stb) == 0) { - strcpy(template_file, extended_template_file); + template_file = extended_template_file; } - tprintf("Template file is %s\n", template_file); - sprintf(str, "cp %s maxscale.cnf", template_file); + tprintf("Template file is %s\n", template_file.c_str()); + + sprintf(str, "cp %s maxscale.cnf", template_file.c_str()); if (verbose) { tprintf("Executing '%s' command\n", str); @@ -826,7 +819,7 @@ void TestConnections::init_maxscales() void TestConnections::init_maxscale(int m) { - process_template(m, m_config_template, maxscales->access_homedir[m]); + process_template(m, m_cnf_template_path, maxscales->access_homedir[m]); if (maxscales->ssh_node_f(m, true, "test -d %s/certs", maxscales->access_homedir[m])) { tprintf("SSL certificates not found, copying to maxscale"); @@ -2154,7 +2147,7 @@ int TestConnections::revert_snapshot(char* snapshot_name) return system(str); } -bool TestConnections::test_bad_config(int m, const char* config) +bool TestConnections::test_bad_config(int m, const string& config) { process_template(m, config, "/tmp/"); diff --git a/maxscale-system-test/utilities.cmake b/maxscale-system-test/utilities.cmake index 9925b9b5b..d38929921 100644 --- a/maxscale-system-test/utilities.cmake +++ b/maxscale-system-test/utilities.cmake @@ -1,78 +1,78 @@ +# Default test timeout +set(TEST_TIMEOUT 3600) -# Helper function to add a configuration template -function(add_template name template labels) - set(CNF_TEMPLATES "${CNF_TEMPLATES}{\"${name}\", \"${template}\", \"${labels}\"}," CACHE INTERNAL "") +# Adds linebreaks to curly brackets in a variable. +function(add_linebreaks source_var dest_var) + string(REPLACE }, },\n splitted "${${source_var}}") + set(${dest_var} ${splitted} PARENT_SCOPE) endfunction() +# Helper function to add a configuration template to the global test definitions list. +# Parameters are as in add_test_executable(). +function(add_template name template labels) + set(config_template_path "${CMAKE_CURRENT_SOURCE_DIR}/cnf/maxscale.cnf.template.${template}") + set(new_def "{\"${name}\", \"${config_template_path}\", \"${labels}\"}") + set(TEST_DEFINITIONS "${TEST_DEFINITIONS}${new_def}," CACHE INTERNAL "") +endfunction() # Helper function to add a configuration template function(add_template_manual name template) - add_template(${name} ${template} "${name}.cpp;${name};${template};LABELS;CONFIG") + add_template(${name} ${template} "CONFIG") +endfunction() + +# Helper function for adding properties to a test. Adds the default timeout and labels. +function(add_test_properties name labels) + list(APPEND labels ${ARGN}) + # Remove the LABELS-string from the list if it's there. + list(REMOVE_ITEM labels "LABELS") + set_property(TEST ${name} PROPERTY TIMEOUT ${TEST_TIMEOUT}) + set_property(TEST ${name} APPEND PROPERTY LABELS ${labels}) endfunction() -# Default test timeout -set(TIMEOUT 3600) # This functions adds a source file as an executable, links that file against -# the common test core and creates a test from it. The first parameter is the -# source file, the second is the name of the executable and the test and the -# last parameter is the template suffix of the test. The template should follow -# the following naming policy: `maxscale.cnf.template.