public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] syscalls/time01:Avoid using TST_RET in time() test to support Y2038-safe time_t
@ 2025-05-19  6:49 Jiaying Song via ltp
  2025-09-19 16:05 ` Cyril Hrubis
  0 siblings, 1 reply; 4+ messages in thread
From: Jiaying Song via ltp @ 2025-05-19  6:49 UTC (permalink / raw)
  To: ltp

From: Jiaying Song <jiaying.song.cn@windriver.com>

On 32-bit systems with Y2038 support, time_t is 64-bit while TST_RET remains a long (usually 32-bit). 
Using TST_RET to store the return value of time() causes overflow after 2038, leading to incorrect comparisons 
and false test failures like:

    TFAIL: time() returned value -2085977741, stored value 2208989555 are different

This patch replaces usage of TST_RET with a local variable of type time_t (ret_time), 
ensuring correct behavior with large timestamps and avoiding truncation.

Signed-off-by: Jiaying Song <jiaying.song.cn@windriver.com>
---
 testcases/kernel/syscalls/time/time01.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/testcases/kernel/syscalls/time/time01.c b/testcases/kernel/syscalls/time/time01.c
index d8625c0..3da7f1c 100644
--- a/testcases/kernel/syscalls/time/time01.c
+++ b/testcases/kernel/syscalls/time/time01.c
@@ -24,24 +24,25 @@ time_t *targs[] = {
 static void verify_time(unsigned int i)
 {
 	time_t *tloc = targs[i];
+        time_t ret_time = time(tloc);        
+        
+        ret_time = time(tloc);
 
-	TEST(time(tloc));
-
-	if (TST_RET == -1) {
+	if (ret_time == -1) {
 		tst_res(TFAIL | TTERRNO, "time()");
 		return;
 	}
 
 	if (!tloc)
-		tst_res(TPASS, "time() returned value %ld", TST_RET);
-	else if (*tloc == TST_RET)
+		tst_res(TPASS, "time() returned value %lld", ret_time);
+	else if (*tloc == ret_time)
 		tst_res(TPASS,
-			"time() returned value %ld, stored value %jd are same",
-			TST_RET, (intmax_t) *tloc);
+			"time() returned value %lld, stored value %jd are same",
+			ret_time, (intmax_t) *tloc);
 	else
 		tst_res(TFAIL,
-			"time() returned value %ld, stored value %jd are different",
-			TST_RET, (intmax_t) *tloc);
+			"time() returned value %lld, stored value %jd are different",
+			ret_time, (intmax_t) *tloc);
 }
 
 static struct tst_test test = {
-- 
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH] syscalls/time01:Avoid using TST_RET in time() test to support Y2038-safe time_t
  2025-05-19  6:49 [LTP] [PATCH] syscalls/time01:Avoid using TST_RET in time() test to support Y2038-safe time_t Jiaying Song via ltp
@ 2025-09-19 16:05 ` Cyril Hrubis
  0 siblings, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2025-09-19 16:05 UTC (permalink / raw)
  To: jiaying.song.cn; +Cc: ltp

Hi!
Sorry for the late reply.

> +        time_t ret_time = time(tloc);        
> +        
> +        ret_time = time(tloc);
>  
> -	TEST(time(tloc));
> -
> -	if (TST_RET == -1) {
> +	if (ret_time == -1) {
>  		tst_res(TFAIL | TTERRNO, "time()");
>  		return;
>  	}
>  
>  	if (!tloc)
> -		tst_res(TPASS, "time() returned value %ld", TST_RET);
> -	else if (*tloc == TST_RET)
> +		tst_res(TPASS, "time() returned value %lld", ret_time);
> +	else if (*tloc == ret_time)
>  		tst_res(TPASS,
> -			"time() returned value %ld, stored value %jd are same",
> -			TST_RET, (intmax_t) *tloc);
> +			"time() returned value %lld, stored value %jd are same",
> +			ret_time, (intmax_t) *tloc);

The ret_time needs a cast, since it's not always long long. Or we can
just use the %jd and cast to (intmax_t) as we do for the tloc argument.

>  	else
>  		tst_res(TFAIL,
> -			"time() returned value %ld, stored value %jd are different",
> -			TST_RET, (intmax_t) *tloc);
> +			"time() returned value %lld, stored value %jd are different",
> +			ret_time, (intmax_t) *tloc);
>  }

