From: Jason Ish Date: Fri, 24 Nov 2017 16:03:24 +0000 (-0600) Subject: run tests from test directory X-Git-Tag: suricata-6.0.4~569 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=010c57af4496a69e52d453c7c2e33b38d0b4fe50;p=thirdparty%2Fsuricata-verify.git run tests from test directory Fixes the case where we had a hardcoded relative path to deal with Lua scripts. --- diff --git a/run.py b/run.py index 5ce8b0ef6..0535ca83b 100755 --- a/run.py +++ b/run.py @@ -1,4 +1,26 @@ #! /usr/bin/env python2 +# +# Copyright 2017 Jason Ish +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. from __future__ import print_function @@ -22,7 +44,8 @@ def pipe_reader(fileobj, output=None, verbose=False): class TestRunner: - def __init__(self, directory, verbose=False): + def __init__(self, cwd, directory, verbose=False): + self.cwd = cwd self.directory = directory self.verbose = verbose self.output = os.path.join(self.directory, "output") @@ -45,6 +68,8 @@ class TestRunner: args += self.default_args() env = { + # The suricata source directory. + "SRCDIR": self.cwd, "TZ": "UTC", "TEST_DIR": self.directory, "ASAN_OPTIONS": "detect_leaks=0", @@ -62,7 +87,8 @@ class TestRunner: " ".join(args)) p = subprocess.Popen( - args, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + args, cwd=self.directory, env=env, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) self.start_reader(p.stdout, stdout) self.start_reader(p.stderr, stderr) @@ -90,11 +116,14 @@ class TestRunner: return True def default_args(self): - args = ["./src/suricata", - "--set", "classification-file=./classification.config", - "--set", "reference-config-file=./reference.config", - "--init-errors-fatal", - "-l", self.output, + args = [ + os.path.join(self.cwd, "src/suricata"), + "--set", "classification-file=%s" % os.path.join( + self.cwd, "classification.config"), + "--set", "reference-config-file=%s" % os.path.join( + self.cwd, "reference.config"), + "--init-errors-fatal", + "-l", self.output, ] if "ips" in self.name: @@ -103,7 +132,7 @@ class TestRunner: if os.path.exists(os.path.join(self.directory, "suricata.yaml")): args += ["-c", os.path.join(self.directory, "suricata.yaml")] else: - args += ["-c", "./suricata.yaml"] + args += ["-c", os.path.join(self.cwd, "suricata.yaml")] # Find pcaps. pcaps = glob.glob(os.path.join(self.directory, "*.pcap")) @@ -163,12 +192,21 @@ def main(): parser.add_argument("patterns", nargs="*", default=[]) args = parser.parse_args() - topdir = os.path.dirname(sys.argv[0]) + topdir = os.path.abspath(os.path.dirname(sys.argv[0])) skipped = 0 passed = 0 failed = 0 + # Get the current working directory, which should be the top + # suricata source directory. + cwd = os.getcwd() + if not (os.path.exists("./suricata.yaml") and + os.path.exists("./src/suricata")): + print("error: this is not a suricata source directory or " + + "suricata is not built") + return 1 + for dirpath, dirnames, filenames in os.walk(os.path.join(topdir, "tests")): # The top directory is not a test... @@ -210,7 +248,7 @@ def main(): break if do_test: - test_runner = TestRunner(dirpath, args.verbose) + test_runner = TestRunner(cwd, dirpath, args.verbose) try: success = test_runner.run() except Exception as err: diff --git a/tests/lua-output-dns/suricata.yaml b/tests/lua-output-dns/suricata.yaml index ac257314c..c5276c0e1 100644 --- a/tests/lua-output-dns/suricata.yaml +++ b/tests/lua-output-dns/suricata.yaml @@ -8,6 +8,6 @@ rule-files: outputs: - lua: enabled: yes - scripts-dir: ../verify/tests/lua-output-dns + scripts-dir: . scripts: - test.lua diff --git a/tests/lua-output-dns/test.rules b/tests/lua-output-dns/test.rules deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/lua-output-http/suricata.yaml b/tests/lua-output-http/suricata.yaml index 7e0bc1785..f47029fc9 100644 --- a/tests/lua-output-http/suricata.yaml +++ b/tests/lua-output-http/suricata.yaml @@ -6,6 +6,6 @@ include: default.yaml outputs: - lua: enabled: yes - scripts-dir: ../verify/tests/lua-output-http + scripts-dir: . scripts: - http.lua diff --git a/tests/lua-output-smtp/suricata.yaml b/tests/lua-output-smtp/suricata.yaml index 2fd72f7f5..ed3a1dc90 100644 --- a/tests/lua-output-smtp/suricata.yaml +++ b/tests/lua-output-smtp/suricata.yaml @@ -6,6 +6,6 @@ include: default.yaml outputs: - lua: enabled: yes - scripts-dir: ../verify/tests/lua-output-smtp + scripts-dir: . scripts: - smtp.lua diff --git a/tests/test-config-empty-rule-file/run.sh b/tests/test-config-empty-rule-file/run.sh index 4d501edc5..3bfd06b69 100755 --- a/tests/test-config-empty-rule-file/run.sh +++ b/tests/test-config-empty-rule-file/run.sh @@ -1,7 +1,7 @@ #! /bin/sh run() { - if ! ./src/suricata -T -c ${TEST_DIR}/suricata.yaml -vvv \ + if ! ${SRCDIR}/src/suricata -T -c ${TEST_DIR}/suricata.yaml -vvv \ -l ${TEST_DIR}/output --set default-rule-path="${TEST_DIR}"; then exit 1 fi