s4:torture:basic: use assert in the second loop in delayed_write_update1
[obnox/samba/samba-obnox.git] / source4 / torture / basic / delaywrite.c
index 0899e8fb425a297cc6b6025c0414682f00dd6a7c..edb3dc9a917b9aa5bf86058f290b5df033be0dc7 100644 (file)
@@ -53,52 +53,44 @@ static bool test_delayed_write_update(struct torture_context *tctx, struct smbcl
        torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
 
        fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
-       if (fnum1 == -1) {
-               torture_result(tctx, TORTURE_FAIL, "Failed to open %s", fname);
-               return false;
-       }
+       torture_assert_int_not_equal(tctx, fnum1, -1, talloc_asprintf(tctx,
+                                    "Failed to open %s", fname));
 
        finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
        finfo1.basic_info.in.file.fnum = fnum1;
        finfo2 = finfo1;
 
        status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
-
        torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
-       
-       torture_comment(tctx, "Initial write time %s\n", 
-              nt_time_string(tctx, finfo1.basic_info.out.write_time));
 
-       written =  smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
+       torture_comment(tctx, "Initial write time %s\n",
+                       nt_time_string(tctx, finfo1.basic_info.out.write_time));
 
-       if (written != 1) {
-               torture_result(tctx, TORTURE_FAIL, 
-                                          "write failed - wrote %d bytes (%s)\n", 
-                                          (int)written, __location__);
-               return false;
-       }
+       written =  smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
+       torture_assert_int_equal(tctx, written, 1,
+                                "unexpected number of bytes written");
 
        start = timeval_current();
-       end = timeval_add(&start, (120*sec), 0);
+       end = timeval_add(&start, (120 * sec), 0);
        while (!timeval_expired(&end)) {
                status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
 
-               if (!NT_STATUS_IS_OK(status)) {
-                       DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
-                       ret = false;
-                       break;
-               }
-               torture_comment(tctx, "write time %s\n", 
-                      nt_time_string(tctx, finfo2.basic_info.out.write_time));
-               if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
+               torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
+
+               torture_comment(tctx, "write time %s\n",
+                       nt_time_string(tctx, finfo2.basic_info.out.write_time));
+
+               if (finfo1.basic_info.out.write_time !=
+                   finfo2.basic_info.out.write_time)
+               {
                        double diff = timeval_elapsed(&start);
-                       if (diff < (used_delay / (double)1000000)) {
-                               torture_result(tctx, TORTURE_FAIL, "Server updated write_time after %.2f seconds"
-                                               "(expected > %.2f) (wrong!)\n",
-                                               diff, used_delay / (double)1000000);
-                               ret = false;
-                               break;
-                       }
+
+                       torture_assert(tctx,
+                                      diff >= (used_delay / (double)1000000),
+                                      talloc_asprintf(tctx,
+                                       "Server updated write_time after %.2f "
+                                       "seconds (expected >= %.2f)\n",
+                                       diff, used_delay/(double)1000000));
 
                        torture_comment(tctx, "Server updated write_time after %.2f seconds (correct)\n",
                                        diff);
@@ -107,13 +99,12 @@ static bool test_delayed_write_update(struct torture_context *tctx, struct smbcl
                fflush(stdout);
                smb_msleep(1 * msec);
        }
-       
-       if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) {
-               torture_result(tctx, TORTURE_FAIL, 
-                                          "Server did not update write time (wrong!)");
-               ret = false;
-       }
 
+       torture_assert_u64_not_equal(tctx,
+                                    finfo2.basic_info.out.write_time,
+                                    finfo1.basic_info.out.write_time,
+                                    "Server did not update write time within "
+                                    "120 seconds");
 
        if (fnum1 != -1)
                smbcli_close(cli->tree, fnum1);
@@ -144,10 +135,8 @@ static bool test_delayed_write_update1(struct torture_context *tctx, struct smbc
        torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
 
        fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
-       if (fnum1 == -1) {
-               torture_result(tctx, TORTURE_FAIL, "Failed to open %s", fname);
-               return false;
-       }
+       torture_assert_int_not_equal(tctx, fnum1, -1, talloc_asprintf(tctx,
+                                    "Failed to open %s", fname));
 
        memset(buf, 'x', 2048);
        written =  smbcli_write(cli->tree, fnum1, 0, buf, 0, 2048);
@@ -167,8 +156,11 @@ static bool test_delayed_write_update1(struct torture_context *tctx, struct smbc
 
        torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
 
-       torture_comment(tctx, "Initial write time %s\n", 
-              nt_time_string(tctx, finfo1.all_info.out.write_time));
+       torture_assert_u64_equal(tctx, finfo1.all_info.out.size, 2048,
+                                "file size not as expected after write(2048)");
+
+       torture_comment(tctx, "Initial write time %s\n",
+                       nt_time_string(tctx, finfo1.all_info.out.write_time));
 
        /* 3 second delay to ensure we get past any 2 second time
           granularity (older systems may have that) */
@@ -176,35 +168,22 @@ static bool test_delayed_write_update1(struct torture_context *tctx, struct smbc
 
        /* Do a zero length SMBwrite call to truncate. */
        written = smbcli_smbwrite(cli->tree, fnum1, "x", 1024, 0);
-
-       if (written != 0) {
-               torture_result(tctx, TORTURE_FAIL, 
-                                          "write failed - wrote %d bytes (%s)\n",
-                                          (int)written, __location__);
-               return false;
-       }
+       torture_assert_int_equal(tctx, written, 0,
+                                "unexpected number of bytes written");
 
        start = timeval_current();
-       end = timeval_add(&start, (120*sec), 0);
+       end = timeval_add(&start, (120 * sec), 0);
        while (!timeval_expired(&end)) {
                status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
 
-               if (!NT_STATUS_IS_OK(status)) {
-                       DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
-                       ret = false;
-                       break;
-               }
+               torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
 
-               if (finfo2.all_info.out.size != 1024) {
-                       torture_result(tctx, TORTURE_FAIL, 
-                                                  "file not truncated, size = %u (should be 1024)",
-                               (unsigned int)finfo2.all_info.out.size);
-                       ret = false;
-                       break;
-               }
+               torture_assert_u64_equal(tctx, finfo2.all_info.out.size, 1024,
+                                        "file not truncated to expected size "
+                                        "(1024)");
 
                torture_comment(tctx, "write time %s\n",
-                      nt_time_string(tctx, finfo2.all_info.out.write_time));
+                       nt_time_string(tctx, finfo2.all_info.out.write_time));
                if (finfo1.all_info.out.write_time != finfo2.all_info.out.write_time) {
                        double diff = timeval_elapsed(&start);
                        if (diff > (0.25 * (used_delay / (double)1000000))) {
@@ -226,62 +205,47 @@ static bool test_delayed_write_update1(struct torture_context *tctx, struct smbc
                smb_msleep(1 * msec);
        }
 
-       if (finfo1.all_info.out.write_time == finfo2.all_info.out.write_time) {
-               torture_result(tctx, TORTURE_FAIL, 
-                                          "Server did not update write time (wrong!)");
-               ret = false;
-       }
+       torture_assert_u64_not_equal(tctx,
+                                    finfo2.all_info.out.write_time,
+                                    finfo1.all_info.out.write_time,
+                                    "Server did not update write time");
 
        fflush(stdout);
        smb_msleep(2 * msec);
 
        /* Do a non-zero length SMBwrite and make sure it doesn't update the write time. */
        written = smbcli_smbwrite(cli->tree, fnum1, "x", 0, 1);
-
-       if (written != 1) {
-               torture_result(tctx, TORTURE_FAIL, 
-                                          "write failed - wrote %d bytes (%s)",
-                                          (int)written, __location__);
-               return false;
-       }
+       torture_assert_int_equal(tctx, written, 1,
+                                "unexpected number of bytes written");
 
        start = timeval_current();
        end = timeval_add(&start, (10*sec), 0);
        while (!timeval_expired(&end)) {
                status = smb_raw_fileinfo(cli->tree, tctx, &finfo3);
 
-               if (!NT_STATUS_IS_OK(status)) {
-                       DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
-                       ret = false;
-                       break;
-               }
+               torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
 
-               if (finfo3.all_info.out.size != 1024) {
-                       DEBUG(0, ("file not truncated, size = %u (should be 1024)\n",
-                               (unsigned int)finfo3.all_info.out.size));
-                       ret = false;
-                       break;
-               }
+               torture_assert_u64_equal(tctx, finfo3.all_info.out.size, 1024,
+                                        "file not truncated to expected size "
+                                        "(1024)");
 
                torture_comment(tctx, "write time %s\n",
-                      nt_time_string(tctx, finfo3.all_info.out.write_time));
-               if (finfo2.all_info.out.write_time != finfo3.all_info.out.write_time) {
-                       double diff = timeval_elapsed(&start);
+                       nt_time_string(tctx, finfo3.all_info.out.write_time));
+
+               torture_assert_u64_equal(tctx,
+                                        finfo3.all_info.out.write_time,
+                                        finfo2.all_info.out.write_time,
+                                        talloc_asprintf(tctx,
+                                               "Server updated write time "
+                                               "after %.2f seconds (wrong!)",
+                                               timeval_elapsed(&start)));
 
-                       torture_comment(tctx, "server updated write_time after %.2f seconds"
-                                       "(1 sec == %.2f)(wrong)\n",
-                                       diff, sec);
-                       break;
-               }
                fflush(stdout);
                smb_msleep(1 * msec);
        }
 
-       if (finfo2.all_info.out.write_time != finfo3.all_info.out.write_time) {
-               torture_result(tctx, TORTURE_FAIL, 
-                                          "Server updated write time (wrong!)");
-               ret = false;
-       }
+       torture_comment(tctx, "Server did not update write time within 10 "
+                       "seconds. Good!\n");
 
        fflush(stdout);
        smb_msleep(2 * msec);
@@ -293,13 +257,17 @@ static bool test_delayed_write_update1(struct torture_context *tctx, struct smbc
        status = smb_raw_pathinfo(cli->tree, tctx, &pinfo4);
        torture_assert_ntstatus_ok(tctx, status, "pathinfo failed");
 
-       if (finfo3.all_info.out.write_time == pinfo4.all_info.out.write_time) {
-               torture_result(tctx, TORTURE_FAIL,
-                                          "Server did not update write time on close (wrong!)");
-               ret = false;
-       } else if (finfo3.all_info.out.write_time < pinfo4.all_info.out.write_time) {
-               torture_comment(tctx, "Server updated write time on close (correct)\n");
-       }
+       torture_assert_u64_not_equal(tctx,
+                                    pinfo4.all_info.out.write_time,
+                                    finfo3.all_info.out.write_time,
+                                    "Server did not update write time on "
+                                    "close (wrong!)");
+       torture_assert(tctx,
+               pinfo4.all_info.out.write_time > finfo3.all_info.out.write_time,
+               "Server updated write time on close, but to an earlier point "
+               "in time");
+
+       torture_comment(tctx, "Server updated write time on close (correct)\n");
 
        if (fnum1 != -1)
                smbcli_close(cli->tree, fnum1);
@@ -452,8 +420,8 @@ static bool test_delayed_write_update1a(struct torture_context *tctx, struct smb
                        double diff = timeval_elapsed(&start);
 
                        torture_result(tctx, TORTURE_FAIL, "server updated write_time after %.2f seconds"
-                                       "(1 sec == %.2f)(correct)\n",
-                                       diff, sec);
+                                       "(write time update delay == %.2f)(correct)\n",
+                                       diff, used_delay / (double)1000000);
                        break;
                }
                fflush(stdout);
@@ -627,8 +595,8 @@ static bool test_delayed_write_update1b(struct torture_context *tctx, struct smb
                        double diff = timeval_elapsed(&start);
 
                        torture_comment(tctx, "server updated write_time after %.2f seconds"
-                                       "(1 sec == %.2f)(correct)\n",
-                                       diff, sec);
+                                       "(write time update delay == %.2f)(correct)\n",
+                                       diff, used_delay / (double)1000000);
                        break;
                }
                fflush(stdout);
@@ -803,8 +771,8 @@ static bool test_delayed_write_update1c(struct torture_context *tctx, struct smb
                        double diff = timeval_elapsed(&start);
 
                        torture_comment(tctx, "server updated write_time after %.2f seconds"
-                                       "(1 sec == %.2f)(correct)\n",
-                                       diff, sec);
+                                       "(write time update delay == %.2f)(wrong)\n",
+                                       diff, used_delay / (double)1000000);
                        break;
                }
                fflush(stdout);
@@ -985,8 +953,8 @@ static bool test_delayed_write_update2(struct torture_context *tctx, struct smbc
                if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
                        double diff = timeval_elapsed(&start);
                        torture_result(tctx, TORTURE_FAIL, "Server updated write_time after %.2f seconds"
-                                       "(1sec == %.2f) (wrong!)\n",
-                                       diff, sec);
+                                       "(wrong!)\n",
+                                       diff);
                        ret = false;
                        break;
                }
@@ -1077,8 +1045,8 @@ static bool test_delayed_write_update2(struct torture_context *tctx, struct smbc
                if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
                        double diff = timeval_elapsed(&start);
                        torture_result(tctx, TORTURE_FAIL, "Server updated write_time after %.2f seconds "
-                                       "(1sec == %.2f) (wrong!)\n",
-                                       diff, sec);
+                                       "(wrong!)\n",
+                                       diff);
                        ret = false;
                        break;
                }
@@ -1166,8 +1134,8 @@ static bool test_delayed_write_update2(struct torture_context *tctx, struct smbc
                        }
 
                        torture_comment(tctx, "Server updated write_time after %.2f seconds"
-                                       "(1sec == %.2f) (correct)\n",
-                                       diff, sec);
+                                       "(correct)\n",
+                                       diff);
                        break;
                }
                fflush(stdout);
