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