Skip to content

Commit 1da2363

Browse files
johnhubbardhtejun
authored andcommitted
selftests/cgroup: fix clang build failures for abs() calls
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 <[email protected]> Reviewed-by: Roman Gushchin <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent b7d56d9 commit 1da2363

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

tools/testing/selftests/cgroup/cgroup_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
static inline int values_close(long a, long b, int err)
2020
{
21-
return abs(a - b) <= (a + b) / 100 * err;
21+
return labs(a - b) <= (a + b) / 100 * err;
2222
}
2323

2424
extern int cg_find_unified_root(char *root, size_t len, bool *nsdelegate);

tools/testing/selftests/cgroup/test_kmem.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static int test_kmem_memcg_deletion(const char *root)
192192
goto cleanup;
193193

194194
sum = anon + file + kernel + sock;
195-
if (abs(sum - current) < MAX_VMSTAT_ERROR) {
195+
if (labs(sum - current) < MAX_VMSTAT_ERROR) {
196196
ret = KSFT_PASS;
197197
} else {
198198
printf("memory.current = %ld\n", current);
@@ -380,7 +380,7 @@ static int test_percpu_basic(const char *root)
380380
current = cg_read_long(parent, "memory.current");
381381
percpu = cg_read_key_long(parent, "memory.stat", "percpu ");
382382

383-
if (current > 0 && percpu > 0 && abs(current - percpu) <
383+
if (current > 0 && percpu > 0 && labs(current - percpu) <
384384
MAX_VMSTAT_ERROR)
385385
ret = KSFT_PASS;
386386
else

0 commit comments

Comments
 (0)