Skip to contentSkip to conversation

selftests: cgroup: build error multiple outpt files

PATCH In review Anders Roxell 4 participants 11 messages Nov 5, 2021 – Dec 3, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 selftests: cgroup: build error multiple outpt files

When building selftests/cgroup: with clang the following error are seen:

clang -Wall -pthread test_memcontrol.c cgroup_util.c ../clone3/clone3_selftests.h -o /home/anders/.cache/tuxmake/builds/current/kselftest/cgroup/test_memcontrol
clang: error: cannot specify -o when generating multiple output files
make[3]: *** [../lib.mk:146: /home/anders/.cache/tuxmake/builds/current/kselftest/cgroup/test_memcontrol] Error 1

Rework to add the header files to LOCAL_HDRS before including ../lib.mk, since the dependency is evaluated in '$(OUTPUT)/%:%.c $(LOCAL_HDRS)' in file lib.mk.

---
 tools/testing/selftests/cgroup/Makefile | 12 +++++++-----
 tools/testing/selftests/lib.mk          |  2 +-
 2 files changed, 8 insertions(+), 6 deletions(-)
tools/testing/selftests/cgroup/Makefile +7 -5
index 59e222460581..745fe25fa0b9 100644
@@ -11,10 +11,12 @@ TEST_GEN_PROGS += test_core
 TEST_GEN_PROGS += test_freezer
 TEST_GEN_PROGS += test_kill
 
+LOCAL_HDRS += $(selfdir)/clone3/clone3_selftests.h $(selfdir)/pidfd/pidfd.h
+
 include ../lib.mk
 
-$(OUTPUT)/test_memcontrol: cgroup_util.c ../clone3/clone3_selftests.h
-$(OUTPUT)/test_kmem: cgroup_util.c ../clone3/clone3_selftests.h
-$(OUTPUT)/test_core: cgroup_util.c ../clone3/clone3_selftests.h
-$(OUTPUT)/test_freezer: cgroup_util.c ../clone3/clone3_selftests.h
-$(OUTPUT)/test_kill: cgroup_util.c ../clone3/clone3_selftests.h ../pidfd/pidfd.h
+$(OUTPUT)/test_memcontrol: cgroup_util.c
+$(OUTPUT)/test_kmem: cgroup_util.c
+$(OUTPUT)/test_core: cgroup_util.c
+$(OUTPUT)/test_freezer: cgroup_util.c
+$(OUTPUT)/test_kill: cgroup_util.c
tools/testing/selftests/lib.mk +1 -1
index fe7ee2b0f29c..a40add31a2e3 100644
@@ -141,7 +141,7 @@ endif
 # Selftest makefiles can override those targets by setting
 # OVERRIDE_TARGETS = 1.
 ifeq ($(OVERRIDE_TARGETS),)
-LOCAL_HDRS := $(selfdir)/kselftest_harness.h $(selfdir)/kselftest.h
+LOCAL_HDRS += $(selfdir)/kselftest_harness.h $(selfdir)/kselftest.h
 $(OUTPUT)/%:%.c $(LOCAL_HDRS)
 	$(LINK.c) $(filter-out $(LOCAL_HDRS),$^) $(LDLIBS) -o $@
 
Signature · 1 line
2.33.0
#1 lore raw

PATCH 2/2 selftests: cgroup: use function 'labs()' over 'abs()'

When building selftests/cgroup with clang, the compiler warn about the function abs() see below:

In file included from test_memcontrol.c:21:
./cgroup_util.h:16:9: warning: absolute value function 'abs' given an argument of type 'long' but has parameter of type 'int' which may cause truncation of value [-Wabsolute-value]

        return abs(a - b) <= (a + b) / 100 * err;
               ^
./cgroup_util.h:16:9: note: use function 'labs' instead
        return abs(a - b) <= (a + b) / 100 * err;
               ^~~
               labs

The note indicates what to do, Rework to use the function 'labs()'.

---
 tools/testing/selftests/cgroup/cgroup_util.h | 2 +-
 tools/testing/selftests/cgroup/test_kmem.c   | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/cgroup/cgroup_util.h +1 -1