@@ -1547,8 +1515,8 @@ static bool test_delayed_write_update3(struct torture_context *tctx,
                        }
 
                        torture_comment(tctx, "Server updated write_time after %.2f seconds "
-                                       "(1sec == %.2f) (correct)\n",
-                                       diff, sec);
+                                       "(correct)\n",
+                                       diff);
                        break;
                }
                smb_msleep(0.5 * msec);
@@ -1575,8 +1543,8 @@ static bool test_delayed_write_update3(struct torture_context *tctx,
                if (finfo2.basic_info.out.write_time > finfo1.basic_info.out.write_time) {
                        double diff = timeval_elapsed(&start);
                        torture_result(tctx, TORTURE_FAIL, "Server updated write_time after %.2f seconds "
-                                       "(1sec == %.2f) (wrong!)\n",
-                                       diff, sec);
+                                       "(wrong!)\n",
+                                       diff);
                        ret = false;
                        break;
                }
@@ -1709,8 +1677,8 @@ static bool test_delayed_write_update3a(struct torture_context *tctx,
                        }
 
                        torture_comment(tctx, "Server updated write_time after %.2f seconds "
-                                       "(1sec == %.2f) (correct)\n",
-                                       diff, sec);
+                                       "(correct)\n",
+                                       diff);
                        break;
                }
                smb_msleep(0.5 * msec);
