]> git.ipfire.org Git - thirdparty/suricata-verify.git/commitdiff
allow command to be set in test.yaml
authorJason Ish <ish@unx.ca>
Mon, 4 Dec 2017 18:02:36 +0000 (12:02 -0600)
committerJason Ish <ish@unx.ca>
Mon, 4 Dec 2017 18:02:36 +0000 (12:02 -0600)
Removes the need to support a test specific run.sh.

Also, don't require a check.sh. In some tests, just a
successful exit code is being tested for.

run.py
tests/test-config-empty-rule-file/check.sh [deleted file]
tests/test-config-empty-rule-file/run.sh [deleted file]
tests/test-config-empty-rule-file/test.yaml

diff --git a/run.py b/run.py
index cdad6b2f662f3427961ad48f21453b7ebcf4fff7..94fd7118731be633319d9dc138bbcca016690e11 100755 (executable)
--- a/run.py
+++ b/run.py
@@ -100,6 +100,12 @@ class TestConfig:
                         raise UnsatisfiedRequirementError(
                             "not for feature %s" % (feature))
 
+    def has_command(self):
+        return "command" in self.config
+
+    def get_command(self):
+        return self.config["command"]
+
     def _version_gte(self, v1, v2):
         """Return True if v1 is great than or equal to v2."""
         if v1.major < v2.major:
@@ -158,7 +164,10 @@ class TestRunner:
             test_config = yaml.load(
                 open(os.path.join(self.directory, "test.yaml"), "rb"))
             test_config = TestConfig(test_config, self.suricata_config)
-            test_config.check_requires()
+        else:
+            test_config = TestConfig({}, self.suricata_config)
+
+        test_config.check_requires()
 
         # Additional requirement checks.
         # - If lua is in the test name, make sure we HAVE_LUA.
@@ -166,11 +175,13 @@ class TestRunner:
             if not self.suricata_config.has_feature("HAVE_LUA"):
                 raise UnsatisfiedRequirementError("requires feature HAVE_LUA")
 
-        args = []
-        if os.path.exists(os.path.join(self.directory, "run.sh")):
-            args.append(os.path.join(self.directory, "run.sh"))
+        shell = False
+
+        if test_config.has_command():
+            args = test_config.get_command()
+            shell = True
         else:
-            args += self.default_args()
+            args = self.default_args()
 
         env = {
             # The suricata source directory.
@@ -192,7 +203,7 @@ class TestRunner:
             " ".join(args))
 
         p = subprocess.Popen(
-            args, cwd=self.directory, env=env,
+            args, shell=shell, cwd=self.directory, env=env,
             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 
         self.start_reader(p.stdout, stdout)
@@ -211,7 +222,7 @@ class TestRunner:
 
     def check(self):
         if not os.path.exists(os.path.join(self.directory, "check.sh")):
-            print("OK (no check script)")
+            print("OK")
             return True
         r = subprocess.call(["./check.sh"], cwd=self.directory)
         if r != 0:
@@ -320,13 +331,9 @@ def main():
             # If a test matches a pattern, we do not skip it.
             for pattern in args.patterns:
                 if name.find(pattern) > -1:
-                    skip, reason = check_skip(dirpath)
-                    if skip:
+                    if check_skip(dirpath):
                         skipped += 1
-                        if reason:
-                            print("===> %s: SKIPPED: %s" % (name, reason))
-                        else:
-                            print("===> %s: SKIPPED" % (name))
+                        print("===> %s: SKIPPED" % (name))
                     else:
                         do_test = True
                     break
diff --git a/tests/test-config-empty-rule-file/check.sh b/tests/test-config-empty-rule-file/check.sh
deleted file mode 100755 (executable)
index cd494df..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-#! /bin/sh
-
-# Nothing to check.
-exit 0
diff --git a/tests/test-config-empty-rule-file/run.sh b/tests/test-config-empty-rule-file/run.sh
deleted file mode 100755 (executable)
index 3bfd06b..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-#! /bin/sh
-
-run() {
-    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
-}
-
-mkdir -p ${TEST_DIR}/output
-run
-
-exit 0
index ab70817ef78693b82dc78016780578031318e3ff..8884095847c6d3572bffcc8914e3399c18bb4fad 100644 (file)
@@ -1,2 +1,9 @@
 requires:
   min-version: 4.0.0
+
+# Override the default command. This is also an example of how it can
+# 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}"
+