]> git.ipfire.org Git - thirdparty/suricata-verify.git/commitdiff
runner: pass environment to shell checks
authorJason Ish <jason.ish@oisf.net>
Sun, 12 Dec 2021 16:32:19 +0000 (10:32 -0600)
committerJason Ish <jason.ish@oisf.net>
Sun, 12 Dec 2021 23:26:38 +0000 (17:26 -0600)
This allows a shell check to know where to found the output
directory.

This will allow us to revert 0bd6984e1249778d6668dd4a906d42a53481279f.

run.py
tests/datasets-06-state-long/test.yaml

diff --git a/run.py b/run.py
index 436c259a99800571909c7234ce77fc5128ae163b..cac453093a73204d9b72f384ab273fb93a55c390 100755 (executable)
--- a/run.py
+++ b/run.py
@@ -385,8 +385,9 @@ class FileCompareCheck:
 
 class ShellCheck:
 
-    def __init__(self, config):
+    def __init__(self, config, env):
         self.config = config
+        self.env = env
 
     def run(self):
         if not self.config or "args" not in self.config:
@@ -395,7 +396,7 @@ class ShellCheck:
             if WIN32:
                 print("skipping shell check on windows")
                 return True;
-            output = subprocess.check_output(self.config["args"], shell=True)
+            output = subprocess.check_output(self.config["args"], shell=True, env=self.env)
             if "expect" in self.config:
                 return str(self.config["expect"]) == output.decode().strip()
             return True
@@ -577,6 +578,15 @@ class TestRunner:
                    glob.glob(os.path.join(self.directory, "*.pcapng")):
                     raise UnsatisfiedRequirementError("No pcap file found")
 
+    def build_env(self):
+        env = os.environ.copy()
+        env["SRCDIR"] = self.cwd
+        env["TZ"] = "UTC"
+        env["TEST_DIR"] = self.directory
+        env["OUTPUT_DIR"] = self.output
+        env["ASAN_OPTIONS"] = "detect_leaks=1"
+        return env
+
     def run(self, outdir):
 
         if not self.force:
@@ -598,16 +608,7 @@ class TestRunner:
         else:
             args = self.default_args()
 
-        extraenv = {
-            # The suricata source directory.
-            "SRCDIR": self.cwd,
-            "TZ": "UTC",
-            "TEST_DIR": self.directory,
-            "OUTPUT_DIR": self.output,
-            "ASAN_OPTIONS": "detect_leaks=1",
-        }
-        env = os.environ.copy()
-        env.update(extraenv)
+        env = self.build_env()
 
         if "count" in self.config:
             count = self.config["count"]
@@ -683,7 +684,7 @@ class TestRunner:
 
     @handle_exceptions
     def perform_shell_checks(self, check, count, test_num, test_name):
-        count = ShellCheck(check).run()
+        count = ShellCheck(check, self.build_env()).run()
         return count
 
     @handle_exceptions
index 69ab704b3e406adb4c8017f8133af85749103489..359d268aa71304265871f0af23e4f275bbb124ab 100644 (file)
@@ -11,5 +11,5 @@ args:
 checks:
   - shell:
       args: |
-        cat ../expected/state.csv | sort > expected.csv
+        cat ${TEST_DIR}/expected/state.csv | sort > expected.csv
         cat state.csv | sort | cmp - expected.csv