diff options
author | unknown <greg@gcw.ath.cx> | 2003-07-23 01:35:24 -0400 |
---|---|---|
committer | unknown <greg@gcw.ath.cx> | 2003-07-23 01:35:24 -0400 |
commit | 970f1abbdb9a67936b66fc96a0c6fa1f0aa1535c (patch) | |
tree | f0605a3830336273f73d85077b78b068ef98833f | |
parent | c64dda59434c026071c09515a68d3c70c15dd648 (diff) | |
download | mariadb-git-970f1abbdb9a67936b66fc96a0c6fa1f0aa1535c.tar.gz |
mysql_test_run.c and associated files, with my initial changes and WAX's changes for Windows
netware/Makefile.am:
Replace tabs
netware/my_manage.c:
Various changes toward platform independence
netware/my_manage.h:
Various changes toward platform independence
netware/mysql_test_run.c:
Various changes toward platform independence
BitKeeper/etc/logging_ok:
Logging to logging@openlogging.org accepted
-rw-r--r-- | BitKeeper/etc/logging_ok | 1 | ||||
-rw-r--r-- | netware/Makefile.am | 56 | ||||
-rw-r--r-- | netware/my_manage.c | 768 | ||||
-rw-r--r-- | netware/my_manage.h | 34 | ||||
-rw-r--r-- | netware/mysql_test_run.c | 633 |
5 files changed, 939 insertions, 553 deletions
diff --git a/BitKeeper/etc/logging_ok b/BitKeeper/etc/logging_ok index 2f79988a274..952eb34b853 100644 --- a/BitKeeper/etc/logging_ok +++ b/BitKeeper/etc/logging_ok @@ -22,6 +22,7 @@ carsten@tsort.bitbybit.dk davida@isil.mysql.com gluh@gluh.(none) gluh@gluh.mysql.r18.ru +greg@gcw.ath.cx greg@mysql.com guilhem@mysql.com gweir@work.mysql.com diff --git a/netware/Makefile.am b/netware/Makefile.am index e4b9a14ecf0..5cc0e21f989 100644 --- a/netware/Makefile.am +++ b/netware/Makefile.am @@ -1,4 +1,4 @@ -# Copyright (c) 2002 Novell, Inc. All Rights Reserved. +# Copyright (c) 2002 Novell, Inc. All Rights Reserved. # # 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 @@ -11,37 +11,37 @@ # 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 +# along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -INCLUDES= -I$(srcdir)/../include -I../include -I.. -bin_PROGRAMS= mysqld_safe mysql_install_db mysql_test_run libmysql -mysqld_safe_SOURCES= mysqld_safe.c my_manage.c -mysql_install_db_SOURCES= mysql_install_db.c my_manage.c -mysql_test_run_SOURCES= mysql_test_run.c my_manage.c -libmysql_SOURCES= libmysqlmain.c -libmysql_LDADD= ../libmysql/.libs/libmysqlclient.a +INCLUDES= -I$(srcdir)/../include -I../include -I.. +bin_PROGRAMS= mysqld_safe mysql_install_db mysql_test_run libmysql +mysqld_safe_SOURCES= mysqld_safe.c my_manage.c +mysql_install_db_SOURCES= mysql_install_db.c my_manage.c +mysql_test_run_SOURCES= mysql_test_run.c my_manage.c +libmysql_SOURCES= libmysqlmain.c +libmysql_LDADD= ../libmysql/.libs/libmysqlclient.a -netware_build_files = client/mysql.def client/mysqladmin.def \ - client/mysqlbinlog.def client/mysqlcheck.def \ - client/mysqldump.def client/mysqlimport.def \ - client/mysqlshow.def client/mysqltest.def \ - extra/mysql_install.def extra/my_print_defaults.def \ - extra/perror.def extra/replace.def \ - extra/resolveip.def extra/comp_err.def \ - isam/isamchk.def \ - isam/isamlog.def isam/pack_isam.def \ - libmysqld/libmysqld.def myisam/myisamchk.def \ - myisam/myisamlog.def myisam/myisampack.def \ - sql/mysqld.def - +netware_build_files = client/mysql.def client/mysqladmin.def \ + client/mysqlbinlog.def client/mysqlcheck.def \ + client/mysqldump.def client/mysqlimport.def \ + client/mysqlshow.def client/mysqltest.def \ + extra/mysql_install.def extra/my_print_defaults.def \ + extra/perror.def extra/replace.def \ + extra/resolveip.def extra/comp_err.def \ + isam/isamchk.def \ + isam/isamlog.def isam/pack_isam.def \ + libmysqld/libmysqld.def myisam/myisamchk.def \ + myisam/myisamlog.def myisam/myisampack.def \ + sql/mysqld.def + link_sources: - set -x; \ - for f in $(netware_build_files); do \ - rm -f $(srcdir)/../$$f; \ - org=`echo $$f | sed -e 's/.*\/\(.*\)/\1/g'`; \ - @LN_CP_F@ $(srcdir)/$$org $(srcdir)/../$$f; \ - done; + set -x; \ + for f in $(netware_build_files); do \ + rm -f $(srcdir)/../$$f; \ + org=`echo $$f | sed -e 's/.*\/\(.*\)/\1/g'`; \ + @LN_CP_F@ $(srcdir)/$$org $(srcdir)/../$$f; \ + done; # Don't update the files from bitkeeper %::SCCS/s.% diff --git a/netware/my_manage.c b/netware/my_manage.c index 490438b0485..f5889766726 100644 --- a/netware/my_manage.c +++ b/netware/my_manage.c @@ -1,90 +1,104 @@ /* - Copyright (c) 2003 Novell, Inc. All Rights Reserved. + Copyright (c) 2003 MySQL AB + Copyright (c) 2003 Novell, Inc. - 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; either version 2 of the License, or - (at your option) any later version. + 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; either version 2 of the License, or + (at your option) any later version. - 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. + 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 + 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -#include <stdio.h> -#include <errno.h> -#include <dirent.h> -#include <string.h> -#include <screen.h> -#include <proc.h> -#include <ctype.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <assert.h> +*/ + +/***************************************************************************** +** Utility functions for support programs +*****************************************************************************/ + +/* MySQL library headers */ +#include <my_global.h> +#include <my_sys.h> +#include <my_dir.h> +#include <m_string.h> + +/* These 'should' be POSIX or ANSI */ +#include <assert.h> /* ASSERT */ +#include <stdarg.h> /* vsprintf, va_* */ +#include <sys/types.h> /* pid_t */ +#ifndef __WIN__ +#include <unistd.h> /* fork, rmdir, execve */ +#endif +#include <stdio.h> /* freopen */ +#include <stdlib.h> /* FILE */ +#ifndef __WIN__ +#include <dirent.h> /* opendir, readdir */ +#endif + +#if !defined(__NETWARE__) && !defined(__WIN__) +#include <sys/wait.h> +#endif + +#if !defined(__NETWARE__) +#include <signal.h> +#endif + +/* For ASSERT -- Not totally sure about this one: */ +#if !defined(ASSERT) +#define ASSERT(A) assert(A) +#endif #include "my_manage.h" - -/****************************************************************************** - - macros - -******************************************************************************/ - -/****************************************************************************** - - global variables - -******************************************************************************/ - +#define __STDC__ 1 +#include "process.h" /****************************************************************************** - functions - -******************************************************************************/ - -/****************************************************************************** + init_args() - init_args() - - Init an argument list. + Init an argument list. ******************************************************************************/ void init_args(arg_list_t *al) { +#ifndef __WIN__ ASSERT(al != NULL); - + al->argc = 0; al->size = ARG_BUF; - al->argv = malloc(al->size * sizeof(char *)); + al->argv = (char **)my_malloc(al->size * sizeof(char *), MYF(MY_WME)); ASSERT(al->argv != NULL); - +#else + win_args[0]= '\0'; + skip_first_param= TRUE; +#endif return; } /****************************************************************************** - add_arg() - - Add an argument to a list. + add_arg() + + Add an argument to a list. ******************************************************************************/ -void add_arg(arg_list_t *al, char *format, ...) +void add_arg(arg_list_t *al, const char *format, ...) { +#ifndef __WIN__ va_list ap; char temp[PATH_MAX]; ASSERT(al != NULL); - // increase size - if (al->argc >= al->size) + /* increase size */ + if (al->argc >= (int)al->size) { al->size += ARG_BUF; - al->argv = realloc(al->argv, al->size * sizeof(char *)); + al->argv = (char **)my_realloc((char *)al->argv, al->size * sizeof(char *), MYF(MY_WME)); ASSERT(al->argv != NULL); } @@ -94,7 +108,7 @@ void add_arg(arg_list_t *al, char *format, ...) vsprintf(temp, format, ap); va_end(ap); - al->argv[al->argc] = malloc(strlen(temp)+1); + al->argv[al->argc] = my_malloc(strlen(temp)+1, MYF(MY_WME)); ASSERT(al->argv[al->argc] != NULL); strcpy(al->argv[al->argc], temp); @@ -104,19 +118,36 @@ void add_arg(arg_list_t *al, char *format, ...) { al->argv[al->argc] = NULL; } +#else + va_list ap; + char param[PATH_MAX]; + if (!skip_first_param) + { + va_start(ap, format); + vsprintf(¶m, format, ap); + va_end(ap); + strcat(win_args," "); + strcat(win_args,param); + } + else + { + skip_first_param= FALSE; + } +#endif return; } /****************************************************************************** - free_args() - - Free an argument list. + free_args() + + Free an argument list. ******************************************************************************/ void free_args(arg_list_t *al) { +#ifndef __WIN__ int i; ASSERT(al != NULL); @@ -124,74 +155,110 @@ void free_args(arg_list_t *al) for(i = 0; i < al->argc; i++) { ASSERT(al->argv[i] != NULL); - free(al->argv[i]); + my_free(al->argv[i], MYF(MY_WME)); al->argv[i] = NULL; } - free(al->argv); + my_free((char *)al->argv, MYF(MY_WME)); al->argc = 0; al->argv = NULL; - +#endif return; } /****************************************************************************** - sleep_until_file_deleted() - - Sleep until the given file is no longer found. + sleep_until_file_deleted() + + Sleep until the given file is no longer found. ******************************************************************************/ int sleep_until_file_deleted(char *pid_file) { - struct stat buf; - int i, err; - - for(i = 0; (i < TRY_MAX) && (err = !stat(pid_file, &buf)); i++) sleep(1); - - if (err != 0) err = errno; - - return err; + MY_STAT stat_info; + int i, err = 0; +#ifndef __WIN__ + for(i = 0; i < TRY_MAX; i++) + { + if (my_stat(pid_file, &stat_info, MYF(0)) == (MY_STAT *) NULL) + { + err = errno; + break; + } + my_sleep(1); + } +#else + switch (pid_mode) + { + case MASTER_PID: + err= (WaitForSingleObject(master_server, TRY_MAX*1000) == WAIT_TIMEOUT); + pid_mode= 0; + break; + case SLAVE_PID: + err= (WaitForSingleObject(slave_server, TRY_MAX*1000) == WAIT_TIMEOUT); + pid_mode= 0; + break; + }; +#endif + return err; } /****************************************************************************** - sleep_until_file_exists() - - Sleep until the given file exists. + sleep_until_file_exists() + + Sleep until the given file exists. ******************************************************************************/ int sleep_until_file_exists(char *pid_file) { - struct stat buf; - int i, err; - - for(i = 0; (i < TRY_MAX) && (err = stat(pid_file, &buf)); i++) sleep(1); - - if (err != 0) err = errno; - - return err; + MY_STAT stat_info; + int i, err = 0; + +#ifndef __WIN__ + for(i = 0; i < TRY_MAX; i++) + { + if (my_stat(pid_file, &stat_info, MYF(0)) == (MY_STAT *) NULL) + { + err = errno; + break; + } + my_sleep(1); + } +#else + switch (pid_mode) + { + case MASTER_PID: + WaitForSingleObject(master_server, TRY_MAX*1000); + pid_mode= 0; + break; + case SLAVE_PID: + WaitForSingleObject(slave_server, TRY_MAX*1000); + pid_mode= 0; + break; + }; +#endif + + return err; } /****************************************************************************** - wait_for_server_start() - - Wait for the server on the given port to start. + wait_for_server_start() + + Wait for the server on the given port to start. ******************************************************************************/ int wait_for_server_start(char *bin_dir, char *user, char *password, int port) { arg_list_t al; - int err, i; - char mysqladmin_file[PATH_MAX]; + int err = 0, i; char trash[PATH_MAX]; - // mysqladmin file - snprintf(mysqladmin_file, PATH_MAX, "%s/mysqladmin", bin_dir); - snprintf(trash, PATH_MAX, "/tmp/trash.out"); - - // args + /* mysqladmin file */ + my_snprintf(trash, PATH_MAX, "/tmp/trash.out"); + + /* args */ init_args(&al); add_arg(&al, "%s", mysqladmin_file); add_arg(&al, "--no-defaults"); @@ -205,13 +272,13 @@ int wait_for_server_start(char *bin_dir, char *user, char *password, int port) add_arg(&al, "--host=localhost"); add_arg(&al, "ping"); - // NetWare does not support the connect timeout in the TCP/IP stack - // -- we will try the ping multiple times - for(i = 0; (i < TRY_MAX) - && (err = spawn(mysqladmin_file, &al, TRUE, NULL, - trash, NULL)); i++) sleep(1); - - // free args + /* NetWare does not support the connect timeout in the TCP/IP stack + -- we will try the ping multiple times */ + for(i = 0; (i < TRY_MAX) + && (err = spawn(mysqladmin_file, &al, TRUE, NULL, + trash, NULL, NOT_NEED_PID)); i++) sleep(1); + + /* free args */ free_args(&al); return err; @@ -219,20 +286,23 @@ int wait_for_server_start(char *bin_dir, char *user, char *password, int port) /****************************************************************************** - spawn() - - Spawn the given path with the given arguments. + spawn() + + Spawn the executable at the given path with the given arguments. ******************************************************************************/ + +#ifdef __NETWARE__ + int spawn(char *path, arg_list_t *al, int join, char *input, char *output, char *error) { - pid_t pid; + pid_t pid; int result = 0; wiring_t wiring = { FD_UNUSED, FD_UNUSED, FD_UNUSED }; unsigned long flags = PROC_CURRENT_SPACE | PROC_INHERIT_CWD; - // open wiring + /* open wiring */ if (input) wiring.infd = open(input, O_RDONLY); @@ -242,14 +312,14 @@ int spawn(char *path, arg_list_t *al, int join, char *input, if (error) wiring.errfd = open(error, O_WRONLY | O_CREAT | O_TRUNC); - // procve requires a NULL + /* procve requires a NULL */ add_arg(al, NULL); - // go + /* go */ pid = procve(path, flags, NULL, &wiring, NULL, NULL, 0, NULL, (const char **)al->argv); - if (pid == -1) + if (pid == -1) { result = -1; } @@ -257,8 +327,8 @@ int spawn(char *path, arg_list_t *al, int join, char *input, { waitpid(pid, &result, 0); } - - // close wiring + + /* close wiring */ if (wiring.infd != -1) close(wiring.infd); @@ -268,207 +338,411 @@ int spawn(char *path, arg_list_t *al, int join, char *input, if (wiring.errfd != -1) close(wiring.errfd); - return result; + return result; +} + +#else /* NOT __NETWARE__ */ + +#ifdef __WIN__ + +int my_vsnprintf_(char *to, size_t n, const char* value, ...) +{ + char *start=to, *end=to+n-1; + uint length, num_state, pre_zero; + reg2 char *par;// = value; + va_list args; + va_start(args,value); + + par = va_arg(args, char *); + while (par != NULL) + { + uint plen,left_len = (uint)(end-to)+1; + if (!par) par = (char*)"(null)"; + plen = (uint) strlen(par); + if (left_len <= plen) + plen = left_len - 1; + to=strnmov(to+strlen(to),par,plen); + par = va_arg(args, char *); + } + va_end(args); + DBUG_ASSERT(to <= end); + *to='\0'; + return (uint) (to - start); +} + +int spawn(char *path, arg_list_t *al, int join, char *input, + char *output, char *error) +{ + char *cl; + char *arg; + intptr_t result; + int j; + int err; + STARTUPINFO startup_info; + PROCESS_INFORMATION process_information; + ULONG dosretval; + int retval; + DWORD exit_code; + SECURITY_ATTRIBUTES process_attributes, thread_attributes; + char command_line[1024]= ""; + + + memset(&startup_info,0,sizeof(STARTUPINFO)); + startup_info.cb = sizeof(STARTUPINFO); + + if (input) + freopen(input, "rb", stdin); + + if (output) + freopen(output, "wb", stdout); + + if (error) + freopen(error, "wb", stderr); + + result= CreateProcess( + path, + &win_args, + NULL, + NULL, + TRUE, + 0, + NULL, + NULL, + &startup_info, + &process_information + ); + + if (process_information.hProcess) + { + if (join) + { + if (WaitForSingleObject(process_information.hProcess, mysqld_timeout) == WAIT_TIMEOUT) + { + exit_code= -1; + } + else + { + GetExitCodeProcess(process_information.hProcess, &exit_code); + } + CloseHandle(process_information.hProcess); + } + else + { + exit_code= 0; + } + if (run_server) + { + switch (pid_mode) + { + case MASTER_PID: + master_server= process_information.hProcess; + break; + case SLAVE_PID: + slave_server= process_information.hProcess; + break; + }; + pid_mode= 0; + run_server= FALSE; + }; + } + else + { + exit_code= -1; + } + if (input) + freopen("CONIN$","rb",stdin); + if (output) + freopen("CONOUT$","wb",stdout); + if (error) + freopen("CONOUT$","wb",stderr); + + return exit_code; } +#else /* NOT __NETWARE__, NOT __WIN__ */ + +/* This assumes full POSIX.1 compliance */ +int spawn(char *path, arg_list_t *al, int join, char *input, + char *output, char *error) +{ + int result = 0; + pid_t pid; + + if ((pid = fork())) + { + /* Remains in parent process */ + if (join && (pid != -1)) + waitpid(pid, &result, 0); + } + else + { + /* Child process */ + + /* Reassign streams */ + if (input) + freopen(input, "r", stdin); + + if (output) + freopen(output, "w", stdout); + + if (error) + freopen(error, "w", stderr); + + /* Spawn the process */ + execve(path, al->argv, environ); + } + + return result; +} + +#endif /* __WIN__ */ + +#endif /* __NETWARE__ */ + /****************************************************************************** - stop_server() - - Stop the server with the given port and pid file. + stop_server() + + Stop the server with the given port and pid file. ******************************************************************************/ int stop_server(char *bin_dir, char *user, char *password, int port, char *pid_file) { - arg_list_t al; - int err, i, argc = 0; - char mysqladmin_file[PATH_MAX]; + arg_list_t al; + int err; char trash[PATH_MAX]; - // mysqladmin file - snprintf(mysqladmin_file, PATH_MAX, "%s/mysqladmin", bin_dir); - snprintf(trash, PATH_MAX, "/tmp/trash.out"); - - // args + my_snprintf(trash, PATH_MAX, "/tmp/trash.out"); + + /* args */ init_args(&al); - add_arg(&al, "%s", mysqladmin_file); - add_arg(&al, "--no-defaults"); - add_arg(&al, "--port=%u", port); - add_arg(&al, "--user=%s", user); - add_arg(&al, "--password=%s", password); - add_arg(&al, "-O"); - add_arg(&al, "shutdown_timeout=20"); - add_arg(&al, "shutdown"); - - // spawn - if ((err = spawn(mysqladmin_file, &al, TRUE, NULL, - trash, NULL)) == 0) - { - sleep_until_file_deleted(pid_file); - } - else - { + add_arg(&al, "%s", mysqladmin_file); + add_arg(&al, "--no-defaults"); + add_arg(&al, "--port=%u", port); + add_arg(&al, "--user=%s", user); + add_arg(&al, "--password=%s", password); + add_arg(&al, "-O"); + add_arg(&al, "shutdown_timeout=20"); + add_arg(&al, "shutdown"); + + /* spawn */ + if ((err = spawn(mysqladmin_file, &al, TRUE, NULL, + trash, NULL)) == 0) + { + sleep_until_file_deleted(pid_file); + } + else + { pid_t pid = get_server_pid(pid_file); - - // shutdown failed - kill server - kill_server(pid); - - sleep(TRY_MAX); - // remove pid file if possible - err = remove(pid_file); + /* shutdown failed - kill server */ + kill_server(pid); + + sleep(TRY_MAX); + + /* remove pid file if possible */ + err = my_delete(pid_file, MYF(MY_WME)); } - // free args + /* free args */ free_args(&al); - return err; + return err; } /****************************************************************************** - get_server_pid() - - Get the VM id with the given pid file. + get_server_pid() + + Get the VM id with the given pid file. ******************************************************************************/ pid_t get_server_pid(char *pid_file) { - char buf[PATH_MAX]; - int fd, err; - char *p; - pid_t id; - - // discover id - fd = open(pid_file, O_RDONLY); - - err = read(fd, buf, PATH_MAX); - - close(fd); - - if (err > 0) - { - // terminate string - if ((p = strchr(buf, '\n')) != NULL) - { - *p = NULL; - - // check for a '\r' - if ((p = strchr(buf, '\r')) != NULL) - { - *p = NULL; - } - } - else - { - buf[err] = NULL; - } - - id = strtol(buf, NULL, 0); - } + char buf[PATH_MAX]; + int err; + File fd; + char *p; + pid_t id = 0; + + /* discover id */ + fd = my_open(pid_file, O_RDONLY, MYF(MY_WME)); + + err = my_read(fd, buf, PATH_MAX, MYF(MY_WME)); + + my_close(fd, MYF(MY_WME)); + + if (err > 0) + { + /* terminate string */ + if ((p = strchr(buf, '\n')) != NULL) + { + *p = '\0'; + + /* check for a '\r' */ + if ((p = strchr(buf, '\r')) != NULL) + { + *p = '\0'; + } + } + else + { + buf[err] = '\0'; + } + id = strtol(buf, NULL, 0); + } + return id; } - /****************************************************************************** - kill_server() - - Force a kill of the server with the given pid. + kill_server() + + Force a kill of the server with the given pid. ******************************************************************************/ void kill_server(pid_t pid) { if (pid > 0) { - // destroy vm + +#if !defined(__NETWARE__) + /* Send SIGTERM to pid */ + kill(pid, SIGTERM); +#else /* __NETWARE__ */ + /* destroy vm */ NXVmDestroy(pid); + +#endif + } } /****************************************************************************** - del_tree() - - Delete the directory and subdirectories. + del_tree() + + Delete the directory and subdirectories. ******************************************************************************/ void del_tree(char *dir) { - DIR *parent = opendir(dir); - DIR *entry; - char temp[PATH_MAX]; - - if (parent == NULL) - { - return; - } - - while((entry = readdir(parent)) != NULL) - { - // create long name - snprintf(temp, PATH_MAX, "%s/%s", dir, entry->d_name); - - if (entry->d_name[0] == '.') - { - // Skip - } - else if (S_ISDIR(entry->d_type)) - { - // delete subdirectory - del_tree(temp); - } - else - { - // remove file - remove(temp); - } - } - - // remove directory - rmdir(dir); + MY_DIR *current; + uint i; + char temp[PATH_MAX]; + + current = my_dir(dir, MYF(MY_WME | MY_WANT_STAT)); + + /* current is NULL if dir does not exist */ + if (current == NULL) + return; + + for (i = 0; i < current->number_off_files; i++) + { + /* create long name */ + my_snprintf(temp, PATH_MAX, "%s/%s", dir, current->dir_entry[i].name); + + if (current->dir_entry[i].name[0] == '.') + { + /* Skip */ + } + else if (MY_S_ISDIR(current->dir_entry[i].mystat.st_mode)) + { + /* delete subdirectory */ + del_tree(temp); + } + else + { + /* remove file */ + my_delete(temp, MYF(MY_WME)); + } + } + + my_dirend(current); + + /* remove directory */ + rmdir(dir); } /****************************************************************************** - removef() - + removef() + ******************************************************************************/ -int removef(char *format, ...) +int removef(const char *format, ...) { - va_list ap; + va_list ap; char path[PATH_MAX]; - - va_start(ap, format); - vsnprintf(path, PATH_MAX, format, ap); - - va_end(ap); + va_start(ap, format); + + my_vsnprintf(path, PATH_MAX, format, ap); - return remove(path); + va_end(ap); +#ifdef __WIN__ + { + MY_DIR *current; + uint i; + struct _finddata_t find; + char temp[PATH_MAX]; +#ifdef _WIN64 + __int64 handle; +#else + long handle; +#endif + char *p; + + p= strrchr(path,'\\'); + if (p == NULL) + { + p= strrchr(path,'/'); + if (p == NULL) + p= &path; + else + p++; + } + else + p++; + + if ((handle=_findfirst(path,&find)) == -1L) + return 0; + do + { + strcpy(p,find.name); + my_delete(path, MYF(MY_WME)); + } while (!_findnext(handle,&find)); + _findclose(handle); + } +#else + return my_delete(path, MYF(MY_WME)); +#endif } /****************************************************************************** - get_basedir() - + get_basedir() + ******************************************************************************/ void get_basedir(char *argv0, char *basedir) { - char temp[PATH_MAX]; - char *p; - - ASSERT(argv0 != NULL); + char temp[PATH_MAX]; + char *p; + + ASSERT(argv0 != NULL); ASSERT(basedir != NULL); - strcpy(temp, strlwr(argv0)); - while((p = strchr(temp, '\\')) != NULL) *p = '/'; - - if ((p = strindex(temp, "/bin/")) != NULL) - { - *p = NULL; - strcpy(basedir, temp); - } + strcpy(temp, argv0); +#ifndef __WIN__ + casedn_str(temp); +#endif + while((p = strchr(temp, '\\')) != NULL) *p = '/'; + + if ((p = strstr(temp, "/bin/")) != NullS) + { + *p = '\0'; + strcpy(basedir, temp); + } } diff --git a/netware/my_manage.h b/netware/my_manage.h index b19662c4ee9..4215ae59a25 100644 --- a/netware/my_manage.h +++ b/netware/my_manage.h @@ -26,17 +26,41 @@ ******************************************************************************/ #include <stdlib.h> +#ifndef __WIN__ #include <unistd.h> +#endif /****************************************************************************** macros ******************************************************************************/ +#ifdef __WIN__ +#define PATH_MAX _MAX_PATH +#define NAME_MAX _MAX_FNAME +#define kill(A,B) TerminateProcess((HANDLE)A,0) +#define NOT_NEED_PID 0 +#define MASTER_PID 1 +#define SLAVE_PID 2 +#define mysqld_timeout 60000 + +intptr_t master_server; +intptr_t slave_server; +int pid_mode; +bool run_server; +char win_args[1024]; +bool skip_first_param; +#endif + #define ARG_BUF 10 #define TRY_MAX 5 +#ifdef __NETWARE__ +#define strstr(A,B) strindex(A,B) +#endif + + /****************************************************************************** structures @@ -53,6 +77,8 @@ typedef struct } arg_list_t; + +typedef int pid_t; /****************************************************************************** global variables @@ -66,7 +92,7 @@ typedef struct ******************************************************************************/ void init_args(arg_list_t *); -void add_arg(arg_list_t *, char *, ...); +void add_arg(arg_list_t *, const char *, ...); void free_args(arg_list_t *); int sleep_until_file_exists(char *); @@ -80,8 +106,12 @@ pid_t get_server_pid(char *); void kill_server(pid_t pid); void del_tree(char *); -int removef(char *, ...); +int removef(const char *, ...); void get_basedir(char *, char *); +char mysqladmin_file[PATH_MAX]; + #endif /* _MY_MANAGE */ + + diff --git a/netware/mysql_test_run.c b/netware/mysql_test_run.c index 8bf0b7e0016..fb914c355e4 100644 --- a/netware/mysql_test_run.c +++ b/netware/mysql_test_run.c @@ -16,21 +16,29 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include <stdlib.h> + +/* MySQL library headers */ +#include <my_global.h> +#include <my_sys.h> +#include <my_dir.h> +#include <m_string.h> + +/* These 'should' be POSIX or ANSI */ #include <stdio.h> -#include <errno.h> -#include <dirent.h> -#include <string.h> +#include <stdarg.h> + +#ifdef __NETWARE__ #include <screen.h> -#include <nks/vm.h> -#include <ctype.h> -#include <sys/stat.h> -#include <unistd.h> -#include <fcntl.h> +#endif #include "my_config.h" #include "my_manage.h" +#ifdef __WIN__ +#include <Shlwapi.h> +#endif + + /****************************************************************************** macros @@ -42,16 +50,16 @@ #define NW_TEST_SUFFIX ".nw-test" #define NW_RESULT_SUFFIX ".nw-result" -#define TEST_SUFFIX ".test" -#define RESULT_SUFFIX ".result" -#define REJECT_SUFFIX ".reject" -#define OUT_SUFFIX ".out" -#define ERR_SUFFIX ".err" +#define TEST_SUFFIX ".test" +#define RESULT_SUFFIX ".result" +#define REJECT_SUFFIX ".reject" +#define OUT_SUFFIX ".out" +#define ERR_SUFFIX ".err" -#define TEST_PASS "[ pass ]" -#define TEST_SKIP "[ skip ]" -#define TEST_FAIL "[ fail ]" -#define TEST_BAD "[ bad ]" +#define TEST_PASS "[ pass ]" +#define TEST_SKIP "[ skip ]" +#define TEST_FAIL "[ fail ]" +#define TEST_BAD "[ bad ]" /****************************************************************************** @@ -59,7 +67,7 @@ ******************************************************************************/ -char base_dir[PATH_MAX] = "sys:/mysql"; +char base_dir[PATH_MAX] = "/mysql"; char db[PATH_MAX] = "test"; char user[PATH_MAX] = "root"; char password[PATH_MAX] = ""; @@ -67,7 +75,7 @@ char password[PATH_MAX] = ""; int master_port = 9306; int slave_port = 9307; -// comma delimited list of tests to skip or empty string +/* comma delimited list of tests to skip or empty string */ char skip_test[PATH_MAX] = ""; char bin_dir[PATH_MAX]; @@ -80,7 +88,6 @@ char slave_dir[PATH_MAX]; char lang_dir[PATH_MAX]; char char_dir[PATH_MAX]; -char mysqladmin_file[PATH_MAX]; char mysqld_file[PATH_MAX]; char mysqltest_file[PATH_MAX]; char master_pid[PATH_MAX]; @@ -109,17 +116,30 @@ int single_test = TRUE; int restarts = 0; FILE *log_fd = NULL; +// WAX +#include <my_getopt.h> + +const char* mysqld = "mysqld", *opt_exedir="client_debug"; + +static struct my_option my_long_options[] = +{ + {"mysqld", 'M', "Type of mysqld (without extention of file)- mysqld, mysql-nt, mysql-nt-max, mysqld-max.", + (gptr*) &mysqld, (gptr*) &mysqld, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"exefiledir", 'e', "Directory of .exe files (client_debug or client_release).", (gptr*) &opt_exedir, + (gptr*) &opt_exedir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, +}; + /****************************************************************************** functions - + ******************************************************************************/ /****************************************************************************** prototypes - + ******************************************************************************/ void report_stats(); @@ -135,17 +155,17 @@ void mysql_restart(); int read_option(char *, char *); void run_test(char *); void setup(char *); -void vlog(char *, va_list); -void log(char *, ...); -void log_info(char *, ...); -void log_error(char *, ...); -void log_errno(char *, ...); -void die(char *); +void vlog(const char *, va_list); +void mtr_log(const char *, ...); +void mtr_log_info(const char *, ...); +void mtr_log_error(const char *, ...); +void mtr_log_errno(const char *, ...); +void die(const char *); /****************************************************************************** report_stats() - + Report the gathered statistics. ******************************************************************************/ @@ -153,42 +173,42 @@ void report_stats() { if (total_fail == 0) { - log("\nAll %d test(s) were successful.\n", total_test); + mtr_log("\nAll %d test(s) were successful.\n", total_test); } else { double percent = ((double)total_pass / total_test) * 100; - - log("\nFailed %u/%u test(s), %.02f%% successful.\n", + + mtr_log("\nFailed %u/%u test(s), %.02f%% successful.\n", total_fail, total_test, percent); - log("\nThe .out and .err files in %s may give you some\n", result_dir); - log("hint of what when wrong.\n"); - log("\nIf you want to report this error, please first read the documentation\n"); - log("at: http://www.mysql.com/doc/M/y/MySQL_test_suite.html\n"); + mtr_log("\nThe .out and .err files in %s may give you some\n", result_dir); + mtr_log("hint of what when wrong.\n"); + mtr_log("\nIf you want to report this error, please first read the documentation\n"); + mtr_log("at: http://www.mysql.com/doc/M/y/MySQL_test_suite.html\n"); } - log("\n%.02f total minutes elapsed in the test cases\n\n", total_time / 60); + mtr_log("\n%.02f total minutes elapsed in the test cases\n\n", total_time / 60); } /****************************************************************************** install_db() - + Install the a database. ******************************************************************************/ void install_db(char *datadir) { arg_list_t al; - int err, i; + int err; char input[PATH_MAX]; char output[PATH_MAX]; char error[PATH_MAX]; // input file - snprintf(input, PATH_MAX, "%s/bin/init_db.sql", base_dir); - snprintf(output, PATH_MAX, "%s/install.out", datadir); - snprintf(error, PATH_MAX, "%s/install.err", datadir); + my_snprintf(input, PATH_MAX, "%s/bin/init_db.sql", base_dir); + my_snprintf(output, PATH_MAX, "%s/install.out", datadir); + my_snprintf(error, PATH_MAX, "%s/install.err", datadir); // args init_args(&al); @@ -201,6 +221,7 @@ void install_db(char *datadir) add_arg(&al, "--skip-bdb"); // spawn + if ((err = spawn(mysqld_file, &al, TRUE, input, output, error)) != 0) { die("Unable to create database."); @@ -221,34 +242,34 @@ void mysql_install_db() { char temp[PATH_MAX]; - // var directory - snprintf(temp, PATH_MAX, "%s/var", mysql_test_dir); + /* var directory */ + my_snprintf(temp, PATH_MAX, "%s/var", mysql_test_dir); - // clean up old direcotry + /* clean up old directory */ del_tree(temp); - // create var directory - mkdir(temp, S_IRWXU); - - // create subdirectories - snprintf(temp, PATH_MAX, "%s/var/run", mysql_test_dir); - mkdir(temp, S_IRWXU); - snprintf(temp, PATH_MAX, "%s/var/tmp", mysql_test_dir); - mkdir(temp, S_IRWXU); - snprintf(temp, PATH_MAX, "%s/var/master-data", mysql_test_dir); - mkdir(temp, S_IRWXU); - snprintf(temp, PATH_MAX, "%s/var/master-data/mysql", mysql_test_dir); - mkdir(temp, S_IRWXU); - snprintf(temp, PATH_MAX, "%s/var/master-data/test", mysql_test_dir); - mkdir(temp, S_IRWXU); - snprintf(temp, PATH_MAX, "%s/var/slave-data", mysql_test_dir); - mkdir(temp, S_IRWXU); - snprintf(temp, PATH_MAX, "%s/var/slave-data/mysql", mysql_test_dir); - mkdir(temp, S_IRWXU); - snprintf(temp, PATH_MAX, "%s/var/slave-data/test", mysql_test_dir); - mkdir(temp, S_IRWXU); - - // install databases + /* create var directory */ + my_mkdir(temp, 0700, MYF(MY_WME)); + + /* create subdirectories */ + my_snprintf(temp, PATH_MAX, "%s/var/run", mysql_test_dir); + my_mkdir(temp, 0700, MYF(MY_WME)); + my_snprintf(temp, PATH_MAX, "%s/var/tmp", mysql_test_dir); + my_mkdir(temp, 0700, MYF(MY_WME)); + my_snprintf(temp, PATH_MAX, "%s/var/master-data", mysql_test_dir); + my_mkdir(temp, 0700, MYF(MY_WME)); + my_snprintf(temp, PATH_MAX, "%s/var/master-data/mysql", mysql_test_dir); + my_mkdir(temp, 0700, MYF(MY_WME)); + my_snprintf(temp, PATH_MAX, "%s/var/master-data/test", mysql_test_dir); + my_mkdir(temp, 0700, MYF(MY_WME)); + my_snprintf(temp, PATH_MAX, "%s/var/slave-data", mysql_test_dir); + my_mkdir(temp, 0700, MYF(MY_WME)); + my_snprintf(temp, PATH_MAX, "%s/var/slave-data/mysql", mysql_test_dir); + my_mkdir(temp, 0700, MYF(MY_WME)); + my_snprintf(temp, PATH_MAX, "%s/var/slave-data/test", mysql_test_dir); + my_mkdir(temp, 0700, MYF(MY_WME)); + + /* install databases */ install_db(master_dir); install_db(slave_dir); } @@ -263,56 +284,35 @@ void mysql_install_db() void start_master() { arg_list_t al; - int err, i; + int err; char master_out[PATH_MAX]; char master_err[PATH_MAX]; - char temp[PATH_MAX]; - // remove old berkeley db log files that can confuse the server + /* remove old berkeley db log files that can confuse the server */ removef("%s/log.*", master_dir); - - // remove stale binary logs + + /* remove stale binary logs */ removef("%s/*-bin.*", master_dir); - // remove stale binary logs + /* remove stale binary logs */ removef("%s/*.index", master_dir); - // remove master.info file + /* remove master.info file */ removef("%s/master.info", master_dir); - // remove relay files + /* remove relay files */ removef("%s/var/log/*relay*", mysql_test_dir); - // remove relay-log.info file + /* remove relay-log.info file */ removef("%s/relay-log.info", master_dir); - // init script - if (master_init_script[0] != NULL) - { - // run_init_script(master_init_script); - - // TODO: use the scripts - if (strindex(master_init_script, "repair_part2-master.sh") != NULL) - { - FILE *fp; - - // create an empty index file - snprintf(temp, PATH_MAX, "%s/test/t1.MYI", master_dir); - fp = fopen(temp, "wb+"); - - fputs("1", fp); - - fclose(fp); - } - } - - // redirection files - snprintf(master_out, PATH_MAX, "%s/var/run/master%u.out", + /* redirection files */ + my_snprintf(master_out, PATH_MAX, "%s/var/run/master%u.out", mysql_test_dir, restarts); - snprintf(master_err, PATH_MAX, "%s/var/run/master%u.err", + my_snprintf(master_err, PATH_MAX, "%s/var/run/master%u.err", mysql_test_dir, restarts); - // args + /* args */ init_args(&al); add_arg(&al, "%s", mysqld_file); add_arg(&al, "--no-defaults"); @@ -328,11 +328,11 @@ void start_master() add_arg(&al, "--tmpdir=%s", mysql_tmp_dir); add_arg(&al, "--language=%s", lang_dir); - // $MASTER_40_ARGS + /* $MASTER_40_ARGS */ add_arg(&al, "--rpl-recovery-rank=1"); add_arg(&al, "--init-rpl-role=master"); - // $SMALL_SERVER + /* $SMALL_SERVER */ add_arg(&al, "-O"); add_arg(&al, "key_buffer_size=1M"); add_arg(&al, "-O"); @@ -340,8 +340,8 @@ void start_master() add_arg(&al, "-O"); add_arg(&al, "max_heap_table_size=1M"); - // $EXTRA_MASTER_OPT - if (master_opt[0] != NULL) + /* $EXTRA_MASTER_OPT */ + if (master_opt[0] != '\0') { char *p; @@ -350,34 +350,39 @@ void start_master() while(p) { add_arg(&al, "%s", p); - + p = (char *)strtok(NULL, " \t"); } } - // remove the pid file if it exists - remove(master_pid); + /* remove the pid file if it exists */ +#ifndef __WIN__ + my_delete(master_pid, MYF(MY_WME)); +#else + pid_mode= MASTER_PID; + run_server= TRUE; +#endif - // spawn + /* spawn */ if ((err = spawn(mysqld_file, &al, FALSE, NULL, master_out, master_err)) == 0) { sleep_until_file_exists(master_pid); - if ((err = wait_for_server_start(bin_dir, user, password, master_port)) == 0) + if ((err = wait_for_server_start(bin_dir, user, password, master_port)) == 0) { master_running = TRUE; } else { - log_error("The master server went down early."); + mtr_log_error("The master server went down early."); } } else { - log_error("Unable to start master server."); + mtr_log_error("Unable to start master server."); } - // free_args + /* free_args */ free_args(&al); } @@ -391,48 +396,48 @@ void start_master() void start_slave() { arg_list_t al; - int err, i; + int err; char slave_out[PATH_MAX]; char slave_err[PATH_MAX]; char temp[PATH_MAX]; - // skip? + /* skip? */ if (skip_slave) return; - // remove stale binary logs + /* remove stale binary logs */ removef("%s/*-bin.*", slave_dir); - // remove stale binary logs + /* remove stale binary logs */ removef("%s/*.index", slave_dir); - // remove master.info file + /* remove master.info file */ removef("%s/master.info", slave_dir); - // remove relay files + /* remove relay files */ removef("%s/var/log/*relay*", mysql_test_dir); - // remove relay-log.info file + /* remove relay-log.info file */ removef("%s/relay-log.info", slave_dir); - // init script - if (slave_init_script[0] != NULL) + /* init script */ + if (slave_init_script[0] != '\0') { - // run_init_script(slave_init_script); + /* run_init_script(slave_init_script); */ - // TODO: use the scripts - if (strindex(slave_init_script, "rpl000016-slave.sh") != NULL) + /* TODO: use the scripts */ + if (strstr(slave_init_script, "rpl000016-slave.sh") != NULL) { - // create empty master.info file - snprintf(temp, PATH_MAX, "%s/master.info", slave_dir); - close(open(temp, O_WRONLY | O_CREAT)); + /* create empty master.info file */ + my_snprintf(temp, PATH_MAX, "%s/master.info", slave_dir); + my_close(my_open(temp, O_WRONLY | O_CREAT, MYF(0)), MYF(0)); } - else if (strindex(slave_init_script, "rpl000017-slave.sh") != NULL) + else if (strstr(slave_init_script, "rpl000017-slave.sh") != NullS) { FILE *fp; - // create a master.info file - snprintf(temp, PATH_MAX, "%s/master.info", slave_dir); - fp = fopen(temp, "wb+"); + /* create a master.info file */ + my_snprintf(temp, PATH_MAX, "%s/master.info", slave_dir); + fp = my_fopen(temp, (int)(O_WRONLY | O_BINARY | O_CREAT), MYF(MY_WME)); fputs("master-bin.001\n", fp); fputs("4\n", fp); @@ -443,20 +448,20 @@ void start_slave() fputs("1\n", fp); fputs("0\n", fp); - fclose(fp); + my_fclose(fp, MYF(MY_WME)); } - else if (strindex(slave_init_script, "rpl_rotate_logs-slave.sh") != NULL) + else if (strstr(slave_init_script, "rpl_rotate_logs-slave.sh") != NullS) { - // create empty master.info file - snprintf(temp, PATH_MAX, "%s/master.info", slave_dir); - close(open(temp, O_WRONLY | O_CREAT)); + /* create empty master.info file */ + my_snprintf(temp, PATH_MAX, "%s/master.info", slave_dir); + my_close(my_open(temp, O_WRONLY | O_CREAT, MYF(0)), MYF(0)); } } - // redirection files - snprintf(slave_out, PATH_MAX, "%s/var/run/slave%u.out", + /* redirection files */ + my_snprintf(slave_out, PATH_MAX, "%s/var/run/slave%u.out", mysql_test_dir, restarts); - snprintf(slave_err, PATH_MAX, "%s/var/run/slave%u.err", + my_snprintf(slave_err, PATH_MAX, "%s/var/run/slave%u.err", mysql_test_dir, restarts); // args @@ -482,15 +487,15 @@ void start_slave() add_arg(&al, "--slave-load-tmpdir=../../var/tmp"); add_arg(&al, "--report-user=%s", user); - add_arg(&al, "--report-host=127.0.0.1"); + add_arg(&al, "--report-host=127.0.0.1"); add_arg(&al, "--report-port=%u", slave_port); add_arg(&al, "--master-retry-count=10"); add_arg(&al, "-O"); add_arg(&al, "slave_net_timeout=10"); - // slave master info - if (slave_master_info[0] != NULL) + /* slave master info */ + if (slave_master_info[0] != '\0') { char *p; @@ -514,7 +519,7 @@ void start_slave() add_arg(&al, "--rpl-recovery-rank=2"); } - // small server + /* small server */ add_arg(&al, "-O"); add_arg(&al, "key_buffer_size=1M"); add_arg(&al, "-O"); @@ -522,8 +527,8 @@ void start_slave() add_arg(&al, "-O"); add_arg(&al, "max_heap_table_size=1M"); - // opt args - if (slave_opt[0] != NULL) + /* opt args */ + if (slave_opt[0] != '\0') { char *p; @@ -536,9 +541,14 @@ void start_slave() p = (char *)strtok(NULL, " \t"); } } - - // remove the pid file if it exists - remove(slave_pid); + + /* remove the pid file if it exists */ +#ifndef __WIN__ + my_delete(slave_pid, MYF(MY_WME)); +#else + pid_mode= SLAVE_PID; + run_server= TRUE; +#endif // spawn if ((err = spawn(mysqld_file, &al, FALSE, NULL, slave_out, slave_err)) == 0) @@ -551,12 +561,12 @@ void start_slave() } else { - log_error("The slave server went down early."); + mtr_log_error("The slave server went down early."); } } else { - log_error("Unable to start slave server."); + mtr_log_error("Unable to start slave server."); } // free args @@ -576,8 +586,10 @@ void mysql_start() start_slave(); +#ifdef __NETWARE__ // activate the test screen ActivateScreen(getscreenhandle()); +#endif } /****************************************************************************** @@ -591,17 +603,20 @@ void stop_slave() { int err; - // running? + /* running? */ if (!slave_running) return; +#ifdef __WIN__ + pid_mode= SLAVE_PID; +#endif - // stop + /* stop */ if ((err = stop_server(bin_dir, user, password, slave_port, slave_pid)) == 0) { slave_running = FALSE; } else { - log_error("Unable to stop slave server."); + mtr_log_error("Unable to stop slave server."); } } @@ -616,16 +631,18 @@ void stop_master() { int err; - // running? + /* running? */ if (!master_running) return; - +#ifdef __WIN__ + pid_mode= MASTER_PID; +#endif if ((err = stop_server(bin_dir, user, password, master_port, master_pid)) == 0) { master_running = FALSE; } else { - log_error("Unable to stop master server."); + mtr_log_error("Unable to stop master server."); } } @@ -642,8 +659,10 @@ void mysql_stop() stop_slave(); +#ifdef __NETWARE__ // activate the test screen ActivateScreen(getscreenhandle()); +#endif } /****************************************************************************** @@ -655,7 +674,7 @@ void mysql_stop() ******************************************************************************/ void mysql_restart() { - log_info("Restarting the MySQL server(s): %u", ++restarts); + mtr_log_info("Restarting the MySQL server(s): %u", ++restarts); mysql_stop(); @@ -671,45 +690,50 @@ void mysql_restart() ******************************************************************************/ int read_option(char *opt_file, char *opt) { - int fd, err; - int result; + File fd; + int err; char *p; char buf[PATH_MAX]; - // copy current option + /* copy current option */ strncpy(buf, opt, PATH_MAX); - // open options file - fd = open(opt_file, O_RDONLY); +#ifdef __WIN__ + if (PathFileExistsA(opt_file)) + { +#endif + + /* open options file */ + fd = my_open(opt_file, O_RDONLY, MYF(MY_WME)); - err = read(fd, opt, PATH_MAX); + err = my_read(fd, opt, PATH_MAX, MYF(MY_WME)); - close(fd); + my_close(fd, MYF(MY_WME)); if (err > 0) { - // terminate string + /* terminate string */ if ((p = strchr(opt, '\n')) != NULL) { - *p = NULL; + *p = '\0'; - // check for a '\r' + /* check for a '\r' */ if ((p = strchr(opt, '\r')) != NULL) { - *p = NULL; + *p = '\0'; } } else { - opt[err] = NULL; + opt[err] = '\0'; } - // check for $MYSQL_TEST_DIR - if ((p = strstr(opt, "$MYSQL_TEST_DIR")) != NULL) + /* check for $MYSQL_TEST_DIR */ + if ((p = strstr(opt, "$MYSQL_TEST_DIR")) != NullS) { char temp[PATH_MAX]; - *p = NULL; + *p = '\0'; strcpy(temp, p + strlen("$MYSQL_TEST_DIR")); @@ -720,11 +744,14 @@ int read_option(char *opt_file, char *opt) } else { - // clear option - *opt = NULL; + /* clear option */ + *opt = '\0'; } +#ifdef __WIN__ + } +#endif - // compare current option with previous + /* compare current option with previous */ return strcmp(opt, buf); } @@ -739,21 +766,20 @@ void run_test(char *test) { char temp[PATH_MAX]; char *rstr; - double elapsed = 0; int skip = FALSE; int restart = FALSE; int flag = FALSE; struct stat info; - - // single test? + + /* single test? */ if (!single_test) { // skip tests in the skip list - snprintf(temp, PATH_MAX, " %s ", test); - skip = (strindex(skip_test, temp) != NULL); + my_snprintf(temp, PATH_MAX, " %s ", test); + skip = strinstr(skip_test, temp); } - // skip test? + /* skip test? */ if (!skip) { char test_file[PATH_MAX]; @@ -766,7 +792,6 @@ void run_test(char *test) char err_file[PATH_MAX]; int err; arg_list_t al; - NXTime_t start, stop; // skip slave? flag = skip_slave; @@ -774,36 +799,36 @@ void run_test(char *test) if (flag != skip_slave) restart = TRUE; // create files - snprintf(master_opt_file, PATH_MAX, "%s/%s-master.opt", test_dir, test); - snprintf(slave_opt_file, PATH_MAX, "%s/%s-slave.opt", test_dir, test); - snprintf(slave_master_info_file, PATH_MAX, "%s/%s.slave-mi", test_dir, test); - snprintf(reject_file, PATH_MAX, "%s/%s%s", result_dir, test, REJECT_SUFFIX); - snprintf(out_file, PATH_MAX, "%s/%s%s", result_dir, test, OUT_SUFFIX); - snprintf(err_file, PATH_MAX, "%s/%s%s", result_dir, test, ERR_SUFFIX); + my_snprintf(master_opt_file, PATH_MAX, "%s/%s-master.opt", test_dir, test); + my_snprintf(slave_opt_file, PATH_MAX, "%s/%s-slave.opt", test_dir, test); + my_snprintf(slave_master_info_file, PATH_MAX, "%s/%s.slave-mi", test_dir, test); + my_snprintf(reject_file, PATH_MAX, "%s/%s%s", result_dir, test, REJECT_SUFFIX); + my_snprintf(out_file, PATH_MAX, "%s/%s%s", result_dir, test, OUT_SUFFIX); + my_snprintf(err_file, PATH_MAX, "%s/%s%s", result_dir, test, ERR_SUFFIX); // netware specific files - snprintf(test_file, PATH_MAX, "%s/%s%s", test_dir, test, NW_TEST_SUFFIX); + my_snprintf(test_file, PATH_MAX, "%s/%s%s", test_dir, test, NW_TEST_SUFFIX); if (stat(test_file, &info)) { - snprintf(test_file, PATH_MAX, "%s/%s%s", test_dir, test, TEST_SUFFIX); + my_snprintf(test_file, PATH_MAX, "%s/%s%s", test_dir, test, TEST_SUFFIX); } - snprintf(result_file, PATH_MAX, "%s/%s%s", result_dir, test, NW_RESULT_SUFFIX); + my_snprintf(result_file, PATH_MAX, "%s/%s%s", result_dir, test, NW_RESULT_SUFFIX); if (stat(result_file, &info)) { - snprintf(result_file, PATH_MAX, "%s/%s%s", result_dir, test, RESULT_SUFFIX); + my_snprintf(result_file, PATH_MAX, "%s/%s%s", result_dir, test, RESULT_SUFFIX); } // init scripts - snprintf(master_init_script, PATH_MAX, "%s/%s-master.sh", test_dir, test); + my_snprintf(master_init_script, PATH_MAX, "%s/%s-master.sh", test_dir, test); if (stat(master_init_script, &info)) - master_init_script[0] = NULL; + master_init_script[0] = '\0'; else restart = TRUE; - snprintf(slave_init_script, PATH_MAX, "%s/%s-slave.sh", test_dir, test); + my_snprintf(slave_init_script, PATH_MAX, "%s/%s-slave.sh", test_dir, test); if (stat(slave_init_script, &info)) - slave_init_script[0] = NULL; + slave_init_script[0] = '\0'; else restart = TRUE; @@ -825,7 +850,7 @@ void run_test(char *test) sleep(1); // show test - log("%-46s ", test); + mtr_log("%-46s ", test); // args init_args(&al); @@ -842,26 +867,16 @@ void run_test(char *test) add_arg(&al, "-R"); add_arg(&al, "%s", result_file); - // start timer - NXGetTime(NX_SINCE_BOOT, NX_USECONDS, &start); - // spawn err = spawn(mysqltest_file, &al, TRUE, test_file, out_file, err_file); - - // stop timer - NXGetTime(NX_SINCE_BOOT, NX_USECONDS, &stop); - - // calculate - elapsed = ((double)(stop - start)) / NX_USECONDS; - total_time += elapsed; - + // free args free_args(&al); if (err == 0) { // pass - rstr = TEST_PASS; + rstr = (char *)TEST_PASS; ++total_pass; // increment total @@ -870,13 +885,13 @@ void run_test(char *test) else if (err == 2) { // skip - rstr = TEST_SKIP; + rstr = (char *)TEST_SKIP; ++total_skip; } else if (err == 1) { // fail - rstr = TEST_FAIL; + rstr = (char *)TEST_FAIL; ++total_fail; // increment total @@ -884,21 +899,21 @@ void run_test(char *test) } else { - rstr = TEST_BAD; + rstr = (char *)TEST_BAD; } } else // early skips { // show test - log("%-46s ", test); + mtr_log("%-46s ", test); // skip - rstr = TEST_SKIP; + rstr = (char *)TEST_SKIP; ++total_skip; } // result - log("%10.06f %-14s\n", elapsed, rstr); + mtr_log(" %-14s\n", rstr); } /****************************************************************************** @@ -908,7 +923,7 @@ void run_test(char *test) Log the message. ******************************************************************************/ -void vlog(char *format, va_list ap) +void vlog(const char *format, va_list ap) { vfprintf(stdout, format, ap); fflush(stdout); @@ -922,12 +937,12 @@ void vlog(char *format, va_list ap) /****************************************************************************** - log() + mtr_log() Log the message. ******************************************************************************/ -void log(char *format, ...) +void mtr_log(const char *format, ...) { va_list ap; @@ -940,60 +955,60 @@ void log(char *format, ...) /****************************************************************************** - log_info() + mtr_log_info() Log the given information. ******************************************************************************/ -void log_info(char *format, ...) +void mtr_log_info(const char *format, ...) { va_list ap; va_start(ap, format); - log("-- INFO : "); + mtr_log("-- INFO : "); vlog(format, ap); - log("\n"); + mtr_log("\n"); va_end(ap); } /****************************************************************************** - log_error() + mtr_log_error() Log the given error. ******************************************************************************/ -void log_error(char *format, ...) +void mtr_log_error(const char *format, ...) { va_list ap; va_start(ap, format); - log("-- ERROR: "); + mtr_log("-- ERROR: "); vlog(format, ap); - log("\n"); + mtr_log("\n"); va_end(ap); } /****************************************************************************** - log_errno() + mtr_log_errno() Log the given error and errno. ******************************************************************************/ -void log_errno(char *format, ...) +void mtr_log_errno(const char *format, ...) { va_list ap; va_start(ap, format); - log("-- ERROR: (%003u) ", errno); + mtr_log("-- ERROR: (%003u) ", errno); vlog(format, ap); - log("\n"); + mtr_log("\n"); va_end(ap); } @@ -1005,11 +1020,13 @@ void log_errno(char *format, ...) Exit the application. ******************************************************************************/ -void die(char *msg) +void die(const char *msg) { - log_error(msg); + mtr_log_error(msg); +#ifdef __NETWARE__ pressanykey(); +#endif exit(-1); } @@ -1027,50 +1044,83 @@ void setup(char *file) char *p; // set the timezone for the timestamp test +#ifdef __WIN__ + _putenv( "TZ=GMT-3" ); +#else setenv("TZ", "GMT-3", TRUE); +#endif // find base dir - strcpy(temp, strlwr(file)); + strcpy(temp, file); +#ifndef __WIN__ + casedn_str(temp); +#endif while((p = strchr(temp, '\\')) != NULL) *p = '/'; - if ((p = strindex(temp, "/mysql-test/")) != NULL) + if ((p = strstr(temp, "/mysql-test/"))) { - *p = NULL; - strcpy(base_dir, temp); + *p = '\0'; + strcpy(base_dir, (const char *)temp); } // setup paths - snprintf(bin_dir, PATH_MAX, "%s/bin", base_dir); - snprintf(mysql_test_dir, PATH_MAX, "%s/mysql-test", base_dir); - snprintf(test_dir, PATH_MAX, "%s/t", mysql_test_dir); - snprintf(mysql_tmp_dir, PATH_MAX, "%s/var/tmp", mysql_test_dir); - snprintf(result_dir, PATH_MAX, "%s/r", mysql_test_dir); - snprintf(master_dir, PATH_MAX, "%s/var/master-data", mysql_test_dir); - snprintf(slave_dir, PATH_MAX, "%s/var/slave-data", mysql_test_dir); - snprintf(lang_dir, PATH_MAX, "%s/share/english", base_dir); - snprintf(char_dir, PATH_MAX, "%s/share/charsets", base_dir); +#ifdef __WIN__ + my_snprintf(bin_dir, PATH_MAX, "%s/%s", base_dir,opt_exedir); +#else + my_snprintf(bin_dir, PATH_MAX, "%s/bin", base_dir); +#endif + my_snprintf(mysql_test_dir, PATH_MAX, "%s/mysql-test", base_dir); + my_snprintf(test_dir, PATH_MAX, "%s/t", mysql_test_dir); + my_snprintf(mysql_tmp_dir, PATH_MAX, "%s/var/tmp", mysql_test_dir); + my_snprintf(result_dir, PATH_MAX, "%s/r", mysql_test_dir); + my_snprintf(master_dir, PATH_MAX, "%s/var/master-data", mysql_test_dir); + my_snprintf(slave_dir, PATH_MAX, "%s/var/slave-data", mysql_test_dir); + my_snprintf(lang_dir, PATH_MAX, "%s/share/english", base_dir); + my_snprintf(char_dir, PATH_MAX, "%s/share/charsets", base_dir); // setup files - snprintf(mysqld_file, PATH_MAX, "%s/mysqld", bin_dir); - snprintf(mysqltest_file, PATH_MAX, "%s/mysqltest", bin_dir); - snprintf(mysqladmin_file, PATH_MAX, "%s/mysqladmin", bin_dir); - snprintf(master_pid, PATH_MAX, "%s/var/run/master.pid", mysql_test_dir); - snprintf(slave_pid, PATH_MAX, "%s/var/run/slave.pid", mysql_test_dir); +#ifdef __WIN__ + my_snprintf(mysqld_file, PATH_MAX, "%s/%s.exe", bin_dir, mysqld); + my_snprintf(mysqltest_file, PATH_MAX, "%s/mysqltest.exe", bin_dir); + my_snprintf(mysqladmin_file, PATH_MAX, "%s/mysqladmin.exe", bin_dir); + pid_mode= NOT_NEED_PID; +#else + my_snprintf(mysqld_file, PATH_MAX, "%s/mysqld", bin_dir); + my_snprintf(mysqltest_file, PATH_MAX, "%s/mysqltest", bin_dir); + my_snprintf(mysqladmin_file, PATH_MAX, "%s/mysqladmin", bin_dir); +#endif + my_snprintf(master_pid, PATH_MAX, "%s/var/run/master.pid", mysql_test_dir); + my_snprintf(slave_pid, PATH_MAX, "%s/var/run/slave.pid", mysql_test_dir); // create log file - snprintf(temp, PATH_MAX, "%s/mysql-test-run.log", mysql_test_dir); + my_snprintf(temp, PATH_MAX, "%s/mysql-test-run.log", mysql_test_dir); if ((log_fd = fopen(temp, "w+")) == NULL) { - log_errno("Unable to create log file."); + mtr_log_errno("Unable to create log file."); } // prepare skip test list while((p = strchr(skip_test, ',')) != NULL) *p = ' '; - strcpy(temp, strlwr(skip_test)); - snprintf(skip_test, PATH_MAX, " %s ", temp); + strcpy(temp, skip_test); +#ifndef __WIN__ + casedn_str(temp); +#endif + my_snprintf(skip_test, PATH_MAX, " %s ", temp); // enviornment - setenv("MYSQL_TEST_DIR", mysql_test_dir, 1); +#ifdef __WIN__ + my_snprintf(temp, PATH_MAX, "MYSQL_TEST_DIR=%s", mysql_test_dir); + _putenv(temp); +#else + setenv("MYSQL_TEST_DIR", mysql_test_dir, 1); +#endif +} + +static my_bool +get_one_option(int optid, const struct my_option *opt __attribute__((unused)), + char *argument) +{ + return(0); } /****************************************************************************** @@ -1080,31 +1130,59 @@ void setup(char *file) ******************************************************************************/ int main(int argc, char **argv) { + int i; + uint ui; + + +#ifdef __WIN__ + int ho_error; + DWORD len= PATH_MAX; + char current_dir[PATH_MAX] = "."; + + if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) + exit(1); + if (len= GetCurrentDirectory(&len,current_dir)) + { + current_dir[len]= '\\'; + current_dir[len+1]='\0'; + }; + MY_INIT(current_dir); +#endif // setup +#ifdef __WIN__ + setup(current_dir); +#else setup(argv[0]); - +#endif // header - log("MySQL Server %s, for %s (%s)\n\n", VERSION, SYSTEM_TYPE, MACHINE_TYPE); + mtr_log("MySQL Server %s, for %s (%s)\n\n", VERSION, SYSTEM_TYPE, MACHINE_TYPE); - log("Initializing Tests...\n"); + mtr_log("Initializing Tests...\n"); // install test databases mysql_install_db(); - log("Starting Tests...\n"); + mtr_log("Starting Tests...\n"); - log("\n"); - log(HEADER); - log(DASH); + mtr_log("\n"); + mtr_log(HEADER); + mtr_log(DASH); +#ifdef __WIN__ + if (argc > 0) +#else if (argc > 1) +#endif { - int i; // single test single_test = TRUE; +#ifdef __WIN__ + for (i = 0; i < argc; i++) +#else for (i = 1; i < argc; i++) +#endif { // run given test run_test(argv[i]); @@ -1113,8 +1191,7 @@ int main(int argc, char **argv) else { // run all tests - DIR *dir = opendir(test_dir); - DIR *entry; + MY_DIR *dir = my_dir(test_dir, MYF(MY_WME | MY_WANT_STAT)); char test[NAME_MAX]; char *p; @@ -1126,14 +1203,16 @@ int main(int argc, char **argv) die("Unable to open tests directory."); } - while((entry = readdir(dir)) != NULL) + for (ui = 0; ui < dir->number_off_files; ui++) { - if (!S_ISDIR(entry->d_type)) + if (!MY_S_ISDIR(dir->dir_entry[ui].mystat.st_mode)) { - strcpy(test, strlwr(entry->d_name)); - + strcpy(test, dir->dir_entry[ui].name); +#ifndef __WIN__ + casedn_str(test); +#endif // find the test suffix - if ((p = strindex(test, TEST_SUFFIX)) != NULL) + if ((p = strstr(test, TEST_SUFFIX))) { // null terminate at the suffix *p = '\0'; @@ -1143,14 +1222,14 @@ int main(int argc, char **argv) } } } - - closedir(dir); + + my_dirend(dir); } - log(DASH); - log("\n"); + mtr_log(DASH); + mtr_log("\n"); - log("Ending Tests...\n"); + mtr_log("Ending Tests...\n"); // stop server mysql_stop(); @@ -1161,8 +1240,10 @@ int main(int argc, char **argv) // close log if (log_fd) fclose(log_fd); +#ifdef __NETWARE__ // keep results up pressanykey(); +#endif return 0; } |