]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/cgroup: fix clang build failures for abs() calls
authorJohn Hubbard <jhubbard@nvidia.com>
Fri, 3 May 2024 03:51:02 +0000 (20:51 -0700)
committerTejun Heo <tj@kernel.org>
Fri, 3 May 2024 19:06:09 +0000 (09:06 -1000)
First of all, in order to build with clang at all, one must first apply
Valentin Obst's build fix for LLVM [1]. Once that is done, then when
building with clang, via:

    make LLVM=1 -C tools/testing/selftests

...clang is pickier than gcc, about which version of abs(3) to call,
depending on the argument type:

   int abs(int j);
   long labs(long j);
   long long llabs(long long j);

...and this is causing both build failures and warnings, when running:

    make LLVM=1 -C tools/testing/selftests

Fix this by calling labs() in value_close(), because the arguments are
unambiguously "long" type.

[1] https://lore.kernel.org/all/20240329-selftests-libmk-llvm-rfc-v1-1-2f9ed7d1c49f@valentinobst.de/

Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Reviewed-by: Roman Gushchin <roman.gushchin@linux.dev>
Signed-off-by: Tejun Heo <tj@kernel.org>
tools/testing/selftests/cgroup/cgroup_util.h
tools/testing/selftests/cgroup/test_kmem.c

index 89e8519fb2719c53d27f2b99b111809ebe929022..e8d04ac9e3d23cdcce8c85e392684dec850562f1 100644 (file)
@@ -18,7 +18,7 @@
  */
 static inline int values_close(long a, long b, int err)
 {
-       return abs(a - b) <= (a + b) / 100 * err;
+       return labs(a - b) <= (a + b) / 100 * err;
 }
 
 extern int cg_find_unified_root(char *root, size_t len, bool *nsdelegate);
index 137506db03127fb3eed6554e684bd41f7112e77f..96693d8772be244874545f6e33726d7561e21aea 100644 (file)
@@ -192,7 +192,7 @@ static int test_kmem_memcg_deletion(const char *root)
                goto cleanup;
 
        sum = anon + file + kernel + sock;
-       if (abs(sum - current) < MAX_VMSTAT_ERROR) {
+       if (labs(sum - current) < MAX_VMSTAT_ERROR) {
                ret = KSFT_PASS;
        } else {
                printf("memory.current = %ld\n", current);
@@ -380,7 +380,7 @@ static int test_percpu_basic(const char *root)
        current = cg_read_long(parent, "memory.current");
        percpu = cg_read_key_long(parent, "memory.stat", "percpu ");
 
-       if (current > 0 && percpu > 0 && abs(current - percpu) <
+       if (current > 0 && percpu > 0 && labs(current - percpu) <
            MAX_VMSTAT_ERROR)
                ret = KSFT_PASS;
        else