From 02395102ed4590140828438fea4241ce83a0dc76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 28 Jun 2019 08:25:00 +0300 Subject: [PATCH] Add log message injection to tests By injecting messages into the maxscale.log from the test, the reader of the log can easily see the "synchronization" with the test case. This does affect the test timing so it can only be used to see whether non-timing related functionality is correct. --- maxscale-system-test/testconnections.cpp | 16 ++++++++++++++++ maxscale-system-test/testconnections.h | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/maxscale-system-test/testconnections.cpp b/maxscale-system-test/testconnections.cpp index 70380ae4f..18f71be0b 100644 --- a/maxscale-system-test/testconnections.cpp +++ b/maxscale-system-test/testconnections.cpp @@ -1885,6 +1885,22 @@ void TestConnections::tprintf(const char* format, ...) fflush(stderr); } +void TestConnections::log_printf(const char* format, ...) +{ + va_list argp; + va_start(argp, format); + int n = vsnprintf(nullptr, 0, format, argp); + va_end(argp); + + va_start(argp, format); + char buf[n + 1]; + vsnprintf(buf, sizeof(buf), format, argp); + va_end(argp); + + maxscales->ssh_node_f(0, true, "echo '--- %s ---' >> /var/log/maxscale/maxscale.log", buf); + tprintf("%s", buf); +} + int TestConnections::get_master_server_id(int m) { int master_id = -1; diff --git a/maxscale-system-test/testconnections.h b/maxscale-system-test/testconnections.h index 4157ef86f..694bb474c 100644 --- a/maxscale-system-test/testconnections.h +++ b/maxscale-system-test/testconnections.h @@ -505,6 +505,11 @@ public: */ void tprintf(const char* format, ...); + /** + * @brief injects a message into maxscale.log + */ + void log_printf(const char* format, ...) mxb_attribute((format(printf, 2, 3))); + /** * @brief Creats t1 table, insert data into it and checks if data can be correctly read from all Maxscale * services