summaryrefslogtreecommitdiffstats
path: root/plugin/handler_socket/regtest/common
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/handler_socket/regtest/common')
-rw-r--r--plugin/handler_socket/regtest/common/binary_my.cnf4
-rw-r--r--plugin/handler_socket/regtest/common/compat.sh29
-rw-r--r--plugin/handler_socket/regtest/common/hstest.pm66
3 files changed, 99 insertions, 0 deletions
diff --git a/plugin/handler_socket/regtest/common/binary_my.cnf b/plugin/handler_socket/regtest/common/binary_my.cnf
new file mode 100644
index 00000000..c3f7c02c
--- /dev/null
+++ b/plugin/handler_socket/regtest/common/binary_my.cnf
@@ -0,0 +1,4 @@
+
+[perl]
+default-character-set-name = binary
+
diff --git a/plugin/handler_socket/regtest/common/compat.sh b/plugin/handler_socket/regtest/common/compat.sh
new file mode 100644
index 00000000..7804bdf1
--- /dev/null
+++ b/plugin/handler_socket/regtest/common/compat.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+if [ "`uname -o`" = "Cygwin" ]; then
+ export DIFF='diff --ignore-space --strip-trailing-cr'
+elif [ "`uname`" = "Darwin" ]; then
+ export DIFF='diff'
+else
+ export DIFF='diff --ignore-space --strip-trailing-cr'
+fi
+
+compile_c() {
+ if [ "`uname -o`" = "Cygwin" ]; then
+ cl /W3 /I../.. /EHsc /FD /MD "$1" /link /DLL "/OUT:$2.dll" \
+ ../../libase.lib 2> cl.log
+ else
+ $CXX -I../.. -O3 -g -Wall -fPIC -shared "$1" -o "$2.so"
+ fi
+}
+
+compile_j() {
+ if [ "`uname -o`" = "Cygwin" ]; then
+ jdk="`echo /cygdrive/c/Program\ Files/Java/jdk* | head -1`"
+ else
+ jdk="$SUNJDK"
+ fi
+ "$jdk/bin/javac" -g "$1"/*.java
+ "$jdk/bin/jar" -cf "$1.jar" "$1"/*.class
+}
+
diff --git a/plugin/handler_socket/regtest/common/hstest.pm b/plugin/handler_socket/regtest/common/hstest.pm
new file mode 100644
index 00000000..89f273c9
--- /dev/null
+++ b/plugin/handler_socket/regtest/common/hstest.pm
@@ -0,0 +1,66 @@
+
+# vim:sw=2:ai
+
+package hstest;
+
+use DBI;
+use Net::HandlerSocket;
+
+our %conf = ();
+
+sub get_conf_env {
+ my ($key, $defval) = @_;
+ return $ENV{$key} || $defval;
+}
+
+sub init_conf {
+ $conf{host} = get_conf_env("MYHOST", "localhost");
+ $conf{myport} = get_conf_env("MYPORT", 3306);
+ $conf{dbname} = get_conf_env("MYDBNAME", "hstestdb");
+ $conf{ssps} = get_conf_env("MYSSPS");
+ $conf{user} = get_conf_env("MYSQLUSER", "root");
+ $conf{pass} = get_conf_env("MYSQLPASS", "");
+ $conf{hsport} = get_conf_env("HSPORT", 9998);
+ $conf{hspass} = get_conf_env("HSPASS", undef);
+}
+
+sub get_dbi_connection {
+ my ($dbname, $host, $myport, $ssps, $user, $pass)
+ = ($conf{dbname}, $conf{host}, $conf{myport}, $conf{ssps},
+ $conf{user}, $conf{pass});
+ my $mycnf = "binary_my.cnf";
+ my $dsn = "DBI:MariaDB:database=;host=$host;port=$myport"
+ . ";mariadb_server_prepare=$ssps"
+ . ";mariadb_read_default_group=perl"
+ . ";mariadb_read_default_file=../common/$mycnf";
+ my $dbh = DBI->connect($dsn, $user, $pass, { RaiseError => 1 });
+ return $dbh;
+}
+
+sub init_testdb {
+ my $charset = $_[0] || "binary";
+ my $dbh = get_dbi_connection();
+ my $dbname = $conf{dbname};
+ $dbh->do("drop database if exists $dbname");
+ $dbh->do("create database $dbname default character set $charset");
+ $dbh->do("use $dbname");
+ return $dbh;
+}
+
+sub get_hs_connection {
+ my ($host, $port) = @_;
+ $host ||= $conf{host};
+ $port ||= $conf{hsport};
+ my $hsargs = { 'host' => $host, 'port' => $port };
+ my $conn = new Net::HandlerSocket($hsargs);
+ if (defined($conn) && defined($conf{hspass})) {
+ $conn->auth($conf{hspass});
+ }
+ return $conn;
+}
+
+
+init_conf();
+
+1;
+