index 82e59cdf16e7..76b35d9dffb5 100644
@@ -13,7 +13,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);
tools/testing/selftests/cgroup/test_kmem.c +2 -2
index 22b31ebb3513..d65bb8fe876a 100644
@@ -192,7 +192,7 @@ static int test_kmem_memcg_deletion(const char *root)
 		goto cleanup;
 
 	sum = slab + anon + file + kernel_stack + pagetables + percpu + 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);
@@ -383,7 +383,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
Signature · 1 line
2.33.0
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] selftests: cgroup: use function 'labs()' over 'abs()'

Quoted 13 lines · Anders Roxell

When building selftests/cgroup with clang, the compiler warn about the function abs() see below:

In file included from test_memcontrol.c:21:
./cgroup_util.h:16:9: warning: absolute value function 'abs' given an argument of type 'long' but has parameter of type 'int' which may cause truncation of value [-Wabsolute-value]

        return abs(a - b) <= (a + b) / 100 * err;
               ^
./cgroup_util.h:16:9: note: use function 'labs' instead
        return abs(a - b) <= (a + b) / 100 * err;
               ^~~
               labs
Quoted 3 lines

The note indicates what to do, Rework to use the function 'labs()'.

Thanks for the patch!

Quoted 43 lines
---
 tools/testing/selftests/cgroup/cgroup_util.h | 2 +-
 tools/testing/selftests/cgroup/test_kmem.c   | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/cgroup/cgroup_util.h +1 -1
index 82e59cdf16e7..76b35d9dffb5 100644
@@ -13,7 +13,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);
tools/testing/selftests/cgroup/test_kmem.c +2 -3
index 22b31ebb3513..d65bb8fe876a 100644
@@ -192,7 +192,7 @@ static int test_kmem_memcg_deletion(const char *root)
                goto cleanup;
 
        sum = slab + anon + file + kernel_stack + pagetables + percpu + 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);
@@ -383,7 +383,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
--

2.33.0

Signature · 2 lines
Thanks,
~Nick Desaulniers
Acked-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] selftests: cgroup: use function 'labs()' over 'abs()'

In reply to Anders Roxell
Quoted 12 lines · Anders Roxell

When building selftests/cgroup with clang, the compiler warn about the function abs() see below:

In file included from test_memcontrol.c:21:
./cgroup_util.h:16:9: warning: absolute value function 'abs' given an argument of type 'long' but has parameter of type 'int' which may cause truncation of value [-Wabsolute-value]

        return abs(a - b) <= (a + b) / 100 * err;
               ^
./cgroup_util.h:16:9: note: use function 'labs' instead
        return abs(a - b) <= (a + b) / 100 * err;
               ^~~
               labs
Quoted 4 lines

The note indicates what to do, Rework to use the function 'labs()'.

---

Thanks!

#4 lore raw
In reply to Anders Roxell
Quoted 2 lines · Anders Roxell

When building selftests/cgroup: with clang the following error are seen:

Thanks for the patches!

typo in subject/oneline, and the : above can be dropped.

Andrew reported similar failures throughout selftests:
https://lore.kernel.org/linux-kselftest/[email protected]/

Both patches touch the same part of tools/testing/selftests/lib.mk. This approach looks cleaner to me, but it should reconcile the changes to tools/testing/selftests/filesystems/binderfs/Makefile that Andrew made in the link above.

Quoted 54 lines

clang -Wall -pthread test_memcontrol.c cgroup_util.c ../clone3/clone3_selftests.h -o /home/anders/.cache/tuxmake/builds/current/kselftest/cgroup/test_memcontrol
clang: error: cannot specify -o when generating multiple output files
make[3]: *** [../lib.mk:146: /home/anders/.cache/tuxmake/builds/current/kselftest/cgroup/test_memcontrol] Error 1

Rework to add the header files to LOCAL_HDRS before including ../lib.mk, since the dependency is evaluated in '$(OUTPUT)/%:%.c $(LOCAL_HDRS)' in file lib.mk.

---
 tools/testing/selftests/cgroup/Makefile | 12 +++++++-----
 tools/testing/selftests/lib.mk          |  2 +-
 2 files changed, 8 insertions(+), 6 deletions(-)
tools/testing/selftests/cgroup/Makefile +7 -5
index 59e222460581..745fe25fa0b9 100644
@@ -11,10 +11,12 @@ TEST_GEN_PROGS += test_core
 TEST_GEN_PROGS += test_freezer
 TEST_GEN_PROGS += test_kill
 
+LOCAL_HDRS += $(selfdir)/clone3/clone3_selftests.h $(selfdir)/pidfd/pidfd.h
+
 include ../lib.mk
 
-$(OUTPUT)/test_memcontrol: cgroup_util.c ../clone3/clone3_selftests.h
-$(OUTPUT)/test_kmem: cgroup_util.c ../clone3/clone3_selftests.h
-$(OUTPUT)/test_core: cgroup_util.c ../clone3/clone3_selftests.h
-$(OUTPUT)/test_freezer: cgroup_util.c ../clone3/clone3_selftests.h
-$(OUTPUT)/test_kill: cgroup_util.c ../clone3/clone3_selftests.h ../pidfd/pidfd.h
+$(OUTPUT)/test_memcontrol: cgroup_util.c
+$(OUTPUT)/test_kmem: cgroup_util.c
+$(OUTPUT)/test_core: cgroup_util.c
+$(OUTPUT)/test_freezer: cgroup_util.c
+$(OUTPUT)/test_kill: cgroup_util.c
tools/testing/selftests/lib.mk +1 -2
index fe7ee2b0f29c..a40add31a2e3 100644
@@ -141,7 +141,7 @@ endif
 # Selftest makefiles can override those targets by setting
 # OVERRIDE_TARGETS = 1.
 ifeq ($(OVERRIDE_TARGETS),)
-LOCAL_HDRS := $(selfdir)/kselftest_harness.h $(selfdir)/kselftest.h
+LOCAL_HDRS += $(selfdir)/kselftest_harness.h $(selfdir)/kselftest.h
 $(OUTPUT)/%:%.c $(LOCAL_HDRS)
        $(LINK.c) $(filter-out $(LOCAL_HDRS),$^) $(LDLIBS) -o $@
 
--

2.33.0

Signature · 2 lines
Thanks,
~Nick Desaulniers
Acked-by on v1 1/2
#5 lore raw
In reply to Anders Roxell
Quoted 6 lines · Anders Roxell

When building selftests/cgroup: with clang the following error are seen:

clang -Wall -pthread test_memcontrol.c cgroup_util.c ../clone3/clone3_selftests.h -o /home/anders/.cache/tuxmake/builds/current/kselftest/cgroup/test_memcontrol
clang: error: cannot specify -o when generating multiple output files
make[3]: *** [../lib.mk:146: /home/anders/.cache/tuxmake/builds/current/kselftest/cgroup/test_memcontrol] Error 1

Quoted 7 lines

Rework to add the header files to LOCAL_HDRS before including ../lib.mk, since the dependency is evaluated in '$(OUTPUT)/%:%.c $(LOCAL_HDRS)' in file lib.mk.

---

Thanks!

maintainer
#6 lore raw
In reply to Anders Roxell
Quoted 22 lines · Anders Roxell

When building selftests/cgroup: with clang the following error are seen:

clang -Wall -pthread test_memcontrol.c cgroup_util.c ../clone3/clone3_selftests.h -o /home/anders/.cache/tuxmake/builds/current/kselftest/cgroup/test_memcontrol
clang: error: cannot specify -o when generating multiple output files
make[3]: *** [../lib.mk:146: /home/anders/.cache/tuxmake/builds/current/kselftest/cgroup/test_memcontrol] Error 1

Rework to add the header files to LOCAL_HDRS before including ../lib.mk, since the dependency is evaluated in '$(OUTPUT)/%:%.c $(LOCAL_HDRS)' in file lib.mk.

---
  tools/testing/selftests/cgroup/Makefile | 12 +++++++-----
  tools/testing/selftests/lib.mk          |  2 +-
  2 files changed, 8 insertions(+), 6 deletions(-)
tools/testing/selftests/cgroup/Makefile +0 -0
index 59e222460581..745fe25fa0b9 100644

tools/testing/selftests/cgroup/Makefile TEST_GEN_PROGS += test_core · line 15

Quoted 5 lines
tools/testing/selftests/cgroup/Makefile +2 -0
@@ -11,10 +11,12 @@ TEST_GEN_PROGS += test_core
  TEST_GEN_PROGS += test_freezer
  TEST_GEN_PROGS += test_kill
 
+LOCAL_HDRS += $(selfdir)/clone3/clone3_selftests.h $(selfdir)/pidfd/pidfd.h
+

