]> git.ipfire.org Git - thirdparty/suricata-verify.git/commitdiff
runner: add --outdir <dir> option
authorVictor Julien <victor@inliniac.net>
Thu, 18 Jan 2018 17:52:59 +0000 (18:52 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 19 Jan 2018 21:11:15 +0000 (22:11 +0100)
Allow specifying an output dir to avoid poluting the work tree
or run tests off a read only file system.

run.py
tests/test-config-empty-rule-file/test.yaml

diff --git a/run.py b/run.py
index 1781b6b17a638c9fe9be19183d378cebed3d4e3f..ff8e8828ae6cb5f97c76e5520f09181b58c38eed 100755 (executable)
--- a/run.py
+++ b/run.py
@@ -154,8 +154,9 @@ class ShellCheck:
 
 class StatsCheck:
 
-    def __init__(self, config):
+    def __init__(self, config, outdir):
         self.config = config
+        self.outdir = outdir
 
     def run(self):
         stats = None
@@ -173,8 +174,9 @@ class StatsCheck:
 
 class FilterCheck:
 
-    def __init__(self, config):
+    def __init__(self, config, outdir):
         self.config = config
+        self.outdir = outdir
 
     def run(self):
         eve_json_path = "eve.json"
@@ -206,12 +208,12 @@ class FilterCheck:
 
 class TestRunner:
 
-    def __init__(self, cwd, directory, suricata_config, verbose=False):
+    def __init__(self, cwd, directory, outdir, suricata_config, verbose=False):
         self.cwd = cwd
         self.directory = directory
         self.suricata_config = suricata_config
         self.verbose = verbose
-        self.output = os.path.join(self.directory, "output")
+        self.output = os.path.join(outdir, "output")
 
         # The name is just the directory name.
         self.name = os.path.basename(self.directory)
@@ -237,7 +239,7 @@ class TestRunner:
                         subprocess.check_call(
                             "%s" % setup[command],
                             shell=True,
-                            cwd=os.path.join(self.directory, "output"))
+                            cwd=self.output)
 
     def check_skip(self):
         if not "skip" in self.config:
@@ -324,6 +326,7 @@ class TestRunner:
             "SRCDIR": self.cwd,
             "TZ": "UTC",
             "TEST_DIR": self.directory,
+            "OUTPUT_DIR": self.output,
             "ASAN_OPTIONS": "detect_leaks=0",
         }
 
@@ -376,13 +379,13 @@ class TestRunner:
     def check(self):
 
         pdir = os.getcwd()
-        os.chdir(os.path.join(self.directory, "output"))
+        os.chdir(self.output)
         try:
             if "checks" in self.config:
                 for check in self.config["checks"]:
                     for key in check:
                         if key == "filter":
-                            if not FilterCheck(check[key]).run():
+                            if not FilterCheck(check[key], self.output).run():
                                 raise TestError("filter did not match: %s" % (
                                     str(check[key])))
                         elif key == "shell":
@@ -391,7 +394,7 @@ class TestRunner:
                                     "shell output did not match: %s" % (
                                         str(check[key])))
                         elif key == "stats":
-                            if not StatsCheck(check[key]).run():
+                            if not StatsCheck(check[key], self.output).run():
                                 raise TestError("stats check did not pass")
                         else:
                             raise TestError("Unknown check type: %s" % (key))
@@ -400,7 +403,7 @@ class TestRunner:
 
         # Old style check script.
         pdir = os.getcwd()
-        os.chdir(os.path.join(self.directory, "output"))
+        os.chdir(self.output)
         try:
             if not os.path.exists(os.path.join(self.directory, "check.sh")):
                 return True
@@ -507,6 +510,8 @@ def main():
                         help="Exit on test failure")
     parser.add_argument("--dir", action="store",
                         help="Runs tests from custom directory")
+    parser.add_argument("--outdir", action="store",
+                        help="Outputs to custom directory")
     parser.add_argument("patterns", nargs="*", default=[])
     args = parser.parse_args()
 
@@ -557,8 +562,12 @@ def main():
     for dirpath in tests:
         name = os.path.basename(dirpath)
 
+        outdir = os.path.join(dirpath, "output")
+        if args.outdir:
+            outdir = os.path.join(args.outdir, name)
+
         test_runner = TestRunner(
-            cwd, dirpath, suricata_config, args.verbose)
+            cwd, dirpath, outdir, suricata_config, args.verbose)
         try:
             if test_runner.run():
                 passed += 1
index 8884095847c6d3572bffcc8914e3399c18bb4fad..f245cc8e35930c120cce5cb9572f7314ffdd8892 100644 (file)
@@ -5,5 +5,5 @@ requires:
 # be broken up over multiple lines for readability.
 command: |
   ${SRCDIR}/src/suricata -T -c ${TEST_DIR}/suricata.yaml -vvv \
-      -l ${TEST_DIR}/output --set default-rule-path="${TEST_DIR}"
+      -l ${OUTPUT_DIR} --set default-rule-path="${TEST_DIR}"