From 06dcf5ee29ed9528d5d2de6c9ce4f9f568072e2c Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Sun, 12 Dec 2021 10:32:19 -0600 Subject: [PATCH] runner: pass environment to shell checks This allows a shell check to know where to found the output directory. This will allow us to revert 0bd6984e1249778d6668dd4a906d42a53481279f. --- run.py | 27 +++++++++++++------------- tests/datasets-06-state-long/test.yaml | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/run.py b/run.py index 436c259a9..cac453093 100755 --- 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 diff --git a/tests/datasets-06-state-long/test.yaml b/tests/datasets-06-state-long/test.yaml index 69ab704b3..359d268aa 100644 --- a/tests/datasets-06-state-long/test.yaml +++ b/tests/datasets-06-state-long/test.yaml @@ -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 -- 2.47.2