s4:torture:raw:notify: use torture_assert instead of printf in test_notify_tree
[kai/samba-autobuild/.git] / source4 / torture / raw / notify.c
index 26f7094b280c6d0ac4386ad510a703e071f5a8b3..02956ce4be25fb8a971784a1fbb228e913e2d4bb 100644 (file)
@@ -177,12 +177,9 @@ static bool test_notify_dir(struct torture_context *mem_ctx,
        for (i=0;i<count;i++) {
                char *fname = talloc_asprintf(cli, BASEDIR "\\test%d.txt", i);
                int fnum3 = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
-               if (fnum3 == -1) {
-                       printf("Failed to create %s - %s\n", 
-                              fname, smbcli_errstr(cli->tree));
-                       ret = false;
-                       goto done;
-               }
+               torture_assert_int_not_equal_goto(mem_ctx, fnum3, -1, ret, done,
+                       talloc_asprintf(mem_ctx, "Failed to create %s - %s",
+                                       fname, smbcli_errstr(cli->tree)));
                talloc_free(fname);
                smbcli_close(cli->tree, fnum3);
        }
@@ -675,10 +672,6 @@ static bool test_notify_mask_change(struct torture_context *mem_ctx,
        CHECK_WSTR(mem_ctx, notify.nttrans.out.changes[0].name, "subname3-r",
                   STR_UNICODE);
 
-       if (!ret) {
-               goto done;
-       }
-
 done:
        smb_raw_exit(cli->session);
        smbcli_deltree(cli->tree, BASEDIR);
@@ -738,7 +731,7 @@ static bool test_notify_mask(struct torture_context *tctx,
 #define NOTIFY_MASK_TEST(test_name, setup, op, cleanup, Action, expected, nchanges) \
        do { \
        smbcli_getatr(cli->tree, test_name, NULL, NULL, NULL); \
-       do { for (mask=i=0;i<32;i++) { \
+       for (mask=i=0;i<32;i++) { \
                struct smbcli_request *req; \
                status = smb_raw_open(cli->tree, tctx, &io); \
                torture_assert_ntstatus_ok_goto(tctx, status, ret, done, \
@@ -763,41 +756,46 @@ static bool test_notify_mask(struct torture_context *tctx,
                    ((expected) & FILE_NOTIFY_CHANGE_ATTRIBUTES) && \
                    Action == NOTIFY_ACTION_OLD_NAME) { \
                        printf("(rename file special handling OK)\n"); \
-               } else if (nchanges != notify.nttrans.out.num_changes) { \
-                       printf("ERROR: nchanges=%d expected=%d action=%d filter=0x%08x\n", \
-                              notify.nttrans.out.num_changes, \
-                              nchanges, \
-                              notify.nttrans.out.changes[0].action, \
-                              notify.nttrans.in.completion_filter); \
-                       ret = false; \
-               } else if (notify.nttrans.out.changes[0].action != Action) { \
-                       printf("ERROR: nchanges=%d action=%d expectedAction=%d filter=0x%08x\n", \
-                              notify.nttrans.out.num_changes, \
-                              notify.nttrans.out.changes[0].action, \
-                              Action, \
-                              notify.nttrans.in.completion_filter); \
-                       ret = false; \
-               } else if (strcmp(notify.nttrans.out.changes[0].name.s, "tname1") != 0) { \
-                       printf("ERROR: nchanges=%d action=%d filter=0x%08x name=%s\n", \
-                              notify.nttrans.out.num_changes, \
-                              notify.nttrans.out.changes[0].action, \
-                              notify.nttrans.in.completion_filter, \
-                              notify.nttrans.out.changes[0].name.s);   \
-                       ret = false; \
+               } else { \
+                       torture_assert_int_equal_goto(tctx, \
+                               notify.nttrans.out.num_changes,\
+                               nchanges, ret, done, \
+                               talloc_asprintf(tctx, \
+                                       "nchanges=%d expected=%d action=%d " \
+                                       "filter=0x%08x\n", \
+                                       notify.nttrans.out.num_changes, \
+                                       nchanges, \
+                                       notify.nttrans.out.changes[0].action, \
+                                       notify.nttrans.in.completion_filter)); \
+                       torture_assert_int_equal_goto(tctx, \
+                               notify.nttrans.out.changes[0].action, \
+                               Action, ret, done, \
+                               talloc_asprintf(tctx, \
+                                       "nchanges=%d action=%d " \
+                                       "expectedAction=%d filter=0x%08x\n", \
+                                       notify.nttrans.out.num_changes, \
+                                       notify.nttrans.out.changes[0].action, \
+                                       Action, \
+                                       notify.nttrans.in.completion_filter)); \
+                       torture_assert_str_equal_goto(tctx, \
+                               notify.nttrans.out.changes[0].name.s, \
+                               "tname1", ret, done, \
+                               talloc_asprintf(tctx, \
+                                       "nchanges=%d action=%d filter=0x%08x " \
+                                       "name=%s expected_name=tname1\n", \
+                                       notify.nttrans.out.num_changes, \
+                                       notify.nttrans.out.changes[0].action, \
+                                       notify.nttrans.in.completion_filter, \
+                                       notify.nttrans.out.changes[0].name.s));\
                } \
                mask |= (1<<i); \
        } \
        if ((expected) != mask) { \
-               if (((expected) & ~mask) != 0) { \
-                       printf("ERROR: trigger on too few bits. mask=0x%08x expected=0x%08x\n", \
-                              mask, expected); \
-                       ret = false; \
-               } else { \
-                       printf("WARNING: trigger on too many bits. mask=0x%08x expected=0x%08x\n", \
-                              mask, expected); \
-               } \
+               torture_assert_int_not_equal_goto(tctx, ((expected) & ~mask), \
+                               0, ret, done, "Too few bits"); \
+               printf("WARNING: trigger on too many bits. mask=0x%08x expected=0x%08x\n", \
+                      mask, expected); \
        } \
-       } while (0); \
        } while (0);
 
        printf("Testing mkdir\n");
@@ -1023,9 +1021,8 @@ static bool test_notify_tdis(struct torture_context *tctx,
        torture_assert(tctx, torture_setup_dir(cli1, BASEDIR),
                       "Failed to setup up test directory: " BASEDIR);
 
-       if (!torture_open_connection(&cli, tctx, 0)) {
-               return false;
-       }
+       torture_assert(tctx, torture_open_connection(&cli, tctx, 0),
+                      "Failed to open connection.");
 
        /*
          get a handle on the directory
@@ -1094,9 +1091,8 @@ static bool test_notify_exit(struct torture_context *tctx,
        torture_assert(tctx, torture_setup_dir(cli1, BASEDIR),
                       "Failed to setup up test directory: " BASEDIR);
 
-       if (!torture_open_connection(&cli, tctx, 0)) {
-               return false;
-       }
+       torture_assert(tctx, torture_open_connection(&cli, tctx, 0),
+                      "Failed to open connection.");
 
        /*
          get a handle on the directory
@@ -1164,9 +1160,8 @@ static bool test_notify_ulogoff(struct torture_context *tctx,
        torture_assert(tctx, torture_setup_dir(cli1, BASEDIR),
                       "Failed to setup up test directory: " BASEDIR);
 
-       if (!torture_open_connection(&cli, tctx, 0)) {
-               return false;
-       }
+       torture_assert(tctx, torture_open_connection(&cli, tctx, 0),
+                      "Failed to open connection.");
 
        /*
          get a handle on the directory
@@ -1241,9 +1236,8 @@ static bool test_notify_tcp_dis(struct torture_context *tctx,
        torture_assert(tctx, torture_setup_dir(cli1, BASEDIR),
                       "Failed to setup up test directory: " BASEDIR);
 
-       if (!torture_open_connection(&cli, tctx, 0)) {
-               return false;
-       }
+       torture_assert(tctx, torture_open_connection(&cli, tctx, 0),
+                      "Failed to open connection.");
 
        /*
          get a handle on the directory
@@ -1493,11 +1487,11 @@ static bool test_notify_tree(struct torture_context *mem_ctx,
        printf("took %.4f seconds to propogate all events\n", timeval_elapsed(&tv));
 
        for (i=0;i<ARRAY_SIZE(dirs);i++) {
-               if (dirs[i].counted != dirs[i].expected) {
-                       printf("ERROR: i=%d expected %d got %d for '%s'\n",
-                              i, dirs[i].expected, dirs[i].counted, dirs[i].path);
-                       ret = false;
-               }
+               torture_assert_int_equal_goto(mem_ctx,
+                       dirs[i].counted, dirs[i].expected, ret, done,
+                       talloc_asprintf(mem_ctx,
+                                       "unexpected number of events for '%s'",
+                                       dirs[i].path));
        }
 
        /*
@@ -1579,12 +1573,9 @@ static bool test_notify_overflow(struct torture_context *mem_ctx,
                char *fname = talloc_asprintf(cli, BASEDIR "\\test%d.txt", i);
                int fnum2 = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR,
                                        DENY_NONE);
-               if (fnum2 == -1) {
-                       printf("Failed to create %s - %s\n",
-                              fname, smbcli_errstr(cli->tree));
-                       ret = false;
-                       goto done;
-               }
+               torture_assert_int_not_equal_goto(mem_ctx, fnum2, -1, ret, done,
+                       talloc_asprintf(mem_ctx, "Failed to create %s - %s",
+                                       fname, smbcli_errstr(cli->tree)));
                talloc_free(fname);
                smbcli_close(cli->tree, fnum2);
        }