Rename get_ipc_timestamp() and move to main LTP library
PATCH v2 1/2 Rename get_ipc_timestamp() and move to main LTP library
The get_ipc_timestamp() helper functions is also needed for generic FS tests. Rename it to tst_get_fs_timestamp() and move it to tst_clocks.h.
---
I forgot to add the tst_ prefix to the renamed function. Sorry about resubmitting so quickly.
include/libnewipc.h | 2 -- include/tst_clocks.h | 6 ++++++ lib/tst_clocks.c | 13 +++++++++++++ libs/libltpnewipc/libnewipc.c | 13 ------------- testcases/kernel/syscalls/ipc/msgrcv/msgrcv01.c | 5 +++-- testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c | 5 +++-- testcases/kernel/syscalls/ipc/shmctl/shmctl01.c | 5 +++-- 7 files changed, 28 insertions(+), 21 deletions(-)
include/libnewipc.h +0 -2
@@ -59,6 +59,4 @@ void *probe_free_addr(const char *file, const int lineno);#define PROBE_FREE_ADDR () \ probe_free_addr(__FILE__, __LINE__) -time_t get_ipc_timestamp (void ); -#endif /* newlibipc.h */
include/tst_clocks.h +6 -0
@@ -20,4 +20,10 @@ int tst_clock_settime(clockid_t clk_id, struct timespec *ts);*/ const char *tst_clock_name (clockid_t clk_id); +/* +* Returns current system time for file/IPC operations, which may slightly lag +* behind time() return values. +*/ +time_t tst_get_fs_timestamp (void ); +#endif /* TST_CLOCKS__ */
lib/tst_clocks.c +13 -0
@@ -142,3 +142,16 @@ const char *tst_clock_name(clockid_t clk_id)return "INVALID/UNKNOWN CLOCK" ; } } + +time_t tst_get_fs_timestamp (void ) +{ +struct timespec ts; +int ret; + + ret =tst_clock_gettime (CLOCK_REALTIME_COARSE , &ts); + +if (ret <0 ) +tst_brk (TBROK |TERRNO ,"clock_gettime(CLOCK_REALTIME_COARSE)" ); + +return ts.tv_sec; +}
libs/libltpnewipc/libnewipc.c +0 -13
@@ -23,7 +23,6 @@#include "libnewipc.h" #include "tst_safe_stdio.h" #include "tst_safe_sysv_ipc.h" -#include "tst_clocks.h" #define BUFSIZE 1024
@@ -87,15 +86,3 @@ void *probe_free_addr(const char *file, const int lineno)return addr; } - -time_t get_ipc_timestamp (void ) -{ -struct timespec ts; -int ret; - - ret =tst_clock_gettime (CLOCK_REALTIME_COARSE , &ts); -if (ret <0 ) -tst_brk (TBROK |TERRNO ,"clock_gettime(CLOCK_REALTIME_COARSE)" ); - -return ts.tv_sec; -}
testcases/kernel/syscalls/ipc/msgrcv/msgrcv01.c +3 -2
@@ -9,6 +9,7 @@#include <sys/wait.h> #include "tst_test.h" #include "tst_safe_sysv_ipc.h" +#include "tst_clocks.h" #include "libnewipc.h" static key_t msgkey;
@@ -25,13 +26,13 @@ static void verify_msgrcv(void)SAFE_MSGSND (queue_id, &snd_buf,MSGSIZE ,0 ); - before_rcv =get_ipc_timestamp (); + before_rcv =tst_get_fs_timestamp ();TEST (msgrcv (queue_id, &rcv_buf,MSGSIZE ,1 ,0 ));if (TST_RET ==-1 ) {tst_res (TFAIL |TTERRNO ,"msgrcv failed" );return ; } - after_rcv =get_ipc_timestamp (); + after_rcv =tst_get_fs_timestamp ();if (strcmp (rcv_buf.mtext, snd_buf.mtext) ==0 ) tst_res(TPASS, "message received(%s) = message sent(%s)",
testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c +3 -2
@@ -15,6 +15,7 @@#include "tst_test.h" #include "tst_safe_sysv_ipc.h" +#include "tst_clocks.h" #include "libnewipc.h" static key_t msgkey;
@@ -29,13 +30,13 @@ static void verify_msgsnd(void)struct msqid_ds qs_buf;time_t before_snd, after_snd; - before_snd =get_ipc_timestamp (); + before_snd =tst_get_fs_timestamp ();TEST (msgsnd (queue_id, &snd_buf,MSGSIZE ,0 ));if (TST_RET ==-1 ) {tst_res (TFAIL |TTERRNO ,"msgsnd() failed" );return ; } - after_snd =get_ipc_timestamp (); + after_snd =tst_get_fs_timestamp ();SAFE_MSGCTL (queue_id,IPC_STAT , &qs_buf);
testcases/kernel/syscalls/ipc/shmctl/shmctl01.c +3 -2
@@ -21,6 +21,7 @@#include <stdlib.h> #include "tst_test.h" #include "tst_safe_sysv_ipc.h" +#include "tst_clocks.h" #include "libnewipc.h" #define NCHILD 20
@@ -243,9 +244,9 @@ static int get_shm_idx_from_id(int shm_id)static void setup (void ) { - ctime_min =get_ipc_timestamp (); + ctime_min =tst_get_fs_timestamp (); shm_id =SAFE_SHMGET (IPC_PRIVATE ,SHM_SIZE ,IPC_CREAT |SHM_RW ); - ctime_max =get_ipc_timestamp (); + ctime_max =tst_get_fs_timestamp (); shm_idx =get_shm_idx_from_id (shm_id);
Signature · 5 lines
2.33.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/2 syscalls/utime03: Fix timestamp checks
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.
--- testcases/kernel/syscalls/utime/utime03.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/utime/utime03.c +3 -2
@@ -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);
Signature · 5 lines
2.33.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/2] syscalls/utime03: Fix timestamp checks
Quoted 3 lines · Martin Doucha
The timestamps set by
utime(path, NULL)may slightly lag behindtime()return values. Usetst_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?
Quoted 37 lines
Signed-off-by Martin Doucha <[email protected]>--- testcases/kernel/syscalls/utime/utime03.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)testcases/kernel/syscalls/utime/utime03.c +3
-3@@ -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
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 4 lines
+/*
+ * Returns current system time for file/IPC operations, which may slightly lag
+ * behindtime()return values.
+ */
I've added slightly longer (and hopefuly better) explanation why this happends here and pushed the patches, thanks.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp