Skip to contentSkip to conversation

ndctl/cxl/test: Add CXL event test

PATCH Superseded Ira Weiny 3 participants 6 messages Jul 27, 2023 – Jul 31, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ira Weiny

author
#0 lore raw

PATCH 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 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.

---
 test/cxl-events.sh | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 test/meson.build   |  2 ++
 2 files changed, 70 insertions(+)
test/cxl-events.sh new file +68 -0
new file mode 100644
index 000000000000..f51046ec39ad
@@ -0,0 +1,68 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2023 Intel Corporation. All rights reserved.
+
+. $(dirname $0)/common
+
+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"
+
+	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
+
+# Only need to test 1 device
+#for memdev in ${memdevs[@]}; do
+#done
+
+test_cxl_events "$memdevs"
+
+echo 0 > /sys/kernel/tracing/tracing_on
+
+echo "TEST: Events seen"
+cat /sys/kernel/tracing/trace
+num_overflow=$(grep "cxl_overflow" /sys/kernel/tracing/trace | wc -l)
+num_fatal=$(grep "log=Fatal" /sys/kernel/tracing/trace | wc -l)
+num_failure=$(grep "log=Failure" /sys/kernel/tracing/trace | wc -l)
+num_info=$(grep "log=Informational" /sys/kernel/tracing/trace | wc -l)
+echo "     LOG     (Expected) : (Found)"
+echo "     overflow      ( 1) : $num_overflow"
+echo "     Fatal         ( 2) : $num_fatal"
+echo "     Failure       (16) : $num_failure"
+echo "     Informational ( 3) : $num_info"
+
+if [ "$num_overflow" -ne 1 ]; then
+	err "$LINENO"
+fi
+if [ "$num_fatal" -ne 2 ]; then
+	err "$LINENO"
+fi
+if [ "$num_failure" -ne 16 ]; then
+	err "$LINENO"
+fi
+if [ "$num_info" -ne 3 ]; 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 Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Ira Weiny

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

Add a CXL 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.

LGTM. Have you tried running shellcheck?

Quoted 105 lines
---
  test/cxl-events.sh | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
  test/meson.build   |  2 ++
  2 files changed, 70 insertions(+)
test/cxl-events.sh new file +68 -0
new file mode 100644
index 000000000000..f51046ec39ad
@@ -0,0 +1,68 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2023 Intel Corporation. All rights reserved.
+
+. $(dirname $0)/common
+
+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"
+
+	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
+
+# Only need to test 1 device
+#for memdev in ${memdevs[@]}; do
+#done
+
+test_cxl_events "$memdevs"
+
+echo 0 > /sys/kernel/tracing/tracing_on
+
+echo "TEST: Events seen"
+cat /sys/kernel/tracing/trace
+num_overflow=$(grep "cxl_overflow" /sys/kernel/tracing/trace | wc -l)
+num_fatal=$(grep "log=Fatal" /sys/kernel/tracing/trace | wc -l)
+num_failure=$(grep "log=Failure" /sys/kernel/tracing/trace | wc -l)
+num_info=$(grep "log=Informational" /sys/kernel/tracing/trace | wc -l)
+echo "     LOG     (Expected) : (Found)"
+echo "     overflow      ( 1) : $num_overflow"
+echo "     Fatal         ( 2) : $num_fatal"
+echo "     Failure       (16) : $num_failure"
+echo "     Informational ( 3) : $num_info"
+
+if [ "$num_overflow" -ne 1 ]; then
+	err "$LINENO"
+fi
+if [ "$num_fatal" -ne 2 ]; then
+	err "$LINENO"
+fi
+if [ "$num_failure" -ne 16 ]; then
+	err "$LINENO"
+fi
+if [ "$num_info" -ne 3 ]; then
+	err "$LINENO"
+fi
+
+check_dmesg "$LINENO"
+
+modprobe -r cxl_test
test/meson.build +2 -1
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,

author
#2 lore raw
Quoted 6 lines · Dave Jiang
Quoted 3 lines · Ira Weiny

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

Quoted 7 lines
Quoted 5 lines

Add a CXL 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.

LGTM. Have you tried running shellcheck?

Never heard of it... searching...

This?

ShellCheck.x86_64 : Shell script analysis tool

Quoted 2 lines

Thanks,
Ira

