Commit 6f604246 authored by greg@gcw.ath.cx's avatar greg@gcw.ath.cx

mysql_test_run.c and associated files, with my initial changes and WAX's changes for Windows

parent 19efafcc
...@@ -22,6 +22,7 @@ carsten@tsort.bitbybit.dk ...@@ -22,6 +22,7 @@ carsten@tsort.bitbybit.dk
davida@isil.mysql.com davida@isil.mysql.com
gluh@gluh.(none) gluh@gluh.(none)
gluh@gluh.mysql.r18.ru gluh@gluh.mysql.r18.ru
greg@gcw.ath.cx
greg@mysql.com greg@mysql.com
guilhem@mysql.com guilhem@mysql.com
gweir@work.mysql.com gweir@work.mysql.com
......
/* /*
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 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 it under the terms of the GNU General Public License as published by
...@@ -16,37 +17,45 @@ ...@@ -16,37 +17,45 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include <stdio.h> /*****************************************************************************
#include <errno.h> ** Utility functions for support programs
#include <dirent.h> *****************************************************************************/
#include <string.h>
#include <screen.h> /* MySQL library headers */
#include <proc.h> #include <my_global.h>
#include <ctype.h> #include <my_sys.h>
#include <sys/stat.h> #include <my_dir.h>
#include <fcntl.h> #include <m_string.h>
#include <assert.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" #include "my_manage.h"
#define __STDC__ 1
/****************************************************************************** #include "process.h"
macros
******************************************************************************/
/******************************************************************************
global variables
******************************************************************************/
/******************************************************************************
functions
******************************************************************************/
/****************************************************************************** /******************************************************************************
init_args() init_args()
...@@ -56,13 +65,17 @@ ...@@ -56,13 +65,17 @@
******************************************************************************/ ******************************************************************************/
void init_args(arg_list_t *al) void init_args(arg_list_t *al)
{ {
#ifndef __WIN__
ASSERT(al != NULL); ASSERT(al != NULL);
al->argc = 0; al->argc = 0;
al->size = ARG_BUF; 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); ASSERT(al->argv != NULL);
#else
win_args[0]= '\0';
skip_first_param= TRUE;
#endif
return; return;
} }
...@@ -73,18 +86,19 @@ void init_args(arg_list_t *al) ...@@ -73,18 +86,19 @@ void init_args(arg_list_t *al)
Add an argument to a list. 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; va_list ap;
char temp[PATH_MAX]; char temp[PATH_MAX];
ASSERT(al != NULL); ASSERT(al != NULL);
// increase size /* increase size */
if (al->argc >= al->size) if (al->argc >= (int)al->size)
{ {
al->size += ARG_BUF; 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); ASSERT(al->argv != NULL);
} }
...@@ -94,7 +108,7 @@ void add_arg(arg_list_t *al, char *format, ...) ...@@ -94,7 +108,7 @@ void add_arg(arg_list_t *al, char *format, ...)
vsprintf(temp, format, ap); vsprintf(temp, format, ap);
va_end(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); ASSERT(al->argv[al->argc] != NULL);
strcpy(al->argv[al->argc], temp); strcpy(al->argv[al->argc], temp);
...@@ -104,7 +118,23 @@ void add_arg(arg_list_t *al, char *format, ...) ...@@ -104,7 +118,23 @@ void add_arg(arg_list_t *al, char *format, ...)
{ {
al->argv[al->argc] = NULL; al->argv[al->argc] = NULL;
} }
#else
va_list ap;
char param[PATH_MAX];
if (!skip_first_param)
{
va_start(ap, format);
vsprintf(&param, format, ap);
va_end(ap);
strcat(win_args," ");
strcat(win_args,param);
}
else
{
skip_first_param= FALSE;
}
#endif
return; return;
} }
...@@ -117,6 +147,7 @@ void add_arg(arg_list_t *al, char *format, ...) ...@@ -117,6 +147,7 @@ void add_arg(arg_list_t *al, char *format, ...)
******************************************************************************/ ******************************************************************************/
void free_args(arg_list_t *al) void free_args(arg_list_t *al)
{ {
#ifndef __WIN__
int i; int i;
ASSERT(al != NULL); ASSERT(al != NULL);
...@@ -124,14 +155,14 @@ void free_args(arg_list_t *al) ...@@ -124,14 +155,14 @@ void free_args(arg_list_t *al)
for(i = 0; i < al->argc; i++) for(i = 0; i < al->argc; i++)
{ {
ASSERT(al->argv[i] != NULL); ASSERT(al->argv[i] != NULL);
free(al->argv[i]); my_free(al->argv[i], MYF(MY_WME));
al->argv[i] = NULL; al->argv[i] = NULL;
} }
free(al->argv); my_free((char *)al->argv, MYF(MY_WME));
al->argc = 0; al->argc = 0;
al->argv = NULL; al->argv = NULL;
#endif
return; return;
} }
...@@ -144,13 +175,31 @@ void free_args(arg_list_t *al) ...@@ -144,13 +175,31 @@ void free_args(arg_list_t *al)
******************************************************************************/ ******************************************************************************/
int sleep_until_file_deleted(char *pid_file) int sleep_until_file_deleted(char *pid_file)
{ {
struct stat buf; MY_STAT stat_info;
int i, err; int i, err = 0;
#ifndef __WIN__
for(i = 0; (i < TRY_MAX) && (err = !stat(pid_file, &buf)); i++) sleep(1); for(i = 0; i < TRY_MAX; i++)
{
if (err != 0) err = errno; 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; return err;
} }
...@@ -163,12 +212,32 @@ int sleep_until_file_deleted(char *pid_file) ...@@ -163,12 +212,32 @@ int sleep_until_file_deleted(char *pid_file)
******************************************************************************/ ******************************************************************************/
int sleep_until_file_exists(char *pid_file) int sleep_until_file_exists(char *pid_file)
{ {
struct stat buf; MY_STAT stat_info;
int i, err; int i, err = 0;
for(i = 0; (i < TRY_MAX) && (err = stat(pid_file, &buf)); i++) sleep(1); #ifndef __WIN__
for(i = 0; i < TRY_MAX; i++)
if (err != 0) err = errno; {
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; return err;
} }
...@@ -183,15 +252,13 @@ int sleep_until_file_exists(char *pid_file) ...@@ -183,15 +252,13 @@ int sleep_until_file_exists(char *pid_file)
int wait_for_server_start(char *bin_dir, char *user, char *password, int port) int wait_for_server_start(char *bin_dir, char *user, char *password, int port)
{ {
arg_list_t al; arg_list_t al;
int err, i; int err = 0, i;
char mysqladmin_file[PATH_MAX];
char trash[PATH_MAX]; char trash[PATH_MAX];
// mysqladmin file /* mysqladmin file */
snprintf(mysqladmin_file, PATH_MAX, "%s/mysqladmin", bin_dir); my_snprintf(trash, PATH_MAX, "/tmp/trash.out");
snprintf(trash, PATH_MAX, "/tmp/trash.out");
// args /* args */
init_args(&al); init_args(&al);
add_arg(&al, "%s", mysqladmin_file); add_arg(&al, "%s", mysqladmin_file);
add_arg(&al, "--no-defaults"); add_arg(&al, "--no-defaults");
...@@ -205,13 +272,13 @@ int wait_for_server_start(char *bin_dir, char *user, char *password, int port) ...@@ -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, "--host=localhost");
add_arg(&al, "ping"); add_arg(&al, "ping");
// NetWare does not support the connect timeout in the TCP/IP stack /* NetWare does not support the connect timeout in the TCP/IP stack
// -- we will try the ping multiple times -- we will try the ping multiple times */
for(i = 0; (i < TRY_MAX) for(i = 0; (i < TRY_MAX)
&& (err = spawn(mysqladmin_file, &al, TRUE, NULL, && (err = spawn(mysqladmin_file, &al, TRUE, NULL,
trash, NULL)); i++) sleep(1); trash, NULL, NOT_NEED_PID)); i++) sleep(1);
// free args /* free args */
free_args(&al); free_args(&al);
return err; return err;
...@@ -221,9 +288,12 @@ int wait_for_server_start(char *bin_dir, char *user, char *password, int port) ...@@ -221,9 +288,12 @@ int wait_for_server_start(char *bin_dir, char *user, char *password, int port)
spawn() spawn()
Spawn the given path with the given arguments. 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, int spawn(char *path, arg_list_t *al, int join, char *input,
char *output, char *error) char *output, char *error)
{ {
...@@ -232,7 +302,7 @@ int spawn(char *path, arg_list_t *al, int join, char *input, ...@@ -232,7 +302,7 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
wiring_t wiring = { FD_UNUSED, FD_UNUSED, FD_UNUSED }; wiring_t wiring = { FD_UNUSED, FD_UNUSED, FD_UNUSED };
unsigned long flags = PROC_CURRENT_SPACE | PROC_INHERIT_CWD; unsigned long flags = PROC_CURRENT_SPACE | PROC_INHERIT_CWD;
// open wiring /* open wiring */
if (input) if (input)
wiring.infd = open(input, O_RDONLY); wiring.infd = open(input, O_RDONLY);
...@@ -242,10 +312,10 @@ int spawn(char *path, arg_list_t *al, int join, char *input, ...@@ -242,10 +312,10 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
if (error) if (error)
wiring.errfd = open(error, O_WRONLY | O_CREAT | O_TRUNC); wiring.errfd = open(error, O_WRONLY | O_CREAT | O_TRUNC);
// procve requires a NULL /* procve requires a NULL */
add_arg(al, NULL); add_arg(al, NULL);
// go /* go */
pid = procve(path, flags, NULL, &wiring, NULL, NULL, 0, pid = procve(path, flags, NULL, &wiring, NULL, NULL, 0,
NULL, (const char **)al->argv); NULL, (const char **)al->argv);
...@@ -258,7 +328,7 @@ int spawn(char *path, arg_list_t *al, int join, char *input, ...@@ -258,7 +328,7 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
waitpid(pid, &result, 0); waitpid(pid, &result, 0);
} }
// close wiring /* close wiring */
if (wiring.infd != -1) if (wiring.infd != -1)
close(wiring.infd); close(wiring.infd);
...@@ -271,6 +341,164 @@ int spawn(char *path, arg_list_t *al, int join, char *input, ...@@ -271,6 +341,164 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
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_server()
...@@ -282,15 +510,12 @@ int stop_server(char *bin_dir, char *user, char *password, int port, ...@@ -282,15 +510,12 @@ int stop_server(char *bin_dir, char *user, char *password, int port,
char *pid_file) char *pid_file)
{ {
arg_list_t al; arg_list_t al;
int err, i, argc = 0; int err;
char mysqladmin_file[PATH_MAX];
char trash[PATH_MAX]; char trash[PATH_MAX];
// mysqladmin file my_snprintf(trash, PATH_MAX, "/tmp/trash.out");
snprintf(mysqladmin_file, PATH_MAX, "%s/mysqladmin", bin_dir);
snprintf(trash, PATH_MAX, "/tmp/trash.out");
// args /* args */
init_args(&al); init_args(&al);
add_arg(&al, "%s", mysqladmin_file); add_arg(&al, "%s", mysqladmin_file);
add_arg(&al, "--no-defaults"); add_arg(&al, "--no-defaults");
...@@ -301,7 +526,7 @@ int stop_server(char *bin_dir, char *user, char *password, int port, ...@@ -301,7 +526,7 @@ int stop_server(char *bin_dir, char *user, char *password, int port,
add_arg(&al, "shutdown_timeout=20"); add_arg(&al, "shutdown_timeout=20");
add_arg(&al, "shutdown"); add_arg(&al, "shutdown");
// spawn /* spawn */
if ((err = spawn(mysqladmin_file, &al, TRUE, NULL, if ((err = spawn(mysqladmin_file, &al, TRUE, NULL,
trash, NULL)) == 0) trash, NULL)) == 0)
{ {
...@@ -311,16 +536,16 @@ int stop_server(char *bin_dir, char *user, char *password, int port, ...@@ -311,16 +536,16 @@ int stop_server(char *bin_dir, char *user, char *password, int port,
{ {
pid_t pid = get_server_pid(pid_file); pid_t pid = get_server_pid(pid_file);
// shutdown failed - kill server /* shutdown failed - kill server */
kill_server(pid); kill_server(pid);
sleep(TRY_MAX); sleep(TRY_MAX);
// remove pid file if possible /* remove pid file if possible */
err = remove(pid_file); err = my_delete(pid_file, MYF(MY_WME));
} }
// free args /* free args */
free_args(&al); free_args(&al);
return err; return err;
...@@ -336,33 +561,34 @@ int stop_server(char *bin_dir, char *user, char *password, int port, ...@@ -336,33 +561,34 @@ int stop_server(char *bin_dir, char *user, char *password, int port,
pid_t get_server_pid(char *pid_file) pid_t get_server_pid(char *pid_file)
{ {
char buf[PATH_MAX]; char buf[PATH_MAX];
int fd, err; int err;
File fd;
char *p; char *p;
pid_t id; pid_t id = 0;
// discover id /* discover id */
fd = open(pid_file, O_RDONLY); fd = my_open(pid_file, O_RDONLY, MYF(MY_WME));
err = read(fd, buf, PATH_MAX); err = my_read(fd, buf, PATH_MAX, MYF(MY_WME));
close(fd); my_close(fd, MYF(MY_WME));
if (err > 0) if (err > 0)
{ {
// terminate string /* terminate string */
if ((p = strchr(buf, '\n')) != NULL) if ((p = strchr(buf, '\n')) != NULL)
{ {
*p = NULL; *p = '\0';
// check for a '\r' /* check for a '\r' */
if ((p = strchr(buf, '\r')) != NULL) if ((p = strchr(buf, '\r')) != NULL)
{ {
*p = NULL; *p = '\0';
} }
} }
else else
{ {
buf[err] = NULL; buf[err] = '\0';
} }
id = strtol(buf, NULL, 0); id = strtol(buf, NULL, 0);
...@@ -370,7 +596,6 @@ pid_t get_server_pid(char *pid_file) ...@@ -370,7 +596,6 @@ pid_t get_server_pid(char *pid_file)
return id; return id;
} }
/****************************************************************************** /******************************************************************************
kill_server() kill_server()
...@@ -382,8 +607,16 @@ void kill_server(pid_t pid) ...@@ -382,8 +607,16 @@ void kill_server(pid_t pid)
{ {
if (pid > 0) if (pid > 0)
{ {
// destroy vm
#if !defined(__NETWARE__)
/* Send SIGTERM to pid */
kill(pid, SIGTERM);
#else /* __NETWARE__ */
/* destroy vm */
NXVmDestroy(pid); NXVmDestroy(pid);
#endif
} }
} }
...@@ -396,37 +629,40 @@ void kill_server(pid_t pid) ...@@ -396,37 +629,40 @@ void kill_server(pid_t pid)
******************************************************************************/ ******************************************************************************/
void del_tree(char *dir) void del_tree(char *dir)
{ {
DIR *parent = opendir(dir); MY_DIR *current;
DIR *entry; uint i;
char temp[PATH_MAX]; char temp[PATH_MAX];
if (parent == NULL) current = my_dir(dir, MYF(MY_WME | MY_WANT_STAT));
{
/* current is NULL if dir does not exist */
if (current == NULL)
return; return;
}
while((entry = readdir(parent)) != NULL) for (i = 0; i < current->number_off_files; i++)
{ {
// create long name /* create long name */
snprintf(temp, PATH_MAX, "%s/%s", dir, entry->d_name); my_snprintf(temp, PATH_MAX, "%s/%s", dir, current->dir_entry[i].name);
if (entry->d_name[0] == '.') if (current->dir_entry[i].name[0] == '.')
{ {
// Skip /* Skip */
} }
else if (S_ISDIR(entry->d_type)) else if (MY_S_ISDIR(current->dir_entry[i].mystat.st_mode))
{ {
// delete subdirectory /* delete subdirectory */
del_tree(temp); del_tree(temp);
} }
else else
{ {
// remove file /* remove file */
remove(temp); my_delete(temp, MYF(MY_WME));
} }
} }
// remove directory my_dirend(current);
/* remove directory */
rmdir(dir); rmdir(dir);
} }
...@@ -435,18 +671,53 @@ void del_tree(char *dir) ...@@ -435,18 +671,53 @@ void del_tree(char *dir)
removef() removef()
******************************************************************************/ ******************************************************************************/
int removef(char *format, ...) int removef(const char *format, ...)
{ {
va_list ap; va_list ap;
char path[PATH_MAX]; char path[PATH_MAX];
va_start(ap, format); va_start(ap, format);
vsnprintf(path, PATH_MAX, format, ap); my_vsnprintf(path, PATH_MAX, format, ap);
va_end(ap); 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;
return remove(path); 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
} }
/****************************************************************************** /******************************************************************************
...@@ -462,12 +733,15 @@ void get_basedir(char *argv0, char *basedir) ...@@ -462,12 +733,15 @@ void get_basedir(char *argv0, char *basedir)
ASSERT(argv0 != NULL); ASSERT(argv0 != NULL);
ASSERT(basedir != NULL); ASSERT(basedir != NULL);
strcpy(temp, strlwr(argv0)); strcpy(temp, argv0);
#ifndef __WIN__
casedn_str(temp);
#endif
while((p = strchr(temp, '\\')) != NULL) *p = '/'; while((p = strchr(temp, '\\')) != NULL) *p = '/';
if ((p = strindex(temp, "/bin/")) != NULL) if ((p = strstr(temp, "/bin/")) != NullS)
{ {
*p = NULL; *p = '\0';
strcpy(basedir, temp); strcpy(basedir, temp);
} }
} }
......
...@@ -26,17 +26,41 @@ ...@@ -26,17 +26,41 @@
******************************************************************************/ ******************************************************************************/
#include <stdlib.h> #include <stdlib.h>
#ifndef __WIN__
#include <unistd.h> #include <unistd.h>
#endif
/****************************************************************************** /******************************************************************************
macros 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 ARG_BUF 10
#define TRY_MAX 5 #define TRY_MAX 5
#ifdef __NETWARE__
#define strstr(A,B) strindex(A,B)
#endif
/****************************************************************************** /******************************************************************************
structures structures
...@@ -53,6 +77,8 @@ typedef struct ...@@ -53,6 +77,8 @@ typedef struct
} arg_list_t; } arg_list_t;
typedef int pid_t;
/****************************************************************************** /******************************************************************************
global variables global variables
...@@ -66,7 +92,7 @@ typedef struct ...@@ -66,7 +92,7 @@ typedef struct
******************************************************************************/ ******************************************************************************/
void init_args(arg_list_t *); 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 *); void free_args(arg_list_t *);
int sleep_until_file_exists(char *); int sleep_until_file_exists(char *);
...@@ -80,8 +106,12 @@ pid_t get_server_pid(char *); ...@@ -80,8 +106,12 @@ pid_t get_server_pid(char *);
void kill_server(pid_t pid); void kill_server(pid_t pid);
void del_tree(char *); void del_tree(char *);
int removef(char *, ...); int removef(const char *, ...);
void get_basedir(char *, char *); void get_basedir(char *, char *);
char mysqladmin_file[PATH_MAX];
#endif /* _MY_MANAGE */ #endif /* _MY_MANAGE */
...@@ -16,21 +16,29 @@ ...@@ -16,21 +16,29 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 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 <stdio.h>
#include <errno.h> #include <stdarg.h>
#include <dirent.h>
#include <string.h> #ifdef __NETWARE__
#include <screen.h> #include <screen.h>
#include <nks/vm.h> #endif
#include <ctype.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include "my_config.h" #include "my_config.h"
#include "my_manage.h" #include "my_manage.h"
#ifdef __WIN__
#include <Shlwapi.h>
#endif
/****************************************************************************** /******************************************************************************
macros macros
...@@ -59,7 +67,7 @@ ...@@ -59,7 +67,7 @@
******************************************************************************/ ******************************************************************************/
char base_dir[PATH_MAX] = "sys:/mysql"; char base_dir[PATH_MAX] = "/mysql";
char db[PATH_MAX] = "test"; char db[PATH_MAX] = "test";
char user[PATH_MAX] = "root"; char user[PATH_MAX] = "root";
char password[PATH_MAX] = ""; char password[PATH_MAX] = "";
...@@ -67,7 +75,7 @@ char password[PATH_MAX] = ""; ...@@ -67,7 +75,7 @@ char password[PATH_MAX] = "";
int master_port = 9306; int master_port = 9306;
int slave_port = 9307; 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 skip_test[PATH_MAX] = "";
char bin_dir[PATH_MAX]; char bin_dir[PATH_MAX];
...@@ -80,7 +88,6 @@ char slave_dir[PATH_MAX]; ...@@ -80,7 +88,6 @@ char slave_dir[PATH_MAX];
char lang_dir[PATH_MAX]; char lang_dir[PATH_MAX];
char char_dir[PATH_MAX]; char char_dir[PATH_MAX];
char mysqladmin_file[PATH_MAX];
char mysqld_file[PATH_MAX]; char mysqld_file[PATH_MAX];
char mysqltest_file[PATH_MAX]; char mysqltest_file[PATH_MAX];
char master_pid[PATH_MAX]; char master_pid[PATH_MAX];
...@@ -109,6 +116,19 @@ int single_test = TRUE; ...@@ -109,6 +116,19 @@ int single_test = TRUE;
int restarts = 0; int restarts = 0;
FILE *log_fd = NULL; 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},
};
/****************************************************************************** /******************************************************************************
...@@ -135,12 +155,12 @@ void mysql_restart(); ...@@ -135,12 +155,12 @@ void mysql_restart();
int read_option(char *, char *); int read_option(char *, char *);
void run_test(char *); void run_test(char *);
void setup(char *); void setup(char *);
void vlog(char *, va_list); void vlog(const char *, va_list);
void log(char *, ...); void mtr_log(const char *, ...);
void log_info(char *, ...); void mtr_log_info(const char *, ...);
void log_error(char *, ...); void mtr_log_error(const char *, ...);
void log_errno(char *, ...); void mtr_log_errno(const char *, ...);
void die(char *); void die(const char *);
/****************************************************************************** /******************************************************************************
...@@ -153,21 +173,21 @@ void report_stats() ...@@ -153,21 +173,21 @@ void report_stats()
{ {
if (total_fail == 0) 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 else
{ {
double percent = ((double)total_pass / total_test) * 100; 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); total_fail, total_test, percent);
log("\nThe .out and .err files in %s may give you some\n", result_dir); mtr_log("\nThe .out and .err files in %s may give you some\n", result_dir);
log("hint of what when wrong.\n"); mtr_log("hint of what when wrong.\n");
log("\nIf you want to report this error, please first read the documentation\n"); mtr_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("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);
} }
/****************************************************************************** /******************************************************************************
...@@ -180,15 +200,15 @@ void report_stats() ...@@ -180,15 +200,15 @@ void report_stats()
void install_db(char *datadir) void install_db(char *datadir)
{ {
arg_list_t al; arg_list_t al;
int err, i; int err;
char input[PATH_MAX]; char input[PATH_MAX];
char output[PATH_MAX]; char output[PATH_MAX];
char error[PATH_MAX]; char error[PATH_MAX];
// input file // input file
snprintf(input, PATH_MAX, "%s/bin/init_db.sql", base_dir); my_snprintf(input, PATH_MAX, "%s/bin/init_db.sql", base_dir);
snprintf(output, PATH_MAX, "%s/install.out", datadir); my_snprintf(output, PATH_MAX, "%s/install.out", datadir);
snprintf(error, PATH_MAX, "%s/install.err", datadir); my_snprintf(error, PATH_MAX, "%s/install.err", datadir);
// args // args
init_args(&al); init_args(&al);
...@@ -201,6 +221,7 @@ void install_db(char *datadir) ...@@ -201,6 +221,7 @@ void install_db(char *datadir)
add_arg(&al, "--skip-bdb"); add_arg(&al, "--skip-bdb");
// spawn // spawn
if ((err = spawn(mysqld_file, &al, TRUE, input, output, error)) != 0) if ((err = spawn(mysqld_file, &al, TRUE, input, output, error)) != 0)
{ {
die("Unable to create database."); die("Unable to create database.");
...@@ -221,34 +242,34 @@ void mysql_install_db() ...@@ -221,34 +242,34 @@ void mysql_install_db()
{ {
char temp[PATH_MAX]; char temp[PATH_MAX];
// var directory /* var directory */
snprintf(temp, PATH_MAX, "%s/var", mysql_test_dir); my_snprintf(temp, PATH_MAX, "%s/var", mysql_test_dir);
// clean up old direcotry /* clean up old directory */
del_tree(temp); del_tree(temp);
// create var directory /* create var directory */
mkdir(temp, S_IRWXU); my_mkdir(temp, 0700, MYF(MY_WME));
// create subdirectories /* create subdirectories */
snprintf(temp, PATH_MAX, "%s/var/run", mysql_test_dir); my_snprintf(temp, PATH_MAX, "%s/var/run", mysql_test_dir);
mkdir(temp, S_IRWXU); my_mkdir(temp, 0700, MYF(MY_WME));
snprintf(temp, PATH_MAX, "%s/var/tmp", mysql_test_dir); my_snprintf(temp, PATH_MAX, "%s/var/tmp", mysql_test_dir);
mkdir(temp, S_IRWXU); my_mkdir(temp, 0700, MYF(MY_WME));
snprintf(temp, PATH_MAX, "%s/var/master-data", mysql_test_dir); my_snprintf(temp, PATH_MAX, "%s/var/master-data", mysql_test_dir);
mkdir(temp, S_IRWXU); my_mkdir(temp, 0700, MYF(MY_WME));
snprintf(temp, PATH_MAX, "%s/var/master-data/mysql", mysql_test_dir); my_snprintf(temp, PATH_MAX, "%s/var/master-data/mysql", mysql_test_dir);
mkdir(temp, S_IRWXU); my_mkdir(temp, 0700, MYF(MY_WME));
snprintf(temp, PATH_MAX, "%s/var/master-data/test", mysql_test_dir); my_snprintf(temp, PATH_MAX, "%s/var/master-data/test", mysql_test_dir);
mkdir(temp, S_IRWXU); my_mkdir(temp, 0700, MYF(MY_WME));
snprintf(temp, PATH_MAX, "%s/var/slave-data", mysql_test_dir); my_snprintf(temp, PATH_MAX, "%s/var/slave-data", mysql_test_dir);
mkdir(temp, S_IRWXU); my_mkdir(temp, 0700, MYF(MY_WME));
snprintf(temp, PATH_MAX, "%s/var/slave-data/mysql", mysql_test_dir); my_snprintf(temp, PATH_MAX, "%s/var/slave-data/mysql", mysql_test_dir);
mkdir(temp, S_IRWXU); my_mkdir(temp, 0700, MYF(MY_WME));
snprintf(temp, PATH_MAX, "%s/var/slave-data/test", mysql_test_dir); my_snprintf(temp, PATH_MAX, "%s/var/slave-data/test", mysql_test_dir);
mkdir(temp, S_IRWXU); my_mkdir(temp, 0700, MYF(MY_WME));
// install databases /* install databases */
install_db(master_dir); install_db(master_dir);
install_db(slave_dir); install_db(slave_dir);
} }
...@@ -263,56 +284,35 @@ void mysql_install_db() ...@@ -263,56 +284,35 @@ void mysql_install_db()
void start_master() void start_master()
{ {
arg_list_t al; arg_list_t al;
int err, i; int err;
char master_out[PATH_MAX]; char master_out[PATH_MAX];
char master_err[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); removef("%s/log.*", master_dir);
// remove stale binary logs /* remove stale binary logs */
removef("%s/*-bin.*", master_dir); removef("%s/*-bin.*", master_dir);
// remove stale binary logs /* remove stale binary logs */
removef("%s/*.index", master_dir); removef("%s/*.index", master_dir);
// remove master.info file /* remove master.info file */
removef("%s/master.info", master_dir); removef("%s/master.info", master_dir);
// remove relay files /* remove relay files */
removef("%s/var/log/*relay*", mysql_test_dir); 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); removef("%s/relay-log.info", master_dir);
// init script /* redirection files */
if (master_init_script[0] != NULL) my_snprintf(master_out, PATH_MAX, "%s/var/run/master%u.out",
{
// 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",
mysql_test_dir, restarts); 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); mysql_test_dir, restarts);
// args /* args */
init_args(&al); init_args(&al);
add_arg(&al, "%s", mysqld_file); add_arg(&al, "%s", mysqld_file);
add_arg(&al, "--no-defaults"); add_arg(&al, "--no-defaults");
...@@ -328,11 +328,11 @@ void start_master() ...@@ -328,11 +328,11 @@ void start_master()
add_arg(&al, "--tmpdir=%s", mysql_tmp_dir); add_arg(&al, "--tmpdir=%s", mysql_tmp_dir);
add_arg(&al, "--language=%s", lang_dir); add_arg(&al, "--language=%s", lang_dir);
// $MASTER_40_ARGS /* $MASTER_40_ARGS */
add_arg(&al, "--rpl-recovery-rank=1"); add_arg(&al, "--rpl-recovery-rank=1");
add_arg(&al, "--init-rpl-role=master"); add_arg(&al, "--init-rpl-role=master");
// $SMALL_SERVER /* $SMALL_SERVER */
add_arg(&al, "-O"); add_arg(&al, "-O");
add_arg(&al, "key_buffer_size=1M"); add_arg(&al, "key_buffer_size=1M");
add_arg(&al, "-O"); add_arg(&al, "-O");
...@@ -340,8 +340,8 @@ void start_master() ...@@ -340,8 +340,8 @@ void start_master()
add_arg(&al, "-O"); add_arg(&al, "-O");
add_arg(&al, "max_heap_table_size=1M"); add_arg(&al, "max_heap_table_size=1M");
// $EXTRA_MASTER_OPT /* $EXTRA_MASTER_OPT */
if (master_opt[0] != NULL) if (master_opt[0] != '\0')
{ {
char *p; char *p;
...@@ -355,10 +355,15 @@ void start_master() ...@@ -355,10 +355,15 @@ void start_master()
} }
} }
// remove the pid file if it exists /* remove the pid file if it exists */
remove(master_pid); #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) if ((err = spawn(mysqld_file, &al, FALSE, NULL, master_out, master_err)) == 0)
{ {
sleep_until_file_exists(master_pid); sleep_until_file_exists(master_pid);
...@@ -369,15 +374,15 @@ void start_master() ...@@ -369,15 +374,15 @@ void start_master()
} }
else else
{ {
log_error("The master server went down early."); mtr_log_error("The master server went down early.");
} }
} }
else else
{ {
log_error("Unable to start master server."); mtr_log_error("Unable to start master server.");
} }
// free_args /* free_args */
free_args(&al); free_args(&al);
} }
...@@ -391,48 +396,48 @@ void start_master() ...@@ -391,48 +396,48 @@ void start_master()
void start_slave() void start_slave()
{ {
arg_list_t al; arg_list_t al;
int err, i; int err;
char slave_out[PATH_MAX]; char slave_out[PATH_MAX];
char slave_err[PATH_MAX]; char slave_err[PATH_MAX];
char temp[PATH_MAX]; char temp[PATH_MAX];
// skip? /* skip? */
if (skip_slave) return; if (skip_slave) return;
// remove stale binary logs /* remove stale binary logs */
removef("%s/*-bin.*", slave_dir); removef("%s/*-bin.*", slave_dir);
// remove stale binary logs /* remove stale binary logs */
removef("%s/*.index", slave_dir); removef("%s/*.index", slave_dir);
// remove master.info file /* remove master.info file */
removef("%s/master.info", slave_dir); removef("%s/master.info", slave_dir);
// remove relay files /* remove relay files */
removef("%s/var/log/*relay*", mysql_test_dir); 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); removef("%s/relay-log.info", slave_dir);
// init script /* init script */
if (slave_init_script[0] != NULL) if (slave_init_script[0] != '\0')
{ {
// run_init_script(slave_init_script); /* run_init_script(slave_init_script); */
// TODO: use the scripts /* TODO: use the scripts */
if (strindex(slave_init_script, "rpl000016-slave.sh") != NULL) if (strstr(slave_init_script, "rpl000016-slave.sh") != NULL)
{ {
// create empty master.info file /* create empty master.info file */
snprintf(temp, PATH_MAX, "%s/master.info", slave_dir); my_snprintf(temp, PATH_MAX, "%s/master.info", slave_dir);
close(open(temp, O_WRONLY | O_CREAT)); 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; FILE *fp;
// create a master.info file /* create a master.info file */
snprintf(temp, PATH_MAX, "%s/master.info", slave_dir); my_snprintf(temp, PATH_MAX, "%s/master.info", slave_dir);
fp = fopen(temp, "wb+"); fp = my_fopen(temp, (int)(O_WRONLY | O_BINARY | O_CREAT), MYF(MY_WME));
fputs("master-bin.001\n", fp); fputs("master-bin.001\n", fp);
fputs("4\n", fp); fputs("4\n", fp);
...@@ -443,20 +448,20 @@ void start_slave() ...@@ -443,20 +448,20 @@ void start_slave()
fputs("1\n", fp); fputs("1\n", fp);
fputs("0\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 /* create empty master.info file */
snprintf(temp, PATH_MAX, "%s/master.info", slave_dir); my_snprintf(temp, PATH_MAX, "%s/master.info", slave_dir);
close(open(temp, O_WRONLY | O_CREAT)); my_close(my_open(temp, O_WRONLY | O_CREAT, MYF(0)), MYF(0));
} }
} }
// redirection files /* redirection files */
snprintf(slave_out, PATH_MAX, "%s/var/run/slave%u.out", my_snprintf(slave_out, PATH_MAX, "%s/var/run/slave%u.out",
mysql_test_dir, restarts); 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); mysql_test_dir, restarts);
// args // args
...@@ -489,8 +494,8 @@ void start_slave() ...@@ -489,8 +494,8 @@ void start_slave()
add_arg(&al, "-O"); add_arg(&al, "-O");
add_arg(&al, "slave_net_timeout=10"); add_arg(&al, "slave_net_timeout=10");
// slave master info /* slave master info */
if (slave_master_info[0] != NULL) if (slave_master_info[0] != '\0')
{ {
char *p; char *p;
...@@ -514,7 +519,7 @@ void start_slave() ...@@ -514,7 +519,7 @@ void start_slave()
add_arg(&al, "--rpl-recovery-rank=2"); add_arg(&al, "--rpl-recovery-rank=2");
} }
// small server /* small server */
add_arg(&al, "-O"); add_arg(&al, "-O");
add_arg(&al, "key_buffer_size=1M"); add_arg(&al, "key_buffer_size=1M");
add_arg(&al, "-O"); add_arg(&al, "-O");
...@@ -522,8 +527,8 @@ void start_slave() ...@@ -522,8 +527,8 @@ void start_slave()
add_arg(&al, "-O"); add_arg(&al, "-O");
add_arg(&al, "max_heap_table_size=1M"); add_arg(&al, "max_heap_table_size=1M");
// opt args /* opt args */
if (slave_opt[0] != NULL) if (slave_opt[0] != '\0')
{ {
char *p; char *p;
...@@ -537,8 +542,13 @@ void start_slave() ...@@ -537,8 +542,13 @@ void start_slave()
} }
} }
// remove the pid file if it exists /* remove the pid file if it exists */
remove(slave_pid); #ifndef __WIN__
my_delete(slave_pid, MYF(MY_WME));
#else
pid_mode= SLAVE_PID;
run_server= TRUE;
#endif
// spawn // spawn
if ((err = spawn(mysqld_file, &al, FALSE, NULL, slave_out, slave_err)) == 0) if ((err = spawn(mysqld_file, &al, FALSE, NULL, slave_out, slave_err)) == 0)
...@@ -551,12 +561,12 @@ void start_slave() ...@@ -551,12 +561,12 @@ void start_slave()
} }
else else
{ {
log_error("The slave server went down early."); mtr_log_error("The slave server went down early.");
} }
} }
else else
{ {
log_error("Unable to start slave server."); mtr_log_error("Unable to start slave server.");
} }
// free args // free args
...@@ -576,8 +586,10 @@ void mysql_start() ...@@ -576,8 +586,10 @@ void mysql_start()
start_slave(); start_slave();
#ifdef __NETWARE__
// activate the test screen // activate the test screen
ActivateScreen(getscreenhandle()); ActivateScreen(getscreenhandle());
#endif
} }
/****************************************************************************** /******************************************************************************
...@@ -591,17 +603,20 @@ void stop_slave() ...@@ -591,17 +603,20 @@ void stop_slave()
{ {
int err; int err;
// running? /* running? */
if (!slave_running) return; 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) if ((err = stop_server(bin_dir, user, password, slave_port, slave_pid)) == 0)
{ {
slave_running = FALSE; slave_running = FALSE;
} }
else else
{ {
log_error("Unable to stop slave server."); mtr_log_error("Unable to stop slave server.");
} }
} }
...@@ -616,16 +631,18 @@ void stop_master() ...@@ -616,16 +631,18 @@ void stop_master()
{ {
int err; int err;
// running? /* running? */
if (!master_running) return; if (!master_running) return;
#ifdef __WIN__
pid_mode= MASTER_PID;
#endif
if ((err = stop_server(bin_dir, user, password, master_port, master_pid)) == 0) if ((err = stop_server(bin_dir, user, password, master_port, master_pid)) == 0)
{ {
master_running = FALSE; master_running = FALSE;
} }
else else
{ {
log_error("Unable to stop master server."); mtr_log_error("Unable to stop master server.");
} }
} }
...@@ -642,8 +659,10 @@ void mysql_stop() ...@@ -642,8 +659,10 @@ void mysql_stop()
stop_slave(); stop_slave();
#ifdef __NETWARE__
// activate the test screen // activate the test screen
ActivateScreen(getscreenhandle()); ActivateScreen(getscreenhandle());
#endif
} }
/****************************************************************************** /******************************************************************************
...@@ -655,7 +674,7 @@ void mysql_stop() ...@@ -655,7 +674,7 @@ void mysql_stop()
******************************************************************************/ ******************************************************************************/
void mysql_restart() void mysql_restart()
{ {
log_info("Restarting the MySQL server(s): %u", ++restarts); mtr_log_info("Restarting the MySQL server(s): %u", ++restarts);
mysql_stop(); mysql_stop();
...@@ -671,45 +690,50 @@ void mysql_restart() ...@@ -671,45 +690,50 @@ void mysql_restart()
******************************************************************************/ ******************************************************************************/
int read_option(char *opt_file, char *opt) int read_option(char *opt_file, char *opt)
{ {
int fd, err; File fd;
int result; int err;
char *p; char *p;
char buf[PATH_MAX]; char buf[PATH_MAX];
// copy current option /* copy current option */
strncpy(buf, opt, PATH_MAX); strncpy(buf, opt, PATH_MAX);
// open options file #ifdef __WIN__
fd = open(opt_file, O_RDONLY); 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) if (err > 0)
{ {
// terminate string /* terminate string */
if ((p = strchr(opt, '\n')) != NULL) if ((p = strchr(opt, '\n')) != NULL)
{ {
*p = NULL; *p = '\0';
// check for a '\r' /* check for a '\r' */
if ((p = strchr(opt, '\r')) != NULL) if ((p = strchr(opt, '\r')) != NULL)
{ {
*p = NULL; *p = '\0';
} }
} }
else else
{ {
opt[err] = NULL; opt[err] = '\0';
} }
// check for $MYSQL_TEST_DIR /* check for $MYSQL_TEST_DIR */
if ((p = strstr(opt, "$MYSQL_TEST_DIR")) != NULL) if ((p = strstr(opt, "$MYSQL_TEST_DIR")) != NullS)
{ {
char temp[PATH_MAX]; char temp[PATH_MAX];
*p = NULL; *p = '\0';
strcpy(temp, p + strlen("$MYSQL_TEST_DIR")); strcpy(temp, p + strlen("$MYSQL_TEST_DIR"));
...@@ -720,11 +744,14 @@ int read_option(char *opt_file, char *opt) ...@@ -720,11 +744,14 @@ int read_option(char *opt_file, char *opt)
} }
else else
{ {
// clear option /* clear option */
*opt = NULL; *opt = '\0';
}
#ifdef __WIN__
} }
#endif
// compare current option with previous /* compare current option with previous */
return strcmp(opt, buf); return strcmp(opt, buf);
} }
...@@ -739,21 +766,20 @@ void run_test(char *test) ...@@ -739,21 +766,20 @@ void run_test(char *test)
{ {
char temp[PATH_MAX]; char temp[PATH_MAX];
char *rstr; char *rstr;
double elapsed = 0;
int skip = FALSE; int skip = FALSE;
int restart = FALSE; int restart = FALSE;
int flag = FALSE; int flag = FALSE;
struct stat info; struct stat info;
// single test? /* single test? */
if (!single_test) if (!single_test)
{ {
// skip tests in the skip list // skip tests in the skip list
snprintf(temp, PATH_MAX, " %s ", test); my_snprintf(temp, PATH_MAX, " %s ", test);
skip = (strindex(skip_test, temp) != NULL); skip = strinstr(skip_test, temp);
} }
// skip test? /* skip test? */
if (!skip) if (!skip)
{ {
char test_file[PATH_MAX]; char test_file[PATH_MAX];
...@@ -766,7 +792,6 @@ void run_test(char *test) ...@@ -766,7 +792,6 @@ void run_test(char *test)
char err_file[PATH_MAX]; char err_file[PATH_MAX];
int err; int err;
arg_list_t al; arg_list_t al;
NXTime_t start, stop;
// skip slave? // skip slave?
flag = skip_slave; flag = skip_slave;
...@@ -774,36 +799,36 @@ void run_test(char *test) ...@@ -774,36 +799,36 @@ void run_test(char *test)
if (flag != skip_slave) restart = TRUE; if (flag != skip_slave) restart = TRUE;
// create files // create files
snprintf(master_opt_file, PATH_MAX, "%s/%s-master.opt", test_dir, test); my_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); my_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); my_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); my_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); my_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(err_file, PATH_MAX, "%s/%s%s", result_dir, test, ERR_SUFFIX);
// netware specific files // 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)) 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)) 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 // 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)) if (stat(master_init_script, &info))
master_init_script[0] = NULL; master_init_script[0] = '\0';
else else
restart = TRUE; 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)) if (stat(slave_init_script, &info))
slave_init_script[0] = NULL; slave_init_script[0] = '\0';
else else
restart = TRUE; restart = TRUE;
...@@ -825,7 +850,7 @@ void run_test(char *test) ...@@ -825,7 +850,7 @@ void run_test(char *test)
sleep(1); sleep(1);
// show test // show test
log("%-46s ", test); mtr_log("%-46s ", test);
// args // args
init_args(&al); init_args(&al);
...@@ -842,26 +867,16 @@ void run_test(char *test) ...@@ -842,26 +867,16 @@ void run_test(char *test)
add_arg(&al, "-R"); add_arg(&al, "-R");
add_arg(&al, "%s", result_file); add_arg(&al, "%s", result_file);
// start timer
NXGetTime(NX_SINCE_BOOT, NX_USECONDS, &start);
// spawn // spawn
err = spawn(mysqltest_file, &al, TRUE, test_file, out_file, err_file); 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
free_args(&al); free_args(&al);
if (err == 0) if (err == 0)
{ {
// pass // pass
rstr = TEST_PASS; rstr = (char *)TEST_PASS;
++total_pass; ++total_pass;
// increment total // increment total
...@@ -870,13 +885,13 @@ void run_test(char *test) ...@@ -870,13 +885,13 @@ void run_test(char *test)
else if (err == 2) else if (err == 2)
{ {
// skip // skip
rstr = TEST_SKIP; rstr = (char *)TEST_SKIP;
++total_skip; ++total_skip;
} }
else if (err == 1) else if (err == 1)
{ {
// fail // fail
rstr = TEST_FAIL; rstr = (char *)TEST_FAIL;
++total_fail; ++total_fail;
// increment total // increment total
...@@ -884,21 +899,21 @@ void run_test(char *test) ...@@ -884,21 +899,21 @@ void run_test(char *test)
} }
else else
{ {
rstr = TEST_BAD; rstr = (char *)TEST_BAD;
} }
} }
else // early skips else // early skips
{ {
// show test // show test
log("%-46s ", test); mtr_log("%-46s ", test);
// skip // skip
rstr = TEST_SKIP; rstr = (char *)TEST_SKIP;
++total_skip; ++total_skip;
} }
// result // result
log("%10.06f %-14s\n", elapsed, rstr); mtr_log(" %-14s\n", rstr);
} }
/****************************************************************************** /******************************************************************************
...@@ -908,7 +923,7 @@ void run_test(char *test) ...@@ -908,7 +923,7 @@ void run_test(char *test)
Log the message. Log the message.
******************************************************************************/ ******************************************************************************/
void vlog(char *format, va_list ap) void vlog(const char *format, va_list ap)
{ {
vfprintf(stdout, format, ap); vfprintf(stdout, format, ap);
fflush(stdout); fflush(stdout);
...@@ -922,12 +937,12 @@ void vlog(char *format, va_list ap) ...@@ -922,12 +937,12 @@ void vlog(char *format, va_list ap)
/****************************************************************************** /******************************************************************************
log() mtr_log()
Log the message. Log the message.
******************************************************************************/ ******************************************************************************/
void log(char *format, ...) void mtr_log(const char *format, ...)
{ {
va_list ap; va_list ap;
...@@ -940,60 +955,60 @@ void log(char *format, ...) ...@@ -940,60 +955,60 @@ void log(char *format, ...)
/****************************************************************************** /******************************************************************************
log_info() mtr_log_info()
Log the given information. Log the given information.
******************************************************************************/ ******************************************************************************/
void log_info(char *format, ...) void mtr_log_info(const char *format, ...)
{ {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
log("-- INFO : "); mtr_log("-- INFO : ");
vlog(format, ap); vlog(format, ap);
log("\n"); mtr_log("\n");
va_end(ap); va_end(ap);
} }
/****************************************************************************** /******************************************************************************
log_error() mtr_log_error()
Log the given error. Log the given error.
******************************************************************************/ ******************************************************************************/
void log_error(char *format, ...) void mtr_log_error(const char *format, ...)
{ {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
log("-- ERROR: "); mtr_log("-- ERROR: ");
vlog(format, ap); vlog(format, ap);
log("\n"); mtr_log("\n");
va_end(ap); va_end(ap);
} }
/****************************************************************************** /******************************************************************************
log_errno() mtr_log_errno()
Log the given error and errno. Log the given error and errno.
******************************************************************************/ ******************************************************************************/
void log_errno(char *format, ...) void mtr_log_errno(const char *format, ...)
{ {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
log("-- ERROR: (%003u) ", errno); mtr_log("-- ERROR: (%003u) ", errno);
vlog(format, ap); vlog(format, ap);
log("\n"); mtr_log("\n");
va_end(ap); va_end(ap);
} }
...@@ -1005,11 +1020,13 @@ void log_errno(char *format, ...) ...@@ -1005,11 +1020,13 @@ void log_errno(char *format, ...)
Exit the application. Exit the application.
******************************************************************************/ ******************************************************************************/
void die(char *msg) void die(const char *msg)
{ {
log_error(msg); mtr_log_error(msg);
#ifdef __NETWARE__
pressanykey(); pressanykey();
#endif
exit(-1); exit(-1);
} }
...@@ -1027,50 +1044,83 @@ void setup(char *file) ...@@ -1027,50 +1044,83 @@ void setup(char *file)
char *p; char *p;
// set the timezone for the timestamp test // set the timezone for the timestamp test
#ifdef __WIN__
_putenv( "TZ=GMT-3" );
#else
setenv("TZ", "GMT-3", TRUE); setenv("TZ", "GMT-3", TRUE);
#endif
// find base dir // find base dir
strcpy(temp, strlwr(file)); strcpy(temp, file);
#ifndef __WIN__
casedn_str(temp);
#endif
while((p = strchr(temp, '\\')) != NULL) *p = '/'; while((p = strchr(temp, '\\')) != NULL) *p = '/';
if ((p = strindex(temp, "/mysql-test/")) != NULL) if ((p = strstr(temp, "/mysql-test/")))
{ {
*p = NULL; *p = '\0';
strcpy(base_dir, temp); strcpy(base_dir, (const char *)temp);
} }
// setup paths // setup paths
snprintf(bin_dir, PATH_MAX, "%s/bin", base_dir); #ifdef __WIN__
snprintf(mysql_test_dir, PATH_MAX, "%s/mysql-test", base_dir); my_snprintf(bin_dir, PATH_MAX, "%s/%s", base_dir,opt_exedir);
snprintf(test_dir, PATH_MAX, "%s/t", mysql_test_dir); #else
snprintf(mysql_tmp_dir, PATH_MAX, "%s/var/tmp", mysql_test_dir); my_snprintf(bin_dir, PATH_MAX, "%s/bin", base_dir);
snprintf(result_dir, PATH_MAX, "%s/r", mysql_test_dir); #endif
snprintf(master_dir, PATH_MAX, "%s/var/master-data", mysql_test_dir); my_snprintf(mysql_test_dir, PATH_MAX, "%s/mysql-test", base_dir);
snprintf(slave_dir, PATH_MAX, "%s/var/slave-data", mysql_test_dir); my_snprintf(test_dir, PATH_MAX, "%s/t", mysql_test_dir);
snprintf(lang_dir, PATH_MAX, "%s/share/english", base_dir); my_snprintf(mysql_tmp_dir, PATH_MAX, "%s/var/tmp", mysql_test_dir);
snprintf(char_dir, PATH_MAX, "%s/share/charsets", base_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 // setup files
snprintf(mysqld_file, PATH_MAX, "%s/mysqld", bin_dir); #ifdef __WIN__
snprintf(mysqltest_file, PATH_MAX, "%s/mysqltest", bin_dir); my_snprintf(mysqld_file, PATH_MAX, "%s/%s.exe", bin_dir, mysqld);
snprintf(mysqladmin_file, PATH_MAX, "%s/mysqladmin", bin_dir); my_snprintf(mysqltest_file, PATH_MAX, "%s/mysqltest.exe", bin_dir);
snprintf(master_pid, PATH_MAX, "%s/var/run/master.pid", mysql_test_dir); my_snprintf(mysqladmin_file, PATH_MAX, "%s/mysqladmin.exe", bin_dir);
snprintf(slave_pid, PATH_MAX, "%s/var/run/slave.pid", mysql_test_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 // 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) 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 // prepare skip test list
while((p = strchr(skip_test, ',')) != NULL) *p = ' '; while((p = strchr(skip_test, ',')) != NULL) *p = ' ';
strcpy(temp, strlwr(skip_test)); strcpy(temp, skip_test);
snprintf(skip_test, PATH_MAX, " %s ", temp); #ifndef __WIN__
casedn_str(temp);
#endif
my_snprintf(skip_test, PATH_MAX, " %s ", temp);
// enviornment // enviornment
#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); 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) ...@@ -1080,31 +1130,59 @@ void setup(char *file)
******************************************************************************/ ******************************************************************************/
int main(int argc, char **argv) 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 // setup
#ifdef __WIN__
setup(current_dir);
#else
setup(argv[0]); setup(argv[0]);
#endif
// header // 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 // install test databases
mysql_install_db(); mysql_install_db();
log("Starting Tests...\n"); mtr_log("Starting Tests...\n");
log("\n"); mtr_log("\n");
log(HEADER); mtr_log(HEADER);
log(DASH); mtr_log(DASH);
#ifdef __WIN__
if (argc > 0)
#else
if (argc > 1) if (argc > 1)
#endif
{ {
int i;
// single test // single test
single_test = TRUE; single_test = TRUE;
#ifdef __WIN__
for (i = 0; i < argc; i++)
#else
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
#endif
{ {
// run given test // run given test
run_test(argv[i]); run_test(argv[i]);
...@@ -1113,8 +1191,7 @@ int main(int argc, char **argv) ...@@ -1113,8 +1191,7 @@ int main(int argc, char **argv)
else else
{ {
// run all tests // run all tests
DIR *dir = opendir(test_dir); MY_DIR *dir = my_dir(test_dir, MYF(MY_WME | MY_WANT_STAT));
DIR *entry;
char test[NAME_MAX]; char test[NAME_MAX];
char *p; char *p;
...@@ -1126,14 +1203,16 @@ int main(int argc, char **argv) ...@@ -1126,14 +1203,16 @@ int main(int argc, char **argv)
die("Unable to open tests directory."); 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 // find the test suffix
if ((p = strindex(test, TEST_SUFFIX)) != NULL) if ((p = strstr(test, TEST_SUFFIX)))
{ {
// null terminate at the suffix // null terminate at the suffix
*p = '\0'; *p = '\0';
...@@ -1144,13 +1223,13 @@ int main(int argc, char **argv) ...@@ -1144,13 +1223,13 @@ int main(int argc, char **argv)
} }
} }
closedir(dir); my_dirend(dir);
} }
log(DASH); mtr_log(DASH);
log("\n"); mtr_log("\n");
log("Ending Tests...\n"); mtr_log("Ending Tests...\n");
// stop server // stop server
mysql_stop(); mysql_stop();
...@@ -1161,8 +1240,10 @@ int main(int argc, char **argv) ...@@ -1161,8 +1240,10 @@ int main(int argc, char **argv)
// close log // close log
if (log_fd) fclose(log_fd); if (log_fd) fclose(log_fd);
#ifdef __NETWARE__
// keep results up // keep results up
pressanykey(); pressanykey();
#endif
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment