From d65d815b999d4d46afb77319128194f847e06c90 Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Wed, 12 Sep 2018 14:10:04 +0200 Subject: [PATCH] Add format attribute to test functions, fix resulting errors Fixes mysqlmon_failover_stress. --- maxscale-system-test/binary_ps_cursor.cpp | 4 ++-- maxscale-system-test/blob_test.cpp | 2 +- maxscale-system-test/bug601.cpp | 2 +- maxscale-system-test/mxs1713_lots_of_databases.cpp | 2 +- maxscale-system-test/mxs1804_long_ps_hang.cpp | 3 ++- maxscale-system-test/mxs922_bad_server.cpp | 2 +- maxscale-system-test/mxs922_restart.cpp | 2 +- maxscale-system-test/mysqlmon_failover_stress.cpp | 2 +- maxscale-system-test/open_close_connections.cpp | 6 +++--- maxscale-system-test/testconnections.h | 4 ++-- 10 files changed, 15 insertions(+), 14 deletions(-) diff --git a/maxscale-system-test/binary_ps_cursor.cpp b/maxscale-system-test/binary_ps_cursor.cpp index 306fe79b0..a3cc5d74f 100644 --- a/maxscale-system-test/binary_ps_cursor.cpp +++ b/maxscale-system-test/binary_ps_cursor.cpp @@ -115,7 +115,7 @@ void test2(TestConnections& test) test.add_result(strcmp(buffer1, buffer2) == 0, "Expected results to differ"); test.add_result(strcmp(buffer2, server_id) != 0, "Expected prepare 2 to go to the master (%s) but it's %s", - server_id[0], buffer2); + server_id, buffer2); } void test3(TestConnections& test) @@ -168,7 +168,7 @@ void test3(TestConnections& test) sprintf(server_id, "%d", test.repl->get_server_id(0)); test.add_result(strcmp(buffer, server_id) != 0, "Expected the execute inside a transaction to go to the master (%s) but it's %s", - server_id[0], buffer); + server_id, buffer); } int main(int argc, char** argv) diff --git a/maxscale-system-test/blob_test.cpp b/maxscale-system-test/blob_test.cpp index 6bb3f85a9..8bbb61173 100644 --- a/maxscale-system-test/blob_test.cpp +++ b/maxscale-system-test/blob_test.cpp @@ -175,7 +175,7 @@ int check_longblob_data(TestConnections* Test, MYSQL * conn, unsigned long chunk { if ((int)data[y] != y) { - Test->add_result(1, "expected %d, got %d", data[y], y); + Test->add_result(1, "expected %lu, got %d", data[y], y); break; } } diff --git a/maxscale-system-test/bug601.cpp b/maxscale-system-test/bug601.cpp index abe0f24e7..5db0fb789 100644 --- a/maxscale-system-test/bug601.cpp +++ b/maxscale-system-test/bug601.cpp @@ -82,7 +82,7 @@ int main(int argc, char *argv[]) { Test->set_timeout(15); Test->add_result(mysql_change_user(Test->maxscales->conn_rwsplit[0], "user", "pass2", (char *) "test"), - "change_user failed! %", mysql_error(Test->maxscales->conn_rwsplit[0])); + "change_user failed! %s", mysql_error(Test->maxscales->conn_rwsplit[0])); Test->add_result(mysql_change_user(Test->maxscales->conn_rwsplit[0], Test->maxscales->user_name, Test->maxscales->password, (char *) "test"), "change_user failed! %s", mysql_error(Test->maxscales->conn_rwsplit[0])); } diff --git a/maxscale-system-test/mxs1713_lots_of_databases.cpp b/maxscale-system-test/mxs1713_lots_of_databases.cpp index 45aefc729..b6db86fea 100644 --- a/maxscale-system-test/mxs1713_lots_of_databases.cpp +++ b/maxscale-system-test/mxs1713_lots_of_databases.cpp @@ -47,7 +47,7 @@ int main(int argc, char** argv) std::accumulate(errors.begin(), errors.end(), std::string(), [](const std::string &a, const std::string &b) { return a + b + " "; - })); + }).c_str()); test.tprintf("Dropping databases..."); for (auto db : db_list) diff --git a/maxscale-system-test/mxs1804_long_ps_hang.cpp b/maxscale-system-test/mxs1804_long_ps_hang.cpp index 70932e798..93ee83d14 100644 --- a/maxscale-system-test/mxs1804_long_ps_hang.cpp +++ b/maxscale-system-test/mxs1804_long_ps_hang.cpp @@ -33,7 +33,8 @@ int main(int argc, char** argv) test.maxscales->connect(); MYSQL_STMT* stmt = mysql_stmt_init(test.maxscales->conn_rwsplit[0]); - test.expect(mysql_stmt_prepare(stmt, sqlstr, strlen(sqlstr)) != 0, "Prepare should fail in 2.2 but not hang", + test.expect(mysql_stmt_prepare(stmt, sqlstr, strlen(sqlstr)) != 0, + "Prepare should fail in 2.2 but not hang. Error: %s", mysql_stmt_error(stmt)); mysql_stmt_close(stmt); diff --git a/maxscale-system-test/mxs922_bad_server.cpp b/maxscale-system-test/mxs922_bad_server.cpp index 066f49734..1aff35f94 100644 --- a/maxscale-system-test/mxs922_bad_server.cpp +++ b/maxscale-system-test/mxs922_bad_server.cpp @@ -59,7 +59,7 @@ void do_query(TestConnections *test, bool should_fail) "Query was successful when failure was expected." : "Query failed when success was expected."; - test->add_result(failed == should_fail, msg); + test->add_result(failed == should_fail, "%s", msg); test->maxscales->close_maxscale_connections(0); test->stop_timeout(); diff --git a/maxscale-system-test/mxs922_restart.cpp b/maxscale-system-test/mxs922_restart.cpp index 282f759ac..a7b72d397 100644 --- a/maxscale-system-test/mxs922_restart.cpp +++ b/maxscale-system-test/mxs922_restart.cpp @@ -38,7 +38,7 @@ void do_query(TestConnections *test, bool should_fail) "Query was successful when failure was expected." : "Query failed when success was expected."; - test->add_result(failed == should_fail, msg); + test->add_result(failed == should_fail, "%s", msg); test->maxscales->close_maxscale_connections(0); test->stop_timeout(); diff --git a/maxscale-system-test/mysqlmon_failover_stress.cpp b/maxscale-system-test/mysqlmon_failover_stress.cpp index e94537e47..a60441e94 100755 --- a/maxscale-system-test/mysqlmon_failover_stress.cpp +++ b/maxscale-system-test/mysqlmon_failover_stress.cpp @@ -552,7 +552,7 @@ void run(TestConnections& test) } else { - test.expect(false, "Unexpected master id: %d"); + test.expect(false, "Unexpected master id: %d", master_id); } } diff --git a/maxscale-system-test/open_close_connections.cpp b/maxscale-system-test/open_close_connections.cpp index ec7e9da75..cda09cda6 100644 --- a/maxscale-system-test/open_close_connections.cpp +++ b/maxscale-system-test/open_close_connections.cpp @@ -75,15 +75,15 @@ void *query_thread1( void *ptr ) { MYSQL *conn1 = data->Test->maxscales->open_rwsplit_connection(0); data->Test->add_result(mysql_errno(conn1), - "Error opening RWsplit conn, thread num is %d, iteration %d, error is: %s\n", + "Error opening RWsplit conn, thread num is %d, iteration %li, error is: %s\n", data->thread_id, data->i, mysql_error(conn1)); MYSQL *conn2 = data->Test->maxscales->open_readconn_master_connection(0); data->Test->add_result(mysql_errno(conn2), - "Error opening ReadConn master conn, thread num is %d, iteration %d, error is: %s\n", data->thread_id, + "Error opening ReadConn master conn, thread num is %d, iteration %li, error is: %s\n", data->thread_id, data->i, mysql_error(conn2)); MYSQL *conn3 = data->Test->maxscales->open_readconn_slave_connection(0); data->Test->add_result(mysql_errno(conn3), - "Error opening ReadConn master conn, thread num is %d, iteration %d, error is: %s\n", data->thread_id, + "Error opening ReadConn master conn, thread num is %d, iteration %li, error is: %s\n", data->thread_id, data->i, mysql_error(conn3)); // USE test here is a hack to prevent Maxscale from failure; should be removed when fixed if (conn1 != NULL) diff --git a/maxscale-system-test/testconnections.h b/maxscale-system-test/testconnections.h index 7d92a8b8d..7d66c5aa6 100644 --- a/maxscale-system-test/testconnections.h +++ b/maxscale-system-test/testconnections.h @@ -252,10 +252,10 @@ public: * @param result 0 if step PASSED * @param format ... message to pring if result is not 0 */ - void add_result(bool result, const char *format, ...); + void add_result(bool result, const char *format, ...) __attribute__((format(printf, 3, 4))); /** Same as add_result() but inverted */ - void expect(bool result, const char *format, ...); + void expect(bool result, const char *format, ...) __attribute__((format(printf, 3, 4))); /** * @brief ReadEnv Reads all Maxscale and Master/Slave and Galera setups info from environmental variables