r3699: - split the delayed write testing out of RAW-WRITE, as it is not yet
authorAndrew Tridgell <tridge@samba.org>
Fri, 12 Nov 2004 09:37:59 +0000 (09:37 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:05:45 +0000 (13:05 -0500)
  clear what the correct behaviour is for delayed stat info update.

- use a common torture_setup_dir() function for setting up a test
  directory in torture tests.

23 files changed:
source/torture/basic/charset.c
source/torture/basic/delaywrite.c [new file with mode: 0644]
source/torture/basic/dir.c
source/torture/basic/disconnect.c
source/torture/basic/mangle_test.c
source/torture/basic/utable.c
source/torture/config.mk
source/torture/raw/chkpath.c
source/torture/raw/context.c
source/torture/raw/ioctl.c
source/torture/raw/lock.c
source/torture/raw/mux.c
source/torture/raw/notify.c
source/torture/raw/open.c
source/torture/raw/read.c
source/torture/raw/rename.c
source/torture/raw/search.c
source/torture/raw/seek.c
source/torture/raw/setfileinfo.c
source/torture/raw/unlink.c
source/torture/raw/write.c
source/torture/torture.c
source/torture/torture_util.c

index 090303ac306645db5832af480ce5cc94f7deccfd..4f57eba64a45ea6270ed711a94b8b8e32a48416b 100644 (file)
@@ -239,12 +239,7 @@ BOOL torture_charset(void)
 
        printf("Starting charset tests\n");
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1) {
-               printf("Failed to clean " BASEDIR "\n");
-               return False;
-       }
-       if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Failed to create " BASEDIR " - %s\n", smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
diff --git a/source/torture/basic/delaywrite.c b/source/torture/basic/delaywrite.c
new file mode 100644 (file)
index 0000000..3a632c4
--- /dev/null
@@ -0,0 +1,284 @@
+/* 
+   Unix SMB/CIFS implementation.
+
+   test suite for delayed write update 
+
+   Copyright (C) Volker Lendecke 2004
+   Copyright (C) Andrew Tridgell 2004
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "libcli/raw/libcliraw.h"
+#include "system/time.h"
+
+#define BASEDIR "\\delaywrite"
+
+static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+{
+       union smb_fileinfo finfo1, finfo2;
+       const char *fname = BASEDIR "\\torture_file.txt";
+       NTSTATUS status;
+       int fnum1 = -1;
+       BOOL ret = True;
+       ssize_t written;
+       time_t t;
+
+       printf("Testing delayed update of write time\n");
+
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return False;
+       }
+
+       fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
+       if (fnum1 == -1) {
+               printf("Failed to open %s\n", fname);
+               return False;
+       }
+
+       finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
+       finfo1.basic_info.in.fnum = fnum1;
+       finfo2 = finfo1;
+
+       status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
+               return False;
+       }
+       
+       printf("Initial write time %s\n", 
+              nt_time_string(mem_ctx, finfo1.basic_info.out.write_time));
+
+       /* 3 second delay to ensure we get past any 2 second time
+          granularity (older systems may have that) */
+       sleep(3);
+
+       written =  smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
+
+       if (written != 1) {
+               printf("write failed - wrote %d bytes (%s)\n", written, __location__);
+               return False;
+       }
+
+       t = time(NULL);
+
+       while (time(NULL) < t+120) {
+               status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2);
+
+               if (!NT_STATUS_IS_OK(status)) {
+                       DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
+                       ret = False;
+                       break;
+               }
+               printf("write time %s\n", 
+                      nt_time_string(mem_ctx, finfo2.basic_info.out.write_time));
+               if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
+                       printf("Server updated write_time after %d seconds\n",
+                              (int)(time(NULL) - t));
+                       break;
+               }
+               sleep(1);
+               fflush(stdout);
+       }
+       
+       if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) {
+               printf("Server did not update write time?!\n");
+               ret = False;
+       }
+
+
+       if (fnum1 != -1)
+               smbcli_close(cli->tree, fnum1);
+       smbcli_unlink(cli->tree, fname);
+       smbcli_deltree(cli->tree, BASEDIR);
+
+       return ret;
+}
+
+
+/* Windows does obviously not update the stat info during a write call. I
+ * *think* this is the problem causing a spurious Excel 2003 on XP error
+ * message when saving a file. Excel does a setfileinfo, writes, and then does
+ * a getpath(!)info. Or so... For Samba sometimes it displays an error message
+ * that the file might have been changed in between. What i've been able to
+ * trace down is that this happens if the getpathinfo after the write shows a
+ * different last write time than the setfileinfo showed. This is really
+ * nasty....
+ */
+
+static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+{
+       union smb_fileinfo finfo1, finfo2;
+       const char *fname = BASEDIR "\\torture_file.txt";
+       NTSTATUS status;
+       int fnum1 = -1;
+       int fnum2;
+       BOOL ret = True;
+       ssize_t written;
+       struct smbcli_state *cli2=NULL;
+
+       printf("Testing finfo update on close\n");
+
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return False;
+       }
+
+       fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
+       if (fnum1 == -1) {
+               ret = False;
+               goto done;
+       }
+
+       finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
+       finfo1.basic_info.in.fnum = fnum1;
+
+       status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
+               ret = False;
+               goto done;
+       }
+
+       msleep(1000);
+
+       written =  smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
+
+       if (written != 1) {
+               printf("(%s) written gave %d - should have been 1\n", 
+                      __location__, written);
+               ret = False;
+               goto done;
+       }
+
+       if (!torture_open_connection(&cli2)) {
+               return False;
+       }
+
+       fnum2 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE);
+       if (fnum2 == -1) {
+               printf("(%s) failed to open 2nd time - %s\n", 
+                      __location__, smbcli_errstr(cli2->tree));
+               ret = False;
+               goto done;
+       }
+       
+       written =  smbcli_write(cli2->tree, fnum2, 0, "x", 0, 1);
+       
+       if (written != 1) {
+               printf("(%s) written gave %d - should have been 1\n", 
+                      __location__, written);
+               ret = False;
+               goto done;
+       }
+       
+       finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO;
+       finfo2.basic_info.in.fname = fname;
+       
+       status = smb_raw_pathinfo(cli2->tree, mem_ctx, &finfo2);
+       
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0, ("(%s) fileinfo failed: %s\n", 
+                         __location__, nt_errstr(status)));
+               ret = False;
+               goto done;
+       }
+       
+       if (finfo1.basic_info.out.create_time !=
+           finfo2.basic_info.out.create_time) {
+               printf("(%s) create_time changed\n", __location__);
+               ret = False;
+               goto done;
+       }
+       
+       if (finfo1.basic_info.out.access_time !=
+           finfo2.basic_info.out.access_time) {
+               printf("(%s) access_time changed\n", __location__);
+               ret = False;
+               goto done;
+       }
+       
+       if (finfo1.basic_info.out.write_time !=
+           finfo2.basic_info.out.write_time) {
+               printf("(%s) write_time changed\n", __location__);
+               ret = False;
+               goto done;
+       }
+       
+       if (finfo1.basic_info.out.change_time !=
+           finfo2.basic_info.out.change_time) {
+               printf("(%s) change_time changed\n", __location__);
+               ret = False;
+               goto done;
+       }
+       
+       /* One of the two following calls updates the qpathinfo. */
+       
+       /* If you had skipped the smbcli_write on fnum2, it would
+        * *not* have updated the stat on disk */
+       
+       smbcli_close(cli2->tree, fnum2);
+       torture_close_connection(cli2);
+       cli2 = NULL;
+
+       /* This call is only for the people looking at ethereal :-) */
+       finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO;
+       finfo2.basic_info.in.fname = fname;
+
+       status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo2);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
+               ret = False;
+               goto done;
+       }
+
+ done:
+       if (fnum1 != -1)
+               smbcli_close(cli->tree, fnum1);
+       smbcli_unlink(cli->tree, fname);
+       smbcli_deltree(cli->tree, BASEDIR);
+       if (cli2 != NULL) {
+               torture_close_connection(cli2);
+       }
+
+       return ret;
+}
+
+
+/* 
+   testing of delayed update of write_time
+*/
+BOOL torture_delay_write(void)
+{
+       struct smbcli_state *cli;
+       BOOL ret = True;
+       TALLOC_CTX *mem_ctx;
+
+       if (!torture_open_connection(&cli)) {
+               return False;
+       }
+
+       mem_ctx = talloc_init("torture_delay_write");
+
+       ret &= test_finfo_after_write(cli, mem_ctx);
+       ret &= test_delayed_write_update(cli, mem_ctx);
+
+       torture_close_connection(cli);
+       talloc_destroy(mem_ctx);
+       return ret;
+}
index 7921b3eb0334aa952d8396d181baf5b0739214c0..6e2e21fc082a9d1f1f9abe19faad06585005d982 100644 (file)
@@ -99,12 +99,7 @@ BOOL torture_dirtest2(void)
                return False;
        }
 
