[PATCH v9 09/15] tests: check expression parsing

Nikolay Marchuk marchuk.nikolay.a at gmail.com
Thu Aug 24 11:19:47 UTC 2017


* 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.
---
 tests/Makefile.am                      |  3 ++
 tests/filtering_action-syntax.test     | 95 ++++++++++++++++++++++++++++++++++
 tests/filtering_expression-empty.test  | 47 +++++++++++++++++
 tests/filtering_expression-syntax.test | 77 +++++++++++++++++++++++++++
 4 files changed, 222 insertions(+)
 create mode 100755 tests/filtering_action-syntax.test
 create mode 100755 tests/filtering_expression-empty.test
 create mode 100755 tests/filtering_expression-syntax.test

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8b25625d..3d822541 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -257,6 +257,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_syscall-syntax.test \
 	fflush.test \
 	get_regs.test \
diff --git a/tests/filtering_action-syntax.test b/tests/filtering_action-syntax.test
new file mode 100755
index 00000000..01b7c9b1
--- /dev/null
+++ b/tests/filtering_action-syntax.test
@@ -0,0 +1,95 @@
+#!/bin/sh
+#
+# Check common action syntax.
+#
+# Copyright (c) 2017 Nikolay Marchuk <marchuk.nikolay.a at 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_exp: $arg action takes no arguments, ignored arguments 'no_args'
+$strace_exp: must have PROG [ARGS] or -p PID
+Try '$strace_exp -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_exp: signal action takes no arguments, ignored arguments 'no_args'
+$strace_exp: must have PROG [ARGS] or -p PID
+Try '$strace_exp -h' for more information.
+__EOF__
+check_exit_status_and_stderr -e signal=none:no_args
diff --git a/tests/filtering_expression-empty.test b/tests/filtering_expression-empty.test
new file mode 100755
index 00000000..26edbfcf
--- /dev/null
+++ b/tests/filtering_expression-empty.test
@@ -0,0 +1,47 @@
+#!/bin/sh
+#
+# Check simple filter-based expressions.
+#
+# Copyright (c) 2017 Nikolay Marchuk <marchuk.nikolay.a at 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
diff --git a/tests/filtering_expression-syntax.test b/tests/filtering_expression-syntax.test
new file mode 100755
index 00000000..f3da49a5
--- /dev/null
+++ b/tests/filtering_expression-syntax.test
@@ -0,0 +1,77 @@
+#!/bin/sh
+#
+# Check filter-based expression syntax.
+#
+# Copyright (c) 2017 Nikolay Marchuk <marchuk.nikolay.a at 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)))))))))))))))))))))))))))))))))"
-- 
2.11.0





More information about the Strace-devel mailing list