From 5ecb68d0d6e8c0a849d468c6f3458e6b36e6f93f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Thu, 21 May 2020 19:26:19 +0200 Subject: [PATCH] Added temporal helper function to write timestamps in test --- test/tap/tap/utils.cpp | 33 +++++++++++++++++++++++++++++++++ test/tap/tap/utils.h | 2 ++ 2 files changed, 35 insertions(+) diff --git a/test/tap/tap/utils.cpp b/test/tap/tap/utils.cpp index 720203a7a..319994193 100644 --- a/test/tap/tap/utils.cpp +++ b/test/tap/tap/utils.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "tap.h" @@ -109,6 +110,38 @@ int get_server_version(MYSQL *mysql, std::string& version) { return 0; } +void proxy_info_(const char* msg, ...) { + va_list args; + va_start(args, msg); + + time_t __timer; + char __buffer[25]; + + // create the time info + struct tm *__tm_info; + time(&__timer); + __tm_info = localtime(&__timer); + strftime(__buffer, 25, "%Y-%m-%d %H:%M:%S", __tm_info); + + // format the message +#ifdef DEBUG + const char* debug_msg_fmt = " %s:%d:%s(): [INFO] "; +#else + const char* debug_msg_fmt = " [INFO]"; +#endif /* DEBUG */ + + std::size_t msg_len = strlen(msg); + char* str_buf = (char*)malloc(25 + strlen(debug_msg_fmt) + msg_len + 1); + strcpy(str_buf, __buffer); + strcat(str_buf, debug_msg_fmt); + strcat(str_buf, msg); + + vfprintf(stderr, str_buf, args); + + free(str_buf); + va_end(args); +} + int kill_child_proc(pid_t child_pid, const uint timeout_us, const uint it_sleep_us) { uint err = 0; uint waited = 0; diff --git a/test/tap/tap/utils.h b/test/tap/tap/utils.h index 92b2c362c..c6f707a63 100644 --- a/test/tap/tap/utils.h +++ b/test/tap/tap/utils.h @@ -28,6 +28,8 @@ int select_config_file(MYSQL* mysql, std::string& resultset); } #endif +void proxy_info_(const char* msg, ...); + /** * @brief Simple struct that holds the 'timeout options' for 'wexecvp'. */