From 7060f165d264f66796409f20f1a29e9e84504afd Mon Sep 17 00:00:00 2001 From: Martin Belanger Date: Tue, 28 Feb 2023 12:17:08 -0500 Subject: [PATCH] python test: Check there is no SIGSEGV during garbage collection Signed-off-by: Martin Belanger --- libnvme/meson.build | 1 + libnvme/tests/gc.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100755 libnvme/tests/gc.py diff --git a/libnvme/meson.build b/libnvme/meson.build index e9589fc4..f83393f4 100644 --- a/libnvme/meson.build +++ b/libnvme/meson.build @@ -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 index 00000000..842a76df --- /dev/null +++ b/libnvme/tests/gc.py @@ -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 -- 2.50.1