From be242703e1dcdd562a5e9b39ee5c0fd95a5ac5cc Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 2 Jul 2001 03:21:17 +0000 Subject: Make smbtorture return status values for use in the build_farm tests. This should not have changed behaviour, and it has been tested. Andrew Bartlett (This used to be commit a73aefef09804bf95eec1449f75adc5ff5e032d0) --- source3/torture/torture.c | 1202 +++++++++++++++++++++++++++------------------ 1 file changed, 733 insertions(+), 469 deletions(-) (limited to 'source3/torture/torture.c') 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 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