Blame SOURCES/0198-test-add-a-cxl-create-region-test.patch

2eb93d
From 11ca099b52ec339b7464946db144e60399ffa344 Mon Sep 17 00:00:00 2001
2eb93d
From: Vishal Verma <vishal.l.verma@intel.com>
2eb93d
Date: Mon, 15 Aug 2022 13:22:13 -0600
2eb93d
Subject: [PATCH 198/217] test: add a cxl-create-region test
2eb93d
2eb93d
Add a unit test to exercise the cxl-create-region command with different
2eb93d
combinations of memdevs and decoders, using cxl_test based mocked
2eb93d
devices.
2eb93d
2eb93d
Link: https://lore.kernel.org/r/20220815192214.545800-11-vishal.l.verma@intel.com
2eb93d
Cc: Dan Williams <dan.j.williams@intel.com>
2eb93d
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
2eb93d
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
2eb93d
---
2eb93d
 test/cxl-create-region.sh | 125 ++++++++++++++++++++++++++++++++++++++
2eb93d
 test/meson.build          |   2 +
2eb93d
 2 files changed, 127 insertions(+)
2eb93d
 create mode 100644 test/cxl-create-region.sh
2eb93d
2eb93d
diff --git a/test/cxl-create-region.sh b/test/cxl-create-region.sh
2eb93d
new file mode 100644
2eb93d
index 0000000..66df38f
2eb93d
--- /dev/null
2eb93d
+++ b/test/cxl-create-region.sh
2eb93d
@@ -0,0 +1,125 @@
2eb93d
+#!/bin/bash
2eb93d
+# SPDX-License-Identifier: GPL-2.0
2eb93d
+# Copyright (C) 2022 Intel Corporation. All rights reserved.
2eb93d
+
2eb93d
+. $(dirname $0)/common
2eb93d
+
2eb93d
+rc=1
2eb93d
+
2eb93d
+set -ex
2eb93d
+
2eb93d
+trap 'err $LINENO' ERR
2eb93d
+
2eb93d
+check_prereq "jq"
2eb93d
+
2eb93d
+modprobe -r cxl_test
2eb93d
+modprobe cxl_test
2eb93d
+udevadm settle
2eb93d
+
2eb93d
+destroy_regions()
2eb93d
+{
2eb93d
+	if [[ "$*" ]]; then
2eb93d
+		$CXL destroy-region -f -b cxl_test "$@"
2eb93d
+	else
2eb93d
+		$CXL destroy-region -f -b cxl_test all
2eb93d
+	fi
2eb93d
+}
2eb93d
+
2eb93d
+create_x1_region()
2eb93d
+{
2eb93d
+	mem="$1"
2eb93d
+
2eb93d
+	# find a pmem capable root decoder for this mem
2eb93d
+	decoder=$($CXL list -b cxl_test -D -d root -m "$mem" |
2eb93d
+		  jq -r ".[] |
2eb93d
+		  select(.pmem_capable == true) |
2eb93d
+		  select(.nr_targets == 1) |
2eb93d
+		  .decoder")
2eb93d
+
2eb93d
+	if [[ ! $decoder ]]; then
2eb93d
+		echo "no suitable decoder found for $mem, skipping"
2eb93d
+		return
2eb93d
+	fi
2eb93d
+
2eb93d
+	# create region
2eb93d
+	region=$($CXL create-region -d "$decoder" -m "$mem" | jq -r ".region")
2eb93d
+
2eb93d
+	if [[ ! $region ]]; then
2eb93d
+		echo "create-region failed for $decoder / $mem"
2eb93d
+		err "$LINENO"
2eb93d
+	fi
2eb93d
+
2eb93d
+	# cycle disable/enable
2eb93d
+	$CXL disable-region --bus=cxl_test "$region"
2eb93d
+	$CXL enable-region --bus=cxl_test "$region"
2eb93d
+
2eb93d
+	# cycle destroying and creating the same region
2eb93d
+	destroy_regions "$region"
2eb93d
+	region=$($CXL create-region -d "$decoder" -m "$mem" | jq -r ".region")
2eb93d
+
2eb93d
+	if [[ ! $region ]]; then
2eb93d
+		echo "create-region failed for $decoder / $mem"
2eb93d
+		err "$LINENO"
2eb93d
+	fi
2eb93d
+	destroy_regions "$region"
2eb93d
+}
2eb93d
+
2eb93d
+create_subregions()
2eb93d
+{
2eb93d
+	slice=$((256 << 20))
2eb93d
+	mem="$1"
2eb93d
+
2eb93d
+	# find a pmem capable root decoder for this mem
2eb93d
+	decoder=$($CXL list -b cxl_test -D -d root -m "$mem" |
2eb93d
+		  jq -r ".[] |
2eb93d
+		  select(.pmem_capable == true) |
2eb93d
+		  select(.nr_targets == 1) |
2eb93d
+		  .decoder")
2eb93d
+
2eb93d
+	if [[ ! $decoder ]]; then
2eb93d
+		echo "no suitable decoder found for $mem, skipping"
2eb93d
+		return
2eb93d
+	fi
2eb93d
+
2eb93d
+	size="$($CXL list -m "$mem" | jq -r '.[].pmem_size')"
2eb93d
+	if [[ ! $size ]]; then
2eb93d
+		echo "$mem: unable to determine size"
2eb93d
+		err "$LINENO"
2eb93d
+	fi
2eb93d
+
2eb93d
+	num_regions=$((size / slice))
2eb93d
+
2eb93d
+	declare -a regions
2eb93d
+	for (( i = 0; i < num_regions; i++ )); do
2eb93d
+		regions[$i]=$($CXL create-region -d "$decoder" -m "$mem" -s "$slice" | jq -r ".region")
2eb93d
+		if [[ ! ${regions[$i]} ]]; then
2eb93d
+			echo "create sub-region failed for $decoder / $mem"
2eb93d
+			err "$LINENO"
2eb93d
+		fi
2eb93d
+		udevadm settle
2eb93d
+	done
2eb93d
+
2eb93d
+	echo "created $num_regions subregions:"
2eb93d
+	for (( i = 0; i < num_regions; i++ )); do
2eb93d
+		echo "${regions[$i]}"
2eb93d
+	done
2eb93d
+
2eb93d
+	for (( i = (num_regions - 1); i >= 0; i-- )); do
2eb93d
+		destroy_regions "${regions[$i]}"
2eb93d
+	done
2eb93d
+}
2eb93d
+
2eb93d
+# test reading labels directly through cxl-cli
2eb93d
+readarray -t mems < <("$CXL" list -b cxl_test -M | jq -r '.[].memdev')
2eb93d
+
2eb93d
+for mem in ${mems[@]}; do
2eb93d
+	create_x1_region "$mem"
2eb93d
+done
2eb93d
+
2eb93d
+# test multiple subregions under the same decoder, using slices of the same memdev
2eb93d
+# to test out back-to-back pmem DPA allocations on memdevs
2eb93d
+for mem in ${mems[@]}; do
2eb93d
+	create_subregions "$mem"
2eb93d
+done
2eb93d
+
2eb93d
+modprobe -r cxl_test
2eb93d
diff --git a/test/meson.build b/test/meson.build
2eb93d
index b382f46..5953c28 100644
2eb93d
--- a/test/meson.build
2eb93d
+++ b/test/meson.build
2eb93d
@@ -153,6 +153,7 @@ track_uuid = find_program('track-uuid.sh')
2eb93d
 cxl_topo = find_program('cxl-topology.sh')
2eb93d
 cxl_sysfs = find_program('cxl-region-sysfs.sh')
2eb93d
 cxl_labels = find_program('cxl-labels.sh')
2eb93d
+cxl_create_region = find_program('cxl-create-region.sh')
2eb93d
 
2eb93d
 tests = [
2eb93d
   [ 'libndctl',               libndctl,		  'ndctl' ],
2eb93d
@@ -180,6 +181,7 @@ tests = [
2eb93d
   [ 'cxl-topology.sh',	      cxl_topo,		  'cxl'   ],
2eb93d
   [ 'cxl-region-sysfs.sh',    cxl_sysfs,	  'cxl'   ],
2eb93d
   [ 'cxl-labels.sh',          cxl_labels,	  'cxl'   ],
2eb93d
+  [ 'cxl-create-region.sh',   cxl_create_region,  'cxl'   ],
2eb93d
 ]
2eb93d
 
2eb93d
 if get_option('destructive').enabled()
2eb93d
-- 
2eb93d
2.27.0
2eb93d