* [LTP] [PATCH v2 1/2] Rename get_ipc_timestamp() and move to main LTP library
@ 2021-09-23 13:44 Martin Doucha
2021-09-23 13:44 ` [LTP] [PATCH v2 2/2] syscalls/utime03: Fix timestamp checks Martin Doucha
2021-09-23 14:04 ` [LTP] [PATCH v2 1/2] Rename get_ipc_timestamp() and move to main LTP library Cyril Hrubis
0 siblings, 2 replies; 4+ messages in thread
From: Martin Doucha @ 2021-09-23 13:44 UTC (permalink / raw)
To: ltp
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.
Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
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(-)
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..952bb4c47 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 tst_get_fs_timestamp(void);
+
#endif /* TST_CLOCKS__ */
diff --git a/lib/tst_clocks.c b/lib/tst_clocks.c
index cdcb9fc4f..0417802fc 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 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;
+}
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..9df20a61e 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 = 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)",
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
index 432b03def..8232f0cac 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 = 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);
diff --git a/testcases/kernel/syscalls/ipc/shmctl/shmctl01.c b/testcases/kernel/syscalls/ipc/shmctl/shmctl01.c
index b32752fb1..789fc8c72 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 = 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);
--
2.33.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [LTP] [PATCH v2 2/2] syscalls/utime03: Fix timestamp checks
2021-09-23 13:44 [LTP] [PATCH v2 1/2] Rename get_ipc_timestamp() and move to main LTP library Martin Doucha
@ 2021-09-23 13:44 ` Martin Doucha
2022-07-21 7:28 ` Jan Stancek
2021-09-23 14:04 ` [LTP] [PATCH v2 1/2] Rename get_ipc_timestamp() and move to main LTP library Cyril Hrubis
1 sibling, 1 reply; 4+ messages in thread
From: Martin Doucha @ 2021-09-23 13:44 UTC (permalink / raw)
To: ltp
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(-)
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH v2 1/2] Rename get_ipc_timestamp() and move to main LTP library
2021-09-23 13:44 [LTP] [PATCH v2 1/2] Rename get_ipc_timestamp() and move to main LTP library Martin Doucha
2021-09-23 13:44 ` [LTP] [PATCH v2 2/2] syscalls/utime03: Fix timestamp checks Martin Doucha
@ 2021-09-23 14:04 ` Cyril Hrubis
1 sibling, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2021-09-23 14:04 UTC (permalink / raw)
To: Martin Doucha; +Cc: ltp
Hi!
> +/*
> + * Returns current system time for file/IPC operations, which may slightly lag
> + * behind time() return values.
> + */
I've added slightly longer (and hopefuly better) explanation why this
happends here and pushed the patches, thanks.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH v2 2/2] syscalls/utime03: Fix timestamp checks
2021-09-23 13:44 ` [LTP] [PATCH v2 2/2] syscalls/utime03: Fix timestamp checks Martin Doucha
@ 2022-07-21 7:28 ` Jan Stancek
0 siblings, 0 replies; 4+ messages in thread
From: Jan Stancek @ 2022-07-21 7:28 UTC (permalink / raw)
To: Martin Doucha; +Cc: LTP List
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
>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-07-21 7:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-23 13:44 [LTP] [PATCH v2 1/2] Rename get_ipc_timestamp() and move to main LTP library Martin Doucha
2021-09-23 13:44 ` [LTP] [PATCH v2 2/2] syscalls/utime03: Fix timestamp checks Martin Doucha
2022-07-21 7:28 ` Jan Stancek
2021-09-23 14:04 ` [LTP] [PATCH v2 1/2] Rename get_ipc_timestamp() and move to main LTP library Cyril Hrubis
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.