diff mbox series

[v2,2/2] syscalls/utime03: Fix timestamp checks

Message ID 20210923134413.25174-2-mdoucha@suse.cz
State Accepted
Headers show
Series [v2,1/2] Rename get_ipc_timestamp() and move to main LTP library | expand

Commit Message

Martin Doucha Sept. 23, 2021, 1:44 p.m. UTC
The timestamps set by utime(path, NULL) may slightly lag behind time() return
values. Use tst_get_fs_timestamp() to get the correct expected time range.

Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
 testcases/kernel/syscalls/utime/utime03.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Jan Stancek July 21, 2022, 7:28 a.m. UTC | #1
On Thu, Sep 23, 2021 at 3:44 PM Martin Doucha <mdoucha@suse.cz> wrote:
>
> The timestamps set by utime(path, NULL) may slightly lag behind time() return
> values. Use tst_get_fs_timestamp() to get the correct expected time range.

I'm now seeing the opposite, coarse time is sporadically behind:

    46 utime03.c:76: TPASS: utime(TEMP_FILE, NULL) passed
    47 utime03.c:82: TFAIL: utime() did not set expected atime,
mintime: 1658240287, maxtime: 1658240287, st_atime: 1658240288
    48 utime03.c:87: TFAIL: utime() did not set expected mtime,
mintime: 1658240287, maxtime: 1658240287, st_mtime: 1658240288

Perhaps we should allow for some epsilon, what do you think?

>
> Signed-off-by: Martin Doucha <mdoucha@suse.cz>
> ---
>  testcases/kernel/syscalls/utime/utime03.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/utime/utime03.c b/testcases/kernel/syscalls/utime/utime03.c
> index f581273f7..48cc3bae7 100644
> --- a/testcases/kernel/syscalls/utime/utime03.c
> +++ b/testcases/kernel/syscalls/utime/utime03.c
> @@ -26,6 +26,7 @@
>
>  #include "tst_test.h"
>  #include "tst_uid.h"
> +#include "tst_clocks.h"
>
>  #define MNTPOINT       "mntpoint"
>  #define TEMP_FILE      MNTPOINT"/tmp_file"
> @@ -71,9 +72,9 @@ static void run(void)
>         }
>
>         SAFE_SETEUID(user_uid);
> -       mintime = time(0);
> +       mintime = tst_get_fs_timestamp();
>         TST_EXP_PASS(utime(TEMP_FILE, NULL));
> -       maxtime = time(0);
> +       maxtime = tst_get_fs_timestamp();
>         SAFE_SETEUID(root_uid);
>         SAFE_STAT(TEMP_FILE, &statbuf);
>
> --
> 2.33.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/utime/utime03.c b/testcases/kernel/syscalls/utime/utime03.c
index f581273f7..48cc3bae7 100644
--- a/testcases/kernel/syscalls/utime/utime03.c
+++ b/testcases/kernel/syscalls/utime/utime03.c
@@ -26,6 +26,7 @@ 
 
 #include "tst_test.h"
 #include "tst_uid.h"
+#include "tst_clocks.h"
 
 #define MNTPOINT	"mntpoint"
 #define TEMP_FILE	MNTPOINT"/tmp_file"
@@ -71,9 +72,9 @@  static void run(void)
 	}
 
 	SAFE_SETEUID(user_uid);
-	mintime = time(0);
+	mintime = tst_get_fs_timestamp();
 	TST_EXP_PASS(utime(TEMP_FILE, NULL));
-	maxtime = time(0);
+	maxtime = tst_get_fs_timestamp();
 	SAFE_SETEUID(root_uid);
 	SAFE_STAT(TEMP_FILE, &statbuf);