HACK source4/torture/basic/delaywrite.c
[metze/samba/wip.git] / source4 / torture / basic / delaywrite.c
index 63bfa829ca1284260a11b53da805e40bfe16dc2d..dd261d86d09630200148b55b240cd8176c785ffa 100644 (file)
@@ -30,6 +30,7 @@
 #include "libcli/libcli.h"
 #include "torture/util.h"
 #include "torture/basic/proto.h"
+#include "lib/util/time_basic.h"
 
 #define BASEDIR "\\delaywrite"
 
@@ -616,6 +617,8 @@ static bool test_delayed_write_update1c(struct torture_context *tctx, struct smb
        double sec = ((double)used_delay) / ((double)normal_delay);
        int msec = 1000 * sec;
        char buf[2048];
+       bool first;
+       bool updated;
 
        torture_comment(tctx, "\nRunning test_delayed_write_update1c\n");
 
@@ -643,6 +646,9 @@ static bool test_delayed_write_update1c(struct torture_context *tctx, struct smb
 
        torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
 
+       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));
 
@@ -658,6 +664,8 @@ static bool test_delayed_write_update1c(struct torture_context *tctx, struct smb
 
        start = timeval_current();
        end = timeval_add(&start, (120*sec), 0);
+       first = true;
+       updated = false;
        while (!timeval_expired(&end)) {
                status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
 
@@ -669,31 +677,27 @@ static bool test_delayed_write_update1c(struct torture_context *tctx, struct smb
 
                torture_comment(tctx, "write time %s\n",
                        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))) {
-                               torture_result(tctx, TORTURE_FAIL, "After SET_ALLOCATION_INFO truncate "
-                                       "server updated write_time after %.2f seconds"
-                                       "(write time update delay == %.2f)(wrong!)\n",
-                                       diff, used_delay / (double)1000000);
-                               ret = false;
-                               break;
-                       }
 
-                       torture_comment(tctx, "After SET_ALLOCATION_INFO truncate "
-                                       "server updated write_time after %.2f seconds"
-                                       "(write time update delay == %.2f)(correct)\n",
-                                       diff, used_delay / (double)1000000);
+               if (finfo1.all_info.out.write_time !=
+                   finfo2.all_info.out.write_time)
+               {
+                       updated = true;
                        break;
                }
+
                fflush(stdout);
                smb_msleep(1 * msec);
+               first = 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");
+       torture_assert(tctx, updated,
+                      "Server did not update write time within 120 seconds");
+
+       torture_assert(tctx, first, talloc_asprintf(tctx,
+                      "Server did not update write time immediately but only "
+                      "after %.2f seconds!", timeval_elapsed(&start)));
+
+       torture_comment(tctx, "Server updated write time immediately. Good!\n");
 
        fflush(stdout);
        smb_msleep(2 * msec);
@@ -715,22 +719,21 @@ static bool test_delayed_write_update1c(struct torture_context *tctx, struct smb
 
                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);
 
-                       torture_comment(tctx, "server updated write_time after %.2f seconds"
-                                       "(write time update delay == %.2f)(wrong)\n",
-                                       diff, used_delay / (double)1000000);
-                       break;
-               }
+               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)));
+
                fflush(stdout);
                smb_msleep(1 * msec);
        }
 
-       torture_assert_u64_equal(tctx,
-                                finfo3.all_info.out.write_time,
-                                finfo2.all_info.out.write_time,
-                                "Server updated write time (wrong!)");
+       torture_comment(tctx, "Server did not update write time within 10 "
+                       "seconds. Good!\n");
 
        /* the close should trigger an write time update */
        smbcli_close(cli->tree, fnum1);
@@ -1306,6 +1309,10 @@ static bool test_finfo_after_write(struct torture_context *tctx, struct smbcli_s
 } while (0)
 
 #define GET_INFO_FILE(finfo) do { \
+       struct timeval atv; \
+       struct timeval wtv; \
+       struct timeval_buf atvb; \
+       struct timeval_buf wtvb; \
        NTSTATUS _status; \
        _status = smb_raw_fileinfo(cli->tree, tctx, &finfo); \
        if (!NT_STATUS_IS_OK(_status)) { \
@@ -1314,9 +1321,11 @@ static bool test_finfo_after_write(struct torture_context *tctx, struct smbcli_s
                               nt_errstr(_status)); \
                goto done; \
        } \
+       nttime_to_timeval(&atv, finfo.basic_info.out.access_time); \
+       nttime_to_timeval(&wtv, finfo.basic_info.out.write_time); \
        torture_comment(tctx, "fileinfo: Access(%s) Write(%s)\n", \
-                       nt_time_string(tctx, finfo.basic_info.out.access_time), \
-                       nt_time_string(tctx, finfo.basic_info.out.write_time)); \
+                       timeval_str_buf(&atv, false, true, &atvb), \
+                       timeval_str_buf(&wtv, false, true, &wtvb)); \
 } while (0)
 #define GET_INFO_FILE2(finfo) do { \
        NTSTATUS _status; \
@@ -1404,6 +1413,8 @@ static bool test_delayed_write_update3(struct torture_context *tctx,
        struct timeval start;
        struct timeval end;
        double used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000);
+       //double used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 1000000);
+       //int normal_delay = 1000000;
        int normal_delay = 2000000;
        double sec = ((double)used_delay) / ((double)normal_delay);
        int msec = 1000 * sec;
@@ -1457,7 +1468,7 @@ static bool test_delayed_write_update3(struct torture_context *tctx,
                if (finfo1.basic_info.out.write_time > finfo0.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 "
+                               torture_result(tctx, TORTURE_FAIL, "111Server updated write_time after %.2f seconds "
                                                "(write time update delay == %.2f) (wrong!)\n",
                                                diff, used_delay / (double)1000000);
                                ret = false;
@@ -2922,7 +2933,7 @@ static bool test_delayed_write_update7(struct torture_context *tctx, struct smbc
 
        if (finfo2.basic_info.out.write_time != finfo3.basic_info.out.write_time) {
                torture_result(tctx, TORTURE_FAIL, 
-                       "qpathinfo time doens't match fileinfo time");
+                       "qpathinfo time doesn't match fileinfo time");
                ret = false;
        }
 
@@ -3066,9 +3077,9 @@ static bool test_directory_update8(struct torture_context *tctx, struct smbcli_s
 /*
    testing of delayed update of write_time
 */
-struct torture_suite *torture_delay_write(void)
+struct torture_suite *torture_delay_write(TALLOC_CTX *ctx)
 {
-       struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "delaywrite");
+       struct torture_suite *suite = torture_suite_create(ctx, "delaywrite");
 
        torture_suite_add_2smb_test(suite, "finfo update on close", test_finfo_after_write);
        torture_suite_add_1smb_test(suite, "delayed update of write time", test_delayed_write_update);
@@ -3086,7 +3097,6 @@ struct torture_suite *torture_delay_write(void)
        torture_suite_add_2smb_test(suite, "delayed update of write time 5b", test_delayed_write_update5b);
        torture_suite_add_2smb_test(suite, "delayed update of write time 6", test_delayed_write_update6);
        torture_suite_add_1smb_test(suite, "timestamp resolution test", test_delayed_write_update7);
-       torture_suite_add_1smb_test(suite, "timestamp resolution test", test_delayed_write_update7);
        torture_suite_add_1smb_test(suite, "directory timestamp update test", test_directory_update8);
 
        return suite;