* [PATCH] tools/testing: add kselftest shell helper library
@ 2020-11-23 16:25 Willem de Bruijn
2020-11-27 10:54 ` Antonio Cardace
0 siblings, 1 reply; 2+ messages in thread
From: Willem de Bruijn @ 2020-11-23 16:25 UTC (permalink / raw)
To: linux-kselftest; +Cc: netdev, kuba, acardace, shuah, Willem de Bruijn
From: Willem de Bruijn <willemb@google.com>
Kselftest expects processes to signal pass/fail/skip through exitcode.
C programs can include kselftest.h for readable definitions.
Add analogous kselftest.sh for shell tests. Extract the existing
definitions from udpgso_bench.sh.
Tested: make TARGETS=net kselftest
Link: https://patchwork.kernel.org/project/netdevbpf/patch/20201113231655.139948-4-acardace@redhat.com/
Signed-off-by: Willem de Bruijn <willemb@google.com>
---
applies cleanly to netnext (f9e425e99b07) and kselftest (v5.10-rc1)
---
tools/testing/selftests/kselftest.sh | 52 +++++++++++++++++++++
tools/testing/selftests/net/udpgso_bench.sh | 42 +----------------
2 files changed, 53 insertions(+), 41 deletions(-)
create mode 100644 tools/testing/selftests/kselftest.sh
diff --git a/tools/testing/selftests/kselftest.sh b/tools/testing/selftests/kselftest.sh
new file mode 100644
index 000000000000..c5a1cff57402
--- /dev/null
+++ b/tools/testing/selftests/kselftest.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# kselftest shell test support library
+#
+# - Define pass/fail/skip exitcodes
+# - Multiprocess support: aggregate child process results
+
+readonly KSFT_PASS=0
+readonly KSFT_FAIL=1
+readonly KSFT_SKIP=4
+
+readonly GREEN='\033[0;92m'
+readonly YELLOW='\033[0;33m'
+readonly RED='\033[0;31m'
+readonly NC='\033[0m' # No Color
+
+num_pass=0
+num_err=0
+num_skip=0
+
+# Test child process exit code, add to aggregates.
+kselftest_test_exitcode() {
+ local -r exitcode=$1
+
+ if [[ ${exitcode} -eq ${KSFT_PASS} ]]; then
+ num_pass=$(( $num_pass + 1 ))
+ elif [[ ${exitcode} -eq ${KSFT_SKIP} ]]; then
+ num_skip=$(( $num_skip + 1 ))
+ else
+ num_err=$(( $num_err + 1 ))
+ fi
+}
+
+# Exit from main process.
+kselftest_exit() {
+ echo -e "$(basename $0): PASS=${num_pass} SKIP=${num_skip} FAIL=${num_err}"
+
+ if [[ $num_err -ne 0 ]]; then
+ echo -e "$(basename $0): ${RED}FAIL${NC}"
+ exit ${KSFT_FAIL}
+ fi
+
+ if [[ $num_skip -ne 0 ]]; then
+ echo -e "$(basename $0): ${YELLOW}SKIP${NC}"
+ exit ${KSFT_SKIP}
+ fi
+
+ echo -e "$(basename $0): ${GREEN}PASS${NC}"
+ exit ${KSFT_PASS}
+}
+
diff --git a/tools/testing/selftests/net/udpgso_bench.sh b/tools/testing/selftests/net/udpgso_bench.sh
index 80b5d352702e..c1f9affe6cf0 100755
--- a/tools/testing/selftests/net/udpgso_bench.sh
+++ b/tools/testing/selftests/net/udpgso_bench.sh
@@ -3,47 +3,7 @@
#
# Run a series of udpgso benchmarks
-readonly GREEN='\033[0;92m'
-readonly YELLOW='\033[0;33m'
-readonly RED='\033[0;31m'
-readonly NC='\033[0m' # No Color
-
-readonly KSFT_PASS=0
-readonly KSFT_FAIL=1
-readonly KSFT_SKIP=4
-
-num_pass=0
-num_err=0
-num_skip=0
-
-kselftest_test_exitcode() {
- local -r exitcode=$1
-
- if [[ ${exitcode} -eq ${KSFT_PASS} ]]; then
- num_pass=$(( $num_pass + 1 ))
- elif [[ ${exitcode} -eq ${KSFT_SKIP} ]]; then
- num_skip=$(( $num_skip + 1 ))
- else
- num_err=$(( $num_err + 1 ))
- fi
-}
-
-kselftest_exit() {
- echo -e "$(basename $0): PASS=${num_pass} SKIP=${num_skip} FAIL=${num_err}"
-
- if [[ $num_err -ne 0 ]]; then
- echo -e "$(basename $0): ${RED}FAIL${NC}"
- exit ${KSFT_FAIL}
- fi
-
- if [[ $num_skip -ne 0 ]]; then
- echo -e "$(basename $0): ${YELLOW}SKIP${NC}"
- exit ${KSFT_SKIP}
- fi
-
- echo -e "$(basename $0): ${GREEN}PASS${NC}"
- exit ${KSFT_PASS}
-}
+source "$(dirname $0)/../kselftest.sh"
wake_children() {
local -r jobs="$(jobs -p)"
--
2.29.2.454.gaff20da3a2-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] tools/testing: add kselftest shell helper library
2020-11-23 16:25 [PATCH] tools/testing: add kselftest shell helper library Willem de Bruijn
@ 2020-11-27 10:54 ` Antonio Cardace
0 siblings, 0 replies; 2+ messages in thread
From: Antonio Cardace @ 2020-11-27 10:54 UTC (permalink / raw)
To: Willem de Bruijn; +Cc: linux-kselftest, netdev, kuba, shuah, Willem de Bruijn
On Mon, Nov 23, 2020 at 11:25:08AM -0500, Willem de Bruijn wrote:
> From: Willem de Bruijn <willemb@google.com>
>
> Kselftest expects processes to signal pass/fail/skip through exitcode.
>
> C programs can include kselftest.h for readable definitions.
>
> Add analogous kselftest.sh for shell tests. Extract the existing
> definitions from udpgso_bench.sh.
>
> Tested: make TARGETS=net kselftest
> Link: https://patchwork.kernel.org/project/netdevbpf/patch/20201113231655.139948-4-acardace@redhat.com/
> Signed-off-by: Willem de Bruijn <willemb@google.com>
>
> ---
>
> applies cleanly to netnext (f9e425e99b07) and kselftest (v5.10-rc1)
> ---
> tools/testing/selftests/kselftest.sh | 52 +++++++++++++++++++++
> tools/testing/selftests/net/udpgso_bench.sh | 42 +----------------
> 2 files changed, 53 insertions(+), 41 deletions(-)
> create mode 100644 tools/testing/selftests/kselftest.sh
>
> diff --git a/tools/testing/selftests/kselftest.sh b/tools/testing/selftests/kselftest.sh
> new file mode 100644
> index 000000000000..c5a1cff57402
> --- /dev/null
> +++ b/tools/testing/selftests/kselftest.sh
> @@ -0,0 +1,52 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +#
> +# kselftest shell test support library
> +#
> +# - Define pass/fail/skip exitcodes
> +# - Multiprocess support: aggregate child process results
> +
> +readonly KSFT_PASS=0
> +readonly KSFT_FAIL=1
> +readonly KSFT_SKIP=4
> +
> +readonly GREEN='\033[0;92m'
> +readonly YELLOW='\033[0;33m'
> +readonly RED='\033[0;31m'
> +readonly NC='\033[0m' # No Color
> +
> +num_pass=0
> +num_err=0
> +num_skip=0
> +
> +# Test child process exit code, add to aggregates.
> +kselftest_test_exitcode() {
> + local -r exitcode=$1
> +
> + if [[ ${exitcode} -eq ${KSFT_PASS} ]]; then
> + num_pass=$(( $num_pass + 1 ))
> + elif [[ ${exitcode} -eq ${KSFT_SKIP} ]]; then
> + num_skip=$(( $num_skip + 1 ))
> + else
> + num_err=$(( $num_err + 1 ))
> + fi
> +}
> +
> +# Exit from main process.
> +kselftest_exit() {
> + echo -e "$(basename $0): PASS=${num_pass} SKIP=${num_skip} FAIL=${num_err}"
> +
> + if [[ $num_err -ne 0 ]]; then
> + echo -e "$(basename $0): ${RED}FAIL${NC}"
> + exit ${KSFT_FAIL}
> + fi
> +
> + if [[ $num_skip -ne 0 ]]; then
> + echo -e "$(basename $0): ${YELLOW}SKIP${NC}"
> + exit ${KSFT_SKIP}
> + fi
> +
> + echo -e "$(basename $0): ${GREEN}PASS${NC}"
> + exit ${KSFT_PASS}
> +}
> +
> diff --git a/tools/testing/selftests/net/udpgso_bench.sh b/tools/testing/selftests/net/udpgso_bench.sh
> index 80b5d352702e..c1f9affe6cf0 100755
> --- a/tools/testing/selftests/net/udpgso_bench.sh
> +++ b/tools/testing/selftests/net/udpgso_bench.sh
> @@ -3,47 +3,7 @@
> #
> # Run a series of udpgso benchmarks
>
> -readonly GREEN='\033[0;92m'
> -readonly YELLOW='\033[0;33m'
> -readonly RED='\033[0;31m'
> -readonly NC='\033[0m' # No Color
> -
> -readonly KSFT_PASS=0
> -readonly KSFT_FAIL=1
> -readonly KSFT_SKIP=4
> -
> -num_pass=0
> -num_err=0
> -num_skip=0
> -
> -kselftest_test_exitcode() {
> - local -r exitcode=$1
> -
> - if [[ ${exitcode} -eq ${KSFT_PASS} ]]; then
> - num_pass=$(( $num_pass + 1 ))
> - elif [[ ${exitcode} -eq ${KSFT_SKIP} ]]; then
> - num_skip=$(( $num_skip + 1 ))
> - else
> - num_err=$(( $num_err + 1 ))
> - fi
> -}
> -
> -kselftest_exit() {
> - echo -e "$(basename $0): PASS=${num_pass} SKIP=${num_skip} FAIL=${num_err}"
> -
> - if [[ $num_err -ne 0 ]]; then
> - echo -e "$(basename $0): ${RED}FAIL${NC}"
> - exit ${KSFT_FAIL}
> - fi
> -
> - if [[ $num_skip -ne 0 ]]; then
> - echo -e "$(basename $0): ${YELLOW}SKIP${NC}"
> - exit ${KSFT_SKIP}
> - fi
> -
> - echo -e "$(basename $0): ${GREEN}PASS${NC}"
> - exit ${KSFT_PASS}
> -}
> +source "$(dirname $0)/../kselftest.sh"
>
> wake_children() {
> local -r jobs="$(jobs -p)"
> --
> 2.29.2.454.gaff20da3a2-goog
>
Reviewed-by: Antonio Cardace <acardace@redhat>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-11-27 10:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-23 16:25 [PATCH] tools/testing: add kselftest shell helper library Willem de Bruijn
2020-11-27 10:54 ` Antonio Cardace
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).