Hi, this patch enhanced the run_kselftest.sh to make the tests individually selectable. I'm not sure the if I could add the reuslt in the patch commit, as the log is too long. So I just put the result to the cover-letter:
Note: I use `tr -s "/-" "_"` to cover the path name in tests to function name. e.g. networking/timestamping -> networking_timestamping. I'm not sure if it's legal in Makefile.
Before the patch:
]# ./kselftest_install.sh /tmp/kselftests ]# cat /tmp/kselftests/run_kselftest.sh #!/bin/sh BASE_DIR=$(realpath $(dirname $0)) cd $BASE_DIR . ./kselftest/runner.sh ROOT=$PWD if [ "$1" = "--summary" ]; then logfile=$BASE_DIR/output.log cat /dev/null > $logfile fi [ -w /dev/kmsg ] && echo "kselftest: Running tests in android" >> /dev/kmsg cd android run_many \ "run.sh" cd $ROOT ...<snip>... [ -w /dev/kmsg ] && echo "kselftest: Running tests in zram" >> /dev/kmsg cd zram run_many \ "zram.sh" cd $ROOT
After the patch: ]# ./kselftest_install.sh /tmp/kselftests ]# cat /tmp/kselftests/run_kselftest.sh #!/bin/sh BASE_DIR=$(realpath $(dirname $0)) . ./kselftest/runner.sh TESTS="android ...<snip>... zram"
run_android() { [ -w /dev/kmsg ] && echo "kselftest: Running tests in android" >> /dev/kmsg cd android run_many \ "run.sh" cd $ROOT }
...<snip>...
run_zram() { [ -w /dev/kmsg ] && echo "kselftest: Running tests in zram" >> /dev/kmsg cd zram run_many \ "zram.sh" cd $ROOT }
usage() { cat <<EOF usage: ${0##*/} OPTS -s | --summary Only print summary info and put detailed log in output.log -t | --tests Test name you want to run specifically -h | --help Show this usage info EOF }
while true; do case "$1" in -s | --summary ) logfile=$BASE_DIR/output.log; cat /dev/null > $logfile; shift ;; -t | --tests ) TESTS=$2; shift 2 ;; -h | --help ) usage; exit 0;; "" ) break;; * ) usage; exit 1;; esac done
cd $BASE_DIR ROOT=$PWD for test in $TESTS; do run_$test done
Hangbin Liu (1): selftests/run_kselftest.sh: make each test individually selectable
tools/testing/selftests/Makefile | 48 +++++++++++++++++++++++++------- tools/testing/selftests/lib.mk | 2 +- 2 files changed, 39 insertions(+), 11 deletions(-)
Currently, after generating run_kselftest.sh, there is no way to choose which test we could run. All the tests are listed together and we have to run all every time. This patch enhanced the run_kselftest.sh to make the tests individually selectable.
Signed-off-by: Hangbin Liu liuhangbin@gmail.com --- tools/testing/selftests/Makefile | 48 +++++++++++++++++++++++++------- tools/testing/selftests/lib.mk | 2 +- 2 files changed, 39 insertions(+), 11 deletions(-)
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 6ec503912bea..3d4bc0071849 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -220,13 +220,9 @@ ifdef INSTALL_PATH @# Ask all targets to emit their test scripts echo "#!/bin/sh" > $(ALL_SCRIPT) echo "BASE_DIR=$$(realpath $$(dirname $$0))" >> $(ALL_SCRIPT) - echo "cd $$BASE_DIR" >> $(ALL_SCRIPT) echo ". ./kselftest/runner.sh" >> $(ALL_SCRIPT) - echo "ROOT=$$PWD" >> $(ALL_SCRIPT) - echo "if [ "$$1" = "--summary" ]; then" >> $(ALL_SCRIPT) - echo " logfile=$$BASE_DIR/output.log" >> $(ALL_SCRIPT) - echo " cat /dev/null > $$logfile" >> $(ALL_SCRIPT) - echo "fi" >> $(ALL_SCRIPT) + echo "TESTS="$(TARGETS)"" | tr -s "/-" "_" >> $(ALL_SCRIPT) + echo "" >> $(ALL_SCRIPT);
@# While building run_kselftest.sh skip also non-existent TARGET dirs: @# they could be the result of a build failure and should NOT be @@ -234,15 +230,47 @@ ifdef INSTALL_PATH for TARGET in $(TARGETS); do \ BUILD_TARGET=$$BUILD/$$TARGET; \ [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \ - echo "[ -w /dev/kmsg ] && echo "kselftest: Running tests in $$TARGET" >> /dev/kmsg" >> $(ALL_SCRIPT); \ - echo "cd $$TARGET" >> $(ALL_SCRIPT); \ - echo -n "run_many" >> $(ALL_SCRIPT); \ + echo "run_$$TARGET()" | tr -s "/-" "_" >> $(ALL_SCRIPT); \ + echo "{" >> $(ALL_SCRIPT); \ + echo -e "\t[ -w /dev/kmsg ] && echo "kselftest: Running tests in $$TARGET" >> /dev/kmsg" >> $(ALL_SCRIPT); \ + echo -e "\tcd $$TARGET" >> $(ALL_SCRIPT); \ + echo -en "\trun_many" >> $(ALL_SCRIPT); \ echo -n "Emit Tests for $$TARGET\n"; \ $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \ echo "" >> $(ALL_SCRIPT); \ - echo "cd $$ROOT" >> $(ALL_SCRIPT); \ + echo -e "\tcd $$ROOT" >> $(ALL_SCRIPT); \ + echo "}" >> $(ALL_SCRIPT); \ + echo "" >> $(ALL_SCRIPT); \ done;
+ echo "usage()" >> $(ALL_SCRIPT); + echo "{" >> $(ALL_SCRIPT); + echo -e "\tcat <<EOF" >> $(ALL_SCRIPT); + echo "usage: $${0##*/} OPTS" >> $(ALL_SCRIPT); + echo -e "\t-s | --summary\t\tOnly print summary info and put detailed log in output.log" >> $(ALL_SCRIPT); + echo -e "\t-t | --tests\t\tTest name you want to run specifically" >> $(ALL_SCRIPT); + echo -e "\t-h | --help\t\tShow this usage info" >> $(ALL_SCRIPT); + echo "EOF" >> $(ALL_SCRIPT); + echo "}" >> $(ALL_SCRIPT); + echo "" >> $(ALL_SCRIPT); + + echo "while true; do" >> $(ALL_SCRIPT); + echo -e "\tcase "$$1" in" >> $(ALL_SCRIPT); + echo -e "\t-s | --summary ) logfile=$$BASE_DIR/output.log; cat /dev/null > $$logfile; shift ;;" >> $(ALL_SCRIPT); + echo -e "\t-t | --tests ) TESTS=$$2; shift 2 ;;" >> $(ALL_SCRIPT); + echo -e "\t-h | --help ) usage; exit 0;;" >> $(ALL_SCRIPT); + echo -e "\t"" ) break;;" >> $(ALL_SCRIPT); + echo -e "\t* ) usage; exit 1;;" >> $(ALL_SCRIPT); + echo -e "\tesac" >> $(ALL_SCRIPT); + echo "done" >> $(ALL_SCRIPT); + echo "" >> $(ALL_SCRIPT); + + echo "cd $$BASE_DIR" >> $(ALL_SCRIPT) + echo "ROOT=$$PWD" >> $(ALL_SCRIPT) + + echo "for test in $$TESTS; do" >> $(ALL_SCRIPT); \ + echo -e "\trun_$$test" >> $(ALL_SCRIPT); \ + echo "done" >> $(ALL_SCRIPT); \ chmod u+x $(ALL_SCRIPT) else $(error Error: set INSTALL_PATH to use install) diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk index 3ed0134a764d..c352d6dab91d 100644 --- a/tools/testing/selftests/lib.mk +++ b/tools/testing/selftests/lib.mk @@ -110,7 +110,7 @@ emit_tests: for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \ BASENAME_TEST=`basename $$TEST`; \ echo " \"; \ - echo -n " "$$BASENAME_TEST""; \ + echo -ne "\t\t"$$BASENAME_TEST""; \ done; \
# define if isn't already. It is undefined in make O= case.
Hi Hangbin,
On 3/9/20 4:12 AM, Hangbin Liu wrote:
Hi, this patch enhanced the run_kselftest.sh to make the tests individually selectable. I'm not sure the if I could add the reuslt in the patch commit, as the log is too long. So I just put the result to the cover-letter:
Note: I use `tr -s "/-" "_"` to cover the path name in tests to function name. e.g. networking/timestamping -> networking_timestamping. I'm not sure if it's legal in Makefile.
Please add this to the patch change log. Please run get_maintainers script before sending the patch. My email address you used is very old.
Please include how to run and update the documentation as well.
thanks, -- Shuah
On Fri, Mar 13, 2020 at 01:42:52PM -0600, shuah wrote:
Hi Hangbin,
On 3/9/20 4:12 AM, Hangbin Liu wrote:
Hi, this patch enhanced the run_kselftest.sh to make the tests individually selectable. I'm not sure the if I could add the reuslt in the patch commit, as the log is too long. So I just put the result to the cover-letter:
Note: I use `tr -s "/-" "_"` to cover the path name in tests to function name. e.g. networking/timestamping -> networking_timestamping. I'm not sure if it's legal in Makefile.
Please add this to the patch change log. Please run get_maintainers script before sending the patch. My email address you used is very old.
Please include how to run and update the documentation as well.
OK, I will, thanks for the feedback and sorry for the inconvenient.
Regards Hangbin
Currently, after generating run_kselftest.sh, there is no way to choose which test we could run. All the tests are listed together and we have to run all every time. This patch enhanced the run_kselftest.sh to make the tests individually selectable. e.g.
$ ./run_kselftest.sh -t "bpf size timers"
Note: I use `tr -s "/-" "_"` to cover the path name to function name in tests. e.g. networking/timestamping -> networking_timestamping.
Before the patch:
$ cat run_kselftest.sh #!/bin/sh BASE_DIR=$(realpath $(dirname $0)) cd $BASE_DIR . ./kselftest/runner.sh ROOT=$PWD if [ "$1" = "--summary" ]; then logfile=$BASE_DIR/output.log cat /dev/null > $logfile fi [ -w /dev/kmsg ] && echo "kselftest: Running tests in android" >> /dev/kmsg cd android run_many \ "run.sh" cd $ROOT ...<snip>... [ -w /dev/kmsg ] && echo "kselftest: Running tests in zram" >> /dev/kmsg cd zram run_many \ "zram.sh" cd $ROOT
After the patch: $ cat run_kselftest.sh #!/bin/sh BASE_DIR=$(realpath $(dirname $0)) . ./kselftest/runner.sh TESTS="android ...<snip>... zram"
run_android() { [ -w /dev/kmsg ] && echo "kselftest: Running tests in android" >> /dev/kmsg cd android run_many \ "run.sh" cd $ROOT }
...<snip>...
run_zram() { [ -w /dev/kmsg ] && echo "kselftest: Running tests in zram" >> /dev/kmsg cd zram run_many \ "zram.sh" cd $ROOT }
usage() { cat <<EOF usage: ${0##*/} OPTS -s | --summary Only print summary info and put detailed log in output.log -t | --tests Test name you want to run specifically -h | --help Show this usage info EOF }
while true; do case "$1" in -s | --summary ) logfile=$BASE_DIR/output.log; cat /dev/null > $logfile; shift ;; -t | --tests ) TESTS=$2; shift 2 ;; -h | --help ) usage; exit 0;; "" ) break;; * ) usage; exit 1;; esac done
cd $BASE_DIR ROOT=$PWD for test in $TESTS; do run_$test done
v2: update document and commit description.
Signed-off-by: Hangbin Liu liuhangbin@gmail.com --- Documentation/dev-tools/kselftest.rst | 4 +++ tools/testing/selftests/Makefile | 48 +++++++++++++++++++++------ tools/testing/selftests/lib.mk | 2 +- 3 files changed, 43 insertions(+), 11 deletions(-)
diff --git a/Documentation/dev-tools/kselftest.rst b/Documentation/dev-tools/kselftest.rst index 61ae13c44f91..e856713a1deb 100644 --- a/Documentation/dev-tools/kselftest.rst +++ b/Documentation/dev-tools/kselftest.rst @@ -151,6 +151,10 @@ note some tests will require root privileges:: $ cd kselftest $ ./run_kselftest.sh
+Or you can run some specific test cases in the installed Kselftests by:: + + $ ./run_kselftest.sh -t "bpf size timers" + Contributing new tests ======================
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index be22dbe94a4c..5481ea0634cf 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -212,13 +212,9 @@ ifdef INSTALL_PATH @# Ask all targets to emit their test scripts echo "#!/bin/sh" > $(ALL_SCRIPT) echo "BASE_DIR=$$(realpath $$(dirname $$0))" >> $(ALL_SCRIPT) - echo "cd $$BASE_DIR" >> $(ALL_SCRIPT) echo ". ./kselftest/runner.sh" >> $(ALL_SCRIPT) - echo "ROOT=$$PWD" >> $(ALL_SCRIPT) - echo "if [ "$$1" = "--summary" ]; then" >> $(ALL_SCRIPT) - echo " logfile=$$BASE_DIR/output.log" >> $(ALL_SCRIPT) - echo " cat /dev/null > $$logfile" >> $(ALL_SCRIPT) - echo "fi" >> $(ALL_SCRIPT) + echo "TESTS="$(TARGETS)"" | tr -s "/-" "_" >> $(ALL_SCRIPT) + echo "" >> $(ALL_SCRIPT);
@# While building run_kselftest.sh skip also non-existent TARGET dirs: @# they could be the result of a build failure and should NOT be @@ -226,15 +222,47 @@ ifdef INSTALL_PATH for TARGET in $(TARGETS); do \ BUILD_TARGET=$$BUILD/$$TARGET; \ [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \ - echo "[ -w /dev/kmsg ] && echo "kselftest: Running tests in $$TARGET" >> /dev/kmsg" >> $(ALL_SCRIPT); \ - echo "cd $$TARGET" >> $(ALL_SCRIPT); \ - echo -n "run_many" >> $(ALL_SCRIPT); \ + echo "run_$$TARGET()" | tr -s "/-" "_" >> $(ALL_SCRIPT); \ + echo "{" >> $(ALL_SCRIPT); \ + echo -e "\t[ -w /dev/kmsg ] && echo "kselftest: Running tests in $$TARGET" >> /dev/kmsg" >> $(ALL_SCRIPT); \ + echo -e "\tcd $$TARGET" >> $(ALL_SCRIPT); \ + echo -en "\trun_many" >> $(ALL_SCRIPT); \ echo -n "Emit Tests for $$TARGET\n"; \ $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \ echo "" >> $(ALL_SCRIPT); \ - echo "cd $$ROOT" >> $(ALL_SCRIPT); \ + echo -e "\tcd $$ROOT" >> $(ALL_SCRIPT); \ + echo "}" >> $(ALL_SCRIPT); \ + echo "" >> $(ALL_SCRIPT); \ done;
+ echo "usage()" >> $(ALL_SCRIPT); + echo "{" >> $(ALL_SCRIPT); + echo -e "\tcat <<EOF" >> $(ALL_SCRIPT); + echo "usage: $${0##*/} OPTS" >> $(ALL_SCRIPT); + echo -e "\t-s | --summary\t\tOnly print summary info and put detailed log in output.log" >> $(ALL_SCRIPT); + echo -e "\t-t | --tests\t\tTest name you want to run specifically" >> $(ALL_SCRIPT); + echo -e "\t-h | --help\t\tShow this usage info" >> $(ALL_SCRIPT); + echo "EOF" >> $(ALL_SCRIPT); + echo "}" >> $(ALL_SCRIPT); + echo "" >> $(ALL_SCRIPT); + + echo "while true; do" >> $(ALL_SCRIPT); + echo -e "\tcase "$$1" in" >> $(ALL_SCRIPT); + echo -e "\t-s | --summary ) logfile=$$BASE_DIR/output.log; cat /dev/null > $$logfile; shift ;;" >> $(ALL_SCRIPT); + echo -e "\t-t | --tests ) TESTS=$$2; shift 2 ;;" >> $(ALL_SCRIPT); + echo -e "\t-h | --help ) usage; exit 0;;" >> $(ALL_SCRIPT); + echo -e "\t"" ) break;;" >> $(ALL_SCRIPT); + echo -e "\t* ) usage; exit 1;;" >> $(ALL_SCRIPT); + echo -e "\tesac" >> $(ALL_SCRIPT); + echo "done" >> $(ALL_SCRIPT); + echo "" >> $(ALL_SCRIPT); + + echo "cd $$BASE_DIR" >> $(ALL_SCRIPT) + echo "ROOT=$$PWD" >> $(ALL_SCRIPT) + + echo "for test in $$TESTS; do" >> $(ALL_SCRIPT); \ + echo -e "\trun_$$test" >> $(ALL_SCRIPT); \ + echo "done" >> $(ALL_SCRIPT); \ chmod u+x $(ALL_SCRIPT) else $(error Error: set INSTALL_PATH to use install) diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk index 1c8a1963d03f..2dc5a0cca6f3 100644 --- a/tools/testing/selftests/lib.mk +++ b/tools/testing/selftests/lib.mk @@ -107,7 +107,7 @@ emit_tests: for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \ BASENAME_TEST=`basename $$TEST`; \ echo " \"; \ - echo -n " "$$BASENAME_TEST""; \ + echo -ne "\t\t"$$BASENAME_TEST""; \ done; \
# define if isn't already. It is undefined in make O= case.
Hi Shuah,
What do you think of this change? Any comments? If you are OK, I can rebase the patch and repost it.
Thanks Hangbin
On Mon, 16 Mar 2020 at 15:26, Hangbin Liu liuhangbin@gmail.com wrote:
Currently, after generating run_kselftest.sh, there is no way to choose which test we could run. All the tests are listed together and we have to run all every time. This patch enhanced the run_kselftest.sh to make the tests individually selectable. e.g.
$ ./run_kselftest.sh -t "bpf size timers"
Note: I use `tr -s "/-" "_"` to cover the path name to function name in tests. e.g. networking/timestamping -> networking_timestamping.
Before the patch:
$ cat run_kselftest.sh #!/bin/sh BASE_DIR=$(realpath $(dirname $0)) cd $BASE_DIR . ./kselftest/runner.sh ROOT=$PWD if [ "$1" = "--summary" ]; then logfile=$BASE_DIR/output.log cat /dev/null > $logfile fi [ -w /dev/kmsg ] && echo "kselftest: Running tests in android" >> /dev/kmsg cd android run_many \ "run.sh" cd $ROOT ...<snip>... [ -w /dev/kmsg ] && echo "kselftest: Running tests in zram" >> /dev/kmsg cd zram run_many \ "zram.sh" cd $ROOT
After the patch: $ cat run_kselftest.sh #!/bin/sh BASE_DIR=$(realpath $(dirname $0)) . ./kselftest/runner.sh TESTS="android ...<snip>... zram"
run_android() { [ -w /dev/kmsg ] && echo "kselftest: Running tests in android" >> /dev/kmsg cd android run_many \ "run.sh" cd $ROOT }
...<snip>...
run_zram() { [ -w /dev/kmsg ] && echo "kselftest: Running tests in zram" >> /dev/kmsg cd zram run_many \ "zram.sh" cd $ROOT }
usage() { cat <<EOF usage: ${0##*/} OPTS -s | --summary Only print summary info and put detailed log in output.log -t | --tests Test name you want to run specifically -h | --help Show this usage info EOF }
while true; do case "$1" in -s | --summary ) logfile=$BASE_DIR/output.log; cat /dev/null > $logfile; shift ;; -t | --tests ) TESTS=$2; shift 2 ;; -h | --help ) usage; exit 0;; "" ) break;; * ) usage; exit 1;; esac done
cd $BASE_DIR ROOT=$PWD for test in $TESTS; do run_$test done
v2: update document and commit description.
Signed-off-by: Hangbin Liu liuhangbin@gmail.com
Documentation/dev-tools/kselftest.rst | 4 +++ tools/testing/selftests/Makefile | 48 +++++++++++++++++++++------ tools/testing/selftests/lib.mk | 2 +- 3 files changed, 43 insertions(+), 11 deletions(-)
diff --git a/Documentation/dev-tools/kselftest.rst b/Documentation/dev-tools/kselftest.rst index 61ae13c44f91..e856713a1deb 100644 --- a/Documentation/dev-tools/kselftest.rst +++ b/Documentation/dev-tools/kselftest.rst @@ -151,6 +151,10 @@ note some tests will require root privileges:: $ cd kselftest $ ./run_kselftest.sh
+Or you can run some specific test cases in the installed Kselftests by::
- $ ./run_kselftest.sh -t "bpf size timers"
Contributing new tests
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index be22dbe94a4c..5481ea0634cf 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -212,13 +212,9 @@ ifdef INSTALL_PATH @# Ask all targets to emit their test scripts echo "#!/bin/sh" > $(ALL_SCRIPT) echo "BASE_DIR=$$(realpath $$(dirname $$0))" >> $(ALL_SCRIPT)
echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT) echo ". ./kselftest/runner.sh" >> $(ALL_SCRIPT)
echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT)
echo " logfile=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT)
echo " cat /dev/null > \$$logfile" >> $(ALL_SCRIPT)
echo "fi" >> $(ALL_SCRIPT)
echo "TESTS=\"$(TARGETS)\"" | tr -s "/-" "_" >> $(ALL_SCRIPT)
echo "" >> $(ALL_SCRIPT); @# While building run_kselftest.sh skip also non-existent TARGET dirs: @# they could be the result of a build failure and should NOT be
@@ -226,15 +222,47 @@ ifdef INSTALL_PATH for TARGET in $(TARGETS); do \ BUILD_TARGET=$$BUILD/$$TARGET; \ [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \
echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \
echo "cd $$TARGET" >> $(ALL_SCRIPT); \
echo -n "run_many" >> $(ALL_SCRIPT); \
echo "run_$$TARGET()" | tr -s "/-" "_" >> $(ALL_SCRIPT); \
echo "{" >> $(ALL_SCRIPT); \
echo -e "\t[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \
echo -e "\tcd $$TARGET" >> $(ALL_SCRIPT); \
echo -en "\trun_many" >> $(ALL_SCRIPT); \ echo -n "Emit Tests for $$TARGET\n"; \ $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \ echo "" >> $(ALL_SCRIPT); \
echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
echo -e "\tcd \$$ROOT" >> $(ALL_SCRIPT); \
echo "}" >> $(ALL_SCRIPT); \
echo "" >> $(ALL_SCRIPT); \ done;
echo "usage()" >> $(ALL_SCRIPT);
echo "{" >> $(ALL_SCRIPT);
echo -e "\tcat <<EOF" >> $(ALL_SCRIPT);
echo "usage: \$${0##*/} OPTS" >> $(ALL_SCRIPT);
echo -e "\t-s | --summary\t\tOnly print summary info and put detailed log in output.log" >> $(ALL_SCRIPT);
echo -e "\t-t | --tests\t\tTest name you want to run specifically" >> $(ALL_SCRIPT);
echo -e "\t-h | --help\t\tShow this usage info" >> $(ALL_SCRIPT);
echo "EOF" >> $(ALL_SCRIPT);
echo "}" >> $(ALL_SCRIPT);
echo "" >> $(ALL_SCRIPT);
echo "while true; do" >> $(ALL_SCRIPT);
echo -e "\tcase \"\$$1\" in" >> $(ALL_SCRIPT);
echo -e "\t-s | --summary ) logfile=\$$BASE_DIR/output.log; cat /dev/null > \$$logfile; shift ;;" >> $(ALL_SCRIPT);
echo -e "\t-t | --tests ) TESTS=\$$2; shift 2 ;;" >> $(ALL_SCRIPT);
echo -e "\t-h | --help ) usage; exit 0;;" >> $(ALL_SCRIPT);
echo -e "\t\"\" ) break;;" >> $(ALL_SCRIPT);
echo -e "\t* ) usage; exit 1;;" >> $(ALL_SCRIPT);
echo -e "\tesac" >> $(ALL_SCRIPT);
echo "done" >> $(ALL_SCRIPT);
echo "" >> $(ALL_SCRIPT);
echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT)
echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
echo "for test in \$$TESTS; do" >> $(ALL_SCRIPT); \
echo -e "\trun_\$$test" >> $(ALL_SCRIPT); \
echo "done" >> $(ALL_SCRIPT); \ chmod u+x $(ALL_SCRIPT)
else $(error Error: set INSTALL_PATH to use install) diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk index 1c8a1963d03f..2dc5a0cca6f3 100644 --- a/tools/testing/selftests/lib.mk +++ b/tools/testing/selftests/lib.mk @@ -107,7 +107,7 @@ emit_tests: for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \ BASENAME_TEST=`basename $$TEST`; \ echo " \"; \
echo -n " \"$$BASENAME_TEST\""; \
echo -ne "\t\t\"$$BASENAME_TEST\""; \ done; \
# define if isn't already. It is undefined in make O= case.
2.19.2
On 9/9/20 7:20 PM, Hangbin Liu wrote:
Hi Shuah,
What do you think of this change? Any comments? If you are OK, I can rebase the patch and repost it.
Thanks
Looks like a good addition to me. Please rebase and send the patch to everybody get_maintainers.pl recommends.
thanks, -- Shuah
Currently, after generating run_kselftest.sh, there is no way to choose which test we could run. All the tests are listed together and we have to run all every time. This patch enhanced the run_kselftest.sh to make the tests individually selectable. e.g.
$ ./run_kselftest.sh -t "bpf size timers"
Before the patch: ================
$ cat run_kselftest.sh #!/bin/sh BASE_DIR=$(realpath $(dirname $0)) cd $BASE_DIR . ./kselftest/runner.sh ROOT=$PWD if [ "$1" = "--summary" ]; then logfile=$BASE_DIR/output.log cat /dev/null > $logfile fi [ -w /dev/kmsg ] && echo "kselftest: Running tests in android" >> /dev/kmsg cd android run_many \ "run.sh" cd $ROOT ...<snip>... [ -w /dev/kmsg ] && echo "kselftest: Running tests in zram" >> /dev/kmsg cd zram run_many \ "zram.sh" cd $ROOT
After the patch: ===============
$ cat run_kselftest.sh #!/bin/sh BASE_DIR=$(realpath $(dirname $0)) . ./kselftest/runner.sh TESTS="android ...<snip>... filesystems/binderfs ...<snip>... zram"
run_android() { [ -w /dev/kmsg ] && echo "kselftest: Running tests in android" >> /dev/kmsg cd android run_many \ "run.sh" cd $ROOT }
...<snip>...
run_filesystems_binderfs() { [ -w /dev/kmsg ] && echo "kselftest: Running tests in filesystems/binderfs" >> /dev/kmsg cd filesystems/binderfs run_many \ "binderfs_test" cd $ROOT }
...<snip>...
run_zram() { [ -w /dev/kmsg ] && echo "kselftest: Running tests in zram" >> /dev/kmsg cd zram run_many \ "zram.sh" cd $ROOT }
usage() { cat <<EOF usage: ${0##*/} OPTS -s | --summary Only print summary info and put detailed log in output.log -t | --tests Test name you want to run specifically -h | --help Show this usage info EOF }
while true; do case "$1" in -s | --summary ) logfile=$BASE_DIR/output.log; cat /dev/null > $logfile; shift ;; -t | --tests ) TESTS=$2; shift 2 ;; -h | --help ) usage; exit 0;; "" ) break;; * ) usage; exit 1;; esac done
cd $BASE_DIR ROOT=$PWD for folder in $TESTS; do folder=$(echo $folder | tr -s '/-' '_') run_$folder done
Signed-off-by: Hangbin Liu liuhangbin@gmail.com
--- v3: 1) rebase the patch to latest code 2) move `tr -s "/-" "_"` to the for loop at the end so user could use test folder name directly. Before the update, user need to run ./run_kselftest.sh -t 'networking_forwarding'. Now they can just run ./run_kselftest.sh -t 'networking/forwarding' directly.
v2: update document and commit description. --- Documentation/dev-tools/kselftest.rst | 4 +++ tools/testing/selftests/Makefile | 49 +++++++++++++++++++++------ tools/testing/selftests/lib.mk | 2 +- 3 files changed, 44 insertions(+), 11 deletions(-)
diff --git a/Documentation/dev-tools/kselftest.rst b/Documentation/dev-tools/kselftest.rst index 469d115a95f1..94da633dd5f8 100644 --- a/Documentation/dev-tools/kselftest.rst +++ b/Documentation/dev-tools/kselftest.rst @@ -151,6 +151,10 @@ note some tests will require root privileges:: $ cd kselftest $ ./run_kselftest.sh
+Or you can run some specific test cases in the installed Kselftests by:: + + $ ./run_kselftest.sh -t "bpf size timers" + Packaging selftests ===================
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 15c1c1359c50..6b11d5e33019 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -225,13 +225,9 @@ ifdef INSTALL_PATH @# Ask all targets to emit their test scripts echo "#!/bin/sh" > $(ALL_SCRIPT) echo "BASE_DIR=$$(realpath $$(dirname $$0))" >> $(ALL_SCRIPT) - echo "cd $$BASE_DIR" >> $(ALL_SCRIPT) echo ". ./kselftest/runner.sh" >> $(ALL_SCRIPT) - echo "ROOT=$$PWD" >> $(ALL_SCRIPT) - echo "if [ "$$1" = "--summary" ]; then" >> $(ALL_SCRIPT) - echo " logfile=$$BASE_DIR/output.log" >> $(ALL_SCRIPT) - echo " cat /dev/null > $$logfile" >> $(ALL_SCRIPT) - echo "fi" >> $(ALL_SCRIPT) + echo "TESTS="$(TARGETS)"" >> $(ALL_SCRIPT) + echo "" >> $(ALL_SCRIPT);
@# While building run_kselftest.sh skip also non-existent TARGET dirs: @# they could be the result of a build failure and should NOT be @@ -239,15 +235,48 @@ ifdef INSTALL_PATH for TARGET in $(TARGETS); do \ BUILD_TARGET=$$BUILD/$$TARGET; \ [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \ - echo "[ -w /dev/kmsg ] && echo "kselftest: Running tests in $$TARGET" >> /dev/kmsg" >> $(ALL_SCRIPT); \ - echo "cd $$TARGET" >> $(ALL_SCRIPT); \ - echo -n "run_many" >> $(ALL_SCRIPT); \ + echo "run_$$TARGET()" | tr -s "/-" "_" >> $(ALL_SCRIPT); \ + echo "{" >> $(ALL_SCRIPT); \ + echo -e "\t[ -w /dev/kmsg ] && echo "kselftest: Running tests in $$TARGET" >> /dev/kmsg" >> $(ALL_SCRIPT); \ + echo -e "\tcd $$TARGET" >> $(ALL_SCRIPT); \ + echo -en "\trun_many" >> $(ALL_SCRIPT); \ echo -n "Emit Tests for $$TARGET\n"; \ $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \ echo "" >> $(ALL_SCRIPT); \ - echo "cd $$ROOT" >> $(ALL_SCRIPT); \ + echo -e "\tcd $$ROOT" >> $(ALL_SCRIPT); \ + echo "}" >> $(ALL_SCRIPT); \ + echo "" >> $(ALL_SCRIPT); \ done;
+ echo "usage()" >> $(ALL_SCRIPT); + echo "{" >> $(ALL_SCRIPT); + echo -e "\tcat <<EOF" >> $(ALL_SCRIPT); + echo "usage: $${0##*/} OPTS" >> $(ALL_SCRIPT); + echo -e "\t-s | --summary\t\tOnly print summary info and put detailed log in output.log" >> $(ALL_SCRIPT); + echo -e "\t-t | --tests\t\tTest name you want to run specifically" >> $(ALL_SCRIPT); + echo -e "\t-h | --help\t\tShow this usage info" >> $(ALL_SCRIPT); + echo "EOF" >> $(ALL_SCRIPT); + echo "}" >> $(ALL_SCRIPT); + echo "" >> $(ALL_SCRIPT); + + echo "while true; do" >> $(ALL_SCRIPT); + echo -e "\tcase "$$1" in" >> $(ALL_SCRIPT); + echo -e "\t-s | --summary ) logfile=$$BASE_DIR/output.log; cat /dev/null > $$logfile; shift ;;" >> $(ALL_SCRIPT); + echo -e "\t-t | --tests ) TESTS=$$2; shift 2 ;;" >> $(ALL_SCRIPT); + echo -e "\t-h | --help ) usage; exit 0;;" >> $(ALL_SCRIPT); + echo -e "\t"" ) break;;" >> $(ALL_SCRIPT); + echo -e "\t* ) usage; exit 1;;" >> $(ALL_SCRIPT); + echo -e "\tesac" >> $(ALL_SCRIPT); + echo "done" >> $(ALL_SCRIPT); + echo "" >> $(ALL_SCRIPT); + + echo "cd $$BASE_DIR" >> $(ALL_SCRIPT) + echo "ROOT=$$PWD" >> $(ALL_SCRIPT) + + echo "for folder in $$TESTS; do" >> $(ALL_SCRIPT); \ + echo -e "\tfolder=$$(echo $$folder | tr -s '/-' '_')" >> $(ALL_SCRIPT); \ + echo -e "\trun_$$folder" >> $(ALL_SCRIPT); \ + echo "done" >> $(ALL_SCRIPT); \ chmod u+x $(ALL_SCRIPT) else $(error Error: set INSTALL_PATH to use install) diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk index 51124b962d56..3c4c94a5d184 100644 --- a/tools/testing/selftests/lib.mk +++ b/tools/testing/selftests/lib.mk @@ -108,7 +108,7 @@ emit_tests: for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \ BASENAME_TEST=`basename $$TEST`; \ echo " \"; \ - echo -n " "$$BASENAME_TEST""; \ + echo -ne "\t\t"$$BASENAME_TEST""; \ done; \
# define if isn't already. It is undefined in make O= case.
Currently, after generating run_kselftest.sh, there is no way to choose which test we could run. All the tests are listed together and we have to run all every time. This patch enhanced the run_kselftest.sh to make the tests individually selectable. e.g.
$ ./run_kselftest.sh -t "bpf size timers"
Before the patch: ================
$ cat run_kselftest.sh #!/bin/sh BASE_DIR=$(realpath $(dirname $0)) cd $BASE_DIR . ./kselftest/runner.sh ROOT=$PWD if [ "$1" = "--summary" ]; then logfile=$BASE_DIR/output.log cat /dev/null > $logfile fi [ -w /dev/kmsg ] && echo "kselftest: Running tests in android" >> /dev/kmsg cd android run_many \ "run.sh" cd $ROOT ...<snip>... [ -w /dev/kmsg ] && echo "kselftest: Running tests in zram" >> /dev/kmsg cd zram run_many \ "zram.sh" cd $ROOT
After the patch: ===============
$ cat run_kselftest.sh #!/bin/sh BASE_DIR=$(realpath $(dirname $0)) . ./kselftest/runner.sh TESTS="android ...<snip>... filesystems/binderfs ...<snip>... zram"
run_android() { [ -w /dev/kmsg ] && echo "kselftest: Running tests in android" >> /dev/kmsg cd android run_many \ "run.sh" cd $ROOT }
...<snip>...
run_filesystems_binderfs() { [ -w /dev/kmsg ] && echo "kselftest: Running tests in filesystems/binderfs" >> /dev/kmsg cd filesystems/binderfs run_many \ "binderfs_test" cd $ROOT }
...<snip>...
run_zram() { [ -w /dev/kmsg ] && echo "kselftest: Running tests in zram" >> /dev/kmsg cd zram run_many \ "zram.sh" cd $ROOT }
usage() { cat <<EOF usage: ${0##*/} OPTS -s | --summary Only print summary info and put detailed log in output.log -t | --tests Test name you want to run specifically -h | --help Show this usage info EOF }
while true; do case "$1" in -s | --summary ) logfile=$BASE_DIR/output.log; cat /dev/null > $logfile; shift ;; -t | --tests ) TESTS=$2; shift 2 ;; -h | --help ) usage; exit 0;; "" ) break;; * ) usage; exit 1;; esac done
cd $BASE_DIR ROOT=$PWD for folder in $TESTS; do folder=$(echo $folder | tr -s '/-' '_') run_$folder done
Signed-off-by: Hangbin Liu liuhangbin@gmail.com
--- v4: Add parameter -l to list available tests, suggested by Bird, Tim
v3: 1) rebase the patch to latest code 2) move `tr -s "/-" "_"` in for loop at the end so user could use test folder name directly. Before the fix, user need to use ./run_kselftest.sh -t 'networking_forwarding'. Now they can just run ./run_kselftest.sh -t 'networking/forwarding' directly.
v2: update document and commit description. --- Documentation/dev-tools/kselftest.rst | 8 +++++ tools/testing/selftests/Makefile | 51 +++++++++++++++++++++------ tools/testing/selftests/lib.mk | 2 +- 3 files changed, 50 insertions(+), 11 deletions(-)
diff --git a/Documentation/dev-tools/kselftest.rst b/Documentation/dev-tools/kselftest.rst index 469d115a95f1..7b92f9c177f6 100644 --- a/Documentation/dev-tools/kselftest.rst +++ b/Documentation/dev-tools/kselftest.rst @@ -151,6 +151,14 @@ note some tests will require root privileges:: $ cd kselftest $ ./run_kselftest.sh
+Or you can run some specific test cases in the installed Kselftests by:: + + $ ./run_kselftest.sh -t "bpf size timers" + +You can view the available tests to run with:: + + $ ./run_kselftest.sh -l + Packaging selftests ===================
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 15c1c1359c50..4c8159dd2bd7 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -225,13 +225,9 @@ ifdef INSTALL_PATH @# Ask all targets to emit their test scripts echo "#!/bin/sh" > $(ALL_SCRIPT) echo "BASE_DIR=$$(realpath $$(dirname $$0))" >> $(ALL_SCRIPT) - echo "cd $$BASE_DIR" >> $(ALL_SCRIPT) echo ". ./kselftest/runner.sh" >> $(ALL_SCRIPT) - echo "ROOT=$$PWD" >> $(ALL_SCRIPT) - echo "if [ "$$1" = "--summary" ]; then" >> $(ALL_SCRIPT) - echo " logfile=$$BASE_DIR/output.log" >> $(ALL_SCRIPT) - echo " cat /dev/null > $$logfile" >> $(ALL_SCRIPT) - echo "fi" >> $(ALL_SCRIPT) + echo "TESTS="$(TARGETS)"" >> $(ALL_SCRIPT) + echo "" >> $(ALL_SCRIPT);
@# While building run_kselftest.sh skip also non-existent TARGET dirs: @# they could be the result of a build failure and should NOT be @@ -239,15 +235,50 @@ ifdef INSTALL_PATH for TARGET in $(TARGETS); do \ BUILD_TARGET=$$BUILD/$$TARGET; \ [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \ - echo "[ -w /dev/kmsg ] && echo "kselftest: Running tests in $$TARGET" >> /dev/kmsg" >> $(ALL_SCRIPT); \ - echo "cd $$TARGET" >> $(ALL_SCRIPT); \ - echo -n "run_many" >> $(ALL_SCRIPT); \ + echo "run_$$TARGET()" | tr -s "/-" "_" >> $(ALL_SCRIPT); \ + echo "{" >> $(ALL_SCRIPT); \ + echo -e "\t[ -w /dev/kmsg ] && echo "kselftest: Running tests in $$TARGET" >> /dev/kmsg" >> $(ALL_SCRIPT); \ + echo -e "\tcd $$TARGET" >> $(ALL_SCRIPT); \ + echo -en "\trun_many" >> $(ALL_SCRIPT); \ echo -n "Emit Tests for $$TARGET\n"; \ $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \ echo "" >> $(ALL_SCRIPT); \ - echo "cd $$ROOT" >> $(ALL_SCRIPT); \ + echo -e "\tcd $$ROOT" >> $(ALL_SCRIPT); \ + echo "}" >> $(ALL_SCRIPT); \ + echo "" >> $(ALL_SCRIPT); \ done;
+ echo "usage()" >> $(ALL_SCRIPT); + echo "{" >> $(ALL_SCRIPT); + echo -e "\tcat <<EOF" >> $(ALL_SCRIPT); + echo "usage: $${0##*/} OPTS" >> $(ALL_SCRIPT); + echo -e "\t-s | --summary\t\tOnly print summary info and put detailed log in output.log" >> $(ALL_SCRIPT); + echo -e "\t-t | --tests\t\tTest name you want to run specifically" >> $(ALL_SCRIPT); + echo -e "\t-l | --list\t\tList the available tests" >> $(ALL_SCRIPT); + echo -e "\t-h | --help\t\tShow this usage info" >> $(ALL_SCRIPT); + echo "EOF" >> $(ALL_SCRIPT); + echo "}" >> $(ALL_SCRIPT); + echo "" >> $(ALL_SCRIPT); + + echo "while true; do" >> $(ALL_SCRIPT); + echo -e "\tcase "$$1" in" >> $(ALL_SCRIPT); + echo -e "\t-s | --summary ) logfile=$$BASE_DIR/output.log; cat /dev/null > $$logfile; shift ;;" >> $(ALL_SCRIPT); + echo -e "\t-t | --tests ) TESTS=$$2; shift 2 ;;" >> $(ALL_SCRIPT); + echo -e "\t-l | --list ) echo $$TESTS; exit 0 ;;" >> $(ALL_SCRIPT); + echo -e "\t-h | --help ) usage; exit 0 ;;" >> $(ALL_SCRIPT); + echo -e "\t"" ) break;;" >> $(ALL_SCRIPT); + echo -e "\t* ) usage; exit 1;;" >> $(ALL_SCRIPT); + echo -e "\tesac" >> $(ALL_SCRIPT); + echo "done" >> $(ALL_SCRIPT); + echo "" >> $(ALL_SCRIPT); + + echo "cd $$BASE_DIR" >> $(ALL_SCRIPT) + echo "ROOT=$$PWD" >> $(ALL_SCRIPT) + + echo "for folder in $$TESTS; do" >> $(ALL_SCRIPT); \ + echo -e "\tfolder=$$(echo $$folder | tr -s '/-' '_')" >> $(ALL_SCRIPT); \ + echo -e "\trun_$$folder" >> $(ALL_SCRIPT); \ + echo "done" >> $(ALL_SCRIPT); \ chmod u+x $(ALL_SCRIPT) else $(error Error: set INSTALL_PATH to use install) diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk index 51124b962d56..3c4c94a5d184 100644 --- a/tools/testing/selftests/lib.mk +++ b/tools/testing/selftests/lib.mk @@ -108,7 +108,7 @@ emit_tests: for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \ BASENAME_TEST=`basename $$TEST`; \ echo " \"; \ - echo -n " "$$BASENAME_TEST""; \ + echo -ne "\t\t"$$BASENAME_TEST""; \ done; \
# define if isn't already. It is undefined in make O= case.
linux-kselftest-mirror@lists.linaro.org