[SCM] Samba Shared Repository - branch master updated

Andreas Schneider asn at samba.org
Tue May 11 07:04:01 UTC 2021


The branch, master has been updated
       via  556b114f11c audit logging tests: Fix flapping test
      from  21934c09bdc s3:smbd - support streams larger than 64 KiB

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 556b114f11c9fbe806d960417e2777560a163793
Author: Joseph Sutton <josephsutton at catalyst.net.nz>
Date:   Tue May 11 10:03:34 2021 +1200

    audit logging tests: Fix flapping test
    
    On Linux, gettimeofday() uses the clock's microsecond field to adjust
    the returned time in seconds, while time() only takes the seconds field
    into account. As a result, time() would occasionally return a smaller
    value than gettimeofday(), despite being called later.
    
    Changing the time() calls to gettimeofday() as used in audit_logging.c
    makes the time values consistent.
    
    https://stackoverflow.com/questions/22917318/time-and-gettimeofday-return-different-seconds
    
    Signed-off-by: Joseph Sutton <josephsutton at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Gary Lockyer <gary at catalyst.net.nz>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    
    Autobuild-User(master): Andreas Schneider <asn at cryptomilk.org>
    Autobuild-Date(master): Tue May 11 07:03:35 UTC 2021 on sn-devel-184

-----------------------------------------------------------------------

Summary of changes:
 lib/audit_logging/tests/audit_logging_test.c | 30 +++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/audit_logging/tests/audit_logging_test.c b/lib/audit_logging/tests/audit_logging_test.c
index 8c949e5f8fc..1f871c2e5f4 100644
--- a/lib/audit_logging/tests/audit_logging_test.c
+++ b/lib/audit_logging/tests/audit_logging_test.c
@@ -283,14 +283,21 @@ static void test_json_add_timestamp(_UNUSED_ void **state)
 	time_t before;
 	time_t after;
 	time_t actual;
-	const int adjustment = 1;
-
+	struct timeval tv;
+	int ret;
 
 	object = json_new_object();
-	before = time(NULL);
+
+	ret = gettimeofday(&tv, NULL);
+	assert_int_equal(0, ret);
+	before = tv.tv_sec;
+
 	rc = json_add_timestamp(&object);
 	assert_int_equal(0, rc);
-	after = time(NULL);
+
+	ret = gettimeofday(&tv, NULL);
+	assert_int_equal(0, ret);
+	after = tv.tv_sec;
 
 	ts = json_object_get(object.root, "timestamp");
 	assert_true(json_is_string(ts));
@@ -321,10 +328,7 @@ static void test_json_add_timestamp(_UNUSED_ void **state)
 
 	/*
 	 * The timestamp should be before <= actual <= after
-	 * but we adjust the times to cater for any precision issues.
 	 */
-	before -= adjustment;
-	after += adjustment;
 	assert_true(difftime(actual, before) >= 0);
 	assert_true(difftime(after, actual) >= 0);
 
@@ -796,6 +800,8 @@ static void test_audit_get_timestamp(_UNUSED_ void **state)
 	time_t before;
 	time_t after;
 	time_t actual;
+	struct timeval tv;
+	int ret;
 	char *env_tz = NULL;
 	char *orig_tz = NULL;
 
@@ -810,9 +816,15 @@ static void test_audit_get_timestamp(_UNUSED_ void **state)
 	}
 	setenv("TZ", "UTC", 1);
 
-	before = time(NULL);
+	ret = gettimeofday(&tv, NULL);
+	assert_int_equal(0, ret);
+	before = tv.tv_sec;
+
 	t = audit_get_timestamp(ctx);
-	after = time(NULL);
+
+	ret = gettimeofday(&tv, NULL);
+	assert_int_equal(0, ret);
+	after = tv.tv_sec;
 
 	c = strptime(t, "%a, %d %b %Y %H:%M:%S", &tm);
 


-- 
Samba Shared Repository



More information about the samba-cvs mailing list