[LTP] [PATCH 1/2] Rename get_ipc_timestamp() and move to main LTP library

Martin Doucha mdoucha@suse.cz
Thu Sep 23 15:27:48 CEST 2021


The get_ipc_timestamp() helper functions is also needed for generic FS tests.
Rename it to get_fs_timestamp() and move it to tst_clocks.h.

Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
 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(-)

diff --git a/include/libnewipc.h b/include/libnewipc.h
index 52e054c51..9eec31763 100644
--- a/include/libnewipc.h
+++ b/include/libnewipc.h
@@ -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 */
diff --git a/include/tst_clocks.h b/include/tst_clocks.h
index 80030c6b0..b6c8c9d53 100644
--- a/include/tst_clocks.h
+++ b/include/tst_clocks.h
@@ -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 get_fs_timestamp(void);
+
 #endif /* TST_CLOCKS__ */
diff --git a/lib/tst_clocks.c b/lib/tst_clocks.c
index cdcb9fc4f..ce8eef55b 100644
--- a/lib/tst_clocks.c
+++ b/lib/tst_clocks.c
@@ -142,3 +142,16 @@ const char *tst_clock_name(clockid_t clk_id)
 		return "INVALID/UNKNOWN CLOCK";
 	}
 }
+
+time_t 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;
+}
diff --git a/libs/libltpnewipc/libnewipc.c b/libs/libltpnewipc/libnewipc.c
index 4ae040f3b..331f1b1f5 100644
--- a/libs/libltpnewipc/libnewipc.c
+++ b/libs/libltpnewipc/libnewipc.c
@@ -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;
-}
diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv01.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv01.c
index afe552c4f..333171654 100644
--- a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv01.c
+++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv01.c
@@ -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 = 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 = get_fs_timestamp();
 
 	if (strcmp(rcv_buf.mtext, snd_buf.mtext) == 0)
 		tst_res(TPASS, "message received(%s) = message sent(%s)",
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
index 432b03def..c6c4eb303 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
+++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
@@ -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 = 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 = get_fs_timestamp();
 
 	SAFE_MSGCTL(queue_id, IPC_STAT, &qs_buf);
 
diff --git a/testcases/kernel/syscalls/ipc/shmctl/shmctl01.c b/testcases/kernel/syscalls/ipc/shmctl/shmctl01.c
index b32752fb1..7f1c913bd 100644
--- a/testcases/kernel/syscalls/ipc/shmctl/shmctl01.c
+++ b/testcases/kernel/syscalls/ipc/shmctl/shmctl01.c
@@ -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 = get_fs_timestamp();
 	shm_id = SAFE_SHMGET(IPC_PRIVATE, SHM_SIZE, IPC_CREAT | SHM_RW);
-	ctime_max = get_ipc_timestamp();
+	ctime_max = get_fs_timestamp();
 
 	shm_idx = get_shm_idx_from_id(shm_id);
 
-- 
2.33.0



More information about the ltp mailing list