From: Tharushi Jayasekara Date: Tue, 16 Feb 2021 18:57:27 +0000 (+0530) Subject: run: convert cmp tests to python X-Git-Tag: suricata-6.0.4~73 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=173dd0cbe3641137e4f469e4dfca2f1ae8d3ed89;p=thirdparty%2Fsuricata-verify.git run: convert cmp tests to python --- diff --git a/run.py b/run.py index d6da6123c..b782e51d4 100755 --- a/run.py +++ b/run.py @@ -40,7 +40,7 @@ import unittest import multiprocessing as mp from collections import namedtuple import threading - +import filecmp import yaml WIN32 = sys.platform == "win32" @@ -306,6 +306,19 @@ def is_version_compatible(version, suri_version, expr): return False return True +class FileCompareCheck: + + def __init__(self, config, directory): + self.config = config + self.directory = directory + + def run(self): + expected = os.path.join(self.directory, self.config["expected"]) + filename = self.config["filename"] + if filecmp.cmp(expected, filename): + return True + else: + raise TestError("%s %s \nFAILED: verification failed" % (expected, filename)) class ShellCheck: @@ -682,6 +695,11 @@ class TestRunner: count = StatsCheck(check, self.output).run() return count + @handle_exceptions + def perform_file_compare_checks(self, check, count, test_num, test_name): + count = FileCompareCheck(check, self.directory).run() + return count + def reset_count(self, dictionary): for k in dictionary.keys(): dictionary[k] = 0 @@ -701,8 +719,8 @@ class TestRunner: self.reset_count(count) for check_count, check in enumerate(self.config["checks"]): for key in check: - if key in ["filter", "shell", "stats"]: - func = getattr(self, "perform_{}_checks".format(key)) + if key in ["filter", "shell", "stats", "file-compare"]: + func = getattr(self, "perform_{}_checks".format(key.replace("-","_"))) count = func(check=check[key], count=count, test_num=check_count + 1, test_name=os.path.basename(self.directory)) else: diff --git a/tests/datasets-01/check.sh b/tests/datasets-01/check.sh deleted file mode 100755 index 8bedbf39c..000000000 --- a/tests/datasets-01/check.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -exec cmp datasets.csv ${TEST_DIR}/expected/datasets.csv