summaryrefslogtreecommitdiff
path: root/source3/utils/torture.c
diff options
context:
space:
mode:
Diffstat (limited to 'source3/utils/torture.c')
-rw-r--r--source3/utils/torture.c959
1 files changed, 591 insertions, 368 deletions
diff --git a/source3/utils/torture.c b/source3/utils/torture.c
index 6dea2f2d229..9dc9d664b2c 100644
--- a/source3/utils/torture.c
+++ b/source3/utils/torture.c
@@ -23,12 +23,13 @@
#include "includes.h"
-extern int DEBUGLEVEL;
-extern pstring debugf;
-
static fstring host, workgroup, share, password, username, myname;
static int max_protocol = PROTOCOL_NT1;
-static char *sockops="";
+static char *sockops="TCP_NODELAY";
+static int nprocs=1, numops=100;
+static struct cli_state current_cli;
+
+static double create_procs(void (*fn)(int));
static struct timeval tp1,tp2;
@@ -45,82 +46,101 @@ static double end_timer(void)
(tp2.tv_usec - tp1.tv_usec)*1.0e-6);
}
-#define FAILED_NO_ERROR 0
-#define FAILED_TCP_CONNECT 1
-#define FAILED_SESSION_REQ 2
-#define FAILED_SMB_SESS_SETUP 3
-#define FAILED_SMB_TCON 4
-#define FAILED_SMB_NEGPROT 5
-#define FAILED_CLI_STATE_INIT 6
-#define NUM_ERR_STATES 7
-static char *smb_messages[] =
+/* return a pointer to a anonymous shared memory segment of size "size"
+ which will persist across fork() but will disappear when all processes
+ exit
+
+ The memory is not zeroed
+
+ This function uses system5 shared memory. It takes advantage of a property
+ that the memory is not destroyed if it is attached when the id is removed
+ */
+static void *shm_setup(int size)
{
- "No errors in connection",
- "TCP connection ",
- "NetBIOS Session Request",
- "SMB Session Setup ",
- "SMB Tcon ",
- "SMB Negprot ",
- "Client initialisation "
-};
-
-static int open_connection(struct cli_state *c)
+ int shmid;
+ void *ret;
+
+ shmid = shmget(IPC_PRIVATE, size, SHM_R | SHM_W);
+ if (shmid == -1) {
+ printf("can't get shared memory\n");
+ exit(1);
+ }
+ ret = (void *)shmat(shmid, 0, 0);
+ if (!ret || ret == (void *)-1) {
+ printf("can't attach to shared memory\n");
+ return NULL;
+ }
+ /* the following releases the ipc, but note that this process
+ and all its children will still have access to the memory, its
+ just that the shmid is no longer valid for other shm calls. This
+ means we don't leave behind lots of shm segments after we exit
+
+ See Stevens "advanced programming in unix env" for details
+ */
+ shmctl(shmid, IPC_RMID, 0);
+
+ return ret;
+}
+
+
+static BOOL open_connection(struct cli_state *c)
{
struct nmb_name called, calling;
+ struct in_addr ip;
+ extern struct in_addr ipzero;
ZERO_STRUCTP(c);
make_nmb_name(&calling, myname, 0x0, "");
make_nmb_name(&called , host, 0x20, "");
- if (!cli_initialise(c))
- {
- DEBUG(0,("Failed to connect with %s\n", host));
- return FAILED_CLI_STATE_INIT;
- }
+ ip = ipzero;
- if (!cli_connect(c, host, NULL)) {
- DEBUG(0,("Failed to connect with %s\n", host));
- return FAILED_TCP_CONNECT;
+ if (!cli_initialise(c) || !cli_connect(c, host, &ip)) {
+ printf("Failed to connect with %s\n", host);
+ return False;
}
+ c->timeout = 120000; /* set a really long timeout (2 minutes) */
+
if (!cli_session_request(c, &calling, &called)) {
+ printf("%s rejected the session\n",host);
cli_shutdown(c);
- DEBUG(0,("%s rejected the session\n",host));
- return FAILED_SESSION_REQ;
+ return False;
}
if (!cli_negprot(c)) {
- DEBUG(0,("%s rejected the negprot (%s)\n",host, cli_errstr(c)));
+ printf("%s rejected the negprot (%s)\n",host, cli_errstr(c));
cli_shutdown(c);
- return FAILED_SMB_NEGPROT;
+ return False;
}
if (!cli_session_setup(c, username,
password, strlen(password),
password, strlen(password),
workgroup)) {
- DEBUG(0,("%s rejected the sessionsetup (%s)\n", host, cli_errstr(c)));
+ printf("%s rejected the sessionsetup (%s)\n", host, cli_errstr(c));
cli_shutdown(c);
- return FAILED_SMB_SESS_SETUP;
+ return False;
}
if (!cli_send_tconX(c, share, "?????",
password, strlen(password)+1)) {
- DEBUG(0,("%s refused tree connect (%s)\n", host, cli_errstr(c)));
+ printf("%s refused tree connect (%s)\n", host, cli_errstr(c));
cli_shutdown(c);
- return FAILED_SMB_TCON;
+ return False;
}
- return FAILED_NO_ERROR;
+ return True;
}
+
static void close_connection(struct cli_state *c)
{
if (!cli_tdis(c)) {
- DEBUG(0,("tdis failed (%s)\n", cli_errstr(c)));
+ printf("tdis failed (%s)\n", cli_errstr(c));
}
cli_shutdown(c);
@@ -133,14 +153,13 @@ static BOOL check_error(struct cli_state *c,
{
uint8 class;
uint32 num;
- int eno;
- eno = cli_error(c, &class, &num);
+ (void)cli_error(c, &class, &num, NULL);
if ((eclass != class || ecode != num) &&
num != (nterr&0xFFFFFF)) {
- DEBUG(0,("unexpected error code class=%d code=%d\n",
- (int)class, (int)num));
- DEBUG(0,(" expected %d/%d %d\n",
- (int)eclass, (int)ecode, (int)nterr));
+ printf("unexpected error code class=%d code=%d\n",
+ (int)class, (int)num);
+ printf(" expected %d/%d %d\n",
+ (int)eclass, (int)ecode, (int)nterr);
return False;
}
return True;
@@ -156,13 +175,13 @@ static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
}
-static BOOL rw_torture(struct cli_state *c, int numops)
+static BOOL rw_torture(struct cli_state *c)
{
char *lockfname = "\\torture.lck";
fstring fname;
int fnum;
int fnum2;
- int pid2, pid = getpid();
+ pid_t pid2, pid = getpid();
int i, j;
char buf[1024];
@@ -171,7 +190,7 @@ static BOOL rw_torture(struct cli_state *c, int numops)
if (fnum2 == -1)
fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
if (fnum2 == -1) {
- DEBUG(0,("open of %s failed (%s)\n", lockfname, cli_errstr(c)));
+ printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
return False;
}
@@ -179,7 +198,7 @@ static BOOL rw_torture(struct cli_state *c, int numops)
for (i=0;i<numops;i++) {
unsigned n = (unsigned)sys_random()%10;
if (i % 10 == 0) {
- DEBUG(0,("%d\r", i));
+ printf("%d\r", i); fflush(stdout);
}
slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
@@ -189,92 +208,194 @@ static BOOL rw_torture(struct cli_state *c, int numops)
fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
if (fnum == -1) {
- DEBUG(0,("open failed (%s)\n", cli_errstr(c)));
+ printf("open failed (%s)\n", cli_errstr(c));
break;
}
if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
- DEBUG(0,("write failed (%s)\n", cli_errstr(c)));
+ printf("write failed (%s)\n", cli_errstr(c));
}
for (j=0;j<50;j++) {
if (cli_write(c, fnum, 0, (char *)buf,
sizeof(pid)+(j*sizeof(buf)),
sizeof(buf)) != sizeof(buf)) {
- DEBUG(0,("write failed (%s)\n", cli_errstr(c)));
+ printf("write failed (%s)\n", cli_errstr(c));
}
}
pid2 = 0;
if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
- DEBUG(0,("read failed (%s)\n", cli_errstr(c)));
+ printf("read failed (%s)\n", cli_errstr(c));
}
if (pid2 != pid) {
- DEBUG(0,("data corruption!\n"));
+ printf("data corruption!\n");
}
if (!cli_close(c, fnum)) {
- DEBUG(0,("close failed (%s)\n", cli_errstr(c)));
+ printf("close failed (%s)\n", cli_errstr(c));
}
if (!cli_unlink(c, fname)) {
- DEBUG(0,("unlink failed (%s)\n", cli_errstr(c)));
+ printf("unlink failed (%s)\n", cli_errstr(c));
}
if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int), -1)) {
- DEBUG(0,("unlock failed (%s)\n", cli_errstr(c)));
+ printf("unlock failed (%s)\n", cli_errstr(c));
}
}
cli_close(c, fnum2);
cli_unlink(c, lockfname);
- DEBUG(0,("%d\n", i));
+ printf("%d\n", i);
return True;
}
-static void usage(void)
+static void run_torture(int dummy)
{
- printf("Usage: smbtorture //server/share <options>\n");
+ struct cli_state cli;
- 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("\t-m maximum protocol\n");
- printf("\n");
+ cli = current_cli;
- exit(1);
-}
+ cli_sockopt(&cli, sockops);
+ rw_torture(&cli);
+
+ close_connection(&cli);
+}
+int line_count = 0;
-static void run_torture(int numops)
+/* run a test that simulates an approximate netbench client load */
+static void run_netbench(int client)
{
- static struct cli_state cli;
+ struct cli_state cli;
+ int i;
+ fstring fname;
+ pstring line;
+ char cname[20];
+ FILE *f;
+ char *params[20];
+
+ cli = current_cli;
+
+ cli_sockopt(&cli, sockops);
- if (open_connection(&cli) == 0)
- {
- cli_sockopt(&cli, sockops);
+ nb_setup(&cli);
- DEBUG(0,("pid %d OK\n", getpid()));
+ slprintf(cname,sizeof(fname), "CLIENT%d", client);
- rw_torture(&cli, numops);
+ f = fopen("client.txt", "r");
- close_connection(&cli);
+ if (!f) {
+ perror("client.txt");
+ return;
}
- else
- {
- DEBUG(0,("pid %d failed\n", getpid()));
+
+ while (fgets(line, sizeof(line)-1, f)) {
+ line_count++;
+
+ line[strlen(line)-1] = 0;
+
+ /* printf("[%d] %s\n", line_count, line); */
+
+ all_string_sub(line,"CLIENT1", cname, sizeof(line));
+
+ for (i=0;i<20;i++) params[i] = "";
+
+ /* parse the command parameters */
+ params[0] = strtok(line," ");
+ i = 0;
+ while (params[i]) params[++i] = strtok(NULL," ");
+
+ params[i] = "";
+
+ if (i < 2) continue;
+
+ if (strcmp(params[1],"REQUEST") == 0) {
+ if (!strcmp(params[0],"SMBopenX")) {
+ fstrcpy(fname, params[5]);
+ } else if (!strcmp(params[0],"SMBclose")) {
+ nb_close(atoi(params[3]));
+ } else if (!strcmp(params[0],"SMBmkdir")) {
+ nb_mkdir(params[3]);
+ } else if (!strcmp(params[0],"CREATE")) {
+ nb_create(params[3], atoi(params[5]));
+ } else if (!strcmp(params[0],"SMBrmdir")) {
+ nb_rmdir(params[3]);
+ } else if (!strcmp(params[0],"SMBunlink")) {
+ fstrcpy(fname, params[3]);
+ } else if (!strcmp(params[0],"SMBmv")) {
+ nb_rename(params[3], params[5]);
+ } else if (!strcmp(params[0],"SMBgetatr")) {
+ fstrcpy(fname, params[3]);
+ } else if (!strcmp(params[0],"SMBwrite")) {
+ nb_write(atoi(params[3]),
+ atoi(params[5]), atoi(params[7]));
+ } else if (!strcmp(params[0],"SMBwritebraw")) {
+ nb_write(atoi(params[3]),
+ atoi(params[7]), atoi(params[5]));
+ } else if (!strcmp(params[0],"SMBreadbraw")) {
+ nb_read(atoi(params[3]),
+ atoi(params[7]), atoi(params[5]));
+ } else if (!strcmp(params[0],"SMBread")) {
+ nb_read(atoi(params[3]),
+ atoi(params[5]), atoi(params[7]));
+ }
+ } else {
+ if (!strcmp(params[0],"SMBopenX")) {
+ if (!strncmp(params[2], "ERR", 3)) continue;
+ nb_open(fname, atoi(params[3]), atoi(params[5]));
+ } else if (!strcmp(params[0],"SMBgetatr")) {
+ if (!strncmp(params[2], "ERR", 3)) continue;
+ nb_stat(fname, atoi(params[3]));
+ } else if (!strcmp(params[0],"SMBunlink")) {
+ if (!strncmp(params[2], "ERR", 3)) continue;
+ nb_unlink(fname);
+ }
+ }
}
+ fclose(f);
+
+ slprintf(fname,sizeof(fname), "CLIENTS/CLIENT%d", client);
+ rmdir(fname);
+ rmdir("CLIENTS");
+ printf("+");
+
+ close_connection(&cli);
}
+
+/* run a test that simulates an approximate netbench w9X client load */
+static void run_nbw95(int dummy)
+{
+ double t;
+ t = create_procs(run_netbench);
+ /* to produce a netbench result we scale accoding to the
+ netbench measured throughput for the run that produced the
+ sniff that was used to produce client.txt. That run used 2
+ clients and ran for 660 seconds to produce a result of
+ 4MBit/sec. */
+ printf("Throughput %g MB/sec (NB=%g MB/sec %g MBit/sec)\n",
+ 132*nprocs/t, 0.5*0.5*nprocs*660/t, 2*nprocs*660/t);
+}
+
+/* run a test that simulates an approximate netbench wNT client load */
+static void run_nbwnt(int dummy)
+{
+ double t;
+ t = create_procs(run_netbench);
+ printf("Throughput %g MB/sec (NB=%g MB/sec %g MBit/sec)\n",
+ 132*nprocs/t, 0.5*0.5*nprocs*660/t, 2*nprocs*660/t);
+}
+
+
+
/*
This test checks for two things:
@@ -282,57 +403,57 @@ static void run_torture(int numops)
must not use posix semantics)
2) support for lock timeouts
*/
-static void run_locktest1(void)
+static void run_locktest1(int dummy)
{
static struct cli_state cli1, cli2;
char *fname = "\\lockt1.lck";
int fnum1, fnum2, fnum3;
time_t t1, t2;
- if (open_connection(&cli1) != 0 || open_connection(&cli2) != 0) {
+ if (!open_connection(&cli1) || !open_connection(&cli2)) {
return;
}
cli_sockopt(&cli1, sockops);
cli_sockopt(&cli2, sockops);
- DEBUG(0,("starting locktest1\n"));
+ printf("starting locktest1\n");
cli_unlink(&cli1, fname);
fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
if (fnum1 == -1) {
- DEBUG(0,("open of %s failed (%s)\n", fname, cli_errstr(&cli1)));
+ printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
return;
}
fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
if (fnum2 == -1) {
- DEBUG(0,("open2 of %s failed (%s)\n", fname, cli_errstr(&cli1)));
+ printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
return;
}
fnum3 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
if (fnum3 == -1) {
- DEBUG(0,("open3 of %s failed (%s)\n", fname, cli_errstr(&cli2)));
+ printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli2));
return;
}
if (!cli_lock(&cli1, fnum1, 0, 4, 0)) {
- DEBUG(0,("lock1 failed (%s)\n", cli_errstr(&cli1)));
+ printf("lock1 failed (%s)\n", cli_errstr(&cli1));
return;
}
if (cli_lock(&cli2, fnum3, 0, 4, 0)) {
- DEBUG(0,("lock2 succeeded! This is a locking bug\n"));
+ printf("lock2 succeeded! This is a locking bug\n");
return;
} else {
if (!check_error(&cli2, ERRDOS, ERRlock, 0)) return;
}
- DEBUG(0,("Testing lock timeouts\n"));
+ printf("Testing lock timeouts\n");
t1 = time(NULL);
if (cli_lock(&cli2, fnum3, 0, 4, 10*1000)) {
- DEBUG(0,("lock3 succeeded! This is a locking bug\n"));
+ printf("lock3 succeeded! This is a locking bug\n");
return;
} else {
if (!check_error(&cli2, ERRDOS, ERRlock, 0)) return;
@@ -340,33 +461,33 @@ static void run_locktest1(void)
t2 = time(NULL);
if (t2 - t1 < 5) {
- DEBUG(0,("error: This server appears not to support timed lock requests\n"));
+ printf("error: This server appears not to support timed lock requests\n");
}
if (!cli_close(&cli1, fnum2)) {
- DEBUG(0,("close1 failed (%s)\n", cli_errstr(&cli1)));
+ printf("close1 failed (%s)\n", cli_errstr(&cli1));
return;
}
if (cli_lock(&cli2, fnum3, 0, 4, 0)) {
- DEBUG(0,("lock4 succeeded! This is a locking bug\n"));
+ printf("lock4 succeeded! This is a locking bug\n");
return;
} else {
if (!check_error(&cli2, ERRDOS, ERRlock, 0)) return;
}
if (!cli_close(&cli1, fnum1)) {
- DEBUG(0,("close2 failed (%s)\n", cli_errstr(&cli1)));
+ printf("close2 failed (%s)\n", cli_errstr(&cli1));
return;
}
if (!cli_close(&cli2, fnum3)) {
- DEBUG(0,("close3 failed (%s)\n", cli_errstr(&cli2)));
+ printf("close3 failed (%s)\n", cli_errstr(&cli2));
return;
}
if (!cli_unlink(&cli1, fname)) {
- DEBUG(0,("unlink failed (%s)\n", cli_errstr(&cli1)));
+ printf("unlink failed (%s)\n", cli_errstr(&cli1));
return;
}
@@ -374,7 +495,7 @@ static void run_locktest1(void)
close_connection(&cli1);
close_connection(&cli2);
- DEBUG(0,("Passed locktest1\n"));
+ printf("Passed locktest1\n");
}
@@ -389,19 +510,19 @@ static void run_locktest1(void)
3) the server denies unlock requests by an incorrect client PID
*/
-static void run_locktest2(void)
+static void run_locktest2(int dummy)
{
static struct cli_state cli;
char *fname = "\\lockt2.lck";
int fnum1, fnum2, fnum3;
- if (open_connection(&cli) != 0) {
+ if (!open_connection(&cli)) {
return;
}
cli_sockopt(&cli, sockops);
- DEBUG(0,("starting locktest2\n"));
+ printf("starting locktest2\n");
cli_unlink(&cli, fname);
@@ -409,13 +530,13 @@ static void run_locktest2(void)
fnum1 = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
if (fnum1 == -1) {
- DEBUG(0,("open of %s failed (%s)\n", fname, cli_errstr(&cli)));
+ printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
return;
}
fnum2 = cli_open(&cli, fname, O_RDWR, DENY_NONE);
if (fnum2 == -1) {
- DEBUG(0,("open2 of %s failed (%s)\n", fname, cli_errstr(&cli)));
+ printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli));
return;
}
@@ -423,19 +544,19 @@ static void run_locktest2(void)
fnum3 = cli_open(&cli, fname, O_RDWR, DENY_NONE);
if (fnum3 == -1) {
- DEBUG(0,("open3 of %s failed (%s)\n", fname, cli_errstr(&cli)));
+ printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli));
return;
}
cli_setpid(&cli, 1);
if (!cli_lock(&cli, fnum1, 0, 4, 0)) {
- DEBUG(0,("lock1 failed (%s)\n", cli_errstr(&cli)));
+ printf("lock1 failed (%s)\n", cli_errstr(&cli));
return;
}
if (cli_lock(&cli, fnum2, 0, 4, 0)) {
- DEBUG(0,("lock2 succeeded! This is a locking bug\n"));
+ printf("lock2 succeeded! This is a locking bug\n");
} else {
if (!check_error(&cli, ERRDOS, ERRlock, 0)) return;
}
@@ -443,11 +564,11 @@ static void run_locktest2(void)
cli_setpid(&cli, 2);
if (cli_unlock(&cli, fnum1, 0, 4, 0)) {
- DEBUG(0,("unlock1 succeeded! This is a locking bug\n"));
+ printf("unlock1 succeeded! This is a locking bug\n");
}
if (cli_lock(&cli, fnum3, 0, 4, 0)) {
- DEBUG(0,("lock3 succeeded! This is a locking bug\n"));
+ printf("lock3 succeeded! This is a locking bug\n");
} else {
if (!check_error(&cli, ERRDOS, ERRlock, 0)) return;
}
@@ -455,23 +576,23 @@ static void run_locktest2(void)
cli_setpid(&cli, 1);
if (!cli_close(&cli, fnum1)) {
- DEBUG(0,("close1 failed (%s)\n", cli_errstr(&cli)));
+ printf("close1 failed (%s)\n", cli_errstr(&cli));
return;
}
if (!cli_close(&cli, fnum2)) {
- DEBUG(0,("close2 failed (%s)\n", cli_errstr(&cli)));
+ printf("close2 failed (%s)\n", cli_errstr(&cli));
return;
}
if (!cli_close(&cli, fnum3)) {
- DEBUG(0,("close3 failed (%s)\n", cli_errstr(&cli)));
+ printf("close3 failed (%s)\n", cli_errstr(&cli));
return;
}
close_connection(&cli);
- DEBUG(0,("locktest2 finished\n"));
+ printf("locktest2 finished\n");
}
@@ -480,7 +601,7 @@ static void run_locktest2(void)
1) the server supports the full offset range in lock requests
*/
-static void run_locktest3(int numops)
+static void run_locktest3(int dummy)
{
static struct cli_state cli1, cli2;
char *fname = "\\lockt3.lck";
@@ -489,40 +610,40 @@ static void run_locktest3(int numops)
#define NEXT_OFFSET offset += (~(uint32)0) / numops
- if (open_connection(&cli1) != 0 || open_connection(&cli2) != 0) {
+ if (!open_connection(&cli1) || !open_connection(&cli2)) {
return;
}
cli_sockopt(&cli1, sockops);
cli_sockopt(&cli2, sockops);
- DEBUG(0,("starting locktest3\n"));
+ printf("starting locktest3\n");
cli_unlink(&cli1, fname);
fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
if (fnum1 == -1) {
- DEBUG(0,("open of %s failed (%s)\n", fname, cli_errstr(&cli1)));
+ printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
return;
}
fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
if (fnum2 == -1) {
- DEBUG(0,("open2 of %s failed (%s)\n", fname, cli_errstr(&cli2)));
+ printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
return;
}
for (offset=i=0;i<numops;i++) {
NEXT_OFFSET;
if (!cli_lock(&cli1, fnum1, offset-1, 1, 0)) {
- DEBUG(0,("lock1 %d failed (%s)\n",
+ printf("lock1 %d failed (%s)\n",
i,
- cli_errstr(&cli1)));
+ cli_errstr(&cli1));
return;
}
if (!cli_lock(&cli2, fnum2, offset-2, 1, 0)) {
- DEBUG(0,("lock2 %d failed (%s)\n",
+ printf("lock2 %d failed (%s)\n",
i,
- cli_errstr(&cli1)));
+ cli_errstr(&cli1));
return;
}
}
@@ -531,22 +652,22 @@ static void run_locktest3(int numops)
NEXT_OFFSET;
if (cli_lock(&cli1, fnum1, offset-2, 1, 0)) {
- DEBUG(0,("error: lock1 %d succeeded!\n", i));
+ printf("error: lock1 %d succeeded!\n", i);
return;
}
if (cli_lock(&cli2, fnum2, offset-1, 1, 0)) {
- DEBUG(0,("error: lock2 %d succeeded!\n", i));
+ printf("error: lock2 %d succeeded!\n", i);
return;
}
if (cli_lock(&cli1, fnum1, offset-1, 1, 0)) {
- DEBUG(0,("error: lock3 %d succeeded!\n", i));
+ printf("error: lock3 %d succeeded!\n", i);
return;
}
if (cli_lock(&cli2, fnum2, offset-2, 1, 0)) {
- DEBUG(0,("error: lock4 %d succeeded!\n", i));
+ printf("error: lock4 %d succeeded!\n", i);
return;
}
}
@@ -555,37 +676,37 @@ static void run_locktest3(int numops)
NEXT_OFFSET;
if (!cli_unlock(&cli1, fnum1, offset-1, 1, 0)) {
- DEBUG(0,("unlock1 %d failed (%s)\n",
+ printf("unlock1 %d failed (%s)\n",
i,
- cli_errstr(&cli1)));
+ cli_errstr(&cli1));
return;
}
if (!cli_unlock(&cli2, fnum2, offset-2, 1, 0)) {
- DEBUG(0,("unlock2 %d failed (%s)\n",
+ printf("unlock2 %d failed (%s)\n",
i,
- cli_errstr(&cli1)));
+ cli_errstr(&cli1));
return;
}
}
if (!cli_close(&cli1, fnum1)) {
- DEBUG(0,("close1 failed (%s)\n", cli_errstr(&cli1)));
+ printf("close1 failed (%s)\n", cli_errstr(&cli1));
}
if (!cli_close(&cli2, fnum2)) {
- DEBUG(0,("close2 failed (%s)\n", cli_errstr(&cli2)));
+ printf("close2 failed (%s)\n", cli_errstr(&cli2));
}
if (!cli_unlink(&cli1, fname)) {
- DEBUG(0,("unlink failed (%s)\n", cli_errstr(&cli1)));
+ printf("unlink failed (%s)\n", cli_errstr(&cli1));
return;
}
close_connection(&cli1);
close_connection(&cli2);
- DEBUG(0,("finished locktest3\n"));
+ printf("finished locktest3\n");
}
@@ -593,31 +714,31 @@ static void run_locktest3(int numops)
test whether fnums and tids open on one VC are available on another (a major
security hole)
*/
-static void run_fdpasstest(void)
+static void run_fdpasstest(int dummy)
{
static struct cli_state cli1, cli2;
char *fname = "\\fdpass.tst";
int fnum1;
pstring buf;
- if (open_connection(&cli1) != 0 || open_connection(&cli2) != 0) {
+ if (!open_connection(&cli1) || !open_connection(&cli2)) {
return;
}
cli_sockopt(&cli1, sockops);
cli_sockopt(&cli2, sockops);
- DEBUG(0,("starting fdpasstest\n"));
+ printf("starting fdpasstest\n");
cli_unlink(&cli1, fname);
fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
if (fnum1 == -1) {
- DEBUG(0,("open of %s failed (%s)\n", fname, cli_errstr(&cli1)));
+ printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
return;
}
if (cli_write(&cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
- DEBUG(0,("write failed (%s)\n", cli_errstr(&cli1)));
+ printf("write failed (%s)\n", cli_errstr(&cli1));
return;
}
@@ -627,8 +748,8 @@ static void run_fdpasstest(void)
if (cli_read(&cli2, fnum1, buf, 0, 13) == 13) {
- DEBUG(0,("read succeeded! nasty security hole [%s]\n",
- buf));
+ printf("read succeeded! nasty security hole [%s]\n",
+ buf);
return;
}
@@ -638,7 +759,7 @@ static void run_fdpasstest(void)
close_connection(&cli1);
close_connection(&cli2);
- DEBUG(0,("finished fdpasstest\n"));
+ printf("finished fdpasstest\n");
}
@@ -647,19 +768,19 @@ static void run_fdpasstest(void)
1) the server does not allow an unlink on a file that is open
*/
-static void run_unlinktest(void)
+static void run_unlinktest(int dummy)
{
static struct cli_state cli;
char *fname = "\\unlink.tst";
int fnum;
- if (open_connection(&cli) != 0) {
+ if (!open_connection(&cli)) {
return;
}
cli_sockopt(&cli, sockops);
- DEBUG(0,("starting unlink test\n"));
+ printf("starting unlink test\n");
cli_unlink(&cli, fname);
@@ -667,12 +788,12 @@ static void run_unlinktest(void)
fnum = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
if (fnum == -1) {
- DEBUG(0,("open of %s failed (%s)\n", fname, cli_errstr(&cli)));
+ printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
return;
}
if (cli_unlink(&cli, fname)) {
- DEBUG(0,("error: server allowed unlink on an open file\n"));
+ printf("error: server allowed unlink on an open file\n");
}
cli_close(&cli, fnum);
@@ -680,59 +801,56 @@ static void run_unlinktest(void)
close_connection(&cli);
- DEBUG(0,("unlink test finished\n"));
+ printf("unlink test finished\n");
}
/*
test how many open files this server supports on the one socket
*/
-static void run_maxfidtest(int n)
+static void run_maxfidtest(int dummy)
{
static struct cli_state cli;
char *template = "\\maxfid.%d.%d";
fstring fname;
int fnum;
int retries=4;
+ int n = numops;
- srandom(getpid());
-
- while (open_connection(&cli) != 0 && retries--) msleep(random() % 2000);
+ cli = current_cli;
if (retries <= 0) {
- DEBUG(0,("failed to connect\n"));
+ printf("failed to connect\n");
return;
}
cli_sockopt(&cli, sockops);
- DEBUG(0,("starting maxfid test\n"));
-
fnum = 0;
while (1) {
- slprintf(fname,sizeof(fname)-1,template, fnum,getpid());
+ slprintf(fname,sizeof(fname)-1,template, fnum,(int)getpid());
if (cli_open(&cli, fname,
O_RDWR|O_CREAT|O_TRUNC, DENY_NONE) ==
-1) {
- DEBUG(0,("open of %s failed (%s)\n",
- fname, cli_errstr(&cli)));
- DEBUG(0,("maximum fnum is %d\n", fnum));
+ printf("open of %s failed (%s)\n",
+ fname, cli_errstr(&cli));
+ printf("maximum fnum is %d\n", fnum);
break;
}
fnum++;
}
- DEBUG(0,("cleaning up\n"));
+ printf("cleaning up\n");
while (fnum > n) {
fnum--;
- slprintf(fname,sizeof(fname)-1,template, fnum,getpid());
+ slprintf(fname,sizeof(fname)-1,template, fnum,(int)getpid());
if (cli_unlink(&cli, fname)) {
- DEBUG(0,("unlink of %s failed (%s)\n",
- fname, cli_errstr(&cli)));
+ printf("unlink of %s failed (%s)\n",
+ fname, cli_errstr(&cli));
}
}
- DEBUG(0,("maxfid test finished\n"));
+ printf("maxfid test finished\n");
close_connection(&cli);
}
@@ -740,116 +858,45 @@ static void run_maxfidtest(int n)
static void rand_buf(char *buf, int len)
{
while (len--) {
- *buf = sys_random();
+ *buf = (char)sys_random();
buf++;
}
}
-#define TORT_BUFFER_SIZE 1024
-
/* send random IPC commands */
-static void run_randomipc(int numops)
+static void run_randomipc(int dummy)
{
char *rparam = NULL;
char *rdata = NULL;
int rdrcnt,rprcnt;
- char param[TORT_BUFFER_SIZE];
+ pstring param;
int api, param_len, i;
- int reconnect_count = 500;
static struct cli_state cli;
- DEBUG(0,("starting random ipc test\n"));
-
- while (reconnect_count > 0 && open_connection(&cli) != 0)
- {
- DEBUG(0,("connection failed: retrying %d\n", reconnect_count));
- msleep(sys_random() % 5000);
- reconnect_count--;
- }
+ printf("starting random ipc test\n");
- if (reconnect_count == 0)
- {
+ if (!open_connection(&cli)) {
return;
}
- for (i=0;i<numops * 100;i++)
- {
+ for (i=0;i<50000;i++) {
api = sys_random() % 500;
- if ((sys_random() % 10) == 0)
- {
- param_len = (sys_random() % TORT_BUFFER_SIZE);
- }
- else
- {
- param_len = (sys_random() % 64);
- }
+ param_len = (sys_random() % 64);
rand_buf(param, param_len);
SSVAL(param,0,api);
- cli_api(&cli,
+ cli_api(&cli,
param, param_len, 8,
NULL, 0, BUFFER_SIZE,
- &rparam, &rprcnt,
+ &rparam, &rprcnt,
&rdata, &rdrcnt);
}
close_connection(&cli);
- DEBUG(0,("finished random ipc test\n"));
-}
-
-/* send random IPC commands */
-static void run_randomipc_nowait(int numops)
-{
- char param[TORT_BUFFER_SIZE];
- int api, param_len, i;
- int reconnect_count = 500;
- static struct cli_state cli;
-
- DEBUG(0,("start random ipc test no waiting for SMBtrans response\n"));
-
- while (reconnect_count > 0 && open_connection(&cli) != 0)
- {
- DEBUG(0,("connection failed: retrying %d\n", reconnect_count));
- msleep(sys_random() % 5000);
- reconnect_count--;
- }
-
- if (reconnect_count == 0)
- {
- return;
- }
-
- for (i=0;i<numops * 100;i++)
- {
- api = sys_random() % 500;
- if ((sys_random() % 10) == 0)
- {
- param_len = (sys_random() % TORT_BUFFER_SIZE);
- }
- else
- {
- param_len = (sys_random() % 64);
- }
-
- rand_buf(param, param_len);
-
- SSVAL(param,0,api);
-
- cli_send_trans(&cli,SMBtrans,
- PIPE_LANMAN,strlen(PIPE_LANMAN), /* Name, length */
- 0,0, /* fid, flags */
- NULL,0,0, /* Setup, length, max */
-
- param, param_len, 8,
- NULL, 0, BUFFER_SIZE);
- }
-
- close_connection(&cli);
-
- DEBUG(0,("finished random ipc test\n"));
+ printf("finished random ipc test\n");
}
@@ -857,7 +904,7 @@ static void run_randomipc_nowait(int numops)
static void browse_callback(const char *sname, uint32 stype,
const char *comment)
{
- DEBUG(0,("\t%20.20s %08x %s\n", sname, stype, comment));
+ printf("\t%20.20s %08x %s\n", sname, stype, comment);
}
@@ -866,45 +913,45 @@ static void browse_callback(const char *sname, uint32 stype,
This test checks the browse list code
*/
-static void run_browsetest(void)
+static void run_browsetest(int dummy)
{
static struct cli_state cli;
- DEBUG(0,("starting browse test\n"));
+ printf("starting browse test\n");
- if (open_connection(&cli) != 0) {
+ if (!open_connection(&cli)) {
return;
}
- DEBUG(0,("domain list:\n"));
- cli_NetServerEnum(&cli, workgroup,
+ printf("domain list:\n");
+ cli_NetServerEnum(&cli, cli.server_domain,
SV_TYPE_DOMAIN_ENUM,
browse_callback);
- DEBUG(0,("machine list:\n"));
- cli_NetServerEnum(&cli, workgroup,
+ printf("machine list:\n");
+ cli_NetServerEnum(&cli, cli.server_domain,
SV_TYPE_ALL,
browse_callback);
close_connection(&cli);
- DEBUG(0,("browse test finished\n"));
+ printf("browse test finished\n");
}
/*
This checks how the getatr calls works
*/
-static void run_attrtest(void)
+static void run_attrtest(int dummy)
{
static struct cli_state cli;
int fnum;
time_t t, t2;
char *fname = "\\attrib.tst";
- DEBUG(0,("starting attrib test\n"));
+ printf("starting attrib test\n");
- if (open_connection(&cli) != 0) {
+ if (!open_connection(&cli)) {
return;
}
@@ -913,43 +960,43 @@ static void run_attrtest(void)
O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
cli_close(&cli, fnum);
if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
- DEBUG(0,("getatr failed (%s)\n", cli_errstr(&cli)));
+ printf("getatr failed (%s)\n", cli_errstr(&cli));
}
if (abs(t - time(NULL)) > 2) {
- DEBUG(0,("ERROR: SMBgetatr bug. time is %s",
- ctime(&t)));
+ printf("ERROR: SMBgetatr bug. time is %s",
+ ctime(&t));
t = time(NULL);
}
t2 = t-60*60*24; /* 1 day ago */
if (!cli_setatr(&cli, fname, 0, t2)) {
- DEBUG(0,("setatr failed (%s)\n", cli_errstr(&cli)));
+ printf("setatr failed (%s)\n", cli_errstr(&cli));
}
if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
- DEBUG(0,("getatr failed (%s)\n", cli_errstr(&cli)));
+ printf("getatr failed (%s)\n", cli_errstr(&cli));
}
if (t != t2) {
- DEBUG(0,("ERROR: getatr/setatr bug. times are\n%s",
- ctime(&t)));
- DEBUG(0,("%s", ctime(&t2)));
+ printf("ERROR: getatr/setatr bug. times are\n%s",
+ ctime(&t));
+ printf("%s", ctime(&t2));
}
cli_unlink(&cli, fname);
close_connection(&cli);
- DEBUG(0,("attrib test finished\n"));
+ printf("attrib test finished\n");
}
/*
This checks a couple of trans2 calls
*/
-static void run_trans2test(void)
+static void run_trans2test(int dummy)
{
static struct cli_state cli;
int fnum;
@@ -959,9 +1006,9 @@ static void run_trans2test(void)
char *dname = "\\trans2";
char *fname2 = "\\trans2\\trans2.tst";
- DEBUG(0,("starting trans2 test\n"));
+ printf("starting trans2 test\n");
- if (open_connection(&cli) != 0) {
+ if (!open_connection(&cli)) {
return;
}
@@ -970,7 +1017,7 @@ static void run_trans2test(void)
O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
if (!cli_qfileinfo(&cli, fnum, NULL, &size, &c_time, &a_time, &m_time,
NULL, NULL)) {
- DEBUG(0,("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli)));
+ printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli));
}
cli_close(&cli, fnum);
@@ -982,20 +1029,20 @@ static void run_trans2test(void)
cli_close(&cli, fnum);
if (!cli_qpathinfo(&cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
- DEBUG(0,("ERROR: qpathinfo failed (%s)\n", cli_errstr(&cli)));
+ printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(&cli));
} else {
if (c_time != m_time) {
- DEBUG(0,("create time=%s", ctime(&c_time)));
- DEBUG(0,("modify time=%s", ctime(&m_time)));
- DEBUG(0,("This system appears to have sticky create times\n"));
+ printf("create time=%s", ctime(&c_time));
+ printf("modify time=%s", ctime(&m_time));
+ printf("This system appears to have sticky create times\n");
}
if (a_time % (60*60) == 0) {
- DEBUG(0,("access time=%s", ctime(&a_time)));
- DEBUG(0,("This system appears to set a midnight access time\n"));
+ printf("access time=%s", ctime(&a_time));
+ printf("This system appears to set a midnight access time\n");
}
if (abs(m_time - time(NULL)) > 60*60*24*7) {
- DEBUG(0,("ERROR: totally incorrect times - maybe word reversed?\n"));
+ printf("ERROR: totally incorrect times - maybe word reversed?\n");
}
}
@@ -1006,11 +1053,11 @@ static void run_trans2test(void)
cli_close(&cli, fnum);
if (!cli_qpathinfo2(&cli, fname, &c_time, &a_time, &m_time,
&w_time, &size, NULL, NULL)) {
- DEBUG(0,("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)));
+ printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
} else {
if (w_time < 60*60*24*2) {
- DEBUG(0,("write time=%s", ctime(&w_time)));
- DEBUG(0,("This system appears to set a initial 0 write time\n"));
+ printf("write time=%s", ctime(&w_time));
+ printf("This system appears to set a initial 0 write time\n");
}
}
@@ -1020,12 +1067,12 @@ static void run_trans2test(void)
/* check if the server updates the directory modification time
when creating a new file */
if (!cli_mkdir(&cli, dname)) {
- DEBUG(0,("ERROR: mkdir failed (%s)\n", cli_errstr(&cli)));
+ printf("ERROR: mkdir failed (%s)\n", cli_errstr(&cli));
}
sleep(3);
if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time,
&w_time, &size, NULL, NULL)) {
- DEBUG(0,("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)));
+ printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
}
fnum = cli_open(&cli, fname2,
@@ -1034,10 +1081,10 @@ static void run_trans2test(void)
cli_close(&cli, fnum);
if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time2,
&w_time, &size, NULL, NULL)) {
- DEBUG(0,("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)));
+ printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
} else {
if (m_time2 == m_time)
- DEBUG(0,("This system does not update directory modification times\n"));
+ printf("This system does not update directory modification times\n");
}
cli_unlink(&cli, fname2);
cli_rmdir(&cli, dname);
@@ -1045,105 +1092,298 @@ static void run_trans2test(void)
close_connection(&cli);
- DEBUG(0,("trans2 test finished\n"));
+ printf("trans2 test finished\n");
}
-static void run_connection(int numops)
+/*
+ this is a harness for some oplock tests
+ */
+static void run_oplock(int dummy)
{
- struct cli_state c;
- int count = 0;
- int failed[NUM_ERR_STATES];
- int i;
+ static struct cli_state cli1, cli2;
+ char *fname = "\\lockt1.lck";
+ char *fname2 = "\\lockt2.lck";
+ int fnum1, fnum2;
- DEBUG(0,("Connection test starts:\n"));
+ printf("starting oplock test\n");
- for (i = 0; i < NUM_ERR_STATES; i++)
- {
- failed[i] = 0;
+ if (!open_connection(&cli1)) {
+ return;
}
- for (i = 0; i < numops; i++)
- {
- int err;
- DEBUG(0,("Connection test %d %d\n", i, numops));
- if ((err = open_connection(&c)))
- {
- failed[err]++;
- }
- count++;
+ cli_unlink(&cli1, fname);
+
+ cli_sockopt(&cli1, sockops);
+
+ cli1.use_oplocks = True;
+
+ fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
+ if (fnum1 == -1) {
+ printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
+ return;
+ }
+
+ cli1.use_oplocks = False;
+
+ cli_unlink(&cli1, fname);
+ cli_unlink(&cli1, fname);
+
+ if (!cli_close(&cli1, fnum1)) {
+ printf("close2 failed (%s)\n", cli_errstr(&cli1));
+ return;
}
- {
- int failtotal = 0;
+ if (!cli_unlink(&cli1, fname)) {
+ printf("unlink failed (%s)\n", cli_errstr(&cli1));
+ return;
+ }
+
+
+ close_connection(&cli1);
+
+ printf("finished oplock test\n");
+}
+
+
+static void list_fn(file_info *finfo, const char *name)
+{
+
+}
+
+/*
+ test directory listing speed
+ */
+static void run_dirtest(int dummy)
+{
+ int i;
+ static struct cli_state cli;
+ int fnum;
+ double t1;
+
+ printf("starting directory test\n");
+
+ if (!open_connection(&cli)) {
+ return;
+ }
+
+ cli_sockopt(&cli, sockops);
- for (i = 0, failtotal = 0; i < NUM_ERR_STATES; i++)
- {
- failtotal += failed[i];
+ srandom(0);
+ for (i=0;i<numops;i++) {
+ fstring fname;
+ slprintf(fname, sizeof(fname), "%x", random());
+ fnum = cli_open(&cli, fname, O_RDWR|O_CREAT, DENY_NONE);
+ if (fnum == -1) {
+ fprintf(stderr,"Failed to open %s\n", fname);
+ return;
}
- DEBUG(0,("Connection test results: count %d success %d\n", count, count-failtotal));
+ cli_close(&cli, fnum);
}
- for (i = 0; i < NUM_ERR_STATES; i++)
- {
- DEBUG(0,("%s: failed: %d\n", smb_messages[i], failed[i]));
+
+ t1 = end_timer();
+
+ printf("Matched %d\n", cli_list(&cli, "a*.*", 0, list_fn));
+ printf("Matched %d\n", cli_list(&cli, "b*.*", 0, list_fn));
+ printf("Matched %d\n", cli_list(&cli, "xyzabc", 0, list_fn));
+
+ printf("dirtest core %g seconds\n", end_timer() - t1);
+
+ srandom(0);
+ for (i=0;i<numops;i++) {
+ fstring fname;
+ slprintf(fname, sizeof(fname), "%x", random());
+ cli_unlink(&cli, fname);
}
+
+ close_connection(&cli);
+
+ printf("finished dirtest\n");
}
-static void create_procs(int nprocs, int numops, void (*fn)(int ))
+
+
+static double create_procs(void (*fn)(int))
{
int i, status;
+ volatile int *child_status;
+ int synccount;
+ int tries = 8;
- for (i=0;i<nprocs;i++)
- {
- if (fork() == 0)
- {
- int mypid = getpid();
- sys_srandom(mypid ^ time(NULL));
-
- if (!dbg_interactive())
- {
- slprintf(debugf, sizeof(debugf), "./log.torture.%d", mypid);
- reopen_logs();
+ start_timer();
+
+ synccount = 0;
+
+ child_status = (volatile int *)shm_setup(sizeof(int)*nprocs);
+ if (!child_status) {
+ printf("Failed to setup shared memory\n");
+ return end_timer();
+ }
+
+ memset((char *)child_status, 0, sizeof(int)*nprocs);
+
+ for (i=0;i<nprocs;i++) {
+ if (fork() == 0) {
+ pid_t mypid = getpid();
+ sys_srandom(((int)mypid) ^ ((int)time(NULL)));
+
+ slprintf(myname,sizeof(myname),"CLIENT%d", i);
+
+ while (1) {
+ memset(&current_cli, 0, sizeof(current_cli));
+ if (open_connection(&current_cli)) break;
+ if (tries-- == 0) {
+ printf("pid %d failed to start\n", (int)getpid());
+ _exit(1);
+ }
+ msleep(10);
}
- fn(numops);
- dbgflush();
+ child_status[i] = getpid();
+
+ while (child_status[i]) msleep(2);
+
+ fn(i);
_exit(0);
}
}
- for (i=0;i<nprocs;i++)
- {
+ do {
+ synccount = 0;
+ for (i=0;i<nprocs;i++) {
+ if (child_status[i]) synccount++;
+ }
+ if (synccount == nprocs) break;
+ msleep(10);
+ } while (end_timer() < 30);
+
+ if (synccount != nprocs) {
+ printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
+ return end_timer();
+ }
+
+ /* start the client load */
+ start_timer();
+
+ for (i=0;i<nprocs;i++) {
+ child_status[i] = 0;
+ }
+
+ printf("%d clients started\n", nprocs);
+
+ for (i=0;i<nprocs;i++) {
waitpid(0, &status, 0);
+ printf("*");
}
+ printf("\n");
+ return end_timer();
}
+#define FLAG_MULTIPROC 1
+
+static struct {
+ char *name;
+ void (*fn)(int);
+ unsigned flags;
+} torture_ops[] = {
+ {"FDPASS", run_fdpasstest, 0},
+ {"LOCK1", run_locktest1, 0},
+ {"LOCK2", run_locktest2, 0},
+ {"LOCK3", run_locktest3, 0},
+ {"UNLINK", run_unlinktest, 0},
+ {"BROWSE", run_browsetest, 0},
+ {"ATTR", run_attrtest, 0},
+ {"TRANS2", run_trans2test, 0},
+ {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
+ {"TORTURE",run_torture, FLAG_MULTIPROC},
+ {"RANDOMIPC", run_randomipc, 0},
+ {"NBW95", run_nbw95, 0},
+ {"NBWNT", run_nbwnt, 0},
+ {"OPLOCK", run_oplock, 0},
+ {"DIR", run_dirtest, 0},
+ {NULL, NULL, 0}};
+
+
+/****************************************************************************
+run a specified test or "ALL"
+****************************************************************************/
+static void run_test(char *name)
+{
+ int i;
+ if (strequal(name,"ALL")) {
+ for (i=0;torture_ops[i].name;i++) {
+ run_test(torture_ops[i].name);
+ }
+ }
+
+ for (i=0;torture_ops[i].name;i++) {
+ if (strequal(name, torture_ops[i].name)) {
+ start_timer();
+ printf("Running %s\n", name);
+ if (torture_ops[i].flags & FLAG_MULTIPROC) {
+ create_procs(torture_ops[i].fn);
+ } else {
+ torture_ops[i].fn(0);
+ }
+ printf("%s took %g secs\n\n", name, end_timer());
+ }
+ }
+}
+
+
+static void usage(void)
+{
+ int i;
+
+ printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\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("\t-m maximum protocol\n");
+ printf("\n\n");
+
+ printf("tests are:");
+ for (i=0;torture_ops[i].name;i++) {
+ printf(" %s", torture_ops[i].name);
+ }
+ printf("\n");
+
+ printf("default test is ALL\n");
+
+ exit(1);
+}
+
+
+
-#define DEBUG_INTERACTIVE True
/****************************************************************************
main program
****************************************************************************/
int main(int argc,char *argv[])
{
- int nprocs=1, numops=100;
- int opt;
+ int opt, i;
char *p;
int gotpass = 0;
extern char *optarg;
extern int optind;
- extern BOOL append_log;
- extern BOOL timestamp_log;
+ extern FILE *dbf;
+ static pstring servicesf = CONFIGFILE;
+
+ dbf = stdout;
- DEBUGLEVEL = 0;
- pstrcpy(debugf,"./log.torture");
- setup_logging(argv[0], DEBUG_INTERACTIVE);
- append_log = True;
- timestamp_log = False;
+ setbuffer(stdout, NULL, 0);
charset_initialise();
+ lp_load(servicesf,True,False,False);
+ load_interfaces();
+
if (argc < 2) {
usage();
}
@@ -1164,7 +1404,7 @@ static void create_procs(int nprocs, int numops, void (*fn)(int ))
*p = 0;
fstrcpy(share, p+1);
- get_myname(myname,NULL);
+ get_myname(myname);
if (*username == 0 && getenv("LOGNAME")) {
pstrcpy(username,getenv("LOGNAME"));
@@ -1174,6 +1414,8 @@ static void create_procs(int nprocs, int numops, void (*fn)(int ))
argv++;
+ fstrcpy(workgroup, lp_workgroup());
+
while ((opt = getopt(argc, argv, "hW:U:n:N:O:o:m:")) != EOF) {
switch (opt) {
case 'W':
@@ -1218,35 +1460,16 @@ static void create_procs(int nprocs, int numops, void (*fn)(int ))
}
}
- printf("host=%s share=%s user=%s myname=%s procs=%d ops=%d\n",
- host, share, username, myname, nprocs, numops);
+ printf("host=%s share=%s user=%s myname=%s\n",
+ host, share, username, myname);
- create_procs(nprocs, numops, run_randomipc);
-/*
- create_procs(nprocs, numops, run_randomipc_nowait);
-
- create_procs(nprocs, numops, run_connection);
-
- run_fdpasstest();
- run_locktest1();
- run_locktest2();
- run_locktest3(numops);
- run_unlinktest();
- run_browsetest();
- run_attrtest();
- run_trans2test();
-
- create_procs(nprocs, numops, run_maxfidtest);
-
-
-
- start_timer();
- create_procs(nprocs, numops, run_torture);
- printf("rw_torture: %g secs\n", end_timer());
-*/
- dbgflush();
+ if (argc == 1) {
+ run_test("ALL");
+ } else {
+ for (i=1;i<argc;i++) {
+ run_test(argv[i]);
+ }
+ }
return(0);
}
-
-