All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vishal Verma <vishal.l.verma@intel.com>
To: <linux-cxl@vger.kernel.org>
Cc: <nvdimm@lists.linux.dev>, Dan Williams <dan.j.williams@intel.com>,
	Alison Schofield <alison.schofield@intel.com>,
	Ira Weiny <ira.weiny@intel.com>,
	Dave Jiang <dave.jiang@intel.com>,
	Vishal Verma <vishal.l.verma@intel.com>
Subject: [ndctl PATCH v3 10/11] test: add a cxl-create-region test
Date: Mon, 15 Aug 2022 13:22:13 -0600	[thread overview]
Message-ID: <20220815192214.545800-11-vishal.l.verma@intel.com> (raw)
In-Reply-To: <20220815192214.545800-1-vishal.l.verma@intel.com>

Add a unit test to exercise the cxl-create-region command with different
combinations of memdevs and decoders, using cxl_test based mocked
devices.

Cc: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 test/cxl-create-region.sh | 125 ++++++++++++++++++++++++++++++++++++++
 test/meson.build          |   2 +
 2 files changed, 127 insertions(+)
 create mode 100644 test/cxl-create-region.sh

diff --git a/test/cxl-create-region.sh b/test/cxl-create-region.sh
new file mode 100644
index 0000000..66df38f
--- /dev/null
+++ b/test/cxl-create-region.sh
@@ -0,0 +1,125 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2022 Intel Corporation. All rights reserved.
+
+. $(dirname $0)/common
+
+rc=1
+
+set -ex
+
+trap 'err $LINENO' ERR
+
+check_prereq "jq"
+
+modprobe -r cxl_test
+modprobe cxl_test
+udevadm settle
+
+destroy_regions()
+{
+	if [[ "$*" ]]; then
+		$CXL destroy-region -f -b cxl_test "$@"
+	else
+		$CXL destroy-region -f -b cxl_test all
+	fi
+}
+
+create_x1_region()
+{
+	mem="$1"
+
+	# find a pmem capable root decoder for this mem
+	decoder=$($CXL list -b cxl_test -D -d root -m "$mem" |
+		  jq -r ".[] |
+		  select(.pmem_capable == true) |
+		  select(.nr_targets == 1) |
+		  .decoder")
+
+	if [[ ! $decoder ]]; then
+		echo "no suitable decoder found for $mem, skipping"
+		return
+	fi
+
+	# create region
+	region=$($CXL create-region -d "$decoder" -m "$mem" | jq -r ".region")
+
+	if [[ ! $region ]]; then
+		echo "create-region failed for $decoder / $mem"
+		err "$LINENO"
+	fi
+
+	# cycle disable/enable
+	$CXL disable-region --bus=cxl_test "$region"
+	$CXL enable-region --bus=cxl_test "$region"
+
+	# cycle destroying and creating the same region
+	destroy_regions "$region"
+	region=$($CXL create-region -d "$decoder" -m "$mem" | jq -r ".region")
+
+	if [[ ! $region ]]; then
+		echo "create-region failed for $decoder / $mem"
+		err "$LINENO"
+	fi
+	destroy_regions "$region"
+}
+
+create_subregions()
+{
+	slice=$((256 << 20))
+	mem="$1"
+
+	# find a pmem capable root decoder for this mem
+	decoder=$($CXL list -b cxl_test -D -d root -m "$mem" |
+		  jq -r ".[] |
+		  select(.pmem_capable == true) |
+		  select(.nr_targets == 1) |
+		  .decoder")
+
+	if [[ ! $decoder ]]; then
+		echo "no suitable decoder found for $mem, skipping"
+		return
+	fi
+
+	size="$($CXL list -m "$mem" | jq -r '.[].pmem_size')"
+	if [[ ! $size ]]; then
+		echo "$mem: unable to determine size"
+		err "$LINENO"
+	fi
+
+	num_regions=$((size / slice))
+
+	declare -a regions
+	for (( i = 0; i < num_regions; i++ )); do
+		regions[$i]=$($CXL create-region -d "$decoder" -m "$mem" -s "$slice" | jq -r ".region")
+		if [[ ! ${regions[$i]} ]]; then
+			echo "create sub-region failed for $decoder / $mem"
+			err "$LINENO"
+		fi
+		udevadm settle
+	done
+
+	echo "created $num_regions subregions:"
+	for (( i = 0; i < num_regions; i++ )); do
+		echo "${regions[$i]}"
+	done
+
+	for (( i = (num_regions - 1); i >= 0; i-- )); do
+		destroy_regions "${regions[$i]}"
+	done
+}
+
+# test reading labels directly through cxl-cli
+readarray -t mems < <("$CXL" list -b cxl_test -M | jq -r '.[].memdev')
+
+for mem in ${mems[@]}; do
+	create_x1_region "$mem"
+done
+
+# test multiple subregions under the same decoder, using slices of the same memdev
+# to test out back-to-back pmem DPA allocations on memdevs
+for mem in ${mems[@]}; do
+	create_subregions "$mem"
+done
+
+modprobe -r cxl_test
diff --git a/test/meson.build b/test/meson.build
index b382f46..5953c28 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -153,6 +153,7 @@ track_uuid = find_program('track-uuid.sh')
 cxl_topo = find_program('cxl-topology.sh')
 cxl_sysfs = find_program('cxl-region-sysfs.sh')
 cxl_labels = find_program('cxl-labels.sh')
+cxl_create_region = find_program('cxl-create-region.sh')
 
 tests = [
   [ 'libndctl',               libndctl,		  'ndctl' ],
@@ -180,6 +181,7 @@ tests = [
   [ 'cxl-topology.sh',	      cxl_topo,		  'cxl'   ],
   [ 'cxl-region-sysfs.sh',    cxl_sysfs,	  'cxl'   ],
   [ 'cxl-labels.sh',          cxl_labels,	  'cxl'   ],
+  [ 'cxl-create-region.sh',   cxl_create_region,  'cxl'   ],
 ]
 
 if get_option('destructive').enabled()
-- 
2.37.1


  parent reply	other threads:[~2022-08-15 19:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-15 19:22 [ndctl PATCH v3 00/11] cxl: add region management Vishal Verma
2022-08-15 19:22 ` [ndctl PATCH v3 01/11] libcxl: add a depth attribute to cxl_port Vishal Verma
2022-08-15 19:22 ` [ndctl PATCH v3 02/11] cxl/port: Consolidate the debug option in cxl-port man pages Vishal Verma
2022-08-15 19:22 ` [ndctl PATCH v3 03/11] cxl/memdev: refactor decoder mode string parsing Vishal Verma
2022-08-15 22:57   ` Dan Williams
2022-08-15 19:22 ` [ndctl PATCH v3 04/11] libcxl: Introduce libcxl region and mapping objects Vishal Verma
2022-08-15 19:22 ` [ndctl PATCH v3 05/11] cxl-cli: add region listing support Vishal Verma
2022-08-15 19:22 ` [ndctl PATCH v3 06/11] libcxl: add low level APIs for region creation Vishal Verma
2022-08-15 19:22 ` [ndctl PATCH v3 07/11] cxl: add a 'create-region' command Vishal Verma
2022-08-15 19:22 ` [ndctl PATCH v3 08/11] cxl: add commands to {enable,disable,destroy}-region Vishal Verma
2022-08-15 19:22 ` [ndctl PATCH v3 09/11] cxl/list: make memdevs and regions the default listing Vishal Verma
2022-08-15 19:22 ` Vishal Verma [this message]
2022-08-15 19:22 ` [ndctl PATCH v3 11/11] cxl/decoder: add a max_available_extent attribute Vishal Verma

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220815192214.545800-11-vishal.l.verma@intel.com \
    --to=vishal.l.verma@intel.com \
    --cc=alison.schofield@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=ira.weiny@intel.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.