tests: check expression parsing

* tests/filtering_action-syntax.test: New file.
* tests/filtering_expression-empty.test: Likewise.
* tests/filtering_expression-syntax.test: Likewise.
* tests/Makefile.am (MISC_TESTS): Add new files.
This commit is contained in:
Nikolay Marchuk 2017-08-18 16:24:20 +07:00 committed by Dmitry V. Levin
parent 39ece647b0
commit fe9e13c311
4 changed files with 222 additions and 0 deletions

View File

@ -303,6 +303,9 @@ MISC_TESTS = \
detach-sleeping.test \
detach-stopped.test \
filter-unavailable.test \
filtering_action-syntax.test \
filtering_expression-empty.test \
filtering_expression-syntax.test \
filtering_fd-syntax.test \
filtering_syscall-syntax.test \
fflush.test \

View File

@ -0,0 +1,95 @@
#!/bin/sh
#
# Check common action syntax.
#
# Copyright (c) 2017 Nikolay Marchuk <marchuk.nikolay.a@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. "${srcdir=.}/syntax.sh"
for arg in '' ' ' ' '\
not \
not_action \
notAction \
notaction \
; do
check_e "invalid filter action '$arg'" -e "$arg=open"
done
for arg in '' ' ' ' '; do
check_e "invalid filter action 'not_action'" -e "$arg"not_action=
check_e "invalid filter action 'not_action'" -e "$arg"not_action\(\)
done
for arg in not_action \
notAction \
notaction \
and "&&" \
or "||" \
; do
check_e "invalid filter action '$arg'" -e "$arg(syscall open)"
done
check_e "invalid arguments position ';':0" -e \;
check_e "invalid arguments position 'not(syscall open;)':16" -e "not(syscall open;)"
check_e "invalid arguments position 'trace((syscall open;arg))':19" \
-e "trace((syscall open;arg))"
check_e "missing ')' in 'not (syscall open'" -e "not (syscall open"
check_e "missing ')' in 'not (syscall open\)'" -e "not (syscall open\)"
check_e "missing ')' in 'trace(syscall open'" -e "trace(syscall open"
check_e "missing ')' in 'trace(syscall open;args'" -e "trace(syscall open;args"
check_e "missing ')' in 'trace(syscall open;args\)'" -e "trace(syscall open;args\)"
check_e "unexpected ')' at '! syscall open)':14" -e "! syscall open)"
check_e "unexpected ')' at '!(syscall open))':15" -e "!(syscall open))"
check_e "unexpected ')' at 'trace(syscall open))':19" -e "trace(syscall open))"
check_e "unexpected ';' at 'trace(syscall open;arg);':23" -e "trace(syscall open;arg);"
check_e "unexpected '&' at 'trace(syscall open)&':19" -e "trace(syscall open)&"
check_e "unexpected '&' at 'trace(syscall open) &':20" -e "trace(syscall open) &"
for arg in trace \
read \
write \
raw \
abbrev \
verbose \
; do
cat > "$EXP" << __EOF__
$STRACE_EXE: $arg action takes no arguments, ignored arguments 'no_args'
$STRACE_EXE: must have PROG [ARGS] or -p PID
Try '$STRACE_EXE -h' for more information.
__EOF__
check_exit_status_and_stderr -e $arg=none:no_args
check_exit_status_and_stderr -e "$arg(syscall none;no_args)"
done
cat > "$EXP" << __EOF__
$STRACE_EXE: signal action takes no arguments, ignored arguments 'no_args'
$STRACE_EXE: must have PROG [ARGS] or -p PID
Try '$STRACE_EXE -h' for more information.
__EOF__
check_exit_status_and_stderr -e signal=none:no_args

View File

@ -0,0 +1,47 @@
#!/bin/sh
#
# Check simple filter-based expressions.
#
# Copyright (c) 2017 Nikolay Marchuk <marchuk.nikolay.a@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. "${srcdir=.}/syntax.sh"
echo "+++ exited with 0 +++" > "$EXP"
for arg in "syscall none" \
"not syscall all" \
"syscall all and not syscall all" \
"syscall all and not syscall all or syscall none" \
"(syscall all and not syscall all) or syscall none" \
"not syscall all and (syscall all or syscall none)" \
"not syscall all and (syscall all or syscall chdir)" \
"syscall none and not syscall all" \
"syscall none or not syscall all" \
; do
run_strace -e "$arg" true
match_diff "$LOG" "$EXP"
run_strace -e "trace($arg)" true
match_diff "$LOG" "$EXP"
done

View File

@ -0,0 +1,77 @@
#!/bin/sh
#
# Check filter-based expression syntax.
#
# Copyright (c) 2017 Nikolay Marchuk <marchuk.nikolay.a@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. "${srcdir=.}/syntax.sh"
check_expression()
{
for action in trace \
inject \
fault \
read \
write \
raw \
abbrev \
verbose \
; do
check_e "$1" -e "$action($2)"
done
}
check_expression "invalid operator at 'or (syscall open)':1" "or (syscall open)"
check_expression "invalid operator at '||(syscall open)':1" "||(syscall open)"
check_expression "invalid operator at 'and (syscall open)':2" "and (syscall open)"
check_expression "invalid operator at '&&(syscall open)':1" "&&(syscall open)"
check_expression "invalid operator at 'syscall open not syscall close':12" \
"syscall open not syscall close"
check_expression "invalid operator at 'syscall open ! syscall close':10" \
"syscall open ! syscall close"
for arg in notsyscall \
not_syscall \
notSyscall \
invalid \
; do
check_expression "invalid filter '$arg'" "$arg open"
check_expression "invalid filter '$arg'" "syscall open and $arg open"
check_expression "invalid filter '$arg'" "syscall open or $arg open"
done
check_expression "invalid filter 'not_'" "not_ syscall open"
for arg in "syscall " \
"(syscall)" \
"syscall open or" \
"syscall open or not" \
"syscall open or syscall" \
; do
check_expression "unfinished filter expression '$arg'" "$arg"
done
check_expression "stack overflow (expression is too complex)" \
"(((((((((((((((((((((((((((((((((syscall open)))))))))))))))))))))))))))))))))"