-       if (smbcli_deltree(cli->tree, "\\LISTDIR") == -1) {
-               fprintf(stderr,"Failed to deltree %s, error=%s\n", "\\LISTDIR", smbcli_errstr(cli->tree));
-               return False;
-       }
-       if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\LISTDIR"))) {
-               fprintf(stderr,"Failed to mkdir %s, error=%s\n", "\\LISTDIR", smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, "\\LISTDIR")) {
                return False;
        }
 
index 683cdb81c8b7ceff753a5a514e93a49230bee3e8..a225178b960805e4814d1cc1e6fc1f820db2be6c 100644 (file)
@@ -136,17 +136,8 @@ BOOL torture_disconnect(void)
                return False;
        }
 
-       /* cleanup */
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1) {
-               printf("(%s) Failed to cleanup " BASEDIR "\n", __location__);
-               ret = False;
-               goto done;
-       }
-
-       if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Failed to create %s\n", BASEDIR);
-               ret = False;
-               goto done;
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return False;
        }
 
        for (i=0;i<100;i++) {
@@ -161,7 +152,6 @@ BOOL torture_disconnect(void)
                }
        }
 
-done:
        smb_raw_exit(cli->session);
        smbcli_deltree(cli->tree, BASEDIR);
        torture_close_connection(cli);
index 8c4f5514a6b13cdd2c7ad0c44a470270c49f0b13..70a92275216bdefceefcf53394ff215df4f8c86e 100644 (file)
@@ -167,11 +167,7 @@ BOOL torture_mangle(void)
                return False;
        }
 
-       smbcli_unlink(cli->tree, "\\mangle_test\\*");
-       smbcli_rmdir(cli->tree, "\\mangle_test");
-
-       if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\mangle_test"))) {
-               printf("ERROR: Failed to make directory\n");
+       if (!torture_setup_dir(cli, "\\mangle_test")) {
                return False;
        }
 
index c09ef576a53ebafc957e9e2f69cf3a037d777b83..30d389dd928c52a22882261b0ac413d56dab4d08 100644 (file)
@@ -42,8 +42,9 @@ BOOL torture_utable(void)
 
        memset(valid, 0, sizeof(valid));
 
-       smbcli_mkdir(cli->tree, "\\utable");
-       smbcli_unlink(cli->tree, "\\utable\\*");
+       if (!torture_setup_dir(cli, "\\utable")) {
+               return False;
+       }
 
        for (c=1; c < 0x10000; c++) {
                char *p;
@@ -133,9 +134,7 @@ BOOL torture_casetable(void)
 
        memset(equiv, 0, sizeof(equiv));
 
-       smbcli_deltree(cli->tree, "\\utable");
-       if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\utable"))) {
-               printf("Failed to create utable directory!\n");
+       if (!torture_setup_dir(cli, "\\utable")) {
                return False;
        }
 
index d939175bb32d001dd197fa4798ac45200a43c29b..d57bbd8e8eb5dbbfdd92fadd105e20be1bdb373e 100644 (file)
@@ -17,6 +17,7 @@ ADD_OBJ_FILES = \
                torture/basic/delete.o \
                torture/basic/unlink.o \
                torture/basic/disconnect.o \
+               torture/basic/delaywrite.o \
                torture/basic/attr.o 
 REQUIRED_SUBSYSTEMS = \
                LIBSMB
index 20bb3f8ebd35853cdf5c2ef3e48f52eb0acf4f70..494894988649f49a066f5291a6647c7eb42ce10a 100644 (file)
@@ -223,12 +223,7 @@ BOOL torture_raw_chkpath(void)
 
        mem_ctx = talloc_init("torture_raw_chkpath");
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1) {
-               printf("Failed to clean " BASEDIR "\n");
-               return False;
-       }
-       if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Failed to create " BASEDIR " - %s\n", smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
index 8f72c6d58238ae0aa4853042da6a5fb95bf86a0a..446ada80a6f79369f6f6a866c4f2cec7e258d56e 100644 (file)
@@ -70,9 +70,7 @@ static BOOL test_session(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        printf("TESTING SESSION HANDLING\n");
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
@@ -213,9 +211,7 @@ static BOOL test_tree(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        printf("TESTING TREE HANDLING\n");
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
@@ -315,9 +311,7 @@ static BOOL test_pid(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        printf("TESTING PID HANDLING\n");
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
index 50d3566fe8b1134b99caf944420e21877b58a33b..f050d220eb27e24e9ea5afce17b1c8ebaf8c83e5 100644 (file)
@@ -142,12 +142,7 @@ BOOL torture_raw_ioctl(void)
 
        mem_ctx = talloc_init("torture_raw_ioctl");
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1) {
-               printf("Failed to clean " BASEDIR "\n");
-               return False;
-       }
-       if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Failed to create " BASEDIR " - %s\n", smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
index 034c79326044454d24d9271e225eb6473f0ac294..547115c9f5e8b1c0a495ea330454128ee1bc6057 100644 (file)
@@ -52,9 +52,7 @@ static BOOL test_lock(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        int fnum;
        const char *fname = BASEDIR "\\test.txt";
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
@@ -190,9 +188,7 @@ static BOOL test_lockx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        int fnum;
        const char *fname = BASEDIR "\\test.txt";
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
@@ -372,9 +368,7 @@ static BOOL test_pidhigh(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        const char *fname = BASEDIR "\\test.txt";
        char c = 1;
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
@@ -456,9 +450,7 @@ static BOOL test_async(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        time_t t;
        struct smbcli_request *req;
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
@@ -609,9 +601,7 @@ static BOOL test_changetype(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        char c = 0;
        const char *fname = BASEDIR "\\test.txt";
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
index 79eb485d554a0399ed404375d0af3c722443d30c..9afbc7c5069a302c19d1d32c661c53fb6184b47a 100644 (file)
@@ -315,18 +315,8 @@ BOOL torture_raw_mux(void)
 
        mem_ctx = talloc_init("torture_raw_mux");
 
-       /* cleanup */
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1) {
-               printf("(%s) Failed to cleanup " BASEDIR "\n", __location__);
-               ret = False;
-               goto done;
-       }
-
-
-       if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Failed to create %s\n", BASEDIR);
-               ret = False;
-               goto done;
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return False;
        }
 
        if (!test_mux_open(cli, mem_ctx)) {
@@ -341,7 +331,6 @@ BOOL torture_raw_mux(void)
                ret = False;
        }
 
-done:
        smb_raw_exit(cli->session);
        smbcli_deltree(cli->tree, BASEDIR);
        torture_close_connection(cli);
index 3fff04fc6f6a41c086d03c87a9fbda7b30aa1e5c..0156f5b2515798a1d95f8248cb566253ccd611e7 100644 (file)
@@ -67,11 +67,8 @@ BOOL torture_raw_notify(void)
 
        mem_ctx = talloc_init("torture_raw_notify");
 
-       /* cleanup */
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1) {
-               printf("Failed to cleanup " BASEDIR "\n");
-               ret = False;
-               goto done;
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return False;
        }
 
        /*
index e299bba254cd02cbdefd49f9109aa8c3ffc1694b..b80f6278c6d4daa8846f59ed8a9bb1d59a2a0cc0 100644 (file)
@@ -993,12 +993,7 @@ BOOL torture_raw_open(void)
 
        mem_ctx = talloc_init("torture_raw_open");
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1) {
-               printf("Failed to clean " BASEDIR "\n");
-               return False;
-       }
-       if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Failed to create " BASEDIR " - %s\n", smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
index 8b76a5a02992151a5b41ad49a19f5c2b73c34f3a..ff6d2baa2b01e8f2e70da73b396570ec6b03674a 100644 (file)
@@ -92,9 +92,7 @@ static BOOL test_read(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        buf = talloc_zero(mem_ctx, maxsize);
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
@@ -218,9 +216,7 @@ static BOOL test_lockread(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        buf = talloc_zero(mem_ctx, maxsize);
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
@@ -363,9 +359,7 @@ static BOOL test_readx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        buf = talloc_zero(mem_ctx, maxsize);
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
@@ -559,9 +553,7 @@ static BOOL test_readbraw(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        buf = talloc_zero(mem_ctx, maxsize);
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
index f80d6e13080360b99d686fb0309b1aa53e84a811..68bd2eda2daa75cbc635d0e6233e48519a68991c 100644 (file)
@@ -51,9 +51,7 @@ static BOOL test_mv(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        printf("Testing SMBmv\n");
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
@@ -141,9 +139,7 @@ static BOOL test_ntrename(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        printf("Testing SMBntrename\n");
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
index 0c3a724bf95ca53ddb8d5dce1ce15c18198fbbef..bca41e23f55e44ed8f4bc38cb12d8b32a4d99b9a 100644 (file)
@@ -607,9 +607,7 @@ static BOOL test_many_files(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
                {"DIRECTORY_INFO",      "NAME",  RAW_SEARCH_DIRECTORY_INFO,      CONT_NAME}
        };
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1 || 
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Failed to create " BASEDIR " - %s\n", smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
@@ -742,9 +740,7 @@ static BOOL test_modify_search(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        union smb_search_next io2;
        union smb_setfileinfo sfinfo;
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1 || 
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Failed to create " BASEDIR " - %s\n", smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
@@ -862,9 +858,7 @@ static BOOL test_sorted(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        NTSTATUS status;
        struct multiple_result result;
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1 || 
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Failed to create " BASEDIR " - %s\n", smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
@@ -927,9 +921,7 @@ static BOOL test_many_dirs(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        NTSTATUS status;
        union smb_search_data *file, *file2, *file3;
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1 || 
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Failed to create " BASEDIR " - %s\n", smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
index 94f0ba2385a427d1eef6a5c6667b251a0aede2c0..10b930b18f3e255679d6d492ad923663d1cc1e2f 100644 (file)
@@ -52,9 +52,7 @@ static BOOL test_seek(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        const char *fname = BASEDIR "\\test.txt";
        char c[2];
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
index 2e4cff99b0dd19b08fb01ecb30d209ce95baa22c..298ccf674b5bb9d8d3fd4695a162de8b6733f90f 100644 (file)
@@ -56,8 +56,9 @@ BOOL torture_raw_sfileinfo(void)
 
        mem_ctx = talloc_init("torture_sfileinfo");
 
-       smbcli_deltree(cli->tree, BASEDIR);
-       smbcli_mkdir(cli->tree, BASEDIR);
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return False;
+       }
 
 #define RECREATE_FILE(fname) do { \
        if (fnum != -1) smbcli_close(cli->tree, fnum); \
index 40ab137fa04e7564cbdaade02091e7b19a864474..d9c7ac6dfabbcbef8297746d09fd95ee16b77bd7 100644 (file)
@@ -40,9 +40,7 @@ static BOOL test_unlink(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        BOOL ret = True;
        const char *fname = BASEDIR "\\test.txt";
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
index 585e231cacb0ce34ffb2558cf5314fd620fab361..7def976b46883df982589b1da97a540217306fa6 100644 (file)
@@ -1,6 +1,7 @@
 /* 
    Unix SMB/CIFS implementation.
    test suite for various write operations
+
    Copyright (C) Andrew Tridgell 2003
    
    This program is free software; you can redistribute it and/or modify
 #define BASEDIR "\\testwrite"
 
 
-static BOOL setup_dir(struct smbcli_state *cli, const char *dname)
-{
-       smb_raw_exit(cli->session);
-       if (smbcli_deltree(cli->tree, dname) == -1 ||
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, dname))) {
-               printf("Unable to setup %s - %s\n", dname, smbcli_errstr(cli->tree));
-               return False;
-       }
-       return True;
-}
-
-
 /*
   setup a random buffer based on a seed
 */
@@ -117,7 +106,7 @@ static BOOL test_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        buf = talloc_zero(mem_ctx, maxsize);
 
-       if (!setup_dir(cli, BASEDIR)) {
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
@@ -234,7 +223,7 @@ static BOOL test_writex(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        buf = talloc_zero(mem_ctx, maxsize);
 
-       if (!setup_dir(cli, BASEDIR)) {
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
@@ -410,7 +399,7 @@ static BOOL test_writeunlock(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        buf = talloc_zero(mem_ctx, maxsize);
 
-       if (!setup_dir(cli, BASEDIR)) {
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
@@ -547,7 +536,7 @@ static BOOL test_writeclose(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        buf = talloc_zero(mem_ctx, maxsize);
 
-       if (!setup_dir(cli, BASEDIR)) {
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
@@ -680,238 +669,6 @@ done:
        return ret;
 }
 
-static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
-{
-       union smb_fileinfo finfo1, finfo2;
-       const char *fname = BASEDIR "\\torture_file.txt";
-       NTSTATUS status;
-       int fnum1 = -1;
-       BOOL ret = True;
-       ssize_t written;
-       time_t t;
-
-       printf("Testing delayed update of write time\n");
-
-       if (!setup_dir(cli, BASEDIR)) {
-               return False;
-       }
-
-       fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
-       if (fnum1 == -1) {
-               printf("Failed to open %s\n", fname);
-               return False;
-       }
-
-       finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
-       finfo1.basic_info.in.fnum = fnum1;
-       finfo2 = finfo1;
-
-       status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1);
-
-       if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
-               return False;
-       }
-       
-       printf("Initial write time %s\n", 
-              nt_time_string(mem_ctx, finfo1.basic_info.out.write_time));
-
-       /* 3 second delay to ensure we get past any 2 second time
-          granularity (older systems may have that) */
-       sleep(3);
-
-       written =  smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
-
-       if (written != 1) {
-               printf("write failed - wrote %d bytes (%s)\n", written, __location__);
-               return False;
-       }
-
-       t = time(NULL);
-
-       while (time(NULL) < t+120) {
-               status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2);
-
-               if (!NT_STATUS_IS_OK(status)) {
-                       DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
-                       ret = False;
-                       break;
-               }
-               printf("write time %s\n", 
-                      nt_time_string(mem_ctx, finfo2.basic_info.out.write_time));
-               if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
-                       printf("Server updated write_time after %d seconds\n",
-                              (int)(time(NULL) - t));
-                       break;
-               }
-               sleep(1);
-               fflush(stdout);
-       }
-       
-       if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) {
-               printf("Server did not update write time?!\n");
-               ret = False;
-       }
-
-
-       if (fnum1 != -1)
-               smbcli_close(cli->tree, fnum1);
-       smbcli_unlink(cli->tree, fname);
-       smbcli_deltree(cli->tree, BASEDIR);
-
-       return ret;
-}
-
-
-/* Windows does obviously not update the stat info during a write call. I
- * *think* this is the problem causing a spurious Excel 2003 on XP error
- * message when saving a file. Excel does a setfileinfo, writes, and then does
- * a getpath(!)info. Or so... For Samba sometimes it displays an error message
- * that the file might have been changed in between. What i've been able to
- * trace down is that this happens if the getpathinfo after the write shows a
- * different last write time than the setfileinfo showed. This is really
- * nasty....
- */
-
-static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
-{
-       union smb_fileinfo finfo1, finfo2;
-       const char *fname = BASEDIR "\\torture_file.txt";
-       NTSTATUS status;
-       int fnum1 = -1;
-       int fnum2;
-       BOOL ret = True;
-       ssize_t written;
-       struct smbcli_state *cli2=NULL;
-
-       printf("Testing finfo update on close\n");
-
-       if (!setup_dir(cli, BASEDIR)) {
-               return False;
-       }
-
-       fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
-       if (fnum1 == -1) {
-               ret = False;
-               goto done;
-       }
-
-       finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
-       finfo1.basic_info.in.fnum = fnum1;
-
-       status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1);
-
-       if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
-               ret = False;
-               goto done;
-       }
-
-       msleep(1000);
-
-       written =  smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
-
-       if (written != 1) {
-               printf("(%s) written gave %d - should have been 1\n", 
-                      __location__, written);
-               ret = False;
-               goto done;
-       }
-
-       if (!torture_open_connection(&cli2)) {
-               return False;
-       }
-
-       fnum2 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE);
-       if (fnum2 == -1) {
-               printf("(%s) failed to open 2nd time - %s\n", 
-                      __location__, smbcli_errstr(cli2->tree));
-               ret = False;
-               goto done;
-       }
-       
-       written =  smbcli_write(cli2->tree, fnum2, 0, "x", 0, 1);
-       
-       if (written != 1) {
-               printf("(%s) written gave %d - should have been 1\n", 
-                      __location__, written);
-               ret = False;
-               goto done;
-       }
-       
-       finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO;
-       finfo2.basic_info.in.fname = fname;
-       
-       status = smb_raw_pathinfo(cli2->tree, mem_ctx, &finfo2);
-       
-       if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, ("(%s) fileinfo failed: %s\n", 
-                         __location__, nt_errstr(status)));
-               ret = False;
-               goto done;
-       }
-       
-       if (finfo1.basic_info.out.create_time !=
-           finfo2.basic_info.out.create_time) {
-               printf("(%s) create_time changed\n", __location__);
-               ret = False;
-               goto done;
-       }
-       
-       if (finfo1.basic_info.out.access_time !=
-           finfo2.basic_info.out.access_time) {
-               printf("(%s) access_time changed\n", __location__);
-               ret = False;
-               goto done;
-       }
-       
-       if (finfo1.basic_info.out.write_time !=
-           finfo2.basic_info.out.write_time) {
-               printf("(%s) write_time changed\n", __location__);
-               ret = False;
-               goto done;
-       }
-       
-       if (finfo1.basic_info.out.change_time !=
-           finfo2.basic_info.out.change_time) {
-               printf("(%s) change_time changed\n", __location__);
-               ret = False;
-               goto done;
-       }
-       
-       /* One of the two following calls updates the qpathinfo. */
-       
-       /* If you had skipped the smbcli_write on fnum2, it would
-        * *not* have updated the stat on disk */
-       
-       smbcli_close(cli2->tree, fnum2);
-       torture_close_connection(cli2);
-       cli2 = NULL;
-
-       /* This call is only for the people looking at ethereal :-) */
-       finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO;
-       finfo2.basic_info.in.fname = fname;
-
-       status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo2);
-
-       if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
-               ret = False;
-               goto done;
-       }
-
- done:
-       if (fnum1 != -1)
-               smbcli_close(cli->tree, fnum1);
-       smbcli_unlink(cli->tree, fname);
-       smbcli_deltree(cli->tree, BASEDIR);
-       if (cli2 != NULL) {
-               torture_close_connection(cli2);
-       }
-
-       return ret;
-}
-
 /* 
    basic testing of write calls
 */
