From 6754586f76dfd167dc75a6af2cfa7f1c16819690 Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Fri, 27 Mar 2020 15:48:15 +0200 Subject: [PATCH] MXS-2900 Add possibility of having system test in any directory The cmake-function add_test_executable_ex() adds a test using a source file in the current directory. The config file is given as a relative path. --- maxscale-system-test/CMakeLists.txt | 3 +-- .../mariadbmonitor/CMakeLists.txt | 1 + .../mysqlmon_switchover.cnf} | 0 .../mysqlmon_switchover.cpp | 0 maxscale-system-test/utilities.cmake | 21 +++++++++++++++++++ 5 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 maxscale-system-test/mariadbmonitor/CMakeLists.txt rename maxscale-system-test/{cnf/maxscale.cnf.template.mysqlmon_switchover => mariadbmonitor/mysqlmon_switchover.cnf} (100%) rename maxscale-system-test/{ => mariadbmonitor}/mysqlmon_switchover.cpp (100%) diff --git a/maxscale-system-test/CMakeLists.txt b/maxscale-system-test/CMakeLists.txt index 9d0c0473e..370ff829d 100644 --- a/maxscale-system-test/CMakeLists.txt +++ b/maxscale-system-test/CMakeLists.txt @@ -229,8 +229,7 @@ add_test_executable(mysqlmon_failover_manual2.cpp mysqlmon_failover_manual2_4 my add_test_executable(mysqlmon_failover_manual2.cpp mysqlmon_failover_manual2_3 mysqlmon_failover_manual2_3 LABELS mysqlmon REPL_BACKEND) add_test_executable(mysqlmon_failover_manual2.cpp mysqlmon_failover_manual2_2 mysqlmon_failover_manual2_2 LABELS mysqlmon REPL_BACKEND) -# MySQL Monitor switchover -add_test_executable(mysqlmon_switchover.cpp mysqlmon_switchover mysqlmon_switchover LABELS mysqlmon REPL_BACKEND) +add_subdirectory(mariadbmonitor) # MySQL Monitor switchover with bad master add_test_executable(mysqlmon_switchover_bad_master.cpp mysqlmon_switchover_bad_master mysqlmon_switchover_bad_master LABELS mysqlmon REPL_BACKEND) diff --git a/maxscale-system-test/mariadbmonitor/CMakeLists.txt b/maxscale-system-test/mariadbmonitor/CMakeLists.txt new file mode 100644 index 000000000..304c702aa --- /dev/null +++ b/maxscale-system-test/mariadbmonitor/CMakeLists.txt @@ -0,0 +1 @@ +add_test_executable_ex(mysqlmon_switchover.cpp mysqlmon_switchover mysqlmon_switchover.cnf LABELS REPL_BACKEND) \ No newline at end of file diff --git a/maxscale-system-test/cnf/maxscale.cnf.template.mysqlmon_switchover b/maxscale-system-test/mariadbmonitor/mysqlmon_switchover.cnf similarity index 100% rename from maxscale-system-test/cnf/maxscale.cnf.template.mysqlmon_switchover rename to maxscale-system-test/mariadbmonitor/mysqlmon_switchover.cnf diff --git a/maxscale-system-test/mysqlmon_switchover.cpp b/maxscale-system-test/mariadbmonitor/mysqlmon_switchover.cpp similarity index 100% rename from maxscale-system-test/mysqlmon_switchover.cpp rename to maxscale-system-test/mariadbmonitor/mysqlmon_switchover.cpp diff --git a/maxscale-system-test/utilities.cmake b/maxscale-system-test/utilities.cmake index d38929921..f2cee6254 100644 --- a/maxscale-system-test/utilities.cmake +++ b/maxscale-system-test/utilities.cmake @@ -20,6 +20,16 @@ function(add_template_manual name template) add_template(${name} ${template} "CONFIG") endfunction() +# Helper function to add a configuration template +function(add_test_info name cnf_file_path labels) + if (NOT EXISTS ${cnf_file_path}) + message(FATAL_ERROR "Config file ${cnf_file_path} not found.") + endif() + + set(new_def "{\"${name}\", \"${cnf_file_path}\", \"${labels}\"}") + set(TEST_DEFINITIONS "${TEST_DEFINITIONS}${new_def}," CACHE INTERNAL "") +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}) @@ -75,6 +85,17 @@ function(add_test_script name script template labels) add_test_properties(${name} ${labels}) endfunction() +# Same as "add_test_executable" but with a local config template file. +function(add_test_executable_ex source name config_file labels) + list(APPEND labels ${ARGN}) + set(config_file_path "${CMAKE_CURRENT_SOURCE_DIR}/${config_file}") + add_test_info(${name} ${config_file_path} "${labels}") + add_executable(${name} ${source}) + target_link_libraries(${name} maxtest) + add_test(NAME ${name} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${name} ${name} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test_properties(${name} ${labels}) +endfunction() + # Label a list of tests as heavy, long running tests macro(heavy_weight_tests) foreach(name IN ITEMS ${ARGN})