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

This commit is contained in:
greg@gcw.ath.cx 2003-07-23 01:35:24 -04:00
parent 19efafcc13
commit 6f60424629
5 changed files with 944 additions and 558 deletions

View File

@ -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

View File

@ -1,5 +1,6 @@
/*
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
@ -16,37 +17,45 @@
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
******************************************************************************/
/******************************************************************************
functions
******************************************************************************/
#define __STDC__ 1
#include "process.h"
/******************************************************************************
init_args()
@ -56,13 +65,17 @@
******************************************************************************/
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;
}
@ -73,18 +86,19 @@ void init_args(arg_list_t *al)
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,7 +118,23 @@ 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(&param, format, ap);
va_end(ap);
strcat(win_args," ");
strcat(win_args,param);
}
else
{
skip_first_param= FALSE;
}
#endif
return;
}
@ -117,6 +147,7 @@ void add_arg(arg_list_t *al, char *format, ...)
******************************************************************************/
void free_args(arg_list_t *al)
{
#ifndef __WIN__
int i;
ASSERT(al != NULL);
@ -124,14 +155,14 @@ 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;
}
@ -144,13 +175,31 @@ void free_args(arg_list_t *al)
******************************************************************************/
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;
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;
}
@ -163,12 +212,32 @@ int sleep_until_file_deleted(char *pid_file)
******************************************************************************/
int sleep_until_file_exists(char *pid_file)
{
struct stat buf;
int i, err;
MY_STAT stat_info;
int i, err = 0;
for(i = 0; (i < TRY_MAX) && (err = stat(pid_file, &buf)); i++) sleep(1);
if (err != 0) err = errno;
#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;
}
@ -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)
{
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");
/* mysqladmin file */
my_snprintf(trash, PATH_MAX, "/tmp/trash.out");
// args
/* 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
/* 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);
trash, NULL, NOT_NEED_PID)); i++) sleep(1);
// free args
/* free args */
free_args(&al);
return err;
@ -221,9 +288,12 @@ int wait_for_server_start(char *bin_dir, char *user, char *password, int port)
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,
char *output, char *error)
{
@ -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 };
unsigned long flags = PROC_CURRENT_SPACE | PROC_INHERIT_CWD;
// open wiring
/* open wiring */
if (input)
wiring.infd = open(input, O_RDONLY);
@ -242,10 +312,10 @@ 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);
@ -258,7 +328,7 @@ 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);
@ -271,6 +341,164 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
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()
@ -282,15 +510,12 @@ 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];
int err;
char trash[PATH_MAX];
// mysqladmin file
snprintf(mysqladmin_file, PATH_MAX, "%s/mysqladmin", bin_dir);
snprintf(trash, PATH_MAX, "/tmp/trash.out");
my_snprintf(trash, PATH_MAX, "/tmp/trash.out");
// args
/* args */
init_args(&al);
add_arg(&al, "%s", mysqladmin_file);
add_arg(&al, "--no-defaults");
@ -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");
// spawn
/* spawn */
if ((err = spawn(mysqladmin_file, &al, TRUE, NULL,
trash, NULL)) == 0)
{
@ -311,16 +536,16 @@ int stop_server(char *bin_dir, char *user, char *password, int port,
{
pid_t pid = get_server_pid(pid_file);
// shutdown failed - kill server
/* shutdown failed - kill server */
kill_server(pid);
sleep(TRY_MAX);
// remove pid file if possible
err = remove(pid_file);
/* remove pid file if possible */
err = my_delete(pid_file, MYF(MY_WME));
}
// free args
/* free args */
free_args(&al);
return err;
@ -336,33 +561,34 @@ int stop_server(char *bin_dir, char *user, char *password, int port,
pid_t get_server_pid(char *pid_file)
{
char buf[PATH_MAX];
int fd, err;
int err;
File fd;
char *p;
pid_t id;
pid_t id = 0;
// discover id
fd = open(pid_file, O_RDONLY);
/* discover id */
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)
{
// terminate string
/* terminate string */
if ((p = strchr(buf, '\n')) != NULL)
{
*p = NULL;
*p = '\0';
// check for a '\r'
/* check for a '\r' */
if ((p = strchr(buf, '\r')) != NULL)
{
*p = NULL;
*p = '\0';
}
}
else
{
buf[err] = NULL;
buf[err] = '\0';
}
id = strtol(buf, NULL, 0);
@ -370,7 +596,6 @@ pid_t get_server_pid(char *pid_file)
return id;
}
/******************************************************************************
kill_server()
@ -382,8 +607,16 @@ 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
}
}
@ -396,37 +629,40 @@ void kill_server(pid_t pid)
******************************************************************************/
void del_tree(char *dir)
{
DIR *parent = opendir(dir);
DIR *entry;
MY_DIR *current;
uint i;
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;
}
while((entry = readdir(parent)) != NULL)
for (i = 0; i < current->number_off_files; i++)
{
// create long name
snprintf(temp, PATH_MAX, "%s/%s", dir, entry->d_name);
/* create long 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);
}
else
{
// remove file
remove(temp);
/* remove file */
my_delete(temp, MYF(MY_WME));
}
}
// remove directory
my_dirend(current);
/* remove directory */
rmdir(dir);
}
@ -435,18 +671,53 @@ void del_tree(char *dir)
removef()
******************************************************************************/
int removef(char *format, ...)
int removef(const char *format, ...)
{
va_list ap;
char path[PATH_MAX];
va_start(ap, format);
vsnprintf(path, PATH_MAX, format, ap);
my_vsnprintf(path, PATH_MAX, format, 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)
ASSERT(argv0 != NULL);
ASSERT(basedir != NULL);
strcpy(temp, strlwr(argv0));
strcpy(temp, argv0);
#ifndef __WIN__
casedn_str(temp);
#endif
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);
}
}

View File

@ -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 */

File diff suppressed because it is too large Load Diff