@@ -1761,8 +1729,8 @@ static bool test_delayed_write_update3a(struct torture_context *tctx,
                if (finfo2.basic_info.out.write_time > finfo1.basic_info.out.write_time) {
                        double diff = timeval_elapsed(&start);
                        torture_result(tctx, TORTURE_FAIL, "Server updated write_time after %.2f seconds "
-                                       "(1sec == %.2f) (wrong!)\n",
-                                       diff, sec);
+                                       "(wrong!)\n",
+                                       diff);
                        ret = false;
                        break;
                }
@@ -1948,8 +1916,8 @@ static bool test_delayed_write_update3b(struct torture_context *tctx,
                if (finfo2.basic_info.out.write_time > finfo1.basic_info.out.write_time) {
                        double diff = timeval_elapsed(&start);
                        torture_result(tctx, TORTURE_FAIL, "Server updated write_time after %.2f seconds "
-                                       "(1sec == %.2f) (wrong!)\n",
-                                       diff, sec);
+                                       "(wrong!)\n",
+                                       diff);
                        ret = false;
                        break;
                }
@@ -2003,8 +1971,8 @@ static bool test_delayed_write_update3c(struct torture_context *tctx,
                                        struct smbcli_state *cli,
                                        struct smbcli_state *cli2)
 {
-       union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4;
-       union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5;
+       union smb_fileinfo finfo0, finfo1, finfo2, finfo3;
+       union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4;
        const char *fname = BASEDIR "\\torture_file3c.txt";
        int fnum1 = -1;
        bool ret = true;
@@ -2034,14 +2002,12 @@ static bool test_delayed_write_update3c(struct torture_context *tctx,
        finfo1 = finfo0;
        finfo2 = finfo0;
        finfo3 = finfo0;
-       finfo4 = finfo0;
        pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
        pinfo0.basic_info.in.file.path = fname;
        pinfo1 = pinfo0;
        pinfo2 = pinfo0;
        pinfo3 = pinfo0;
        pinfo4 = pinfo0;
-       pinfo5 = pinfo0;
 
        /* get the initial times */
        GET_INFO_BOTH(finfo0,pinfo0);
@@ -2093,8 +2059,8 @@ static bool test_delayed_write_update3c(struct torture_context *tctx,
                if (finfo2.basic_info.out.write_time > finfo1.basic_info.out.write_time) {
                        double diff = timeval_elapsed(&start);
                        torture_result(tctx, TORTURE_FAIL, "Server updated write_time after %.2f seconds "
-                                       "(1sec == %.2f) (wrong!)\n",
-                                       diff, sec);
+                                       "(wrong!)\n",
+                                       diff);
                        ret = false;
                        break;
                }
@@ -2158,8 +2124,8 @@ static bool test_delayed_write_update3c(struct torture_context *tctx,
                if (finfo2.basic_info.out.write_time > finfo1.basic_info.out.write_time) {
                        double diff = timeval_elapsed(&start);
                        torture_result(tctx, TORTURE_FAIL, "Server updated write_time after %.2f seconds "
-                                       "(1sec == %.2f) (wrong!)\n",
-                                       diff, sec);
+                                       "(wrong!)\n",
+                                       diff);
                        ret = false;
                        break;
                }
@@ -2317,8 +2283,8 @@ static bool test_delayed_write_update4(struct torture_context *tctx,
                if (finfo2.basic_info.out.write_time > finfo1.basic_info.out.write_time) {
                        double diff = timeval_elapsed(&start);
                        torture_result(tctx, TORTURE_FAIL, "Server updated write_time after %.2f seconds "
-                                       "(1sec == %.2f) (wrong!)\n",
-                                       diff, sec);
+                                       "(wrong!)\n",
+                                       diff);
                        ret = false;
                        break;
                }
@@ -2446,8 +2412,8 @@ static bool test_delayed_write_update5(struct torture_context *tctx,
                if (finfo3.basic_info.out.write_time > finfo2.basic_info.out.write_time) {
                        double diff = timeval_elapsed(&start);
                        torture_result(tctx, TORTURE_FAIL, "Server updated write_time after %.2f seconds "
-                                       "(1sec == %.2f) (wrong!)\n",
-                                       diff, sec);
+                                       "(wrong!)\n",
+                                       diff);
                        ret = false;
                        break;
                }
@@ -2478,8 +2444,8 @@ static bool test_delayed_write_update5(struct torture_context *tctx,
                if (finfo4.basic_info.out.write_time > finfo3.basic_info.out.write_time) {
                        double diff = timeval_elapsed(&start);
                        torture_result(tctx, TORTURE_FAIL, "Server updated write_time after %.2f seconds "
-                                       "(1sec == %.2f) (wrong!)\n",
-                                       diff, sec);
+                                       "(wrong!)\n",
+                                       diff);
                        ret = false;
                        break;
                }
@@ -2606,8 +2572,8 @@ static bool test_delayed_write_update5b(struct torture_context *tctx,
                if (finfo3.basic_info.out.write_time > finfo2.basic_info.out.write_time) {
                        double diff = timeval_elapsed(&start);
                        torture_result(tctx, TORTURE_FAIL, "Server updated write_time after %.2f seconds "
-                                       "(1sec == %.2f) (wrong!)\n",
-                                       diff, sec);
+                                       "(wrong!)\n",
+                                       diff);
                        ret = false;
                        break;
                }
@@ -2638,8 +2604,8 @@ static bool test_delayed_write_update5b(struct torture_context *tctx,
                if (finfo4.basic_info.out.write_time > finfo3.basic_info.out.write_time) {
                        double diff = timeval_elapsed(&start);
                        torture_result(tctx, TORTURE_FAIL, "Server updated write_time after %.2f seconds "
-                                       "(1sec == %.2f) (wrong!)\n",
-                                       diff, sec);
+                                       "(wrong!)\n",
+                                       diff);
                        ret = false;
                        break;
                }
@@ -2783,8 +2749,8 @@ again:
                if (finfo3.basic_info.out.write_time > finfo2.basic_info.out.write_time) {
                        double diff = timeval_elapsed(&start);
                        torture_result(tctx, TORTURE_FAIL, "Server updated write_time after %.2f seconds "
-                                       "(1sec == %.2f) (wrong!)\n",
-                                       diff, sec);
+                                       "(wrong!)\n",
+                                       diff);
                        ret = false;
                        break;
                }
@@ -2815,8 +2781,8 @@ again:
                if (finfo4.basic_info.out.write_time > finfo3.basic_info.out.write_time) {
                        double diff = timeval_elapsed(&start);
                        torture_result(tctx, TORTURE_FAIL, "Server updated write_time after %.2f seconds "
-                                       "(1sec == %.2f) (wrong!)\n",
-                                       diff, sec);
+                                       "(wrong!)\n",
+                                       diff);
                        ret = false;
                        break;
                }
@@ -2878,8 +2844,8 @@ again:
                if (finfo5.basic_info.out.write_time > pinfo6.basic_info.out.write_time) {
                        double diff = timeval_elapsed(&start);
                        torture_result(tctx, TORTURE_FAIL, "Server updated write_time after %.2f seconds "
-                                       "(1sec == %.2f) (wrong!)\n",
-                                       diff, sec);
+                                       "(wrong!)\n",
+                                       diff);
                        ret = false;
                        break;
                }
@@ -2905,8 +2871,8 @@ again:
                if (finfo5.basic_info.out.write_time > pinfo6.basic_info.out.write_time) {
                        double diff = timeval_elapsed(&start);
                        torture_result(tctx, TORTURE_FAIL, "Server updated write_time after %.2f seconds "
-                                       "(1sec == %.2f) (wrong!)\n",
-                                       diff, sec);
+                                       "(wrong!)\n",
+                                       diff);
                        ret = false;
                        break;
                }