]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
tests/pytests: quality-of-life improvements and notes
authorOto Šťáva <oto.stava@nic.cz>
Thu, 26 Jan 2023 07:45:24 +0000 (08:45 +0100)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 1 Feb 2023 11:36:34 +0000 (12:36 +0100)
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
tests/pytests/README.rst
tests/pytests/kresd.py

index d4522a87b1541bc4718419273fd0f1d123e358f3..9f27fe442cad93ca6caa9fc6bcfa3f681952f9d2 100644 (file)
@@ -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
index 173dc408f01f2d76ac45d85b45146c2fcf377bbf..63db3efeec6fadc62077afe98c0a4bb1614aeec5 100644 (file)
@@ -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-<username>/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
 ---------------
 
index 149efe959acbd511648d291ba841f79ed6ddf37c..ca15e0d7e371ea912165e7070333cc1e11d2d749 100644 (file)
@@ -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: