Signed-off-by: Paul Moore <[email protected]>
---
tests/.gitignore | 1 +
tests/regression | 46 +++++++++++++++++++++++++++++++++-----------
tests/util.c | 4 ++--
tests/util.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 93 insertions(+), 14 deletions(-)
create mode 100644 tests/util.py
diff --git a/tests/.gitignore b/tests/.gitignore
index 7bc23f4..ee1cf17 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1,4 +1,5 @@
*.bpf
+util.pyc
01-allow
02-basic
03-basic-chains
diff --git a/tests/regression b/tests/regression
index 41205de..5aa861e 100755
--- a/tests/regression
+++ b/tests/regression
@@ -43,12 +43,13 @@ function verify_deps() {
#
function usage() {
cat << EOF
-usage: regression [-h] [-a] [-b BATCH_NAME] [-g] [-l [LOG]]
+usage: regression [-h] [-m MODE] [-a] [-b BATCH_NAME] [-g] [-l [LOG]]
[-s SINGLE_TEST] [-t [TEMP_DIR]] [-v]
libseccomp regression test automation script
optional arguments:
-h show this help message and exit
+ -m MODE specified the test mode [c (default), python]
-a specifies all tests are to be run
-b BATCH_NAME specifies batch of tests to be run
-g specifies that tests are to be run with valgrind
@@ -148,7 +149,8 @@ function get_range() {
#
# Arguments:
# 1 string containing generated test number
-# 2 string containing command to run
+# 2 string containing command name
+# 3 string containing command options and redirects
#
function run_test_command() {
local cmd
@@ -156,19 +158,23 @@ function run_test_command() {
if $use_valgrind && $verbose; then
print_valgrind $1
if [[ $logfd -eq 3 ]]; then
- cmd="/usr/bin/valgrind --log-fd=$logfd ./$2"
+ cmd="/usr/bin/valgrind --log-fd=$logfd ./$2 $3"
else
- cmd="/usr/bin/valgrind ./$2"
+ cmd="/usr/bin/valgrind ./$2 $3"
fi
elif $use_valgrind; then
# With -q, valgrind will only print error messages
if [[ $logfd -eq 3 ]]; then
- cmd="/usr/bin/valgrind -q --log-fd=$logfd ./$2"
+ cmd="/usr/bin/valgrind -q --log-fd=$logfd ./$2 $3"
else
- cmd="/usr/bin/valgrind -q ./$2"
+ cmd="/usr/bin/valgrind -q ./$2 $3"
fi
+ elif [[ $mode == "python" ]]; then
+ cmd="PYTHONPATH=$PYTHONPATH"
+ cmd="$cmd:$(cd $(pwd)/../src/python/build/lib.*; pwd)"
+ cmd="$cmd /usr/bin/env python ./$2.py $3"
else
- cmd="./$2"
+ cmd="./$2 $3"
fi
#Run the command
@@ -277,7 +283,7 @@ function run_test_bpf_sim_fuzz() {
done
# Run the test command and put the BPF filter in a temp file
- run_test_command "$testnumstr" "$testname -b > $tmpfile"
+ run_test_command "$testnumstr" "$testname" "-b > $tmpfile"
if [[ $? -ne 0 ]]; then
print_result $testnumstr "ERROR" "$testname rc=$?"
stats_error=$(($stats_error+1))
@@ -471,7 +477,7 @@ function run_test_bpf_sim() {
done
# Run the test command and put the BPF filter in a temp file
- run_test_command "$testnumstr" "$testname -b > $tmpfile"
+ run_test_command "$testnumstr" "$testname" "-b > $tmpfile"
if [[ $? -ne 0 ]]; then
print_result $testnumstr "ERROR" "$testname rc=$?"
stats_error=$(($stats_error+1))
@@ -521,7 +527,7 @@ function run_test_basic() {
print_data "$1" "$2"
# Run the command
- run_test_command "$1" "$2"
+ run_test_command "$1" "$2" ""
if [[ $? -ne 0 ]]; then
print_result $1 "FAILURE" "$2 rc=$?"
stats_failure=$(($stats_failure+1))
@@ -586,6 +592,8 @@ function run_tests() {
# Print batch name to log file
echo " batch name: $batch_name" >&$logfd
+ # Print test mode to log file
+ echo " test mode: $mode" >&$logfd
# Loop through each line of the file and run the requested tests
while read line; do
@@ -601,7 +609,7 @@ function run_tests() {
test_type=`echo "$line" |
sed -e 's/^test type: //;'`
# Print test type to log file
- echo " test type: $test_type" >&$logfd
+ echo " test type: $test_type" >&$logfd
continue
elif [[ ${single_list[@]} ]]; then
for i in ${single_list[@]}; do
@@ -637,6 +645,7 @@ arch=
batch_count=0
logfile=
logfd=
+mode=c
runall=false
singlecount=0
tmpfile=""
@@ -649,7 +658,7 @@ stats_success=0
stats_failure=0
stats_error=0
-while getopts "ab:gl:s:t:vh" opt; do
+while getopts "ab:gl:m:s:t:vh" opt; do
case $opt in
a)
runall=true
@@ -665,6 +674,19 @@ while getopts "ab:gl:s:t:vh" opt; do
l)
logfile="$OPTARG"
;;
+ m)
+ case $OPTARG in
+ c)
+ mode=c
+ ;;
+ python)
+ mode=python
+ ;;
+ *)
+ usage
+ exit 1
+ esac
+ ;;
s)
single_list[single_count]=$OPTARG
single_count=$(($single_count+1))
diff --git a/tests/util.c b/tests/util.c
index d4dc1ff..ce507fa 100644
--- a/tests/util.c
+++ b/tests/util.c
@@ -88,8 +88,8 @@ int util_getopt(int argc, char *argv[], struct util_options
*opts)
* @param opts the options structure
* @param ctx the filter context
*
- * This function outputs the seccomp filter to in either BPF or PFC format
- * depending on the test paramaeters supplied by @opts.
+ * This function outputs the seccomp filter to stdout in either BPF or PFC
+ * format depending on the test paramaeters supplied by @opts.
*
*/
int util_filter_output(const struct util_options *opts,
diff --git a/tests/util.py b/tests/util.py
new file mode 100644
index 0000000..8e4c689
--- /dev/null
+++ b/tests/util.py
@@ -0,0 +1,56 @@
+#
+# Seccomp Library utility code for tests
+#
+# Copyright (c) 2012 Red Hat <[email protected]>
+# Author: Paul Moore <[email protected]>
+#
+
+#
+# This library is free software; you can redistribute it and/or modify it
+# under the terms of version 2.1 of the GNU Lesser General Public License as
+# published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+# for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, see <http://www.gnu.org/licenses>.
+#
+
+""" Python utility code for the libseccomp test suite """
+
+import argparse
+import sys
+
+def get_opt():
+ """ Parse the arguments passed to main
+
+ Description:
+ Parse the arguments passed to the test from the command line. Returns
+ a parsed argparse object.
+ """
+ parser = argparse.ArgumentParser()
+ parser.add_argument("-b", "--bpf", action="store_true")
+ parser.add_argument("-p", "--pfc", action="store_true")
+ return parser.parse_args()
+
+def filter_output(args, ctx):
+ """ Output the filter in either BPF or PFC
+
+ Arguments:
+ args - an argparse object from UtilGetOpt()
+ ctx - a seccomp SyscallFilter object
+
+ Description:
+ Output the SyscallFilter to stdout in either BPF or PFC format depending
+ on the test's command line arguments.
+ """
+ if (args.bpf):
+ ctx.export_bpf(sys.stdout)
+ else:
+ ctx.export_pfc(sys.stdout)
+
+# kate: syntax python;
+# kate: indent-mode python; space-indent on; indent-width 4; mixedindent off;
------------------------------------------------------------------------------
LogMeIn Central: Instant, anywhere, Remote PC access and management.
Stay in control, update software, and manage PCs from one command center
Diagnose problems and improve visibility into emerging IT issues
Automate, monitor and manage. Do more in less time with Central
http://p.sf.net/sfu/logmein12331_d2d
_______________________________________________
libseccomp-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libseccomp-discuss