On Mon, 2023-11-27 at 20:11 -0800, [email protected] wrote:
> From: Alison Schofield <[email protected]>
> 
> 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 <[email protected]>
> ---
>  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
>  }

Reply via email to