From 47fe00e6500a76cf82105f5a35349c2a2c6b03fe Mon Sep 17 00:00:00 2001 From: =?utf8?q?Oto=20=C5=A0=C5=A5=C3=A1va?= Date: Thu, 26 Jan 2023 08:45:24 +0100 Subject: [PATCH] tests/pytests: quality-of-life improvements and notes Added the option to run `kresd` inside `pytests` under `valgrind` and `rr`, which can help with debugging. Also added a clarifying note that I personally would have liked to have while exploring this. --- .gitignore | 2 +- tests/pytests/README.rst | 13 +++++++++++++ tests/pytests/kresd.py | 14 ++++++++++++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index d4522a87b..9f27fe442 100644 --- a/.gitignore +++ b/.gitignore @@ -65,7 +65,7 @@ /tags /tests/pytests/*/tcproxy /tests/pytests/*/tlsproxy -/tests/pytests/pytests.parallel.html +/tests/pytests/pytests.*.html /tests/pytests/*.junit.xml /tests/test_array /tests/test_lru diff --git a/tests/pytests/README.rst b/tests/pytests/README.rst index 173dc408f..63db3efee 100644 --- a/tests/pytests/README.rst +++ b/tests/pytests/README.rst @@ -42,6 +42,19 @@ the path to test file directly. Note: some tests may fail without an internet connection. +Additional usage notes +---------------------- + +- Not everything is logged into pytest's standard output. To inspect the logs of + `kresd` itself, see `/tmp/pytest-of-/pytest-current`. +- The `rr` and `valgrind` parameters of the `Kresd` constructor may be used to + gain further information on failing tests. Simply set them to `True` in the + test cases temporarily if you need them. + - `rr=True` will record the execution of `kresd`, which can then be replayed + with the usual `rr replay` command. + - `valgrind=True` will run `kresd` under `valgrind`, the results of which + can be inspected in `kresd`'s logs (see above). + Developer notes --------------- diff --git a/tests/pytests/kresd.py b/tests/pytests/kresd.py index 149efe959..ca15e0d7e 100644 --- a/tests/pytests/kresd.py +++ b/tests/pytests/kresd.py @@ -50,7 +50,8 @@ Forward = namedtuple('Forward', ['proto', 'ip', 'port', 'hostname', 'ca_file']) class Kresd(ContextDecorator): def __init__( self, workdir, port=None, tls_port=None, ip=None, ip6=None, certname=None, - verbose=True, hints=None, forward=None, policy_test_pass=False): + verbose=True, hints=None, forward=None, policy_test_pass=False, rr=False, + valgrind=False): if ip is None and ip6 is None: raise ValueError("IPv4 or IPv6 must be specified!") self.workdir = str(workdir) @@ -65,6 +66,8 @@ class Kresd(ContextDecorator): self.hints = {} if hints is None else hints self.forward = forward self.policy_test_pass = policy_test_pass + self.rr = rr + self.valgrind = valgrind if certname: self.tls_cert_path = os.path.join(CERTS_DIR, certname + '.cert.pem') @@ -93,8 +96,15 @@ class Kresd(ContextDecorator): create_file_from_template(KRESD_CONF_TEMPLATE, self.config_path, {'kresd': self}) self.logfile = open(self.logfile_path, 'w', encoding='UTF-8') + + proc_args = ['kresd', '-c', self.config_path, '-n', self.workdir] + if self.rr: + proc_args = ['rr', 'record', '--'] + proc_args + if self.valgrind: + proc_args = ['valgrind', '--'] + proc_args + self.process = subprocess.Popen( - ['kresd', '-c', self.config_path, '-n', self.workdir], + proc_args, stderr=self.logfile, env=os.environ.copy()) try: -- 2.47.2