Linux Test Project
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: jiaying.song.cn@windriver.com
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] syscalls/stime: Fix Time Overflow for 2038 Problem on 32-bit Systems
Date: Fri, 11 Jul 2025 17:32:05 +0200	[thread overview]
Message-ID: <aHEudV9Fk4lQJEWs@yuki.lan> (raw)
In-Reply-To: <20250428073811.133441-1-jiaying.song.cn@windriver.com>

Hi!
> Signed-off-by: Jiaying Song <jiaying.song.cn@windriver.com>
> ---
>  testcases/kernel/syscalls/stime/stime01.c   | 10 +++++-----
>  testcases/kernel/syscalls/stime/stime_var.h |  4 ++--
>  2 files changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/stime/stime01.c b/testcases/kernel/syscalls/stime/stime01.c
> index 82a340258..9e909d7ca 100644
> --- a/testcases/kernel/syscalls/stime/stime01.c
> +++ b/testcases/kernel/syscalls/stime/stime01.c
> @@ -33,7 +33,7 @@ static void run(void)
>  	new_time = real_time_tv.tv_sec + 30;
>  
>  	if (do_stime(&new_time) < 0) {
> -		tst_res(TFAIL | TERRNO, "stime(%ld) failed", new_time);
> +		tst_res(TFAIL | TERRNO, "stime(%jd) failed", (intmax_t)new_time);
>  		return;
>  	}
>  
> @@ -43,12 +43,12 @@ static void run(void)
>  	switch (pres_time_tv.tv_sec - new_time) {
>  	case 0:
>  	case 1:
> -		tst_res(TINFO, "pt.tv_sec: %ld", pres_time_tv.tv_sec);
> -		tst_res(TPASS, "system time was set to %ld", new_time);
> +		tst_res(TINFO, "pt.tv_sec: %jd", (intmax_t)pres_time_tv.tv_sec);
> +		tst_res(TPASS, "system time was set to %jd", (intmax_t)new_time);
>  	break;
>  	default:
> -		tst_res(TFAIL, "system time not set to %ld (got: %ld)",
> -			new_time, pres_time_tv.tv_sec);
> +		tst_res(TFAIL, "system time not set to %jd (got: %jd)",
> +			(intmax_t)new_time, (intmax_t)pres_time_tv.tv_sec);
>  	}
>  }
>  
> diff --git a/testcases/kernel/syscalls/stime/stime_var.h b/testcases/kernel/syscalls/stime/stime_var.h
> index 708b80573..326240972 100644
> --- a/testcases/kernel/syscalls/stime/stime_var.h
> +++ b/testcases/kernel/syscalls/stime/stime_var.h
> @@ -27,12 +27,12 @@ static int do_stime(time_t *ntime)
>  	case 1:
>  		return tst_syscall(__NR_stime, ntime);
>  	case 2: {
> -		struct __kernel_old_timeval tv;
> +		struct timeval tv;
>  
>  		tv.tv_sec = *ntime;
>  		tv.tv_usec = 0;
>  
> -		return tst_syscall(__NR_settimeofday, &tv, (struct timezone *) 0);
> +		return settimeofday(&tv, (struct timezone *) 0);

The point of this code is to call all possible kernel variants, so we
cant just change it like this.

I guess that the easiest fix is to set the new_time to a fixed value
that is not going to overflow.

Something like:

diff --git a/testcases/kernel/syscalls/stime/stime01.c b/testcases/kernel/syscalls/stime/stime01.c
index 82a340258..12b7ccb39 100644
--- a/testcases/kernel/syscalls/stime/stime01.c
+++ b/testcases/kernel/syscalls/stime/stime01.c
@@ -20,17 +20,12 @@
 #include "tst_test.h"
 #include "stime_var.h"

-static struct timeval real_time_tv;
-
 static void run(void)
 {
        time_t new_time;
        struct timeval pres_time_tv;

-       if (gettimeofday(&real_time_tv, NULL) < 0)
-               tst_brk(TBROK | TERRNO, "gettimeofday() failed");
-
-       new_time = real_time_tv.tv_sec + 30;
+       new_time = 1752247867;

-- 
Cyril Hrubis
chrubis@suse.cz

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

      parent reply	other threads:[~2025-07-11 15:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-28  7:38 [LTP] [PATCH] syscalls/stime: Fix Time Overflow for 2038 Problem on 32-bit Systems Jiaying Song via ltp
2025-04-30  7:29 ` Andrea Cervesato via ltp
2025-05-07  7:55   ` Song, Jiaying (CN) via ltp
2025-05-07 13:43   ` Petr Vorel
2025-07-11 15:32 ` Cyril Hrubis [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aHEudV9Fk4lQJEWs@yuki.lan \
    --to=chrubis@suse.cz \
    --cc=jiaying.song.cn@windriver.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox