Linux-kselftest Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] selftests: more general make nesting support
@ 2020-07-28  7:32 Greg Thelen
  2020-08-05 19:36 ` Greg Thelen
  0 siblings, 1 reply; 4+ messages in thread
From: Greg Thelen @ 2020-07-28  7:32 UTC (permalink / raw)
  To: Shuah Khan; +Cc: linux-kernel, linux-kselftest, Greg Thelen

selftests can be built from the toplevel kernel makefile (e.g. make
kselftest-all) or directly (make -C tools/testing/selftests all).

The toplevel kernel makefile explicitly disables implicit rules with
"MAKEFLAGS += -rR", which is passed to tools/testing/selftests.  Some
selftest makefiles require implicit make rules, which is why
commit 67d8712dcc70 ("selftests: Fix build failures when invoked from
kselftest target") reenables implicit rules by clearing MAKEFLAGS if
MAKELEVEL=1.

So far so good.  However, if the toplevel makefile is called from an
outer makefile then MAKELEVEL will be elevated, which breaks the
MAKELEVEL equality test.
Example wrapped makefile error:
  $ cat ~/Makefile
  all:
  	$(MAKE) defconfig
  	$(MAKE) kselftest-all
  $ make -sf ~/Makefile
    futex_wait_timeout.c /src/tools/testing/selftests/kselftest_harness.h   /src/tools/testing/selftests/kselftest.h ../include/futextest.h ../include/atomic.h ../include/logging.h -lpthread -lrt -o /src/tools/testing/selftests/futex/functional/futex_wait_timeout
  make[4]: futex_wait_timeout.c: Command not found

Rather than checking $(MAKELEVEL), check for $(LINK.c), which is a more
direct side effect of "make -R".  This enables arbitrary makefile
nesting.

Signed-off-by: Greg Thelen <gthelen@google.com>
---
 tools/testing/selftests/Makefile | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 1195bd85af38..289a2e4b3f6f 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -84,10 +84,10 @@ endif
 # of the targets gets built.
 FORCE_TARGETS ?=
 
-# Clear LDFLAGS and MAKEFLAGS if called from main
-# Makefile to avoid test build failures when test
-# Makefile doesn't have explicit build rules.
-ifeq (1,$(MAKELEVEL))
+# Clear LDFLAGS and MAKEFLAGS when implicit rules are missing.  This provides
+# implicit rules to sub-test Makefiles which avoids build failures in test
+# Makefile that don't have explicit build rules.
+ifeq (,$(LINK.c))
 override LDFLAGS =
 override MAKEFLAGS =
 endif
-- 
2.28.0.rc0.142.g3c755180ce-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] selftests: more general make nesting support
  2020-07-28  7:32 [PATCH] selftests: more general make nesting support Greg Thelen
@ 2020-08-05 19:36 ` Greg Thelen
  2020-08-05 19:50   ` Shuah Khan
  0 siblings, 1 reply; 4+ messages in thread
From: Greg Thelen @ 2020-08-05 19:36 UTC (permalink / raw)
  To: Shuah Khan, skhan; +Cc: LKML, linux-kselftest

On Tue, Jul 28, 2020 at 12:32 AM Greg Thelen <gthelen@google.com> wrote:
>
> selftests can be built from the toplevel kernel makefile (e.g. make
> kselftest-all) or directly (make -C tools/testing/selftests all).
>
> The toplevel kernel makefile explicitly disables implicit rules with
> "MAKEFLAGS += -rR", which is passed to tools/testing/selftests.  Some
> selftest makefiles require implicit make rules, which is why
> commit 67d8712dcc70 ("selftests: Fix build failures when invoked from
> kselftest target") reenables implicit rules by clearing MAKEFLAGS if
> MAKELEVEL=1.
>
> So far so good.  However, if the toplevel makefile is called from an
> outer makefile then MAKELEVEL will be elevated, which breaks the
> MAKELEVEL equality test.
> Example wrapped makefile error:
>   $ cat ~/Makefile
>   all:
>         $(MAKE) defconfig
>         $(MAKE) kselftest-all
>   $ make -sf ~/Makefile
>     futex_wait_timeout.c /src/tools/testing/selftests/kselftest_harness.h   /src/tools/testing/selftests/kselftest.h ../include/futextest.h ../include/atomic.h ../include/logging.h -lpthread -lrt -o /src/tools/testing/selftests/futex/functional/futex_wait_timeout
>   make[4]: futex_wait_timeout.c: Command not found
>
> Rather than checking $(MAKELEVEL), check for $(LINK.c), which is a more
> direct side effect of "make -R".  This enables arbitrary makefile
> nesting.
>
> Signed-off-by: Greg Thelen <gthelen@google.com>
> ---
>  tools/testing/selftests/Makefile | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
> index 1195bd85af38..289a2e4b3f6f 100644
> --- a/tools/testing/selftests/Makefile
> +++ b/tools/testing/selftests/Makefile
> @@ -84,10 +84,10 @@ endif
>  # of the targets gets built.
>  FORCE_TARGETS ?=
>
> -# Clear LDFLAGS and MAKEFLAGS if called from main
> -# Makefile to avoid test build failures when test
> -# Makefile doesn't have explicit build rules.
> -ifeq (1,$(MAKELEVEL))
> +# Clear LDFLAGS and MAKEFLAGS when implicit rules are missing.  This provides
> +# implicit rules to sub-test Makefiles which avoids build failures in test
> +# Makefile that don't have explicit build rules.
> +ifeq (,$(LINK.c))
>  override LDFLAGS =
>  override MAKEFLAGS =
>  endif
> --
> 2.28.0.rc0.142.g3c755180ce-goog

Is there any feedback on this patch?  It's not high priority but something that
will help me make more use of selftests.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] selftests: more general make nesting support
  2020-08-05 19:36 ` Greg Thelen
@ 2020-08-05 19:50   ` Shuah Khan
  2020-08-05 20:40     ` Greg Thelen
  0 siblings, 1 reply; 4+ messages in thread
From: Shuah Khan @ 2020-08-05 19:50 UTC (permalink / raw)
  To: Greg Thelen, Shuah Khan; +Cc: LKML, linux-kselftest, Shuah Khan

On 8/5/20 1:36 PM, Greg Thelen wrote:
> On Tue, Jul 28, 2020 at 12:32 AM Greg Thelen <gthelen@google.com> wrote:
>>
>> selftests can be built from the toplevel kernel makefile (e.g. make
>> kselftest-all) or directly (make -C tools/testing/selftests all).
>>
>> The toplevel kernel makefile explicitly disables implicit rules with
>> "MAKEFLAGS += -rR", which is passed to tools/testing/selftests.  Some
>> selftest makefiles require implicit make rules, which is why
>> commit 67d8712dcc70 ("selftests: Fix build failures when invoked from
>> kselftest target") reenables implicit rules by clearing MAKEFLAGS if
>> MAKELEVEL=1.
>>
>> So far so good.  However, if the toplevel makefile is called from an
>> outer makefile then MAKELEVEL will be elevated, which breaks the
>> MAKELEVEL equality test.
>> Example wrapped makefile error:
>>    $ cat ~/Makefile
>>    all:
>>          $(MAKE) defconfig
>>          $(MAKE) kselftest-all
>>    $ make -sf ~/Makefile
>>      futex_wait_timeout.c /src/tools/testing/selftests/kselftest_harness.h   /src/tools/testing/selftests/kselftest.h ../include/futextest.h ../include/atomic.h ../include/logging.h -lpthread -lrt -o /src/tools/testing/selftests/futex/functional/futex_wait_timeout
>>    make[4]: futex_wait_timeout.c: Command not found
>>
>> Rather than checking $(MAKELEVEL), check for $(LINK.c), which is a more
>> direct side effect of "make -R".  This enables arbitrary makefile
>> nesting.
>>
>> Signed-off-by: Greg Thelen <gthelen@google.com>
>> ---
>>   tools/testing/selftests/Makefile | 8 ++++----
>>   1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
>> index 1195bd85af38..289a2e4b3f6f 100644
>> --- a/tools/testing/selftests/Makefile
>> +++ b/tools/testing/selftests/Makefile
>> @@ -84,10 +84,10 @@ endif
>>   # of the targets gets built.
>>   FORCE_TARGETS ?=
>>
>> -# Clear LDFLAGS and MAKEFLAGS if called from main
>> -# Makefile to avoid test build failures when test
>> -# Makefile doesn't have explicit build rules.
>> -ifeq (1,$(MAKELEVEL))
>> +# Clear LDFLAGS and MAKEFLAGS when implicit rules are missing.  This provides
>> +# implicit rules to sub-test Makefiles which avoids build failures in test
>> +# Makefile that don't have explicit build rules.
>> +ifeq (,$(LINK.c))
>>   override LDFLAGS =
>>   override MAKEFLAGS =
>>   endif
>> --
>> 2.28.0.rc0.142.g3c755180ce-goog
> 
> Is there any feedback on this patch?  It's not high priority but something that
> will help me make more use of selftests.
> 

No issues with the patch. I will apply it once the merge window ends.

thanks,
-- Shuah

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] selftests: more general make nesting support
  2020-08-05 19:50   ` Shuah Khan
@ 2020-08-05 20:40     ` Greg Thelen
  0 siblings, 0 replies; 4+ messages in thread
