1# 2# Test mysql_plugin tool 3# 4# This test contains test cases for testing the mysql_plugin client with 5# the daemon_example plugin. Test cases include tests for: 6# 7# - successful enable/disable 8# - incorrect paths 9# - missing paths/options 10# 11# Implementation Notes 12# 13# The mysql_plugin tool now accepts --mysqld the path to mysqld server. The 14# mysqld path is extracted from MYSQLD_BOOTSTRAP_CMD line. We also extract 15# the path of MYSQLD_BASEDIR (where mysql exists) and use it for the errmsg 16# file. The directories differ between Windows and Unix but the Perl script 17# included below will pick as per platform. 18# 19# The test is also designed to issue the --skip directive if the location of 20# the mysqld, my_print_defaults, or daemon_example.ini files cannot be found. 21# 22 23--source include/not_embedded.inc 24--source include/have_innodb_16k.inc 25 26call mtr.add_suppression('InnoDB: Resizing redo log'); 27call mtr.add_suppression('InnoDB: Starting to delete and rewrite log files'); 28call mtr.add_suppression('InnoDB: New log files created'); 29 30# Add the datadir, basedir, plugin_dir to the bootstrap command 31let $MYSQLD_DATADIR= `select @@datadir`; 32let $MYSQL_BASEDIR= `select @@basedir`; 33let $MYSQL_ERRMSG_BASEDIR=`select @@lc_messages_dir`; 34let $PLUGIN_DIR=`select @@plugin_dir`; 35 36--disable_abort_on_error 37 38# Perl script to extract the location of the basedir from environment 39# variables. This is needed to ensure the test will run on the PB machines 40# designed to test release as well as debug builds. It also checks for the 41# location of the my_print_defaults and daemon_example.ini files. 42 43perl; 44use File::Basename; 45 my ($mysqld)= split " ", $ENV{MYSQLD_BOOTSTRAP_CMD}; 46 my $mysqld_basedir=dirname($mysqld); 47 my $my_print_defaults= $ENV{MYSQL_MY_PRINT_DEFAULTS}; 48 my $my_print_defaults_basedir=dirname($my_print_defaults); 49 my $daemonexample_ini= "$ENV{DAEMONEXAMPLE_DIR}/daemon_example.ini"; 50 my $notfound= ""; 51 $daemonexample_ini =~ s,/plugin/debug/,/plugin/,; 52 open(FILE, ">", "$ENV{MYSQL_TMP_DIR}/mysqld.inc") or die; 53 print FILE "let \$MYSQLD_BASEDIR= $mysqld_basedir;\n"; 54 print FILE "let \$MYSQL_MY_PRINT_DEFAULTS_BASEDIR= $my_print_defaults_basedir;\n"; 55 if ((!-e $daemonexample_ini) || (!-r $daemonexample_ini)) 56 { 57 print FILE "let \$DAEMONEXAMPLE_DIR= $not_found;\n"; 58 } 59 else 60 { 61 print FILE "let \$MYSQL_PLUGIN_INI= $daemonexample_ini;\n"; 62 } 63 close FILE; 64EOF 65 66source $MYSQL_TMP_DIR/mysqld.inc; 67remove_file $MYSQL_TMP_DIR/mysqld.inc; 68 69# The mysql_plugin tool expects a directory structure like in the installed 70# mysql version, so errmsg.sys will be copied to "basedir/share", we create 71# and remove this structure. 72 73--mkdir $MYSQLD_BASEDIR/share 74--mkdir $MYSQLD_BASEDIR/share/mysql 75--copy_file $MYSQL_ERRMSG_BASEDIR/english/errmsg.sys $MYSQLD_BASEDIR/share/errmsg.sys 76--copy_file $MYSQL_ERRMSG_BASEDIR/english/errmsg.sys $MYSQLD_BASEDIR/share/mysql/errmsg.sys 77 78# The mysql_plugin tool now accepts --my-print-defaults which points to the 79# executable my_print_defaults.exe we can get this path from the variable 80# $MYSQL_MY_PRINT_DEFAULTS. 81 82# Check for my_print_defaults location. Skip if not found. 83if ($MYSQL_MY_PRINT_DEFAULTS_BASEDIR == '') 84{ 85 --skip Test requires known location of my_print_defaults executable. 86} 87 88# Check for mysqld location. Skip if not found. 89if ($MYSQLD == '') 90{ 91 --skip Test requires known location of mysqld executable. 92} 93 94# Check for daemon_example.ini location. Skip if not found in either 95# the plugin_dir path or the daemon_example_dir path. 96if ($DAEMONEXAMPLE_DIR == '') 97{ 98 --skip Test requires known location of daemon_example.ini file. 99} 100 101# Build client command for reuse. 102 103let $MYSQL_PLUGIN_CMD= $MYSQL_PLUGIN --datadir=$MYSQLD_DATADIR --basedir=$MYSQLD_BASEDIR --plugin-dir=$PLUGIN_DIR --mysqld=$MYSQLD_BASEDIR --my-print-defaults=$MYSQL_MY_PRINT_DEFAULTS_BASEDIR; 104 105--echo # 106--echo # Ensure the plugin isn't loaded. 107--echo # 108SELECT * FROM mysql.plugin WHERE dl like 'libdaemon%' ORDER BY name; 109 110--echo # 111--echo # Enable the plugin... 112--echo # 113 114--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect 115--shutdown_server 116--source include/wait_until_disconnected.inc 117 118# 119# Enable the plugin 120# 121--exec $MYSQL_PLUGIN_CMD --plugin-ini=$MYSQL_PLUGIN_INI ENABLE daemon_example 122 123 124# Ensure enabling an enabled plugin doesn't fail 125--exec $MYSQL_PLUGIN_CMD --plugin-ini=$MYSQL_PLUGIN_INI ENABLE daemon_example 126 127# 128# Restart the server 129# 130 131--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect 132--enable_reconnect 133--source include/wait_until_connected_again.inc 134 135--echo # 136--echo # Simulate loading a plugin libary with multiple entry points. 137--echo # This will test the DISABLE to ensure all rows are removed. 138--echo # 139--replace_regex /\.dll/.so/ 140eval INSERT INTO mysql.plugin VALUES ('wicky', '$DAEMONEXAMPLE'); 141--replace_regex /\.dll/.so/ 142eval INSERT INTO mysql.plugin VALUES ('wacky', '$DAEMONEXAMPLE'); 143--replace_regex /\.dll/.so/ 144eval INSERT INTO mysql.plugin VALUES ('wonky', '$DAEMONEXAMPLE'); 145 146--echo # 147--echo # Ensure the plugin is now loaded. 148--echo # 149--replace_regex /\.dll/.so/ 150SELECT * FROM mysql.plugin WHERE dl like 'libdaemon%' ORDER BY name; 151 152--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect 153--shutdown_server 154--source include/wait_until_disconnected.inc 155 156# 157# Disable the plugin - to remove winky, wonky entries 158# 159--exec $MYSQL_PLUGIN_CMD --plugin-ini=$MYSQL_PLUGIN_INI DISABLE daemon_example 160 161# 162# Enable the plugin again 163# 164--exec $MYSQL_PLUGIN_CMD --plugin-ini=$MYSQL_PLUGIN_INI ENABLE daemon_example 165 166# 167# Restart the server 168# 169--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect 170--enable_reconnect 171--source include/wait_until_connected_again.inc 172 173--echo # 174--echo # Ensure the plugin is loaded. 175--echo # 176--replace_regex /\.dll/.so/ 177SELECT * FROM mysql.plugin WHERE dl like '%libdaemon%' ORDER BY name; 178 179--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect 180--shutdown_server 181--source include/wait_until_disconnected.inc 182 183# To test the case where the same plugin is reloaded with a different soname, 184# we must copy the example daemon to a new location renaming it. 185 186let $DAEMON_RELOAD = lib$DAEMONEXAMPLE; 187--copy_file $PLUGIN_DIR/$DAEMONEXAMPLE $PLUGIN_DIR/$DAEMON_RELOAD 188--copy_file include/libdaemon_example.ini $PLUGIN_DIR/libdaemon_example.ini 189 190# Now reload it and see that it is a different name. 191--exec $MYSQL_PLUGIN_CMD ENABLE libdaemon_example 192 193# 194# Restart the server 195# 196--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect 197--enable_reconnect 198--source include/wait_until_connected_again.inc 199 200--echo # 201--echo # Ensure the plugin is replaced. 202--echo # 203--replace_regex /\.dll/.so/ 204SELECT * FROM mysql.plugin WHERE dl like '%libdaemon%' ORDER BY name; 205 206--echo # 207--echo # Disable the plugin... 208--echo # 209 210--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect 211--shutdown_server 212--source include/wait_until_disconnected.inc 213 214# 215# Disable the plugin 216# 217--exec $MYSQL_PLUGIN_CMD DISABLE libdaemon_example 218 219# Remove files for last test case. 220 221--remove_file $PLUGIN_DIR/$DAEMON_RELOAD 222--remove_file $DAEMONEXAMPLE_DIR/libdaemon_example.ini 223 224# 225# Restart the server 226# 227--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect 228--enable_reconnect 229--source include/wait_until_connected_again.inc 230 231--echo # 232--echo # Ensure the plugin isn't loaded. 233--echo # 234SELECT * FROM mysql.plugin WHERE dl like '%libdaemon%' ORDER BY name; 235 236# 237# Stop the server for error conditions 238# 239 240--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect 241--shutdown_server 242--source include/wait_until_disconnected.inc 243 244--echo # 245--echo # Attempt to load non-existant plugin 246--echo # 247--error 1,2,256 248--exec $MYSQL_PLUGIN_CMD DISABLE NOT_THERE_AT_ALL 2>&1 249 250--echo # 251--echo # Attempt to use non-existant plugin.ini file 252--echo # 253--error 1,2,7,256 254--exec $MYSQL_PLUGIN_CMD DISABLE daemon_example --plugin-ini=/NOT/THERE/pi.ini 2>&1 255 256--echo # 257--echo # Attempt to omit the plugin 258--echo # 259--error 1,2,256 260--exec $MYSQL_PLUGIN_CMD DISABLE 2>&1 261 262--echo # 263--echo # Attempt to omit DISABLE|ENABLE 264--echo # 265--error 1,2,256 266--exec $MYSQL_PLUGIN_CMD --plugin-ini=$MYSQL_PLUGIN_INI daemon_example 2>&1 267 268--echo # 269--echo # Attempt to use bad paths - datadir 270--echo # 271let $MYSQL_PLUGIN_CMD= $MYSQL_PLUGIN -n --datadir=/data_not_there/ --basedir=$MYSQL_BASEDIR --plugin-dir=$PLUGIN_DIR --mysqld=$MYSQLD_BASEDIR --my-print-defaults=$MYSQL_MY_PRINT_DEFAULTS_BASEDIR; 272--error 1,2,256 273--exec $MYSQL_PLUGIN_CMD --plugin-ini=$MYSQL_PLUGIN_INI DISABLE daemon_example 2>&1 274 275--echo # 276--echo # Attempt to use bad paths - basedir 277--echo # 278let $MYSQL_PLUGIN_CMD= $MYSQL_PLUGIN -n --datadir=$MYSQLD_DATADIR --basedir=/basedir_not_there/ --plugin-dir=$PLUGIN_DIR --mysqld=$MYSQLD_BASEDIR --my-print-defaults=$MYSQL_MY_PRINT_DEFAULTS_BASEDIR; 279replace_result "/basedir_not_there//" "/basedir_not_there/"; 280--error 1,2,256 281--exec $MYSQL_PLUGIN_CMD --plugin-ini=$MYSQL_PLUGIN_INI DISABLE daemon_example 2>&1 282 283--echo # 284--echo # Attempt to use bad paths - plugin_dir 285--echo # 286let $MYSQL_PLUGIN_CMD= $MYSQL_PLUGIN -n --datadir=$MYSQLD_DATADIR --basedir=$MYSQL_BASEDIR --plugin-dir=/plugin_not_there/ --mysqld=$MYSQLD_BASEDIR --my-print-defaults=$MYSQL_MY_PRINT_DEFAULTS_BASEDIR; 287--error 1,2,256 288--exec $MYSQL_PLUGIN_CMD --plugin-ini=$MYSQL_PLUGIN_INI DISABLE daemon_example 2>&1 289 290--echo # 291--echo # Attempt to use bad paths - mysqld 292--echo # 293let $MYSQL_PLUGIN_CMD= $MYSQL_PLUGIN -n --datadir=$MYSQLD_DATADIR --basedir=$MYSQL_BASEDIR --plugin-dir=$PLUGIN_DIR --mysqld=/mysqld_not_there/ --my-print-defaults=$MYSQL_MY_PRINT_DEFAULTS_BASEDIR; 294--error 1,2,256 295--exec $MYSQL_PLUGIN_CMD --plugin-ini=$MYSQL_PLUGIN_INI DISABLE daemon_example 2>&1 296 297--echo # 298--echo # Attempt to use bad paths - my_print_defaults 299--echo # 300let $MYSQL_PLUGIN_CMD= $MYSQL_PLUGIN -n --datadir=$MYSQLD_DATADIR --basedir=$MYSQL_BASEDIR --plugin-dir=$PLUGIN_DIR --mysqld=$MYSQLD_BASEDIR --my-print-defaults=/my_print_defaults_not_there/; 301--error 1,2,256 302--exec $MYSQL_PLUGIN_CMD --plugin-ini=$MYSQL_PLUGIN_INI DISABLE daemon_example 2>&1 303 304 305--echo # 306--echo # Missing library 307--echo # 308let $MYSQL_PLUGIN_CMD= $MYSQL_PLUGIN -n --datadir=$MYSQLD_DATADIR --basedir=$MYSQL_BASEDIR --plugin-dir=$PLUGIN_DIR --plugin-ini=$MYSQL_TEST_DIR/include/daemon_example_bad_soname.ini --mysqld=$MYSQLD_BASEDIR --my-print-defaults=$MYSQL_MY_PRINT_DEFAULTS_BASEDIR; 309--error 1,2,256 310--exec $MYSQL_PLUGIN_CMD DISABLE daemon_example 2>&1 311 312--echo # 313--echo # Bad format for config file 314--echo # 315let $MYSQL_PLUGIN_CMD= $MYSQL_PLUGIN -n --datadir=$MYSQLD_DATADIR --basedir=$MYSQL_BASEDIR --plugin-dir=$PLUGIN_DIR --plugin-ini=$MYSQL_TEST_DIR/include/daemon_example_bad_format.ini --mysqld=$MYSQLD_BASEDIR --my-print-defaults=$MYSQL_MY_PRINT_DEFAULTS_BASEDIR; 316--error 1,2,256 317--exec $MYSQL_PLUGIN_CMD DISABLE daemon_example 2>&1 318 319--echo # 320--echo # Missing base_dir option 321--echo # 322let $MYSQL_PLUGIN_CMD= $MYSQL_PLUGIN -n --datadir=$MYSQLD_DATADIR --plugin-dir=$PLUGIN_DIR --mysqld=$MYSQLD_BASEDIR --my-print-defaults=$MYSQL_MY_PRINT_DEFAULTS_BASEDIR; 323--error 1,2,139,256 324--exec $MYSQL_PLUGIN_CMD --plugin-ini=$MYSQL_PLUGIN_INI DISABLE daemon_example 2>&1 325 326--echo # 327--echo # Missing data_dir option 328--echo # 329let $MYSQL_PLUGIN_CMD= $MYSQL_PLUGIN -n --basedir=$MYSQL_BASEDIR --plugin-dir=$PLUGIN_DIR --mysqld=$MYSQLD_BASEDIR --my-print-defaults=$MYSQL_MY_PRINT_DEFAULTS_BASEDIR; 330--error 1,2,139,256 331--exec $MYSQL_PLUGIN_CMD --plugin-ini=$MYSQL_PLUGIN_INI DISABLE daemon_example 2>&1 332 333--echo # 334--echo # Missing plugin_dir option 335--echo # 336let $MYSQL_PLUGIN_CMD= $MYSQL_PLUGIN -n --datadir=$MYSQL_DATADIR --basedir=$MYSQL_BASEDIR --mysqld=$MYSQLD_BASEDIR --my-print-defaults=$MYSQL_MY_PRINT_DEFAULTS_BASEDIR; 337--error 1,2,139,256 338--exec $MYSQL_PLUGIN_CMD --plugin-ini=$MYSQL_PLUGIN_INI DISABLE daemon_example 2>&1 339 340--echo # 341--echo # Show the help. 342--echo # 343--replace_result $MYSQL_PLUGIN mysql_plugin $MYSQL_SERVER_VERSION XX.XX.XX 344--replace_regex /Ver [0-9.]+/Ver V.V.VV/ 345--exec $MYSQL_PLUGIN --help 346 347--replace_result $MYSQL_PLUGIN mysql_plugin $MYSQL_SERVER_VERSION XX.XX.XX 348--replace_regex /Ver [0-9.]+/Ver V.V.VV/ 349--exec $MYSQL_PLUGIN --version 350 351# 352# Restart the server 353# 354--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect 355--enable_reconnect 356--source include/wait_until_connected_again.inc 357 358# 359# Cleanup 360 361--remove_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect 362 363# Cleanup the share folder in the binary path. 364--remove_file $MYSQLD_BASEDIR/share/errmsg.sys 365--rmdir $MYSQLD_BASEDIR/share/mysql 366--rmdir $MYSQLD_BASEDIR/share 367 368--enable_abort_on_error 369