2017-03-28 05:37:59

by Fathi Boudra

[permalink] [raw]
Subject: [PATCH v2] selftests: gpio: fix Makefile

* Fix hardcoded and misplaced libmount headers. Use pkg-config instead to
figure out CFLAGS/LDLIBS, fixing also their value for cross-compilation.
Note: if pkg-config is missing (command not found), it will fail to
build because headers can't be found or libmount library can't be
linked.

* Fix the clean target to clean up also gpio-utils.

* Fix gpio-mockup-chardev installation by using TEST_PROGS_EXTENDED
instead of BINARIES which is not supported by the top-level lib.mk.

* Get rid of INSTALL_HDR_PATH. We don't need it since make -C is putting
us in the right location.

* Improve readibility:
- introduce GPIODIR/GPIOOBJ/GPIOINC variables
- split CFLAGS on multiple lines

Signed-off-by: Fathi Boudra <[email protected]>
---

in v2:
* per Michael Ellerman request, revert to use exported headers instead of uapi.

tools/testing/selftests/gpio/Makefile | 31 ++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/tools/testing/selftests/gpio/Makefile b/tools/testing/selftests/gpio/Makefile
index 205e4d10e085..41826897af35 100644
--- a/tools/testing/selftests/gpio/Makefile
+++ b/tools/testing/selftests/gpio/Makefile
@@ -1,23 +1,28 @@
+CFLAGS += -O2 -g -std=gnu99 -Wall
+CFLAGS += -I../../../../usr/include/
+CFLAGS += $(shell pkg-config --cflags mount)
+LDLIBS += $(shell pkg-config --libs mount)

TEST_PROGS := gpio-mockup.sh
-TEST_FILES := gpio-mockup-sysfs.sh $(BINARIES)
-BINARIES := gpio-mockup-chardev
+TEST_PROGS_EXTENDED := gpio-mockup-chardev
+TEST_FILES := gpio-mockup-sysfs.sh
+
+GPIODIR := ../../../gpio
+GPIOOBJ := gpio-utils.o
+GPIOINC := gpio.h

include ../lib.mk

-all: $(BINARIES)
+all: $(GPIOINC) $(TEST_PROGS_EXTENDED)

clean:
- $(RM) $(BINARIES)
-
-CFLAGS += -O2 -g -std=gnu99 -Wall -I../../../../usr/include/
-LDLIBS += -lmount -I/usr/include/libmount
-
-$(BINARIES): ../../../gpio/gpio-utils.o ../../../../usr/include/linux/gpio.h
+ $(RM) $(TEST_PROGS_EXTENDED)
+ $(MAKE) -C $(GPIODIR) clean

-../../../gpio/gpio-utils.o:
- make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C ../../../gpio
+$(TEST_PROGS_EXTENDED): $(GPIODIR)/$(GPIOOBJ)

-../../../../usr/include/linux/gpio.h:
- make -C ../../../.. headers_install INSTALL_HDR_PATH=$(shell pwd)/../../../../usr/
+$(GPIODIR)/$(GPIOOBJ):
+ $(MAKE) -C $(GPIODIR)

+$(GPIOINC):
+ $(MAKE) -C ../../../.. headers_install
--
2.11.0


2017-03-30 13:14:42

by Bamvor Zhang Jian

[permalink] [raw]
Subject: Re: [PATCH v2] selftests: gpio: fix Makefile

Hi, Fathi

Thanks for your patch.

On 28 March 2017 at 13:36, Fathi Boudra <[email protected]> wrote:
> * Fix hardcoded and misplaced libmount headers. Use pkg-config instead to
> figure out CFLAGS/LDLIBS, fixing also their value for cross-compilation.
> Note: if pkg-config is missing (command not found), it will fail to
> build because headers can't be found or libmount library can't be
> linked.
>
> * Fix the clean target to clean up also gpio-utils.
>
> * Fix gpio-mockup-chardev installation by using TEST_PROGS_EXTENDED
> instead of BINARIES which is not supported by the top-level lib.mk.
>
> * Get rid of INSTALL_HDR_PATH. We don't need it since make -C is putting
> us in the right location.
>
> * Improve readibility:
> - introduce GPIODIR/GPIOOBJ/GPIOINC variables
> - split CFLAGS on multiple lines
>
> Signed-off-by: Fathi Boudra <[email protected]>
> ---
>
> in v2:
> * per Michael Ellerman request, revert to use exported headers instead of uapi.
>
> tools/testing/selftests/gpio/Makefile | 31 ++++++++++++++++++-------------
> 1 file changed, 18 insertions(+), 13 deletions(-)
>
> diff --git a/tools/testing/selftests/gpio/Makefile b/tools/testing/selftests/gpio/Makefile
> index 205e4d10e085..41826897af35 100644
> --- a/tools/testing/selftests/gpio/Makefile
> +++ b/tools/testing/selftests/gpio/Makefile
> @@ -1,23 +1,28 @@
> +CFLAGS += -O2 -g -std=gnu99 -Wall
> +CFLAGS += -I../../../../usr/include/
> +CFLAGS += $(shell pkg-config --cflags mount)
> +LDLIBS += $(shell pkg-config --libs mount)
>
> TEST_PROGS := gpio-mockup.sh
> -TEST_FILES := gpio-mockup-sysfs.sh $(BINARIES)
> -BINARIES := gpio-mockup-chardev
> +TEST_PROGS_EXTENDED := gpio-mockup-chardev
> +TEST_FILES := gpio-mockup-sysfs.sh
> +
> +GPIODIR := ../../../gpio
> +GPIOOBJ := gpio-utils.o
> +GPIOINC := gpio.h
>
> include ../lib.mk
>
> -all: $(BINARIES)
> +all: $(GPIOINC) $(TEST_PROGS_EXTENDED)
All the TEST_PROGS_EXTENDED should be TEST_GEN_FILES which will output to
KBUILD_OUTPUT/O directory when it enabled.
>
> clean:
> - $(RM) $(BINARIES)
> -
> -CFLAGS += -O2 -g -std=gnu99 -Wall -I../../../../usr/include/
> -LDLIBS += -lmount -I/usr/include/libmount
> -
> -$(BINARIES): ../../../gpio/gpio-utils.o ../../../../usr/include/linux/gpio.h
> + $(RM) $(TEST_PROGS_EXTENDED)
> + $(MAKE) -C $(GPIODIR) clean
When I enable KBUILD_OUTPUT, it will affect the output directory in
tools/gpio and
output to wired directory:

$ make KBUILD_OUTPUT=$PWD/2001 -C tools/testing/selftests/ TARGETS=gpio
make: Entering directory
`/home/bamvor/works/source/kernel/linux/tools/testing/selftests'
for TARGET in gpio; do \
BUILD_TARGET=$BUILD/$TARGET; \
mkdir $BUILD_TARGET -p; \
make OUTPUT=$BUILD_TARGET -C $TARGET;\
done;
make[1]: Entering directory
`/home/bamvor/works/source/kernel/linux/tools/testing/selftests/gpio'
Makefile:19: warning: overriding commands for target `clean'
../lib.mk:55: warning: ignoring old commands for target `clean'
make -C ../../../gpio
make[2]: Entering directory `/home/bamvor/works/source/kernel/linux/tools/gpio'
mkdir -p /home/bamvor/works/source/kernel/linux/2001/gpioinclude/linux
2>&1 || true
ln -sf /home/bamvor/works/source/kernel/linux/tools/gpio/../../include/uapi/linux/gpio.h
/home/bamvor/works/source/kernel/linux/2001/gpioinclude/linux/gpio.h
make -f /home/bamvor/works/source/kernel/linux/tools/build/Makefile.build
dir=. obj=lsgpio
make[3]: Entering directory `/home/bamvor/works/source/kernel/linux/tools/gpio'
CC /home/bamvor/works/source/kernel/linux/2001/gpiolsgpio.o
CC /home/bamvor/works/source/kernel/linux/2001/gpiogpio-utils.o
LD /home/bamvor/works/source/kernel/linux/2001/gpiolsgpio-in.o

It could be fixed by building the tools/gpio manually or passing the
correct absolute path:
$(MAKE) OUTPUT=$(realpath $(GPIODIR))/ -C $(GPIODIR) clean

I looked for a bettter fix. But no progress so far. Loop Amaldo, hope could
get some input.
>
> -../../../gpio/gpio-utils.o:
> - make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C ../../../gpio
> +$(TEST_PROGS_EXTENDED): $(GPIODIR)/$(GPIOOBJ)
>
> -../../../../usr/include/linux/gpio.h:
> - make -C ../../../.. headers_install INSTALL_HDR_PATH=$(shell pwd)/../../../../usr/
> +$(GPIODIR)/$(GPIOOBJ):
> + $(MAKE) -C $(GPIODIR)
Similiar to the above clean target.

Regards

Bamvor
>
> +$(GPIOINC):
> + $(MAKE) -C ../../../.. headers_install
> --
> 2.11.0

