Skip to contentSkip to conversation

ndctl,cxl/test: Add a common unit test for creating pmem namespaces

PATCH New [email protected] 1 participant 1 message Jul 9, 2024

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/1 ndctl,cxl/test: Add a common unit test for creating pmem namespaces

From: Alison Schofield <[email protected]>

Replace the nfit-only create.sh unit test with a set of scripts that test pmem namespace creation in either the nfit or cxl environments.

The intent is to do the same reconfiguring of pmem namespaces as was done by create.sh and then expand that with devdax namespaces and create/destroy (no reconfigure) cases.

Script namespace.sh provides the shared functionality. Scripts cxl-namespace and nfit-namespace set up the environments. Scripts cxl-namespace.sh and nfit-namespace.sh kick off the tests.

---
 test/create.sh         | 45 --------------------
 test/cxl-namespace     | 25 +++++++++++
 test/cxl-namespace.sh  |  5 +++
 test/meson.build       |  6 ++-
 test/namespace.sh      | 95 ++++++++++++++++++++++++++++++++++++++++++
 test/nfit-namespace    |  6 +++
 test/nfit-namespace.sh |  5 +++
 7 files changed, 140 insertions(+), 47 deletions(-)
 delete mode 100755 test/create.sh
 create mode 100644 test/cxl-namespace
 create mode 100644 test/cxl-namespace.sh
 create mode 100644 test/namespace.sh
 create mode 100644 test/nfit-namespace
 create mode 100644 test/nfit-namespace.sh
test/create.sh deleted +0 -45
deleted file mode 100755
index 9a6f3733939e..000000000000
@@ -1,45 +0,0 @@
-#!/bin/bash -x
-# SPDX-License-Identifier: GPL-2.0
-# Copyright (C) 2015-2020 Intel Corporation. All rights reserved.
-
-set -e
-
-SECTOR_SIZE="4096"
-rc=77
-
-. $(dirname $0)/common
-
-check_min_kver "4.5" || do_skip "may lack namespace mode attribute"
-
-trap 'err $LINENO' ERR
-
-# setup (reset nfit_test dimms)
-modprobe nfit_test
-reset
-
-rc=1
-
-# create pmem
-dev="x"
-json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -t pmem -m raw)
-eval $(echo $json | json2var )
-[ $dev = "x" ] && echo "fail: $LINENO" && exit 1
-[ $mode != "raw" ] && echo "fail: $LINENO" &&  exit 1
-
-# convert pmem to fsdax mode
-json=$($NDCTL create-namespace -m fsdax -f -e $dev)
-eval $(echo $json | json2var)
-[ $mode != "fsdax" ] && echo "fail: $LINENO" &&  exit 1
-
-# convert pmem to sector mode
-json=$($NDCTL create-namespace -m sector -l $SECTOR_SIZE -f -e $dev)
-eval $(echo $json | json2var)
-[ $sector_size != $SECTOR_SIZE ] && echo "fail: $LINENO" &&  exit 1
-[ $mode != "sector" ] && echo "fail: $LINENO" &&  exit 1
-
-# free capacity for blk creation
-$NDCTL destroy-namespace -f $dev
-
-_cleanup
-
-exit 0
test/cxl-namespace new file +25 -0
new file mode 100644
index 000000000000..8a7c23b8ce95
@@ -0,0 +1,25 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2024 Intel Corporation. All rights reserved.
+
+cxl_create_region()
+{
+	decoder=$($CXL list -b cxl_test -D -d root | jq -r ".[] |
+		select(.pmem_capable == true) |
+		select(.nr_targets == 1) |
+		.decoder")
+
+	port_dev0=$($CXL list -T -d "$decoder" | jq -r ".[] |
+		.targets | .[] | select(.position == 0) | .target")
+	mem0=$($CXL list -M -p "$port_dev0" | jq -r ".[0].memdev")
+
+	region=$($CXL create-region -d "$decoder" -m "$mem0" |
+		jq -r ".region")
+	if [[ ! $region ]]; then
+		err "$LINENO"
+	fi
+}
+
+modprobe -r cxl_test
+modprobe cxl_test
+rc=1
+cxl_create_region
test/cxl-namespace.sh new file +5 -0
new file mode 100644
index 000000000000..15259ea09603
@@ -0,0 +1,5 @@
+#!/bin/bash -Ex
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2024 Intel Corporation. All rights reserved.
+
+. $(dirname $0)/namespace.sh cxl
test/meson.build +4 -2
index a965a79fd6cb..02bd368743b7 100644
@@ -132,7 +132,7 @@ revoke_devmem = executable('revoke_devmem', testcore + [
 
 mmap = executable('mmap', 'mmap.c',)
 
-create = find_program('create.sh')
+nfit_namespace = find_program('nfit-namespace.sh')
 clear = find_program('clear.sh')
 pmem_errors = find_program('pmem-errors.sh')
 daxdev_errors_sh = find_program('daxdev-errors.sh')
@@ -160,11 +160,12 @@ cxl_events = find_program('cxl-events.sh')
 cxl_sanitize = find_program('cxl-sanitize.sh')
 cxl_destroy_region = find_program('cxl-destroy-region.sh')
 cxl_qos_class = find_program('cxl-qos-class.sh')
+cxl_namespace = find_program('cxl-namespace.sh')
 
 tests = [
   [ 'libndctl',               libndctl,		  'ndctl' ],
   [ 'dsm-fail',               dsm_fail,	      	  'ndctl' ],
-  [ 'create.sh',              create,	      	  'ndctl' ],
+  [ 'nfit-namespace.sh',      nfit_namespace,     'ndctl' ],
   [ 'clear.sh',               clear,	      	  'ndctl' ],
   [ 'pmem-errors.sh',         pmem_errors,    	  'ndctl' ],
   [ 'daxdev-errors.sh',       daxdev_errors_sh,	  'dax'	  ],
@@ -192,6 +193,7 @@ tests = [
   [ 'cxl-sanitize.sh',        cxl_sanitize,       'cxl'   ],
   [ 'cxl-destroy-region.sh',  cxl_destroy_region, 'cxl'   ],
   [ 'cxl-qos-class.sh',       cxl_qos_class,      'cxl'   ],
+  [ 'cxl-namespace.sh',       cxl_namespace,      'cxl'   ],
 ]
 
 if get_option('destructive').enabled()
test/namespace.sh new file +95 -0

95 lines not on this page · raw message

test/nfit-namespace new file +6 -0
new file mode 100644
index 000000000000..1f7db4051537
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2024 Intel Corporation. All rights reserved.
+
+modprobe -r nfit_test
+modprobe nfit_test
+reset
test/nfit-namespace.sh new file +5 -0
new file mode 100644
index 000000000000..28f4deac69d6
@@ -0,0 +1,5 @@
+#!/bin/bash -Ex
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2024 Intel Corporation. All rights reserved.
+
+. $(dirname $0)/namespace.sh nfit

base-commit: 16f45755f991f4fb6d76fec70a42992426c84234

Signature · 1 line
2.37.3