This looks odd to me. Why are we introducing dependencies between tests? clone3 includes in cgroup? Looks odd to me.

thanks,
-- Shuah

#7 lore raw
Quoted 18 lines · Shuah Khan
Quoted 17 lines · Anders Roxell

When building selftests/cgroup: with clang the following error are seen:

clang -Wall -pthread test_memcontrol.c cgroup_util.c ../clone3/clone3_selftests.h -o /home/anders/.cache/tuxmake/builds/current/kselftest/cgroup/test_memcontrol
clang: error: cannot specify -o when generating multiple output files
make[3]: *** [../lib.mk:146: /home/anders/.cache/tuxmake/builds/current/kselftest/cgroup/test_memcontrol] Error 1

Rework to add the header files to LOCAL_HDRS before including ../lib.mk, since the dependency is evaluated in '$(OUTPUT)/%:%.c $(LOCAL_HDRS)' in file lib.mk.

---
  tools/testing/selftests/cgroup/Makefile | 12 +++++++-----
  tools/testing/selftests/lib.mk          |  2 +-
  2 files changed, 8 insertions(+), 6 deletions(-)
Quoted 12 lines

tools/testing/selftests/cgroup/Makefile TEST_GEN_PROGS += test_core · line 14

Quoted 9 lines
tools/testing/selftests/cgroup/Makefile +2 -0
index 59e222460581..745fe25fa0b9 100644
@@ -11,10 +11,12 @@ TEST_GEN_PROGS += test_core
  TEST_GEN_PROGS += test_freezer
  TEST_GEN_PROGS += test_kill
+LOCAL_HDRS += $(selfdir)/clone3/clone3_selftests.h $(selfdir)/pidfd/pidfd.h
+

This looks odd to me. Why are we introducing dependencies between tests? clone3 includes in cgroup? Looks odd to me.

The cgroup tests need access to clone3() functionality in order to test CLONE_INTO_CGROUP which is more suited to be placed alongside the cgroup tests. There are a few other tests that include the clone3 header.

maintainer
#8 lore raw
Quoted 32 lines · Christian Brauner
Quoted 18 lines · Shuah Khan
Quoted 17 lines · Anders Roxell

When building selftests/cgroup: with clang the following error are seen:

clang -Wall -pthread test_memcontrol.c cgroup_util.c ../clone3/clone3_selftests.h -o /home/anders/.cache/tuxmake/builds/current/kselftest/cgroup/test_memcontrol
clang: error: cannot specify -o when generating multiple output files
make[3]: *** [../lib.mk:146: /home/anders/.cache/tuxmake/builds/current/kselftest/cgroup/test_memcontrol] Error 1

Rework to add the header files to LOCAL_HDRS before including ../lib.mk, since the dependency is evaluated in '$(OUTPUT)/%:%.c $(LOCAL_HDRS)' in file lib.mk.

---
   tools/testing/selftests/cgroup/Makefile | 12 +++++++-----
   tools/testing/selftests/lib.mk          |  2 +-
   2 files changed, 8 insertions(+), 6 deletions(-)
Quoted 12 lines

tools/testing/selftests/cgroup/Makefile TEST_GEN_PROGS += test_core · line 14

Quoted 9 lines
tools/testing/selftests/cgroup/Makefile +2 -0
index 59e222460581..745fe25fa0b9 100644
@@ -11,10 +11,12 @@ TEST_GEN_PROGS += test_core
   TEST_GEN_PROGS += test_freezer
   TEST_GEN_PROGS += test_kill
+LOCAL_HDRS += $(selfdir)/clone3/clone3_selftests.h $(selfdir)/pidfd/pidfd.h
+

This looks odd to me. Why are we introducing dependencies between tests? clone3 includes in cgroup? Looks odd to me.

Quoted 4 lines

The cgroup tests need access to clone3() functionality in order to test CLONE_INTO_CGROUP which is more suited to be placed alongside the cgroup tests. There are a few other tests that include the clone3 header.

If other tests are also including this header, we could move it up under selftests level. Might have to add include directory.

thanks,
-- Shuah

#9 lore raw
Quoted 33 lines · Shuah Khan
Quoted 32 lines · Christian Brauner
Quoted 30 lines · Shuah Khan
Quoted 22 lines · Anders Roxell

When building selftests/cgroup: with clang the following error are seen:

