anitazha / rpms / ndctl

Forked from rpms/ndctl a year ago
Clone

Blame SOURCES/0165-cxl-test-Add-topology-enumeration-and-hotplug-test.patch

e0018b
From ef85ab79e7a45d19ca329c6e4cad9881a5a904e9 Mon Sep 17 00:00:00 2001
e0018b
From: Dan Williams <dan.j.williams@intel.com>
e0018b
Date: Thu, 28 Apr 2022 15:10:54 -0700
e0018b
Subject: [PATCH 165/217] cxl/test: Add topology enumeration and hotplug test
e0018b
e0018b
Test the re-plug of memdevs, switch ports, root ports, and bus objects.
e0018b
e0018b
Link: https://lore.kernel.org/r/165118385401.1676208.9224280236045777443.stgit@dwillia2-desk3.amr.corp.intel.com
e0018b
Cc: Luis Chamberlain <mcgrof@kernel.org>
e0018b
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
e0018b
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
e0018b
---
e0018b
 test/common          |  12 ++++
e0018b
 test/cxl-topology.sh | 166 +++++++++++++++++++++++++++++++++++++++++++
e0018b
 test/meson.build     |   2 +
e0018b
 3 files changed, 180 insertions(+)
e0018b
 create mode 100644 test/cxl-topology.sh
e0018b
e0018b
diff --git a/test/common b/test/common
e0018b
index fb48795..65615cc 100644
e0018b
--- a/test/common
e0018b
+++ b/test/common
e0018b
@@ -27,6 +27,18 @@ if [ -z $DAXCTL ]; then
e0018b
 	fi
e0018b
 fi
e0018b
 
e0018b
+# CXL
e0018b
+if [ -z $CXL ]; then
e0018b
+	if [ -f "../cxl/cxl" ] && [ -x "../cxl/cxl" ]; then
e0018b
+		export CXL=../cxl/cxl
e0018b
+	elif [ -f "./cxl/cxl" ] && [ -x "./cxl/cxl" ]; then
e0018b
+		export CXL=./cxl/cxl
e0018b
+	else
e0018b
+		echo "Couldn't find a cxl binary"
e0018b
+		exit 1
e0018b
+	fi
e0018b
+fi
e0018b
+
e0018b
 if [ -z $TEST_PATH ]; then
e0018b
 	export TEST_PATH=.
e0018b
 fi