maintainer
#3 lore raw
Quoted 13 lines · Ira Weiny
Quoted 12 lines · Dave Jiang
Quoted 8 lines · Ira Weiny

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

Add a CXL 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.

Quoted 7 lines
Quoted 1 line

LGTM. Have you tried running shellcheck?

Never heard of it... searching...

This?

ShellCheck.x86_64 : Shell script analysis tool

I think so.

Quoted 6 lines
Quoted 3 lines

Thanks,
Ira

maintainer
#4 lore raw
In reply to Ira Weiny
Quoted 7 lines · Ira Weiny

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

Add a CXL 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.

Quoted 5 lines

---
 test/cxl-events.sh | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/meson.build   |  2 ++

 2 files changed, 70 insertions(+)

Hi Ira,

Thanks for adding this test. Just a few minor comments below, otherwise looks good.

Quoted 20 lines
test/cxl-events.sh new file +13 -0
new file mode 100644
index 000000000000..f51046ec39ad
@@ -0,0 +1,68 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2023 Intel Corporation. All rights reserved.
+
+. $(dirname $0)/common
+
+set -ex
+
+trap 'err $LINENO' ERR
+
+check_prereq "jq"
+
+modprobe -r cxl_test

test/cxl-events.sh line 23

Quoted 10 lines
test/cxl-events.sh new file +10 -0
+modprobe cxl_test
+
+dev_path="/sys/bus/platform/devices"
+
+test_cxl_events()
+{
+       memdev="$1"
+
+       echo "TEST: triggering $memdev"
+       echo 1 > $dev_path/$memdev/event_trigger

Quote the "$variables" here. We don't expect spaces in the path in this case, so it will still work, but it is good practice to always quote everything.

We might also need a test to see if this file exists first. For kernels that don't have this support, we probably want to print a message and skip the test (return '77').

test/cxl-events.sh line 35

Quoted 12 lines
test/cxl-events.sh new file +12 -0
+}
+
+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
+
+# Only need to test 1 device
+#for memdev in ${memdevs[@]}; do
+#done

Probably just remove the commented out loop, if we need to test more than one memdev in the future, it is easy enough to add back then.

test/cxl-events.sh line 37

Quoted 2 lines
test/cxl-events.sh new file +2 -0
+
+test_cxl_events "$memdevs"

Shouldn't use "$memdevs" here since it is an array. If you want to pass in just the first memdev, use "${memdevs[0]}"

test/cxl-events.sh line 46

Quoted 9 lines
test/cxl-events.sh new file +9 -0
+
+echo 0 > /sys/kernel/tracing/tracing_on
+
+echo "TEST: Events seen"
+cat /sys/kernel/tracing/trace
+num_overflow=$(grep "cxl_overflow" /sys/kernel/tracing/trace | wc -l)
+num_fatal=$(grep "log=Fatal" /sys/kernel/tracing/trace | wc -l)
+num_failure=$(grep "log=Failure" /sys/kernel/tracing/trace | wc -l)
+num_info=$(grep "log=Informational" /sys/kernel/tracing/trace | wc -l)

Minor nit, but you can 'grep -c' instead of 'grep | wc -l'

Also could put /sys/kernel/tracing/trace into a variable just for readability since it is used many times.

Quoted 8 lines
test/cxl-events.sh new file +8 -0
+echo "     LOG     (Expected) : (Found)"
+echo "     overflow      ( 1) : $num_overflow"
+echo "     Fatal         ( 2) : $num_fatal"
+echo "     Failure       (16) : $num_failure"
+echo "     Informational ( 3) : $num_info"
+
+if [ "$num_overflow" -ne 1 ]; then
+       err "$LINENO"

test/cxl-events.sh line 64

Quoted 10 lines
test/cxl-events.sh new file +10 -0
+fi
+if [ "$num_fatal" -ne 2 ]; then
+       err "$LINENO"
+fi
+if [ "$num_failure" -ne 16 ]; then
+       err "$LINENO"
+fi
+if [ "$num_info" -ne 3 ]; then
+       err "$LINENO"
+fi

Perhaps define variables for each of the expected nums, that way there is only one spot to change in case the numbers change in the future.

Quoted 30 lines
test/cxl-events.sh new file +4 -0
+
+check_dmesg "$LINENO"
+
+modprobe -r cxl_test
test/meson.build +1 -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' ],

