From patchwork Tue Jun 27 00:52:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orson Zhai X-Patchwork-Id: 106382 Delivered-To: patch@linaro.org Received: by 10.140.101.48 with SMTP id t45csp635041qge; Mon, 26 Jun 2017 17:56:20 -0700 (PDT) X-Received: by 10.98.219.5 with SMTP id f5mr2682464pfg.2.1498524980692; Mon, 26 Jun 2017 17:56:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498524980; cv=none; d=google.com; s=arc-20160816; b=FcTEaGiNrTkI9r/yg7TQ9s+DO6yxadhLvJl/5mzQabsO23wIgtMPt1+5TJ9tBeld0I BOVy3j4dFx/cW6MGXJ9q81rPvAf2g3P5XmcmkEcryN+0LovFuXLnCwa9CbIbhGiOfSX4 P3jeP75FE5jovFii3LuQVFApFS+SwJZyEgmZm3DAhd30y2yYFi/e8CNb8dMFCNDHZJgC fNkBCLMLXIAr2J64AdUyITnRJEg/fIv8T/e9pQkVcbq8qTRfs49Aj+Zcsecf+juOcyDL qxdJ2D618zLY5/WbYOmo9g7/3TtxyjiFvZBGD7fyDmWXP11UmGwP7NSfHK0kFZWGtz0l kyag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=uGvm2mAdmqO4xaH+dvV0Vi2u8GB89a9fdLzCUB1VF5I=; b=ygazFcwGJFsAOKZoq5URWn4bUI4K01+I16/odxvq8KpXqAowuSNGQbfuxvaFbjeRik xyHaQgej87lK78t9F2rGrqJ5N4dm68Y8r8wyto8xiSSo5Cg5YdJD4f3yZ0JwYgZtuGmo vaFtktvs6YD4fLtUo0CXiBkm7VO8Odo6mdCqoJz9VlG4ifkz9hDAU5Ao1GSbJpWbNt+H P7m8SPj4nmCt+8unvU92JrEjYFjv8K0WjdBI7OIQAmU8EAVIa6TIWVXIK28rB5Ju0jfF k1q3qsu5bajle9RD5IBiuD2jmb0POSCKQbKUr3uJ33/lxcYLlaI7fM2RDkf1z+8hkOI9 0n/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z8si934075pgs.455.2017.06.26.17.56.20; Mon, 26 Jun 2017 17:56:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751521AbdF0A4D (ORCPT + 25 others); Mon, 26 Jun 2017 20:56:03 -0400 Received: from sci-ig2.spreadtrum.com ([222.66.158.135]:45887 "EHLO SHSQR01.spreadtrum.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751445AbdF0Azz (ORCPT ); Mon, 26 Jun 2017 20:55:55 -0400 Received: from ig2.spreadtrum.com (shcas03.spreadtrum.com [10.0.1.207]) by SHSQR01.spreadtrum.com with ESMTP id v5R0tchD054844 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO); Tue, 27 Jun 2017 08:55:38 +0800 (CST) (envelope-from Orson.Zhai@spreadtrum.com) Received: from SHCAS01.spreadtrum.com (10.0.1.201) by SHMBX03.spreadtrum.com (10.0.1.208) with Microsoft SMTP Server (TLS) id 15.0.847.32; Tue, 27 Jun 2017 08:55:37 +0800 Received: from localhost (10.0.73.143) by SHCAS01.spreadtrum.com (10.0.1.250) with Microsoft SMTP Server (TLS) id 15.0.847.32 via Frontend Transport; Tue, 27 Jun 2017 08:55:37 +0800 From: Orson Zhai To: Shuah Khan CC: Sumit Semwal , , , , Orson Zhai Subject: [PATCH V4] tools/testing/selftests/sysctl: Add pre-check to the value of writes_strict Date: Tue, 27 Jun 2017 08:52:09 +0800 Message-ID: <20170627005209.26415-1-orson.zhai@linaro.org> X-Mailer: git-send-email 2.12.2 MIME-Version: 1.0 X-MAIL: SHSQR01.spreadtrum.com v5R0tchD054844 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sysctl test will fail in some items if the value of /proc/sys/kernel /sysctrl_writes_strict is 0 as the default value in kernel older than v4.5. Make this test more robus and compatible with older kernel by checking and update writes_strict value and restore it when test is done. Signed-off-by: Orson Zhai Reviewed-by: Sumit Semwal Tested-by: Sumit Semwal --- tools/testing/selftests/sysctl/common_tests | 22 ++++++++++++++++++++++ tools/testing/selftests/sysctl/run_numerictests | 2 +- tools/testing/selftests/sysctl/run_stringtests | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) -- 2.12.2 Reviewed-by: Kees Cook diff --git a/tools/testing/selftests/sysctl/common_tests b/tools/testing/selftests/sysctl/common_tests index 17d534b1b7b4..b6862322962f 100644 --- a/tools/testing/selftests/sysctl/common_tests +++ b/tools/testing/selftests/sysctl/common_tests @@ -24,6 +24,14 @@ verify() return 0 } +exit_test() +{ + if [ ! -z ${old_strict} ]; then + echo ${old_strict} > ${WRITES_STRICT} + fi + exit $rc +} + trap 'set_orig; rm -f "${TEST_FILE}"' EXIT rc=0 @@ -63,6 +71,20 @@ else echo "ok" fi +echo -n "Checking write strict setting ... " +WRITES_STRICT="${SYSCTL}/kernel/sysctl_writes_strict" +if [ ! -e ${WRITES_STRICT} ]; then + echo "FAIL, but skip in case of old kernel" >&2 +else + old_strict=$(cat ${WRITES_STRICT}) + if [ "$old_strict" = "1" ]; then + echo "ok" + else + echo "FAIL, strict value is 0 but force to 1 to continue" >&2 + echo "1" > ${WRITES_STRICT} + fi +fi + # Now that we've validated the sanity of "set_test" and "set_orig", # we can use those functions to set starting states before running # specific behavioral tests. diff --git a/tools/testing/selftests/sysctl/run_numerictests b/tools/testing/selftests/sysctl/run_numerictests index 8510f93f2d14..e6e76c93d948 100755 --- a/tools/testing/selftests/sysctl/run_numerictests +++ b/tools/testing/selftests/sysctl/run_numerictests @@ -7,4 +7,4 @@ TEST_STR=$(( $ORIG + 1 )) . ./common_tests -exit $rc +exit_test diff --git a/tools/testing/selftests/sysctl/run_stringtests b/tools/testing/selftests/sysctl/run_stringtests index 90a9293d520c..857ec667fb02 100755 --- a/tools/testing/selftests/sysctl/run_stringtests +++ b/tools/testing/selftests/sysctl/run_stringtests @@ -74,4 +74,4 @@ else echo "ok" fi -exit $rc +exit_test