clang -Wall -pthread test_memcontrol.c cgroup_util.c ../clone3/clone3_selftests.h -o /home/anders/.cache/tuxmake/builds/current/kselftest/cgroup/test_memcontrol
clang: error: cannot specify -o when generating multiple output files
make[3]: *** [../lib.mk:146: /home/anders/.cache/tuxmake/builds/current/kselftest/cgroup/test_memcontrol] Error 1

Rework to add the header files to LOCAL_HDRS before including ../lib.mk, since the dependency is evaluated in '$(OUTPUT)/%:%.c $(LOCAL_HDRS)' in file lib.mk.

---
   tools/testing/selftests/cgroup/Makefile | 12 +++++++-----
   tools/testing/selftests/lib.mk          |  2 +-
   2 files changed, 8 insertions(+), 6 deletions(-)
tools/testing/selftests/cgroup/Makefile +0 -0
index 59e222460581..745fe25fa0b9 100644

tools/testing/selftests/cgroup/Makefile TEST_GEN_PROGS += test_core · line 14

Quoted 4 lines
tools/testing/selftests/cgroup/Makefile +2 -0
@@ -11,10 +11,12 @@ TEST_GEN_PROGS += test_core
   TEST_GEN_PROGS += test_freezer
   TEST_GEN_PROGS += test_kill
+LOCAL_HDRS += $(selfdir)/clone3/clone3_selftests.h $(selfdir)/pidfd/pidfd.h
+

This looks odd to me. Why are we introducing dependencies between tests? clone3 includes in cgroup? Looks odd to me.

Quoted 7 lines
Quoted 4 lines

The cgroup tests need access to clone3() functionality in order to test CLONE_INTO_CGROUP which is more suited to be placed alongside the cgroup tests. There are a few other tests that include the clone3 header.

If other tests are also including this header, we could move it up under selftests level. Might have to add include directory.

No objection from me if that's useful. I won't have time for that in the near future. (This might be of interest for one of the LF programs that help get new folks interested in kernel development started.)

Christian

maintainer
#10 lore raw
Quoted 39 lines · Christian Brauner
Quoted 38 lines · Shuah Khan
Quoted 36 lines · Christian Brauner
Quoted 18 lines · Shuah Khan
Quoted 17 lines · Anders Roxell

When building selftests/cgroup: with clang the following error are seen:

clang -Wall -pthread test_memcontrol.c cgroup_util.c ../clone3/clone3_selftests.h -o /home/anders/.cache/tuxmake/builds/current/kselftest/cgroup/test_memcontrol
clang: error: cannot specify -o when generating multiple output files
make[3]: *** [../lib.mk:146: /home/anders/.cache/tuxmake/builds/current/kselftest/cgroup/test_memcontrol] Error 1

Rework to add the header files to LOCAL_HDRS before including ../lib.mk, since the dependency is evaluated in '$(OUTPUT)/%:%.c $(LOCAL_HDRS)' in file lib.mk.

---
    tools/testing/selftests/cgroup/Makefile | 12 +++++++-----
    tools/testing/selftests/lib.mk          |  2 +-
    2 files changed, 8 insertions(+), 6 deletions(-)
Quoted 12 lines

tools/testing/selftests/cgroup/Makefile TEST_GEN_PROGS += test_core · line 14

Quoted 9 lines
tools/testing/selftests/cgroup/Makefile +2 -0
index 59e222460581..745fe25fa0b9 100644
@@ -11,10 +11,12 @@ TEST_GEN_PROGS += test_core
    TEST_GEN_PROGS += test_freezer
    TEST_GEN_PROGS += test_kill
+LOCAL_HDRS += $(selfdir)/clone3/clone3_selftests.h $(selfdir)/pidfd/pidfd.h
+

This looks odd to me. Why are we introducing dependencies between tests? clone3 includes in cgroup? Looks odd to me.

The cgroup tests need access to clone3() functionality in order to test CLONE_INTO_CGROUP which is more suited to be placed alongside the cgroup tests. There are a few other tests that include the clone3 header.

Quoted 9 lines
Quoted 2 lines

If other tests are also including this header, we could move it up under selftests level. Might have to add include directory.

No objection from me if that's useful. I won't have time for that in the near future. (This might be of interest for one of the LF programs that help get new folks interested in kernel development started.)

Christian

Thanks. I will apply this fix for now.

thanks,
-- Shuah