summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/torture/torture.c1202
1 files changed, 733 insertions, 469 deletions
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index d7e169bdcc..77e9a7eaf2 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -33,7 +33,7 @@ static fstring randomfname;
static BOOL use_oplocks;
static BOOL use_level_II_oplocks;
-static double create_procs(void (*fn)(int));
+static double create_procs(BOOL (*fn)(int), BOOL *result);
static struct timeval tp1,tp2;
@@ -153,13 +153,17 @@ static BOOL open_connection(struct cli_state *c)
}
-static void close_connection(struct cli_state *c)
+static BOOL close_connection(struct cli_state *c)
{
+ BOOL ret = True;
if (!cli_tdis(c)) {
printf("tdis failed (%s)\n", cli_errstr(c));
+ ret = False;
}
- cli_shutdown(c);
+ cli_shutdown(c);
+
+ return ret;
}
@@ -200,6 +204,7 @@ static BOOL rw_torture(struct cli_state *c)
pid_t pid2, pid = getpid();
int i, j;
char buf[1024];
+ BOOL correct = True;
fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
DENY_NONE);
@@ -225,11 +230,13 @@ static BOOL rw_torture(struct cli_state *c)
fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
if (fnum == -1) {
printf("open failed (%s)\n", cli_errstr(c));
+ correct = False;
break;
}
if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
printf("write failed (%s)\n", cli_errstr(c));
+ correct = False;
}
for (j=0;j<50;j++) {
@@ -237,6 +244,7 @@ static BOOL rw_torture(struct cli_state *c)
sizeof(pid)+(j*sizeof(buf)),
sizeof(buf)) != sizeof(buf)) {
printf("write failed (%s)\n", cli_errstr(c));
+ correct = False;
}
}
@@ -244,22 +252,27 @@ static BOOL rw_torture(struct cli_state *c)
if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
printf("read failed (%s)\n", cli_errstr(c));
+ correct = False;
}
if (pid2 != pid) {
printf("data corruption!\n");
+ correct = False;
}
if (!cli_close(c, fnum)) {
printf("close failed (%s)\n", cli_errstr(c));
+ correct = False;
}
if (!cli_unlink(c, fname)) {
printf("unlink failed (%s)\n", cli_errstr(c));
+ correct = False;
}
if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) {
printf("unlock failed (%s)\n", cli_errstr(c));
+ correct = False;
}
}
@@ -268,20 +281,25 @@ static BOOL rw_torture(struct cli_state *c)
printf("%d\n", i);
- return True;
+ return correct;
}
-static void run_torture(int dummy)
+static BOOL run_torture(int dummy)
{
struct cli_state cli;
+ BOOL ret;
cli = current_cli;
cli_sockopt(&cli, sockops);
- rw_torture(&cli);
+ ret = rw_torture(&cli);
- close_connection(&cli);
+ if (!close_connection(&cli)) {
+ ret = False;
+ }
+
+ return ret;
}
static BOOL rw_torture3(struct cli_state *c, char *lockfname)
@@ -293,6 +311,7 @@ static BOOL rw_torture3(struct cli_state *c, char *lockfname)
unsigned count;
unsigned countprev = 0;
unsigned sent = 0;
+ BOOL correct = True;
srandom(1);
for (i = 0; i < sizeof(buf); i += sizeof(uint32))
@@ -345,6 +364,7 @@ static BOOL rw_torture3(struct cli_state *c, char *lockfname)
if (cli_write(c, fnum, 0, buf+count, count, sent) != sent) {
printf("write failed (%s)\n", cli_errstr(c));
+ correct = False;
}
}
else
@@ -356,6 +376,7 @@ static BOOL rw_torture3(struct cli_state *c, char *lockfname)
printf("read failed offset:%d size:%d (%s)\n",
count, sizeof(buf)-count,
cli_errstr(c));
+ correct = False;
sent = 0;
}
if (sent > 0)
@@ -365,6 +386,7 @@ static BOOL rw_torture3(struct cli_state *c, char *lockfname)
printf("read/write compare failed\n");
printf("offset: %d req %d recvd %d\n",
count, sizeof(buf)-count, sent);
+ correct = False;
break;
}
}
@@ -374,9 +396,10 @@ static BOOL rw_torture3(struct cli_state *c, char *lockfname)
if (!cli_close(c, fnum)) {
printf("close failed (%s)\n", cli_errstr(c));
+ correct = False;
}
- return True;
+ return correct;
}
static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2)
@@ -387,9 +410,11 @@ static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2)
int i;
char buf[131072];
char buf_rd[131072];
+ BOOL correct = True;
+ ssize_t bytes_read;
if (!cli_unlink(c1, lockfname)) {
- printf("unlink failed (%s)\n", cli_errstr(c1));
+ printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
}
fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
@@ -410,7 +435,7 @@ static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2)
for (i=0;i<numops;i++)
{
- unsigned buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
+ size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
if (i % 10 == 0) {
printf("%d\r", i); fflush(stdout);
}
@@ -419,56 +444,70 @@ static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2)
if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
printf("write failed (%s)\n", cli_errstr(c1));
+ correct = False;
}
- if (cli_read(c2, fnum2, buf_rd, 0, buf_size) != buf_size) {
+ if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
printf("read failed (%s)\n", cli_errstr(c2));
+ printf("read %d, expected %d\n", bytes_read, buf_size);
+ correct = False;
}
if (memcmp(buf_rd, buf, buf_size) != 0)
{
printf("read/write compare failed\n");
+ correct = False;
}
}
if (!cli_close(c2, fnum2)) {
printf("close failed (%s)\n", cli_errstr(c2));
+ correct = False;
}
if (!cli_close(c1, fnum1)) {
printf("close failed (%s)\n", cli_errstr(c1));
+ correct = False;
}
if (!cli_unlink(c1, lockfname)) {
printf("unlink failed (%s)\n", cli_errstr(c1));
+ correct = False;
}
- return True;
+ return correct;
}
-static void run_readwritetest(int dummy)
+static BOOL run_readwritetest(int dummy)
{
static struct cli_state cli1, cli2;
- BOOL test;
+ BOOL test1, test2;
if (!open_connection(&cli1) || !open_connection(&cli2)) {
- return;
+ return False;
}
cli_sockopt(&cli1, sockops);
cli_sockopt(&cli2, sockops);
printf("starting readwritetest\n");
- test = rw_torture2(&cli1, &cli2);
- printf("Passed readwritetest v1: %s\n", BOOLSTR(test));
+ test1 = rw_torture2(&cli1, &cli2);
+ printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
- test = rw_torture2(&cli1, &cli1);
- printf("Passed readwritetest v2: %s\n", BOOLSTR(test));
+ test2 = rw_torture2(&cli1, &cli1);
+ printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
- close_connection(&cli1);
- close_connection(&cli2);
+ if (!close_connection(&cli1)) {
+ test1 = False;
+ }
+
+ if (!close_connection(&cli2)) {
+ test2 = False;
+ }
+
+ return (test1 && test2);
}
-static void run_readwritemulti(int dummy)
+static BOOL run_readwritemulti(int dummy)
{
static struct cli_state cli;
BOOL test;
@@ -480,61 +519,74 @@ static void run_readwritemulti(int dummy)
printf("run_readwritemulti: fname %s\n", randomfname);
test = rw_torture3(&cli, randomfname);
- close_connection(&cli);
+ if (!close_connection(&cli)) {
+ test = False;
+ }
+
+ return test;
}
-static void run_readwritelarge(int dummy)
+static BOOL run_readwritelarge(int dummy)
{
- static struct cli_state cli1;
+ static struct cli_state cli1;
int fnum1;
char *lockfname = "\\large.dat";
size_t fsize;
char buf[0x10000];
+ BOOL correct = True;
- if (!open_connection(&cli1)) {
- return;
- }
- cli_sockopt(&cli1, sockops);
+ if (!open_connection(&cli1)) {
+ return False;
+ }
+ cli_sockopt(&cli1, sockops);
memset(buf,'\0',sizeof(buf));
-
+
cli1.max_xmit = 0x11000;
-
- printf("starting readwritelarge\n");
+
+ printf("starting readwritelarge\n");
cli_unlink(&cli1, lockfname);
fnum1 = cli_open(&cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
if (fnum1 == -1) {
printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(&cli1));
- return;
+ return False;
}
cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf));
if (!cli_close(&cli1, fnum1)) {
printf("close failed (%s)\n", cli_errstr(&cli1));
+ correct = False;
}
if (!cli_qpathinfo(&cli1, lockfname, NULL, NULL, NULL, &fsize, NULL)) {
printf("qpathinfo failed (%s)\n", cli_errstr(&cli1));
+ correct = False;
}
if (fsize == sizeof(buf))
printf("readwritelarge test succeeded (size = %x)\n", fsize);
- else
- printf("readwritelarge test failed (size = %x)\n", fsize);
+ else {
+ printf("readwritelarge test failed (size = %x)\n", fsize);
+ correct = False;
+ }
if (!cli_unlink(&cli1, lockfname)) {
printf("unlink failed (%s)\n", cli_errstr(&cli1));
+ correct = False;
}
- close_connection(&cli1);
+ if (!close_connection(&cli1)) {
+ correct = False;
+ }
+ return correct;
}
int line_count = 0;
/* run a test that simulates an approximate netbench client load */
-static void run_netbench(int client)
+static BOOL run_netbench(int client)
{
struct cli_state cli;
int i;
@@ -543,6 +595,7 @@ static void run_netbench(int client)
char cname[20];
FILE *f;
char *params[20];
+ BOOL correct = True;
cli = current_cli;
@@ -556,7 +609,7 @@ static void run_netbench(int client)
if (!f) {
perror("client.txt");
- return;
+ return False;
}
while (fgets(line, sizeof(line)-1, f)) {
@@ -630,15 +683,20 @@ static void run_netbench(int client)
printf("+");
- close_connection(&cli);
+ if (!close_connection(&cli)) {
+ correct = False;
+ }
+
+ return correct;
}
/* run a test that simulates an approximate netbench w9X client load */
-static void run_nbw95(int dummy)
+static BOOL run_nbw95(int dummy)
{
double t;
- t = create_procs(run_netbench);
+ BOOL correct = True;
+ t = create_procs(run_netbench, &correct);
/* 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
@@ -646,15 +704,18 @@ static void run_nbw95(int dummy)
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);
+ return correct;
}
/* run a test that simulates an approximate netbench wNT client load */
-static void run_nbwnt(int dummy)
+static BOOL run_nbwnt(int dummy)
{
double t;
- t = create_procs(run_netbench);
+ BOOL correct = True;
+ t = create_procs(run_netbench, &correct);
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);
+ return correct;
}
@@ -666,7 +727,7 @@ static void run_nbwnt(int dummy)
must not use posix semantics)
2) support for lock timeouts
*/
-static void run_locktest1(int dummy)
+static BOOL run_locktest1(int dummy)
{
static struct cli_state cli1, cli2;
char *fname = "\\lockt1.lck";
@@ -674,7 +735,7 @@ static void run_locktest1(int dummy)
time_t t1, t2;
if (!open_connection(&cli1) || !open_connection(&cli2)) {
- return;
+ return False;
}
cli_sockopt(&cli1, sockops);
cli_sockopt(&cli2, sockops);
@@ -686,30 +747,30 @@ static void run_locktest1(int dummy)
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;
+ return False;
}
fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
if (fnum2 == -1) {
printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
- return;
+ return False;
}
fnum3 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
if (fnum3 == -1) {
printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli2));
- return;
+ return False;
}
if (!cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
printf("lock1 failed (%s)\n", cli_errstr(&cli1));
- return;
+ return False;
}
if (cli_lock(&cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
printf("lock2 succeeded! This is a locking bug\n");
- return;
+ return False;
} else {
- if (!check_error(&cli2, ERRDOS, ERRlock, 0)) return;
+ if (!check_error(&cli2, ERRDOS, ERRlock, 0)) return False;
}
@@ -717,9 +778,9 @@ static void run_locktest1(int dummy)
t1 = time(NULL);
if (cli_lock(&cli2, fnum3, 0, 4, 10*1000, WRITE_LOCK)) {
printf("lock3 succeeded! This is a locking bug\n");
- return;
+ return False;
} else {
- if (!check_error(&cli2, ERRDOS, ERRlock, 0)) return;
+ if (!check_error(&cli2, ERRDOS, ERRlock, 0)) return False;
}
t2 = time(NULL);
@@ -729,42 +790,48 @@ static void run_locktest1(int dummy)
if (!cli_close(&cli1, fnum2)) {
printf("close1 failed (%s)\n", cli_errstr(&cli1));
- return;
+ return False;
}
if (cli_lock(&cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
printf("lock4 succeeded! This is a locking bug\n");
- return;
+ return False;
} else {
- if (!check_error(&cli2, ERRDOS, ERRlock, 0)) return;
+ if (!check_error(&cli2, ERRDOS, ERRlock, 0)) return False;
}
if (!cli_close(&cli1, fnum1)) {
printf("close2 failed (%s)\n", cli_errstr(&cli1));
- return;
+ return False;
}
if (!cli_close(&cli2, fnum3)) {
printf("close3 failed (%s)\n", cli_errstr(&cli2));
- return;
+ return False;
}
if (!cli_unlink(&cli1, fname)) {
printf("unlink failed (%s)\n", cli_errstr(&cli1));
- return;
+ return False;
}
- close_connection(&cli1);
- close_connection(&cli2);
+ if (!close_connection(&cli1)) {
+ return False;
+ }
+
+ if (!close_connection(&cli2)) {
+ return False;
+ }
printf("Passed locktest1\n");
+ return True;
}
/*
checks for correct tconX support
*/
-static void run_tcon_test(int dummy)
+static BOOL run_tcon_test(int dummy)
{
static struct cli_state cli1;
char *fname = "\\tcontest.tmp";
@@ -773,7 +840,7 @@ static void run_tcon_test(int dummy)
char buf[4];
if (!open_connection(&cli1)) {
- return;
+ return False;
}
cli_sockopt(&cli1, sockops);
@@ -785,7 +852,7 @@ static void run_tcon_test(int dummy)
if (fnum1 == -1)
{
printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
- return;
+ return False;
}
cnum = cli1.cnum;
@@ -793,7 +860,7 @@ static void run_tcon_test(int dummy)
if (cli_write(&cli1, fnum1, 0, buf, 130, 4) != 4)
{
printf("write failed (%s)", cli_errstr(&cli1));
- return;
+ return False;
}
if (!cli_send_tconX(&cli1, share, "?????",
@@ -801,35 +868,38 @@ static void run_tcon_test(int dummy)
printf("%s refused 2nd tree connect (%s)\n", host,
cli_errstr(&cli1));
cli_shutdown(&cli1);
- return ;
+ return False;
}
if (cli_write(&cli1, fnum1, 0, buf, 130, 4) == 4)
{
printf("write succeeded (%s)", cli_errstr(&cli1));
- return;
+ return False;
}
if (cli_close(&cli1, fnum1)) {
printf("close2 succeeded (%s)\n", cli_errstr(&cli1));
- return;
+ return False;
}
if (!cli_tdis(&cli1)) {
printf("tdis failed (%s)\n", cli_errstr(&cli1));
- return;
+ return False;
}
cli1.cnum = cnum;
if (!cli_close(&cli1, fnum1)) {
printf("close2 failed (%s)\n", cli_errstr(&cli1));
- return;
+ return False;
}
- close_connection(&cli1);
+ if (!close_connection(&cli1)) {
+ return False;
+ }
printf("Passed tcontest\n");
+ return True;
}
@@ -844,14 +914,15 @@ static void run_tcon_test(int dummy)
3) the server denies unlock requests by an incorrect client PID
*/
-static void run_locktest2(int dummy)
+static BOOL run_locktest2(int dummy)
{
static struct cli_state cli;
char *fname = "\\lockt2.lck";
int fnum1, fnum2, fnum3;
+ BOOL correct = True;
if (!open_connection(&cli)) {
- return;
+ return False;
}
cli_sockopt(&cli, sockops);
@@ -865,13 +936,13 @@ static void run_locktest2(int dummy)
fnum1 = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
if (fnum1 == -1) {
printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
- return;
+ return False;
}
fnum2 = cli_open(&cli, fname, O_RDWR, DENY_NONE);
if (fnum2 == -1) {
printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli));
- return;
+ return False;
}
cli_setpid(&cli, 2);
@@ -879,74 +950,75 @@ static void run_locktest2(int dummy)
fnum3 = cli_open(&cli, fname, O_RDWR, DENY_NONE);
if (fnum3 == -1) {
printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli));
- return;
+ return False;
}
cli_setpid(&cli, 1);
if (!cli_lock(&cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
printf("lock1 failed (%s)\n", cli_errstr(&cli));
- return;
+ return False;
}
if (cli_lock(&cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
printf("WRITE lock1 succeeded! This is a locking bug\n");
+ correct = False;
} else {
- if (!check_error(&cli, ERRDOS, ERRlock, 0)) return;
+ if (!check_error(&cli, ERRDOS, ERRlock, 0)) return False;
}
if (cli_lock(&cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
printf("WRITE lock2 succeeded! This is a locking bug\n");
+ correct = False;
} else {
- if (!check_error(&cli, ERRDOS, ERRlock, 0)) return;
+ if (!check_error(&cli, ERRDOS, ERRlock, 0)) return False;
}
if (cli_lock(&cli, fnum2, 0, 4, 0, READ_LOCK)) {
printf("READ lock2 succeeded! This is a locking bug\n");
+ correct = False;
} else {
- if (!check_error(&cli, ERRDOS, ERRlock, 0)) return;
+ if (!check_error(&cli, ERRDOS, ERRlock, 0)) return False;
}
cli_setpid(&cli, 2);
- if (cli_unlock(&cli, fnum1, 0, 4)) {
- printf("unlock1 succeeded! This is a locking bug\n");
- } else {
- if (!check_error(&cli, ERRDOS, ERRnotlocked, 0)) return;
- }
-
if (cli_unlock(&cli, fnum1, 0, 8)) {
- printf("unlock2 succeeded! This is a locking bug\n");
- } else {
- if (!check_error(&cli, ERRDOS, ERRnotlocked, 0)) return;
+ printf("unlock1 succeeded! This is a locking bug\n");
+ correct = False;
}
if (cli_lock(&cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
printf("lock3 succeeded! This is a locking bug\n");
+ correct = False;
} else {
- if (!check_error(&cli, ERRDOS, ERRlock, 0)) return;
+ if (!check_error(&cli, ERRDOS, ERRlock, 0)) return False;
}
cli_setpid(&cli, 1);
if (!cli_close(&cli, fnum1)) {
printf("close1 failed (%s)\n", cli_errstr(&cli));
- return;
+ return False;
}
if (!cli_close(&cli, fnum2)) {
printf("close2 failed (%s)\n", cli_errstr(&cli));
- return;
+ return False;
}
if (!cli_close(&cli, fnum3)) {
printf("close3 failed (%s)\n", cli_errstr(&cli));
- return;
+ return False;
}
- close_connection(&cli);
+ if (!close_connection(&cli)) {
+ correct = False;
+ }
printf("locktest2 finished\n");
+
+ return correct;
}
@@ -955,17 +1027,18 @@ static void run_locktest2(int dummy)
1) the server supports the full offset range in lock requests
*/
-static void run_locktest3(int dummy)
+static BOOL run_locktest3(int dummy)
{
static struct cli_state cli1, cli2;
char *fname = "\\lockt3.lck";
int fnum1, fnum2, i;
uint32 offset;
+ BOOL correct = True;
#define NEXT_OFFSET offset += (~(uint32)0) / numops
if (!open_connection(&cli1) || !open_connection(&cli2)) {
- return;
+ return False;
}
cli_sockopt(&cli1, sockops);
cli_sockopt(&cli2, sockops);
@@ -977,12 +1050,12 @@ static void run_locktest3(int dummy)
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;
+ return False;
}
fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
if (fnum2 == -1) {
printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
- return;
+ return False;
}
for (offset=i=0;i<numops;i++) {
@@ -991,14 +1064,14 @@ static void run_locktest3(int dummy)
printf("lock1 %d failed (%s)\n",
i,
cli_errstr(&cli1));
- return;
+ return False;
}
if (!cli_lock(&cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
printf("lock2 %d failed (%s)\n",
i,
cli_errstr(&cli1));
- return;
+ return False;
}
}
@@ -1007,22 +1080,22 @@ static void run_locktest3(int dummy)
if (cli_lock(&cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
printf("error: lock1 %d succeeded!\n", i);
- return;
+ return False;
}
if (cli_lock(&cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
printf("error: lock2 %d succeeded!\n", i);
- return;
+ return False;
}
if (cli_lock(&cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
printf("error: lock3 %d succeeded!\n", i);
- return;
+ return False;
}
if (cli_lock(&cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
printf("error: lock4 %d succeeded!\n", i);
- return;
+ return False;
}
}
@@ -1033,51 +1106,63 @@ static void run_locktest3(int dummy)
printf("unlock1 %d failed (%s)\n",
i,
cli_errstr(&cli1));
- return;
+ return False;
}
if (!cli_unlock(&cli2, fnum2, offset-2, 1)) {
printf("unlock2 %d failed (%s)\n",
i,
cli_errstr(&cli1));
- return;
+ return False;
}
}
if (!cli_close(&cli1, fnum1)) {
printf("close1 failed (%s)\n", cli_errstr(&cli1));
+ return False;
}
if (!cli_close(&cli2, fnum2)) {
printf("close2 failed (%s)\n", cli_errstr(&cli2));
+ return False;
}
if (!cli_unlink(&cli1, fname)) {
printf("unlink failed (%s)\n", cli_errstr(&cli1));
- return;
+ return False;
}
- close_connection(&cli1);
- close_connection(&cli2);
+ if (!close_connection(&cli1)) {
+ correct = False;
+ }
+
+ if (!close_connection(&cli2)) {
+ correct = False;
+ }
printf("finished locktest3\n");
+
+ return correct;
}
-#define EXPECTED(ret, v) if ((ret) != (v)) printf("** ")
+#define EXPECTED(ret, v) if ((ret) != (v)) { \
+ printf("** "); correct = False; \
+ }
/*
looks at overlapping locks
*/
-static void run_locktest4(int dummy)
+static BOOL run_locktest4(int dummy)
{
static struct cli_state cli1, cli2;
char *fname = "\\lockt4.lck";
int fnum1, fnum2, f;
BOOL ret;
char buf[1000];
+ BOOL correct = True;
if (!open_connection(&cli1) || !open_connection(&cli2)) {
- return;
+ return False;
}
cli_sockopt(&cli1, sockops);
@@ -1094,6 +1179,7 @@ static void run_locktest4(int dummy)
if (cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
printf("Failed to create file\n");
+ correct = False;
goto fail;
}
@@ -1222,8 +1308,6 @@ static void run_locktest4(int dummy)
EXPECTED(ret, True);
printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
-
-
fail:
cli_close(&cli1, fnum1);
cli_close(&cli2, fnum2);
@@ -1232,21 +1316,23 @@ static void run_locktest4(int dummy)
close_connection(&cli2);
printf("finished locktest4\n");
+ return correct;
}
/*
looks at lock upgrade/downgrade.
*/
-static void run_locktest5(int dummy)
+static BOOL run_locktest5(int dummy)
{
static struct cli_state cli1, cli2;
char *fname = "\\lockt5.lck";
int fnum1, fnum2, fnum3;
BOOL ret;
char buf[1000];
+ BOOL correct = True;
if (!open_connection(&cli1) || !open_connection(&cli2)) {
- return;
+ return False;
}
cli_sockopt(&cli1, sockops);
@@ -1264,6 +1350,7 @@ static void run_locktest5(int dummy)
if (cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
printf("Failed to create file\n");
+ correct = False;
goto fail;
}
@@ -1339,21 +1426,28 @@ static void run_locktest5(int dummy)
printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
+
fail:
cli_close(&cli1, fnum1);
cli_close(&cli2, fnum2);
cli_unlink(&cli1, fname);
- close_connection(&cli1);
- close_connection(&cli2);
+ if (!close_connection(&cli1)) {
+ correct = False;
+ }
+ if (!close_connection(&cli2)) {
+ correct = False;
+ }
printf("finished locktest5\n");
+
+ return correct;
}
/*
this produces a matrix of deny mode behaviour
*/
-static void run_denytest1(int dummy)
+static BOOL run_denytest1(int dummy)
{
static struct cli_state cli1, cli2;
int fnum1, fnum2;
@@ -1378,9 +1472,10 @@ static void run_denytest1(int dummy)
{O_RDONLY, "O_RDONLY"},
{O_WRONLY, "O_WRONLY"},
{-1, NULL}};
+ BOOL correct = True;
if (!open_connection(&cli1) || !open_connection(&cli2)) {
- return;
+ return False;
}
cli_sockopt(&cli1, sockops);
cli_sockopt(&cli2, sockops);
@@ -1433,10 +1528,15 @@ static void run_denytest1(int dummy)
cli_unlink(&cli1, fnames[f]);
}
- close_connection(&cli1);
- close_connection(&cli2);
+ if (!close_connection(&cli1)) {
+ correct = False;
+ }
+ if (!close_connection(&cli2)) {
+ correct = False;
+ }
printf("finshed denytest1\n");
+ return correct;
}
@@ -1444,7 +1544,7 @@ static void run_denytest1(int dummy)
this produces a matrix of deny mode behaviour for two opens on the
same connection
*/
-static void run_denytest2(int dummy)
+static BOOL run_denytest2(int dummy)
{
static struct cli_state cli1;
int fnum1, fnum2;
@@ -1469,9 +1569,10 @@ static void run_denytest2(int dummy)
{O_RDONLY, "O_RDONLY"},
{O_WRONLY, "O_WRONLY"},
{-1, NULL}};
+ BOOL correct = True;
if (!open_connection(&cli1)) {
- return;
+ return False;
}
cli_sockopt(&cli1, sockops);
@@ -1523,16 +1624,19 @@ static void run_denytest2(int dummy)
cli_unlink(&cli1, fnames[f]);
}
- close_connection(&cli1);
+ if (!close_connection(&cli1)) {
+ correct = False;
+ }
printf("finshed denytest2\n");
+ return correct;
}
/*
test whether fnums and tids open on one VC are available on another (a major
security hole)
*/
-static void run_fdpasstest(int dummy)
+static BOOL run_fdpasstest(int dummy)
{
static struct cli_state cli1, cli2, cli3;
char *fname = "\\fdpass.tst";
@@ -1540,7 +1644,7 @@ static void run_fdpasstest(int dummy)
pstring buf;
if (!open_connection(&cli1) || !open_connection(&cli2)) {
- return;
+ return False;
}
cli_sockopt(&cli1, sockops);
cli_sockopt(&cli2, sockops);
@@ -1552,12 +1656,12 @@ static void run_fdpasstest(int dummy)
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;
+ return False;
}
if (cli_write(&cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
printf("write failed (%s)\n", cli_errstr(&cli1));
- return;
+ return False;
}
cli3 = cli2;
@@ -1568,7 +1672,7 @@ static void run_fdpasstest(int dummy)
if (cli_read(&cli3, fnum1, buf, 0, 13) == 13) {
printf("read succeeded! nasty security hole [%s]\n",
buf);
- return;
+ return False;
}
cli_close(&cli1, fnum1);
@@ -1578,6 +1682,7 @@ static void run_fdpasstest(int dummy)
close_connection(&cli2);
printf("finished fdpasstest\n");
+ return True;
}
@@ -1586,14 +1691,15 @@ static void run_fdpasstest(int dummy)
1) the server does not allow an unlink on a file that is open
*/
-static void run_unlinktest(int dummy)
+static BOOL run_unlinktest(int dummy)
{
static struct cli_state cli;
char *fname = "\\unlink.tst";
int fnum;
+ BOOL correct = True;
if (!open_connection(&cli)) {
- return;
+ return False;
}
cli_sockopt(&cli, sockops);
@@ -1607,38 +1713,44 @@ static void run_unlinktest(int dummy)
fnum = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
if (fnum == -1) {
printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
- return;
+ return False;
}
if (cli_unlink(&cli, fname)) {
printf("error: server allowed unlink on an open file\n");
+ correct = False;
}
cli_close(&cli, fnum);
cli_unlink(&cli, fname);
- close_connection(&cli);
+ if (!close_connection(&cli)) {
+ correct = False;
+ }
printf("unlink test finished\n");
+
+ return correct;
}
/*
test how many open files this server supports on the one socket
*/
-static void run_maxfidtest(int dummy)
+static BOOL run_maxfidtest(int dummy)
{
static struct cli_state cli;
char *template = "\\maxfid.%d.%d";
fstring fname;
int fnum;
int retries=4;
+ BOOL correct = True;
cli = current_cli;
if (retries <= 0) {
printf("failed to connect\n");
- return;
+ return False;
}
cli_sockopt(&cli, sockops);
@@ -1667,11 +1779,15 @@ static void run_maxfidtest(int dummy)
if (!cli_unlink(&cli, fname)) {
printf("unlink of %s failed (%s)\n",
fname, cli_errstr(&cli));
+ correct = False;
}
}
printf("maxfid test finished\n");
- close_connection(&cli);
+ if (!close_connection(&cli)) {
+ correct = False;
+ }
+ return correct;
}
/* generate a random buffer */
@@ -1684,29 +1800,34 @@ static void rand_buf(char *buf, int len)
}
/* send smb negprot commands, not reading the response */
-static void run_negprot_nowait(int dummy)
+static BOOL run_negprot_nowait(int dummy)
{
int i;
static struct cli_state cli;
+ BOOL correct = True;
printf("starting negprot nowait test\n");
if (!open_nbt_connection(&cli)) {
- return;
+ return False;
}
for (i=0;i<50000;i++) {
cli_negprot_send(&cli);
}
- close_connection(&cli);
+ if (!close_connection(&cli)) {
+ correct = False;
+ }
printf("finished negprot nowait test\n");
+
+ return correct;
}
/* send random IPC commands */
-static void run_randomipc(int dummy)
+static BOOL run_randomipc(int dummy)
{
char *rparam = NULL;
char *rdata = NULL;
@@ -1714,11 +1835,12 @@ static void run_randomipc(int dummy)
pstring param;
int api, param_len, i;
static struct cli_state cli;
+ BOOL correct = True;
printf("starting random ipc test\n");
if (!open_connection(&cli)) {
- return;
+ return False;
}
for (i=0;i<50000;i++) {
@@ -1736,9 +1858,13 @@ static void run_randomipc(int dummy)
&rdata, &rdrcnt);
}
- close_connection(&cli);
+ if (!close_connection(&cli)) {
+ correct = False;
+ }
printf("finished random ipc test\n");
+
+ return correct;
}
@@ -1755,14 +1881,15 @@ static void browse_callback(const char *sname, uint32 stype,
This test checks the browse list code
*/
-static void run_browsetest(int dummy)
+static BOOL run_browsetest(int dummy)
{
static struct cli_state cli;
+ BOOL correct = True;
printf("starting browse test\n");
if (!open_connection(&cli)) {
- return;
+ return False;
}
printf("domain list:\n");
@@ -1775,26 +1902,32 @@ static void run_browsetest(int dummy)
SV_TYPE_ALL,
browse_callback, NULL);
- close_connection(&cli);
+ if (!close_connection(&cli)) {
+ correct = False;
+ }
printf("browse test finished\n");
+
+ return correct;
+
}
/*
This checks how the getatr calls works
*/
-static void run_attrtest(int dummy)
+static BOOL run_attrtest(int dummy)
{
static struct cli_state cli;
int fnum;
time_t t, t2;
char *fname = "\\attrib.tst";
+ BOOL correct = True;
printf("starting attrib test\n");
if (!open_connection(&cli)) {
- return;
+ return False;
}
cli_unlink(&cli, fname);
@@ -1803,42 +1936,51 @@ static void run_attrtest(int dummy)
cli_close(&cli, fnum);
if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
printf("getatr failed (%s)\n", cli_errstr(&cli));
+ correct = False;
}
if (abs(t - time(NULL)) > 2) {
printf("ERROR: SMBgetatr bug. time is %s",
ctime(&t));
t = time(NULL);
+ correct = True;
}
t2 = t-60*60*24; /* 1 day ago */
if (!cli_setatr(&cli, fname, 0, t2)) {
printf("setatr failed (%s)\n", cli_errstr(&cli));
+ correct = True;
}
if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
printf("getatr failed (%s)\n", cli_errstr(&cli));
+ correct = True;
}
if (t != t2) {
printf("ERROR: getatr/setatr bug. times are\n%s",
ctime(&t));
printf("%s", ctime(&t2));
+ correct = True;
}
cli_unlink(&cli, fname);
- close_connection(&cli);
+ if (!close_connection(&cli)) {
+ correct = False;
+ }
printf("attrib test finished\n");
+
+ return correct;
}
/*
This checks a couple of trans2 calls
*/
-static void run_trans2test(int dummy)
+static BOOL run_trans2test(int dummy)
{
static struct cli_state cli;
int fnum;
@@ -1847,11 +1989,12 @@ static void run_trans2test(int dummy)
char *fname = "\\trans2.tst";
char *dname = "\\trans2";
char *fname2 = "\\trans2\\trans2.tst";
+ BOOL correct = True;
printf("starting trans2 test\n");
if (!open_connection(&cli)) {
- return;
+ return False;
}
cli_unlink(&cli, fname);
@@ -1860,6 +2003,7 @@ static void run_trans2test(int dummy)
if (!cli_qfileinfo(&cli, fnum, NULL, &size, &c_time, &a_time, &m_time,
NULL, NULL)) {
printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli));
+ correct = False;
}
cli_close(&cli, fnum);
@@ -1872,19 +2016,23 @@ static void run_trans2test(int dummy)
if (!cli_qpathinfo(&cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(&cli));
+ correct = False;
} else {
if (c_time != m_time) {
printf("create time=%s", ctime(&c_time));
printf("modify time=%s", ctime(&m_time));
printf("This system appears to have sticky create times\n");
+ correct = False;
}
if (a_time % (60*60) == 0) {
printf("access time=%s", ctime(&a_time));
printf("This system appears to set a midnight access time\n");
+ correct = False;
}
if (abs(m_time - time(NULL)) > 60*60*24*7) {
printf("ERROR: totally incorrect times - maybe word reversed?\n");
+ correct = False;
}
}
@@ -1896,10 +2044,12 @@ static void run_trans2test(int dummy)
if (!cli_qpathinfo2(&cli, fname, &c_time, &a_time, &m_time,
&w_time, &size, NULL, NULL)) {
printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
+ correct = False;
} else {
if (w_time < 60*60*24*2) {
printf("write time=%s", ctime(&w_time));
printf("This system appears to set a initial 0 write time\n");
+ correct = False;
}
}
@@ -1910,11 +2060,13 @@ static void run_trans2test(int dummy)
when creating a new file */
if (!cli_mkdir(&cli, dname)) {
printf("ERROR: mkdir failed (%s)\n", cli_errstr(&cli));
+ correct = False;
}
sleep(3);
if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time,
&w_time, &size, NULL, NULL)) {
printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
+ correct = False;
}
fnum = cli_open(&cli, fname2,
@@ -1924,79 +2076,96 @@ static void run_trans2test(int dummy)
if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time2,
&w_time, &size, NULL, NULL)) {
printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
+ correct = False;
} else {
- if (m_time2 == m_time)
+ if (m_time2 == m_time) {
printf("This system does not update directory modification times\n");
+ correct = False;
+ }
}
cli_unlink(&cli, fname2);
cli_rmdir(&cli, dname);
-
- close_connection(&cli);
+ if (!close_connection(&cli)) {
+ correct = False;
+ }
printf("trans2 test finished\n");
+
+ return correct;
}
/*
This checks new W2K calls.
*/
-void new_trans(struct cli_state *pcli, int fnum, int level)
+static BOOL new_trans(struct cli_state *pcli, int fnum, int level)
{
char buf[4096];
+ BOOL correct = True;
memset(buf, 0xff, sizeof(buf));
if (!cli_qfileinfo_test(pcli, fnum, level, buf)) {
printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
+ correct = False;
} else {
printf("qfileinfo: level %d\n", level);
dump_data(0, buf, 256);
printf("\n");
}
+ return correct;
}
-static void run_w2ktest(int dummy)
+static BOOL run_w2ktest(int dummy)
{
static struct cli_state cli;
int fnum;
char *fname = "\\w2ktest\\w2k.tst";
int level;
+ BOOL correct = True;
printf("starting w2k test\n");
if (!open_connection(&cli)) {
- return;
+ return False;
}
fnum = cli_open(&cli, fname,
O_RDWR | O_CREAT , DENY_NONE);
- for (level = 1004; level < 1040; level++)
- new_trans(&cli, fnum, level);
+ for (level = 1004; level < 1040; level++) {
+ if (!new_trans(&cli, fnum, level)) {
+ correct = False;
+ }
+ }
cli_close(&cli, fnum);
-
- close_connection(&cli);
+ if (!close_connection(&cli)) {
+ correct = False;
+ }
printf("w2k test finished\n");
+
+ return correct;
}
/*
this is a harness for some oplock tests
*/
-static void run_oplock1(int dummy)
+static BOOL run_oplock1(int dummy)
{
static struct cli_state cli1;
char *fname = "\\lockt1.lck";
int fnum1;
+ BOOL correct = True;
printf("starting oplock test 1\n");
if (!open_connection(&cli1)) {
- return;
+ return False;
}
cli_unlink(&cli1, fname);
@@ -2008,7 +2177,7 @@ static void run_oplock1(int dummy)
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;
+ return False;
}
cli1.use_oplocks = False;
@@ -2018,27 +2187,35 @@ static void run_oplock1(int dummy)
if (!cli_close(&cli1, fnum1)) {
printf("close2 failed (%s)\n", cli_errstr(&cli1));
- return;
+ return False;
}
if (!cli_unlink(&cli1, fname)) {
printf("unlink failed (%s)\n", cli_errstr(&cli1));
- return;
+ return False;
}
-
- close_connection(&cli1);
+ if (!close_connection(&cli1)) {
+ correct = False;
+ }
printf("finished oplock test 1\n");
+
+ return correct;
}
-static void run_oplock2(int dummy)
+static BOOL run_oplock2(int dummy)
{
static struct cli_state cli1, cli2;
char *fname = "\\lockt2.lck";
int fnum1, fnum2;
int saved_use_oplocks = use_oplocks;
char buf[4];
+ BOOL correct = True;
+ volatile BOOL *shared_correct;
+
+ shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
+ *shared_correct = True;
use_level_II_oplocks = True;
use_oplocks = True;
@@ -2048,7 +2225,7 @@ static void run_oplock2(int dummy)
if (!open_connection(&cli1)) {
use_level_II_oplocks = False;
use_oplocks = saved_use_oplocks;
- return;
+ return False;
}
cli1.use_oplocks = True;
@@ -2057,7 +2234,7 @@ static void run_oplock2(int dummy)
if (!open_connection(&cli2)) {
use_level_II_oplocks = False;
use_oplocks = saved_use_oplocks;
- return;
+ return False;
}
cli2.use_oplocks = True;
@@ -2071,7 +2248,7 @@ static void run_oplock2(int dummy)
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;
+ return False;
}
/* Don't need the globals any more. */
@@ -2083,6 +2260,7 @@ static void run_oplock2(int dummy)
fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
if (fnum2 == -1) {
printf("second open of %s failed (%s)\n", fname, cli_errstr(&cli1));
+ *shared_correct = False;
exit(0);
}
@@ -2090,6 +2268,7 @@ static void run_oplock2(int dummy)
if (!cli_close(&cli2, fnum2)) {
printf("close2 failed (%s)\n", cli_errstr(&cli1));
+ *shared_correct = False;
}
exit(0);
@@ -2101,6 +2280,7 @@ static void run_oplock2(int dummy)
if (cli_read(&cli1, fnum1, buf, 0, 4) != 4) {
printf("read on fnum1 failed (%s)\n", cli_errstr(&cli1));
+ correct = False;
}
/* Should now be at level II. */
@@ -2108,6 +2288,7 @@ static void run_oplock2(int dummy)
if (!cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK)) {
printf("lock failed (%s)\n", cli_errstr(&cli1));
+ correct = False;
}
cli_unlock(&cli1, fnum1, 0, 4);
@@ -2116,6 +2297,7 @@ static void run_oplock2(int dummy)
if (!cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
printf("lock failed (%s)\n", cli_errstr(&cli1));
+ correct = False;
}
cli_unlock(&cli1, fnum1, 0, 4);
@@ -2127,22 +2309,33 @@ static void run_oplock2(int dummy)
#if 0
if (cli_write(&cli1, fnum1, 0, buf, 0, 4) != 4) {
printf("write on fnum1 failed (%s)\n", cli_errstr(&cli1));
+ correct = False;
}
#endif
if (!cli_close(&cli1, fnum1)) {
printf("close1 failed (%s)\n", cli_errstr(&cli1));
+ correct = False;
}
sleep(4);
if (!cli_unlink(&cli1, fname)) {
printf("unlink failed (%s)\n", cli_errstr(&cli1));
+ correct = False;
}
- close_connection(&cli1);
+ if (!close_connection(&cli1)) {
+ correct = False;
+ }
+
+ if (!*shared_correct) {
+ correct = False;
+ }
printf("finished oplock test 2\n");
+
+ return correct;
}
/* handler for oplock 3 tests */
@@ -2153,12 +2346,17 @@ static BOOL oplock3_handler(struct cli_state *cli, int fnum, unsigned char level
return cli_oplock_ack(cli, fnum, level);
}
-static void run_oplock3(int dummy)
+static BOOL run_oplock3(int dummy)
{
static struct cli_state cli;
char *fname = "\\oplockt3.dat";
int fnum;
char buf[4] = "abcd";
+ BOOL correct = True;
+ volatile BOOL *shared_correct;
+
+ shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
+ *shared_correct = True;
printf("starting oplock test 3\n");
@@ -2166,7 +2364,10 @@ static void run_oplock3(int dummy)
/* Child code */
use_oplocks = True;
use_level_II_oplocks = True;
- if (!open_connection(&cli)) return;
+ if (!open_connection(&cli)) {
+ *shared_correct = False;
+ exit(0);
+ }
sleep(2);
/* try to trigger a oplock break in parent */
fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE);
@@ -2177,7 +2378,9 @@ static void run_oplock3(int dummy)
/* parent code */
use_oplocks = True;
use_level_II_oplocks = True;
- if (!open_connection(&cli)) return;
+ if (!open_connection(&cli)) {
+ return False;
+ }
cli_oplock_handler(&cli, oplock3_handler);
fnum = cli_open(&cli, fname, O_RDWR|O_CREAT, DENY_NONE);
cli_write(&cli, fnum, 0, buf, 0, 4);
@@ -2186,6 +2389,10 @@ static void run_oplock3(int dummy)
cli.timeout = 20000;
cli_receive_smb(&cli);
printf("finished oplock test 3\n");
+
+ return (correct && *shared_correct);
+
+/* What are we looking for here? What's sucess and what's FAILURE? */
}
@@ -2193,86 +2400,88 @@ static void run_oplock3(int dummy)
/*
Test delete on close semantics.
*/
-static void run_deletetest(int dummy)
+static BOOL run_deletetest(int dummy)
{
- static struct cli_state cli1;
- static struct cli_state cli2;
- char *fname = "\\delete.file";
- int fnum1, fnum2;
-
- printf("starting delete test\n");
-
- if (!open_connection(&cli1)) {
- return;
- }
-
+ static struct cli_state cli1;
+ static struct cli_state cli2;
+ char *fname = "\\delete.file";
+ int fnum1, fnum2;
+ BOOL correct = True;
+
+ printf("starting delete test\n");
+
+ if (!open_connection(&cli1)) {
+ return False;
+ }
+
cli_sockopt(&cli1, sockops);
-
+
/* Test 1 - this should *NOT* delete the file on close. */
-
+
cli_setatr(&cli1, fname, 0, 0);
cli_unlink(&cli1, fname);
-
+
fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_DELETE, FILE_OVERWRITE_IF, DELETE_ON_CLOSE_FLAG);
-
+ FILE_SHARE_DELETE, FILE_OVERWRITE_IF, DELETE_ON_CLOSE_FLAG);
+
if (fnum1 == -1) {
printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
- return;
+ return False;
+ }
+
+ if (!cli_close(&cli1, fnum1)) {
+ printf("[1] close failed (%s)\n", cli_errstr(&cli1));
+ return False;
}
- if (!cli_close(&cli1, fnum1)) {
- printf("[1] close failed (%s)\n", cli_errstr(&cli1));
- return;
- }
-
- fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
- if (fnum1 == -1) {
- printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
- return;
- }
-
- if (!cli_close(&cli1, fnum1)) {
- printf("[1] close failed (%s)\n", cli_errstr(&cli1));
- return;
- }
-
+ fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
+ if (fnum1 == -1) {
+ printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
+ return False;
+ }
+
+ if (!cli_close(&cli1, fnum1)) {
+ printf("[1] close failed (%s)\n", cli_errstr(&cli1));
+ return False;
+ }
+
printf("first delete on close test succeeded.\n");
-
+
/* Test 2 - this should delete the file on close. */
-
+
cli_setatr(&cli1, fname, 0, 0);
cli_unlink(&cli1, fname);
-
+
fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS,
- FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
-
+ FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
+
if (fnum1 == -1) {
printf("[2] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
- return;
+ return False;
}
-
+
if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
- printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
- return;
- }
-
- if (!cli_close(&cli1, fnum1)) {
- printf("[2] close failed (%s)\n", cli_errstr(&cli1));
- return;
- }
-
- fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
- if (fnum1 != -1) {
+ printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
+ return False;
+ }
+
+ if (!cli_close(&cli1, fnum1)) {
+ printf("[2] close failed (%s)\n", cli_errstr(&cli1));
+ return False;
+ }
+
+ fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
+ if (fnum1 != -1) {
printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
if (!cli_close(&cli1, fnum1)) {
printf("[2] close failed (%s)\n", cli_errstr(&cli1));
+ correct = False;
}
cli_unlink(&cli1, fname);
- } else
+ } else
printf("second delete on close test succeeded.\n");
-
-
+
+
/* Test 3 - ... */
cli_setatr(&cli1, fname, 0, 0);
cli_unlink(&cli1, fname);
@@ -2282,7 +2491,7 @@ static void run_deletetest(int dummy)
if (fnum1 == -1) {
printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
- return;
+ return False;
}
/* This should fail with a sharing violation - open for delete is only compatible
@@ -2293,7 +2502,7 @@ static void run_deletetest(int dummy)
if (fnum2 != -1) {
printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
- return;
+ return False;
}
/* This should succeed. */
@@ -2303,34 +2512,35 @@ static void run_deletetest(int dummy)
if (fnum2 == -1) {
printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
- return;
+ return False;
}
if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
- printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
- return;
- }
-
- if (!cli_close(&cli1, fnum1)) {
- printf("[3] close 1 failed (%s)\n", cli_errstr(&cli1));
- return;
- }
-
- if (!cli_close(&cli1, fnum2)) {
- printf("[3] close 2 failed (%s)\n", cli_errstr(&cli1));
- return;
- }
-
+ printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
+ return False;
+ }
+
+ if (!cli_close(&cli1, fnum1)) {
+ printf("[3] close 1 failed (%s)\n", cli_errstr(&cli1));
+ return False;
+ }
+
+ if (!cli_close(&cli1, fnum2)) {
+ printf("[3] close 2 failed (%s)\n", cli_errstr(&cli1));
+ return False;
+ }
+
/* This should fail - file should no longer be there. */
- fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
- if (fnum1 != -1) {
+ fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
+ if (fnum1 != -1) {
printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
if (!cli_close(&cli1, fnum1)) {
printf("[3] close failed (%s)\n", cli_errstr(&cli1));
}
cli_unlink(&cli1, fname);
- } else
+ correct = False;
+ } else
printf("third delete on close test succeeded.\n");
/* Test 4 ... */
@@ -2342,7 +2552,7 @@ static void run_deletetest(int dummy)
if (fnum1 == -1) {
printf("[4] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
- return;
+ return False;
}
/* This should succeed. */
@@ -2350,339 +2560,349 @@ static void run_deletetest(int dummy)
FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
if (fnum2 == -1) {
printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
- return;
+ return False;
}
-
- if (!cli_close(&cli1, fnum2)) {
- printf("[4] close - 1 failed (%s)\n", cli_errstr(&cli1));
- return;
- }
-
+
+ if (!cli_close(&cli1, fnum2)) {
+ printf("[4] close - 1 failed (%s)\n", cli_errstr(&cli1));
+ return False;
+ }
+
if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
- printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
- return;
- }
-
+ printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
+ return False;
+ }
+
/* This should fail - no more opens once delete on close set. */
fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS,
- FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
+ FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
if (fnum2 != -1) {
printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
- return;
- } else
+ return False;
+ } else
printf("fourth delete on close test succeeded.\n");
-
- if (!cli_close(&cli1, fnum1)) {
- printf("[4] close - 2 failed (%s)\n", cli_errstr(&cli1));
- return;
- }
-
+
+ if (!cli_close(&cli1, fnum1)) {
+ printf("[4] close - 2 failed (%s)\n", cli_errstr(&cli1));
+ return False;
+ }
+
/* Test 5 ... */
cli_setatr(&cli1, fname, 0, 0);
cli_unlink(&cli1, fname);
-
- fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
+
+ fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
if (fnum1 == -1) {
printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
- return;
+ return False;
}
/* This should fail - only allowed on NT opens with DELETE access. */
if (cli_nt_delete_on_close(&cli1, fnum1, True)) {
- printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
- return;
- }
-
- if (!cli_close(&cli1, fnum1)) {
- printf("[5] close - 2 failed (%s)\n", cli_errstr(&cli1));
- return;
- }
+ printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
+ return False;
+ }
+ if (!cli_close(&cli1, fnum1)) {
+ printf("[5] close - 2 failed (%s)\n", cli_errstr(&cli1));
+ return False;
+ }
+
printf("fifth delete on close test succeeded.\n");
-
+
/* Test 6 ... */
cli_setatr(&cli1, fname, 0, 0);
cli_unlink(&cli1, fname);
-
+
fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA,
- FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
- FILE_OVERWRITE_IF, 0);
-
+ FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+ FILE_OVERWRITE_IF, 0);
+
if (fnum1 == -1) {
printf("[6] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
- return;
+ return False;
}
-
+
/* This should fail - only allowed on NT opens with DELETE access. */
-
+
if (cli_nt_delete_on_close(&cli1, fnum1, True)) {
- printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
- return;
- }
+ printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
+ return False;
+ }
- if (!cli_close(&cli1, fnum1)) {
- printf("[6] close - 2 failed (%s)\n", cli_errstr(&cli1));
- return;
- }
+ if (!cli_close(&cli1, fnum1)) {
+ printf("[6] close - 2 failed (%s)\n", cli_errstr(&cli1));
+ return False;
+ }
printf("sixth delete on close test succeeded.\n");
-
+
/* Test 7 ... */
cli_setatr(&cli1, fname, 0, 0);
cli_unlink(&cli1, fname);
-
+
fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
- FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0);
+ FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0);
if (fnum1 == -1) {
printf("[7] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
- return;
+ return False;
}
if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
- printf("[7] setting delete_on_close on file failed !\n");
- return;
- }
-
+ printf("[7] setting delete_on_close on file failed !\n");
+ return False;
+ }
+
if (!cli_nt_delete_on_close(&cli1, fnum1, False)) {
- printf("[7] unsetting delete_on_close on file failed !\n");
- return;
- }
-
- if (!cli_close(&cli1, fnum1)) {
- printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1));
- return;
- }
+ printf("[7] unsetting delete_on_close on file failed !\n");
+ return False;
+ }
+ if (!cli_close(&cli1, fnum1)) {
+ printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1));
+ return False;
+ }
+
/* This next open should succeed - we reset the flag. */
-
- fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
+
+ fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
if (fnum1 == -1) {
printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
- return;
+ return False;
}
- if (!cli_close(&cli1, fnum1)) {
- printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1));
- return;
- }
+ if (!cli_close(&cli1, fnum1)) {
+ printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1));
+ return False;
+ }
printf("seventh delete on close test succeeded.\n");
-
+
/* Test 7 ... */
cli_setatr(&cli1, fname, 0, 0);
cli_unlink(&cli1, fname);
-
- if (!open_connection(&cli2)) {
+
+ if (!open_connection(&cli2)) {
printf("[8] failed to open second connection.\n");
- return;
- }
+ return False;
+ }
cli_sockopt(&cli1, sockops);
-
+
fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
- FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0);
-
+ FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0);
+
if (fnum1 == -1) {
printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
- return;
+ return False;
}
fnum2 = cli_nt_create_full(&cli2, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
- FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
-
+ FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
+
if (fnum2 == -1) {
printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
- return;
+ return False;
}
if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
- printf("[8] setting delete_on_close on file failed !\n");
- return;
- }
-
- if (!cli_close(&cli1, fnum1)) {
- printf("[8] close - 1 failed (%s)\n", cli_errstr(&cli1));
- return;
- }
+ printf("[8] setting delete_on_close on file failed !\n");
+ return False;
+ }
+
+ if (!cli_close(&cli1, fnum1)) {
+ printf("[8] close - 1 failed (%s)\n", cli_errstr(&cli1));
+ return False;
+ }
- if (!cli_close(&cli2, fnum2)) {
- printf("[8] close - 2 failed (%s)\n", cli_errstr(&cli2));
- return;
- }
+ if (!cli_close(&cli2, fnum2)) {
+ printf("[8] close - 2 failed (%s)\n", cli_errstr(&cli2));
+ return False;
+ }
/* This should fail.. */
- fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
- if (fnum1 != -1) {
+ fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
+ if (fnum1 != -1) {
printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
if (!cli_close(&cli1, fnum1)) {
printf("[8] close failed (%s)\n", cli_errstr(&cli1));
}
cli_unlink(&cli1, fname);
- } else
+ correct = False;
+ } else
printf("eighth delete on close test succeeded.\n");
- printf("finished delete test\n");
-
+ printf("finished delete test\n");
+
cli_setatr(&cli1, fname, 0, 0);
cli_unlink(&cli1, fname);
-
- close_connection(&cli1);
- close_connection(&cli2);
+
+ if (!close_connection(&cli1)) {
+ correct = False;
+ }
+ if (!close_connection(&cli2)) {
+ correct = False;
+ }
+ return correct;
}
/*
Test open mode returns on read-only files.
*/
-static void run_opentest(int dummy)
+static BOOL run_opentest(int dummy)
{
- static struct cli_state cli1;
- char *fname = "\\readonly.file";
- int fnum1, fnum2;
+ static struct cli_state cli1;
+ char *fname = "\\readonly.file";
+ int fnum1, fnum2;
uint8 eclass;
uint32 errnum;
char buf[20];
size_t fsize;
+ BOOL correct = True;
- printf("starting open test\n");
-
- if (!open_connection(&cli1)) {
- return;
- }
-
+ printf("starting open test\n");
+
+ if (!open_connection(&cli1)) {
+ return False;
+ }
+
cli_setatr(&cli1, fname, 0, 0);
- cli_unlink(&cli1, fname);
-
- cli_sockopt(&cli1, sockops);
-
- 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;
- }
-
- if (!cli_close(&cli1, fnum1)) {
- printf("close2 failed (%s)\n", cli_errstr(&cli1));
- return;
- }
+ cli_unlink(&cli1, fname);
+
+ cli_sockopt(&cli1, sockops);
+
+ 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 False;
+ }
+ if (!cli_close(&cli1, fnum1)) {
+ printf("close2 failed (%s)\n", cli_errstr(&cli1));
+ return False;
+ }
+
if (!cli_setatr(&cli1, fname, aRONLY, 0)) {
printf("cli_setatr failed (%s)\n", cli_errstr(&cli1));
- return;
+ return False;
}
-
- fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE);
- if (fnum1 == -1) {
- printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
- return;
- }
-
+
+ fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE);
+ if (fnum1 == -1) {
+ printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
+ return False;
+ }
+
/* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
- fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL);
-
+ fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL);
+
cli_error( &cli1, &eclass, &errnum, NULL);
-
+
if (eclass != ERRDOS || errnum != ERRnoaccess) {
printf("wrong error code (%x,%x) = %s\n", (unsigned int)eclass,
- (unsigned int)errnum, cli_errstr(&cli1) );
+ (unsigned int)errnum, cli_errstr(&cli1) );
+ correct = False;
} else {
printf("correct error code ERRDOS/ERRnoaccess returned\n");
}
-
- printf("finished open test 1\n");
-
+
+ printf("finished open test 1\n");
+
cli_close(&cli1, fnum1);
-
+
/* Now try not readonly and ensure ERRbadshare is returned. */
-
+
cli_setatr(&cli1, fname, 0, 0);
-
- fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE);
- if (fnum1 == -1) {
- printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
- return;
- }
-
+
+ fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE);
+ if (fnum1 == -1) {
+ printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
+ return False;
+ }
+
/* This will fail - but the error should be ERRshare. */
- fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL);
-
+ fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL);
+
cli_error( &cli1, &eclass, &errnum, NULL);
if (eclass != ERRDOS || errnum != ERRbadshare) {
printf("wrong error code (%x,%x) = %s\n", (unsigned int)eclass,
- (unsigned int)errnum, cli_errstr(&cli1) );
+ (unsigned int)errnum, cli_errstr(&cli1) );
+ correct = False;
} else {
printf("correct error code ERRDOS/ERRbadshare returned\n");
}
-
- if (!cli_close(&cli1, fnum1)) {
- printf("close2 failed (%s)\n", cli_errstr(&cli1));
- return;
- }
-
+
+ if (!cli_close(&cli1, fnum1)) {
+ printf("close2 failed (%s)\n", cli_errstr(&cli1));
+ return False;
+ }
+
cli_unlink(&cli1, fname);
-
- printf("finished open test 2\n");
-
+
+ printf("finished open test 2\n");
+
/* Test truncate open disposition on file opened for read. */
-
- fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
- if (fnum1 == -1) {
- printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(&cli1));
- return;
- }
-
+
+ fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
+ if (fnum1 == -1) {
+ printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(&cli1));
+ return False;
+ }
+
/* write 20 bytes. */
-
+
memset(buf, '\0', 20);
if (cli_write(&cli1, fnum1, 0, buf, 0, 20) != 20) {
printf("write failed (%s)\n", cli_errstr(&cli1));
+ correct = False;
}
- if (!cli_close(&cli1, fnum1)) {
- printf("(3) close1 failed (%s)\n", cli_errstr(&cli1));
- return;
- }
-
+ if (!cli_close(&cli1, fnum1)) {
+ printf("(3) close1 failed (%s)\n", cli_errstr(&cli1));
+ return False;
+ }
+
/* Ensure size == 20. */
if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) {
printf("(3) getatr failed (%s)\n", cli_errstr(&cli1));
- return;
+ return False;
}
-
+
if (fsize != 20) {
printf("(3) file size != 20\n");
- return;
+ return False;
}
/* Now test if we can truncate a file opened for readonly. */
-
+
fnum1 = cli_open(&cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
- if (fnum1 == -1) {
- printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(&cli1));
- return;
- }
-
- if (!cli_close(&cli1, fnum1)) {
- printf("close2 failed (%s)\n", cli_errstr(&cli1));
- return;
- }
+ if (fnum1 == -1) {
+ printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(&cli1));
+ return False;
+ }
+
+ if (!cli_close(&cli1, fnum1)) {
+ printf("close2 failed (%s)\n", cli_errstr(&cli1));
+ return False;
+ }
/* Ensure size == 0. */
if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) {
printf("(3) getatr failed (%s)\n", cli_errstr(&cli1));
- return;
+ return False;
}
if (fsize != 0) {
printf("(3) file size != 0\n");
- return;
+ return False;
}
- printf("finished open test 3\n");
-
+ printf("finished open test 3\n");
+
cli_unlink(&cli1, fname);
@@ -2692,15 +2912,18 @@ static void run_opentest(int dummy)
fnum1 = cli_ctemp(&cli1, "\\", &tmp_path);
if (fnum1 == -1) {
printf("ctemp failed (%s)\n", cli_errstr(&cli1));
- return;
+ return False;
}
printf("ctemp gave path %s\n", tmp_path);
cli_close(&cli1, fnum1);
cli_unlink(&cli1, tmp_path);
}
-
- close_connection(&cli1);
-
+
+ if (!close_connection(&cli1)) {
+ correct = False;
+ }
+
+ return correct;
}
static void list_fn(file_info *finfo, const char *name, void *state)
@@ -2711,17 +2934,18 @@ static void list_fn(file_info *finfo, const char *name, void *state)
/*
test directory listing speed
*/
-static void run_dirtest(int dummy)
+static BOOL run_dirtest(int dummy)
{
int i;
static struct cli_state cli;
int fnum;
double t1;
+ BOOL correct = True;
printf("starting directory test\n");
if (!open_connection(&cli)) {
- return;
+ return False;
}
cli_sockopt(&cli, sockops);
@@ -2733,7 +2957,7 @@ static void run_dirtest(int dummy)
fnum = cli_open(&cli, fname, O_RDWR|O_CREAT, DENY_NONE);
if (fnum == -1) {
fprintf(stderr,"Failed to open %s\n", fname);
- return;
+ return False;
}
cli_close(&cli, fnum);
}
@@ -2753,31 +2977,43 @@ static void run_dirtest(int dummy)
cli_unlink(&cli, fname);
}
- close_connection(&cli);
+ if (!close_connection(&cli)) {
+ correct = False;
+ }
printf("finished dirtest\n");
+
+ return correct;
}
-static double create_procs(void (*fn)(int))
+static double create_procs(BOOL (*fn)(int), BOOL *result)
{
int i, status;
- volatile int *child_status;
+ volatile pid_t *child_status;
+ volatile BOOL *child_status_out;
int synccount;
int tries = 8;
- start_timer();
-
synccount = 0;
- child_status = (volatile int *)shm_setup(sizeof(int)*nprocs);
+ child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
if (!child_status) {
printf("Failed to setup shared memory\n");
- return end_timer();
+ return -1;
+ }
+
+ child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*nprocs);
+ if (!child_status_out) {
+ printf("Failed to setup result status shared memory\n");
+ return -1;
}
- memset((char *)child_status, 0, sizeof(int)*nprocs);
+ memset(child_status, 0, sizeof(pid_t)*nprocs);
+ memset(child_status_out, True, sizeof(BOOL)*nprocs);
+
+ start_timer();
for (i=0;i<nprocs;i++) {
procnum = i;
@@ -2794,14 +3030,14 @@ static double create_procs(void (*fn)(int))
printf("pid %d failed to start\n", (int)getpid());
_exit(1);
}
- msleep(10);
+ msleep(10);
}
child_status[i] = getpid();
while (child_status[i]) msleep(2);
- fn(i);
+ child_status_out[i] = fn(i);
_exit(0);
}
}
@@ -2817,6 +3053,7 @@ static double create_procs(void (*fn)(int))
if (synccount != nprocs) {
printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
+ *result = False;
return end_timer();
}
@@ -2833,7 +3070,14 @@ static double create_procs(void (*fn)(int))
waitpid(0, &status, 0);
printf("*");
}
+
printf("\n");
+
+ for (i=0;i<nprocs;i++) {
+ if (!child_status_out[i]) {
+ *result = False;
+ }
+ }
return end_timer();
}
@@ -2842,7 +3086,7 @@ static double create_procs(void (*fn)(int))
static struct {
char *name;
- void (*fn)(int);
+ BOOL (*fn)(int);
unsigned flags;
} torture_ops[] = {
{"FDPASS", run_fdpasstest, 0},
@@ -2881,9 +3125,12 @@ static struct {
/****************************************************************************
run a specified test or "ALL"
****************************************************************************/
-static void run_test(char *name)
+static BOOL run_test(char *name)
{
+ BOOL ret = True;
+ BOOL result = True;
int i;
+ double t;
if (strequal(name,"ALL")) {
for (i=0;torture_ops[i].name;i++) {
run_test(torture_ops[i].name);
@@ -2895,16 +3142,26 @@ static void run_test(char *name)
(unsigned)random());
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);
+ t = create_procs(torture_ops[i].fn, &result);
+ if (!result) {
+ ret = False;
+ printf("TEST %s FAILED!\n", name);
+ }
+
} else {
- torture_ops[i].fn(0);
+ start_timer();
+ if (!torture_ops[i].fn(0)) {
+ ret = False;
+ printf("TEST %s FAILED!\n", name);
+ }
+ t = end_timer();
}
- printf("%s took %g secs\n\n", name, end_timer());
+ printf("%s took %g secs\n\n", name, t);
}
}
+ return ret;
}
@@ -2952,6 +3209,7 @@ static void usage(void)
extern int optind;
extern FILE *dbf;
static pstring servicesf = CONFIGFILE;
+ BOOL correct = True;
dbf = stdout;
@@ -3052,12 +3310,18 @@ static void usage(void)
host, share, username, myname);
if (argc == 1) {
- run_test("ALL");
+ correct = run_test("ALL");
} else {
for (i=1;i<argc;i++) {
- run_test(argv[i]);
+ if (!run_test(argv[i])) {
+ correct = False;
+ }
}
}
- return(0);
+ if (correct) {
+ return(0);
+ } else {
+ return(1);
+ }
}