mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-25 23:05:44 +01:00
Merge pull request #3905 from gilles-peskine-arm/ssl-opt-less-grep-2.16
Backport 2.16: Speed up ssl-opt.sh when running a small number of test cases
This commit is contained in:
commit
05371be430
112
tests/ssl-opt.sh
112
tests/ssl-opt.sh
@ -130,8 +130,8 @@ print_usage() {
|
|||||||
echo "Usage: $0 [options]"
|
echo "Usage: $0 [options]"
|
||||||
printf " -h|--help\tPrint this help.\n"
|
printf " -h|--help\tPrint this help.\n"
|
||||||
printf " -m|--memcheck\tCheck memory leaks and errors.\n"
|
printf " -m|--memcheck\tCheck memory leaks and errors.\n"
|
||||||
printf " -f|--filter\tOnly matching tests are executed (BRE)\n"
|
printf " -f|--filter\tOnly matching tests are executed (substring or BRE)\n"
|
||||||
printf " -e|--exclude\tMatching tests are excluded (BRE)\n"
|
printf " -e|--exclude\tMatching tests are excluded (substring or BRE)\n"
|
||||||
printf " -n|--number\tExecute only numbered test (comma-separated, e.g. '245,256')\n"
|
printf " -n|--number\tExecute only numbered test (comma-separated, e.g. '245,256')\n"
|
||||||
printf " -s|--show-numbers\tShow test numbers in front of test names\n"
|
printf " -s|--show-numbers\tShow test numbers in front of test names\n"
|
||||||
printf " -p|--preserve-logs\tPreserve logs of successful tests as well\n"
|
printf " -p|--preserve-logs\tPreserve logs of successful tests as well\n"
|
||||||
@ -184,6 +184,14 @@ get_options() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Read boolean configuration options from config.h for easy and quick
|
||||||
|
# testing. Skip non-boolean options (with something other than spaces
|
||||||
|
# and a comment after "#define SYMBOL"). The variable contains a
|
||||||
|
# space-separated list of symbols.
|
||||||
|
CONFIGS_ENABLED=" $(<"$CONFIG_H" \
|
||||||
|
sed -n 's!^ *#define *\([A-Za-z][0-9A-Z_a-z]*\) *\(/*\)*!\1!p' |
|
||||||
|
tr '\n' ' ')"
|
||||||
|
|
||||||
# Skip next test; use this macro to skip tests which are legitimate
|
# Skip next test; use this macro to skip tests which are legitimate
|
||||||
# in theory and expected to be re-introduced at some point, but
|
# in theory and expected to be re-introduced at some point, but
|
||||||
# aren't expected to succeed at the moment due to problems outside
|
# aren't expected to succeed at the moment due to problems outside
|
||||||
@ -194,16 +202,17 @@ skip_next_test() {
|
|||||||
|
|
||||||
# skip next test if the flag is not enabled in config.h
|
# skip next test if the flag is not enabled in config.h
|
||||||
requires_config_enabled() {
|
requires_config_enabled() {
|
||||||
if grep "^#define $1" $CONFIG_H > /dev/null; then :; else
|
case $CONFIGS_ENABLED in
|
||||||
SKIP_NEXT="YES"
|
*" $1 "*) :;;
|
||||||
fi
|
*) SKIP_NEXT="YES";;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# skip next test if the flag is enabled in config.h
|
# skip next test if the flag is enabled in config.h
|
||||||
requires_config_disabled() {
|
requires_config_disabled() {
|
||||||
if grep "^#define $1" $CONFIG_H > /dev/null; then
|
case $CONFIGS_ENABLED in
|
||||||
SKIP_NEXT="YES"
|
*" $1 "*) SKIP_NEXT="YES";;
|
||||||
fi
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
get_config_value_or_default() {
|
get_config_value_or_default() {
|
||||||
@ -422,17 +431,21 @@ fail() {
|
|||||||
|
|
||||||
# is_polar <cmd_line>
|
# is_polar <cmd_line>
|
||||||
is_polar() {
|
is_polar() {
|
||||||
echo "$1" | grep 'ssl_server2\|ssl_client2' > /dev/null
|
case "$1" in
|
||||||
|
*ssl_client2*) true;;
|
||||||
|
*ssl_server2*) true;;
|
||||||
|
*) false;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# openssl s_server doesn't have -www with DTLS
|
# openssl s_server doesn't have -www with DTLS
|
||||||
check_osrv_dtls() {
|
check_osrv_dtls() {
|
||||||
if echo "$SRV_CMD" | grep 's_server.*-dtls' >/dev/null; then
|
case "$SRV_CMD" in
|
||||||
NEEDS_INPUT=1
|
*s_server*-dtls*)
|
||||||
SRV_CMD="$( echo $SRV_CMD | sed s/-www// )"
|
NEEDS_INPUT=1
|
||||||
else
|
SRV_CMD="$( echo $SRV_CMD | sed s/-www// )";;
|
||||||
NEEDS_INPUT=0
|
*) NEEDS_INPUT=0;;
|
||||||
fi
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# provide input to commands that need it
|
# provide input to commands that need it
|
||||||
@ -548,11 +561,10 @@ wait_client_done() {
|
|||||||
|
|
||||||
# check if the given command uses dtls and sets global variable DTLS
|
# check if the given command uses dtls and sets global variable DTLS
|
||||||
detect_dtls() {
|
detect_dtls() {
|
||||||
if echo "$1" | grep 'dtls=1\|-dtls1\|-u' >/dev/null; then
|
case "$1" in
|
||||||
DTLS=1
|
*dtls=1*|-dtls|-u) DTLS=1;;
|
||||||
else
|
*) DTLS=0;;
|
||||||
DTLS=0
|
esac
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Usage: run_test name [-p proxy_cmd] srv_cmd cli_cmd cli_exit [option [...]]
|
# Usage: run_test name [-p proxy_cmd] srv_cmd cli_cmd cli_exit [option [...]]
|
||||||
@ -568,8 +580,7 @@ run_test() {
|
|||||||
NAME="$1"
|
NAME="$1"
|
||||||
shift 1
|
shift 1
|
||||||
|
|
||||||
if echo "$NAME" | grep "$FILTER" | grep -v "$EXCLUDE" >/dev/null; then :
|
if is_excluded "$NAME"; then
|
||||||
else
|
|
||||||
SKIP_NEXT="NO"
|
SKIP_NEXT="NO"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
@ -577,10 +588,11 @@ run_test() {
|
|||||||
print_name "$NAME"
|
print_name "$NAME"
|
||||||
|
|
||||||
# Do we only run numbered tests?
|
# Do we only run numbered tests?
|
||||||
if [ "X$RUN_TEST_NUMBER" = "X" ]; then :
|
if [ -n "$RUN_TEST_NUMBER" ]; then
|
||||||
elif echo ",$RUN_TEST_NUMBER," | grep ",$TESTS," >/dev/null; then :
|
case ",$RUN_TEST_NUMBER," in
|
||||||
else
|
*",$TESTS,"*) :;;
|
||||||
SKIP_NEXT="YES"
|
*) SKIP_NEXT="YES";;
|
||||||
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# should we skip?
|
# should we skip?
|
||||||
@ -606,10 +618,10 @@ run_test() {
|
|||||||
shift 3
|
shift 3
|
||||||
|
|
||||||
# Check if test uses files
|
# Check if test uses files
|
||||||
TEST_USES_FILES=$(echo "$SRV_CMD $CLI_CMD" | grep "\.\(key\|crt\|pem\)" )
|
case "$SRV_CMD $CLI_CMD" in
|
||||||
if [ ! -z "$TEST_USES_FILES" ]; then
|
*data_files/*)
|
||||||
requires_config_enabled MBEDTLS_FS_IO
|
requires_config_enabled MBEDTLS_FS_IO;;
|
||||||
fi
|
esac
|
||||||
|
|
||||||
# should we skip?
|
# should we skip?
|
||||||
if [ "X$SKIP_NEXT" = "XYES" ]; then
|
if [ "X$SKIP_NEXT" = "XYES" ]; then
|
||||||
@ -840,6 +852,46 @@ cleanup() {
|
|||||||
|
|
||||||
get_options "$@"
|
get_options "$@"
|
||||||
|
|
||||||
|
# Optimize filters: if $FILTER and $EXCLUDE can be expressed as shell
|
||||||
|
# patterns rather than regular expressions, use a case statement instead
|
||||||
|
# of calling grep. To keep the optimizer simple, it is incomplete and only
|
||||||
|
# detects simple cases: plain substring, everything, nothing.
|
||||||
|
#
|
||||||
|
# As an exception, the character '.' is treated as an ordinary character
|
||||||
|
# if it is the only special character in the string. This is because it's
|
||||||
|
# rare to need "any one character", but needing a literal '.' is common
|
||||||
|
# (e.g. '-f "DTLS 1.2"').
|
||||||
|
need_grep=
|
||||||
|
case "$FILTER" in
|
||||||
|
'^$') simple_filter=;;
|
||||||
|
'.*') simple_filter='*';;
|
||||||
|
*[][$+*?\\^{\|}]*) # Regexp special characters (other than .), we need grep
|
||||||
|
need_grep=1;;
|
||||||
|
*) # No regexp or shell-pattern special character
|
||||||
|
simple_filter="*$FILTER*";;
|
||||||
|
esac
|
||||||
|
case "$EXCLUDE" in
|
||||||
|
'^$') simple_exclude=;;
|
||||||
|
'.*') simple_exclude='*';;
|
||||||
|
*[][$+*?\\^{\|}]*) # Regexp special characters (other than .), we need grep
|
||||||
|
need_grep=1;;
|
||||||
|
*) # No regexp or shell-pattern special character
|
||||||
|
simple_exclude="*$EXCLUDE*";;
|
||||||
|
esac
|
||||||
|
if [ -n "$need_grep" ]; then
|
||||||
|
is_excluded () {
|
||||||
|
! echo "$1" | grep "$FILTER" | grep -q -v "$EXCLUDE"
|
||||||
|
}
|
||||||
|
else
|
||||||
|
is_excluded () {
|
||||||
|
case "$1" in
|
||||||
|
$simple_exclude) true;;
|
||||||
|
$simple_filter) false;;
|
||||||
|
*) true;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
# sanity checks, avoid an avalanche of errors
|
# sanity checks, avoid an avalanche of errors
|
||||||
P_SRV_BIN="${P_SRV%%[ ]*}"
|
P_SRV_BIN="${P_SRV%%[ ]*}"
|
||||||
P_CLI_BIN="${P_CLI%%[ ]*}"
|
P_CLI_BIN="${P_CLI%%[ ]*}"
|
||||||
|
Loading…
Reference in New Issue
Block a user