From 224c40a52335bf1afc7662183900e143307aa5be Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 1 Nov 1997 13:22:16 +0000 Subject: a simple SMB torture tester. This will allow us to evaluate locking techniques more accurately. (This used to be commit 054e3b2ae3a8cfb98fde72becef9b05de34d2ba7) --- source3/utils/torture.c | 316 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 316 insertions(+) create mode 100644 source3/utils/torture.c (limited to 'source3/utils/torture.c') diff --git a/source3/utils/torture.c b/source3/utils/torture.c new file mode 100644 index 0000000000..bc7ebfb335 --- /dev/null +++ b/source3/utils/torture.c @@ -0,0 +1,316 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + SMB torture tester + Copyright (C) Andrew Tridgell 1997 + + 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. + + 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., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifdef SYSLOG +#undef SYSLOG +#endif + +#include "includes.h" + +static struct cli_state cli; +static fstring host, workgroup, share, password, username, myname; +static char *sockops=""; + + +static struct timeval tp1,tp2; + +static void start_timer() +{ + gettimeofday(&tp1,NULL); +} + +static double end_timer() +{ + gettimeofday(&tp2,NULL); + return((tp2.tv_sec - tp1.tv_sec) + + (tp2.tv_usec - tp1.tv_usec)*1.0e-6); +} + + +static int open_connection(void) +{ + if (!cli_initialise(&cli) || !cli_connect(&cli, host, NULL)) { + printf("Failed to connect with %s\n", host); + } + + if (!cli_session_request(&cli, host, 0x20, myname)) { + printf("%s rejected the session\n",host); + cli_shutdown(&cli); + return -1; + } + + if (!cli_negprot(&cli)) { + printf("%s rejected the negprot (%s)\n",host, cli_errstr(&cli)); + cli_shutdown(&cli); + return -1; + } + + if (!cli_session_setup(&cli, username, password, strlen(password), + "", 0, workgroup)) { + printf("%s rejected the sessionsetup (%s)\n", host, cli_errstr(&cli)); + cli_shutdown(&cli); + return -1; + } + + if (!cli_send_tconX(&cli, share, "A:", password, strlen(password)+1)) { + printf("%s refused tree connect (%s)\n", host, cli_errstr(&cli)); + cli_shutdown(&cli); + return -1; + } + + return 0; +} + + + +static void close_connection(void) +{ + if (!cli_tdis(&cli)) { + printf("tdis failed (%s)\n", cli_errstr(&cli)); + } + + cli_shutdown(&cli); +} + + + + +static BOOL wait_lock(int fnum, uint32 offset, uint32 len) +{ + while (!cli_lock(&cli, fnum, offset, len, -1)) { + int eclass, num; + cli_error(&cli, &eclass, &num); + if (eclass != ERRDOS || num != ERRlock) { + printf("lock failed (%s)\n", + cli_errstr(&cli)); + return False; + } + } + return True; +} + + +static int rw_torture(int numops) +{ + char *lockfname = "\\torture.lck"; + fstring fname; + int fnum; + int fnum2; + int pid2, pid = getpid(); + int i; + + fnum2 = cli_open(&cli, lockfname, O_RDWR | O_EXCL, DENY_NONE); + if (fnum2 == -1) + fnum2 = cli_open(&cli, lockfname, O_RDWR, DENY_NONE); + if (fnum2 == -1) { + printf("open of %s failed (%s)\n", lockfname, cli_errstr(&cli)); + return -1; + } + + + for (i=0;i\n"); + + printf("\t-U user%%pass\n"); + printf("\t-N numprocs\n"); + printf("\t-n my_netbios_name\n"); + printf("\t-W workgroup\n"); + printf("\t-o num_operations\n"); + printf("\t-O socket_options\n"); + printf("\n"); + + exit(1); +} + + + +static void run_torture(int numops) +{ + if (open_connection() == 0) { + cli_sockopt(&cli, sockops); + + printf("pid %d OK\n", getpid()); + + rw_torture(numops); + + close_connection(); + } +} + + +static void create_procs(int nprocs, int numops) +{ + int i, status; + + for (i=0;i