[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240920175842.388781-1-quic_wasimn@quicinc.com>
Date: Fri, 20 Sep 2024 23:28:42 +0530
From: Wasim Nazir <quic_wasimn@...cinc.com>
To: Shuah Khan <shuah@...nel.org>, Bjorn Andersson <andersson@...nel.org>,
Mathieu Poirier <mathieu.poirier@...aro.org>
Cc: linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org,
linux-remoteproc@...r.kernel.org,
Wasim Nazir <quic_wasimn@...cinc.com>
Subject: [PATCH] selftest: remoteproc: Add basic test for start/stop sequence
Add new basic remoteproc test that check start/stop
sequence of all subsystems available.
diff --git a/MAINTAINERS b/MAINTAINERS
index e062b5328341..aff76edc4242 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -18225,6 +18225,7 @@ F: Documentation/staging/remoteproc.rst
F: drivers/remoteproc/
F: include/linux/remoteproc.h
F: include/linux/remoteproc/
+F: tools/testing/selftests/remoteproc/
REMOTE PROCESSOR MESSAGING (RPMSG) SUBSYSTEM
M: Bjorn Andersson <andersson@...nel.org>
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 697f13bbbc32..31db0311efdc 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -68,6 +68,7 @@ TARGETS += proc
TARGETS += pstore
TARGETS += ptrace
TARGETS += openat2
+TARGETS += remoteproc
TARGETS += resctrl
TARGETS += riscv
TARGETS += rlimits
diff --git a/tools/testing/selftests/remoteproc/Makefile b/tools/testing/selftests/remoteproc/Makefile
new file mode 100644
index 000000000000..a84b3934fd36
--- /dev/null
+++ b/tools/testing/selftests/remoteproc/Makefile
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
+TEST_PROGS := remoteproc_test.sh
+
+include ../lib.mk
diff --git a/tools/testing/selftests/remoteproc/config b/tools/testing/selftests/remoteproc/config
new file mode 100644
index 000000000000..a5c237d2f3b4
--- /dev/null
+++ b/tools/testing/selftests/remoteproc/config
@@ -0,0 +1 @@
+CONFIG_REMOTEPROC=y
diff --git a/tools/testing/selftests/remoteproc/remoteproc_test.sh b/tools/testing/selftests/remoteproc/remoteproc_test.sh
new file mode 100644
index 000000000000..88c8f15d8406
--- /dev/null
+++ b/tools/testing/selftests/remoteproc/remoteproc_test.sh
@@ -0,0 +1,165 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+#
+# Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
+#
+
+DIR="$(dirname $(readlink -f "$0"))"
+
+KTAP_HELPERS="${DIR}/../kselftest/ktap_helpers.sh"
+if [ -e "$KTAP_HELPERS" ]; then
+ source "$KTAP_HELPERS"
+else
+ echo -n "1..0 # SKIP $KTAP_HELPERS file not found"
+ exit 4
+fi
+
+RPROC_SYS=/sys/class/remoteproc
+RPROC_SEQ_SLEEP=5
+rproc_ss_files=
+num_tests=0
+test_err=0
+
+check_error() {
+ if [ $? -ne 0 ]; then
+ test_err=$((test_err+1))
+ ktap_print_msg "$@"
+ fi
+}
+
+rproc_seq_test_ss_one() {
+ ss=$1
+ rproc=${RPROC_SYS}/$ss
+ rproc_name=$(cat $rproc/name)
+ rproc_state=$(cat $rproc/state)
+ rproc_ssr=$(cat $rproc/recovery)
+ ktap_print_msg "Testing rproc sequence for $rproc_name"
+
+ # Reset test_err value
+ test_err=0
+ if [ "$rproc_ssr" != "enabled" ]; then
+ echo enabled > $rproc/recovery
+ check_error "$rproc_name SSR-enabled failed"
+ fi
+
+ if [ "$rproc_state" != "running" ]; then
+ echo start > "$rproc/state"
+ check_error "$rproc_name state-start failed"
+
+ sleep ${RPROC_SEQ_SLEEP}
+
+ echo stop > "$rproc/state"
+ check_error "$rproc_name state-stop failed"
+ else
+ echo stop > "$rproc/state"
+ check_error "$rproc_name state-stop failed"
+
+ sleep ${RPROC_SEQ_SLEEP}
+
+ echo start > "$rproc/state"
+ check_error "$rproc_name state-start failed"
+ fi
+
+ if [ $test_err -ne 0 ]; then
+ ktap_test_fail "$rproc_name"
+ else
+ ktap_test_pass "$rproc_name"
+ fi
+}
+
+rproc_seq_test_all_ss() {
+ # Declare an array to save initial states of each ss
+ org_ss_to_state=""
+
+ # Reset test_err value
+ test_err=0
+
+ for ss in ${rproc_ss_files}; do
+ rproc=${RPROC_SYS}/$ss
+ rproc_name=$(cat $rproc/name)
+ rproc_ssr=$(cat $rproc/recovery)
+
+ # Enable SSR-recovery support
+ if [ "$rproc_ssr" != "enabled" ]; then
+ echo enabled > $rproc/recovery
+ check_error "$rproc_name SSR-enabled failed"
+ fi
+ done
+
+ for ss in ${rproc_ss_files}; do
+ rproc=${RPROC_SYS}/$ss
+ rproc_name=$(cat $rproc/name)
+ rproc_state=$(cat $rproc/state)
+
+ # Save initial states for each ss
+ org_ss_to_state="$org_ss_to_state $rproc_state"
+
+ # Initiate start/stop sequence
+ if [ "$rproc_state" != "running" ]; then
+ echo start > "$rproc/state"
+ check_error "$rproc_name state-start failed"
+ else
+ echo stop > "$rproc/state"
+ check_error "$rproc_name state-stop failed"
+ fi
+ sleep ${RPROC_SEQ_SLEEP}
+ done
+
+ index=1
+ for ss in ${rproc_ss_files}; do
+ rproc=${RPROC_SYS}/$ss
+ rproc_name=$(cat $rproc/name)
+ rproc_state=$(cat $rproc/state)
+
+ ss_state=$(echo $org_ss_to_state | cut -d' ' -f$index)
+ # Terminate start/stop sequence
+ if [ "$ss_state" != "running" ]; then
+ echo stop > "$rproc/state"
+ check_error "$rproc_name state-stop failed"
+ else
+ echo start > "$rproc/state"
+ check_error "$rproc_name state-start failed"
+ fi
+ index=$((index+1))
+ sleep ${RPROC_SEQ_SLEEP}
+ done
+
+ if [ $test_err -ne 0 ]; then
+ ktap_test_fail "for any of $rproc_ss_files"
+ else
+ ktap_test_pass "for all $rproc_ss_files"
+ fi
+}
+
+ktap_print_header
+
+if [[ ! -d "${RPROC_SYS}" ]]; then
+ ktap_skip_all "${RPROC_SYS} doesn't exist."
+ exit "${KSFT_SKIP}"
+fi
+
+rproc_ss_files=$(find ${RPROC_SYS}/remoteproc* -maxdepth 1 -exec basename {} \;)
+num_tests=$(echo ${rproc_ss_files} | wc -w)
+if [[ "${num_tests}" -eq 0 ]]; then
+ ktap_skip_all "${RPROC_SYS}/remoteproc* doesn't exist."
+ exit "${KSFT_SKIP}"
+fi
+
+# Total tests will be:
+# 1) Seq tests for each subsystem sequencially
+# 2) Seq tests for all subsystems concurrently
+num_tests=$((num_tests+1))
+
+ktap_set_plan "${num_tests}"
+
+# Test 1
+ktap_print_msg "Testing rproc up/down sequence for each subsystem sequencially"
+for ss in ${rproc_ss_files}; do
+ rproc_seq_test_ss_one $ss
+done
+
+# Test 2
+ktap_print_msg "Testing rproc up/down sequence for all subsystems concurrently"
+rproc_seq_test_all_ss
+
+ktap_finished
--
2.46.1
Powered by blists - more mailing lists