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