test/meson.build +1 -0
@@ -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,

author
#5 lore raw
Quoted 14 lines · Vishal L
Quoted 7 lines · Ira Weiny

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

Add a CXL 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.

Quoted 5 lines

---
 test/cxl-events.sh | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/meson.build   |  2 ++

 2 files changed, 70 insertions(+)
Quoted 4 lines

Hi Ira,

Thanks for adding this test. Just a few minor comments below, otherwise looks good.

Thanks!

Quoted 27 lines
Quoted 27 lines
test/cxl-events.sh new file +19 -0
new file mode 100644
index 000000000000..f51046ec39ad
@@ -0,0 +1,68 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2023 Intel Corporation. All rights reserved.
+
+. $(dirname $0)/common
+
+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()
+{
Quoted 8 lines

test/cxl-events.sh line 23

Quoted 4 lines
test/cxl-events.sh new file +4 -0
+       memdev="$1"
+
+       echo "TEST: triggering $memdev"
+       echo 1 > $dev_path/$memdev/event_trigger

Quote the "$variables" here. We don't expect spaces in the path in this case, so it will still work, but it is good practice to always quote everything.

Done.

Quoted 4 lines

We might also need a test to see if this file exists first. For kernels that don't have this support, we probably want to print a message and skip the test (return '77').

Good idea.

Quoted 16 lines

test/cxl-events.sh line 35

Quoted 13 lines
test/cxl-events.sh new file +12 -0
+}
+
+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
+
+# Only need to test 1 device
+#for memdev in ${memdevs[@]}; do
+#done

Probably just remove the commented out loop, if we need to test more than one memdev in the future, it is easy enough to add back then.

Done.

Quoted 6 lines

test/cxl-events.sh line 37

Quoted 3 lines
test/cxl-events.sh new file +2 -0
+
+test_cxl_events "$memdevs"

Shouldn't use "$memdevs" here since it is an array. If you want to pass in just the first memdev, use "${memdevs[0]}"

Ah yea caught my hack ;-) done.

Quoted 12 lines

test/cxl-events.sh line 46

Quoted 10 lines
test/cxl-events.sh new file +9 -0
+
+echo 0 > /sys/kernel/tracing/tracing_on
+
+echo "TEST: Events seen"
+cat /sys/kernel/tracing/trace
+num_overflow=$(grep "cxl_overflow" /sys/kernel/tracing/trace | wc -l)
+num_fatal=$(grep "log=Fatal" /sys/kernel/tracing/trace | wc -l)
+num_failure=$(grep "log=Failure" /sys/kernel/tracing/trace | wc -l)
+num_info=$(grep "log=Informational" /sys/kernel/tracing/trace | wc -l)

Minor nit, but you can 'grep -c' instead of 'grep | wc -l'

Ok Done.

Quoted 3 lines

Also could put /sys/kernel/tracing/trace into a variable just for readability since it is used many times.

Done.

Quoted 14 lines
Quoted 14 lines
test/cxl-events.sh new file +13 -0
+echo "     LOG     (Expected) : (Found)"
+echo "     overflow      ( 1) : $num_overflow"
+echo "     Fatal         ( 2) : $num_fatal"
+echo "     Failure       (16) : $num_failure"
+echo "     Informational ( 3) : $num_info"
+
+if [ "$num_overflow" -ne 1 ]; then
+       err "$LINENO"
+fi
+if [ "$num_fatal" -ne 2 ]; then
+       err "$LINENO"
+fi
+if [ "$num_failure" -ne 16 ]; then
Quoted 8 lines

test/cxl-events.sh line 64

Quoted 5 lines
test/cxl-events.sh new file +5 -0
+       err "$LINENO"
+fi
+if [ "$num_info" -ne 3 ]; then
+       err "$LINENO"
+fi

Perhaps define variables for each of the expected nums, that way there is only one spot to change in case the numbers change in the future.

Good idea, done.

V2 on it's way soon, thanks for looking,
Ira

Quoted 32 lines
Quoted 31 lines
test/cxl-events.sh new file +4 -0
+
+check_dmesg "$LINENO"
+
+modprobe -r cxl_test
test/meson.build +1 -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' ],

test/meson.build +1 -0
@@ -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,