From patchwork Wed Nov 29 01:09:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10081269 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 08BF260353 for ; Wed, 29 Nov 2017 01:09:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F010729727 for ; Wed, 29 Nov 2017 01:09:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3224297BB; Wed, 29 Nov 2017 01:09:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6503829727 for ; Wed, 29 Nov 2017 01:09:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752054AbdK2BJm (ORCPT ); Tue, 28 Nov 2017 20:09:42 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:51272 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751439AbdK2BJm (ORCPT ); Tue, 28 Nov 2017 20:09:42 -0500 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id vAT19dCI002120 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 29 Nov 2017 01:09:40 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id vAT19cO6017568 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 29 Nov 2017 01:09:39 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id vAT19c9T019671; Wed, 29 Nov 2017 01:09:38 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 28 Nov 2017 17:09:38 -0800 Date: Tue, 28 Nov 2017 17:09:37 -0800 From: "Darrick J. Wong" To: Eryu Guan Cc: fstests , xfs Subject: [PATCH] common/rc: report kmemleak errors Message-ID: <20171129010937.GB31372@magnolia> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Source-IP: userv0022.oracle.com [156.151.31.74] Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong If kmemleak is enabled, scan and report memory leaks after every test. Signed-off-by: Darrick J. Wong --- check | 2 ++ common/rc | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe fstests" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/check b/check index b2d251a..469188e 100755 --- a/check +++ b/check @@ -497,6 +497,7 @@ _check_filesystems() fi } +_init_kmemleak _prepare_test_list if $OPTIONS_HAVE_SECTIONS; then @@ -793,6 +794,7 @@ for section in $HOST_OPTIONS_SECTIONS; do n_try=`expr $n_try + 1` _check_filesystems _check_dmesg || err=true + _check_kmemleak || err=true fi fi diff --git a/common/rc b/common/rc index cb83918..6dc77d5 100644 --- a/common/rc +++ b/common/rc @@ -3339,6 +3339,57 @@ _check_dmesg() fi } +# set up kmemleak +_init_kmemleak() +{ + local _kern_knob="/sys/kernel/debug/kmemleak" + + if [ ! -w "${_kern_knob}" ]; then + return 0 + fi + + # Scan for all the memory leaks that have happened to date and + # clear them so that we can pinpoint leaks to tests accurately. + # Scan twice because the first write finishes before the scan + # does.... + echo "scan" > "${_kern_knob}" + cat "${_kern_knob}" > /dev/null + echo "scan" > "${_kern_knob}" + cat "${_kern_knob}" > /dev/null + echo "clear" > "${_kern_knob}" +} + +# check kmemleak log +_check_kmemleak() +{ + local _kern_knob="/sys/kernel/debug/kmemleak" + local _leak_file="${RESULT_DIR}/check_kmemleak" + + if [ ! -w "${_kern_knob}" ]; then + return 0 + fi + + # Tell the kernel to scan for memory leaks. Apparently the write + # returns before the scan is complete, so do it twice in the hopes + # that twice is enough to capture all the leaks. + echo "scan" > "${_kern_knob}" + sed -e 's/age [0-9\.]*s/age XXXX/g' < "${_kern_knob}" > "${_leak_file}.new" + echo "scan" > "${_kern_knob}" + sed -e 's/age [0-9\.]*s/age XXXX/g' < "${_kern_knob}" > "${_leak_file}.new" + + diff -u -N "${_leak_file}" "${_leak_file}.new" > $seqres.kmemleak + res=$? + mv "${_leak_file}.new" "${_leak_file}" + + if [ $res -ne 0 ]; then + _dump_err "_check_kmemleak: something found in kmemleak (see $seqres.kmemleak)" + return 1 + else + rm -f $seqres.kmemleak + return 0 + fi +} + # don't check dmesg log after test _disable_dmesg_check() {