]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
python test: Check there is no SIGSEGV during garbage collection
authorMartin Belanger <martin.belanger@dell.com>
Tue, 28 Feb 2023 17:17:08 +0000 (12:17 -0500)
committerDaniel Wagner <wagi@monom.org>
Tue, 28 Feb 2023 17:30:30 +0000 (18:30 +0100)
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
libnvme/meson.build
libnvme/tests/gc.py [new file with mode: 0755]

index e9589fc416a04e0a6f5a5c84b2889ac29acaaa64..f83393f42f306f2e03e2ee95bab501e7759d6cd5 100644 (file)
@@ -62,6 +62,7 @@ if have_python_support
 
     py_tests = [ 
         [ 'create ctrl object', files('tests/create-ctrl-obj.py') ], 
+        [ 'SIGSEGV during gc', files('tests/gc.py') ],
     ]
     foreach test: py_tests
         description = test[0]
diff --git a/libnvme/tests/gc.py b/libnvme/tests/gc.py
new file mode 100755 (executable)
index 0000000..842a76d
--- /dev/null
@@ -0,0 +1,41 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: LGPL-2.1-or-later
+import gc
+import sys
+import pprint
+from libnvme import nvme
+
+root = nvme.root()
+root.log_level('debug')
+print(f'root: {root}')
+
+host = nvme.host(root)
+print(f'host: {host}')
+
+subsystem = host.subsystems()
+print(f'subsystem: {subsystem}')
+
+ctrls = []
+for i in range(10):
+    ctrl = nvme.ctrl(
+        root,
+        subsysnqn=nvme.NVME_DISC_SUBSYS_NAME,
+        transport='loop',
+    )
+    ctrls.append(ctrl)
+    print(f'ctrl {i}: {ctrl}')
+
+ns = subsystem.namespaces() if subsystem is not None else None
+print(f'ns: {ns}')
+
+# Deleting objects in the following order would create a segmentation
+# fault if it weren't for the %pythonappend in nvme.i. This test is to
+# make sure garbage collection is not impacted by object deletion order.
+root = None
+host = None
+
+gc.collect()  # Force garbage collection before controller/subsystem objects get deleted
+
+ctrls = None
+subsystem= None
+ns = None