Hi,
Just a bunch of fixes as part of my work to make selftests build cleanly with clang.
Enjoy!
thanks, John Hubbard
John Hubbard (4): selftests/cgroup: fix clang build failures for abs() calls selftests/cgroup: fix clang warnings: uninitialized fd variable selftests/cgroup: cpu_hogger init: use {} instead of {NULL} selftests/cgroup: fix uninitialized variables in test_zswap.c
tools/testing/selftests/cgroup/cgroup_util.h | 2 +- tools/testing/selftests/cgroup/test_cpu.c | 4 ++-- tools/testing/selftests/cgroup/test_kmem.c | 4 ++-- tools/testing/selftests/cgroup/test_memcontrol.c | 4 +++- tools/testing/selftests/cgroup/test_zswap.c | 4 ++-- 5 files changed, 10 insertions(+), 8 deletions(-)
base-commit: f03359bca01bf4372cf2c118cd9a987a5951b1c8 prerequisite-patch-id: b901ece2a5b78503e2fb5480f20e304d36a0ea27
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-2f9ed7d1c...
Signed-off-by: John Hubbard jhubbard@nvidia.com --- tools/testing/selftests/cgroup/cgroup_util.h | 2 +- tools/testing/selftests/cgroup/test_kmem.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/cgroup/cgroup_util.h b/tools/testing/selftests/cgroup/cgroup_util.h index 1df7f202214a..239633e936df 100644 --- a/tools/testing/selftests/cgroup/cgroup_util.h +++ b/tools/testing/selftests/cgroup/cgroup_util.h @@ -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); diff --git a/tools/testing/selftests/cgroup/test_kmem.c b/tools/testing/selftests/cgroup/test_kmem.c index c82f974b85c9..d21d3d280ca2 100644 --- a/tools/testing/selftests/cgroup/test_kmem.c +++ b/tools/testing/selftests/cgroup/test_kmem.c @@ -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
On Thu, May 02, 2024 at 08:51:02PM -0700, John Hubbard wrote:
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-2f9ed7d1c...
Signed-off-by: John Hubbard jhubbard@nvidia.com
Reviewed-by: Roman Gushchin roman.gushchin@linux.dev
Thanks!
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 warns about fd being used uninitialized, in test_memcg_reclaim()'s error handling path.
Fix this by initializing fd to -1.
[1] https://lore.kernel.org/all/20240329-selftests-libmk-llvm-rfc-v1-1-2f9ed7d1c...
Signed-off-by: John Hubbard jhubbard@nvidia.com --- tools/testing/selftests/cgroup/test_memcontrol.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c index c7c9572003a8..a97832b0c1cd 100644 --- a/tools/testing/selftests/cgroup/test_memcontrol.c +++ b/tools/testing/selftests/cgroup/test_memcontrol.c @@ -716,7 +716,9 @@ static bool reclaim_until(const char *memcg, long goal) */ static int test_memcg_reclaim(const char *root) { - int ret = KSFT_FAIL, fd, retries; + int ret = KSFT_FAIL; + int fd = -1; + int retries; char *memcg; long current, expected_usage;
On Thu, May 02, 2024 at 08:51:03PM -0700, John Hubbard wrote:
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 warns about fd being used uninitialized, in test_memcg_reclaim()'s error handling path.
Fix this by initializing fd to -1.
[1] https://lore.kernel.org/all/20240329-selftests-libmk-llvm-rfc-v1-1-2f9ed7d1c...
Signed-off-by: John Hubbard jhubbard@nvidia.com
Reviewed-by: Roman Gushchin roman.gushchin@linux.dev
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 generates warning here, because struct cpu_hogger has multiple fields, and the code is initializing an array of these structs, and it is incorrect to specify a single NULL value as the initializer.
Fix this by initializing with {}, so that the compiler knows to use default initializer values for all fields in each array entry.
[1] https://lore.kernel.org/all/20240329-selftests-libmk-llvm-rfc-v1-1-2f9ed7d1c...
Signed-off-by: John Hubbard jhubbard@nvidia.com --- tools/testing/selftests/cgroup/test_cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/cgroup/test_cpu.c b/tools/testing/selftests/cgroup/test_cpu.c index 24020a2c68dc..e4266b60e5ac 100644 --- a/tools/testing/selftests/cgroup/test_cpu.c +++ b/tools/testing/selftests/cgroup/test_cpu.c @@ -237,7 +237,7 @@ run_cpucg_weight_test( { int ret = KSFT_FAIL, i; char *parent = NULL; - struct cpu_hogger children[3] = {NULL}; + struct cpu_hogger children[3] = {};
parent = cg_name(root, "cpucg_test_0"); if (!parent) @@ -408,7 +408,7 @@ run_cpucg_nested_weight_test(const char *root, bool overprovisioned) { int ret = KSFT_FAIL, i; char *parent = NULL, *child = NULL; - struct cpu_hogger leaf[3] = {NULL}; + struct cpu_hogger leaf[3] = {}; long nested_leaf_usage, child_usage; int nprocs = get_nprocs();
On Thu, May 02, 2024 at 08:51:04PM -0700, John Hubbard wrote:
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 generates warning here, because struct cpu_hogger has multiple fields, and the code is initializing an array of these structs, and it is incorrect to specify a single NULL value as the initializer.
Fix this by initializing with {}, so that the compiler knows to use default initializer values for all fields in each array entry.
[1] https://lore.kernel.org/all/20240329-selftests-libmk-llvm-rfc-v1-1-2f9ed7d1c...
Signed-off-by: John Hubbard jhubbard@nvidia.com
Reviewed-by: Roman Gushchin roman.gushchin@linux.dev
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 finds and warning about some uninitialized variables. Fix these by initializing them.
[1] https://lore.kernel.org/all/20240329-selftests-libmk-llvm-rfc-v1-1-2f9ed7d1c...
Signed-off-by: John Hubbard jhubbard@nvidia.com --- tools/testing/selftests/cgroup/test_zswap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/selftests/cgroup/test_zswap.c index f0e488ed90d8..6aac80eadc5d 100644 --- a/tools/testing/selftests/cgroup/test_zswap.c +++ b/tools/testing/selftests/cgroup/test_zswap.c @@ -257,7 +257,7 @@ static int test_no_invasive_cgroup_shrink(const char *root) { int ret = KSFT_FAIL; size_t control_allocation_size = MB(10); - char *control_allocation, *wb_group = NULL, *control_group = NULL; + char *control_allocation = NULL, *wb_group = NULL, *control_group = NULL;
wb_group = setup_test_group_1M(root, "per_memcg_wb_test1"); if (!wb_group) @@ -342,7 +342,7 @@ static int test_no_kmem_bypass(const char *root) struct sysinfo sys_info; int ret = KSFT_FAIL; int child_status; - char *test_group; + char *test_group = NULL; pid_t child_pid;
/* Read sys info and compute test values accordingly */
On Thu, May 02, 2024 at 08:51:05PM -0700, John Hubbard wrote:
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 finds and warning about some uninitialized variables. Fix these by initializing them.
[1] https://lore.kernel.org/all/20240329-selftests-libmk-llvm-rfc-v1-1-2f9ed7d1c...
Signed-off-by: John Hubbard jhubbard@nvidia.com
Reviewed-by: Roman Gushchin roman.gushchin@linux.dev
Thanks!
On Thu, May 2, 2024 at 8:51 PM John Hubbard jhubbard@nvidia.com wrote:
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 finds and warning about some uninitialized variables. Fix these by initializing them.
[1] https://lore.kernel.org/all/20240329-selftests-libmk-llvm-rfc-v1-1-2f9ed7d1c...
Signed-off-by: John Hubbard jhubbard@nvidia.com
Reviewed-by: Nhat Pham nphamcs@gmail.com
On Thu, May 02, 2024 at 08:51:01PM -0700, John Hubbard wrote:
Hi,
Just a bunch of fixes as part of my work to make selftests build cleanly with clang.
Enjoy!
thanks, John Hubbard
John Hubbard (4): selftests/cgroup: fix clang build failures for abs() calls selftests/cgroup: fix clang warnings: uninitialized fd variable selftests/cgroup: cpu_hogger init: use {} instead of {NULL} selftests/cgroup: fix uninitialized variables in test_zswap.c
Applied to cgroup/for-6.10.
Thanks.
linux-kselftest-mirror@lists.linaro.org