From ff7238f4ad7eb8c8114073c2505334b59b6736d4 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 10 Jan 2019 00:05:18 +0100 Subject: [PATCH] Support wildcard patterns with a positive list of components to run Wildcard patterns now work with command line COMPONENT arguments without --except as well as with. You can now run e.g. `all.sh "check_*` to run all the sanity checks. --- tests/scripts/all.sh | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 50b3750c5..83f6cc75e 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -154,11 +154,9 @@ pre_initialize_variables () { done } -# Test whether $1 is excluded via the command line. -is_component_excluded() +# Test whether the component $1 is included in the command line patterns. +is_component_included() { - # Is $1 excluded via $COMPONENTS (a space-separated list of wildcard - # patterns)? set -f for pattern in $COMMAND_LINE_COMPONENTS; do set +f @@ -174,6 +172,13 @@ usage() Usage: $0 [OPTION]... [COMPONENT]... Run mbedtls release validation tests. By default, run all tests. With one or more COMPONENT, run only those. +COMPONENT can be the name of a component or a shell wildcard pattern. + +Examples: + $0 "check_*" + Run all sanity checks. + $0 --no-armcc --except test_memsan + Run everything except builds that require armcc and MemSan. Special options: -h|--help Print this help and exit. @@ -185,11 +190,8 @@ General options: -k|--keep-going Run all tests and report errors at the end. -m|--memory Additional optional memory tests. --armcc Run ARM Compiler builds (on by default). - --except If some components are passed on the command line, - run all the tests except for these components. In - this mode, you can pass shell wildcard patterns as - component names, e.g. "$0 --except 'test_*'" to - exclude all components that run tests. + --except Exclude the COMPONENTs listed on the command line, + instead of running only those. --no-armcc Skip ARM Compiler builds. --no-force Refuse to overwrite modified files (default). --no-keep-going Stop at the first error (default). @@ -295,7 +297,7 @@ check_tools() pre_parse_command_line () { COMMAND_LINE_COMPONENTS= - all_except= + all_except=0 no_armcc= while [ $# -gt 0 ]; do @@ -336,29 +338,26 @@ pre_parse_command_line () { shift done + # With no list of components, run everything. if [ -z "$COMMAND_LINE_COMPONENTS" ]; then all_except=1 fi # --no-armcc is a legacy option. The modern way is --except '*_armcc*'. # Ignore it if components are listed explicitly on the command line. - if [ -n "$no_armcc" ] && [ -n "$all_except" ]; then + if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*" # --no-armcc also disables yotta. COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_yotta*" fi # Build the list of components to run. - if [ -n "$all_except" ]; then - RUN_COMPONENTS= - for component in $SUPPORTED_COMPONENTS; do - if ! is_component_excluded "$component"; then - RUN_COMPONENTS="$RUN_COMPONENTS $component" - fi - done - else - RUN_COMPONENTS="$COMMAND_LINE_COMPONENTS" - fi + RUN_COMPONENTS= + for component in $SUPPORTED_COMPONENTS; do + if is_component_included "$component"; [ $? -eq $all_except ]; then + RUN_COMPONENTS="$RUN_COMPONENTS $component" + fi + done unset all_except unset no_armcc