* [PATCH v3] selftest/timerns: fix clang build failures for abs() calls
@ 2024-07-04 2:52 John Hubbard
2024-07-04 3:44 ` Andrei Vagin
0 siblings, 1 reply; 3+ messages in thread
From: John Hubbard @ 2024-07-04 2:52 UTC (permalink / raw)
To: Shuah Khan
Cc: Andrei Vagin, Andrei Vagin, Dmitry Safonov, Thomas Gleixner,
Valentin Obst, linux-kselftest, LKML, llvm, John Hubbard,
Muhammad Usama Anjum
When building with clang, via:
make LLVM=1 -C tools/testing/selftests
...clang warns about mismatches between the expected and required
integer length being supplied to abs(3).
Fix this by using the correct variant of abs(3): labs(3) or llabs(3), in
these cases.
Reviewed-by: Dmitry Safonov <dima@arista.com>
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
---
Hi,
Changes since v2:
1) Commit description: removed the reference to Valentin Obst's patch
being a prerequisite, now that that has been merged.
2) Rebased on Linux 6.10-rc6+.
Changes since the first version:
1) Rebased onto Linux 6.10-rc1
2) Reviewed-by's added.
thanks,
John Hubbard
tools/testing/selftests/timens/exec.c | 6 +++---
tools/testing/selftests/timens/timer.c | 2 +-
tools/testing/selftests/timens/timerfd.c | 2 +-
tools/testing/selftests/timens/vfork_exec.c | 4 ++--
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/tools/testing/selftests/timens/exec.c b/tools/testing/selftests/timens/exec.c
index e40dc5be2f66..d12ff955de0d 100644
--- a/tools/testing/selftests/timens/exec.c
+++ b/tools/testing/selftests/timens/exec.c
@@ -30,7 +30,7 @@ int main(int argc, char *argv[])
for (i = 0; i < 2; i++) {
_gettime(CLOCK_MONOTONIC, &tst, i);
- if (abs(tst.tv_sec - now.tv_sec) > 5)
+ if (labs(tst.tv_sec - now.tv_sec) > 5)
return pr_fail("%ld %ld\n", now.tv_sec, tst.tv_sec);
}
return 0;
@@ -50,7 +50,7 @@ int main(int argc, char *argv[])
for (i = 0; i < 2; i++) {
_gettime(CLOCK_MONOTONIC, &tst, i);
- if (abs(tst.tv_sec - now.tv_sec) > 5)
+ if (labs(tst.tv_sec - now.tv_sec) > 5)
return pr_fail("%ld %ld\n",
now.tv_sec, tst.tv_sec);
}
@@ -70,7 +70,7 @@ int main(int argc, char *argv[])
/* Check that a child process is in the new timens. */
for (i = 0; i < 2; i++) {
_gettime(CLOCK_MONOTONIC, &tst, i);
- if (abs(tst.tv_sec - now.tv_sec - OFFSET) > 5)
+ if (labs(tst.tv_sec - now.tv_sec - OFFSET) > 5)
return pr_fail("%ld %ld\n",
now.tv_sec + OFFSET, tst.tv_sec);
}
diff --git a/tools/testing/selftests/timens/timer.c b/tools/testing/selftests/timens/timer.c
index 5e7f0051bd7b..5b939f59dfa4 100644
--- a/tools/testing/selftests/timens/timer.c
+++ b/tools/testing/selftests/timens/timer.c
@@ -56,7 +56,7 @@ int run_test(int clockid, struct timespec now)
return pr_perror("timerfd_gettime");
elapsed = new_value.it_value.tv_sec;
- if (abs(elapsed - 3600) > 60) {
+ if (llabs(elapsed - 3600) > 60) {
ksft_test_result_fail("clockid: %d elapsed: %lld\n",
clockid, elapsed);
return 1;
diff --git a/tools/testing/selftests/timens/timerfd.c b/tools/testing/selftests/timens/timerfd.c
index 9edd43d6b2c1..a4196bbd6e33 100644
--- a/tools/testing/selftests/timens/timerfd.c
+++ b/tools/testing/selftests/timens/timerfd.c
@@ -61,7 +61,7 @@ int run_test(int clockid, struct timespec now)
return pr_perror("timerfd_gettime(%d)", clockid);
elapsed = new_value.it_value.tv_sec;
- if (abs(elapsed - 3600) > 60) {
+ if (llabs(elapsed - 3600) > 60) {
ksft_test_result_fail("clockid: %d elapsed: %lld\n",
clockid, elapsed);
return 1;
diff --git a/tools/testing/selftests/timens/vfork_exec.c b/tools/testing/selftests/timens/vfork_exec.c
index beb7614941fb..5b8907bf451d 100644
--- a/tools/testing/selftests/timens/vfork_exec.c
+++ b/tools/testing/selftests/timens/vfork_exec.c
@@ -32,7 +32,7 @@ static void *tcheck(void *_args)
for (i = 0; i < 2; i++) {
_gettime(CLOCK_MONOTONIC, &tst, i);
- if (abs(tst.tv_sec - now->tv_sec) > 5) {
+ if (labs(tst.tv_sec - now->tv_sec) > 5) {
pr_fail("%s: in-thread: unexpected value: %ld (%ld)\n",
args->tst_name, tst.tv_sec, now->tv_sec);
return (void *)1UL;
@@ -64,7 +64,7 @@ static int check(char *tst_name, struct timespec *now)
for (i = 0; i < 2; i++) {
_gettime(CLOCK_MONOTONIC, &tst, i);
- if (abs(tst.tv_sec - now->tv_sec) > 5)
+ if (labs(tst.tv_sec - now->tv_sec) > 5)
return pr_fail("%s: unexpected value: %ld (%ld)\n",
tst_name, tst.tv_sec, now->tv_sec);
}
base-commit: 8a9c6c40432e265600232b864f97d7c675e8be52
--
2.45.2
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v3] selftest/timerns: fix clang build failures for abs() calls
2024-07-04 2:52 [PATCH v3] selftest/timerns: fix clang build failures for abs() calls John Hubbard
@ 2024-07-04 3:44 ` Andrei Vagin
2024-07-09 20:35 ` Shuah Khan
0 siblings, 1 reply; 3+ messages in thread
From: Andrei Vagin @ 2024-07-04 3:44 UTC (permalink / raw)
To: John Hubbard
Cc: Shuah Khan, Dmitry Safonov, Thomas Gleixner, Valentin Obst,
linux-kselftest, LKML, llvm, Muhammad Usama Anjum
On Wed, Jul 3, 2024 at 7:52 PM John Hubbard <jhubbard@nvidia.com> wrote:
>
> When building with clang, via:
>
> make LLVM=1 -C tools/testing/selftests
>
> ...clang warns about mismatches between the expected and required
> integer length being supplied to abs(3).
>
> Fix this by using the correct variant of abs(3): labs(3) or llabs(3), in
> these cases.
>
Acked-by: Andrei Vagin <avagin@google.com>
> Reviewed-by: Dmitry Safonov <dima@arista.com>
> Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> Signed-off-by: John Hubbard <jhubbard@nvidia.com>
> ---
>
> Hi,
>
> Changes since v2:
>
> 1) Commit description: removed the reference to Valentin Obst's patch
> being a prerequisite, now that that has been merged.
>
> 2) Rebased on Linux 6.10-rc6+.
>
> Changes since the first version:
>
> 1) Rebased onto Linux 6.10-rc1
>
> 2) Reviewed-by's added.
>
> thanks,
> John Hubbard
>
>
> tools/testing/selftests/timens/exec.c | 6 +++---
> tools/testing/selftests/timens/timer.c | 2 +-
> tools/testing/selftests/timens/timerfd.c | 2 +-
> tools/testing/selftests/timens/vfork_exec.c | 4 ++--
> 4 files changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/tools/testing/selftests/timens/exec.c b/tools/testing/selftests/timens/exec.c
> index e40dc5be2f66..d12ff955de0d 100644
> --- a/tools/testing/selftests/timens/exec.c
> +++ b/tools/testing/selftests/timens/exec.c
> @@ -30,7 +30,7 @@ int main(int argc, char *argv[])
>
> for (i = 0; i < 2; i++) {
> _gettime(CLOCK_MONOTONIC, &tst, i);
> - if (abs(tst.tv_sec - now.tv_sec) > 5)
> + if (labs(tst.tv_sec - now.tv_sec) > 5)
> return pr_fail("%ld %ld\n", now.tv_sec, tst.tv_sec);
> }
> return 0;
> @@ -50,7 +50,7 @@ int main(int argc, char *argv[])
>
> for (i = 0; i < 2; i++) {
> _gettime(CLOCK_MONOTONIC, &tst, i);
> - if (abs(tst.tv_sec - now.tv_sec) > 5)
> + if (labs(tst.tv_sec - now.tv_sec) > 5)
> return pr_fail("%ld %ld\n",
> now.tv_sec, tst.tv_sec);
> }
> @@ -70,7 +70,7 @@ int main(int argc, char *argv[])
> /* Check that a child process is in the new timens. */
> for (i = 0; i < 2; i++) {
> _gettime(CLOCK_MONOTONIC, &tst, i);
> - if (abs(tst.tv_sec - now.tv_sec - OFFSET) > 5)
> + if (labs(tst.tv_sec - now.tv_sec - OFFSET) > 5)
> return pr_fail("%ld %ld\n",
> now.tv_sec + OFFSET, tst.tv_sec);
> }
> diff --git a/tools/testing/selftests/timens/timer.c b/tools/testing/selftests/timens/timer.c
> index 5e7f0051bd7b..5b939f59dfa4 100644
> --- a/tools/testing/selftests/timens/timer.c
> +++ b/tools/testing/selftests/timens/timer.c
> @@ -56,7 +56,7 @@ int run_test(int clockid, struct timespec now)
> return pr_perror("timerfd_gettime");
>
> elapsed = new_value.it_value.tv_sec;
> - if (abs(elapsed - 3600) > 60) {
> + if (llabs(elapsed - 3600) > 60) {
> ksft_test_result_fail("clockid: %d elapsed: %lld\n",
> clockid, elapsed);
> return 1;
> diff --git a/tools/testing/selftests/timens/timerfd.c b/tools/testing/selftests/timens/timerfd.c
> index 9edd43d6b2c1..a4196bbd6e33 100644
> --- a/tools/testing/selftests/timens/timerfd.c
> +++ b/tools/testing/selftests/timens/timerfd.c
> @@ -61,7 +61,7 @@ int run_test(int clockid, struct timespec now)
> return pr_perror("timerfd_gettime(%d)", clockid);
>
> elapsed = new_value.it_value.tv_sec;
> - if (abs(elapsed - 3600) > 60) {
> + if (llabs(elapsed - 3600) > 60) {
> ksft_test_result_fail("clockid: %d elapsed: %lld\n",
> clockid, elapsed);
> return 1;
> diff --git a/tools/testing/selftests/timens/vfork_exec.c b/tools/testing/selftests/timens/vfork_exec.c
> index beb7614941fb..5b8907bf451d 100644
> --- a/tools/testing/selftests/timens/vfork_exec.c
> +++ b/tools/testing/selftests/timens/vfork_exec.c
> @@ -32,7 +32,7 @@ static void *tcheck(void *_args)
>
> for (i = 0; i < 2; i++) {
> _gettime(CLOCK_MONOTONIC, &tst, i);
> - if (abs(tst.tv_sec - now->tv_sec) > 5) {
> + if (labs(tst.tv_sec - now->tv_sec) > 5) {
> pr_fail("%s: in-thread: unexpected value: %ld (%ld)\n",
> args->tst_name, tst.tv_sec, now->tv_sec);
> return (void *)1UL;
> @@ -64,7 +64,7 @@ static int check(char *tst_name, struct timespec *now)
>
> for (i = 0; i < 2; i++) {
> _gettime(CLOCK_MONOTONIC, &tst, i);
> - if (abs(tst.tv_sec - now->tv_sec) > 5)
> + if (labs(tst.tv_sec - now->tv_sec) > 5)
> return pr_fail("%s: unexpected value: %ld (%ld)\n",
> tst_name, tst.tv_sec, now->tv_sec);
> }
>
> base-commit: 8a9c6c40432e265600232b864f97d7c675e8be52
> --
> 2.45.2
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v3] selftest/timerns: fix clang build failures for abs() calls
2024-07-04 3:44 ` Andrei Vagin
@ 2024-07-09 20:35 ` Shuah Khan
0 siblings, 0 replies; 3+ messages in thread
From: Shuah Khan @ 2024-07-09 20:35 UTC (permalink / raw)
To: Andrei Vagin, John Hubbard
Cc: Shuah Khan, Dmitry Safonov, Thomas Gleixner, Valentin Obst,
linux-kselftest, LKML, llvm, Muhammad Usama Anjum, Shuah Khan
On 7/3/24 21:44, Andrei Vagin wrote:
> On Wed, Jul 3, 2024 at 7:52 PM John Hubbard <jhubbard@nvidia.com> wrote:
>>
>> When building with clang, via:
>>
>> make LLVM=1 -C tools/testing/selftests
>>
>> ...clang warns about mismatches between the expected and required
>> integer length being supplied to abs(3).
>>
>> Fix this by using the correct variant of abs(3): labs(3) or llabs(3), in
>> these cases.
>>
>
> Acked-by: Andrei Vagin <avagin@google.com>
>
Sent in for Linux 6.10 fixes update.
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-07-09 20:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-04 2:52 [PATCH v3] selftest/timerns: fix clang build failures for abs() calls John Hubbard
2024-07-04 3:44 ` Andrei Vagin
2024-07-09 20:35 ` Shuah Khan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®