Blame SOURCES/0187-cxl-test-add-a-test-to-read-write-zero-labels.patch

2eb93d
From f149f539e874415c0ec19b43a2c9bf2c56f3aa80 Mon Sep 17 00:00:00 2001
2eb93d
From: Vishal Verma <vishal.l.verma@intel.com>
2eb93d
Date: Wed, 13 Jul 2022 14:37:58 -0600
2eb93d
Subject: [PATCH 187/217] cxl/test: add a test to {read,write,zero}-labels
2eb93d
2eb93d
Add a unit test to test writing, reading, and zeroing LSA aread for
2eb93d
cxl_test based memdevs using ndctl commands, and reading using cxl-cli
2eb93d
commands to exercise that route as much as possible.
2eb93d
2eb93d
Note that writing using cxl-cli requires a bit more enabling to enable,
2eb93d
as the corresponding nvdimm-bridge object will need to be disabled
2eb93d
first.
2eb93d
2eb93d
Link: https://lore.kernel.org/r/20220713203758.519892-1-vishal.l.verma@intel.com
2eb93d
Cc: Dan Williams <dan.j.williams@intel.com>
2eb93d
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
2eb93d
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
2eb93d
---
2eb93d
 test/cxl-labels.sh | 69 ++++++++++++++++++++++++++++++++++++++++++++++
2eb93d
 test/meson.build   |  2 ++
2eb93d
 2 files changed, 71 insertions(+)
2eb93d
 create mode 100644 test/cxl-labels.sh
2eb93d
2eb93d
diff --git a/test/cxl-labels.sh b/test/cxl-labels.sh
2eb93d
new file mode 100644
2eb93d
index 0000000..e782e2d
2eb93d
--- /dev/null
2eb93d
+++ b/test/cxl-labels.sh
2eb93d
@@ -0,0 +1,69 @@
2eb93d
+#!/bin/bash
2eb93d
+# SPDX-License-Identifier: GPL-2.0
2eb93d
+# Copyright (C) 2022 Intel Corporation. All rights reserved.
2eb93d
+
2eb93d
+. $(dirname $0)/common
2eb93d
+
2eb93d
+rc=1
2eb93d
+
2eb93d
+set -ex
2eb93d
+
2eb93d
+trap 'err $LINENO' ERR
2eb93d
+
2eb93d
+check_prereq "jq"
2eb93d
+
2eb93d
+modprobe -r cxl_test
2eb93d
+modprobe cxl_test
2eb93d
+udevadm settle
2eb93d
+
2eb93d
+test_label_ops()
2eb93d
+{
2eb93d
+	nmem="$1"
2eb93d
+	lsa=$(mktemp /tmp/lsa-$nmem.XXXX)
2eb93d
+	lsa_read=$(mktemp /tmp/lsa-read-$nmem.XXXX)
2eb93d
+
2eb93d
+	# determine LSA size
2eb93d
+	"$NDCTL" read-labels -o "$lsa_read" "$nmem"
2eb93d
+	lsa_size=$(stat -c %s "$lsa_read")
2eb93d
+
2eb93d
+	dd "if=/dev/urandom" "of=$lsa" "bs=$lsa_size" "count=1"
2eb93d
+	"$NDCTL" write-labels -i "$lsa" "$nmem"
2eb93d
+	"$NDCTL" read-labels -o "$lsa_read" "$nmem"
2eb93d
+
2eb93d
+	# compare what was written vs read
2eb93d
+	diff "$lsa" "$lsa_read"
2eb93d
+
2eb93d
+	# zero the LSA and test
2eb93d
+	"$NDCTL" zero-labels "$nmem"
2eb93d
+	dd "if=/dev/zero" "of=$lsa" "bs=$lsa_size" "count=1"
2eb93d
+	"$NDCTL" read-labels -o "$lsa_read" "$nmem"
2eb93d
+	diff "$lsa" "$lsa_read"
2eb93d
+
2eb93d
+	# cleanup
2eb93d
+	rm "$lsa" "$lsa_read"
2eb93d
+}
2eb93d
+
2eb93d
+test_label_ops_cxl()
2eb93d
+{
2eb93d
+	mem="$1"
2eb93d
+	lsa_read=$(mktemp /tmp/lsa-read-$mem.XXXX)
2eb93d
+
2eb93d
+	"$CXL" read-labels -o "$lsa_read" "$mem"
2eb93d
+	rm "$lsa_read"
2eb93d
+}
2eb93d
+
2eb93d
+# test reading labels directly through cxl-cli
2eb93d
+readarray -t mems < <("$CXL" list -b cxl_test -Mi | jq -r '.[].memdev')
2eb93d
+
2eb93d
+for mem in ${mems[@]}; do
2eb93d
+	test_label_ops_cxl "$mem"
2eb93d
+done
2eb93d
+
2eb93d
+# find nmem devices corresponding to cxl memdevs
2eb93d
+readarray -t nmems < <("$NDCTL" list -b cxl_test -Di | jq -r '.[].dev')
2eb93d
+
2eb93d
+for nmem in ${nmems[@]}; do
2eb93d
+	test_label_ops "$nmem"
2eb93d
+done
2eb93d
+
2eb93d
+modprobe -r cxl_test
2eb93d
diff --git a/test/meson.build b/test/meson.build
2eb93d
index 3203d9c..b382f46 100644
2eb93d
--- a/test/meson.build
2eb93d
+++ b/test/meson.build
2eb93d
@@ -152,6 +152,7 @@ pfn_meta_errors = find_program('pfn-meta-errors.sh')
2eb93d
 track_uuid = find_program('track-uuid.sh')
2eb93d
 cxl_topo = find_program('cxl-topology.sh')
2eb93d
 cxl_sysfs = find_program('cxl-region-sysfs.sh')
2eb93d
+cxl_labels = find_program('cxl-labels.sh')
2eb93d
 
2eb93d
 tests = [
2eb93d
   [ 'libndctl',               libndctl,		  'ndctl' ],
2eb93d
@@ -178,6 +179,7 @@ tests = [
2eb93d
   [ 'track-uuid.sh',          track_uuid,	  'ndctl' ],
2eb93d
   [ 'cxl-topology.sh',	      cxl_topo,		  'cxl'   ],
2eb93d
   [ 'cxl-region-sysfs.sh',    cxl_sysfs,	  'cxl'   ],
2eb93d
+  [ 'cxl-labels.sh',          cxl_labels,	  'cxl'   ],
2eb93d
 ]
2eb93d
 
2eb93d
 if get_option('destructive').enabled()
2eb93d
-- 
2eb93d
2.27.0
2eb93d