r4430: - fixed the BASE-LOCK* tests to use a subdirectory, and properly setup the...
[samba.git] / source4 / torture / basic / locking.c
index aea94bd5a1b8577c75023282950efea8e8f5e741..00310e54055b2bf0682a4e739602e16e391599e3 100644 (file)
@@ -25,6 +25,8 @@
 #include "libcli/raw/libcliraw.h"
 #include "system/time.h"
 
+#define BASEDIR "\\locktest"
+
 /*
   This test checks for two things:
 
@@ -35,7 +37,7 @@
 BOOL torture_locktest1(void)
 {
        struct smbcli_state *cli1, *cli2;
-       const char *fname = "\\lockt1.lck";
+       const char *fname = BASEDIR "\\lockt1.lck";
        int fnum1, fnum2, fnum3;
        time_t t1, t2;
        uint_t lock_timeout;
@@ -46,7 +48,9 @@ BOOL torture_locktest1(void)
 
        printf("starting locktest1\n");
 
-       smbcli_unlink(cli1->tree, fname);
+       if (!torture_setup_dir(cli1, BASEDIR)) {
+               return False;
+       }
 
        fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
        if (fnum1 == -1) {
@@ -55,7 +59,8 @@ BOOL torture_locktest1(void)
        }
        fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_NONE);
        if (fnum2 == -1) {
-               printf("open2 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
+               printf("(%s) open2 of %s failed (%s)\n", 
+                      __location__, fname, smbcli_errstr(cli1->tree));
                return False;
        }
        fnum3 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE);
@@ -189,7 +194,7 @@ BOOL torture_locktest1(void)
 BOOL torture_locktest2(void)
 {
        struct smbcli_state *cli;
-       const char *fname = "\\lockt2.lck";
+       const char *fname = BASEDIR "\\lockt2.lck";
        int fnum1, fnum2, fnum3;
        BOOL correct = True;
 
@@ -199,7 +204,9 @@ BOOL torture_locktest2(void)
 
        printf("starting locktest2\n");
 
-       smbcli_unlink(cli->tree, fname);
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return False;
+       }
 
        printf("Testing pid context\n");
        
@@ -213,7 +220,8 @@ BOOL torture_locktest2(void)
 
        fnum2 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE);
        if (fnum2 == -1) {
-               printf("open2 of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
+               printf("(%s) open2 of %s failed (%s)\n", 
+                      __location__, fname, smbcli_errstr(cli->tree));
                return False;
        }
 
@@ -327,7 +335,7 @@ BOOL torture_locktest2(void)
 BOOL torture_locktest3(void)
 {
        struct smbcli_state *cli1, *cli2;
-       const char *fname = "\\lockt3.lck";
+       const char *fname = BASEDIR "\\lockt3.lck";
        int fnum1, fnum2, i;
        uint32_t offset;
        BOOL correct = True;
@@ -343,7 +351,9 @@ BOOL torture_locktest3(void)
 
        printf("Testing 32 bit offset ranges\n");
 
-       smbcli_unlink(cli1->tree, fname);
+       if (!torture_setup_dir(cli1, BASEDIR)) {
+               return False;
+       }
 
        fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
        if (fnum1 == -1) {
@@ -459,10 +469,10 @@ BOOL torture_locktest3(void)
 BOOL torture_locktest4(void)
 {
        struct smbcli_state *cli1, *cli2;
-       const char *fname = "\\lockt4.lck";
+       const char *fname = BASEDIR "\\lockt4.lck";
        int fnum1, fnum2, f;
        BOOL ret;
-       char buf[1000];
+       uint8_t buf[1000];
        BOOL correct = True;
 
        if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
@@ -471,7 +481,9 @@ BOOL torture_locktest4(void)
 
        printf("starting locktest4\n");
 
-       smbcli_unlink(cli1->tree, fname);
+       if (!torture_setup_dir(cli1, BASEDIR)) {
+               return False;
+       }
 
        fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
        fnum2 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE);
@@ -627,10 +639,10 @@ BOOL torture_locktest4(void)
 BOOL torture_locktest5(void)
 {
        struct smbcli_state *cli1, *cli2;
-       const char *fname = "\\lockt5.lck";
+       const char *fname = BASEDIR "\\lockt5.lck";
        int fnum1, fnum2, fnum3;
        BOOL ret;
-       char buf[1000];
+       uint8_t buf[1000];
        BOOL correct = True;
 
        if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
@@ -639,7 +651,9 @@ BOOL torture_locktest5(void)
 
        printf("starting locktest5\n");
 
-       smbcli_unlink(cli1->tree, fname);
+       if (!torture_setup_dir(cli1, BASEDIR)) {
+               return False;
+       }
 
        fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
        fnum2 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE);
@@ -757,6 +771,10 @@ BOOL torture_locktest6(void)
                return False;
        }
 
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return False;
+       }
+
        printf("starting locktest6\n");
 
        for (i=0;i<1;i++) {
@@ -786,11 +804,11 @@ BOOL torture_locktest6(void)
 BOOL torture_locktest7(void)
 {
        struct smbcli_state *cli1;
-       const char *fname = "\\lockt7.lck";
+       const char *fname = BASEDIR "\\lockt7.lck";
        int fnum1;
-       int fnum2;
+       int fnum2 = -1;
        size_t size;
-       char buf[200];
+       uint8_t buf[200];
        BOOL correct = False;
 
        if (!torture_open_connection(&cli1)) {
@@ -799,7 +817,9 @@ BOOL torture_locktest7(void)
 
        printf("starting locktest7\n");
 
-       smbcli_unlink(cli1->tree, fname);
+       if (!torture_setup_dir(cli1, BASEDIR)) {
+               return False;
+       }
 
        fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);