From nobody Wed Apr 1 09:43:45 2026 Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62B6E3BAD8D for ; Tue, 31 Mar 2026 11:51:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774957878; cv=none; b=L/yofND1uo1GUsEomHteKXBUAlUhMcSMHu0d14Cb9F3jKahOpi0tXfVk3pT87UVB11Lyd0tiSXdMxAtD2buhdJoWm0pYxt+bKiuWgr1OxmUeY109EatdCQOhTokxp9yag5lHdtAiqcAIIeqkc4uNpk7IbdHLl3lMC1r1P5eklb4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774957878; c=relaxed/simple; bh=MOHg8GNucDfsNquw43LHOfCrdChFF0YE3N1a8S/iBrA=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=u48fk9BBkGkpPwSCGiY79KZ1Ctc85+M/J+5JHYmV7VKGoSiqzerxjxnTH/8MgTu6NHPeLC8oEEQANd9YzgW578OQ3vMSRoJncYajqblrnqeSRd1HPwr7os/uucjhVFFlS87H8LJ5e1M2H7FAwA2/7N4jPAI3eKzJlBnpipmxjt0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--hmazur.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=WuMEOKSw; arc=none smtp.client-ip=209.85.208.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--hmazur.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WuMEOKSw" Received: by mail-ed1-f73.google.com with SMTP id 4fb4d7f45d1cf-66bb7305ae7so2400430a12.2 for ; Tue, 31 Mar 2026 04:51:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774957874; x=1775562674; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=WRloscZyoQNUj+6jOFuo3gKcXIEEqAMmJol3GtAnhZc=; b=WuMEOKSwDPh3h3OkCFSCZTH8PnSJbor1sFst0kaUDmp86rGU2Aw3q/txvsStEafhi3 0U5bdLNC3XwTUYcE2MLaGmg4H4OofsrDipNfCKIGzNcUivNQvHGbJE8F5vib5WPjXlBQ hozVGIMlJOav3BduL26sAiV4Lhx1gtXrIoky0yEHkEHjRWrmuQV6sEcf8cTT1fTgxV5S qpcbQgwnzcqQMCMLv4cBZrUfJ9zr2PE82AqXZaQdK6xgOUZ3u1HZquK88gD8/XV32Sqo WbKyBTDlMSwEUYBzh60UQ1bYovbP7BLugWjctaKUfiC6y2dDvLZR38eNoonAMfq7FttL 2Yvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774957874; x=1775562674; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=WRloscZyoQNUj+6jOFuo3gKcXIEEqAMmJol3GtAnhZc=; b=YabX1XkGFQHpHhHVcILdmDNBYUN4JDiskfB+JYg2o6TRyn+sHuLCxD7gD2YrNSXhF4 LP56vCUSrnQfCxhVLsSHT/ClFg7XykQeXrCFVbnVk7B3Fm11LiX685+e/AyE0TK/z6am UJCQDuVtc/2T0QFiMnrdi5FppFehSXI0aEze4FU9+tWKXXFGnUuPXx9EpLDtJoRY1MXn Jf3Hj03EHdsHA0+gIlBZcdj7AJu4fOIIFD7to7i8qc34GkGkI33uvoxQj4qjp3JHl/0g +HjwK7YSyKKcV/VJh5OsiAjE579osRbMWUnapaOuod8JQap3bBwpZNfN77LfgX6TV8Vs mQTg== X-Forwarded-Encrypted: i=1; AJvYcCUI3QGkLjf3pdobHpWgv/XBAgE5IVeWzoA1CG2fR3FA2gW1FDvckJHUUBgKXFWC/YpbmVQXTWRt/ALS8RA=@vger.kernel.org X-Gm-Message-State: AOJu0YxbBhUdIjnuTlwvB5TPfhwDhRJVIym7dg0OT9f6elpsfA+rLGOP doQa7htvE1svjxX0mhl7qBpC4Z2daGv1ETY3Yv5Wu43IJ4VNTnEk6ntrHfQUk953RjJP9kTlmeA farD8fw== X-Received: from eddz21.prod.google.com ([2002:a05:6402:2755:b0:662:582d:af8e]) (user=hmazur job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:21da:b0:668:3afb:a775 with SMTP id 4fb4d7f45d1cf-66b28c6ad07mr8185674a12.18.1774957873686; Tue, 31 Mar 2026 04:51:13 -0700 (PDT) Date: Tue, 31 Mar 2026 11:51:10 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.53.0.1018.g2bb0e51243-goog Message-ID: <20260331115111.1522473-1-hmazur@google.com> Subject: [PATCH v2] selftests/cpu-hotplug: Make the script complaint with sh shell From: Hubert Mazur To: Shuah Khan , Jihed Chaibi Cc: Lukasz Majczak , Slawomir Rosek , Wake Liu , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Hubert Mazur Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The script uses by default the bash shell that is inaccessible in the x86 embedded devices. This leads to the syntax errors. To mitigate this, change the interpreter to /bin/sh and rework the prints from echo to printf to make it more robust and posix compliant. Change the conditional check for being a root from not existent UID and replace with command execution "id -u". Signed-off-by: Hubert Mazur --- Changes in v2: - Fix issues reported with sashiko.dev - https://sashiko.dev/#/patchset/20260318080825.3063959-2-hmazur%40google= .com - Make sure the script is compliant with strict posix shells - Test the script syntax on busybox Link to v1: - https://lore.kernel.org/all/20260318080825.3063959-2-hmazur@google.com/ .../selftests/cpu-hotplug/cpu-on-off-test.sh | 74 ++++++++++--------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh b/tools= /testing/selftests/cpu-hotplug/cpu-on-off-test.sh index 6232a46ca6e1..a91c8e47fe46 100755 --- a/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh +++ b/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # SPDX-License-Identifier: GPL-2.0 =20 SYSFS=3D @@ -10,8 +10,8 @@ prerequisite() { msg=3D"skip all tests:" =20 - if [ $UID !=3D 0 ]; then - echo $msg must be run as root >&2 + if [ $(id -u) -ne 0 ]; then + printf "%s must be run as root\n" "$msg" >&2 exit $ksft_skip fi =20 @@ -20,37 +20,37 @@ prerequisite() SYSFS=3D`mount -t sysfs | head -1 | awk '{ print $3 }'` =20 if [ ! -d "$SYSFS" ]; then - echo $msg sysfs is not mounted >&2 + printf "%s sysfs is not mounted\n" "$msg" >&2 exit $ksft_skip fi =20 if ! ls $SYSFS/devices/system/cpu/cpu* > /dev/null 2>&1; then - echo $msg cpu hotplug is not supported >&2 + printf "%s cpu hotplug is not supported\n" "$msg" >&2 exit $ksft_skip fi =20 - echo "CPU online/offline summary:" + printf "CPU online/offline summary:\n" online_cpus=3D`cat $SYSFS/devices/system/cpu/online` online_max=3D${online_cpus##*-} =20 - if [[ "$online_cpus" =3D "$online_max" ]]; then - echo "$msg: since there is only one cpu: $online_cpus" + if [ "$online_cpus" =3D "$online_max" ]; then + printf "%s since there is only one cpu: %s\n" "$msg" "$online_cpus" exit $ksft_skip fi =20 present_cpus=3D`cat $SYSFS/devices/system/cpu/present` present_max=3D${present_cpus##*-} - echo "present_cpus =3D $present_cpus present_max =3D $present_max" + printf "present_cpus =3D %s, present_max =3D %s\n" "$present_cpus" "$pre= sent_max" =20 - echo -e "\t Cpus in online state: $online_cpus" + printf "\t Cpus in online state: %s\n" "$online_cpus" =20 offline_cpus=3D`cat $SYSFS/devices/system/cpu/offline` - if [[ "a$offline_cpus" =3D "a" ]]; then + if [ "a$offline_cpus" =3D "a" ]; then offline_cpus=3D0 else offline_max=3D${offline_cpus##*-} fi - echo -e "\t Cpus in offline state: $offline_cpus" + printf "\t Cpus in offline state: %s\n" "$offline_cpus" } =20 # @@ -62,7 +62,7 @@ hotpluggable_cpus() =20 for cpu in $SYSFS/devices/system/cpu/cpu*; do if [ -f $cpu/online ] && grep -q $state $cpu/online; then - echo ${cpu##/*/cpu} + printf "%s\n" "${cpu##/*/cpu}" fi done } @@ -99,39 +99,44 @@ offline_cpu() =20 online_cpu_expect_success() { + FUNC=3D"online_cpu_expect_success()" local cpu=3D$1 =20 if ! online_cpu $cpu; then - echo $FUNCNAME $cpu: unexpected fail >&2 + printf "%s %s: unexpected fail\n" "$FUNC" "$cpu" >&2 retval=3D1 elif ! cpu_is_online $cpu; then - echo $FUNCNAME $cpu: unexpected offline >&2 + printf "%s %s: unexpected offline\n" "$FUNC" "$cpu" >&2 retval=3D1 fi } =20 online_cpu_expect_fail() { + + FUNC=3D"online_cpu_expect_fail()" local cpu=3D$1 =20 if online_cpu $cpu 2> /dev/null; then - echo $FUNCNAME $cpu: unexpected success >&2 + printf "%s %s: unexpected success\n" "$FUNC" "$cpu" >&2 retval=3D1 elif ! cpu_is_offline $cpu; then - echo $FUNCNAME $cpu: unexpected online >&2 + printf "%s %s: unexpected online\n" "$FUNC" "$cpu" >&2 retval=3D1 fi } =20 offline_cpu_expect_success() { + + FUNC=3D"offline_cpu_expect_success()" local cpu=3D$1 =20 if ! offline_cpu $cpu; then - echo $FUNCNAME $cpu: unexpected fail >&2 + printf "%s %s: unexpected fail\n" "$FUNC" "$cpu" >&2 retval=3D1 elif ! cpu_is_offline $cpu; then - echo $FUNCNAME $cpu: unexpected offline >&2 + printf "%s %s: unexpected offline\n" "$FUNC" "$cpu" >&2 retval=3D1 fi } @@ -139,12 +144,13 @@ offline_cpu_expect_success() offline_cpu_expect_fail() { local cpu=3D$1 + FUNC=3D"offline_cpu_expect_fail()" =20 if offline_cpu $cpu 2> /dev/null; then - echo $FUNCNAME $cpu: unexpected success >&2 + printf "%s %s: unexpected success\n" "$FUNC" "$cpu" >&2 retval=3D1 elif ! cpu_is_online $cpu; then - echo $FUNCNAME $cpu: unexpected offline >&2 + printf "%s %s: unexpected offline\n" "$FUNC" "$cpu" >&2 retval=3D1 fi } @@ -182,9 +188,9 @@ while getopts ah opt; do allcpus=3D1 ;; h) - echo "Usage $0 [ -a ]" - echo -e "\t default offline one cpu" - echo -e "\t run with -a option to offline all cpus" + printf "Usage %s [ -a ]\n" "$0" + printf "\t default offline one cpu\n" + printf "\t run with -a option to offline all cpus\n" exit ;; esac @@ -195,25 +201,25 @@ prerequisite # # Safe test (default) - offline and online one cpu # -if [ $allcpus -eq 0 ]; then - echo "Limited scope test: one hotplug cpu" - echo -e "\t (leaves cpu in the original state):" - echo -e "\t online to offline to online: cpu $online_max" +if [ "$allcpus" -eq 0 ]; then + printf "Limited scope test: one hotplug cpu\n" + printf "\t (leaves cpu in the original state):\n" + printf "\t online to offline to online: cpu %s\n" "$online_max" offline_cpu_expect_success $online_max online_cpu_expect_success $online_max =20 - if [[ $offline_cpus -gt 0 ]]; then - echo -e "\t online to offline to online: cpu $present_max" + if [ "$offline_cpus" -gt 0 ]; then + printf "\t online to offline to online: cpu %s\n" "$present_max" online_cpu_expect_success $present_max offline_cpu_expect_success $present_max online_cpu $present_max fi exit $retval else - echo "Full scope test: all hotplug cpus" - echo -e "\t online all offline cpus" - echo -e "\t offline all online cpus" - echo -e "\t online all offline cpus" + printf "Full scope test: all hotplug cpus\n" + printf "\t online all offline cpus\n" + printf "\t offline all online cpus\n" + printf "\t online all offline cpus\n" fi =20 online_all_hot_pluggable_cpus --=20 2.53.0.1018.g2bb0e51243-goog