e0018b
diff --git a/test/cxl-topology.sh b/test/cxl-topology.sh
e0018b
new file mode 100644
e0018b
index 0000000..ff11614
e0018b
--- /dev/null
e0018b
+++ b/test/cxl-topology.sh
e0018b
@@ -0,0 +1,166 @@
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
+# THEORY OF OPERATION: Validate the hard coded assumptions of the
e0018b
+# cxl_test.ko module that defines its topology in
e0018b
+# tools/testing/cxl/test/cxl.c. If that model ever changes then the
e0018b
+# paired update must be made to this test.
e0018b
+
e0018b
+# collect cxl_test root device id
e0018b
+json=$($CXL list -b cxl_test)
e0018b
+count=$(jq "length" <<< $json)
e0018b
+((count == 1)) || err "$LINENO"
e0018b
+root=$(jq -r ".[] | .bus" <<< $json)
e0018b
+
e0018b
+
e0018b
+# validate 2 host bridges under a root port
e0018b
+port_sort="sort_by(.port | .[4:] | tonumber)"
e0018b
+json=$($CXL list -b cxl_test -BP)
e0018b
+count=$(jq ".[] | .[\"ports:$root\"] | length" <<< $json)
e0018b
+((count == 2)) || err "$LINENO"
e0018b
+
e0018b
+bridge[0]=$(jq -r ".[] | .[\"ports:$root\"] | $port_sort | .[0].port" <<< $json)
e0018b
+bridge[1]=$(jq -r ".[] | .[\"ports:$root\"] | $port_sort | .[1].port" <<< $json)
e0018b
+
e0018b
+
e0018b
+# validate 2 root ports per host bridge
e0018b
+json=$($CXL list -b cxl_test -T -p ${bridge[0]})
e0018b
+count=$(jq ".[] | .dports | length" <<< $json)
e0018b
+((count == 2)) || err "$LINENO"
e0018b
+
e0018b
+json=$($CXL list -b cxl_test -T -p ${bridge[1]})
e0018b
+count=$(jq ".[] | .dports | length" <<< $json)
e0018b
+((count == 2)) || err "$LINENO"
e0018b
+
e0018b
+
e0018b
+# validate 2 switches per-root port
e0018b
+json=$($CXL list -b cxl_test -P -p ${bridge[0]})
e0018b
+count=$(jq ".[] | .[\"ports:${bridge[0]}\"] | length" <<< $json)
e0018b
+((count == 2)) || err "$LINENO"
e0018b
+
e0018b
+switch[0]=$(jq -r ".[] | .[\"ports:${bridge[0]}\"] | $port_sort | .[0].host" <<< $json)
e0018b
+switch[1]=$(jq -r ".[] | .[\"ports:${bridge[0]}\"] | $port_sort | .[1].host" <<< $json)
e0018b
+
e0018b
+json=$($CXL list -b cxl_test -P -p ${bridge[1]})
e0018b
+count=$(jq ".[] | .[\"ports:${bridge[1]}\"] | length" <<< $json)
e0018b
+((count == 2)) || err "$LINENO"
e0018b
+
e0018b
+switch[2]=$(jq -r ".[] | .[\"ports:${bridge[1]}\"] | $port_sort | .[0].host" <<< $json)
e0018b
+switch[3]=$(jq -r ".[] | .[\"ports:${bridge[1]}\"] | $port_sort | .[1].host" <<< $json)
e0018b
+
e0018b
+
e0018b
+# check that all 8 cxl_test memdevs are enabled by default and have a
e0018b
+# pmem size of 256M
e0018b
+json=$($CXL list -b cxl_test -M)
e0018b
+count=$(jq "map(select(.pmem_size == $((256 << 20)))) | length" <<< $json)
e0018b
+((count == 8)) || err "$LINENO"
e0018b
+
e0018b
+
e0018b
+# validate the expected properties of the 4 root decoders
e0018b
+json=$($CXL list -b cxl_test -D -d root)
e0018b
+port_id=${root:4}
e0018b
+port_id_len=${#port_id}
e0018b
+decoder_sort="sort_by(.decoder | .[$((8+port_id_len)):] | tonumber)"
e0018b
+count=$(jq "[ $decoder_sort | .[0] |
e0018b
+	select(.volatile_capable == true) |
e0018b
+	select(.size == $((256 << 20))) |
e0018b
+	select(.nr_targets == 1) ] | length" <<< $json)
e0018b
+((count == 1)) || err "$LINENO"
e0018b
+
e0018b
+count=$(jq "[ $decoder_sort | .[1] |
e0018b
+	select(.volatile_capable == true) |
e0018b
+	select(.size == $((512 << 20))) |
e0018b
+	select(.nr_targets == 2) ] | length" <<< $json)
e0018b
+((count == 1)) || err "$LINENO"
e0018b
+
e0018b
+count=$(jq "[ $decoder_sort | .[2] |
e0018b
+	select(.pmem_capable == true) |
e0018b
+	select(.size == $((256 << 20))) |
e0018b
+	select(.nr_targets == 1) ] | length" <<< $json)
e0018b
+((count == 1)) || err "$LINENO"
e0018b
+
e0018b
+count=$(jq "[ $decoder_sort | .[3] |
e0018b
+	select(.pmem_capable == true) |
e0018b
+	select(.size == $((512 << 20))) |
e0018b
+	select(.nr_targets == 2) ] | length" <<< $json)
e0018b
+((count == 1)) || err "$LINENO"
e0018b
+
e0018b
+# check that switch ports disappear after all of their memdevs have been
e0018b
+# disabled, and return when the memdevs are enabled.
e0018b
+for s in ${switch[@]}
e0018b
+do
e0018b
+	json=$($CXL list -M -p $s)
e0018b
+	count=$(jq "length" <<< $json)
e0018b
+	((count == 2)) || err "$LINENO"
e0018b
+
e0018b
+	mem[0]=$(jq -r ".[0] | .memdev" <<< $json)
e0018b
+	mem[1]=$(jq -r ".[1] | .memdev" <<< $json)
e0018b
+
e0018b
+	$CXL disable-memdev ${mem[0]} --force
e0018b
+	json=$($CXL list -p $s)
e0018b
+	count=$(jq "length" <<< $json)
e0018b
+	((count == 1)) || err "$LINENO"
e0018b
+
e0018b
+	$CXL disable-memdev ${mem[1]} --force
e0018b
+	json=$($CXL list -p $s)
e0018b
+	count=$(jq "length" <<< $json)
e0018b
+	((count == 0)) || err "$LINENO"
e0018b
+
e0018b
+	$CXL enable-memdev ${mem[0]}
e0018b
+	$CXL enable-memdev ${mem[1]}
e0018b
+
e0018b
+	json=$($CXL list -p $s)
e0018b
+	count=$(jq "length" <<< $json)
e0018b
+	((count == 1)) || err "$LINENO"
e0018b
+
e0018b
+	$CXL disable-port $s --force
e0018b
+	json=$($CXL list -p $s)
e0018b
+	count=$(jq "length" <<< $json)
e0018b
+	((count == 0)) || err "$LINENO"
e0018b
+
e0018b
+	$CXL enable-memdev ${mem[0]} ${mem[1]}
e0018b
+	json=$($CXL list -p $s)
e0018b
+	count=$(jq "length" <<< $json)
e0018b
+	((count == 1)) || err "$LINENO"
e0018b
+done
e0018b
+
e0018b
+
e0018b
+# validate host bridge tear down
e0018b
+for b in ${bridge[@]}
e0018b
+do
e0018b
+	$CXL disable-port $b -f
e0018b
+	json=$($CXL list -M -i -p $b)
e0018b
+	count=$(jq "map(select(.state == \"disabled\")) | length" <<< $json)
e0018b
+	((count == 4)) || err "$LINENO"
e0018b
+
e0018b
+	$CXL enable-port $b -m
e0018b
+	json=$($CXL list -M -p $b)
e0018b
+	count=$(jq "length" <<< $json)
e0018b
+	((count == 4)) || err "$LINENO"
e0018b
+done
e0018b
+
e0018b
+
e0018b
+# validate that the bus can be disabled without issue
e0018b
+$CXL disable-bus $root -f
e0018b
+
e0018b
+
e0018b
+# validate no WARN or lockdep report during the run
e0018b
+log=$(journalctl -r -k --since "-$((SECONDS+1))s")
e0018b
+grep -q "Call Trace" <<< $log && err "$LINENO"
e0018b
+
e0018b
+modprobe -r cxl_test
e0018b
diff --git a/test/meson.build b/test/meson.build
e0018b
index 7ccd451..210dcb0 100644
e0018b
--- a/test/meson.build
e0018b
+++ b/test/meson.build
e0018b
@@ -150,6 +150,7 @@ monitor = find_program('monitor.sh')
e0018b
 max_extent = find_program('max_available_extent_ns.sh')
e0018b
 pfn_meta_errors = find_program('pfn-meta-errors.sh')
e0018b
 track_uuid = find_program('track-uuid.sh')
e0018b
+cxl_topo = find_program('cxl-topology.sh')
e0018b
 
e0018b
 tests = [
e0018b
   [ 'libndctl',               libndctl,		  'ndctl' ],
e0018b
@@ -174,6 +175,7 @@ tests = [
e0018b
   [ 'max_extent_ns',          max_extent,	  'ndctl' ],
e0018b
   [ 'pfn-meta-errors.sh',     pfn_meta_errors,	  'ndctl' ],
e0018b
   [ 'track-uuid.sh',          track_uuid,	  'ndctl' ],
e0018b
+  [ 'cxl-topology.sh',	      cxl_topo,		  'cxl'   ],
e0018b
 ]
e0018b
 
e0018b
 if get_option('destructive').enabled()
e0018b
-- 
e0018b
2.27.0
e0018b