Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit f76f9bc

Browse files
johnhubbardshuahkh
authored andcommitted
selftest/timerns: fix clang build failures for abs() calls
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> Acked-by: Andrei Vagin <avagin@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 4823696 commit f76f9bc

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

tools/testing/selftests/timens/exec.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ int main(int argc, char *argv[])
3030

3131
for (i = 0; i < 2; i++) {
3232
_gettime(CLOCK_MONOTONIC, &tst, i);
33-
if (abs(tst.tv_sec - now.tv_sec) > 5)
33+
if (labs(tst.tv_sec - now.tv_sec) > 5)
3434
return pr_fail("%ld %ld\n", now.tv_sec, tst.tv_sec);
3535
}
3636
return 0;
@@ -50,7 +50,7 @@ int main(int argc, char *argv[])
5050

5151
for (i = 0; i < 2; i++) {
5252
_gettime(CLOCK_MONOTONIC, &tst, i);
53-
if (abs(tst.tv_sec - now.tv_sec) > 5)
53+
if (labs(tst.tv_sec - now.tv_sec) > 5)
5454
return pr_fail("%ld %ld\n",
5555
now.tv_sec, tst.tv_sec);
5656
}
@@ -70,7 +70,7 @@ int main(int argc, char *argv[])
7070
/* Check that a child process is in the new timens. */
7171
for (i = 0; i < 2; i++) {
7272
_gettime(CLOCK_MONOTONIC, &tst, i);
73-
if (abs(tst.tv_sec - now.tv_sec - OFFSET) > 5)
73+
if (labs(tst.tv_sec - now.tv_sec - OFFSET) > 5)
7474
return pr_fail("%ld %ld\n",
7575
now.tv_sec + OFFSET, tst.tv_sec);
7676
}

tools/testing/selftests/timens/timer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ int run_test(int clockid, struct timespec now)
5656
return pr_perror("timerfd_gettime");
5757

5858
elapsed = new_value.it_value.tv_sec;
59-
if (abs(elapsed - 3600) > 60) {
59+
if (llabs(elapsed - 3600) > 60) {
6060
ksft_test_result_fail("clockid: %d elapsed: %lld\n",
6161
clockid, elapsed);
6262
return 1;

tools/testing/selftests/timens/timerfd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int run_test(int clockid, struct timespec now)
6161
return pr_perror("timerfd_gettime(%d)", clockid);
6262

6363
elapsed = new_value.it_value.tv_sec;
64-
if (abs(elapsed - 3600) > 60) {
64+
if (llabs(elapsed - 3600) > 60) {
6565
ksft_test_result_fail("clockid: %d elapsed: %lld\n",
6666
clockid, elapsed);
6767
return 1;

tools/testing/selftests/timens/vfork_exec.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static void *tcheck(void *_args)
3232

3333
for (i = 0; i < 2; i++) {
3434
_gettime(CLOCK_MONOTONIC, &tst, i);
35-
if (abs(tst.tv_sec - now->tv_sec) > 5) {
35+
if (labs(tst.tv_sec - now->tv_sec) > 5) {
3636
pr_fail("%s: in-thread: unexpected value: %ld (%ld)\n",
3737
args->tst_name, tst.tv_sec, now->tv_sec);
3838
return (void *)1UL;
@@ -64,7 +64,7 @@ static int check(char *tst_name, struct timespec *now)
6464

6565
for (i = 0; i < 2; i++) {
6666
_gettime(CLOCK_MONOTONIC, &tst, i);
67-
if (abs(tst.tv_sec - now->tv_sec) > 5)
67+
if (labs(tst.tv_sec - now->tv_sec) > 5)
6868
return pr_fail("%s: unexpected value: %ld (%ld)\n",
6969
tst_name, tst.tv_sec, now->tv_sec);
7070
}

0 commit comments

Comments
 (0)