From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 532ECC81981 for ; Mon, 27 Apr 2020 18:05:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 212F8214D8 for ; Mon, 27 Apr 2020 18:05:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 212F8214D8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 658368E000A; Mon, 27 Apr 2020 14:04:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E0CE8E0006; Mon, 27 Apr 2020 14:04:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4AC1A8E000A; Mon, 27 Apr 2020 14:04:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0059.hostedemail.com [216.40.44.59]) by kanga.kvack.org (Postfix) with ESMTP id 2E28A8E0006 for ; Mon, 27 Apr 2020 14:04:53 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id E0AA5180AD804 for ; Mon, 27 Apr 2020 18:04:52 +0000 (UTC) X-FDA: 76754410824.09.boot57_64c6d1e8ebc01 X-HE-Tag: boot57_64c6d1e8ebc01 X-Filterd-Recvd-Size: 4967 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Mon, 27 Apr 2020 18:04:52 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id A6F9AAD5D; Mon, 27 Apr 2020 18:04:48 +0000 (UTC) From: Vlastimil Babka To: Andrew Morton , Luis Chamberlain , Kees Cook , Iurii Zaikin Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-mm@kvack.org, Ivan Teterevkov , Michal Hocko , David Rientjes , Matthew Wilcox , "Eric W . Biederman" , "Guilherme G . Piccoli" , Alexey Dobriyan , Thomas Gleixner , Greg Kroah-Hartman , Christian Brauner , Masami Hiramatsu , Vlastimil Babka Subject: [PATCH v3 5/5] lib/test_sysctl: support testing of sysctl. boot parameter Date: Mon, 27 Apr 2020 20:04:33 +0200 Message-Id: <20200427180433.7029-6-vbabka@suse.cz> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200427180433.7029-1-vbabka@suse.cz> References: <20200427180433.7029-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Testing is done by a new parameter debug.test_sysctl.boot_int which defau= lts to 0 and it's expected that the tester passes a boot parameter that sets it = to 1. The test checks if it's set to 1. To distinguish true failure from parame= ter not being set, the test checks /proc/cmdline for the expected parameter, = and whether test_sysctl is built-in and not a module. Signed-off-by: Vlastimil Babka --- lib/test_sysctl.c | 13 +++++++++ tools/testing/selftests/sysctl/sysctl.sh | 36 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/lib/test_sysctl.c b/lib/test_sysctl.c index 566dad3f4196..84eaae22d3a6 100644 --- a/lib/test_sysctl.c +++ b/lib/test_sysctl.c @@ -44,6 +44,8 @@ struct test_sysctl_data { int int_0002; int int_0003[4]; =20 + int boot_int; + unsigned int uint_0001; =20 char string_0001[65]; @@ -61,6 +63,8 @@ static struct test_sysctl_data test_data =3D { .int_0003[2] =3D 2, .int_0003[3] =3D 3, =20 + .boot_int =3D 0, + .uint_0001 =3D 314, =20 .string_0001 =3D "(none)", @@ -91,6 +95,15 @@ static struct ctl_table test_table[] =3D { .mode =3D 0644, .proc_handler =3D proc_dointvec, }, + { + .procname =3D "boot_int", + .data =3D &test_data.boot_int, + .maxlen =3D sizeof(test_data.boot_int), + .mode =3D 0644, + .proc_handler =3D proc_dointvec, + .extra1 =3D SYSCTL_ZERO, + .extra2 =3D SYSCTL_ONE, + }, { .procname =3D "uint_0001", .data =3D &test_data.uint_0001, diff --git a/tools/testing/selftests/sysctl/sysctl.sh b/tools/testing/sel= ftests/sysctl/sysctl.sh index ce1eeea6f769..ef6417b8067b 100755 --- a/tools/testing/selftests/sysctl/sysctl.sh +++ b/tools/testing/selftests/sysctl/sysctl.sh @@ -39,6 +39,7 @@ ALL_TESTS=3D"$ALL_TESTS 0003:1:1:int_0002" ALL_TESTS=3D"$ALL_TESTS 0004:1:1:uint_0001" ALL_TESTS=3D"$ALL_TESTS 0005:3:1:int_0003" ALL_TESTS=3D"$ALL_TESTS 0006:50:1:bitmap_0001" +ALL_TESTS=3D"$ALL_TESTS 0007:1:1:boot_int" =20 test_modprobe() { @@ -752,6 +753,40 @@ sysctl_test_0006() run_bitmaptest } =20 +sysctl_test_0007() +{ + TARGET=3D"${SYSCTL}/boot_int" + if [ -d $DIR ]; then + echo "Boot param test only possible sysctl_test is built-in, not modul= e:" + cat $TEST_DIR/config >&2 + return 0 + fi + + echo -n "Testing if $TARGET is set to 1 ..." + ORIG=3D$(cat "${TARGET}") + + if [ x$ORIG =3D "x1" ]; then + echo "ok" + return 0 + fi + echo "FAIL" + echo "Checking if /proc/cmdline contains setting of the expected parame= ter ..." + if [ ! -f /proc/cmdline ]; then + echo "/proc/cmdline does not exist, test inconclusive" + return 0 + fi + + FOUND=3D$(grep -c "sysctl[./]debug[./]test_sysctl[./]boot_int=3D1" /pro= c/cmdline) + if [ $FOUND =3D "1" ]; then + echo "Kernel param found but $TARGET is not 1, TEST FAILED" + rc=3D1 + test_rc + fi + + echo "Skipping test, expected kernel parameter missing." + echo "To perform this test, make sure kernel is booted with parameter: = sysctl.debug.test_sysctl.boot_int=3D1" +} + list_tests() { echo "Test ID list:" @@ -766,6 +801,7 @@ list_tests() echo "0004 x $(get_test_count 0004) - tests proc_douintvec()" echo "0005 x $(get_test_count 0005) - tests proc_douintvec() array" echo "0006 x $(get_test_count 0006) - tests proc_do_large_bitmap()" + echo "0007 x $(get_test_count 0007) - tests setting sysctl from kernel = boot param" } =20 usage() --=20 2.26.0