summaryrefslogtreecommitdiffstats
path: root/libnvme/tests/gc.py
blob: 842a76df872871e8f5db9ddd84aa2dc88db459ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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