Skip to contentSkip to conversation

ndctl/test: fully reset nfit_test in pmem-ns unit test

PATCH In review Alison Schofield 2 participants 3 messages Oct 29, 2025 – Oct 31, 2025 libnvdimm: non-volatile memory device

lore
Share & tools
lore

Alison Schofield

author maintainer
#0 lore raw

PATCH v2 1/1 ndctl/test: fully reset nfit_test in pmem-ns unit test

The pmem_ns unit test is designed to fallback to using the nfit_test bus resource when an ACPI resource is not available. That fallback is not as solid as it could be, causing intermittent failures of the unit test.

That nfit_test fallback fails with errors such as:
path: /sys/devices/platform/nfit_test.0/ndbus2/region7/namespace7.0/uuid
libndctl: write_attr: failed to open /sys/devices/platform/nfit_test.0/ndbus2/region7/namespace7.0/uuid: No such file or directory /root/ndctl/build/test/pmem-ns: failed to create PMEM namespace

This occurs because calling ndctl_test_init() with a NULL context only unloads and reloads the nfit_test module, but does not invalidate and reinitialize the libndctl context or its sysfs view from previous runs. The resulting stale state prevents the test from creating a new namespace cleanly.

Replace the NULL context parameter when calling ndctl_test_init() with the available ndctl_ctx to ensure pmem_ns can find usable PMEM regions.

Add more debug messaging to describe why the nfit_test fallback path is taken, ie NULL bus or NULL region.

---

Changes in v2:
- Clarify which ACPI resource was not found, bus or region (MarcH)
- Update commit message and log
- Remove Closes tag (MarcH)

 test/pmem_namespaces.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
test/pmem_namespaces.c +9 -5
index 4bafff5164c8..6411e58ed5fd 100644
@@ -178,20 +178,24 @@ int test_pmem_namespaces(int log_level, struct ndctl_test *test,
 
 	ndctl_set_log_priority(ctx, log_level);
 
+	/* Try to use ACPI resource first, then nfit_test */
 	bus = ndctl_bus_get_by_provider(ctx, "ACPI.NFIT");
-	if (bus) {
-		/* skip this bus if no label-enabled PMEM regions */
+	if (bus)
 		ndctl_region_foreach(bus, region)
 			if (ndctl_region_get_nstype(region)
 					== ND_DEVICE_NAMESPACE_PMEM)
 				break;
-		if (!region)
-			bus = NULL;
+
+	if (!bus)
+		fprintf(stderr, "ACPI.NFIT: bus not found\n");
+	else if (!region) {
+		fprintf(stderr, "ACPI.NFIT: no PMEM region found\n");
+		bus = NULL;
 	}
 
 	if (!bus) {
 		fprintf(stderr, "ACPI.NFIT unavailable falling back to nfit_test\n");
-		rc = ndctl_test_init(&kmod_ctx, &mod, NULL, log_level, test);
+		rc = ndctl_test_init(&kmod_ctx, &mod, ctx, log_level, test);
 		ndctl_invalidate(ctx);
 		bus = ndctl_bus_get_by_provider(ctx, "nfit_test.0");
 		if (rc < 0 || !bus) {
Signature · 1 line
2.37.3
Reviewed-by on v2 1/1
#1 lore raw
Quoted 20 lines · Alison Schofield

The pmem_ns unit test is designed to fallback to using the nfit_test bus resource when an ACPI resource is not available. That fallback is not as solid as it could be, causing intermittent failures of the unit test.

That nfit_test fallback fails with errors such as:
path: /sys/devices/platform/nfit_test.0/ndbus2/region7/namespace7.0/uuid
libndctl: write_attr: failed to open /sys/devices/platform/nfit_test.0/ndbus2/region7/namespace7.0/uuid: No such file or directory /root/ndctl/build/test/pmem-ns: failed to create PMEM namespace

This occurs because calling ndctl_test_init() with a NULL context only unloads and reloads the nfit_test module, but does not invalidate and reinitialize the libndctl context or its sysfs view from previous runs. The resulting stale state prevents the test from creating a new namespace cleanly.

Replace the NULL context parameter when calling ndctl_test_init() with the available ndctl_ctx to ensure pmem_ns can find usable PMEM regions.

Quoted 6 lines

Add more debug messaging to describe why the nfit_test fallback path is taken, ie NULL bus or NULL region.

[snip]

author maintainer
#2 lore raw
In reply to Alison Schofield
Quoted 28 lines · Alison Schofield

The pmem_ns unit test is designed to fallback to using the nfit_test bus resource when an ACPI resource is not available. That fallback is not as solid as it could be, causing intermittent failures of the unit test.

That nfit_test fallback fails with errors such as:
path: /sys/devices/platform/nfit_test.0/ndbus2/region7/namespace7.0/uuid
libndctl: write_attr: failed to open /sys/devices/platform/nfit_test.0/ndbus2/region7/namespace7.0/uuid: No such file or directory /root/ndctl/build/test/pmem-ns: failed to create PMEM namespace

This occurs because calling ndctl_test_init() with a NULL context only unloads and reloads the nfit_test module, but does not invalidate and reinitialize the libndctl context or its sysfs view from previous runs. The resulting stale state prevents the test from creating a new namespace cleanly.

Replace the NULL context parameter when calling ndctl_test_init() with the available ndctl_ctx to ensure pmem_ns can find usable PMEM regions.

Add more debug messaging to describe why the nfit_test fallback path is taken, ie NULL bus or NULL region.

Quoted 6 lines

---

Changes in v2:
- Clarify which ACPI resource was not found, bus or region (MarcH)
- Update commit message and log
- Remove Closes tag (MarcH)

Thanks for the reviews and testing.
Applied to : https://github.com/pmem/ndctl/commits/pending/

Added note to github issue https://github.com/pmem/ndctl/issues/290

"This fixes up the failure of the pmem-ns unit test for nfit_test users. It also adds debug messaging to help debug of ACPI.NFIT users. Patches welcome."

Quoted 42 lines

 test/pmem_namespaces.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
test/pmem_namespaces.c +9 -5
index 4bafff5164c8..6411e58ed5fd 100644
@@ -178,20 +178,24 @@ int test_pmem_namespaces(int log_level, struct ndctl_test *test,
 
 	ndctl_set_log_priority(ctx, log_level);
 
+	/* Try to use ACPI resource first, then nfit_test */
 	bus = ndctl_bus_get_by_provider(ctx, "ACPI.NFIT");
-	if (bus) {
-		/* skip this bus if no label-enabled PMEM regions */
+	if (bus)
 		ndctl_region_foreach(bus, region)
 			if (ndctl_region_get_nstype(region)
 					== ND_DEVICE_NAMESPACE_PMEM)
 				break;
-		if (!region)
-			bus = NULL;
+
+	if (!bus)
+		fprintf(stderr, "ACPI.NFIT: bus not found\n");
+	else if (!region) {
+		fprintf(stderr, "ACPI.NFIT: no PMEM region found\n");
+		bus = NULL;
 	}
 
 	if (!bus) {
 		fprintf(stderr, "ACPI.NFIT unavailable falling back to nfit_test\n");
-		rc = ndctl_test_init(&kmod_ctx, &mod, NULL, log_level, test);
+		rc = ndctl_test_init(&kmod_ctx, &mod, ctx, log_level, test);
 		ndctl_invalidate(ctx);
 		bus = ndctl_bus_get_by_provider(ctx, "nfit_test.0");
 		if (rc < 0 || !bus) {
Signature · 1 line
2.37.3