Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp848234pxb; Fri, 22 Apr 2022 12:30:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1SVxJEnZq9jR/d+Jr5Y/IHGYKBDzeH9qbRg+6JNZlXIfpRBHoQCErtDkxj0/zqTb44DjO X-Received: by 2002:a63:c10c:0:b0:3a9:aac3:dd89 with SMTP id w12-20020a63c10c000000b003a9aac3dd89mr5365752pgf.110.1650655841618; Fri, 22 Apr 2022 12:30:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650655841; cv=none; d=google.com; s=arc-20160816; b=YD2wMKB3N8S/OGJ3orVLlnB0sN1SVV4TWNJsF2rppQXCrSwnAScfcqSdA4TH7DHa75 ZpliOewIbUMv0nRyRvrZUemU7Ip0a4Ytlmf1OnyXkyg7Qze9SCLXQYAd+ynQOn0EtZ1w KDelDg1GBYSY5sh7AH2+R/oNsandZtDWNE7WBPDm6n1nEy/TpiaWjx7A1FYM+zOsdYKN GVVdkz11JeDwtMvDV2lssucoAVOlwXS8sSQQeiOaQlBQ2w2h6Gi2SkEoqiRoVIdhmdp5 abM/L1gXg1R7C4dAd87+14ACErRryNqnDiPhBzE9W5guIGl2uWkUtppWBVt/s1Mh+SNn zKDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=xa3gPtQxiIaZQi4cOdGfuCjGLSoIDga5By+KnB16kpE=; b=IEo4KCFLdIkoNzJdC2eu9w1fSAVOTvPxeIOU9C2ZaOf9ODSHWDoXodQWkvmpASP4f2 4uGHDgU952XYciZ+qvZf2wW3Qr0whb7taAEvtM9zXhK0lp4nLf/cU93RxlPJQY3hqj8n b8XCWGld8489rO7YyAiVtEIeQYK7MmSxhdQqxzS4hn9Bv7ACxXPduuZR/eFtyK3tpNS5 OYXbgZTkA1ecDjBWRZQyLQuiWkm/vCgGK5CsW2LaAgQJaCFywY0PjHeYCxlbQ1eJg8J6 DvU495JgTC4aZhMSUjEGsqa5zqwgscOSEm570RAY2401B4sVKuMdKJReeFDOTQlwqGdA fekQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=WDlmKDHD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id e6-20020a17090301c600b00156dd62acffsi9834137plh.376.2022.04.22.12.30.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 12:30:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=WDlmKDHD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DED201D70C9; Fri, 22 Apr 2022 11:40:47 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1391928AbiDUWwy (ORCPT + 99 others); Thu, 21 Apr 2022 18:52:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1391912AbiDUWwb (ORCPT ); Thu, 21 Apr 2022 18:52:31 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32B7F46164 for ; Thu, 21 Apr 2022 15:49:39 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-2f4cd508549so42237677b3.22 for ; Thu, 21 Apr 2022 15:49:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=xa3gPtQxiIaZQi4cOdGfuCjGLSoIDga5By+KnB16kpE=; b=WDlmKDHDZdMB81vcHg2wWwoZSgM+ke7xK/5wdN1pMuGhi2snEtkLZRZojK+iBRPim8 j2+0mQW+4OmahwojdP5OQ9Bbj8QhExOsbr3qCM3HO4JesmgSTyiqJqnaQUlk1fxXIYDq eMtNdpAESyzwOwHEP01uBBXFslQy4/EPjk5FrJQ5z86PhWDSqoOA5OyfI7wyu0Iwd0Z2 CZIB3lS9ph+NQvfYLwZ0w4NhZI6PRNorTGePhPTk9SpAoDEysEFQOYIvUYIjI5yH02dF 0qQfaKFYxHfeKQk035UW+lrYG5/G2ok2BQt4OI3iVW5xNSv67TCS8nig7Ddiqn9vC776 +fGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=xa3gPtQxiIaZQi4cOdGfuCjGLSoIDga5By+KnB16kpE=; b=pCxh7PGwsVeIh1HS+sjCQzRkOvJxxTjZBBPqXw7c/KGgcHn+QhAFg1efqWI/Vv/aex 19UKyeEts+WIzS2Bmp0+JCiQ3NPZGes1KOdvHm3ni69ITXbT4DlKMxS9zL+Fk/ogKs1K fMXZWH7v6c1AmW3+JN+MZfLdLNlVnrGi72sCZD+SKc8rxcwk3U+LgbQDawLGpOmw9gBc kJpNbMcsNAYw6qBE414a/yQbU8A7agG19T9xKgMZ+3CgcpN06RXwL0UOgzOy025MLjH1 7RT77GcPUlNr/Q8VMVlxB7RnI1y8PyQJelVbhVHnSP69WzaLTJIjWO52OWSvVhUlCNEV nImg== X-Gm-Message-State: AOAM531KjeZMqs6qYAmZdNMfKjAlz7HzrcduAJsnoBqRhxnJO/YWO58l uDt+XklrJtfhpprlJ9DSmLvDcYKE2sCtLBK6tG6j X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:1cc4:3b55:a67d:61fa]) (user=axelrasmussen job=sendgmr) by 2002:a5b:24e:0:b0:63d:cba0:3d55 with SMTP id g14-20020a5b024e000000b0063dcba03d55mr1880487ybp.613.1650581378449; Thu, 21 Apr 2022 15:49:38 -0700 (PDT) Date: Thu, 21 Apr 2022 15:49:28 -0700 In-Reply-To: <20220421224928.1848230-1-axelrasmussen@google.com> Message-Id: <20220421224928.1848230-2-axelrasmussen@google.com> Mime-Version: 1.0 References: <20220421224928.1848230-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog Subject: [PATCH 2/2] selftests: vm: fix shellcheck warnings in run_vmtests.sh From: Axel Rasmussen To: Andrew Morton , Shuah Khan Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Axel Rasmussen Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org These might not be issues yet, but they make the script more fragile. Also by fixing them we give a better example to future readers, who might copy/paste or otherwise re-use snippets from our script. - Use "read -r", since we don't ever want read to be interpreting '\' characters as escape sequences... - Quote variables, to deal with spaces properly. - Use $() instead of the older and harder-to-nest ``. - Get rid of superfluous "$" prefixes inside arithmetic $(()). Signed-off-by: Axel Rasmussen --- tools/testing/selftests/vm/run_vmtests.sh | 55 +++++++++++------------ 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/tools/testing/selftests/vm/run_vmtests.sh b/tools/testing/selftests/vm/run_vmtests.sh index 2d5a3da42cbe..a2302b5faaf2 100755 --- a/tools/testing/selftests/vm/run_vmtests.sh +++ b/tools/testing/selftests/vm/run_vmtests.sh @@ -9,12 +9,12 @@ mnt=./huge exitcode=0 #get huge pagesize and freepages from /proc/meminfo -while read name size unit; do +while read -r name size unit; do if [ "$name" = "HugePages_Free:" ]; then - freepgs=$size + freepgs="$size" fi if [ "$name" = "Hugepagesize:" ]; then - hpgsize_KB=$size + hpgsize_KB="$size" fi done < /proc/meminfo @@ -30,27 +30,26 @@ needmem_KB=$((half_ufd_size_MB * 2 * 1024)) #set proper nr_hugepages if [ -n "$freepgs" ] && [ -n "$hpgsize_KB" ]; then - nr_hugepgs=`cat /proc/sys/vm/nr_hugepages` + nr_hugepgs=$(cat /proc/sys/vm/nr_hugepages) needpgs=$((needmem_KB / hpgsize_KB)) tries=2 - while [ $tries -gt 0 ] && [ $freepgs -lt $needpgs ]; do - lackpgs=$(( $needpgs - $freepgs )) + while [ "$tries" -gt 0 ] && [ "$freepgs" -lt "$needpgs" ]; do + lackpgs=$((needpgs - freepgs)) echo 3 > /proc/sys/vm/drop_caches - echo $(( $lackpgs + $nr_hugepgs )) > /proc/sys/vm/nr_hugepages - if [ $? -ne 0 ]; then + if ! echo $((lackpgs + nr_hugepgs)) > /proc/sys/vm/nr_hugepages; then echo "Please run this test as root" exit $ksft_skip fi - while read name size unit; do + while read -r name size unit; do if [ "$name" = "HugePages_Free:" ]; then freepgs=$size fi done < /proc/meminfo tries=$((tries - 1)) done - if [ $freepgs -lt $needpgs ]; then + if [ "$freepgs" -lt "$needpgs" ]; then printf "Not enough huge pages available (%d < %d)\n" \ - $freepgs $needpgs + "$freepgs" "$needpgs" exit 1 fi else @@ -60,11 +59,11 @@ fi #filter 64bit architectures ARCH64STR="arm64 ia64 mips64 parisc64 ppc64 ppc64le riscv64 s390x sh64 sparc64 x86_64" -if [ -z $ARCH ]; then - ARCH=`uname -m 2>/dev/null | sed -e 's/aarch64.*/arm64/'` +if [ -z "$ARCH" ]; then + ARCH=$(uname -m 2>/dev/null | sed -e 's/aarch64.*/arm64/') fi VADDR64=0 -echo "$ARCH64STR" | grep $ARCH && VADDR64=1 +echo "$ARCH64STR" | grep "$ARCH" && VADDR64=1 # Usage: run_test [test binary] [arbitrary test arguments...] run_test() { @@ -85,28 +84,28 @@ run_test() { fi } -mkdir $mnt -mount -t hugetlbfs none $mnt +mkdir "$mnt" +mount -t hugetlbfs none "$mnt" run_test ./hugepage-mmap -shmmax=`cat /proc/sys/kernel/shmmax` -shmall=`cat /proc/sys/kernel/shmall` +shmmax=$(cat /proc/sys/kernel/shmmax) +shmall=$(cat /proc/sys/kernel/shmall) echo 268435456 > /proc/sys/kernel/shmmax echo 4194304 > /proc/sys/kernel/shmall run_test ./hugepage-shm -echo $shmmax > /proc/sys/kernel/shmmax -echo $shmall > /proc/sys/kernel/shmall +echo "$shmmax" > /proc/sys/kernel/shmmax +echo "$shmall" > /proc/sys/kernel/shmall run_test ./map_hugetlb -run_test ./hugepage-mremap $mnt/huge_mremap -rm -f $mnt/huge_mremap +run_test ./hugepage-mremap "$mnt"/huge_mremap +rm -f "$mnt"/huge_mremap run_test ./hugepage-vmemmap -run_test ./hugetlb-madvise $mnt/madvise-test -rm -f $mnt/madvise-test +run_test ./hugetlb-madvise "$mnt"/madvise-test +rm -f "$mnt"/madvise-test echo "NOTE: The above hugetlb tests provide minimal coverage. Use" echo " https://github.com/libhugetlbfs/libhugetlbfs.git for" @@ -124,13 +123,13 @@ run_test ./gup_test -ct -F 0x1 0 19 0x1000 run_test ./userfaultfd anon 20 16 # Test requires source and destination huge pages. Size of source # (half_ufd_size_MB) is passed as argument to test. -run_test ./userfaultfd hugetlb $half_ufd_size_MB 32 +run_test ./userfaultfd hugetlb "$half_ufd_size_MB" 32 run_test ./userfaultfd shmem 20 16 #cleanup -umount $mnt -rm -rf $mnt -echo $nr_hugepgs > /proc/sys/vm/nr_hugepages +umount "$mnt" +rm -rf "$mnt" +echo "$nr_hugepgs" > /proc/sys/vm/nr_hugepages run_test ./compaction_test -- 2.36.0.rc2.479.g8af0fa9b8e-goog