From patchwork Thu May 17 06:29:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 915106 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40mhHN4JHtz9s1d for ; Thu, 17 May 2018 16:29:52 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B59BB3E64B8 for ; Thu, 17 May 2018 08:29:49 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) by picard.linux.it (Postfix) with ESMTP id 945153E6493 for ; Thu, 17 May 2018 08:29:48 +0200 (CEST) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id D49A3601CE6 for ; Thu, 17 May 2018 08:29:47 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7503D4075766; Thu, 17 May 2018 06:29:46 +0000 (UTC) Received: from dhcp-12-102.nay.redhat.com (dhcp-12-102.nay.redhat.com [10.66.12.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 00D482166BAD; Thu, 17 May 2018 06:29:44 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Thu, 17 May 2018 14:29:43 +0800 Message-Id: <20180517062943.13178-1-liwang@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 17 May 2018 06:29:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 17 May 2018 06:29:46 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'liwang@redhat.com' RCPT:'' X-Virus-Scanned: clamav-milter 0.99.2 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_HELO_PASS,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH] ltp: replace the retry loops by new exponential backoff macro X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Li Wang Cc: Petr Vorel Cc: Cyril Hrubis --- testcases/commands/mkswap/mkswap01.sh | 17 ++++------ testcases/kernel/numa/numa01.sh | 58 +++++++++++++++-------------------- 2 files changed, 31 insertions(+), 44 deletions(-) diff --git a/testcases/commands/mkswap/mkswap01.sh b/testcases/commands/mkswap/mkswap01.sh index 1c01c86..fc07933 100755 --- a/testcases/commands/mkswap/mkswap01.sh +++ b/testcases/commands/mkswap/mkswap01.sh @@ -37,25 +37,20 @@ setup() DEVICE_SIZE=$((($real_size/$PAGE_SIZE * $PAGE_SIZE)/1024)) } -wait_for_file() +check_for_file() { local path="$1" - local retries=10 if [ -z "$path" ]; then return fi - while [ $retries -gt 0 ]; do - if [ -e "$path" ]; then - return - fi - tst_res TINFO "Waiting for $path to appear" - retries=$((retries - 1)) - tst_sleep 10ms - done + if [ -e "$path" ]; then + return 0 + fi tst_res TINFO "The file $path haven't appeared" + return 1 } mkswap_verify() @@ -75,7 +70,7 @@ mkswap_verify() local pagesize=$PAGE_SIZE fi - wait_for_file "$dev_file" + TST_RETRY_FUNC "check_for_file "$dev_file"" 0 swapon $swapfile 2>/dev/null diff --git a/testcases/kernel/numa/numa01.sh b/testcases/kernel/numa/numa01.sh index 27a2f2f..f8d8f30 100755 --- a/testcases/kernel/numa/numa01.sh +++ b/testcases/kernel/numa/numa01.sh @@ -59,25 +59,17 @@ extract_numastat_p() echo $(numastat -p $pid |awk '/^Total/ {print $'$node'}') } -wait_for_support_numa() +check_for_support_numa() { local pid=$1 - local retries=20 - while [ $retries -gt 0 ]; do - local state=$(awk '{print $3}' /proc/$pid/stat) + local state=$(awk '{print $3}' /proc/$pid/stat) - if [ $state = 'T' ]; then - break - fi - - retries=$((retries-1)) - tst_sleep 50ms - done - - if [ $retries -le 0 ]; then - tst_brk TBROK "Timeouted while waiting for support_numa ($pid)" + if [ $state = 'T' ]; then + return 0 fi + + return 1 } setup() @@ -109,7 +101,7 @@ test1() numactl --cpunodebind=$node --membind=$node support_numa alloc_1MB & pid=$! - wait_for_support_numa $pid + TST_RETRY_FUNC "check_for_support_numa $pid" 0 Mem_curr=$(echo "$(extract_numastat_p $pid $node) * $MB" |bc) if [ $(echo "$Mem_curr < $MB" | bc) -eq 1 ]; then @@ -143,7 +135,7 @@ test2() numactl --cpunodebind=$node --preferred=$Preferred_node support_numa alloc_1MB & pid=$! - wait_for_support_numa $pid + TST_RETRY_FUNC "check_for_support_numa $pid" 0 Mem_curr=$(echo "$(extract_numastat_p $pid $Preferred_node) * $MB" |bc) if [ $(echo "$Mem_curr < $MB" |bc ) -eq 1 ]; then @@ -179,7 +171,7 @@ test3() numactl --cpunodebind=$node --preferred=$Preferred_node support_numa alloc_1MB_shared & pid=$! - wait_for_support_numa $pid + TST_RETRY_FUNC "check_for_support_numa $pid" 0 Mem_curr=$(echo "$(extract_numastat_p $pid $Preferred_node) * $MB" |bc) if [ $(echo "$Mem_curr < $MB" |bc ) -eq 1 ]; then @@ -206,7 +198,7 @@ test4() numactl --interleave=all support_numa alloc_1MB & pid=$! - wait_for_support_numa $pid + TST_RETRY_FUNC "check_for_support_numa $pid" 0 for node in $nodes_list; do Mem_curr=$(echo "$(extract_numastat_p $pid $node) * $MB" |bc) @@ -233,7 +225,7 @@ test5() numactl --interleave=all support_numa alloc_1MB_shared & pid=$! - wait_for_support_numa $pid + TST_RETRY_FUNC "check_for_support_numa $pid" 0 for node in $nodes_list; do Mem_curr=$(echo "$(extract_numastat_p $pid $node) * $MB" |bc) @@ -292,7 +284,7 @@ test7() numactl --cpunodebind=$node --localalloc support_numa alloc_1MB & pid=$! - wait_for_support_numa $pid + TST_RETRY_FUNC "check_for_support_numa $pid" 0 Mem_curr=$(echo "$(extract_numastat_p $pid $node) * $MB" |bc) if [ $(echo "$Mem_curr < $MB" |bc ) -eq 1 ]; then @@ -308,6 +300,15 @@ test7() tst_res TPASS "NUMA local node allocation" } +check_ltp_numa_test8_log() +{ + if grep -m1 -q '.' ltp_numa_test8.log; then + return 0 + fi + + return 1 +} + # Verification of memhog with interleave policy test8() { @@ -318,16 +319,7 @@ test8() numactl --interleave=all memhog -r1000000 1MB >ltp_numa_test8.log 2>&1 & pid=$! - local retries=20 - while [ $retries -gt 0 ]; do - - if grep -m1 -q '.' ltp_numa_test8.log; then - break - fi - - retries=$((retries-1)) - tst_sleep 50ms - done + TST_RETRY_FUNC "check_ltp_numa_test8_log" 0 for node in $nodes_list; do Mem_curr=$(echo "$(extract_numastat_p $pid $node) * $MB" |bc) @@ -396,7 +388,7 @@ test10() numactl --preferred=$node support_numa alloc_1MB & pid=$! - wait_for_support_numa $pid + TST_RETRY_FUNC "check_for_support_numa $pid" 0 migratepages $pid $node $Preferred_node @@ -439,7 +431,7 @@ test11() numactl --cpunodebind=$node --membind=$node support_numa alloc_1huge_page & pid=$! - wait_for_support_numa $pid + TST_RETRY_FUNC "check_for_support_numa $pid" 0 Mem_huge=$(echo $(numastat -p $pid |awk '/^Huge/ {print $'$((node+2))'}')) Mem_huge=$((${Mem_huge%.*} * 1024)) @@ -482,7 +474,7 @@ test12() numactl --cpunodebind=$node --preferred=$Preferred_node support_numa alloc_2HPSZ_THP & pid=$! - wait_for_support_numa $pid + TST_RETRY_FUNC "check_for_support_numa $pid" 0 Mem_curr=$(echo "$(extract_numastat_p $pid $Preferred_node) * 1024" |bc) if [ $(echo "$Mem_curr < $HPAGE_SIZE * 2" |bc ) -eq 1 ]; then