From: Jason Ish Date: Tue, 16 Jan 2018 20:12:44 +0000 (-0600) Subject: runner: custom args and pcap requires option X-Git-Tag: suricata-6.0.4~535 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=82c3dfb62428b0fa32bc575b499b9db7c39c0b66;p=thirdparty%2Fsuricata-verify.git runner: custom args and pcap requires option To specify additional args, test.yaml can have: args: - --set field=val Also, by default a pcap file is required for a test to run. Add pcap option to requires that can turn this off. --- diff --git a/README.md b/README.md index 3d8fa7a12..b79d3cb40 100644 --- a/README.md +++ b/README.md @@ -47,14 +47,11 @@ Or to run a single test: ## Example test.yaml ``` -# 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}" - requires: + # Require a minimum version of Suricata. + min-version: 4.1.0 + # Require the presence of specific features. features: # Restrict the test to builds with HAVE_LUA. @@ -63,3 +60,19 @@ requires: # Require that Suricata not be built with specific features. not-features: RUST: option reason + + # Don't require a pcap file to be present. By default a test will be skipped + # if there is no pcap file in the test directory. Not applicable if a + # command is provided. + pcap: false + +# Add additional arguments to Suricata. +args: + - --set stream.reassembly.depth=0 + +# Override the default command. This is also an example of how it can +# be broken up over multiple lines for readability. If providing the command +# all arguments must be provided as part of the command. +command: | + ${SRCDIR}/src/suricata -T -c ${TEST_DIR}/suricata.yaml -vvv \ + -l ${TEST_DIR}/output --set default-rule-path="${TEST_DIR}" diff --git a/run.py b/run.py index 4fed5a408..ce0508a3c 100755 --- a/run.py +++ b/run.py @@ -228,8 +228,12 @@ class FilterCheck: self.config = config def run(self): + eve_json_path = os.path.join("output", "eve.json") + if not os.path.exists(eve_json_path): + raise TestError("%s does not exist" % (eve_json_path)) + count = 0 - with open(os.path.join("output", "eve.json"), "r") as fileobj: + with open(eve_json_path, "r") as fileobj: for line in fileobj: event = json.loads(line) if self.match(event): @@ -266,9 +270,18 @@ class TestRunner: # List of thread readers. self.readers = [] - def setup(self, config): - if "setup" in config: - for setup in config["setup"]: + self.load_config() + + def load_config(self): + if os.path.exists(os.path.join(self.directory, "test.yaml")): + self.config = yaml.safe_load( + open(os.path.join(self.directory, "test.yaml"), "rb")) + else: + self.config = {} + + def setup(self): + if "setup" in self.config: + for setup in self.config["setup"]: for command in setup: if command == "script": subprocess.check_call( @@ -276,6 +289,22 @@ class TestRunner: shell=True, cwd=self.directory) + def check_requires(self): + if not "requires" in self.config: + return + requires = self.config["requires"] + + # Check if a pcap is required or not. By default a pcap is + # required unless a "command" has been provided. + if not "command" in self.config: + if "pcap" in requires: + pcap_required = requires["pcap"] + else: + pcap_required = True + if pcap_required: + if not glob.glob(os.path.join(self.directory, "*.pcap")): + raise UnsatisfiedRequirementError("No pcap file found") + def run(self): sys.stdout.write("===> %s: " % os.path.basename(self.directory)) @@ -294,7 +323,8 @@ class TestRunner: os.makedirs(self.output) test_config.check_requires() - self.setup(test_config.config) + self.check_requires() + self.setup() shell = False @@ -374,6 +404,16 @@ class TestRunner: def default_args(self): args = [ os.path.join(self.cwd, "src/suricata"), + ] + + # Load args from config file. + if "args" in self.config: + assert(type(self.config["args"]) == type([])) + for arg in self.config["args"]: + args += re.split("\s", arg) + + # Add other fixed arguments. + args += [ "--set", "classification-file=%s" % os.path.join( self.cwd, "classification.config"), "--set", "reference-config-file=%s" % os.path.join( @@ -392,11 +432,10 @@ class TestRunner: # Find pcaps. pcaps = glob.glob(os.path.join(self.directory, "*.pcap")) - if not pcaps: - raise UnsatisfiedRequirementError("No pcap file found") - elif len(pcaps) > 1: + if len(pcaps) > 1: raise TestError("More than 1 pcap file found") - args += ["-r", pcaps[0]] + if pcaps: + args += ["-r", pcaps[0]] # Find rules. rules = glob.glob(os.path.join(self.directory, "*.rules"))