Here as well.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [LTP] [PATCH] syscalls/time01:Avoid using TST_RET in time() test to support Y2038-safe time_t
@ 2025-10-20 11:13 Jiaying Song via ltp
  2025-11-07 12:19 ` Petr Vorel
  0 siblings, 1 reply; 4+ messages in thread
From: Jiaying Song via ltp @ 2025-10-20 11:13 UTC (permalink / raw)
  To: ltp, chrubis

From: Jiaying Song <jiaying.song.cn@windriver.com>

On 32-bit systems with Y2038 support, time_t is 64-bit while TST_RET
remains a long (usually 32-bit).Using TST_RET to store the return value
of time() causes overflow after 2038, leading to incorrect comparisons
and false test failures like:

    TFAIL: time() returned value -2085977741, stored value 2208989555 are different

This patch replaces usage of TST_RET with a local variable of type
time_t (ret_time), ensuring correct behavior with large timestamps and
avoiding truncation.

Signed-off-by: Jiaying Song <jiaying.song.cn@windriver.com>
---
 testcases/kernel/syscalls/time/time01.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/testcases/kernel/syscalls/time/time01.c b/testcases/kernel/syscalls/time/time01.c
index 9b176f892..7924f94b8 100644
--- a/testcases/kernel/syscalls/time/time01.c
+++ b/testcases/kernel/syscalls/time/time01.c
@@ -23,24 +23,23 @@ static time_t *targs[] = {
 static void verify_time(unsigned int i)
 {
 	time_t *tloc = targs[i];
+        time_t ret_time = time(tloc);
 
-	TEST(time(tloc));
-
-	if (TST_RET == -1) {
+	if (ret_time == -1) {
 		tst_res(TFAIL | TTERRNO, "time()");
 		return;
 	}
 
 	if (!tloc) {
-		tst_res(TPASS, "time() returned value %ld", TST_RET);
-	} else if (*tloc == TST_RET) {
+		tst_res(TPASS, "time() returned value %jd", (intmax_t) ret_time);
+	} else if (*tloc == ret_time) {
 		tst_res(TPASS,
-			"time() returned value %ld, stored value %jd are same",
-			TST_RET, (intmax_t) *tloc);
+			"time() returned value %jd, stored value %jd are same",
+			(intmax_t) ret_time, (intmax_t) *tloc);
 	} else {
 		tst_res(TFAIL,
-			"time() returned value %ld, stored value %jd are different",
-			TST_RET, (intmax_t) *tloc);
+			"time() returned value %jd, stored value %jd are different",
+			(intmax_t) ret_time, (intmax_t) *tloc);
 	}
 }
 
-- 
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH] syscalls/time01:Avoid using TST_RET in time() test to support Y2038-safe time_t
  2025-10-20 11:13 Jiaying Song via ltp
@ 2025-11-07 12:19 ` Petr Vorel
  0 siblings, 0 replies; 4+ messages in thread
From: Petr Vorel @ 2025-11-07 12:19 UTC (permalink / raw)
  To: jiaying.song.cn; +Cc: ltp

Hi Jiaying,

> On 32-bit systems with Y2038 support, time_t is 64-bit while TST_RET
> remains a long (usually 32-bit).Using TST_RET to store the return value
> of time() causes overflow after 2038, leading to incorrect comparisons
> and false test failures like:

>     TFAIL: time() returned value -2085977741, stored value 2208989555 are different

> This patch replaces usage of TST_RET with a local variable of type
> time_t (ret_time), ensuring correct behavior with large timestamps and
> avoiding truncation.

+1

...
> +++ b/testcases/kernel/syscalls/time/time01.c
> @@ -23,24 +23,23 @@ static time_t *targs[] = {
>  static void verify_time(unsigned int i)
>  {
>  	time_t *tloc = targs[i];
> +        time_t ret_time = time(tloc);

> -	TEST(time(tloc));

nit: wrong whitespace indent (can be fixed before merge).

Fixed that and merged.

Thanks!

Kind regards,
Petr

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-11-07 12:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-19  6:49 [LTP] [PATCH] syscalls/time01:Avoid using TST_RET in time() test to support Y2038-safe time_t Jiaying Song via ltp
2025-09-19 16:05 ` Cyril Hrubis
  -- strict thread matches above, loose matches on Subject: below --
2025-10-20 11:13 Jiaying Song via ltp
2025-11-07 12:19 ` Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox