testcases/nvme: Add NVMe device discovery and identification test
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v2 1/1 testcases/nvme: Add NVMe device discovery and identification test
From: priyama2 <[email protected]>
This test verifies NVMe device discovery and identification by:
- Detecting NVMe controllers in /dev
- Enumerating namespaces for detected controllers
- Verifying PCI enumeration (class code 0x010802)
- Checking NVMe driver binding
Changes in v2:
- Use LTP buildsystem instead of standalone Makefile
- Remove README file (use doc comments instead)
- Fix author attribution
- Add proper LTP documentation comment format
- Use SAFE_OPENDIR() and SAFE_CLOSEDIR() macros
- Remove obvious and redundant comments
- Code cleanup and style improvements
--- testcases/kernel/device-drivers/nvme/Makefile | 7 + testcases/kernel/device-drivers/nvme/nvme01 | Bin 0 -> 995536 bytes testcases/kernel/device-drivers/nvme/nvme01.c | 208 ++++++++++++++++++ 3 files changed, 215 insertions(+) create mode 100644 testcases/kernel/device-drivers/nvme/Makefile create mode 100755 testcases/kernel/device-drivers/nvme/nvme01 create mode 100644 testcases/kernel/device-drivers/nvme/nvme01.c
testcases/kernel/device-drivers/nvme/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2024 IBM Corporation + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/env_pre.mk +include $(top_srcdir)/include/mk/generic_trunk_target.mk
testcases/kernel/device-drivers/nvme/nvme01 new file binary +0 -0
testcases/kernel/device-drivers/nvme/nvme01.c new file +208 -0
208 lines not on this page · raw message
Signature · 5 lines
2.52.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Priya,
Quoted 5 lines · On Thu, 30 Apr 2026 15:48:52 +0000, priyama2 wrote:
testcases/nvme: Add NVMe device discovery and identification test
This test verifies NVMe device discovery and identification by:
- Detecting NVMe controllers in /dev
[...]
The commit body describes what the test does but not why it is needed — what coverage gap does this fill? Also, "Changes in v2:" belongs in the cover letter, not the commit body; strip it before sending.
Quoted 3 lines
+++ b/testcases/kernel/device-drivers/nvme/nvme01
new file mode 100755
Bin 0 -> 995536 bytes
Do not commit compiled binaries. Remove nvme01 from the patch and add a .gitignore in the test directory listing it.
Quoted 1 line
+ * Copyright (c) 2024 IBM Corporation
This file is new and added in 2026; use the current year.
testcases/kernel/device-drivers/nvme/nvme01.c line 36
Quoted 2 lines
testcases/kernel/device-drivers/nvme/nvme01.c new file +2
-0+static int nvme_device_found; +static char nvme_dev_name[256 ];
These statics are set in case 0 of run() but never cleared. With -i, stale state from a prior iteration persists into subsequent ones. Reset them at the top of run().
testcases/kernel/device-drivers/nvme/nvme01.c line 207
Quoted 1 line
testcases/kernel/device-drivers/nvme/nvme01.c new file +1
-0+ .needs_root = 1,
No operation in this test requires root. All reads from /dev and sysfs are accessible to unprivileged users. Drop needs_root.
The patch is also missing a runtest entry (e.g. in runtest/drivers) and a .gitignore entry for the nvme01 binary.
---
Note:
Our agent completed the review of the patch.
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/1 testcases/nvme: Add NVMe device discovery and identification test
In reply to a message not in the archiveFrom: priyama2 <[email protected]>
This test verifies NVMe device discovery and identification by:
- Detecting NVMe controllers in /dev
- Enumerating namespaces for detected controllers
- Verifying PCI enumeration (class code 0x010802)
- Checking NVMe driver binding
Changes in v2:
- Use LTP buildsystem instead of standalone Makefile
- Remove README file (use doc comments instead)
- Fix author attribution
- Add proper LTP documentation comment format
- Use SAFE_OPENDIR() and SAFE_CLOSEDIR() macros
- Remove obvious and redundant comments
- Code cleanup and style improvements
--- testcases/kernel/device-drivers/nvme/Makefile | 7 + testcases/kernel/device-drivers/nvme/nvme01.c | 208 ++++++++++++++++++ 2 files changed, 215 insertions(+) create mode 100644 testcases/kernel/device-drivers/nvme/Makefile create mode 100644 testcases/kernel/device-drivers/nvme/nvme01.c
testcases/kernel/device-drivers/nvme/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2024 IBM Corporation + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/env_pre.mk +include $(top_srcdir)/include/mk/generic_trunk_target.mk
testcases/kernel/device-drivers/nvme/nvme01.c new file +208 -0
208 lines not on this page · raw message
Signature · 5 lines
2.52.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Priya,
Quoted 1 line · On 2026-04-30, priyama2 <[email protected]> wrote:
[PATCH] testcases/nvme: Add NVMe device discovery and identification test
The subject prefix should match the actual directory path:
testcases/kernel/device-drivers/nvme:
The commit body only describes what the test does (restating the subject). Please add a sentence explaining why the test is needed, e.g. what gap in NVMe coverage this fills.
Quoted 2 lines
+/*
+ * Copyright (c) 2024 IBM Corporation
New files added in 2026 must use 2026 as the copyright year.
[...]
Review
Quoted 2 lines
(quoted diff) +2
-0+SUBDIRS := acpi \ + ...
testcases/kernel/device-drivers/Makefile has an explicit SUBDIRS list that does not include nvme. The directory will not be built. Add nvme to the list.
[...]
testcases/kernel/device-drivers/nvme/nvme01.c line 36
Quoted 2 lines
testcases/kernel/device-drivers/nvme/nvme01.c new file +2
-0+static int nvme_device_found; +static char nvme_dev_name[256 ];
These statics are written in run() case 0 and read in cases 1-3 but are never reset at the top of run(). With -i, stale values from a previous iteration carry over. Reset them at the start of run().
[...]
testcases/kernel/device-drivers/nvme/nvme01.c line 207
Quoted 1 line
testcases/kernel/device-drivers/nvme/nvme01.c new file +1
-0+ .needs_root = 1,
All operations here (reading /dev, /sys) are world-readable. Remove .needs_root = 1.
[...]
testcases/kernel/device-drivers/nvme/nvme01.c line 135
Quoted 5 lines
testcases/kernel/device-drivers/nvme/nvme01.c new file +5
-0+ fp =fopen (class_path,"r" ); +if (!fp) +continue ; + ... +fclose (fp);
Use SAFE_FOPEN/SAFE_FCLOSE (include/tst_safe_stdio.h), or document why the raw call with continue-on-failure is intentional.
[...]
testcases/kernel/device-drivers/nvme/nvme01.c line 160
Quoted 1 line
testcases/kernel/device-drivers/nvme/nvme01.c new file +1
-0+ len =readlink (driver_path, driver_link,sizeof (driver_link) -1 );
Use SAFE_READLINK (include/tst_safe_macros.h).
Also missing:
- testcases/kernel/device-drivers/nvme/.gitignore entry for nvme01
- runtest/ entry for nvme01 (e.g. in runtest/drivers)
---
Note:
Our agent completed the review of the patch. The full review can be found at: (not available)
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 1/1 testcases/kernel/device-drivers/nvme: Add NVMe device discovery test
In reply to a message not in the archiveFrom: priyama2 <[email protected]>
This test fills a gap in NVMe test coverage by validating basic device enumeration and driver binding, which are fundamental prerequisites for any NVMe functionality testing.
The test verifies:
- Detection of NVMe controllers in /dev
- Enumeration of namespaces for detected controllers
- PCI enumeration (class code 0x010802)
- NVMe driver binding
Changes in v3:
- Fix subject prefix to match directory path
- Update copyright year to 2026
- Add nvme to SUBDIRS in testcases/kernel/device-drivers/Makefile
- Reset static variables at start of run() for -i support
- Remove .needs_root (all operations are world-readable)
- Use SAFE_FOPEN/SAFE_FCLOSE for PCI class file access
- Use SAFE_READLINK for driver symlink reading
- Add .gitignore entry for nvme01 binary
- Add runtest/device-drivers entry for nvme01
- Fix author field to use priyama2
Changes in v2:
- Use LTP buildsystem instead of standalone Makefile
- Remove README file (use doc comments instead)
- Add proper LTP documentation comment format
- Use SAFE_OPENDIR() and SAFE_CLOSEDIR() macros
- Remove obvious and redundant comments
- Code cleanup and style improvements
--- runtest/device-drivers | 1 + testcases/kernel/device-drivers/Makefile | 1 + .../kernel/device-drivers/nvme/.gitignore | 1 + testcases/kernel/device-drivers/nvme/Makefile | 7 + testcases/kernel/device-drivers/nvme/nvme01.c | 205 ++++++++++++++++++ 5 files changed, 215 insertions(+) create mode 100644 runtest/device-drivers create mode 100644 testcases/kernel/device-drivers/nvme/.gitignore create mode 100644 testcases/kernel/device-drivers/nvme/Makefile create mode 100644 testcases/kernel/device-drivers/nvme/nvme01.c
runtest/device-drivers new file +1 -0
@@ -0,0 +1 @@ +nvme01 nvme01
testcases/kernel/device-drivers/Makefile +1 -0
@@ -9,6 +9,7 @@ SUBDIRS := acpi \ block \ cpufreq \ locking \ + nvme \ pci \ rcu \ rtc \
testcases/kernel/device-drivers/nvme/.gitignore new file +1 -0
@@ -0,0 +1 @@ +nvme01
testcases/kernel/device-drivers/nvme/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2024 IBM Corporation + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/env_pre.mk +include $(top_srcdir)/include/mk/generic_trunk_target.mk
testcases/kernel/device-drivers/nvme/nvme01.c new file +205 -0
205 lines not on this page · raw message
Signature · 5 lines
2.52.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] testcases/kernel/device-drivers/nvme: Add NVMe device discovery test
Hi priyama2,
Quoted 2 lines · On Fri, 1 May 2026 15:14:20 +0000, priyama2 wrote:
+++ b/testcases/kernel/device-drivers/nvme/Makefile +# Copyright (c) 2024 IBM Corporation
This file is new and added in 2026; the copyright year must match the year of creation. Change 2024 -> 2026.
[...]
Quoted 2 lines
testcases/kernel/device-drivers/nvme/nvme01.c new file +2
-0+static int nvme_device_found; +static char nvme_dev_name[256 ];
[...]
testcases/kernel/device-drivers/nvme/nvme01.c line 190
Quoted 12 lines
testcases/kernel/device-drivers/nvme/nvme01.c new file +12
-0+static void run (unsigned int n) +{ +/* Reset state for each iteration */ + nvme_device_found =0 ; +memset (nvme_dev_name,0 ,sizeof (nvme_dev_name)); + +switch (n) { +case 0 : +test_detect_nvme_controllers (); +break ; +case 1 : +test_enumerate_namespaces ();
With .tcnt = 4, each run(n) is a separate call, so the reset at the top zeroes out nvme_device_found before cases 1-3 can use the value set by case 0. On a machine with NVMe hardware, cases 1-3 always TCONF. Move the device discovery into setup() so the state persists across all run() invocations.
---
Note:
Our agent completed the review of the patch. The full review can be found at: https://github.com/linux-test-project/ltp-agent/actions/runs/25150858409
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3] testcases/kernel/device-drivers/nvme: Add NVMe device discovery test
In reply to [email protected]Hi Priyama,
The patch doesn't compile:
https://github.com/linux-test-project/ltp/actions/runs/25153014278
Kind regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3] testcases/kernel/device-drivers/nvme: Add NVMe device discovery test
In reply to [email protected]Hi Priyama,
Sorry for top-posting, but I have a broader question here.
First of all, thanks for working on this and for looking into NVMe coverage.
Before going further, could you please explain the intended LTP-specific value of
this test? blktests already has a dedicated NVMe test group with much broader
coverage, including controller/namespace discovery, NVMe commands, fabrics, etc.:
https://github.com/linux-blktests/blktests/tree/master/tests/nvme
So I think we should be careful not to duplicate coverage unless there is a clear
reason for having a small LTP-level smoke test as well. Maybe your intention is
different? Could you please clarify?
Cheers,
Sebastian
Quoted 319 lines · On Thu, 30 Apr 2026 at 07:10, <[email protected]> wrote:
From: priyama2 <[email protected]>
This test fills a gap in NVMe test coverage by validating basic device enumeration and driver binding, which are fundamental prerequisites for any NVMe functionality testing.
The test verifies:
- Detection of NVMe controllers in /dev
- Enumeration of namespaces for detected controllers
- PCI enumeration (class code0x010802)
- NVMe driver bindingChanges in v3:
- Fix subject prefix to match directory path
- Update copyright year to 2026
- Add nvme to SUBDIRS in testcases/kernel/device-drivers/Makefile
- Reset static variables at start ofrun()for -i support
- Remove .needs_root (all operations are world-readable)
- Use SAFE_FOPEN/SAFE_FCLOSE for PCI class file access
- UseSAFE_READLINKfor driver symlink reading
- Add .gitignore entry for nvme01 binary
- Add runtest/device-drivers entry for nvme01
- Fix author field to use priyama2Changes in v2:
- Use LTP buildsystem instead of standaloneMakefile
- Remove README file (use doc comments instead)
- Add proper LTP documentation comment format
- UseSAFE_OPENDIR()andSAFE_CLOSEDIR()macros
- Remove obvious and redundant comments
- Code cleanup and style improvementsSigned-off-by priyama2 <[email protected]>--- runtest/device-drivers | 1 + testcases/kernel/device-drivers/Makefile | 1 + .../kernel/device-drivers/nvme/.gitignore | 1 + testcases/kernel/device-drivers/nvme/Makefile | 7 + testcases/kernel/device-drivers/nvme/nvme01.c | 205 ++++++++++++++++++ 5 files changed, 215 insertions(+) create mode 100644 runtest/device-drivers create mode 100644 testcases/kernel/device-drivers/nvme/.gitignore create mode 100644 testcases/kernel/device-drivers/nvme/Makefile create mode 100644 testcases/kernel/device-drivers/nvme/nvme01.cruntest/device-drivers new file +1
-0@@ -0,0 +1 @@ +nvme01 nvme01testcases/kernel/device-drivers/Makefile +1
-0@@ -9,6 +9,7 @@ SUBDIRS := acpi \ block \ cpufreq \ locking \ + nvme \ pci \ rcu \ rtc \testcases/kernel/device-drivers/nvme/.gitignore new file +1
-0@@ -0,0 +1 @@ +nvme01testcases/kernel/device-drivers/nvme/Makefile new file +7
-0@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2024 IBM Corporation + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/env_pre.mk +include $(top_srcdir)/include/mk/generic_trunk_target.mktestcases/kernel/device-drivers/nvme/nvme01.c new file +55
-0@@ -0,0 +1,205 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2026 IBM Corporation +* Author: priyama2 <[email protected]> +*/ + +/* * [Description] +* +* Verify NVMe device discovery and identification. +* +* This test fills a gap in NVMe test coverage by validating basic device +* enumeration and driver binding, which are fundamental prerequisites for +* any NVMe functionality testing. +* +* - Detect NVMe controllers in /dev +* - Enumerate namespaces for detected controllers +* - Verify PCI enumeration (class code 0x010802) +* - Check NVMe driver binding +*/ + +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <dirent.h> +#include <errno.h> + +#include "tst_test.h" +#include "tst_safe_stdio.h" + +#define NVME_DEV_PATH "/dev" +#define NVME_SYS_PATH "/sys/class/nvme" +#define PCI_DEVICES_PATH "/sys/bus/pci/devices" + +static int nvme_device_found; +static char nvme_dev_name[256 ]; + +static void test_detect_nvme_controllers (void ) +{ +DIR *dir; +struct dirent *entry; +int found =0 ; + + dir =SAFE_OPENDIR (NVME_DEV_PATH ); + +tst_res (TINFO ,"Scanning for NVMe devices in %s" ,NVME_DEV_PATH ); + +while ((entry =readdir (dir)) !=NULL ) { +if (strncmp (entry->d_name,"nvme" ,4 ) ==0 && +strlen (entry->d_name) ==5 ) { + tst_res(TINFO, "Found NVMe controller: %s",
entry->d_name);
+ strncpy(nvme_dev_name,entry->d_name,sizeof(nvme_dev_name)- 1);testcases/kernel/device-drivers/nvme/nvme01.c new file +22
-0+ found =1 ; + nvme_device_found =1 ; + } + } + +SAFE_CLOSEDIR (dir); + +if (found) +tst_res (TPASS ,"NVMe controller(s) detected successfully" ); +else +tst_res (TCONF ,"No NVMe controllers found in system" ); +} + +static void test_enumerate_namespaces (void ) +{ +DIR *dir; +struct dirent *entry; +int ns_count =0 ; +char search_pattern[32 ]; + +if (!nvme_device_found) { + tst_res(TCONF, "No NVMe device found, skipping namespaceenumeration");
testcases/kernel/device-drivers/nvme/nvme01.c new file +4
-0+return ; + } + + snprintf(search_pattern, sizeof(search_pattern), "%sn",
nvme_dev_name);testcases/kernel/device-drivers/nvme/nvme01.c new file +7
-0+ + dir =SAFE_OPENDIR (NVME_DEV_PATH ); + +tst_res (TINFO ,"Enumerating namespaces for %s" , nvme_dev_name); + +while ((entry =readdir (dir)) !=NULL ) { + if (strncmp(entry->d_name, search_pattern,
strlen(search_pattern)) == 0) {
+ tst_res(TINFO, "Found namespace: %s",entry->d_name);testcases/kernel/device-drivers/nvme/nvme01.c new file +8
-0+ ns_count++; + } + } + +SAFE_CLOSEDIR (dir); + +if (ns_count >0 ) + tst_res(TPASS, "Enumerated %d namespace(s) successfully",
ns_count);testcases/kernel/device-drivers/nvme/nvme01.c new file +2
-0+else + tst_res(TPASS, "No namespaces found for %s (device may nothave namespaces configured)",
nvme_dev_name);testcases/kernel/device-drivers/nvme/nvme01.c new file +13
-0+} + +static void test_verify_pci_enumeration (void ) +{ +DIR *dir; +struct dirent *entry; +int found =0 ; +char class_path[512 ]; +FILE *fp; +char class_id[16 ]; + +if (!nvme_device_found) { + tst_res(TCONF, "No NVMe device found, skipping PCIenumeration check");
testcases/kernel/device-drivers/nvme/nvme01.c new file +19
-0+return ; + } + + dir =SAFE_OPENDIR (PCI_DEVICES_PATH ); + +tst_res (TINFO ,"Checking PCI enumeration for NVMe devices" ); + +while ((entry =readdir (dir)) !=NULL ) { +if (entry->d_name[0 ] =='.' ) +continue ; + +snprintf (class_path,sizeof (class_path),"%s/%s/class" , +PCI_DEVICES_PATH , entry->d_name); + + fp =SAFE_FOPEN (class_path,"r" ); + +if (fgets (class_id,sizeof (class_id), fp)) { +if (strncmp (class_id,"0x010802" ,8 ) ==0 ) { + tst_res(TINFO, "Found NVMe PCI device: %s(class: %s)",
testcases/kernel/device-drivers/nvme/nvme01.c new file +11
-0+ entry->d_name, class_id); + found =1 ; + } + } +SAFE_FCLOSE (fp); + } + +SAFE_CLOSEDIR (dir); + +if (found) + tst_res(TPASS, "NVMe device properly enumerated on PCIbus");
testcases/kernel/device-drivers/nvme/nvme01.c new file +11
-0+else +tst_res (TFAIL ,"NVMe device not found on PCI bus" ); +} + +static void test_check_driver_binding (void ) +{ +char driver_path[512 ]; +char driver_link[512 ]; + +if (!nvme_device_found) { + tst_res(TCONF, "No NVMe device found, skipping driverbinding check");
testcases/kernel/device-drivers/nvme/nvme01.c new file +14
-0+return ; + } + +snprintf (driver_path,sizeof (driver_path),"%s/%s/device/driver" , +NVME_SYS_PATH , nvme_dev_name); + +SAFE_READLINK (driver_path, driver_link,sizeof (driver_link)); + +tst_res (TINFO ,"Driver binding: %s" , driver_link); + +if (strstr (driver_link,"nvme" ) !=NULL ) +tst_res (TPASS ,"NVMe driver properly bound to device" ); +else + tst_res(TFAIL, "Unexpected driver bound to NVMe device:%s",
driver_link);testcases/kernel/device-drivers/nvme/nvme01.c new file +37
-1+} + +static void setup (void ) +{ +if (access ("/sys/module/nvme" ,F_OK ) !=0 ) +tst_brk (TCONF ,"NVMe kernel module not loaded" ); + +tst_res (TINFO ,"NVMe Device Discovery & Identification Test" ); +} + +static void run (unsigned int n) +{ +/* Reset state for each iteration */ + nvme_device_found =0 ; +memset (nvme_dev_name,0 ,sizeof (nvme_dev_name)); + +switch (n) { +case 0 : +test_detect_nvme_controllers (); +break ; +case 1 : +test_enumerate_namespaces (); +break ; +case 2 : +test_verify_pci_enumeration (); +break ; +case 3 : +test_check_driver_binding (); +break ; + } +} + +static struct tst_test test = { + .test = run, + .tcnt =4 , + .setup = setup, +}; --2.52.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3] testcases/kernel/device-drivers/nvme: Add NVMe device discovery test
Adding Shin'ichiro
Quoted 349 lines · Sebastian Chlad
Hi Priyama,
Sorry for top-posting, but I have a broader question here.
First of all, thanks for working on this and for looking into NVMe coverage.
Before going further, could you please explain the intended LTP-specific value of this test? blktests already has a dedicated NVMe test group with much broader coverage, including controller/namespace discovery, NVMe commands, fabrics, etc.:
https://github.com/linux-blktests/blktests/tree/master/tests/nvme <https://github.com/linux-blktests/blktests/tree/master/tests/nvme>
So I think we should be careful not to duplicate coverage unless there is a clear reason for having a small LTP-level smoke test as well. Maybe your intention is different? Could you please clarify?
Cheers,
SebastianOn Thu, 30 Apr 2026 at 07:10, <[email protected] <mailto:[email protected]>> wrote:
From: priyama2 <[email protected] <mailto:[email protected]>> This test fills a gap in NVMe test coverage by validating basic device enumeration and driver binding, which are fundamental prerequisites for any NVMe functionality testing. The test verifies: - Detection of NVMe controllers in /dev - Enumeration of namespaces for detected controllers - PCI enumeration (class code 0x010802) - NVMe driver binding Changes in v3: - Fix subject prefix to match directory path - Update copyright year to 2026 - Add nvme to SUBDIRS in testcases/kernel/device-drivers/Makefile - Reset static variables at start of run() for -i support - Remove .needs_root (all operations are world-readable) - Use SAFE_FOPEN/SAFE_FCLOSE for PCI class file access - Use SAFE_READLINK for driver symlink reading - Add .gitignore entry for nvme01 binary - Add runtest/device-drivers entry for nvme01 - Fix author field to use priyama2 Changes in v2: - Use LTP buildsystem instead of standalone Makefile - Remove README file (use doc comments instead) - Add proper LTP documentation comment format - Use SAFE_OPENDIR() and SAFE_CLOSEDIR() macros - Remove obvious and redundant comments - Code cleanup and style improvements Signed-off-by: priyama2 <[email protected] <mailto:[email protected]>> --- runtest/device-drivers | 1 + testcases/kernel/device-drivers/Makefile | 1 + .../kernel/device-drivers/nvme/.gitignore | 1 + testcases/kernel/device-drivers/nvme/Makefile | 7 + testcases/kernel/device-drivers/nvme/nvme01.c | 205 ++++++++++++++++++ 5 files changed, 215 insertions(+) create mode 100644 runtest/device-drivers create mode 100644 testcases/kernel/device-drivers/nvme/.gitignore create mode 100644 testcases/kernel/device-drivers/nvme/Makefile create mode 100644 testcases/kernel/device-drivers/nvme/nvme01.c diff --git a/runtest/device-drivers b/runtest/device-drivers new file mode 100644 index 000000000..a7295584e --- /dev/null +++ b/runtest/device-drivers @@ -0,0 +1 @@ +nvme01 nvme01 diff --git a/testcases/kernel/device-drivers/Makefile b/testcases/ kernel/device-drivers/Makefile index 229a50683..664f4cd18 100644 --- a/testcases/kernel/device-drivers/Makefile +++ b/testcases/kernel/device-drivers/Makefile @@ -9,6 +9,7 @@ SUBDIRS := acpi \ block \ cpufreq \ locking \ + nvme \ pci \ rcu \ rtc \ diff --git a/testcases/kernel/device-drivers/nvme/.gitignore b/ testcases/kernel/device-drivers/nvme/.gitignore new file mode 100644 index 000000000..c60bc210c --- /dev/null +++ b/testcases/kernel/device-drivers/nvme/.gitignore @@ -0,0 +1 @@ +nvme01 diff --git a/testcases/kernel/device-drivers/nvme/Makefile b/ testcases/kernel/device-drivers/nvme/Makefile new file mode 100644 index 000000000..d47e99e6a --- /dev/null +++ b/testcases/kernel/device-drivers/nvme/Makefile @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2024 IBM Corporation + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/env_pre.mk <http://env_pre.mk> +include $(top_srcdir)/include/mk/generic_trunk_target.mk <http:// generic_trunk_target.mk> diff --git a/testcases/kernel/device-drivers/nvme/nvme01.c b/ testcases/kernel/device-drivers/nvme/nvme01.c new file mode 100644 index 000000000..3c3cb92ce --- /dev/null +++ b/testcases/kernel/device-drivers/nvme/nvme01.c @@ -0,0 +1,205 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2026 IBM Corporation + * Author: priyama2 <[email protected] <mailto:[email protected]>> + */ + +/* * [Description] + * + * Verify NVMe device discovery and identification. + * + * This test fills a gap in NVMe test coverage by validating basic device + * enumeration and driver binding, which are fundamental prerequisites for + * any NVMe functionality testing. + * + * - Detect NVMe controllers in /dev + * - Enumerate namespaces for detected controllers + * - Verify PCI enumeration (class code 0x010802) + * - Check NVMe driver binding + */ + +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <dirent.h> +#include <errno.h> + +#include "tst_test.h" +#include "tst_safe_stdio.h" + +#define NVME_DEV_PATH "/dev" +#define NVME_SYS_PATH "/sys/class/nvme" +#define PCI_DEVICES_PATH "/sys/bus/pci/devices" + +static int nvme_device_found; +static char nvme_dev_name[256]; + +static void test_detect_nvme_controllers(void) +{ + DIR *dir; + struct dirent *entry; + int found = 0; + + dir = SAFE_OPENDIR(NVME_DEV_PATH); + + tst_res(TINFO, "Scanning for NVMe devices in %s", NVME_DEV_PATH); + + while ((entry = readdir(dir)) != NULL) { + if (strncmp(entry->d_name, "nvme", 4) == 0 && + strlen(entry->d_name) == 5) { + tst_res(TINFO, "Found NVMe controller: %s", entry->d_name); + strncpy(nvme_dev_name, entry->d_name, sizeof(nvme_dev_name) - 1); + found = 1; + nvme_device_found = 1; + } + } + + SAFE_CLOSEDIR(dir); + + if (found) + tst_res(TPASS, "NVMe controller(s) detected successfully"); + else + tst_res(TCONF, "No NVMe controllers found in system"); +} + +static void test_enumerate_namespaces(void) +{ + DIR *dir; + struct dirent *entry; + int ns_count = 0; + char search_pattern[32]; + + if (!nvme_device_found) { + tst_res(TCONF, "No NVMe device found, skipping namespace enumeration"); + return; + } + + snprintf(search_pattern, sizeof(search_pattern), "%sn", nvme_dev_name); + + dir = SAFE_OPENDIR(NVME_DEV_PATH); + + tst_res(TINFO, "Enumerating namespaces for %s", nvme_dev_name); + + while ((entry = readdir(dir)) != NULL) { + if (strncmp(entry->d_name, search_pattern, strlen(search_pattern)) == 0) { + tst_res(TINFO, "Found namespace: %s", entry- >d_name); + ns_count++; + } + } + + SAFE_CLOSEDIR(dir); + + if (ns_count > 0) + tst_res(TPASS, "Enumerated %d namespace(s) successfully", ns_count); + else + tst_res(TPASS, "No namespaces found for %s (device may not have namespaces configured)", nvme_dev_name); +} + +static void test_verify_pci_enumeration(void) +{ + DIR *dir; + struct dirent *entry; + int found = 0; + char class_path[512]; + FILE *fp; + char class_id[16]; + + if (!nvme_device_found) { + tst_res(TCONF, "No NVMe device found, skipping PCI enumeration check"); + return; + } + + dir = SAFE_OPENDIR(PCI_DEVICES_PATH); + + tst_res(TINFO, "Checking PCI enumeration for NVMe devices"); + + while ((entry = readdir(dir)) != NULL) { + if (entry->d_name[0] == '.') + continue; + + snprintf(class_path, sizeof(class_path), "%s/%s/class", + PCI_DEVICES_PATH, entry->d_name); + + fp = SAFE_FOPEN(class_path, "r"); + + if (fgets(class_id, sizeof(class_id), fp)) { + if (strncmp(class_id, "0x010802", 8) == 0) { + tst_res(TINFO, "Found NVMe PCI device: %s (class: %s)", + entry->d_name, class_id); + found = 1; + } + } + SAFE_FCLOSE(fp); + } + + SAFE_CLOSEDIR(dir); + + if (found) + tst_res(TPASS, "NVMe device properly enumerated on PCI bus"); + else + tst_res(TFAIL, "NVMe device not found on PCI bus"); +} + +static void test_check_driver_binding(void) +{ + char driver_path[512]; + char driver_link[512]; + + if (!nvme_device_found) { + tst_res(TCONF, "No NVMe device found, skipping driver binding check"); + return; + } + + snprintf(driver_path, sizeof(driver_path), "%s/%s/device/ driver", + NVME_SYS_PATH, nvme_dev_name); + + SAFE_READLINK(driver_path, driver_link, sizeof(driver_link)); + + tst_res(TINFO, "Driver binding: %s", driver_link); + + if (strstr(driver_link, "nvme") != NULL) + tst_res(TPASS, "NVMe driver properly bound to device"); + else + tst_res(TFAIL, "Unexpected driver bound to NVMe device: %s", driver_link); +} + +static void setup(void) +{ + if (access("/sys/module/nvme", F_OK) != 0) + tst_brk(TCONF, "NVMe kernel module not loaded"); + + tst_res(TINFO, "NVMe Device Discovery & Identification Test"); +} + +static void run(unsigned int n) +{ + /* Reset state for each iteration */ + nvme_device_found = 0; + memset(nvme_dev_name, 0, sizeof(nvme_dev_name)); + + switch (n) { + case 0: + test_detect_nvme_controllers(); + break; + case 1: + test_enumerate_namespaces(); + break; + case 2: + test_verify_pci_enumeration(); + break; + case 3: + test_check_driver_binding(); + break; + } +} + +static struct tst_test test = { + .test = run, + .tcnt = 4, + .setup = setup, +}; -- 2.52.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp <https:// lists.linux.it/listinfo/ltp>
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3] testcases/kernel/device-drivers/nvme: Add NVMe device discovery test
Hi,
Quoted 3 lines · Daniel Wagner
Quoted 3 lines
Before going further, could you please explain the intended LTP- specific value of this test? blktests already has a dedicated NVMe test group with much broader coverage, including controller/namespace discovery, NVMe commands, fabrics, etc.:
I’ve had a quick look at the test attached to this email and I completely agree with Sebastian. This should go into blktests.
We already have a good collection of NVMe-specific tests there, so it would be a perfect fit. Plus, the upstream developers run the blktests suite regularly against both the mainline and 'nvme-next' branches. Moving it there would help us catch any NVMe issues very early on. Honestly, I’m not quite sure how often LTP is executed for NVMe, so this feels like the safer bet!
Thanks,
Daniel
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3] testcases/kernel/device-drivers/nvme: Add NVMe device discovery test
In reply to Daniel WagnerHi Sebastian,
Thank you for raising this important question. After reviewing blktests' coverage, I see the concern about duplication.
*Proposed LTP NVMe Test Suite - System Integration Focus:*
Rather than duplicating blktests' comprehensive NVMe protocol testing, I propose LTP focus on system-level integration and kernel API validation. Here's an overview of the planned test suite:
*1. nvme01 - Device Discovery & System Integration (Current Patch)*
* Basic device enumeration through /sys and /dev interfaces
* Driver binding verification
* *LTP-specific angle*: Validates kernel's sysfs/devfs integration, not NVMe protocol
*2. nvme02 - File System Operations (Planned)*
* Standard POSIX I/O operations (open, read, write, close, fsync)
* O_DIRECT, O_SYNC flag behavior
* mmap() operations on NVMe-backed files
* File locking (flock, fcntl) with NVMe storage
* *Differentiation*: Tests syscall interface, not NVMe commands
*3. nvme03 - Process & Thread Safety (Planned)*
* Concurrent access from multiple processes
* fork() with open NVMe file descriptors
* Thread-safe I/O operations
* Signal handling during NVMe I/O
* *Differentiation*: Multi-process integration, not device-level testing
*4. nvme04 - Resource Management & Limits (Planned)*
* Cgroup I/O throttling with NVMe devices
* ulimit enforcement (RLIMIT_FSIZE, RLIMIT_NOFILE)
* Disk quota behavior on NVMe filesystems
* Memory pressure scenarios
* *Differentiation*: Kernel resource management integration
*Key Differentiators from blktests:*
Aspect blktests LTP (Proposed)
*Focus* NVMe protocol & features System call & kernel API
*Scope* Block layer specifics Multi-subsystem integration
*Interface* NVMe commands, ioctl POSIX syscalls (read/write/open)
*Duration* Comprehensive (longer) Smoke tests (<5 min total)
*Use Case* NVMe validation System regression detection
*Concrete Examples of LTP-Specific Value:*
1. *System Integration*: Does|fsync()|properly flush NVMe write cache through the kernel's VFS layer?
2. *Process Safety*: Can a child process inherit and use parent's NVMe file descriptor after|fork()|?
3. *Resource Limits*: Does cgroup I/O throttling correctly limit NVMe bandwidth?
4. *Platform Coverage*: Does NVMe work in PowerPC LPAR, s390x LPAR, ARM virtualization?
5. *Container Integration*: Are NVMe devices properly accessible in containerized environments?
*Positioning:*
* *blktests*: "Does NVMe hardware/protocol work correctly?"
* *LTP*: "Does the kernel's NVMe integration work with the rest of the system?"
*Current Status & Next Steps:*
The current nvme01 patch is admittedly basic. I'm happy to:
1. *Withdraw*if LTP prefers no NVMe coverage
2. *Refocus*nvme01 on system integration (e.g., test sysfs attribute access patterns)
3. *Proceed*with the differentiated test suite outlined above
4. *Collaborate*with blktests maintainers to ensure no overlap
Please let know which direction would the LTP community prefer?
Best regards, priyama2
Quoted 18 lines · Daniel Wagner
Hi Priyama,
Sorry for top-posting, but I have a broader question here.
First of all, thanks for working on this and for looking into NVMe coverage.
Before going further, could you please explain the intended LTP-specific value of this test? blktests already has a dedicated NVMe test group with much broader coverage, including controller/namespace discovery, NVMe commands, fabrics, etc.:
https://github.com/linux-blktests/blktests/tree/master/tests/nvme <https://github.com/linux-blktests/blktests/tree/master/tests/nvme>
So I think we should be careful not to duplicate coverage unless there is a clear reason for having a small LTP-level smoke test as well. Maybe your intention is different? Could you please clarify?
Cheers,
Sebastian
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3] testcases/kernel/device-drivers/nvme: Add NVMe device discovery test
Hello Priyama,
From blktests maintainer side, let me share my views on your proposal.
Blktests started as the community effort among the kernel storage sub-system developers. It was discussed at LSF/MM 2017, and started as the place to stock test scripts for the kernel stroage sub-system. In my understanding, the developers expect blktests is the test set to run before posting patches for the storage subsystem. In the same manner, I expect and hope that nvme driver patches tested with the nvme test group in blktests, to reduce the load of reviewers and maintainers.
When LTP supports the nvme tests as you propose, what will be your expectation for nvme driver patch submitters? Do you expect they run both blktests nvme test group and LTP nvme group? If so, I suggest to add linux-nvme mailing list to this discussion thread to ask their opinions.
Also, please find my inline comment below.
Quoted 9 lines · On May 25, 2026 / 11:00, priyama2 wrote:
Hi Sebastian,
Thank you for raising this important question. After reviewing blktests' coverage, I see the concern about duplication.
*Proposed LTP NVMe Test Suite - System Integration Focus:*
Rather than duplicating blktests' comprehensive NVMe protocol testing, I propose LTP focus on system-level integration and kernel API validation.
The primary role of the blktests nvme test group is to cover the nvme driver codes in the kernel source tree. It is not intended to test NVMe protocol or NVMe devices. Blktests can be used for NVMe protocol/device testing as just a side effect.
It is often discussed to extend blktests to cover NVMe device compatibility test with Linux nvme driver, but it is still an idea at this moment.
I guess you misunderstood this point, so the list below still has duplications with the blktests coverage. It will make it difficult to tell which test framework (blktests or LTP) to add new nvme driver tests.
Said that, the list below includes testing aspects that is not yet covered. I agree that those ideas are great.
Quoted 74 lines
Here's an overview of the planned test suite:
*1. nvme01 - Device Discovery & System Integration (Current Patch)*
* Basic device enumeration through /sys and /dev interfaces
* Driver binding verification
* *LTP-specific angle*: Validates kernel's sysfs/devfs integration, not NVMe protocol*2. nvme02 - File System Operations (Planned)*
* Standard POSIX I/O operations (open, read, write, close, fsync)
*O_DIRECT,O_SYNCflag behavior
*mmap()operations on NVMe-backed files
* File locking (flock, fcntl) with NVMe storage
* *Differentiation*: Tests syscall interface, not NVMe commands*3. nvme03 - Process & Thread Safety (Planned)*
* Concurrent access from multiple processes
*fork()with open NVMe file descriptors
* Thread-safe I/O operations
* Signal handling during NVMe I/O
* *Differentiation*: Multi-process integration, not device-level testing*4. nvme04 - Resource Management & Limits (Planned)*
* Cgroup I/O throttling with NVMe devices
* ulimit enforcement (RLIMIT_FSIZE,RLIMIT_NOFILE)
* Disk quota behavior on NVMe filesystems
* Memory pressure scenarios
* *Differentiation*: Kernel resource management integration*Key Differentiators from blktests:*
Aspect blktests LTP (Proposed)
*Focus* NVMe protocol & features System call & kernel API
*Scope* Block layer specifics Multi-subsystem integration
*Interface* NVMe commands, ioctl POSIX syscalls (read/write/open)
*Duration* Comprehensive (longer) Smoke tests (<5 min total)
*Use Case* NVMe validation System regression detection*Concrete Examples of LTP-Specific Value:*
1. *System Integration*: Does|fsync()|properly flush NVMe write cache through the kernel's VFS layer?
2. *Process Safety*: Can a child process inherit and use parent's NVMe file descriptor after|fork()|?
3. *Resource Limits*: Does cgroup I/O throttling correctly limit NVMe bandwidth?
4. *Platform Coverage*: Does NVMe work in PowerPC LPAR, s390x LPAR, ARM virtualization?
5. *Container Integration*: Are NVMe devices properly accessible in containerized environments?*Positioning:*
* *blktests*: "Does NVMe hardware/protocol work correctly?"
* *LTP*: "Does the kernel's NVMe integration work with the rest of the system?"*Current Status & Next Steps:*
The current nvme01 patch is admittedly basic. I'm happy to:
1. *Withdraw*if LTP prefers no NVMe coverage
2. *Refocus*nvme01 on system integration (e.g., test sysfs attribute access patterns)
3. *Proceed*with the differentiated test suite outlined above
4. *Collaborate*with blktests maintainers to ensure no overlapPlease let know which direction would the LTP community prefer?
Best regards, priyama2
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3] testcases/kernel/device-drivers/nvme: Add NVMe device discovery test
Hi Priyama, Shin'ichiro,
Quoted 44 lines · Shin'ichiro Kawasaki
Hello Priyama,
From blktests maintainer side, let me share my views on your proposal.
Blktests started as the community effort among the kernel storage sub-system
developers. It was discussed at LSF/MM 2017, and started as the place to stock
test scripts for the kernel stroage sub-system. In my understanding, the developers expect blktests is the test set to run before posting patches for the
storage subsystem. In the same manner, I expect and hope that nvme driver patches tested with the nvme test group in blktests, to reduce the load of reviewers and maintainers.When LTP supports the nvme tests as you propose, what will be your expectation
for nvme driver patch submitters? Do you expect they run both blktests nvme test
group and LTP nvme group? If so, I suggest to add linux-nvme mailing list to
this discussion thread to ask their opinions.Also, please find my inline comment below.
Quoted 9 lines · On May 25, 2026 / 11:00, priyama2 wrote:
Hi Sebastian,
Thank you for raising this important question. After reviewing blktests' coverage, I see the concern about duplication.
*Proposed LTP NVMe Test Suite - System Integration Focus:*
Rather than duplicating blktests' comprehensive NVMe protocol testing, I propose LTP focus on system-level integration and kernel API validation.
The primary role of the blktests nvme test group is to cover the nvme driver
codes in the kernel source tree. It is not intended to test NVMe protocol or
NVMe devices. Blktests can be used for NVMe protocol/device testing as just a
side effect.
Quoted 10 lines
It is often discussed to extend blktests to cover NVMe device
compatibility
test with Linux nvme driver, but it is still an idea at this moment.I guess you misunderstood this point, so the list below still has duplications
with the blktests coverage. It will make it difficult to tell which test framework (blktests or LTP) to add new nvme driver tests.
Personally I agree with the above - the list still has duplications. If we get clinical and define things carefully, we still - I believe - expose ourselves to such duplications in the future. Effectively we would have NVMe tests in both LTP and blktests, people will contribute to both and we end up with competing tests...
LTP is oftentimes used for some regression testing. From this standpoint I would assume it might make sense to introduce some sort
of NVMe sometests - basic coverage to see if things are terribly broken. Personally I would still prefer to use blktests/nvme as that one is well maintained and goes deeper into details.
But yeah your ideas are great however - writing directly - I would just implement them in the blktests, so we end up with more mature coverage in there
rather than spreading the effort on 2 testing tools (ltp and blktests).
I would also emphasize the point made here by Shin'ichiro and earlier by Daniel - blktests are run on the relevant -next trees, so we would be better off
with more mature tests in the blktests.
cheers,
Sebastian
Quoted 80 lines
Said that, the list below includes testing aspects that is not yet
covered.
I agree that those ideas are great.Quoted 74 lines
Here's an overview of the planned test suite:
*1. nvme01 - Device Discovery & System Integration (Current Patch)*
* Basic device enumeration through /sys and /dev interfaces
* Driver binding verification
* *LTP-specific angle*: Validates kernel's sysfs/devfs integration, not NVMe protocol*2. nvme02 - File System Operations (Planned)*
* Standard POSIX I/O operations (open, read, write, close, fsync)
*O_DIRECT,O_SYNCflag behavior
*mmap()operations on NVMe-backed files
* File locking (flock, fcntl) with NVMe storage
* *Differentiation*: Tests syscall interface, not NVMe commands*3. nvme03 - Process & Thread Safety (Planned)*
* Concurrent access from multiple processes
*fork()with open NVMe file descriptors
* Thread-safe I/O operations
* Signal handling during NVMe I/O
* *Differentiation*: Multi-process integration, not device-level testing*4. nvme04 - Resource Management & Limits (Planned)*
* Cgroup I/O throttling with NVMe devices
* ulimit enforcement (RLIMIT_FSIZE,RLIMIT_NOFILE)
* Disk quota behavior on NVMe filesystems
* Memory pressure scenarios
* *Differentiation*: Kernel resource management integration*Key Differentiators from blktests:*
Aspect blktests LTP (Proposed) *Focus* NVMe protocol & features System call & kernel API *Scope* Block layer specifics Multi-subsystem integration *Interface* NVMe commands, ioctl POSIX syscalls (read/write/open) *Duration* Comprehensive (longer) Smoke tests (<5 min total) *Use Case* NVMe validation System regression detection*Concrete Examples of LTP-Specific Value:*
1. *System Integration*: Does|fsync()|properly flush NVMe write cache through the kernel's VFS layer?
2. *Process Safety*: Can a child process inherit and use parent's NVMe file descriptor after|fork()|?
3. *Resource Limits*: Does cgroup I/O throttling correctly limit NVMe bandwidth?
4. *Platform Coverage*: Does NVMe work in PowerPC LPAR, s390x LPAR, ARM virtualization?
5. *Container Integration*: Are NVMe devices properly accessible in containerized environments?*Positioning:*
* *blktests*: "Does NVMe hardware/protocol work correctly?"
* *LTP*: "Does the kernel's NVMe integration work with the rest of the system?"*Current Status & Next Steps:*
The current nvme01 patch is admittedly basic. I'm happy to:
1. *Withdraw*if LTP prefers no NVMe coverage
2. *Refocus*nvme01 on system integration (e.g., test sysfs attribute access patterns)
3. *Proceed*with the differentiated test suite outlined above
4. *Collaborate*with blktests maintainers to ensure no overlapPlease let know which direction would the LTP community prefer?
Best regards, priyama2
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp