Skip to contentSkip to conversation

ndctl/cxl/test: Add CXL event test

PATCH In review Ira Weiny 2 participants 3 messages Jul 31, 2023 – Aug 1, 2023

Subsystems (2)
lore
Share & tools
lore

Ira Weiny

author
#0 lore raw

PATCH v2 1/1 ndctl/cxl/test: Add CXL event test

Previously CXL event testing was run by hand. This reduces testing coverage including a lack of regression testing.

Add a CXL event test as part of the meson test infrastructure. Passing is predicated on receiving the appropriate number of errors in each log. Individual event values are not checked.

---
Changes in v2:
[djiang] run shellcheck and fix as needed
[vishal] quote variables
[vishal] skip test if event_trigger is not available
[vishal] remove dead code
[vishal] explicitly use the first memdev returned from cxl-cli
[vishal] store trace output in a variable
[vishal] simplify grep statement looking for results
[vishal] use variables for expected values
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 test/cxl-events.sh | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 test/meson.build   |  2 ++
 2 files changed, 78 insertions(+)
test/cxl-events.sh new file +76 -0
new file mode 100644
index 000000000000..33b68daa6ade
@@ -0,0 +1,76 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2023 Intel Corporation. All rights reserved.
+
+. "$(dirname "$0")/common"
+
+# Results expected
+num_overflow_expected=1
+num_fatal_expected=2
+num_failure_expected=16
+num_info_expected=3
+
+set -ex
+
+trap 'err $LINENO' ERR
+
+check_prereq "jq"
+
+modprobe -r cxl_test
+modprobe cxl_test
+
+dev_path="/sys/bus/platform/devices"
+
+test_cxl_events()
+{
+	memdev="$1"
+
+	if [ ! -f "${dev_path}/${memdev}/event_trigger" ]; then
+		echo "TEST: Kernel does not support test event trigger"
+		exit 77
+	fi
+
+	echo "TEST: triggering $memdev"
+	echo 1 > "${dev_path}/${memdev}/event_trigger"
+}
+
+readarray -t memdevs < <("$CXL" list -b cxl_test -Mi | jq -r '.[].host')
+
+echo "TEST: Prep event trace"
+echo "" > /sys/kernel/tracing/trace
+echo 1 > /sys/kernel/tracing/events/cxl/enable
+echo 1 > /sys/kernel/tracing/tracing_on
+
+test_cxl_events "${memdevs[0]}"
+
+echo 0 > /sys/kernel/tracing/tracing_on
+
+echo "TEST: Events seen"
+trace_out=$(cat /sys/kernel/tracing/trace)
+
+num_overflow=$(grep -c "cxl_overflow" <<< "${trace_out}")
+num_fatal=$(grep -c "log=Fatal" <<< "${trace_out}")
+num_failure=$(grep -c "log=Failure" <<< "${trace_out}")
+num_info=$(grep -c "log=Informational" <<< "${trace_out}")
+echo "     LOG     (Expected) : (Found)"
+echo "     overflow      ($num_overflow_expected) : $num_overflow"
+echo "     Fatal         ($num_fatal_expected) : $num_fatal"
+echo "     Failure       ($num_failure_expected) : $num_failure"
+echo "     Informational ($num_info_expected) : $num_info"
+
+if [ "$num_overflow" -ne $num_overflow_expected ]; then
+	err "$LINENO"
+fi
+if [ "$num_fatal" -ne $num_fatal_expected ]; then
+	err "$LINENO"
+fi
+if [ "$num_failure" -ne $num_failure_expected ]; then
+	err "$LINENO"
+fi
+if [ "$num_info" -ne $num_info_expected ]; then
+	err "$LINENO"
+fi
+
+check_dmesg "$LINENO"
+
+modprobe -r cxl_test
test/meson.build +2 -0
index a956885f6df6..a33255bde1a8 100644
@@ -155,6 +155,7 @@ 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_xor_region = find_program('cxl-xor-region.sh')
+cxl_events = find_program('cxl-events.sh')
 
 tests = [
   [ 'libndctl',               libndctl,		  'ndctl' ],
@@ -183,6 +184,7 @@ tests = [
   [ 'cxl-labels.sh',          cxl_labels,	  'cxl'   ],
   [ 'cxl-create-region.sh',   cxl_create_region,  'cxl'   ],
   [ 'cxl-xor-region.sh',      cxl_xor_region,     'cxl'   ],
+  [ 'cxl-events.sh',          cxl_events,         'cxl'   ],
 ]
 
 if get_option('destructive').enabled()

---
base-commit: 2fd570a0ed788b1bd0971dfdb1466a5dbcb79775
change-id: 20230726-cxl-event-dc00a2f94b60

Best regards,

Signature · 1 line
Ira Weiny <[email protected]>
maintainer
#1 lore raw
Quoted 1 line · Ira Weiny

Previously CXL event testing was run by hand.  This reduces testing

Reduces or increases / improves? Or did you mean running by hand reduced coverage.

Maybe this can read "Improve testing coverage and address a lack of automated regression testing by adding a unit test for this"

(no need to respin, I can fixup when applying, just making sure I'm not misinterpreting what you meant to say).

Quoted 21 lines

coverage including a lack of regression testing.

Add a CXL event test as part of the meson test infrastructure.  Passing is predicated on receiving the appropriate number of errors in each log. Individual event values are not checked.

---
Changes in v2:
[djiang] run shellcheck and fix as needed
[vishal] quote variables
[vishal] skip test if event_trigger is not available
[vishal] remove dead code
[vishal] explicitly use the first memdev returned from cxl-cli
[vishal] store trace output in a variable
[vishal] simplify grep statement looking for results
[vishal] use variables for expected values
- Link to v1: https://lore.kernel.org/r/[email protected]
---
 test/cxl-events.sh | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/meson.build   |  2 ++

Quoted 2 lines
 2 files changed, 78 insertions(+)

Thanks for the rev, everything else looks good.

author
#2 lore raw
Quoted 5 lines · Vishal L
Quoted 1 line · Ira Weiny

Previously CXL event testing was run by hand.  This reduces testing

Reduces or increases / improves? Or did you mean running by hand reduced coverage.

Running by hand reduces test coverage.

Quoted 3 lines

Maybe this can read "Improve testing coverage and address a lack of automated regression testing by adding a unit test for this"

Sounds good.

Quoted 3 lines

(no need to respin, I can fixup when applying, just making sure I'm not misinterpreting what you meant to say).

Thanks,
Ira

Quoted 25 lines
Quoted 22 lines

coverage including a lack of regression testing.

Add a CXL event test as part of the meson test infrastructure.  Passing is predicated on receiving the appropriate number of errors in each log. Individual event values are not checked.

---
Changes in v2:
[djiang] run shellcheck and fix as needed
[vishal] quote variables
[vishal] skip test if event_trigger is not available
[vishal] remove dead code
[vishal] explicitly use the first memdev returned from cxl-cli
[vishal] store trace output in a variable
[vishal] simplify grep statement looking for results
[vishal] use variables for expected values
- Link to v1: https://lore.kernel.org/r/[email protected]
---
 test/cxl-events.sh | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/meson.build   |  2 ++

Quoted 2 lines
 2 files changed, 78 insertions(+)

Thanks for the rev, everything else looks good.