cxl: Add CXL type2 accelerator unit test
Dave Jiang
maintainerPATCH v2 1/1 cxl: Add CXL type2 accelerator unit test
CXL type2 hierachy can be setup via the cxl_test. Add a regression test unit to CXL CLI to verify the type2 loading/unloading. Test include removing the root port and bringing it back, unbinding the type2 mock device driver and bringing it back, and checking to see if a region can be destroyed and a memdev can be disabled.
---
v2:
- Load/unload module once for test. (Alison)
- Add additional tests. (Alison)
--- test/cxl-type2.sh | 103 ++++++++++++++++++++++++++++++++++++++++++++++ test/meson.build | 2 + 2 files changed, 105 insertions(+) create mode 100644 test/cxl-type2.sh
test/cxl-type2.sh new file +103 -0
@@ -0,0 +1,103 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2026 Intel Corporation. All rights reserved. + +. "$(dirname "$0")"/common + +rc=77 +set -ex +trap 'err $LINENO' ERR +check_prereq "jq" + +remove_kmod() { + modprobe -r cxl_test +} + +load_kmod() { + modprobe cxl_test type2_test=1 +} + +init_check() { + load_kmod + [ -f /sys/module/cxl_test/parameters/type2_test ] || \ + do_skip "cxl_test type2_test module param not available" + region=$("$CXL" list -b "$CXL_TEST_BUS" -R | jq -r '.[0].region') + [ -n "$region" ] || err "$LINENO" +} + +# Test rootport disable/enable case +cycle_root_port() { + echo "Testing root port disable/enable" + memdev=$("$CXL" list -b "$CXL_TEST_BUS" -M | jq -r '.[0].memdev') + [ -n "$memdev" ] || err "$LINENO" + port=$("$CXL" list -b "$CXL_TEST_BUS" -m "$memdev" -P | jq -r '.[0].port') + [ -n "$port" ] || err "$LINENO" + + "$CXL" disable-port "$port" -f + region=$("$CXL" list -b "$CXL_TEST_BUS" -R | jq -r '.[0].region // empty') + [ -z "$region" ] || err "$LINENO" + + "$CXL" enable-port "$port" + echo cxl_type2_accel.0 > /sys/bus/platform/drivers/cxl_mock_accel/bind + region=$("$CXL" list -b "$CXL_TEST_BUS" -R | jq -r '.[0].region') + [ -n "$region" ] || err "$LINENO" +} + +# Test rebind device driver +cycle_pdev_driver() { + echo "Testing device driver unbind/bind" + region=$("$CXL" list -b "$CXL_TEST_BUS" -R | jq -r '.[0].region') + [ -n "$region" ] || err "$LINENO" + echo cxl_type2_accel.0 > /sys/bus/platform/drivers/cxl_mock_accel/unbind + region=$("$CXL" list -b "$CXL_TEST_BUS" -R | jq -r '.[0].region // empty') + [ -z "$region" ] || err "$LINENO" + echo cxl_type2_accel.0 > /sys/bus/platform/drivers/cxl_mock_accel/bind + region=$("$CXL" list -b "$CXL_TEST_BUS" -R | jq -r '.[0].region') + [ -n "$region" ] || err "$LINENO" +} + +# Test memdev removal with CXL CLI +test_dev_removal() { + echo "Testing device removal with CXL CLI" + region=$("$CXL" list -b "$CXL_TEST_BUS" -R | jq -r '.[0].region') + [ -n "$region" ] || err "$LINENO" + "$CXL" disable-region "$region" + region=$("$CXL" list -b "$CXL_TEST_BUS" -R | jq -r '.[0].region // empty') + [ -z "$region" ] || err "$LINENO" + + # type2 region is auto region and cannot be destroyed + region=$("$CXL" list -b "$CXL_TEST_BUS" -Ri | jq -r '.[0].region // empty') + [ -n "$region" ] || err "$LINENO" + "$CXL" destroy-region "$region" || true + region=$("$CXL" list -b "$CXL_TEST_BUS" -Ri | jq -r '.[0].region // empty') + [ -n "$region" ] || err "$LINENO" + + # Do it directly via sysfs since CXL CLI has checks that will skip sysfs + echo "0" | tee /sys/bus/cxl/devices/"$region"/commit || true + region=$("$CXL" list -b "$CXL_TEST_BUS" -Ri | jq -r '.[0].region // empty') + [ -n "$region" ] || err "$LINENO" + + # Make sure there's no delete_region for a type2 root decoder + rd=$("$CXL" list -b "$CXL_TEST_BUS" -r"$region" -D | jq -r '.[0]."root decoders"[0].decoder') + [ -n "$rd" ] || err "$LINENO" + [ ! -f /sys/bus/cxl/devices/"$rd"/delete_region ] || err "$LINENO" + + memdev=$("$CXL" list -b "$CXL_TEST_BUS" -M | jq -r '.[0].memdev') + [ -n "$memdev" ] || err "$LINENO" + + # memdev is not expected to be removed because region can't be destroyed + "$CXL" disable-memdev "$memdev" || true + memdev=$("$CXL" list -b "$CXL_TEST_BUS" -M | jq -r '.[0].memdev // empty') + [ -n "$memdev" ] || err "$LINENO" +} + +remove_kmod +init_check +rc=1 + +cycle_root_port +cycle_pdev_driver +test_dev_removal + +check_dmesg "$LINENO" +remove_kmod
test/meson.build +2 -0
@@ -171,6 +171,7 @@ cxl_translate = find_program('cxl-translate.sh') cxl_elc = find_program('cxl-elc.sh') cxl_dax_hmem = find_program('cxl-dax-hmem.sh') cxl_region_replay = find_program('cxl-region-replay.sh') +cxl_type2 = find_program('cxl-type2.sh') tests = [ [ 'libndctl', libndctl, 'ndctl' ],
@@ -207,6 +208,7 @@ tests = [ [ 'cxl-elc.sh', cxl_elc, 'cxl' ], [ 'cxl-dax-hmem.sh', cxl_dax_hmem, 'cxl' ], [ 'cxl-region-replay.sh', cxl_region_replay, 'cxl' ], + [ 'cxl-type2.sh', cxl_type2, 'cxl' ], ] if get_option('destructive').enabled()
base-commit: 81c7cdd6cbcb4f1f77870ff02d8dd86298036f58
Signature · 1 line
2.54.0
Alison Schofield
maintainerQuoted 1 line · Dave Jiang
CXL type2 hierachy can be setup via the
cxl_test. Add a regression test
hierarchy
Quoted 1 line
unit to CXL CLI to verify the type2 loading/unloading. Test include
Tests
Quoted 4 lines
removing the root port and bringing it back, unbinding the type2 mock device driver and bringing it back, and checking to see if a region can be destroyed and a memdev can be disabled.
Hi Dave,
FWIW I tested this v2 using v1 of the kernel cxl-test patchset. Doubtful, but possible, I may have more comments when I sync up with v2 of the kernel set.
snip
test/cxl-type2.sh line 25
Quoted 7 lines
test/cxl-type2.sh new file +7
-0+ +init_check() { + load_kmod + [ -f /sys/module/cxl_test/parameters/type2_test ] || \ + do_skip "cxl_test type2_test module param not available" + region=$("$CXL" list -b "$CXL_TEST_BUS" -R | jq -r '.[0].region') + [ -n "$region" ] || err "$LINENO"
This needs the //empty treatment so that if the cxl-test module doesn't provide the autoregion upon load, we fail right here.
It looks like //empty is used to verify removal or disappearance cases, but not in the positive discovery checks where we depend on cxl-test topology to provide a valid object. Everywhere that jq result is treated as a shell string testing for existence, it needs the check. That keeps the failure messages 'on point'.
snip