From: Greg Thelen @ 2020-08-05 20:40 UTC (permalink / raw)
  To: Shuah Khan, Shuah Khan; +Cc: LKML, linux-kselftest, Shuah Khan

Shuah Khan <skhan@linuxfoundation.org> wrote:

> On 8/5/20 1:36 PM, Greg Thelen wrote:
>> On Tue, Jul 28, 2020 at 12:32 AM Greg Thelen <gthelen@google.com> wrote:
>>>
>>> selftests can be built from the toplevel kernel makefile (e.g. make
>>> kselftest-all) or directly (make -C tools/testing/selftests all).
>>>
>>> The toplevel kernel makefile explicitly disables implicit rules with
>>> "MAKEFLAGS += -rR", which is passed to tools/testing/selftests.  Some
>>> selftest makefiles require implicit make rules, which is why
>>> commit 67d8712dcc70 ("selftests: Fix build failures when invoked from
>>> kselftest target") reenables implicit rules by clearing MAKEFLAGS if
>>> MAKELEVEL=1.
>>>
>>> So far so good.  However, if the toplevel makefile is called from an
>>> outer makefile then MAKELEVEL will be elevated, which breaks the
>>> MAKELEVEL equality test.
>>> Example wrapped makefile error:
>>>    $ cat ~/Makefile
>>>    all:
>>>          $(MAKE) defconfig
>>>          $(MAKE) kselftest-all
>>>    $ make -sf ~/Makefile
>>>      futex_wait_timeout.c /src/tools/testing/selftests/kselftest_harness.h   /src/tools/testing/selftests/kselftest.h ../include/futextest.h ../include/atomic.h ../include/logging.h -lpthread -lrt -o /src/tools/testing/selftests/futex/functional/futex_wait_timeout
>>>    make[4]: futex_wait_timeout.c: Command not found
>>>
>>> Rather than checking $(MAKELEVEL), check for $(LINK.c), which is a more
>>> direct side effect of "make -R".  This enables arbitrary makefile
>>> nesting.
>>>
>>> Signed-off-by: Greg Thelen <gthelen@google.com>
>>> ---
>>>   tools/testing/selftests/Makefile | 8 ++++----
>>>   1 file changed, 4 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
>>> index 1195bd85af38..289a2e4b3f6f 100644
>>> --- a/tools/testing/selftests/Makefile
>>> +++ b/tools/testing/selftests/Makefile
>>> @@ -84,10 +84,10 @@ endif
>>>   # of the targets gets built.
>>>   FORCE_TARGETS ?=
>>>
>>> -# Clear LDFLAGS and MAKEFLAGS if called from main
>>> -# Makefile to avoid test build failures when test
>>> -# Makefile doesn't have explicit build rules.
>>> -ifeq (1,$(MAKELEVEL))
>>> +# Clear LDFLAGS and MAKEFLAGS when implicit rules are missing.  This provides
>>> +# implicit rules to sub-test Makefiles which avoids build failures in test
>>> +# Makefile that don't have explicit build rules.
>>> +ifeq (,$(LINK.c))
>>>   override LDFLAGS =
>>>   override MAKEFLAGS =
>>>   endif
>>> --
>>> 2.28.0.rc0.142.g3c755180ce-goog
>> 
>> Is there any feedback on this patch?  It's not high priority but something that
>> will help me make more use of selftests.
>> 
>
> No issues with the patch. I will apply it once the merge window ends.
>
> thanks,
> -- Shuah

Great.  Thank you.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-28  7:32 [PATCH] selftests: more general make nesting support Greg Thelen
2020-08-05 19:36 ` Greg Thelen
2020-08-05 19:50   ` Shuah Khan
2020-08-05 20:40     ` Greg Thelen

Linux-kselftest Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-kselftest/0 linux-kselftest/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-kselftest linux-kselftest/ https://lore.kernel.org/linux-kselftest \
		linux-kselftest@vger.kernel.org
	public-inbox-index linux-kselftest

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kselftest


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git