cxl/test: add a test to {read,write,zero}-labels
Vishal Verma
maintainerPATCH 1/1 cxl/test: add a test to {read,write,zero}-labels
Add a unit test to test writing, reading, and zeroing LSA aread for cxl_test based memdevs using ndctl commands.
--- test/cxl-labels.sh | 53 ++++++++++++++++++++++++++++++++++++++++++++++ test/meson.build | 2 ++ 2 files changed, 55 insertions(+) create mode 100644 test/cxl-labels.sh
test/cxl-labels.sh new file +53 -0
@@ -0,0 +1,53 @@ +#!/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 + +test_label_ops() +{ + nmem="$1" + lsa=$(mktemp /tmp/lsa-$nmem.XXXX) + lsa_read=$(mktemp /tmp/lsa-read-$nmem.XXXX) + + # determine LSA size + "$NDCTL" read-labels -o "$lsa_read" "$nmem" + lsa_size=$(stat -c %s "$lsa_read") + + dd "if=/dev/urandom" "of=$lsa" "bs=$lsa_size" "count=1" + "$NDCTL" write-labels -i "$lsa" "$nmem" + "$NDCTL" read-labels -o "$lsa_read" "$nmem" + + # compare what was written vs read + diff "$lsa" "$lsa_read" + + # zero the LSA and test + "$NDCTL" zero-labels "$nmem" + dd "if=/dev/zero" "of=$lsa" "bs=$lsa_size" "count=1" + "$NDCTL" read-labels -o "$lsa_read" "$nmem" + diff "$lsa" "$lsa_read" + + # cleanup + rm "$lsa" "$lsa_read" +} + +# find nmem devices corresponding to cxl memdevs +readarray -t nmems < <("$NDCTL" list -b cxl_test -Di | jq -r '.[].dev') + +for nmem in ${nmems[@]}; do + test_label_ops "$nmem" +done + +modprobe -r cxl_test
test/meson.build +2 -0
@@ -152,6 +152,7 @@ pfn_meta_errors = find_program('pfn-meta-errors.sh') track_uuid = find_program('track-uuid.sh') cxl_topo = find_program('cxl-topology.sh') cxl_region = find_program('cxl-region-create.sh') +cxl_labels = find_program('cxl-labels.sh') tests = [ [ 'libndctl', libndctl, 'ndctl' ],
@@ -178,6 +179,7 @@ tests = [ [ 'track-uuid.sh', track_uuid, 'ndctl' ], [ 'cxl-topology.sh', cxl_topo, 'cxl' ], [ 'cxl-region-create.sh', cxl_region, 'cxl' ], + [ 'cxl-labels.sh', cxl_labels, 'cxl' ], ] if get_option('destructive').enabled()
Signature · 1 line
2.36.1
Quoted 54 lines · Vishal Verma
Add a unit test to test writing, reading, and zeroing LSA aread for
cxl_testbased memdevs using ndctl commands.Cc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>---
test/cxl-labels.sh| 53 ++++++++++++++++++++++++++++++++++++++++++++++
test/meson.build | 2 ++2 files changed, 55 insertions(+)create mode 100644
test/cxl-labels.shtest/cxl-labels.sh new file +37
-0@@ -0,0 +1,53 @@ +#!/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 + +test_label_ops() +{ + nmem="$1" + lsa=$(mktemp /tmp/lsa-$nmem.XXXX) + lsa_read=$(mktemp /tmp/lsa-read-$nmem.XXXX) + + # determine LSA size + "$NDCTL" read-labels -o "$lsa_read" "$nmem" + lsa_size=$(stat -c %s "$lsa_read") + + dd "if=/dev/urandom" "of=$lsa" "bs=$lsa_size" "count=1" + "$NDCTL" write-labels -i "$lsa" "$nmem" + "$NDCTL" read-labels -o "$lsa_read" "$nmem" + + # compare what was written vs read + diff "$lsa" "$lsa_read" + + # zero the LSA and test + "$NDCTL" zero-labels "$nmem"
test/cxl-labels.sh line 47
Quoted 10 lines
test/cxl-labels.sh new file +10
-0+ dd "if=/dev/zero" "of=$lsa" "bs=$lsa_size" "count=1" + "$NDCTL" read-labels -o "$lsa_read" "$nmem" + diff "$lsa" "$lsa_read" + + # cleanup + rm "$lsa" "$lsa_read" +} + +# find nmem devices corresponding to cxl memdevs +readarray -t nmems < <("$NDCTL" list -b cxl_test -Di | jq -r '.[].dev')
s/$NDCTL/$CXL
Beyond sharing a repo, I would really avoid mixing and matching ndctl and cxl tooling and thereby keep them self sufficient. I understand that there are cases where pmem specific operations can can be done reusing relevant pmem/nvdimm/ndctl machinery and interfaces, but I don't see this as the case for something like lsa unit testing.
Thanks,
Davidlohr
Quoted 29 lines
test/cxl-labels.sh new file +6
-0+ +for nmem in ${nmems[@]}; do + test_label_ops "$nmem" +done + +modprobe -r cxl_testtest/meson.build +1
-0@@ -152,6 +152,7 @@ pfn_meta_errors = find_program('pfn-meta-errors.sh') track_uuid = find_program('track-uuid.sh') cxl_topo = find_program('cxl-topology.sh') cxl_region = find_program('cxl-region-create.sh') +cxl_labels = find_program('cxl-labels.sh')tests = [
[ 'libndctl', libndctl, 'ndctl' ],test/meson.build +1
-0@@ -178,6 +179,7 @@ tests = [ [ 'track-uuid.sh', track_uuid, 'ndctl' ], [ 'cxl-topology.sh', cxl_topo, 'cxl' ], [ 'cxl-region-create.sh', cxl_region, 'cxl' ], + [ 'cxl-labels.sh', cxl_labels, 'cxl' ],]
if get_option('destructive').enabled()
--
2.36.1
Verma, Vishal L
maintainerQuoted 69 lines · Davidlohr Bueso
Quoted 54 lines · Vishal Verma
Add a unit test to test writing, reading, and zeroing LSA aread for
cxl_testbased memdevs using ndctl commands.Cc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>---
test/cxl-labels.sh| 53 ++++++++++++++++++++++++++++++++++++++++++++++ test/meson.build | 2 ++2 files changed, 55 insertions(+)create mode 100644
test/cxl-labels.shtest/cxl-labels.sh new file +37
-0@@ -0,0 +1,53 @@ +#!/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 + +test_label_ops() +{ + nmem="$1" + lsa=$(mktemp /tmp/lsa-$nmem.XXXX) + lsa_read=$(mktemp /tmp/lsa-read-$nmem.XXXX) + + # determine LSA size + "$NDCTL" read-labels -o "$lsa_read" "$nmem" + lsa_size=$(stat -c %s "$lsa_read") + + dd "if=/dev/urandom" "of=$lsa" "bs=$lsa_size" "count=1" + "$NDCTL" write-labels -i "$lsa" "$nmem" + "$NDCTL" read-labels -o "$lsa_read" "$nmem" + + # compare what was written vs read + diff "$lsa" "$lsa_read" + + # zero the LSA and test + "$NDCTL" zero-labels "$nmem"test/cxl-labels.sh line 47
Quoted 10 lines
test/cxl-labels.sh new file +10
-0+ dd "if=/dev/zero" "of=$lsa" "bs=$lsa_size" "count=1" + "$NDCTL" read-labels -o "$lsa_read" "$nmem" + diff "$lsa" "$lsa_read" + + # cleanup + rm "$lsa" "$lsa_read" +} + +# find nmem devices corresponding to cxl memdevs +readarray -t nmems < <("$NDCTL" list -b cxl_test -Di | jq -r '.[].dev')s/$NDCTL/$CXL
Quoted 9 lines
Beyond sharing a repo, I would really avoid mixing and matching ndctl and cxl tooling and thereby keep them self sufficient. I understand that there are cases where pmem specific operations can can be done reusing relevant pmem/nvdimm/ndctl machinery and interfaces, but I don't see this as the case for something like lsa unit testing.
Thanks,
Davidlohr
Hi David,
Thanks for the review - however this was intentional. cxl-cli may block LSA write access because libnvdimm could 'own' the label space.
cxl memdev: action_write: mem0: has active nvdimm bridge, abort label write
So the test has to use ndctl for label writes. Reads could be done with 'cxl', but for now there isn't a good/predictable mapping between ndctl 'nmemX' and cxl 'memX'. Once that is solved, either by a shared id allocator, or by listings showing the nmem->mem mapping, I will at least add another cxl read-labels here which would validate the same LSA data through cxl-cli.
Quoted 1 line
Quoted 84 lines · Vishal L
Quoted 69 lines · Davidlohr Bueso
Quoted 54 lines · Vishal Verma
Add a unit test to test writing, reading, and zeroing LSA aread for
cxl_testbased memdevs using ndctl commands.Cc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>---
test/cxl-labels.sh| 53 ++++++++++++++++++++++++++++++++++++++++++++++ test/meson.build | 2 ++2 files changed, 55 insertions(+)create mode 100644
test/cxl-labels.shtest/cxl-labels.sh new file +37
-0@@ -0,0 +1,53 @@ +#!/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 + +test_label_ops() +{ + nmem="$1" + lsa=$(mktemp /tmp/lsa-$nmem.XXXX) + lsa_read=$(mktemp /tmp/lsa-read-$nmem.XXXX) + + # determine LSA size + "$NDCTL" read-labels -o "$lsa_read" "$nmem" + lsa_size=$(stat -c %s "$lsa_read") + + dd "if=/dev/urandom" "of=$lsa" "bs=$lsa_size" "count=1" + "$NDCTL" write-labels -i "$lsa" "$nmem" + "$NDCTL" read-labels -o "$lsa_read" "$nmem" + + # compare what was written vs read + diff "$lsa" "$lsa_read" + + # zero the LSA and test + "$NDCTL" zero-labels "$nmem"test/cxl-labels.sh line 47
Quoted 10 lines
test/cxl-labels.sh new file +10
-0+ dd "if=/dev/zero" "of=$lsa" "bs=$lsa_size" "count=1" + "$NDCTL" read-labels -o "$lsa_read" "$nmem" + diff "$lsa" "$lsa_read" + + # cleanup + rm "$lsa" "$lsa_read" +} + +# find nmem devices corresponding to cxl memdevs +readarray -t nmems < <("$NDCTL" list -b cxl_test -Di | jq -r '.[].dev')s/$NDCTL/$CXL
Quoted 9 lines
Beyond sharing a repo, I would really avoid mixing and matching ndctl and cxl tooling and thereby keep them self sufficient. I understand that there are cases where pmem specific operations can can be done reusing relevant pmem/nvdimm/ndctl machinery and interfaces, but I don't see this as the case for something like lsa unit testing.
Thanks,
DavidlohrHi David,
Thanks for the review - however this was intentional. cxl-cli may block LSA write access because libnvdimm could 'own' the label space.
Quoted 8 lines
cxl memdev:
action_write: mem0: has active nvdimm bridge, abort label writeSo the test has to use ndctl for label writes. Reads could be done with 'cxl', but for now there isn't a good/predictable mapping between ndctl 'nmemX' and cxl 'memX'. Once that is solved, either by a shared id allocator, or by listings showing the
nmem->memmapping, I will at least add another cxl read-labels here which would validate the same LSA data through cxl-cli.
I do think this test should eventually do both to validate that the nvdimm passthrough and the native CXL operations are working. However, the native CXL case needs a bit more infrastructure to disconnect the memdev from nvdimm. Something like:
cxl disable-pmem mem0
cxl write-labels mem0 ...
You can add a "cxl read-labels" test though since that is not blocked while the memdev is attached to nvdimm, only label writes.
Verma, Vishal L
maintainerQuoted 112 lines · Dan Williams
Quoted 95 lines · Vishal L
Quoted 82 lines · Davidlohr Bueso
Quoted 66 lines · Vishal Verma
Add a unit test to test writing, reading, and zeroing LSA aread for
cxl_testbased memdevs using ndctl commands.Cc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>---
test/cxl-labels.sh| 53
++++++++++++++++++++++++++++++++++++++++++++++
test/meson.build | 2 ++2 files changed, 55 insertions(+)create mode 100644
test/cxl-labels.shtest/cxl-labels.sh new file +47
-0@@ -0,0 +1,53 @@ +#!/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 + +test_label_ops() +{ + nmem="$1" + lsa=$(mktemp /tmp/lsa-$nmem.XXXX) + lsa_read=$(mktemp /tmp/lsa-read-$nmem.XXXX) + + # determine LSA size + "$NDCTL" read-labels -o "$lsa_read" "$nmem" + lsa_size=$(stat -c %s "$lsa_read") + + dd "if=/dev/urandom" "of=$lsa" "bs=$lsa_size" "count=1" + "$NDCTL" write-labels -i "$lsa" "$nmem" + "$NDCTL" read-labels -o "$lsa_read" "$nmem" + + # compare what was written vs read + diff "$lsa" "$lsa_read" + + # zero the LSA and test + "$NDCTL" zero-labels "$nmem" + dd "if=/dev/zero" "of=$lsa" "bs=$lsa_size" "count=1" + "$NDCTL" read-labels -o "$lsa_read" "$nmem" + diff "$lsa" "$lsa_read" + + # cleanup + rm "$lsa" "$lsa_read" +} + +# find nmem devices corresponding to cxl memdevs +readarray -t nmems < <("$NDCTL" list -b cxl_test -Di | jq -rQuoted 1 line
'.[].dev')
s/$NDCTL/$CXL
Beyond sharing a repo, I would really avoid mixing and matching ndctl and cxl
tooling and thereby keep them self sufficient. I understand that there are cases
where pmem specific operations can can be done reusing relevant pmem/nvdimm/ndctl
machinery and interfaces, but I don't see this as the case for something like lsa
unit testing.Quoted 3 lines
Thanks,
DavidlohrHi David,
Thanks for the review - however this was intentional. cxl-cli may block
LSA write access because libnvdimm could 'own' the label space.cxl memdev:
action_write: mem0: has active nvdimm bridge, abort label writeQuoted 9 lines
So the test has to use ndctl for label writes. Reads could be done with
'cxl', but for now there isn't a good/predictable mapping between ndctl
'nmemX' and cxl 'memX'. Once that is solved, either by a shared id allocator, or by listings showing thenmem->memmapping, I will at least add another cxl read-labels here which would validate the same
LSA data through cxl-cli.I do think this test should eventually do both to validate that the nvdimm passthrough and the native CXL operations are working. However,
the native CXL case needs a bit more infrastructure to disconnect the memdev from nvdimm. Something like:
Quoted 5 lines
cxl disable-pmem mem0
cxl write-labels mem0 ...You can add a "cxl read-labels" test though since that is not blocked while the memdev is attached to nvdimm, only label writes.
Ah - yeah I think just going through all memdevs and reading the LSA is harmless enough, and it exercises the cxl-cli paths. I'll add it to v2.
Quoted 5 lines · Vishal Verma
Add a unit test to test writing, reading, and zeroing LSA aread for
cxl_testbased memdevs using ndctl commands.Cc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>
Looks good to me: