2023-02-09 08:54:58

by Guillaume Tucker

[permalink] [raw]
Subject: [PATCH v3] selftests: use printf instead of echo -ne

Rather than trying to guess which implementation of "echo" to run with
support for "-ne" options, use "printf" instead of "echo -ne". It
handles escape characters as a standard feature and it is widespread
among modern shells.

Reported-by: "kernelci.org bot" <[email protected]>
Suggested-by: David Laight <[email protected]>
Fixes: 3297a4df805d ("kselftests: Enable the echo command to print newlines in Makefile")
Fixes: 79c16b1120fe ("selftests: find echo binary to use -ne options")
Signed-off-by: Guillaume Tucker <[email protected]>
---

Notes:
v2: use printf insead of $(which echo)
v3: rebase on top of fix with $(which echo)

tools/testing/selftests/Makefile | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 9619d0f3b2ff..06578963f4f1 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -234,11 +234,10 @@ ifdef INSTALL_PATH
@# While building kselftest-list.text skip also non-existent TARGET dirs:
@# they could be the result of a build failure and should NOT be
@# included in the generated runlist.
- ECHO=`which echo`; \
for TARGET in $(TARGETS); do \
BUILD_TARGET=$$BUILD/$$TARGET; \
- [ ! -d $(INSTALL_PATH)/$$TARGET ] && $$ECHO "Skipping non-existent dir: $$TARGET" && continue; \
- $$ECHO -ne "Emit Tests for $$TARGET\n"; \
+ [ ! -d $(INSTALL_PATH)/$$TARGET ] && printf "Skipping non-existent dir: $$TARGET\n" && continue; \
+ printf "Emit Tests for $$TARGET\n"; \
$(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
-C $$TARGET emit_tests >> $(TEST_LIST); \
done;
--
2.30.2



2023-02-09 16:20:02

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v3] selftests: use printf instead of echo -ne

On Thu, Feb 9, 2023 at 12:55 AM Guillaume Tucker
<[email protected]> wrote:
>
> Rather than trying to guess which implementation of "echo" to run with
> support for "-ne" options, use "printf" instead of "echo -ne". It
> handles escape characters as a standard feature and it is widespread
> among modern shells.
>
> Reported-by: "kernelci.org bot" <[email protected]>
> Suggested-by: David Laight <[email protected]>
> Fixes: 3297a4df805d ("kselftests: Enable the echo command to print newlines in Makefile")
> Fixes: 79c16b1120fe ("selftests: find echo binary to use -ne options")
> Signed-off-by: Guillaume Tucker <[email protected]>

Reviewed-by: Guenter Roeck <[email protected]>

> ---
>
> Notes:
> v2: use printf insead of $(which echo)
> v3: rebase on top of fix with $(which echo)
>
> tools/testing/selftests/Makefile | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
> index 9619d0f3b2ff..06578963f4f1 100644
> --- a/tools/testing/selftests/Makefile
> +++ b/tools/testing/selftests/Makefile
> @@ -234,11 +234,10 @@ ifdef INSTALL_PATH
> @# While building kselftest-list.text skip also non-existent TARGET dirs:
> @# they could be the result of a build failure and should NOT be
> @# included in the generated runlist.
> - ECHO=`which echo`; \
> for TARGET in $(TARGETS); do \
> BUILD_TARGET=$$BUILD/$$TARGET; \
> - [ ! -d $(INSTALL_PATH)/$$TARGET ] && $$ECHO "Skipping non-existent dir: $$TARGET" && continue; \
> - $$ECHO -ne "Emit Tests for $$TARGET\n"; \
> + [ ! -d $(INSTALL_PATH)/$$TARGET ] && printf "Skipping non-existent dir: $$TARGET\n" && continue; \
> + printf "Emit Tests for $$TARGET\n"; \
> $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
> -C $$TARGET emit_tests >> $(TEST_LIST); \
> done;
> --
> 2.30.2
>
>

2023-02-10 01:10:25

by Shuah Khan

[permalink] [raw]
Subject: Re: [PATCH v3] selftests: use printf instead of echo -ne

On 2/9/23 09:19, Guenter Roeck wrote:
> On Thu, Feb 9, 2023 at 12:55 AM Guillaume Tucker
> <[email protected]> wrote:
>>
>> Rather than trying to guess which implementation of "echo" to run with
>> support for "-ne" options, use "printf" instead of "echo -ne". It
>> handles escape characters as a standard feature and it is widespread
>> among modern shells.
>>
>> Reported-by: "kernelci.org bot" <[email protected]>
>> Suggested-by: David Laight <[email protected]>
>> Fixes: 3297a4df805d ("kselftests: Enable the echo command to print newlines in Makefile")
>> Fixes: 79c16b1120fe ("selftests: find echo binary to use -ne options")
>> Signed-off-by: Guillaume Tucker <[email protected]>
>
> Reviewed-by: Guenter Roeck <[email protected]>
>

Thank you. Applied to linux-kselftest next for Linux 6.3-rc1.

thanks,
-- Shuah