Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp48884rdf; Mon, 20 Nov 2023 15:56:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IF2buARRSIbGslLGJR1iLRwHB1SUw9oHzGFuyYbn2Ebrv+AsKSfP9Me2Xw6TB4e5aiP9To4 X-Received: by 2002:a05:6808:1826:b0:3ad:f866:39bd with SMTP id bh38-20020a056808182600b003adf86639bdmr13036404oib.27.1700524570954; Mon, 20 Nov 2023 15:56:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700524570; cv=none; d=google.com; s=arc-20160816; b=lqahyBgp7wHf7QgSyOI1Gz1RCRDGD5lbSIxBhdt4nGKDUip/zQ5jJMdyyQsBkqqHpv Mww66ILU12DF+TqZLuf+WI3WTtvH51GgDie51ENQw4CgdPoHnZ79CQUouZnjcUzJretm R7E5Qp7kNJ6MGycsTnHRMUxFJsXsdBZf/UNRzdeTXvwFdNlA2oj4oh+YQJIJiy3y/vdN 0dXddMv9yxR8wxFbGuJjPJSBp95w16ytiQv4EsXUHFzfJnYM6qfYhL7BwhXQbboCOcus KQh7cvA0s3Vwi8FPmT7m9Dr6jMTCnT/vaeSkcJ0//v1XLFReLFbWiOlcGF76BfLIRqm0 qOmg== 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=mUQoFF7dunJdm0OTuwpCjw3a+BvzGijC6AE6BY8z4NpnZuRo4LzvDmvkCclNDQQ//3 eBPlnNasy2bRZdeose4WiGK2xpj5VY9fP4ih3fe0/cAl6DR/5kvGpmBLYDfNzGt5LhDJ XFnN+ykk7IR7L2+Pnt+Y+7dwax/Qbp/JN0NW21XCK7DKuBUGhHZzlt82lIftQVshc1la FtaqcEffpGUUUIr3HBBwvxTU65mLKSDRq1rC4Ztm285q19Yiu/4DWdDiWJEpOOtTylJM cbIPSPbY575zvW9dixtGGlEv6r6LweYCYYskwvg1wAUxQc/PP0WD+NY85loIZ7YQvZBp l68g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sbNb1lAP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id a11-20020a65418b000000b005b4a9b2f404si8729315pgq.710.2023.11.20.15.56.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 15:56:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sbNb1lAP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id C76CD80310E6; Mon, 20 Nov 2023 15:56:07 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232772AbjKTXzw (ORCPT + 99 others); Mon, 20 Nov 2023 18:55:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232678AbjKTXzt (ORCPT ); Mon, 20 Nov 2023 18:55:49 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1362C7 for ; Mon, 20 Nov 2023 15:55:45 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F18A9C43395; Mon, 20 Nov 2023 23:55:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700524545; bh=bhar0tJdOqw54YK6iRyaAGbYhafIqhucm+rmgUHLm6s=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=sbNb1lAPsl6sDP/tWTQu1Rz0P0N22caWVrWtkm3Aupuki5R4MDTEbkjYRahtzKnOp TS49D15rjqBO0dPJbSNGnGxF5WjrIm1DaF5b3wz0fjJzxf4EGe2kvzjAnxutMwAQre qMpXITiZa0Ph1fxYBdtmvH5ZC0BAn5zjNqzFHDpJKryoPazMVvrGBpFG385YEStdGm 3NuQQFBvOAoKPmuWRe1zOB7/vOjL92hbyR3zYD73bZcnnOjR6TTe+j0hCCzNFZzhD9 G+2y/dBRXHDY27ZToDMrBXHB3Y46mDlUNgekAxTuQReGSZMnHo2OiCi5/0p2G3QPM8 Gxa/esUVawgAQ== From: Mark Brown Date: Mon, 20 Nov 2023 23:54:31 +0000 Subject: [PATCH RFT v3 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: <20231120-clone3-shadow-stack-v3-3-a7b8ed3e2acc@kernel.org> References: <20231120-clone3-shadow-stack-v3-0-a7b8ed3e2acc@kernel.org> In-Reply-To: <20231120-clone3-shadow-stack-v3-0-a7b8ed3e2acc@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/pANAwAKASTWi3JdVIfQAcsmYgBlW/HgP5b6BhRuIr5G+HNtIoh396YxC2fEVDwlQCIA cfRuecyJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZVvx4AAKCRAk1otyXVSH0PX3CA CCEnfkUPFFpPUROq1L+Sp+FJRBtKQh0aJtXZwE3SQa+n2gOmuE3MpcL3rJcHB235Z0jZslOsN9gJyx OJVFm3V3YY+HKUAXtH8DnZrmDui9hTfX3WgmIyBvSvq0Ygg08gWSb8SghG5HJjzGaejdY6DpUwcrnC sIuxAZqX4FDzlS4VOM8ngVUsFhetDIsLIYTRYjW2fc4MCMwhmzyyRg251AaNOfiyCC/JQ3tpzc3uym jo+P8kQHpoNzsBPMgyNIJX+EO/xQjz5+caORTxjYNSJin+eQZzAV6ByNPtgdNxV+LdB3vpOCSzJ++Z rKJV3rfuFANlis6xKG1tYF5s/ZI5NN 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Mon, 20 Nov 2023 15:56:07 -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