diff mbox series

[NDCTL,v7,4/4] ndctl: add test for qos_class in CXL test suite

Message ID 20240208201435.2081583-5-dave.jiang@intel.com (mailing list archive)
State Superseded
Headers show
Series [NDCTL,v7,1/4] ndctl: cxl: Add QoS class retrieval for the root decoder | expand

Commit Message

Dave Jiang Feb. 8, 2024, 8:11 p.m. UTC
Add tests in cxl-qos-class.sh to verify qos_class are set with the fake
qos_class create by the kernel.  Root decoders should have qos_class
attribute set. Memory devices should have ram_qos_class or pmem_qos_class
set depending on which partitions are valid.

Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
v7:
- Add create_region -Q testing (Vishal)
---
 test/common           |   4 ++
 test/cxl-qos-class.sh | 102 ++++++++++++++++++++++++++++++++++++++++++
 test/meson.build      |   2 +
 3 files changed, 108 insertions(+)
 create mode 100755 test/cxl-qos-class.sh

Comments

Verma, Vishal L Feb. 22, 2024, 7:59 a.m. UTC | #1
On Thu, 2024-02-08 at 13:11 -0700, Dave Jiang wrote:
> Add tests in cxl-qos-class.sh to verify qos_class are set with the fake
> qos_class create by the kernel.  Root decoders should have qos_class
> attribute set. Memory devices should have ram_qos_class or pmem_qos_class
> set depending on which partitions are valid.
> 
> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
> ---
> v7:
> - Add create_region -Q testing (Vishal)
> ---
>  test/common           |   4 ++
>  test/cxl-qos-class.sh | 102 ++++++++++++++++++++++++++++++++++++++++++
>  test/meson.build      |   2 +
>  3 files changed, 108 insertions(+)
>  create mode 100755 test/cxl-qos-class.sh
> 
> diff --git a/test/common b/test/common
> index f1023ef20f7e..5694820c7adc 100644
> --- a/test/common
> +++ b/test/common
> @@ -150,3 +150,7 @@ check_dmesg()
>  	grep -q "Call Trace" <<< $log && err $1
>  	true
>  }
> +
> +
> +# CXL COMMON
> +TEST_QOS_CLASS=42
> diff --git a/test/cxl-qos-class.sh b/test/cxl-qos-class.sh
> new file mode 100755
> index 000000000000..145df6134685
> --- /dev/null
> +++ b/test/cxl-qos-class.sh
> @@ -0,0 +1,102 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2024 Intel Corporation. All rights reserved.
> +
> +. $(dirname $0)/common
> +
> +rc=77
> +
> +set -ex
> +
> +trap 'err $LINENO' ERR
> +
> +check_prereq "jq"
> +
> +modprobe -r cxl_test
> +modprobe cxl_test
> +rc=1
> +
> +check_qos_decoders () {
> +	# check root decoders have expected fake qos_class
> +	# also make sure the number of root decoders equal to the number
> +	# with qos_class found
> +	json=$($CXL list -b cxl_test -D -d root)
> +	decoders=$(echo "$json" | jq length)
> +	count=0
> +	while read -r qos_class
> +	do
> +		((qos_class == TEST_QOS_CLASS)) || err "$LINENO"
> +		count=$((count+1))
> +	done <<< "$(echo "$json" | jq -r '.[] | .qos_class')"
> +
> +	((count == decoders)) || err "$LINENO";
> +}
> +
> +check_qos_memdevs () {
> +	# Check that memdevs that expose ram_qos_class or pmem_qos_class have
> +	# expected fake value programmed.
> +	json=$(cxl list -b cxl_test -M)
> +	readarray -t lines < <(jq ".[] | .ram_size, .pmem_size, .ram_qos_class, .pmem_qos_class" <<<"$json")
> +	for (( i = 0; i < ${#lines[@]}; i += 4 ))
> +	do
> +		ram_size=${lines[i]}
> +		pmem_size=${lines[i+1]}
> +		ram_qos_class=${lines[i+2]}
> +		pmem_qos_class=${lines[i+3]}
> +
> +		if [[ "$ram_size" != null ]]
> +		then
> +			((ram_qos_class == TEST_QOS_CLASS)) || err "$LINENO"
> +		fi
> +		if [[ "$pmem_size" != null ]]
> +		then
> +			((pmem_qos_class == TEST_QOS_CLASS)) || err "$LINENO"
> +		fi
> +	done
> +}
> +
> +# Based on cxl-create-region.sh create_single()
> +destroy_regions()
> +{
> +	if [[ "$*" ]]; then
> +		$CXL destroy-region -f -b cxl_test "$@"
> +	else
> +		$CXL destroy-region -f -b cxl_test all
> +	fi
> +}
> +
> +create_region_check_qos()
> +{
> +	# the 5th cxl_test decoder is expected to target a single-port
> +	# host-bridge. Older cxl_test implementations may not define it,
> +	# so skip the test in that case.
> +	decoder=$($CXL list -b cxl_test -D -d root |
> +		  jq -r ".[4] |
> +		  select(.pmem_capable == true) |
> +		  select(.nr_targets == 1) |
> +		  .decoder")

Instead of assuming the 5th decoder, can we select based on some
property of the decoder or its parentage? This works, but it's a bit
sensitive to future cxl_test topology changes that will easily and
(more importantly) silently break this part of the test (since we skip
but still pass).

> +
> +        if [[ ! $decoder ]]; then
> +                echo "no single-port host-bridge decoder found, skipping"
> +                return
> +        fi

I think there's some space/tab mixing going on here.

> +
> +	# Send create-region with -Q to enforce qos_class matching
> +	region=$($CXL create-region -Q -d "$decoder" | jq -r ".region")
> +	if [[ ! $region ]]; then
> +		echo "failed to create single-port host-bridge region"
> +		err "$LINENO"
> +	fi
> +
> +	destroy_regions "$region"
> +}
> +
> +check_qos_decoders
> +
> +check_qos_memdevs
> +
> +create_region_check_qos
> +
> +check_dmesg "$LINEO"
> +
> +modprobe -r cxl_test
> diff --git a/test/meson.build b/test/meson.build
> index 5eb35749a95b..4892df11119f 100644
> --- a/test/meson.build
> +++ b/test/meson.build
> @@ -160,6 +160,7 @@ cxl_events = find_program('cxl-events.sh')
>  cxl_poison = find_program('cxl-poison.sh')
>  cxl_sanitize = find_program('cxl-sanitize.sh')
>  cxl_destroy_region = find_program('cxl-destroy-region.sh')
> +cxl_qos_class = find_program('cxl-qos-class.sh')
>  
>  tests = [
>    [ 'libndctl',               libndctl,		  'ndctl' ],
> @@ -192,6 +193,7 @@ tests = [
>    [ 'cxl-poison.sh',          cxl_poison,         'cxl'   ],
>    [ 'cxl-sanitize.sh',        cxl_sanitize,       'cxl'   ],
>    [ 'cxl-destroy-region.sh',  cxl_destroy_region, 'cxl'   ],
> +  [ 'cxl-qos-class.sh',       cxl_qos_class,      'cxl'   ],
>  ]
>  
>  if get_option('destructive').enabled()
Verma, Vishal L Feb. 23, 2024, 10:07 p.m. UTC | #2
On Thu, 2024-02-08 at 13:11 -0700, Dave Jiang wrote:
> Add tests in cxl-qos-class.sh to verify qos_class are set with the fake
> qos_class create by the kernel.  Root decoders should have qos_class
> attribute set. Memory devices should have ram_qos_class or pmem_qos_class
> set depending on which partitions are valid.
> 
> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
> ---
> v7:
> - Add create_region -Q testing (Vishal)
> ---
>  test/common           |   4 ++
>  test/cxl-qos-class.sh | 102 ++++++++++++++++++++++++++++++++++++++++++
>  test/meson.build      |   2 +
>  3 files changed, 108 insertions(+)
>  create mode 100755 test/cxl-qos-class.sh
> 
> diff --git a/test/common b/test/common
> index f1023ef20f7e..5694820c7adc 100644
> --- a/test/common
> +++ b/test/common
> @@ -150,3 +150,7 @@ check_dmesg()
>  	grep -q "Call Trace" <<< $log && err $1
>  	true`
>  }
> +
> +
> +# CXL COMMON
> +TEST_QOS_CLASS=42
> diff --git a/test/cxl-qos-class.sh b/test/cxl-qos-class.sh
> new file mode 100755
> index 000000000000..145df6134685
> --- /dev/null
> +++ b/test/cxl-qos-class.sh
> @@ -0,0 +1,102 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2024 Intel Corporation. All rights reserved.
> +
> +. $(dirname $0)/common
> +
> +rc=77
> +
> +set -ex
> +
> +trap 'err $LINENO' ERR
> +
> +check_prereq "jq"
> +
> +modprobe -r cxl_test
> +modprobe cxl_test
> +rc=1
> +
> +check_qos_decoders () {
> +	# check root decoders have expected fake qos_class
> +	# also make sure the number of root decoders equal to the number
> +	# with qos_class found
> +	json=$($CXL list -b cxl_test -D -d root)
> +	decoders=$(echo "$json" | jq length)
> +	count=0
> +	while read -r qos_class
> +	do

For consistency, the script based tests all have the while..do,
for..do, if..then bits on the same line. Would be nice not to break
that precedent.

> +		((qos_class == TEST_QOS_CLASS)) || err "$LINENO"
> +		count=$((count+1))
> +	done <<< "$(echo "$json" | jq -r '.[] | .qos_class')"
> +
> +	((count == decoders)) || err "$LINENO";
> +}
> +
> +check_qos_memdevs () {
> +	# Check that memdevs that expose ram_qos_class or pmem_qos_class have
> +	# expected fake value programmed.
> +	json=$(cxl list -b cxl_test -M)
> +	readarray -t lines < <(jq ".[] | .ram_size, .pmem_size, .ram_qos_class, .pmem_qos_class" <<<"$json")
> +	for (( i = 0; i < ${#lines[@]}; i += 4 ))
> +	do
> +		ram_size=${lines[i]}
> +		pmem_size=${lines[i+1]}
> +		ram_qos_class=${lines[i+2]}
> +		pmem_qos_class=${lines[i+3]}

Hm instead of splitting into lines, and then looping through them, why
not just invoke jq for each?

ram_size=$(jq ".[] | .ram_size" <<< $json)
pmem_size=$(jq ".[] | .pmem_size" <<< $json)
...etc

> +
> +		if [[ "$ram_size" != null ]]
> +		then
> +			((ram_qos_class == TEST_QOS_CLASS)) || err "$LINENO"
> +		fi

This might be a bit more readable as:

if [[ "$ram_size" != null ]] && ((ram_qos_class != TEST_QOS_CLASS)); then
	err "$LINENO"
fi

> +		if [[ "$pmem_size" != null ]]
> +		then
> +			((pmem_qos_class == TEST_QOS_CLASS)) || err "$LINENO"
> +		fi
> +	done
> +}
> +
> +# Based on cxl-create-region.sh create_single()
> +destroy_regions()
> +{
> +	if [[ "$*" ]]; then
> +		$CXL destroy-region -f -b cxl_test "$@"
> +	else
> +		$CXL destroy-region -f -b cxl_test all
> +	fi
> +}
> +
> +create_region_check_qos()
> +{
> +	# the 5th cxl_test decoder is expected to target a single-port
> +	# host-bridge. Older cxl_test implementations may not define it,
> +	# so skip the test in that case.
> +	decoder=$($CXL list -b cxl_test -D -d root |
> +		  jq -r ".[4] |
> +		  select(.pmem_capable == true) |
> +		  select(.nr_targets == 1) |
> +		  .decoder")
> +
> +        if [[ ! $decoder ]]; then
> +                echo "no single-port host-bridge decoder found, skipping"
> +                return
> +        fi
> +
> +	# Send create-region with -Q to enforce qos_class matching
> +	region=$($CXL create-region -Q -d "$decoder" | jq -r ".region")
> +	if [[ ! $region ]]; then
> +		echo "failed to create single-port host-bridge region"
> +		err "$LINENO"
> +	fi
> +
> +	destroy_regions "$region"
> +}
> +
> +check_qos_decoders
> +
> +check_qos_memdevs
> +
> +create_region_check_qos
> +
> +check_dmesg "$LINEO"
> +
> +modprobe -r cxl_test
> diff --git a/test/meson.build b/test/meson.build
> index 5eb35749a95b..4892df11119f 100644
> --- a/test/meson.build
> +++ b/test/meson.build
> @@ -160,6 +160,7 @@ cxl_events = find_program('cxl-events.sh')
>  cxl_poison = find_program('cxl-poison.sh')
>  cxl_sanitize = find_program('cxl-sanitize.sh')
>  cxl_destroy_region = find_program('cxl-destroy-region.sh')
> +cxl_qos_class = find_program('cxl-qos-class.sh')
>  
>  tests = [
>    [ 'libndctl',               libndctl,		  'ndctl' ],
> @@ -192,6 +193,7 @@ tests = [
>    [ 'cxl-poison.sh',          cxl_poison,         'cxl'   ],
>    [ 'cxl-sanitize.sh',        cxl_sanitize,       'cxl'   ],
>    [ 'cxl-destroy-region.sh',  cxl_destroy_region, 'cxl'   ],
> +  [ 'cxl-qos-class.sh',       cxl_qos_class,      'cxl'   ],
>  ]
>  
>  if get_option('destructive').enabled()
Dave Jiang Feb. 26, 2024, 10:39 p.m. UTC | #3
On 2/22/24 12:59 AM, Verma, Vishal L wrote:
> On Thu, 2024-02-08 at 13:11 -0700, Dave Jiang wrote:
>> Add tests in cxl-qos-class.sh to verify qos_class are set with the fake
>> qos_class create by the kernel.  Root decoders should have qos_class
>> attribute set. Memory devices should have ram_qos_class or pmem_qos_class
>> set depending on which partitions are valid.
>>
>> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
>> ---
>> v7:
>> - Add create_region -Q testing (Vishal)
>> ---
>>  test/common           |   4 ++
>>  test/cxl-qos-class.sh | 102 ++++++++++++++++++++++++++++++++++++++++++
>>  test/meson.build      |   2 +
>>  3 files changed, 108 insertions(+)
>>  create mode 100755 test/cxl-qos-class.sh
>>
>> diff --git a/test/common b/test/common
>> index f1023ef20f7e..5694820c7adc 100644
>> --- a/test/common
>> +++ b/test/common
>> @@ -150,3 +150,7 @@ check_dmesg()
>>  	grep -q "Call Trace" <<< $log && err $1
>>  	true
>>  }
>> +
>> +
>> +# CXL COMMON
>> +TEST_QOS_CLASS=42
>> diff --git a/test/cxl-qos-class.sh b/test/cxl-qos-class.sh
>> new file mode 100755
>> index 000000000000..145df6134685
>> --- /dev/null
>> +++ b/test/cxl-qos-class.sh
>> @@ -0,0 +1,102 @@
>> +#!/bin/bash
>> +# SPDX-License-Identifier: GPL-2.0
>> +# Copyright (C) 2024 Intel Corporation. All rights reserved.
>> +
>> +. $(dirname $0)/common
>> +
>> +rc=77
>> +
>> +set -ex
>> +
>> +trap 'err $LINENO' ERR
>> +
>> +check_prereq "jq"
>> +
>> +modprobe -r cxl_test
>> +modprobe cxl_test
>> +rc=1
>> +
>> +check_qos_decoders () {
>> +	# check root decoders have expected fake qos_class
>> +	# also make sure the number of root decoders equal to the number
>> +	# with qos_class found
>> +	json=$($CXL list -b cxl_test -D -d root)
>> +	decoders=$(echo "$json" | jq length)
>> +	count=0
>> +	while read -r qos_class
>> +	do
>> +		((qos_class == TEST_QOS_CLASS)) || err "$LINENO"
>> +		count=$((count+1))
>> +	done <<< "$(echo "$json" | jq -r '.[] | .qos_class')"
>> +
>> +	((count == decoders)) || err "$LINENO";
>> +}
>> +
>> +check_qos_memdevs () {
>> +	# Check that memdevs that expose ram_qos_class or pmem_qos_class have
>> +	# expected fake value programmed.
>> +	json=$(cxl list -b cxl_test -M)
>> +	readarray -t lines < <(jq ".[] | .ram_size, .pmem_size, .ram_qos_class, .pmem_qos_class" <<<"$json")
>> +	for (( i = 0; i < ${#lines[@]}; i += 4 ))
>> +	do
>> +		ram_size=${lines[i]}
>> +		pmem_size=${lines[i+1]}
>> +		ram_qos_class=${lines[i+2]}
>> +		pmem_qos_class=${lines[i+3]}
>> +
>> +		if [[ "$ram_size" != null ]]
>> +		then
>> +			((ram_qos_class == TEST_QOS_CLASS)) || err "$LINENO"
>> +		fi
>> +		if [[ "$pmem_size" != null ]]
>> +		then
>> +			((pmem_qos_class == TEST_QOS_CLASS)) || err "$LINENO"
>> +		fi
>> +	done
>> +}
>> +
>> +# Based on cxl-create-region.sh create_single()
>> +destroy_regions()
>> +{
>> +	if [[ "$*" ]]; then
>> +		$CXL destroy-region -f -b cxl_test "$@"
>> +	else
>> +		$CXL destroy-region -f -b cxl_test all
>> +	fi
>> +}
>> +
>> +create_region_check_qos()
>> +{
>> +	# the 5th cxl_test decoder is expected to target a single-port
>> +	# host-bridge. Older cxl_test implementations may not define it,
>> +	# so skip the test in that case.
>> +	decoder=$($CXL list -b cxl_test -D -d root |
>> +		  jq -r ".[4] |
>> +		  select(.pmem_capable == true) |
>> +		  select(.nr_targets == 1) |
>> +		  .decoder")
> 
> Instead of assuming the 5th decoder, can we select based on some
> property of the decoder or its parentage? This works, but it's a bit
> sensitive to future cxl_test topology changes that will easily and
> (more importantly) silently break this part of the test (since we skip
> but still pass).

I copied it straight from cxl-topology.sh. It can be any really. All cxl_test setup should have qos_class. I would imagine cxl-topology.sh would also break if there's some future change

> 
>> +
>> +        if [[ ! $decoder ]]; then
>> +                echo "no single-port host-bridge decoder found, skipping"
>> +                return
>> +        fi
> 
> I think there's some space/tab mixing going on here.

I'll fix.

> 
>> +
>> +	# Send create-region with -Q to enforce qos_class matching
>> +	region=$($CXL create-region -Q -d "$decoder" | jq -r ".region")
>> +	if [[ ! $region ]]; then
>> +		echo "failed to create single-port host-bridge region"
>> +		err "$LINENO"
>> +	fi
>> +
>> +	destroy_regions "$region"
>> +}
>> +
>> +check_qos_decoders
>> +
>> +check_qos_memdevs
>> +
>> +create_region_check_qos
>> +
>> +check_dmesg "$LINEO"
>> +
>> +modprobe -r cxl_test
>> diff --git a/test/meson.build b/test/meson.build
>> index 5eb35749a95b..4892df11119f 100644
>> --- a/test/meson.build
>> +++ b/test/meson.build
>> @@ -160,6 +160,7 @@ cxl_events = find_program('cxl-events.sh')
>>  cxl_poison = find_program('cxl-poison.sh')
>>  cxl_sanitize = find_program('cxl-sanitize.sh')
>>  cxl_destroy_region = find_program('cxl-destroy-region.sh')
>> +cxl_qos_class = find_program('cxl-qos-class.sh')
>>  
>>  tests = [
>>    [ 'libndctl',               libndctl,		  'ndctl' ],
>> @@ -192,6 +193,7 @@ tests = [
>>    [ 'cxl-poison.sh',          cxl_poison,         'cxl'   ],
>>    [ 'cxl-sanitize.sh',        cxl_sanitize,       'cxl'   ],
>>    [ 'cxl-destroy-region.sh',  cxl_destroy_region, 'cxl'   ],
>> +  [ 'cxl-qos-class.sh',       cxl_qos_class,      'cxl'   ],
>>  ]
>>  
>>  if get_option('destructive').enabled()
>
Dave Jiang Feb. 26, 2024, 11:09 p.m. UTC | #4
On 2/23/24 3:07 PM, Verma, Vishal L wrote:
> On Thu, 2024-02-08 at 13:11 -0700, Dave Jiang wrote:
>> Add tests in cxl-qos-class.sh to verify qos_class are set with the fake
>> qos_class create by the kernel.  Root decoders should have qos_class
>> attribute set. Memory devices should have ram_qos_class or pmem_qos_class
>> set depending on which partitions are valid.
>>
>> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
>> ---
>> v7:
>> - Add create_region -Q testing (Vishal)
>> ---
>>  test/common           |   4 ++
>>  test/cxl-qos-class.sh | 102 ++++++++++++++++++++++++++++++++++++++++++
>>  test/meson.build      |   2 +
>>  3 files changed, 108 insertions(+)
>>  create mode 100755 test/cxl-qos-class.sh
>>
>> diff --git a/test/common b/test/common
>> index f1023ef20f7e..5694820c7adc 100644
>> --- a/test/common
>> +++ b/test/common
>> @@ -150,3 +150,7 @@ check_dmesg()
>>  	grep -q "Call Trace" <<< $log && err $1
>>  	true`
>>  }
>> +
>> +
>> +# CXL COMMON
>> +TEST_QOS_CLASS=42
>> diff --git a/test/cxl-qos-class.sh b/test/cxl-qos-class.sh
>> new file mode 100755
>> index 000000000000..145df6134685
>> --- /dev/null
>> +++ b/test/cxl-qos-class.sh
>> @@ -0,0 +1,102 @@
>> +#!/bin/bash
>> +# SPDX-License-Identifier: GPL-2.0
>> +# Copyright (C) 2024 Intel Corporation. All rights reserved.
>> +
>> +. $(dirname $0)/common
>> +
>> +rc=77
>> +
>> +set -ex
>> +
>> +trap 'err $LINENO' ERR
>> +
>> +check_prereq "jq"
>> +
>> +modprobe -r cxl_test
>> +modprobe cxl_test
>> +rc=1
>> +
>> +check_qos_decoders () {
>> +	# check root decoders have expected fake qos_class
>> +	# also make sure the number of root decoders equal to the number
>> +	# with qos_class found
>> +	json=$($CXL list -b cxl_test -D -d root)
>> +	decoders=$(echo "$json" | jq length)
>> +	count=0
>> +	while read -r qos_class
>> +	do
> 
> For consistency, the script based tests all have the while..do,
> for..do, if..then bits on the same line. Would be nice not to break
> that precedent.

Will fix. BTW, cxl-topology.sh also deviates.

> 
>> +		((qos_class == TEST_QOS_CLASS)) || err "$LINENO"
>> +		count=$((count+1))
>> +	done <<< "$(echo "$json" | jq -r '.[] | .qos_class')"
>> +
>> +	((count == decoders)) || err "$LINENO";
>> +}
>> +
>> +check_qos_memdevs () {
>> +	# Check that memdevs that expose ram_qos_class or pmem_qos_class have
>> +	# expected fake value programmed.
>> +	json=$(cxl list -b cxl_test -M)
>> +	readarray -t lines < <(jq ".[] | .ram_size, .pmem_size, .ram_qos_class, .pmem_qos_class" <<<"$json")
>> +	for (( i = 0; i < ${#lines[@]}; i += 4 ))
>> +	do
>> +		ram_size=${lines[i]}
>> +		pmem_size=${lines[i+1]}
>> +		ram_qos_class=${lines[i+2]}
>> +		pmem_qos_class=${lines[i+3]}
> 
> Hm instead of splitting into lines, and then looping through them, why
> not just invoke jq for each?
> 
> ram_size=$(jq ".[] | .ram_size" <<< $json)
> pmem_size=$(jq ".[] | .pmem_size" <<< $json)
> ...etc
> 

ok

>> +
>> +		if [[ "$ram_size" != null ]]
>> +		then
>> +			((ram_qos_class == TEST_QOS_CLASS)) || err "$LINENO"
>> +		fi
> 
> This might be a bit more readable as:
> 
> if [[ "$ram_size" != null ]] && ((ram_qos_class != TEST_QOS_CLASS)); then
> 	err "$LINENO"
> fi

ok

DJ

> 
>> +		if [[ "$pmem_size" != null ]]
>> +		then
>> +			((pmem_qos_class == TEST_QOS_CLASS)) || err "$LINENO"
>> +		fi
>> +	done
>> +}
>> +
>> +# Based on cxl-create-region.sh create_single()
>> +destroy_regions()
>> +{
>> +	if [[ "$*" ]]; then
>> +		$CXL destroy-region -f -b cxl_test "$@"
>> +	else
>> +		$CXL destroy-region -f -b cxl_test all
>> +	fi
>> +}
>> +
>> +create_region_check_qos()
>> +{
>> +	# the 5th cxl_test decoder is expected to target a single-port
>> +	# host-bridge. Older cxl_test implementations may not define it,
>> +	# so skip the test in that case.
>> +	decoder=$($CXL list -b cxl_test -D -d root |
>> +		  jq -r ".[4] |
>> +		  select(.pmem_capable == true) |
>> +		  select(.nr_targets == 1) |
>> +		  .decoder")
>> +
>> +        if [[ ! $decoder ]]; then
>> +                echo "no single-port host-bridge decoder found, skipping"
>> +                return
>> +        fi
>> +
>> +	# Send create-region with -Q to enforce qos_class matching
>> +	region=$($CXL create-region -Q -d "$decoder" | jq -r ".region")
>> +	if [[ ! $region ]]; then
>> +		echo "failed to create single-port host-bridge region"
>> +		err "$LINENO"
>> +	fi
>> +
>> +	destroy_regions "$region"
>> +}
>> +
>> +check_qos_decoders
>> +
>> +check_qos_memdevs
>> +
>> +create_region_check_qos
>> +
>> +check_dmesg "$LINEO"
>> +
>> +modprobe -r cxl_test
>> diff --git a/test/meson.build b/test/meson.build
>> index 5eb35749a95b..4892df11119f 100644
>> --- a/test/meson.build
>> +++ b/test/meson.build
>> @@ -160,6 +160,7 @@ cxl_events = find_program('cxl-events.sh')
>>  cxl_poison = find_program('cxl-poison.sh')
>>  cxl_sanitize = find_program('cxl-sanitize.sh')
>>  cxl_destroy_region = find_program('cxl-destroy-region.sh')
>> +cxl_qos_class = find_program('cxl-qos-class.sh')
>>  
>>  tests = [
>>    [ 'libndctl',               libndctl,		  'ndctl' ],
>> @@ -192,6 +193,7 @@ tests = [
>>    [ 'cxl-poison.sh',          cxl_poison,         'cxl'   ],
>>    [ 'cxl-sanitize.sh',        cxl_sanitize,       'cxl'   ],
>>    [ 'cxl-destroy-region.sh',  cxl_destroy_region, 'cxl'   ],
>> +  [ 'cxl-qos-class.sh',       cxl_qos_class,      'cxl'   ],
>>  ]
>>  
>>  if get_option('destructive').enabled()
>
diff mbox series

Patch

diff --git a/test/common b/test/common
index f1023ef20f7e..5694820c7adc 100644
--- a/test/common
+++ b/test/common
@@ -150,3 +150,7 @@  check_dmesg()
 	grep -q "Call Trace" <<< $log && err $1
 	true
 }
+
+
+# CXL COMMON
+TEST_QOS_CLASS=42
diff --git a/test/cxl-qos-class.sh b/test/cxl-qos-class.sh
new file mode 100755
index 000000000000..145df6134685
--- /dev/null
+++ b/test/cxl-qos-class.sh
@@ -0,0 +1,102 @@ 
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2024 Intel Corporation. All rights reserved.
+
+. $(dirname $0)/common
+
+rc=77
+
+set -ex
+
+trap 'err $LINENO' ERR
+
+check_prereq "jq"
+
+modprobe -r cxl_test
+modprobe cxl_test
+rc=1
+
+check_qos_decoders () {
+	# check root decoders have expected fake qos_class
+	# also make sure the number of root decoders equal to the number
+	# with qos_class found
+	json=$($CXL list -b cxl_test -D -d root)
+	decoders=$(echo "$json" | jq length)
+	count=0
+	while read -r qos_class
+	do
+		((qos_class == TEST_QOS_CLASS)) || err "$LINENO"
+		count=$((count+1))
+	done <<< "$(echo "$json" | jq -r '.[] | .qos_class')"
+
+	((count == decoders)) || err "$LINENO";
+}
+
+check_qos_memdevs () {
+	# Check that memdevs that expose ram_qos_class or pmem_qos_class have
+	# expected fake value programmed.
+	json=$(cxl list -b cxl_test -M)
+	readarray -t lines < <(jq ".[] | .ram_size, .pmem_size, .ram_qos_class, .pmem_qos_class" <<<"$json")
+	for (( i = 0; i < ${#lines[@]}; i += 4 ))
+	do
+		ram_size=${lines[i]}
+		pmem_size=${lines[i+1]}
+		ram_qos_class=${lines[i+2]}
+		pmem_qos_class=${lines[i+3]}
+
+		if [[ "$ram_size" != null ]]
+		then
+			((ram_qos_class == TEST_QOS_CLASS)) || err "$LINENO"
+		fi
+		if [[ "$pmem_size" != null ]]
+		then
+			((pmem_qos_class == TEST_QOS_CLASS)) || err "$LINENO"
+		fi
+	done
+}
+
+# Based on cxl-create-region.sh create_single()
+destroy_regions()
+{
+	if [[ "$*" ]]; then
+		$CXL destroy-region -f -b cxl_test "$@"
+	else
+		$CXL destroy-region -f -b cxl_test all
+	fi
+}
+
+create_region_check_qos()
+{
+	# the 5th cxl_test decoder is expected to target a single-port
+	# host-bridge. Older cxl_test implementations may not define it,
+	# so skip the test in that case.
+	decoder=$($CXL list -b cxl_test -D -d root |
+		  jq -r ".[4] |
+		  select(.pmem_capable == true) |
+		  select(.nr_targets == 1) |
+		  .decoder")
+
+        if [[ ! $decoder ]]; then
+                echo "no single-port host-bridge decoder found, skipping"
+                return
+        fi
+
+	# Send create-region with -Q to enforce qos_class matching
+	region=$($CXL create-region -Q -d "$decoder" | jq -r ".region")
+	if [[ ! $region ]]; then
+		echo "failed to create single-port host-bridge region"
+		err "$LINENO"
+	fi
+
+	destroy_regions "$region"
+}
+
+check_qos_decoders
+
+check_qos_memdevs
+
+create_region_check_qos
+
+check_dmesg "$LINEO"
+
+modprobe -r cxl_test
diff --git a/test/meson.build b/test/meson.build
index 5eb35749a95b..4892df11119f 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -160,6 +160,7 @@  cxl_events = find_program('cxl-events.sh')
 cxl_poison = find_program('cxl-poison.sh')
 cxl_sanitize = find_program('cxl-sanitize.sh')
 cxl_destroy_region = find_program('cxl-destroy-region.sh')
+cxl_qos_class = find_program('cxl-qos-class.sh')
 
 tests = [
   [ 'libndctl',               libndctl,		  'ndctl' ],
@@ -192,6 +193,7 @@  tests = [
   [ 'cxl-poison.sh',          cxl_poison,         'cxl'   ],
   [ 'cxl-sanitize.sh',        cxl_sanitize,       'cxl'   ],
   [ 'cxl-destroy-region.sh',  cxl_destroy_region, 'cxl'   ],
+  [ 'cxl-qos-class.sh',       cxl_qos_class,      'cxl'   ],
 ]
 
 if get_option('destructive').enabled()