Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4056232rdh; Tue, 28 Nov 2023 10:32:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IEszqI0nVBp3+okBpraDWHoMcNv4S9lprtgqF2x5CbUWWXjErWO7uVmz6YEmSLvihGoDirj X-Received: by 2002:a17:902:d346:b0:1cf:b1d2:a9f5 with SMTP id l6-20020a170902d34600b001cfb1d2a9f5mr11090838plk.56.1701196340862; Tue, 28 Nov 2023 10:32:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701196340; cv=none; d=google.com; s=arc-20160816; b=KVqnQjuwbda5SkCuogW9h0Lk8MXKAyrtUMePJeL69L3p73P2z/Rsb/pX91Z5xGTcFy gFrEIFJ/x5xxqk5JFzS1q10WV/e91EqRnnli2QMo7YgmFqHDqLlyAtFfkS9DvU0ORx8F XGyrN6PBhwUMlQ4sAPztpC5HV2lOxd7zq/dA4RAivRhom5Wi3qH+t+VndbymtiPXSmgM RsV9+7Lb1eieT0hcvKQznwmndv5aeLxzC1QeRl5+j7+gv8Y/86G2Oxi0b11gCYVrJ7Rt GncN8NEOLIn01yUSWS4Ws3+aNJIYjkbKnlHwyLo3qzl1KS+zSZPL266qhwGguM1U6cjM VsMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=vVZkVRUin1/QmjMnw/YaKi0zacs/6BQ0/2j1SkJTQ38=; fh=oQRZOFrDQfXNJ7G92Ah9cs8vRP0rRtblCDc+u4U9urY=; b=VsYHVcTNyqZwgAVZYeyM+PUoovWgbuVy1AWelkF4bR6TIY3F0WBiyT4eE0caNf1rdj q+MQwBp4ZL2wErlSI12RELjDjnr2orJvG3SkZRX2f9kOT2rsCqY0X9vvUkkXxclf3D0I /L8k1d8oDlS6X5KUOGHngQnverikq4UDcphASHsNh360r+LnLjCe+aERDpsVZc0Kzekh tXbGl8AI7HqRJeHbRxtcRpeRavghVQfL425D6j0W7n4L51NvLpKieo3mJqbozM1yojqb zAGKvKyLJsujaoMyifUu0Vjivw3Ay2JduqjhIZ5AGb/CL46/Rue4tTESkfDVzxWv5Apj 5zRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DtYhpW1N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id t8-20020a170902bc4800b001c60d334996si12200853plz.622.2023.11.28.10.32.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 10:32:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DtYhpW1N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 9966F80A7CE5; Tue, 28 Nov 2023 10:32:16 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230011AbjK1Sb4 (ORCPT + 99 others); Tue, 28 Nov 2023 13:31:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345968AbjK1Sbs (ORCPT ); Tue, 28 Nov 2023 13:31:48 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8506E18D for ; Tue, 28 Nov 2023 10:31:54 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 720DFC433D9; Tue, 28 Nov 2023 18:31:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701196314; bh=bhar0tJdOqw54YK6iRyaAGbYhafIqhucm+rmgUHLm6s=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=DtYhpW1N3uw4McaklqObtf/dBUkjET9T6wKTaFn5ILv3JyDK7872xK9Kn5nKj8dQX uwwd25sxK4GU9gTg8Abf3yF14SvIUrhTksGRu2w5SWmBGKmmR/dlbkgXh61CiQUELr qXDBMOIcyOB3zbkgDlVbMzVbWzaOUfKFlmn1NuiZAPmCFfWhAmxwUh8QcsVNA/MAl3 8iAkOkUfAnzMOgZJ/yXIBeBScmwUh2sis8pMFG9m5LXsE+yTQqhnpmy3rfb9hgRHcO WmOwPrNyR5SojI1T7tD5ebMfavcdk0v/bFj8YrU87imc8lzlOOSCniq3PfA1feQy8m CKiG/unh2MAdw== From: Mark Brown Date: Tue, 28 Nov 2023 18:22:41 +0000 Subject: [PATCH RFT v4 3/5] selftests/clone3: Factor more of main loop into test_clone3() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231128-clone3-shadow-stack-v4-3-8b28ffe4f676@kernel.org> References: <20231128-clone3-shadow-stack-v4-0-8b28ffe4f676@kernel.org> In-Reply-To: <20231128-clone3-shadow-stack-v4-0-8b28ffe4f676@kernel.org> To: "Rick P. Edgecombe" , Deepak Gupta , Szabolcs Nagy , "H.J. Lu" , Florian Weimer , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Christian Brauner , Shuah Khan Cc: linux-kernel@vger.kernel.org, Catalin Marinas , Will Deacon , Kees Cook , jannh@google.com, bsegall@google.com, linux-kselftest@vger.kernel.org, linux-api@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-0438c X-Developer-Signature: v=1; a=openpgp-sha256; l=3743; i=broonie@kernel.org; h=from:subject:message-id; bh=bhar0tJdOqw54YK6iRyaAGbYhafIqhucm+rmgUHLm6s=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlZjH/fxDftmH0AHLm/uq5bsPzNGnZHpqyb3BMMhDK TgMMKxuJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZWYx/wAKCRAk1otyXVSH0LAUB/ 9nlA+s7w4LDOOcuGu/WldUA9dhLfwL4+yMRemAumoVvdyOdfOPEUgb+8tVvlIPvGupI+HQV1fp1zO+ mvbE7BKF2Y78Y+IzqZZlMiGSpRMC9BmGPw3cSTA9FNSvxgMGnEDSd4BDzLaT/MVBd44fpEO9QoUSgh 1oi2V4l2O29gHlIKZriXrvK4mfyCN69scs/kKEemoPYpFZKAHV//JbZIBXlt1I/GYXwudBRbL57tsk Sxu2w9pgHCSF80gvDbpD5VPWKh/qq5ZgZSBlZWJBpBtKb2U9B2d08ELR1DSGag34bHDLfqCx0f34le bbolPUkw70CUc2/OHzrDJUE839tUoD X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 28 Nov 2023 10:32:16 -0800 (PST) In order to make it easier to add more configuration for the tests and more support for runtime detection of when tests can be run pass the structure describing the tests into test_clone3() rather than picking the arguments out of it and have that function do all the per-test work. No functional change. Signed-off-by: Mark Brown --- tools/testing/selftests/clone3/clone3.c | 77 ++++++++++++++++----------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/tools/testing/selftests/clone3/clone3.c b/tools/testing/selftests/clone3/clone3.c index 3c9bf0cd82a8..1108bd8e36d6 100644 --- a/tools/testing/selftests/clone3/clone3.c +++ b/tools/testing/selftests/clone3/clone3.c @@ -30,6 +30,19 @@ enum test_mode { CLONE3_ARGS_INVAL_EXIT_SIGNAL_NSIG, }; +typedef bool (*filter_function)(void); +typedef size_t (*size_function)(void); + +struct test { + const char *name; + uint64_t flags; + size_t size; + size_function size_function; + int expected; + enum test_mode test_mode; + filter_function filter; +}; + static int call_clone3(uint64_t flags, size_t size, enum test_mode test_mode) { struct __clone_args args = { @@ -104,30 +117,40 @@ static int call_clone3(uint64_t flags, size_t size, enum test_mode test_mode) return 0; } -static bool test_clone3(uint64_t flags, size_t size, int expected, - enum test_mode test_mode) +static void test_clone3(const struct test *test) { + size_t size; int ret; + if (test->filter && test->filter()) { + ksft_test_result_skip("%s\n", test->name); + return; + } + + if (test->size_function) + size = test->size_function(); + else + size = test->size; + + ksft_print_msg("Running test '%s'\n", test->name); + ksft_print_msg( "[%d] Trying clone3() with flags %#" PRIx64 " (size %zu)\n", - getpid(), flags, size); - ret = call_clone3(flags, size, test_mode); + getpid(), test->flags, size); + ret = call_clone3(test->flags, size, test->test_mode); ksft_print_msg("[%d] clone3() with flags says: %d expected %d\n", - getpid(), ret, expected); - if (ret != expected) { + getpid(), ret, test->expected); + if (ret != test->expected) { ksft_print_msg( "[%d] Result (%d) is different than expected (%d)\n", - getpid(), ret, expected); - return false; + getpid(), ret, test->expected); + ksft_test_result_fail("%s\n", test->name); + return; } - return true; + ksft_test_result_pass("%s\n", test->name); } -typedef bool (*filter_function)(void); -typedef size_t (*size_function)(void); - static bool not_root(void) { if (getuid() != 0) { @@ -155,16 +178,6 @@ static size_t page_size_plus_8(void) return getpagesize() + 8; } -struct test { - const char *name; - uint64_t flags; - size_t size; - size_function size_function; - int expected; - enum test_mode test_mode; - filter_function filter; -}; - static const struct test tests[] = { { .name = "simple clone3()", @@ -314,24 +327,8 @@ int main(int argc, char *argv[]) ksft_set_plan(ARRAY_SIZE(tests)); test_clone3_supported(); - for (i = 0; i < ARRAY_SIZE(tests); i++) { - if (tests[i].filter && tests[i].filter()) { - ksft_test_result_skip("%s\n", tests[i].name); - continue; - } - - if (tests[i].size_function) - size = tests[i].size_function(); - else - size = tests[i].size; - - ksft_print_msg("Running test '%s'\n", tests[i].name); - - ksft_test_result(test_clone3(tests[i].flags, size, - tests[i].expected, - tests[i].test_mode), - "%s\n", tests[i].name); - } + for (i = 0; i < ARRAY_SIZE(tests); i++) + test_clone3(&tests[i]); ksft_finished(); } -- 2.30.2