r3148: make --failures work for the BASE-DENY1 and BASE-DENY2 tests
[bbaumbach/samba-autobuild/.git] / source4 / torture / basic / denytest.c
index 0e4f5251da4686275843d5245c32a246e36dd7ba..8c0339dfedc44e8d096208dab7a8c66e11ca6bc6 100644 (file)
@@ -21,6 +21,9 @@
 #include "includes.h"
 
 extern BOOL torture_showall;
+extern int torture_failures;
+
+#define CHECK_MAX_FAILURES(label) do { if (++failures >= torture_failures) goto label; } while (0)
 
 enum deny_result {A_0=0, A_X=1, A_R=2, A_W=3, A_RW=5};
 
@@ -79,7 +82,7 @@ static const char *resultstr(enum deny_result res)
        return "*";
 }
 
-static struct {
+static const struct {
        int isexe;
        int mode1, deny1;
        int mode2, deny2;
@@ -736,7 +739,7 @@ static struct {
 };
 
 
-static struct {
+static const struct {
        int isexe;
        int mode1, deny1;
        int mode2, deny2;
@@ -1393,7 +1396,7 @@ static struct {
 };
 
 
-static void progress_bar(unsigned i, unsigned total)
+static void progress_bar(uint_t i, uint_t total)
 {
        if (i % 10 != 0) return;
        printf("%5d/%5d\r", i, total);
@@ -1405,11 +1408,13 @@ static void progress_bar(unsigned i, unsigned total)
  */
 BOOL torture_denytest1(int dummy)
 {
-       static struct cli_state *cli1;
+       static struct smbcli_state *cli1;
        int fnum1, fnum2;
        int i;
        BOOL correct = True;
+       struct timeval tv, tv_start;
        const char *fnames[2] = {"\\denytest1.dat", "\\denytest1.exe"};
+       int failures=0;
 
        if (!torture_open_connection(&cli1)) {
                return False;
@@ -1420,24 +1425,26 @@ BOOL torture_denytest1(int dummy)
        printf("Testing deny modes with 1 connection\n");
 
        for (i=0;i<2;i++) {
-               cli_unlink(cli1->tree, fnames[i]);
-               fnum1 = cli_open(cli1->tree, fnames[i], O_RDWR|O_CREAT, DENY_NONE);
-               cli_write(cli1->tree, fnum1, 0, fnames[i], 0, strlen(fnames[i]));
-               cli_close(cli1->tree, fnum1);
+               smbcli_unlink(cli1->tree, fnames[i]);
+               fnum1 = smbcli_open(cli1->tree, fnames[i], O_RDWR|O_CREAT, DENY_NONE);
+               smbcli_write(cli1->tree, fnum1, 0, fnames[i], 0, strlen(fnames[i]));
+               smbcli_close(cli1->tree, fnum1);
        }
 
        printf("testing %d entries\n", ARRAY_SIZE(denytable1));
 
+       GetTimeOfDay(&tv_start);
+
        for (i=0; i<ARRAY_SIZE(denytable1); i++) {
                enum deny_result res;
                const char *fname = fnames[denytable1[i].isexe];
 
                progress_bar(i, ARRAY_SIZE(denytable1));
 
-               fnum1 = cli_open(cli1->tree, fname, 
+               fnum1 = smbcli_open(cli1->tree, fname, 
                                 denytable1[i].mode1,
                                 denytable1[i].deny1);
-               fnum2 = cli_open(cli1->tree, fname, 
+               fnum2 = smbcli_open(cli1->tree, fname, 
                                 denytable1[i].mode2,
                                 denytable1[i].deny2);
 
@@ -1448,20 +1455,21 @@ BOOL torture_denytest1(int dummy)
                } else {
                        char x = 1;
                        res = A_0;
-                       if (cli_read(cli1->tree, fnum2, (void *)&x, 0, 1) == 1) {
+                       if (smbcli_read(cli1->tree, fnum2, (void *)&x, 0, 1) == 1) {
                                res += A_R;
                        }
-                       if (cli_write(cli1->tree, fnum2, 0, (void *)&x, 0, 1) == 1) {
+                       if (smbcli_write(cli1->tree, fnum2, 0, (void *)&x, 0, 1) == 1) {
                                res += A_W;
                        }
                }
 
-               if (res != denytable1[i].result) {
-                       correct = False;
-               }
-
                if (torture_showall || res != denytable1[i].result) {
-                       printf("%s %8s %10s    %8s %10s    %s (correct=%s)\n",
+                       int64_t tdif;
+                       GetTimeOfDay(&tv);
+                       tdif = usec_time_diff(&tv, &tv_start);
+                       tdif /= 1000;
+                       printf("%lld: %s %8s %10s    %8s %10s    %s (correct=%s)\n",
+                              tdif,
                               fname,
                               denystr(denytable1[i].deny1),
                               openstr(denytable1[i].mode1),
@@ -1471,19 +1479,25 @@ BOOL torture_denytest1(int dummy)
                               resultstr(denytable1[i].result));
                }
 
-               cli_close(cli1->tree, fnum1);
-               cli_close(cli1->tree, fnum2);
+               if (res != denytable1[i].result) {
+                       correct = False;
+                       CHECK_MAX_FAILURES(failed);
+               }
+
+               smbcli_close(cli1->tree, fnum1);
+               smbcli_close(cli1->tree, fnum2);
        }
 
+failed:
        for (i=0;i<2;i++) {
-               cli_unlink(cli1->tree, fnames[i]);
+               smbcli_unlink(cli1->tree, fnames[i]);
        }
                
        if (!torture_close_connection(cli1)) {
                correct = False;
        }
        
-       printf("finshed denytest1\n");
+       printf("finshed denytest1 (%d failures)\n", failures);
        return correct;
 }
 
@@ -1493,11 +1507,13 @@ BOOL torture_denytest1(int dummy)
  */
 BOOL torture_denytest2(int dummy)
 {
-       static struct cli_state *cli1, *cli2;
+       static struct smbcli_state *cli1, *cli2;
        int fnum1, fnum2;
        int i;
        BOOL correct = True;
        const char *fnames[2] = {"\\denytest2.dat", "\\denytest2.exe"};
+       struct timeval tv, tv_start;
+       int failures=0;
 
        if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
                return False;
@@ -1508,22 +1524,24 @@ BOOL torture_denytest2(int dummy)
        printf("Testing deny modes with 2 connections\n");
 
        for (i=0;i<2;i++) {
-               cli_unlink(cli1->tree, fnames[i]);
-               fnum1 = cli_open(cli1->tree, fnames[i], O_RDWR|O_CREAT, DENY_NONE);
-               cli_write(cli1->tree, fnum1, 0, fnames[i], 0, strlen(fnames[i]));
-               cli_close(cli1->tree, fnum1);
+               smbcli_unlink(cli1->tree, fnames[i]);
+               fnum1 = smbcli_open(cli1->tree, fnames[i], O_RDWR|O_CREAT, DENY_NONE);
+               smbcli_write(cli1->tree, fnum1, 0, fnames[i], 0, strlen(fnames[i]));
+               smbcli_close(cli1->tree, fnum1);
        }
 
+       GetTimeOfDay(&tv_start);
+
        for (i=0; i<ARRAY_SIZE(denytable2); i++) {
                enum deny_result res;
                const char *fname = fnames[denytable2[i].isexe];
 
                progress_bar(i, ARRAY_SIZE(denytable1));
 
-               fnum1 = cli_open(cli1->tree, fname, 
+               fnum1 = smbcli_open(cli1->tree, fname, 
                                 denytable2[i].mode1,
                                 denytable2[i].deny1);
-               fnum2 = cli_open(cli2->tree, fname, 
+               fnum2 = smbcli_open(cli2->tree, fname, 
                                 denytable2[i].mode2,
                                 denytable2[i].deny2);
 
@@ -1534,20 +1552,21 @@ BOOL torture_denytest2(int dummy)
                } else {
                        char x = 1;
                        res = A_0;
-                       if (cli_read(cli2->tree, fnum2, (void *)&x, 0, 1) == 1) {
+                       if (smbcli_read(cli2->tree, fnum2, (void *)&x, 0, 1) == 1) {
                                res += A_R;
                        }
-                       if (cli_write(cli2->tree, fnum2, 0, (void *)&x, 0, 1) == 1) {
+                       if (smbcli_write(cli2->tree, fnum2, 0, (void *)&x, 0, 1) == 1) {
                                res += A_W;
                        }
                }
 
-               if (res != denytable2[i].result) {
-                       correct = False;
-               }
-
                if (torture_showall || res != denytable2[i].result) {
-                       printf("%s %8s %10s    %8s %10s    %s (correct=%s)\n",
+                       int64_t tdif;
+                       GetTimeOfDay(&tv);
+                       tdif = usec_time_diff(&tv, &tv_start);
+                       tdif /= 1000;
+                       printf("%lld: %s %8s %10s    %8s %10s    %s (correct=%s)\n",
+                               tdif,
                               fname,
                               denystr(denytable2[i].deny1),
                               openstr(denytable2[i].mode1),
@@ -1557,12 +1576,18 @@ BOOL torture_denytest2(int dummy)
                               resultstr(denytable2[i].result));
                }
 
-               cli_close(cli1->tree, fnum1);
-               cli_close(cli2->tree, fnum2);
+               if (res != denytable2[i].result) {
+                       correct = False;
+                       CHECK_MAX_FAILURES(failed);
+               }
+
+               smbcli_close(cli1->tree, fnum1);
+               smbcli_close(cli2->tree, fnum2);
        }
-               
+
+failed:                
        for (i=0;i<2;i++) {
-               cli_unlink(cli1->tree, fnames[i]);
+               smbcli_unlink(cli1->tree, fnames[i]);
        }
 
        if (!torture_close_connection(cli1)) {
@@ -1572,7 +1597,7 @@ BOOL torture_denytest2(int dummy)
                correct = False;
        }
        
-       printf("finshed denytest2\n");
+       printf("finshed denytest2 (%d failures)\n", failures);
        return correct;
 }