Skip to content

Commit 7060f16

Browse files
Martin Belangerigaw
authored andcommitted
python test: Check there is no SIGSEGV during garbage collection
Signed-off-by: Martin Belanger <[email protected]>
1 parent 3fb81f1 commit 7060f16

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

libnvme/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ if have_python_support
6262

6363
py_tests = [
6464
[ 'create ctrl object', files('tests/create-ctrl-obj.py') ],
65+
[ 'SIGSEGV during gc', files('tests/gc.py') ],
6566
]
6667
foreach test: py_tests
6768
description = test[0]

libnvme/tests/gc.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python3
2+
# SPDX-License-Identifier: LGPL-2.1-or-later
3+
import gc
4+
import sys
5+
import pprint
6+
from libnvme import nvme
7+
8+
root = nvme.root()
9+
root.log_level('debug')
10+
print(f'root: {root}')
11+
12+
host = nvme.host(root)
13+
print(f'host: {host}')
14+
15+
subsystem = host.subsystems()
16+
print(f'subsystem: {subsystem}')
17+
18+
ctrls = []
19+
for i in range(10):
20+
ctrl = nvme.ctrl(
21+
root,
22+
subsysnqn=nvme.NVME_DISC_SUBSYS_NAME,
23+
transport='loop',
24+
)
25+
ctrls.append(ctrl)
26+
print(f'ctrl {i}: {ctrl}')
27+
28+
ns = subsystem.namespaces() if subsystem is not None else None
29+
print(f'ns: {ns}')
30+
31+
# Deleting objects in the following order would create a segmentation
32+
# fault if it weren't for the %pythonappend in nvme.i. This test is to
33+
# make sure garbage collection is not impacted by object deletion order.
34+
root = None
35+
host = None
36+
37+
gc.collect() # Force garbage collection before controller/subsystem objects get deleted
38+
39+
ctrls = None
40+
subsystem= None
41+
ns = None

0 commit comments

Comments
 (0)