summaryrefslogtreecommitdiff
path: root/mysql-test/include
diff options
context:
space:
mode:
authorJohn H. Embretsen <john.embretsen@oracle.com>2011-01-29 12:38:36 +0100
committerJohn H. Embretsen <john.embretsen@oracle.com>2011-01-29 12:38:36 +0100
commit26528be7112fadd5f23994f96174d3c45bd741b5 (patch)
tree56d651e7859dda13fef1541a41d00a960225d582 /mysql-test/include
parentd83706bc74a5a53e9f4472e6846a73aa0d1df2d1 (diff)
downloadmariadb-git-26528be7112fadd5f23994f96174d3c45bd741b5.tar.gz
Fix for Bug#56817 - mysqlhotcopy tests fail when DBI and DBD-mysql perl modules are not found
Third updated patch - this version also includes copyright notice in added Perl script. This patch implements a check for such modules at runtime. If modules are not found or unable to load, the test is skipped with the following message: [ skipped ] Test needs Perl modules DBI and DBD::mysql Checks are done via a helper Perl script which looks for the module in a runtime environment that is as similar to that of the mysqlhotcopy script as possible (thus not intended for Windows environments at this time). The helper script tells mysql-test about the result by writing information to a temporary file that is later read by mysql-test. See comments in added files (have_dbi_dbd-mysql.inc and checkDBI_DBD-mysql.pl) for details. The patch also removes the mysqlhotcopy tests from the list of disabled tests.
Diffstat (limited to 'mysql-test/include')
-rw-r--r--mysql-test/include/have_dbi_dbd-mysql.inc78
-rw-r--r--mysql-test/include/mysqlhotcopy.inc14
2 files changed, 92 insertions, 0 deletions
diff --git a/mysql-test/include/have_dbi_dbd-mysql.inc b/mysql-test/include/have_dbi_dbd-mysql.inc
new file mode 100644
index 00000000000..212e36ac353
--- /dev/null
+++ b/mysql-test/include/have_dbi_dbd-mysql.inc
@@ -0,0 +1,78 @@
+#
+# Originally created by John Embretsen, 2011-01-26.
+#
+# Checks for the existence of Perl modules DBI and DBD::mysql as seen from the
+# perl installation used by "external" executable perl scripts, i.e. scripts
+# that are executed as standalone scripts interpreted by the perl installation
+# specified by the "shebang" line in the top of these scripts.
+#
+# If either module is not found, the test will be skipped.
+#
+# For use in tests that call perl scripts that require these modules.
+#
+# This file is intended to work on Unix. Windows may need different treatment.
+# Reasoning:
+# - "shebangs" are not relevant on Windows, but need to be handled here.
+# - Perl scripts cannot be made executable on Windows, interpreter must be
+# specified.
+#
+# Note that if there are multiple perl installations and not all have the
+# required modules, this check may fail even if the perl in path does have
+# the modules available. This may happen if the perl specified by the script's
+# shebang (e.g. #!/usr/bin/perl) does not have these modules, and script is
+# called without specifying the perl interpreter. However, this will be
+# a correct result in cases where a test calls a script with a similar shebang.
+#
+################################################################################
+
+--source include/not_windows.inc
+
+# We jump through some hoops since there is no direct way to check if an
+# external command went OK or not from a mysql-test file:
+#
+# - In theory, we could do as simple as "exec perl -MDBI -MDBD::mysql -e 1",
+# however we cannot check the result (exit code) from within a test script.
+# Also, this may not yield the same result as other uses of perl due to the
+# shebang issue mentioned above.
+# - Instead we use a separate helper perl script that checks for the modules.
+# - If the modules are found, the perl script leaves a file which sets a
+# variable that can be read by this file.
+# If the modules are not found, the perl script does not set this variable,
+# but leaves an empty file instead.
+#
+# This is done because there is apparently no direct way to transfer
+# information from perl to the test script itself.
+
+--disable_query_log
+--disable_result_log
+--disable_warnings
+
+# We do not use embedded perl in this script because that would not have yielded
+# correct results for a situation where an external Perl script is called like
+# "scriptname" instead of "perl scriptname" and the shebang in the script points
+# to a specific perl that may be different than the perl in PATH.
+#
+# Instead, we call a separate helper script which checks for the modules in its
+# own environment. We call it without "perl" in front.
+
+--let $perlChecker= $MYSQLTEST_VARDIR/std_data/checkDBI_DBD-mysql.pl
+--let $resultFile= $MYSQL_TMP_DIR/dbidbd-mysql.txt
+
+# Make the script executable and execute it.
+--chmod 0755 $perlChecker
+--exec $perlChecker
+
+# Source the resulting temporary file and look for a variable being set.
+--source $resultFile
+
+if (!$dbidbd) {
+ --skip Test needs Perl modules DBI and DBD::mysql
+}
+
+# Clean up
+--remove_file $resultFile
+
+--enable_query_log
+--enable_result_log
+--enable_warnings
+
diff --git a/mysql-test/include/mysqlhotcopy.inc b/mysql-test/include/mysqlhotcopy.inc
index 91e0eff1e0f..110b0769ae1 100644
--- a/mysql-test/include/mysqlhotcopy.inc
+++ b/mysql-test/include/mysqlhotcopy.inc
@@ -4,12 +4,26 @@
--source include/not_windows.inc
--source include/not_embedded.inc
+--source include/have_dbi_dbd-mysql.inc
if (!$MYSQLHOTCOPY)
{
+ # Fail the test if the mysqlhotcopy script is missing.
+ # If the tool's location changes, mysql-test-run.pl must be updated to
+ # reflect this (look for "MYSQLHOTCOPY").
die due to missing mysqlhotcopy tool;
}
+# NOTE (johnemb, 2011-01-26):
+# In this test mysqlhotcopy (a perl script) is executed as a standalone
+# executable, i.e. not necessarily using the perl interpreter in PATH,
+# because that is how the documentation demonstrates it.
+#
+# We include have_dbi_dbd-mysql.inc above so that the test will
+# be skipped if Perl modules required by the mysqlhotcopy tool are not
+# found when the script is run this way.
+
+
let $MYSQLD_DATADIR= `SELECT @@datadir`;
--disable_warnings
DROP DATABASE IF EXISTS hotcopy_test;