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.
This commit is contained in:
Esa Korhonen
2020-03-25 13:37:41 +02:00
parent d69e519038
commit c6a9c8bb0f
6 changed files with 82 additions and 83 deletions

View File

@ -13,7 +13,7 @@
# BREAKS_REPL # BREAKS_REPL
# BREAKS_GALERA # BREAKS_GALERA
set(CTEST_BUILD_NAME "${BUILDNAME}") 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 "-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") 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 # The core testing library
add_linebreaks(TEST_DEFINITIONS TEST_DEFINITIONS)
configure_file(maxtest/src/test_info.cc.in maxtest/src/test_info.cc @ONLY) configure_file(maxtest/src/test_info.cc.in maxtest/src/test_info.cc @ONLY)
add_subdirectory(maxtest) add_subdirectory(maxtest)

View File

@ -7,6 +7,8 @@
#include <unistd.h> #include <unistd.h>
#include "testconnections.h" #include "testconnections.h"
using std::string;
const char* bad_configs[] = const char* bad_configs[] =
{ {
"bug359", "bug359",
@ -35,8 +37,9 @@ int main(int argc, char** argv)
for (int i = 0; bad_configs[i]; i++) for (int i = 0; bad_configs[i]; i++)
{ {
printf("Testing %s...\n", bad_configs[i]); string config_file_path = (string)test_dir + "/cnf/maxscale.cnf.template." + bad_configs[i];
if (test->test_bad_config(0, bad_configs[i])) printf("Testing %s...\n", config_file_path.c_str());
if (test->test_bad_config(0, config_file_path))
{ {
printf("FAILED\n"); printf("FAILED\n");
rval++; rval++;

View File

@ -521,14 +521,16 @@ public:
* @param config Name of the config template * @param config Name of the config template
* @return Always false, the test will time out if the loading is successful * @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 * @brief Process a template configuration file
* *
* @param cnf_template_path Config file template path
* @param dest Destination file name for actual configuration file * @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 * Execute a MaxCtrl command
@ -605,23 +607,23 @@ private:
std::vector<std::function<void(void)>> m_on_destroy; std::vector<std::function<void(void)>> m_on_destroy;
std::string m_test_name; /**< Test name */ std::string m_test_name; /**< Test name */
std::string m_config_template; /**< MaxScale config file template used by test */ std::string m_cnf_template_path; /**< MaxScale config file template used by test */
std::string m_labels; /**< Test labels */ std::string m_labels; /**< Test labels */
std::string m_mdbci_labels; /**< Labels for MDBCI */ std::string m_mdbci_labels; /**< Labels for MDBCI */
std::string m_mdbci_config_name; /**< Name of MDBCI VMs set */ 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_vm_path; /**< Path to directory with MDBCI VMs descriptions */
std::string m_mdbci_template; /**< Name of mdbci VMs tempate file */ 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_target; /**< Name of Maxscale repository in the CI */
/** /**
* Command to copy log files from node virtual machines (should handle one parameter: IP address of * Command to copy log files from node virtual machines (should handle one parameter: IP address of
* virtual machine to kill) */ * virtual machine to kill) */
std::string m_get_logs_command; std::string m_get_logs_command;
std::string m_take_snapshot_command; /**< Command line to create 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 */ 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_enable_timeouts {true}; /**< Whether timeouts are enabled or not */
bool m_local_maxscale {false}; /**< MaxScale runs locally, specified using -l. */ bool m_local_maxscale {false}; /**< MaxScale runs locally, specified using -l. */

View File

@ -2,10 +2,10 @@
const TestDefinition test_definitions_arr[] = const TestDefinition test_definitions_arr[] =
{ {
@CNF_TEMPLATES@{nullptr, nullptr, nullptr} @TEST_DEFINITIONS@{nullptr, nullptr, nullptr}
}; };
const TestDefinition* test_definitions = test_definitions_arr; 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@"; const char* test_dir = "@CMAKE_CURRENT_SOURCE_DIR@";

View File

@ -253,7 +253,8 @@ TestConnections::TestConnections(int argc, char* argv[])
m_test_name = (optind < argc) ? argv[optind] : basename(argv[0]); m_test_name = (optind < argc) ? argv[optind] : basename(argv[0]);
set_template_and_labels(); 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(); set_mdbci_labels();
std::string delimiter = std::string (","); std::string delimiter = std::string (",");
@ -695,48 +696,40 @@ void TestConnections::set_template_and_labels()
} }
} }
string labels_string;
if (found) if (found)
{ {
labels_string = found->labels; m_cnf_template_path = found->config_template;
m_config_template = found->config_template; m_labels = found->labels;
} }
else else
{ {
printf("Failed to find configuration template for test '%s', using default template '%s'.\n", printf("Failed to find configuration template for test '%s', using default template '%s'.\n",
m_test_name.c_str(), default_template); 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 (m_labels.empty())
if (labels_pos != string::npos)
{ {
m_labels = labels_string.substr(labels_pos); m_labels = "REPL_BACKEND";
}
else
{
m_labels = "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; struct stat stb;
char str[4096]; char str[4096];
char template_file[1024]; string template_file = cnf_template_path;
char extended_template_file[1024]; char extended_template_file[1024];
sprintf(extended_template_file, "%s.%03d", cnf_template_path.c_str(), m);
sprintf(template_file, "%s/cnf/maxscale.cnf.template.%s", test_dir, template_name.c_str()); if (stat(extended_template_file, &stb) == 0)
sprintf(extended_template_file, "%s.%03d", template_file, m);
if (stat((char*)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) if (verbose)
{ {
tprintf("Executing '%s' command\n", str); tprintf("Executing '%s' command\n", str);
@ -826,7 +819,7 @@ void TestConnections::init_maxscales()
void TestConnections::init_maxscale(int m) 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])) if (maxscales->ssh_node_f(m, true, "test -d %s/certs", maxscales->access_homedir[m]))
{ {
tprintf("SSL certificates not found, copying to maxscale"); tprintf("SSL certificates not found, copying to maxscale");
@ -2154,7 +2147,7 @@ int TestConnections::revert_snapshot(char* snapshot_name)
return system(str); 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/"); process_template(m, config, "/tmp/");

View File

@ -1,78 +1,78 @@
# Default test timeout
set(TEST_TIMEOUT 3600)
# Helper function to add a configuration template # Adds linebreaks to curly brackets in a variable.
function(add_template name template labels) function(add_linebreaks source_var dest_var)
set(CNF_TEMPLATES "${CNF_TEMPLATES}{\"${name}\", \"${template}\", \"${labels}\"}," CACHE INTERNAL "") string(REPLACE }, },\n splitted "${${source_var}}")
set(${dest_var} ${splitted} PARENT_SCOPE)
endfunction() 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 # Helper function to add a configuration template
function(add_template_manual name 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() endfunction()
# Default test timeout
set(TIMEOUT 3600)
# This functions adds a source file as an executable, links that file against # 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 # the common test core and creates a test from it.
# source file, the second is the name of the executable and the test and the # Parameters:
# last parameter is the template suffix of the test. The template should follow # source Test source code file name
# the following naming policy: `maxscale.cnf.template.<template name>` and the # name Name of the generated test executable and the test itself
# file should be located in the /cnf/ directory. # template Configuration file template file name. Should only be the last part of the file name. The file
# # should be located in the /cnf/ directory and have prefix "maxscale.cnf.template.".
# labels Test labels. The labels can be given as "Label1;Label2;Label3..." or "Label1 Label2 Label3 ..."
# Example: to add simple_test.cpp with maxscale.cnf.template.simple_config to the # Example: to add simple_test.cpp with maxscale.cnf.template.simple_config to the
# test set, the function should be called as follows: # test set, the function should be called as follows:
# add_test_executable(simple_test.cpp simple_test simple_config LABELS some_label) # add_test_executable(simple_test.cpp simple_test simple_config LABELS some_label)
function(add_test_executable source name template) function(add_test_executable source name template labels)
add_template(${name} ${template} "${ARGV}") list(APPEND labels ${ARGN})
add_template(${name} ${template} "${labels}")
add_executable(${name} ${source}) add_executable(${name} ${source})
target_link_libraries(${name} maxtest) target_link_libraries(${name} maxtest)
add_test(NAME ${name} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${name} ${name} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_test(NAME ${name} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${name} ${name} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_test_properties(${name} ${labels})
list(REMOVE_AT ARGV 0 1 2 3)
foreach (label IN LISTS ARGV)
get_property(prev_labels TEST ${name} PROPERTY LABELS)
set_property(TEST ${name} PROPERTY LABELS ${label} ${prev_labels})
endforeach()
set_property(TEST ${name} PROPERTY TIMEOUT ${TIMEOUT})
endfunction() endfunction()
# Same as add_test_executable, but do not add executable into tests list # Same as add_test_executable, but do not add executable into tests list
function(add_test_executable_notest source name template) function(add_test_executable_notest source name template)
add_template(${name} ${template} "${ARGV}") add_template(${name} ${template} "${ARGN}")
add_executable(${name} ${source}) add_executable(${name} ${source})
target_link_libraries(${name} maxtest) target_link_libraries(${name} maxtest)
endfunction() endfunction()
# Add a test which uses another test as the executable # Add a test which uses another test as the executable
function(add_test_derived name executable template) function(add_test_derived name executable template labels)
add_template(${name} ${template} "${ARGV}") list(APPEND labels ${ARGN})
add_template(${name} ${template} "${labels}")
add_test(NAME ${name} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${executable} ${name} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_test(NAME ${name} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${executable} ${name} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set_property(TEST ${name} PROPERTY TIMEOUT ${TIMEOUT}) add_test_properties(${name} ${labels})
list(REMOVE_AT ARGV 0 1 2)
foreach (label IN LISTS ARGV)
get_property(prev_labels TEST ${name} PROPERTY LABELS)
set_property(TEST ${name} PROPERTY LABELS ${label} ${prev_labels})
endforeach()
endfunction() endfunction()
# This function adds a script as a test with the specified name and template. # This function adds a script as a test with the specified name and template.
# The naming of the templates follow the same principles as add_test_executable. # The naming of the templates follow the same principles as add_test_executable.
# also suitable for symlinks # also suitable for symlinks
function(add_test_script name script template labels) function(add_test_script name script template labels)
add_template(${name} ${template} "${ARGV}") list(APPEND labels ${ARGN})
add_template(${name} ${template} "${labels}")
add_test(NAME ${name} COMMAND non_native_setup ${name} ${script} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_test(NAME ${name} COMMAND non_native_setup ${name} ${script} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_test_properties(${name} ${labels})
list(REMOVE_AT ARGV 0 1 2)
foreach (label IN LISTS ARGV)
get_property(prev_labels TEST ${name} PROPERTY LABELS)
set_property(TEST ${name} PROPERTY LABELS ${label} ${prev_labels})
endforeach()
set_property(TEST ${name} PROPERTY TIMEOUT ${TIMEOUT})
endfunction() endfunction()
# Label a list of tests as heavy, long running tests # Label a list of tests as heavy, long running tests