2017-03-31 08:49:59

by Fathi Boudra

[permalink] [raw]
Subject: Re: [PATCH v2] selftests: gpio: fix Makefile

On 30 March 2017 at 16:14, Bamvor Zhang Jian
<[email protected]> wrote:
> Hi, Fathi
>
> Thanks for your patch.
>
> On 28 March 2017 at 13:36, Fathi Boudra <[email protected]> wrote:
>> * Fix hardcoded and misplaced libmount headers. Use pkg-config instead to
>> figure out CFLAGS/LDLIBS, fixing also their value for cross-compilation.
>> Note: if pkg-config is missing (command not found), it will fail to
>> build because headers can't be found or libmount library can't be
>> linked.
>>
>> * Fix the clean target to clean up also gpio-utils.
>>
>> * Fix gpio-mockup-chardev installation by using TEST_PROGS_EXTENDED
>> instead of BINARIES which is not supported by the top-level lib.mk.
>>
>> * Get rid of INSTALL_HDR_PATH. We don't need it since make -C is putting
>> us in the right location.
>>
>> * Improve readibility:
>> - introduce GPIODIR/GPIOOBJ/GPIOINC variables
>> - split CFLAGS on multiple lines
>>
>> Signed-off-by: Fathi Boudra <[email protected]>
>> ---
>>
>> in v2:
>> * per Michael Ellerman request, revert to use exported headers instead of uapi.
>>
>> tools/testing/selftests/gpio/Makefile | 31 ++++++++++++++++++-------------
>> 1 file changed, 18 insertions(+), 13 deletions(-)
>>
>> diff --git a/tools/testing/selftests/gpio/Makefile b/tools/testing/selftests/gpio/Makefile
>> index 205e4d10e085..41826897af35 100644
>> --- a/tools/testing/selftests/gpio/Makefile
>> +++ b/tools/testing/selftests/gpio/Makefile
>> @@ -1,23 +1,28 @@
>> +CFLAGS += -O2 -g -std=gnu99 -Wall
>> +CFLAGS += -I../../../../usr/include/
>> +CFLAGS += $(shell pkg-config --cflags mount)
>> +LDLIBS += $(shell pkg-config --libs mount)
>>
>> TEST_PROGS := gpio-mockup.sh
>> -TEST_FILES := gpio-mockup-sysfs.sh $(BINARIES)
>> -BINARIES := gpio-mockup-chardev
>> +TEST_PROGS_EXTENDED := gpio-mockup-chardev
>> +TEST_FILES := gpio-mockup-sysfs.sh
>> +
>> +GPIODIR := ../../../gpio
>> +GPIOOBJ := gpio-utils.o
>> +GPIOINC := gpio.h
>>
>> include ../lib.mk
>>
>> -all: $(BINARIES)
>> +all: $(GPIOINC) $(TEST_PROGS_EXTENDED)
> All the TEST_PROGS_EXTENDED should be TEST_GEN_FILES which will output to
> KBUILD_OUTPUT/O directory when it enabled.
>>
>> clean:
>> - $(RM) $(BINARIES)
>> -
>> -CFLAGS += -O2 -g -std=gnu99 -Wall -I../../../../usr/include/
>> -LDLIBS += -lmount -I/usr/include/libmount
>> -
>> -$(BINARIES): ../../../gpio/gpio-utils.o ../../../../usr/include/linux/gpio.h
>> + $(RM) $(TEST_PROGS_EXTENDED)
>> + $(MAKE) -C $(GPIODIR) clean
> When I enable KBUILD_OUTPUT, it will affect the output directory in
> tools/gpio and
> output to wired directory:
>
> $ make KBUILD_OUTPUT=$PWD/2001 -C tools/testing/selftests/ TARGETS=gpio
> make: Entering directory
> `/home/bamvor/works/source/kernel/linux/tools/testing/selftests'
> for TARGET in gpio; do \
> BUILD_TARGET=$BUILD/$TARGET; \
> mkdir $BUILD_TARGET -p; \
> make OUTPUT=$BUILD_TARGET -C $TARGET;\
> done;
> make[1]: Entering directory
> `/home/bamvor/works/source/kernel/linux/tools/testing/selftests/gpio'
> Makefile:19: warning: overriding commands for target `clean'
> ../lib.mk:55: warning: ignoring old commands for target `clean'
> make -C ../../../gpio
> make[2]: Entering directory `/home/bamvor/works/source/kernel/linux/tools/gpio'
> mkdir -p /home/bamvor/works/source/kernel/linux/2001/gpioinclude/linux
> 2>&1 || true
> ln -sf /home/bamvor/works/source/kernel/linux/tools/gpio/../../include/uapi/linux/gpio.h
> /home/bamvor/works/source/kernel/linux/2001/gpioinclude/linux/gpio.h
> make -f /home/bamvor/works/source/kernel/linux/tools/build/Makefile.build
> dir=. obj=lsgpio
> make[3]: Entering directory `/home/bamvor/works/source/kernel/linux/tools/gpio'
> CC /home/bamvor/works/source/kernel/linux/2001/gpiolsgpio.o
> CC /home/bamvor/works/source/kernel/linux/2001/gpiogpio-utils.o
> LD /home/bamvor/works/source/kernel/linux/2001/gpiolsgpio-in.o
>
> It could be fixed by building the tools/gpio manually or passing the
> correct absolute path:
> $(MAKE) OUTPUT=$(realpath $(GPIODIR))/ -C $(GPIODIR) clean
>
> I looked for a bettter fix. But no progress so far. Loop Amaldo, hope could
> get some input.

