new file mode 100644
@@ -0,0 +1,78 @@
+#!/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
+
+# The number or errors that cxl_test mocks is subject to change.
+NR_ERRS=2
+
+# THEORY OF OPERATION: Exercise cxl-cli and cxl driver capabilites wrt
+# retrieving poison lists. The poison list is maintained by the device.
+# It may be requested per memdev or per region.
+
+create_region()
+{
+ region=$($CXL create-region -d $decoder -m $memdevs | jq -r ".region")
+
+ if [[ ! $region ]]; then
+ echo "create-region failed for $decoder"
+ err "$LINENO"
+ fi
+}
+
+setup_x2_region()
+{
+ # Find an x2 decoder
+ decoder=$($CXL list -b cxl_test -D -d root | jq -r ".[] |
+ select(.pmem_capable == true) |
+ select(.nr_targets == 2) |
+ .decoder")
+
+ # Find a memdev for each host-bridge interleave position
+ port_dev0=$($CXL list -T -d $decoder | jq -r ".[] |
+ .targets | .[] | select(.position == 0) | .target")
+ port_dev1=$($CXL list -T -d $decoder | jq -r ".[] |
+ .targets | .[] | select(.position == 1) | .target")
+ mem0=$($CXL list -M -p $port_dev0 | jq -r ".[0].memdev")
+ mem1=$($CXL list -M -p $port_dev1 | jq -r ".[0].memdev")
+ memdevs="$mem0 $mem1"
+}
+
+find_media_errors()
+{
+ nr=$(echo $json | jq -r ".nr_media_errors")
+ if [[ $nr -ne $NR_ERRS ]]; then
+ echo "$mem: $NR_ERRS media errors expected, $nr found"
+ err "$LINENO"
+ fi
+}
+
+# Read poison from each available memdev
+readarray -t mems < <("$CXL" list -b cxl_test -Mi | jq -r '.[].memdev')
+for mem in ${mems[@]}; do
+ json=$("$CXL" list -m "$mem" --media-errors | jq -r '.[].media_errors')
+ find_media_errors
+done
+
+# Read poison from one region
+setup_x2_region
+create_region
+json=$("$CXL" list -r "$region" --media-errors | jq -r '.[].media_errors')
+find_media_errors
+cxl disable-region $region
+cxl destroy-region $region
+
+modprobe -r cxl_test
@@ -154,6 +154,7 @@ 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')
+cxl_get_poison = find_program('cxl-get-poison.sh')
tests = [
[ 'libndctl', libndctl, 'ndctl' ],
@@ -182,6 +183,7 @@ tests = [
[ 'cxl-region-sysfs.sh', cxl_sysfs, 'cxl' ],
[ 'cxl-labels.sh', cxl_labels, 'cxl' ],
[ 'cxl-create-region.sh', cxl_create_region, 'cxl' ],
+ [ 'cxl-get-poison.sh', cxl_get_poison, 'cxl' ],
]
if get_option('destructive').enabled()