summaryrefslogtreecommitdiff
path: root/mysql-test/lib
diff options
context:
space:
mode:
Diffstat (limited to 'mysql-test/lib')
-rw-r--r--mysql-test/lib/My/SafeProcess.pm6
-rw-r--r--mysql-test/lib/My/SafeProcess/CMakeLists.txt10
-rw-r--r--mysql-test/lib/My/SafeProcess/wsrep_check_version.c123
3 files changed, 138 insertions, 1 deletions
diff --git a/mysql-test/lib/My/SafeProcess.pm b/mysql-test/lib/My/SafeProcess.pm
index 19f2893ea51..87054019759 100644
--- a/mysql-test/lib/My/SafeProcess.pm
+++ b/mysql-test/lib/My/SafeProcess.pm
@@ -100,6 +100,8 @@ else
$bindir = getcwd();
}
+our $wsrep_check_version;
+
# Find the safe process binary or script
sub find_bin {
if (IS_WIN32PERL or IS_CYGWIN)
@@ -119,6 +121,10 @@ sub find_bin {
"my_safe_process");
push(@safe_process_cmd, $exe);
}
+ # Wsrep version check utility:
+ $wsrep_check_version=
+ my_find_bin($bindir, ["lib/My/SafeProcess", "My/SafeProcess"],
+ "wsrep_check_version", NOT_REQUIRED);
}
diff --git a/mysql-test/lib/My/SafeProcess/CMakeLists.txt b/mysql-test/lib/My/SafeProcess/CMakeLists.txt
index a71f5d8ca36..4c3b62fa67e 100644
--- a/mysql-test/lib/My/SafeProcess/CMakeLists.txt
+++ b/mysql-test/lib/My/SafeProcess/CMakeLists.txt
@@ -14,7 +14,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA
- IF (WIN32)
+IF (WIN32)
ADD_EXECUTABLE(my_safe_process safe_process_win.cc)
ADD_EXECUTABLE(my_safe_kill safe_kill_win.cc)
TARGET_LINK_LIBRARIES(my_safe_kill dbghelp psapi)
@@ -22,6 +22,11 @@ ELSE()
ADD_EXECUTABLE(my_safe_process safe_process.cc)
ENDIF()
+IF(WITH_WSREP)
+ ADD_EXECUTABLE(wsrep_check_version wsrep_check_version.c)
+ TARGET_LINK_LIBRARIES(wsrep_check_version ${LIBDL})
+ENDIF()
+
IF(NOT INSTALL_MYSQLTESTDIR)
RETURN()
ENDIF()
@@ -32,6 +37,9 @@ SET(INSTALL_ARGS
)
INSTALL(TARGETS my_safe_process ${INSTALL_ARGS})
+IF(WITH_WSREP)
+ INSTALL(TARGETS wsrep_check_version ${INSTALL_ARGS})
+ENDIF()
IF (WIN32)
INSTALL(TARGETS my_safe_kill ${INSTALL_ARGS})
ENDIF()
diff --git a/mysql-test/lib/My/SafeProcess/wsrep_check_version.c b/mysql-test/lib/My/SafeProcess/wsrep_check_version.c
new file mode 100644
index 00000000000..616548d4f2d
--- /dev/null
+++ b/mysql-test/lib/My/SafeProcess/wsrep_check_version.c
@@ -0,0 +1,123 @@
+/* Copyright (c) 2009, 2019, MariaDB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef _WIN32
+#include <windows.h>
+#define dlsym(lib, name) GetProcAddress((HMODULE)lib, name)
+#define dlopen(libname, unused) LoadLibraryEx(libname, NULL, 0)
+#define dlclose(lib) FreeLibrary((HMODULE)lib)
+#elif defined(HAVE_DLFCN_H)
+#include <dlfcn.h>
+#else
+#define NO_DLL
+#endif
+
+#ifndef NO_DLL
+
+#include "../../../../wsrep-lib/wsrep-API/v26/wsrep_api.h"
+
+/**************************************************************************
+ * Library loader
+ **************************************************************************/
+
+static int wsrep_check_iface_version(const char *found, const char *iface_ver)
+{
+ if (strcmp(found, iface_ver)) {
+ return ERANGE;
+ }
+ return 0;
+}
+
+typedef int (*wsrep_loader_fun)(wsrep_t*);
+
+static wsrep_loader_fun wsrep_dlf(void *dlh, const char *sym)
+{
+ union {
+ wsrep_loader_fun dlfun;
+ void *obj;
+ } alias;
+ alias.obj = dlsym(dlh, sym);
+ return alias.dlfun;
+}
+
+static int wsrep_check_version_symbol(void *dlh)
+{
+ char** dlversion = NULL;
+ dlversion = (char**) dlsym(dlh, "wsrep_interface_version");
+ if (dlversion == NULL)
+ return EINVAL;
+ return wsrep_check_iface_version(*dlversion, WSREP_INTERFACE_VERSION);
+}
+
+static int wsrep_print_version(void *dlh)
+{
+ char** dlversion = NULL;
+ dlversion = (char**) dlsym(dlh, "wsrep_interface_version");
+ if (dlversion == NULL)
+ return EINVAL;
+ printf("found: %s, need: %s\n", *dlversion, WSREP_INTERFACE_VERSION);
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ int rc = EINVAL;
+ void *dlh;
+ wsrep_loader_fun dlfun;
+
+ if (!(dlh = dlopen(getenv("WSREP_PROVIDER"), RTLD_NOW | RTLD_LOCAL))) {
+ goto err;
+ }
+
+ if (!(dlfun = wsrep_dlf(dlh, "wsrep_loader"))) {
+ goto err;
+ }
+
+ if (argc < 2 || strcmp(argv[1], "-p")) {
+ rc = wsrep_check_version_symbol(dlh);
+ }
+ else {
+ rc = wsrep_print_version(dlh);
+ }
+
+err:
+ if (dlh) dlclose(dlh);
+
+ if (rc == 0)
+ return 0;
+ else if (rc == ERANGE)
+ return 2;
+ else
+ return 1;
+}
+
+#else
+
+int main(void)
+{
+ return 1;
+}
+
+#endif