Thanks for the review. I'll see if I can come with something better.
Otherwise, I prefer passing the correct absolute path over building
tools/gpio manually.

>>
>> -../../../gpio/gpio-utils.o:
>> - make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C ../../../gpio
>> +$(TEST_PROGS_EXTENDED): $(GPIODIR)/$(GPIOOBJ)
>>
>> -../../../../usr/include/linux/gpio.h:
>> - make -C ../../../.. headers_install INSTALL_HDR_PATH=$(shell pwd)/../../../../usr/
>> +$(GPIODIR)/$(GPIOOBJ):
>> + $(MAKE) -C $(GPIODIR)
> Similiar to the above clean target.

ack, will fix in v3.

> Regards
>
> Bamvor
>>
>> +$(GPIOINC):
>> + $(MAKE) -C ../../../.. headers_install
>> --
>> 2.11.0

2017-04-12 01:37:08

by kernel test robot

[permalink] [raw]
Subject: [lkp-robot] [selftests] 066233fe32: kernel_selftests.gpio.make_fail


FYI, we noticed the following commit:

commit: 066233fe32ac62c11e5dc87bd5ebf47e4f495377 ("selftests: gpio: fix Makefile")
url: https://github.com/0day-ci/linux/commits/Fathi-Boudra/selftests-gpio-fix-Makefile/20170328-141050


in testcase: kernel_selftests
with following parameters:


test-description: The kernel contains a set of "self tests" under the tools/testing/selftests/ directory. These are intended to be small unit tests to exercise individual code paths in the kernel.
test-url: https://www.kernel.org/doc/Documentation/kselftest.txt


on test machine: qemu-system-x86_64 -enable-kvm -cpu host -smp 4 -m 5G

caused below changes (please refer to attached dmesg/kmsg for entire log/backtrace):




2017-04-07 19:37:04 make run_tests -C gpio
make: Entering directory '/usr/src/linux-selftests-x86_64-rhel-7.2-066233fe32ac62c11e5dc87bd5ebf47e4f495377/tools/testing/selftests/gpio'
Makefile:19: warning: overriding recipe for target 'clean'
../lib.mk:55: warning: ignoring old recipe for target 'clean'
make -C ../../../.. headers_install
make[1]: Entering directory '/usr/src/linux-selftests-x86_64-rhel-7.2-066233fe32ac62c11e5dc87bd5ebf47e4f495377'
make[1]: *** No rule to make target 'headers_install'. Stop.
make[1]: Leaving directory '/usr/src/linux-selftests-x86_64-rhel-7.2-066233fe32ac62c11e5dc87bd5ebf47e4f495377'
Makefile:28: recipe for target 'gpio.h' failed
make: *** [gpio.h] Error 2
make: Leaving directory '/usr/src/linux-selftests-x86_64-rhel-7.2-066233fe32ac62c11e5dc87bd5ebf47e4f495377/tools/testing/selftests/gpio'
skip ia64 test: not be default compiling/testing target



To reproduce:

git clone https://github.com/01org/lkp-tests.git
cd lkp-tests
bin/lkp qemu -k <bzImage> job-script # job-script is attached in this email



Thanks,
Xiaolong


Attachments:
(No filename) (1.76 kB)
config-4.11.0-rc3-00140-g066233f (154.34 kB)
job-script (5.12 kB)
dmesg.xz (39.53 kB)
kernel_selftests (97.52 kB)
Download all attachments