@@ -927,8 +684,6 @@ BOOL torture_raw_write(void)
 
        mem_ctx = talloc_init("torture_raw_write");
 
-       ret &= test_finfo_after_write(cli, mem_ctx);
-       ret &= test_delayed_write_update(cli, mem_ctx);
        ret &= test_write(cli, mem_ctx);
        ret &= test_writeunlock(cli, mem_ctx);
        ret &= test_writeclose(cli, mem_ctx);
index 4db4662f6c6d412a427047452627ee0cfa59e581..9db2f7f6bc00df5c253d5b52d87bb0db19279b8d 100644 (file)
@@ -2391,6 +2391,7 @@ static struct {
        {"BASE-CHKPATH",  torture_chkpath_test, 0},
        {"BASE-SECLEAK",  torture_sec_leak, 0},
        {"BASE-DISCONNECT",  torture_disconnect, 0},
+       {"BASE-DELAYWRITE", torture_delay_write, 0},
 
        /* benchmarking tests */
        {"BENCH-HOLDCON",  torture_holdcon, 0},
index 22aa9ffedd39e7a2ae35a1d06f1a1cf0e076c5df..af8a1ca0650e29c832ed94ff99952c42db5977fe 100644 (file)
 #include "system/time.h"
 
 
+/*
+  setup a directory ready for a test
+*/
+BOOL torture_setup_dir(struct smbcli_state *cli, const char *dname)
+{
+       smb_raw_exit(cli->session);
+       if (smbcli_deltree(cli->tree, dname) == -1 ||
+           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, dname))) {
+               printf("Unable to setup %s - %s\n", dname, smbcli_errstr(cli->tree));
+               return False;
+       }
+       return True;
+}
+
 /*
   create a directory, returning a handle to it
 */