diff mbox series

[ndctl,2/3] cxl/test: add a cxl_ derivative of check_dmesg()

Message ID 39c11efdefeb12c3c928f36e9c59eeb40a841e72.1701143039.git.alison.schofield@intel.com
State New, archived
Headers show
Series cxl/test: CXL unit test helpers | expand

Commit Message

Alison Schofield Nov. 28, 2023, 4:11 a.m. UTC
From: Alison Schofield <alison.schofield@intel.com>

check_dmesg() is used by CXL unit tests as well as by a few
DAX unit tests. Add a cxl_check_dmesg() version that can be
expanded for CXL special checks like this:

Add a check for an interleave calculation failure. This is
a dev_dbg() message that spews (success or failure) whenever
a user creates a region. It is useful as a regression check
across the entire CXL suite.

Signed-off-by: Alison Schofield <alison.schofield@intel.com>
---
 test/common | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Comments

Dave Jiang Nov. 28, 2023, 6:18 p.m. UTC | #1
On 11/27/23 21:11, alison.schofield@intel.com wrote:
> From: Alison Schofield <alison.schofield@intel.com>
> 
> check_dmesg() is used by CXL unit tests as well as by a few
> DAX unit tests. Add a cxl_check_dmesg() version that can be
> expanded for CXL special checks like this:
> 
> Add a check for an interleave calculation failure. This is
> a dev_dbg() message that spews (success or failure) whenever
> a user creates a region. It is useful as a regression check
> across the entire CXL suite.
> 
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>

> ---
>  test/common | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/test/common b/test/common
> index 7a4711593624..c20b7e48c2b6 100644
> --- a/test/common
> +++ b/test/common
> @@ -151,6 +151,19 @@ check_dmesg()
>  	true
>  }
>  
> +# cxl_check_dmesg
> +# $1: line number where this is called
> +cxl_check_dmesg()
> +{
> +	sleep 1
> +	log=$(journalctl -r -k --since "-$((SECONDS+1))s")
> +	# validate no WARN or lockdep report during the run
> +	grep -q "Call Trace" <<< "$log" && err "$1"
> +	# validate no failures of the interleave calc dev_dbg() check
> +	grep -q "Test cxl_calc_interleave_pos(): fail" <<< "$log" && err "$1"
> +	true
> +}
> +
>  # cxl_common_start
>  # $1: optional module parameter(s) for cxl-test
>  cxl_common_start()
> @@ -170,6 +183,6 @@ cxl_common_start()
>  # $1: line number where this is called
>  cxl_common_stop()
>  {
> -	check_dmesg "$1"
> +	cxl_check_dmesg "$1"
>  	modprobe -r cxl_test
>  }
Verma, Vishal L Nov. 28, 2023, 10:11 p.m. UTC | #2
On Mon, 2023-11-27 at 20:11 -0800, alison.schofield@intel.com wrote:
> From: Alison Schofield <alison.schofield@intel.com>
> 
> check_dmesg() is used by CXL unit tests as well as by a few
> DAX unit tests. Add a cxl_check_dmesg() version that can be
> expanded for CXL special checks like this:
> 
> Add a check for an interleave calculation failure. This is
> a dev_dbg() message that spews (success or failure) whenever
> a user creates a region. It is useful as a regression check
> across the entire CXL suite.
> 
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>
> ---
>  test/common | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/test/common b/test/common
> index 7a4711593624..c20b7e48c2b6 100644
> --- a/test/common
> +++ b/test/common
> @@ -151,6 +151,19 @@ check_dmesg()
>         true
>  }
>  
> +# cxl_check_dmesg
> +# $1: line number where this is called
> +cxl_check_dmesg()
> +{
> +       sleep 1
> +       log=$(journalctl -r -k --since "-$((SECONDS+1))s")
> +       # validate no WARN or lockdep report during the run
> +       grep -q "Call Trace" <<< "$log" && err "$1"
> +       # validate no failures of the interleave calc dev_dbg() check
> +       grep -q "Test cxl_calc_interleave_pos(): fail" <<< "$log" && err "$1"
> +       true
> +}

I like the idea of adding new checks - how about a generic helper that
greps on a list of strings passed to it, and wrappers on top of it can
have their own custom set of strings.

Something like this (untested):

# __check_dmesg
# $1: line number where this is called
# $2.. : strings to check for
__check_dmesg()
{
	line="$1"
	shift
	strings=( "$@" )

	sleep 1
	log=$(journalctl -r -k --since "-$((SECONDS+1))s")
		for string in "${strings[@]}"; do
			if grep -q "$string" <<< $log; then
				err "$line"
			fi
		done
	true
}

check_dmesg()
{
	line="$1"
	shift
	strings=( "$@" )

	__check_dmesg "$line" "Call Trace" "${strings[@]}"
}

cxl_check_dmesg()
{
	line="$1"
	shift
	strings=( "$@" )

	check_dmesg "$line" \
		"Test cxl_calc_interleave_pos(): fail" \
		"${strings[@]}"
}

This lets tests opt in to any 'level' of checks, and lets them add any
of their own test-specific strings to be checked at any stage as well.

> +
>  # cxl_common_start
>  # $1: optional module parameter(s) for cxl-test
>  cxl_common_start()
> @@ -170,6 +183,6 @@ cxl_common_start()
>  # $1: line number where this is called
>  cxl_common_stop()
>  {
> -       check_dmesg "$1"
> +       cxl_check_dmesg "$1"
>         modprobe -r cxl_test
>  }
diff mbox series

Patch

diff --git a/test/common b/test/common
index 7a4711593624..c20b7e48c2b6 100644
--- a/test/common
+++ b/test/common
@@ -151,6 +151,19 @@  check_dmesg()
 	true
 }
 
+# cxl_check_dmesg
+# $1: line number where this is called
+cxl_check_dmesg()
+{
+	sleep 1
+	log=$(journalctl -r -k --since "-$((SECONDS+1))s")
+	# validate no WARN or lockdep report during the run
+	grep -q "Call Trace" <<< "$log" && err "$1"
+	# validate no failures of the interleave calc dev_dbg() check
+	grep -q "Test cxl_calc_interleave_pos(): fail" <<< "$log" && err "$1"
+	true
+}
+
 # cxl_common_start
 # $1: optional module parameter(s) for cxl-test
 cxl_common_start()
@@ -170,6 +183,6 @@  cxl_common_start()
 # $1: line number where this is called
 cxl_common_stop()
 {
-	check_dmesg "$1"
+	cxl_check_dmesg "$1"
 	modprobe -r cxl_test
 }