From patchwork Thu Apr 6 13:56:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 80257 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1054830vqo; Thu, 6 Apr 2023 07:08:46 -0700 (PDT) X-Google-Smtp-Source: AKy350YXoAipbOhhDAD+m0rSH/7cU5mcKV6PTRZaCgrjFCm0yV5a/nRiFjOmW6m5MkSjvsxjbFak X-Received: by 2002:a17:906:d9cf:b0:92c:138e:ff1f with SMTP id qk15-20020a170906d9cf00b0092c138eff1fmr7758932ejb.18.1680790125923; Thu, 06 Apr 2023 07:08:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680790125; cv=none; d=google.com; s=arc-20160816; b=qjehOK5mevZfUyIB05raJwng11SjvIUxz/jshJxc8idGQ4XOmEnAq2ibBKLUpy84Tk eP4+54bCNHyUYvYL9eZR0HqXXnuIW9/6UsBLs7g4g3lVi+afVVwlpmhLoxYOAkQP5KrI lcc0dO1K/m1J1OyELPOo70mSxlXMUpINkS+hsjfrqFk/c9eBVTerZ0YoCrcbFjA6PAGI 4AofJjfdNgtQIcQNawLkTaGjlshf+AS38XeRydQe4CPKax9O8QdprC+CvaMKp6Ofb3Pm KeWXRHMB1388olY0eo6jGtSldkpMaVtm9UUf8LxGtofkkb7SNFXgD22QSGwBDJflmXUz VkPA== 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=yglPQqY9HbQtsWURBYdX9J+rXDSpyN4ZYwUOW6zNOuI=; b=gPaRkUo99WAKnzKINHxArnTgc7kpJoo4dCdtJcj3AYzad5fXDS4Cy1DTBdss3s3Pgs SAau2OT6vcwy7GYDeGb8guIoLEbjpbAZj+pCdk5nNnfqsnRGjb0jWQrgWnHhTuf8/UHO PEEekxf1v4AGhL+HLb7q1XAjzRvxro3ZE/vI0b9NKWrpPCHiBp1uXQ1ce9KtkHgVmzm2 HP4pAOohw/HJVPZfAxwAM2Jdpv2077uAyS+aTKUiEfMSapiO7UkiF89DKvb9Iii21SRs OQ+isT9VNRNlvNlUl5uXen5MtONYAKKmfzXueTt1kz4s8H9DjC1PZ4X6I979LLq2Lj0p q08g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ELrykX2b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qb13-20020a1709077e8d00b00945201cecbdsi1465842ejc.996.2023.04.06.07.08.21; Thu, 06 Apr 2023 07:08:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ELrykX2b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238955AbjDFN6L (ORCPT + 99 others); Thu, 6 Apr 2023 09:58:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238894AbjDFN55 (ORCPT ); Thu, 6 Apr 2023 09:57:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05C31A5C6; Thu, 6 Apr 2023 06:57:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3B44B60DBF; Thu, 6 Apr 2023 13:57:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D20FAC433D2; Thu, 6 Apr 2023 13:57:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680789441; bh=a79oajkhQYVRaB6DwXBTM0ag0IUaHV1EBWHADnz2lHk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ELrykX2bdSssJi10V3rL9ckMK0huAvl1wMVY8P31xTyyYCK/jwq9s2vMazoCjluFK IMWh/f1AVCNvPC1g0buxk4hdVTGKWE6ASgMh4XxEFfIKetCM47fFDgZnM8U6AHKlWd zls10d3p0kADlG4uRfshgYilSQkUsK9EeC6LYQ7y0dF2ulTUpCBKhegizv0wCNDRrf FMi4PCKjyMShrswQy7K/mi8s3+Y1y+3fsGSeV2HffKRidErv6+TXILq3GY2iN9ZOig SrxuprHt1n+NkJ68+0uxPmpw+b3hHO8Z6vEkV100rqD1f6V386xjjxFoMhW08FbslF Jm2tfBSrz4ZUQ== From: Mark Brown Date: Thu, 06 Apr 2023 14:56:29 +0100 Subject: [PATCH 1/2] kselftest: Support nolibc MIME-Version: 1.0 Message-Id: <20230405-kselftest-nolibc-v1-1-63fbcd70b202@kernel.org> References: <20230405-kselftest-nolibc-v1-0-63fbcd70b202@kernel.org> In-Reply-To: <20230405-kselftest-nolibc-v1-0-63fbcd70b202@kernel.org> To: Shuah Khan , Catalin Marinas , Will Deacon , "Paul E. McKenney" Cc: linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-00303 X-Developer-Signature: v=1; a=openpgp-sha256; l=11785; i=broonie@kernel.org; h=from:subject:message-id; bh=a79oajkhQYVRaB6DwXBTM0ag0IUaHV1EBWHADnz2lHk=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBkLs+7erwrk7RnEeNVoFpLU3iXhOt2tuhANaHD45/y QLSxDb6JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZC7PuwAKCRAk1otyXVSH0Lq+B/ 43w6CkOjngdTrY09nlmgjf6DFUrZkA6qawnyCIqH8OG5gy2LUg0VofMP28j+hXCZzp68Ha4nOzVmwj zq4MbAEIDgG5iTLjXKJKp3LB+P1QUAns4pZz8EYVf+UADOdxzwSbleMOCkkXHClVVTPqc7KxdrzAQF 0eTWs7S3J+yXDXqP+Qqg9av1J0w1Gg4RX+1vvMoUWqEbyOQCzyyObsxLFqVdgt8/jNbuT53LhwNU1f 1AF6o7+wDvJfcwFk5tHD8s/GFZPkIhsEyQoNqT1r6t6ROGcm/9krEFc4nVUybhyAZppWkt9nEOaLQm UNzEfyRrMFOXpQ9Qa88Wwiw+g7ORjB X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Spam-Status: No, score=-5.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762435554773621716?= X-GMAIL-MSGID: =?utf-8?q?1762436187133634256?= At present the kselftest header can't be used with nolibc since it makes use of vprintf() which is not available in nolibc and seems like it would be inappropriate to implement given the minimal system requirements and environment intended for nolibc. This has resulted in some open coded kselftests which use nolibc to test features that are supposed to be controlled via libc and therefore better exercised in an environment with no libc. Rather than continue this let's factor out the I/O routines in kselftest.h into a separate header file and provide a nolibc implementation which only allows simple strings to be provided rather than full printf() support. This is limiting but a great improvement on sharing no code at all. Signed-off-by: Mark Brown --- tools/testing/selftests/kselftest-nolibc.h | 93 ++++++++++++++++++ tools/testing/selftests/kselftest-std.h | 151 +++++++++++++++++++++++++++++ tools/testing/selftests/kselftest.h | 149 +++------------------------- 3 files changed, 255 insertions(+), 138 deletions(-) diff --git a/tools/testing/selftests/kselftest-nolibc.h b/tools/testing/selftests/kselftest-nolibc.h new file mode 100644 index 000000000000..3dea10cc5490 --- /dev/null +++ b/tools/testing/selftests/kselftest-nolibc.h @@ -0,0 +1,93 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * kselftest-nolibc Cut down nolibc based kselftest output functions + * + * Copyright (c) 2014 Shuah Khan + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + */ + +#ifndef __KSELFTEST_H +#error This file should never be included directly, always include kselftest.h +#endif + +static inline void ksft_print_msg(const char *msg) +{ + printf("# %s", msg); +} + +static inline void ksft_test_result_pass(const char *msg) +{ + ksft_cnt.ksft_pass++; + + printf("ok %d %s", ksft_test_num(), msg); +} + +static inline void ksft_test_result_fail(const char *msg) +{ + ksft_cnt.ksft_fail++; + + printf("not ok %d %s", ksft_test_num(), msg); +} + +/** + * ksft_test_result() - Report test success based on truth of condition + * + * @condition: if true, report test success, otherwise failure. + */ +#define ksft_test_result(condition, fmt) do { \ + if (!!(condition)) \ + ksft_test_result_pass(fmt);\ + else \ + ksft_test_result_fail(fmt);\ + } while (0) + +static inline void ksft_test_result_xfail(const char *msg) +{ + ksft_cnt.ksft_xfail++; + + printf("ok %d # XFAIL %s", ksft_test_num(), msg); +} + +static inline void ksft_test_result_skip(const char *msg) +{ + ksft_cnt.ksft_xskip++; + + printf("ok %d # SKIP %s", ksft_test_num(), msg); +} + +static inline void ksft_test_result_error(const char *msg) +{ + ksft_cnt.ksft_error++; + + printf("not ok %d # error %s", ksft_test_num(), msg); +} + +static inline int ksft_exit_fail_msg(const char *msg) +{ + printf("Bail out! %s", msg); + + ksft_print_cnts(); + exit(KSFT_FAIL); +} + +static inline int ksft_exit_skip(const char *msg) +{ + /* + * FIXME: several tests misuse ksft_exit_skip so produce + * something sensible if some tests have already been run + * or a plan has been printed. Those tests should use + * ksft_test_result_skip or ksft_exit_fail_msg instead. + */ + if (ksft_plan || ksft_test_num()) { + ksft_cnt.ksft_xskip++; + printf("ok %d # SKIP ", 1 + ksft_test_num()); + } else { + printf("1..0 # SKIP "); + } + if (msg) + printf("%s", msg); + if (ksft_test_num()) + ksft_print_cnts(); + exit(KSFT_SKIP); +} diff --git a/tools/testing/selftests/kselftest-std.h b/tools/testing/selftests/kselftest-std.h new file mode 100644 index 000000000000..b57c515f6dda --- /dev/null +++ b/tools/testing/selftests/kselftest-std.h @@ -0,0 +1,151 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * kselftest-std.h: Full stdio based kselftest output functions + * + * Copyright (c) 2014 Shuah Khan + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + */ + +#ifndef __KSELFTEST_H +#error This file should never be included directly, always include kselftest.h +#endif + +static inline void ksft_print_msg(const char *msg, ...) +{ + int saved_errno = errno; + va_list args; + + va_start(args, msg); + printf("# "); + errno = saved_errno; + vprintf(msg, args); + va_end(args); +} + +static inline void ksft_test_result_pass(const char *msg, ...) +{ + int saved_errno = errno; + va_list args; + + ksft_cnt.ksft_pass++; + + va_start(args, msg); + printf("ok %d ", ksft_test_num()); + errno = saved_errno; + vprintf(msg, args); + va_end(args); +} + +static inline void ksft_test_result_fail(const char *msg, ...) +{ + int saved_errno = errno; + va_list args; + + ksft_cnt.ksft_fail++; + + va_start(args, msg); + printf("not ok %d ", ksft_test_num()); + errno = saved_errno; + vprintf(msg, args); + va_end(args); +} + +/** + * ksft_test_result() - Report test success based on truth of condition + * + * @condition: if true, report test success, otherwise failure. + */ +#define ksft_test_result(condition, fmt, ...) do { \ + if (!!(condition)) \ + ksft_test_result_pass(fmt, ##__VA_ARGS__);\ + else \ + ksft_test_result_fail(fmt, ##__VA_ARGS__);\ + } while (0) + +static inline void ksft_test_result_xfail(const char *msg, ...) +{ + int saved_errno = errno; + va_list args; + + ksft_cnt.ksft_xfail++; + + va_start(args, msg); + printf("ok %d # XFAIL ", ksft_test_num()); + errno = saved_errno; + vprintf(msg, args); + va_end(args); +} + +static inline void ksft_test_result_skip(const char *msg, ...) +{ + int saved_errno = errno; + va_list args; + + ksft_cnt.ksft_xskip++; + + va_start(args, msg); + printf("ok %d # SKIP ", ksft_test_num()); + errno = saved_errno; + vprintf(msg, args); + va_end(args); +} + +/* TODO: how does "error" differ from "fail" or "skip"? */ +static inline void ksft_test_result_error(const char *msg, ...) +{ + int saved_errno = errno; + va_list args; + + ksft_cnt.ksft_error++; + + va_start(args, msg); + printf("not ok %d # error ", ksft_test_num()); + errno = saved_errno; + vprintf(msg, args); + va_end(args); +} + +static inline int ksft_exit_fail_msg(const char *msg, ...) +{ + int saved_errno = errno; + va_list args; + + va_start(args, msg); + printf("Bail out! "); + errno = saved_errno; + vprintf(msg, args); + va_end(args); + + ksft_print_cnts(); + exit(KSFT_FAIL); +} + +static inline int ksft_exit_skip(const char *msg, ...) +{ + int saved_errno = errno; + va_list args; + + va_start(args, msg); + + /* + * FIXME: several tests misuse ksft_exit_skip so produce + * something sensible if some tests have already been run + * or a plan has been printed. Those tests should use + * ksft_test_result_skip or ksft_exit_fail_msg instead. + */ + if (ksft_plan || ksft_test_num()) { + ksft_cnt.ksft_xskip++; + printf("ok %d # SKIP ", 1 + ksft_test_num()); + } else { + printf("1..0 # SKIP "); + } + if (msg) { + errno = saved_errno; + vprintf(msg, args); + va_end(args); + } + if (ksft_test_num()) + ksft_print_cnts(); + exit(KSFT_SKIP); +} diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h index 33a0dbd26bd3..10fb6f7c4ae2 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h @@ -26,6 +26,10 @@ * ksft_test_result_xfail(fmt, ...); * ksft_test_result_error(fmt, ...); * + * If building with nolibc then only a string may be provided, va_args + * arre not supported and format characters within the string will not be + * interpreted. + * * When all tests are finished, clean up and exit the program with one of: * * ksft_finished(); @@ -43,11 +47,13 @@ #ifndef __KSELFTEST_H #define __KSELFTEST_H +#ifndef NOLIBC #include #include #include #include #include +#endif #ifndef ARRAY_SIZE #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) @@ -132,100 +138,11 @@ static inline void ksft_print_cnts(void) ksft_cnt.ksft_xskip, ksft_cnt.ksft_error); } -static inline void ksft_print_msg(const char *msg, ...) -{ - int saved_errno = errno; - va_list args; - - va_start(args, msg); - printf("# "); - errno = saved_errno; - vprintf(msg, args); - va_end(args); -} - -static inline void ksft_test_result_pass(const char *msg, ...) -{ - int saved_errno = errno; - va_list args; - - ksft_cnt.ksft_pass++; - - va_start(args, msg); - printf("ok %d ", ksft_test_num()); - errno = saved_errno; - vprintf(msg, args); - va_end(args); -} - -static inline void ksft_test_result_fail(const char *msg, ...) -{ - int saved_errno = errno; - va_list args; - - ksft_cnt.ksft_fail++; - - va_start(args, msg); - printf("not ok %d ", ksft_test_num()); - errno = saved_errno; - vprintf(msg, args); - va_end(args); -} - -/** - * ksft_test_result() - Report test success based on truth of condition - * - * @condition: if true, report test success, otherwise failure. - */ -#define ksft_test_result(condition, fmt, ...) do { \ - if (!!(condition)) \ - ksft_test_result_pass(fmt, ##__VA_ARGS__);\ - else \ - ksft_test_result_fail(fmt, ##__VA_ARGS__);\ - } while (0) - -static inline void ksft_test_result_xfail(const char *msg, ...) -{ - int saved_errno = errno; - va_list args; - - ksft_cnt.ksft_xfail++; - - va_start(args, msg); - printf("ok %d # XFAIL ", ksft_test_num()); - errno = saved_errno; - vprintf(msg, args); - va_end(args); -} - -static inline void ksft_test_result_skip(const char *msg, ...) -{ - int saved_errno = errno; - va_list args; - - ksft_cnt.ksft_xskip++; - - va_start(args, msg); - printf("ok %d # SKIP ", ksft_test_num()); - errno = saved_errno; - vprintf(msg, args); - va_end(args); -} - -/* TODO: how does "error" differ from "fail" or "skip"? */ -static inline void ksft_test_result_error(const char *msg, ...) -{ - int saved_errno = errno; - va_list args; - - ksft_cnt.ksft_error++; - - va_start(args, msg); - printf("not ok %d # error ", ksft_test_num()); - errno = saved_errno; - vprintf(msg, args); - va_end(args); -} +#ifdef NOLIBC +#include "kselftest-nolibc.h" +#else +#include "kselftest-std.h" +#endif static inline int ksft_exit_pass(void) { @@ -260,21 +177,6 @@ static inline int ksft_exit_fail(void) ksft_cnt.ksft_xfail + \ ksft_cnt.ksft_xskip) -static inline int ksft_exit_fail_msg(const char *msg, ...) -{ - int saved_errno = errno; - va_list args; - - va_start(args, msg); - printf("Bail out! "); - errno = saved_errno; - vprintf(msg, args); - va_end(args); - - ksft_print_cnts(); - exit(KSFT_FAIL); -} - static inline int ksft_exit_xfail(void) { ksft_print_cnts(); @@ -287,33 +189,4 @@ static inline int ksft_exit_xpass(void) exit(KSFT_XPASS); } -static inline int ksft_exit_skip(const char *msg, ...) -{ - int saved_errno = errno; - va_list args; - - va_start(args, msg); - - /* - * FIXME: several tests misuse ksft_exit_skip so produce - * something sensible if some tests have already been run - * or a plan has been printed. Those tests should use - * ksft_test_result_skip or ksft_exit_fail_msg instead. - */ - if (ksft_plan || ksft_test_num()) { - ksft_cnt.ksft_xskip++; - printf("ok %d # SKIP ", 1 + ksft_test_num()); - } else { - printf("1..0 # SKIP "); - } - if (msg) { - errno = saved_errno; - vprintf(msg, args); - va_end(args); - } - if (ksft_test_num()) - ksft_print_cnts(); - exit(KSFT_SKIP); -} - #endif /* __KSELFTEST_H */ From patchwork Thu Apr 6 13:56:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 80256 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1054654vqo; Thu, 6 Apr 2023 07:08:33 -0700 (PDT) X-Google-Smtp-Source: AKy350ZzeuMFZ/PQ4CgYhGSgcuHlEpLeICiyqF4a6oMi90wwTA2nXBS6/tVK/zP+CNzkhu8xdJJK X-Received: by 2002:a17:907:7b84:b0:949:c05d:73b6 with SMTP id ne4-20020a1709077b8400b00949c05d73b6mr2668771ejc.17.1680790113476; Thu, 06 Apr 2023 07:08:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680790113; cv=none; d=google.com; s=arc-20160816; b=Lz+yTWF51MMx7W6ZzPwPAyFAPlCeGQ4qLeDm2P6QEAMzHSTSRER9vm2bO5/oiBJLW9 PodG6QnF5iSywrFVzBGTFKu1AyJBU2/9JSekb0Qd+iwu5uOgyoS8x68C47uyOFsIzI// Bc23zjNWzepBsJYfObrw/3ShXtSd7mh7VtQlaaYmj8kugC3vzdSrdOKAXBxhYAFvoBxF qjqmcD8sY3hZnsiPHj5CylM+cdnJ+f+PMEkszcj0f4yInVOM57frzu9x7RoRu9chaZYq dEmJyP9ZERvmyiqB7n2HAX7jx9vKWiCd96XCHz3Xuy2zwzrO5vPZzSBoVLjFvU5Nures HnLA== 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=wU5m9ENI+xqZY7gNG0d9Ei0srSKuV0S63yUiJNiG9/E=; b=vWZHrc5pwzoNGbwdF1kR2W9ezvm00JzYxwR92pl9IC1LxH5YTN/7/aJYhf1pbDm2Rz GwIQADiVpSP8+ZBCFcDpUcf6sEMP+qYj9Rc/Ft6IKDaNnQqCwoED7flnzn435O1DZidY yVODMdXnvu25RjGPtcARe701CuqxU7lyFoCqiDM4cQNh5apfp7Nx0U+mcCufKY0JbNKY pLTCJ4ncp/msoM/Eeajy7Q1xw+Gw+7bPMcKPcIDp8BtlyLmUk3NNOyA2AyaSSEE5LN4P iTmbI/JBnINBwfZcCn4WmJnA7Esc8qyV/Ofhla2i0OCgMj+YsbA5RqEAtA6qJfVp7zen ZxsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IJcZ4F1x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gb4-20020a170907960400b00948aae5e3d2si1402688ejc.122.2023.04.06.07.08.07; Thu, 06 Apr 2023 07:08:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IJcZ4F1x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238907AbjDFN5w (ORCPT + 99 others); Thu, 6 Apr 2023 09:57:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238843AbjDFN5s (ORCPT ); Thu, 6 Apr 2023 09:57:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A61A9775; Thu, 6 Apr 2023 06:57:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 50E6264827; Thu, 6 Apr 2023 13:57:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1F19AC433A4; Thu, 6 Apr 2023 13:57:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680789443; bh=ytJn4w5Dy5SWLa0FnByQtdiXEcdwmqHMOCYVqkoHY8M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=IJcZ4F1xjaQ4Y8Cse4s6lD4Fs/8+l9oFFrg4IWSplJzD5fDpXHw38gkJNZcoYgy2m KxnbKunAaNfykgVwfk7oenBAJ3tVS4CvhZB2G3YJWnSIhD25BjU0AwRpKrDt2cfqzl IpO5EbtT2d2k3k9ndhhPzHVsfHix9nIeXQ3IinQiSmgBqIKftv6JD2FVsVcQU+hXsS NyQs+Nij+CD1V2BNwoE3OUW/QoN5ziH/3SWf+nSo7xEuOFAtw2KvkTPc11WdY/4bMJ S2x49NlI7KdN3KnjBFdzJPGa0nIKpUIByBb+hqeV6J5t6/y82NCV6Bkj7UH4wZhmQ3 CdFuQzQ6FGmsg== From: Mark Brown Date: Thu, 06 Apr 2023 14:56:30 +0100 Subject: [PATCH 2/2] kselftest/arm64: Convert za-fork to use kselftest.h MIME-Version: 1.0 Message-Id: <20230405-kselftest-nolibc-v1-2-63fbcd70b202@kernel.org> References: <20230405-kselftest-nolibc-v1-0-63fbcd70b202@kernel.org> In-Reply-To: <20230405-kselftest-nolibc-v1-0-63fbcd70b202@kernel.org> To: Shuah Khan , Catalin Marinas , Will Deacon , "Paul E. McKenney" Cc: linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-00303 X-Developer-Signature: v=1; a=openpgp-sha256; l=5178; i=broonie@kernel.org; h=from:subject:message-id; bh=ytJn4w5Dy5SWLa0FnByQtdiXEcdwmqHMOCYVqkoHY8M=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBkLs+80yzLeyGUhQXPJmaYoxHF1c5gwAnwwLgvREBL QLj2zJCJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZC7PvAAKCRAk1otyXVSH0MaiB/ 9GqQ45Q2obhNcd6abvqwjxt292Y9OnTQjQAbChlA/DhCQuwldDpml2LncJHCUVlYC7vkLkP8gYktcy 3aLR1l8sZjDhZez0DEMq6coFfwjkyBx04gTI6oT4wmcDdxgsY3lpJH/bm3dPrBw+R0CutOhRM1PMMb Jazidq5KMzV84HbR7bfohl6FBOpAzpt6zLlIBFdL1nsgZqKwB7WbaxsN9NIfnf8BbJnbAHCKfMh80a s7F3cRhKbgL8p9dihTUApdIsGfvfuXMiZUEG4w6gMN0Gb+LLFDuaP0kb2CLZyHbQtBwm+8CPnU/z9N zuCKHjGpoB1nLU5BZwesCzluYSsYfW X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762436173859436024?= X-GMAIL-MSGID: =?utf-8?q?1762436173859436024?= Now that kselftest.h can be used with nolibc convert the za-fork test to use it. We do still have to open code ksft_print_msg() but that's not the end of the world. Some of the advantage comes from using printf() which we could have been using already. This does change the output when tests are skipped, bringing it in line with the standard kselftest output by removing the test name - we move from ok 0 skipped to ok 1 # SKIP fork_test The old output was not following KTAP format for skips, and the numbering was not standard or consistent with the reported plan. Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/fp/Makefile | 2 +- tools/testing/selftests/arm64/fp/za-fork.c | 88 ++++++------------------------ 2 files changed, 17 insertions(+), 73 deletions(-) diff --git a/tools/testing/selftests/arm64/fp/Makefile b/tools/testing/selftests/arm64/fp/Makefile index 48f56c86ad45..b413b0af07f9 100644 --- a/tools/testing/selftests/arm64/fp/Makefile +++ b/tools/testing/selftests/arm64/fp/Makefile @@ -38,7 +38,7 @@ $(OUTPUT)/vec-syscfg: vec-syscfg.c $(OUTPUT)/rdvl.o $(OUTPUT)/vlset: vlset.c $(OUTPUT)/za-fork: za-fork.c $(OUTPUT)/za-fork-asm.o $(CC) -fno-asynchronous-unwind-tables -fno-ident -s -Os -nostdlib \ - -include ../../../../include/nolibc/nolibc.h \ + -include ../../../../include/nolibc/nolibc.h -I../..\ -static -ffreestanding -Wall $^ -o $@ $(OUTPUT)/za-ptrace: za-ptrace.c $(OUTPUT)/za-test: za-test.S $(OUTPUT)/asm-utils.o diff --git a/tools/testing/selftests/arm64/fp/za-fork.c b/tools/testing/selftests/arm64/fp/za-fork.c index ff475c649e96..3acd5621e468 100644 --- a/tools/testing/selftests/arm64/fp/za-fork.c +++ b/tools/testing/selftests/arm64/fp/za-fork.c @@ -9,42 +9,9 @@ #include #include -#define EXPECTED_TESTS 1 - -static void putstr(const char *str) -{ - write(1, str, strlen(str)); -} - -static void putnum(unsigned int num) -{ - char c; - - if (num / 10) - putnum(num / 10); - - c = '0' + (num % 10); - write(1, &c, 1); -} +#include "kselftest.h" -static int tests_run; -static int tests_passed; -static int tests_failed; -static int tests_skipped; - -static void print_summary(void) -{ - if (tests_passed + tests_failed + tests_skipped != EXPECTED_TESTS) - putstr("# UNEXPECTED TEST COUNT: "); - - putstr("# Totals: pass:"); - putnum(tests_passed); - putstr(" fail:"); - putnum(tests_failed); - putstr(" xfail:0 xpass:0 skip:"); - putnum(tests_skipped); - putstr(" error:0\n"); -} +#define EXPECTED_TESTS 1 int fork_test(void); int verify_fork(void); @@ -63,22 +30,21 @@ int fork_test_c(void) if (newpid == 0) { /* In child */ if (!verify_fork()) { - putstr("# ZA state invalid in child\n"); + ksft_print_msg("ZA state invalid in child\n"); exit(0); } else { exit(1); } } if (newpid < 0) { - putstr("# fork() failed: -"); - putnum(-newpid); - putstr("\n"); + printf("# fork() failed: %d\n", newpid); + return 0; } parent_result = verify_fork(); if (!parent_result) - putstr("# ZA state invalid in parent\n"); + ksft_print_msg("ZA state invalid in parent\n"); for (;;) { waiting = waitpid(newpid, &child_status, 0); @@ -86,18 +52,16 @@ int fork_test_c(void) if (waiting < 0) { if (errno == EINTR) continue; - putstr("# waitpid() failed: "); - putnum(errno); - putstr("\n"); + printf("# waitpid() failed: %d\n", errno); return 0; } if (waiting != newpid) { - putstr("# waitpid() returned wrong PID\n"); + printf("# waitpid() returned wrong PID\n"); return 0; } if (!WIFEXITED(child_status)) { - putstr("# child did not exit\n"); + printf("# child did not exit\n"); return 0; } @@ -105,29 +69,14 @@ int fork_test_c(void) } } -#define run_test(name) \ - if (name()) { \ - tests_passed++; \ - } else { \ - tests_failed++; \ - putstr("not "); \ - } \ - putstr("ok "); \ - putnum(++tests_run); \ - putstr(" " #name "\n"); - int main(int argc, char **argv) { int ret, i; - putstr("TAP version 13\n"); - putstr("1.."); - putnum(EXPECTED_TESTS); - putstr("\n"); + ksft_print_header(); + ksft_set_plan(EXPECTED_TESTS); - putstr("# PID: "); - putnum(getpid()); - putstr("\n"); + printf("# PID: %d\n", getpid()); /* * This test is run with nolibc which doesn't support hwcap and @@ -136,21 +85,16 @@ int main(int argc, char **argv) */ ret = open("/proc/sys/abi/sme_default_vector_length", O_RDONLY, 0); if (ret >= 0) { - run_test(fork_test); + ksft_test_result(fork_test(), "fork_test"); } else { - putstr("# SME support not present\n"); - + ksft_print_msg("SME not supported\n"); for (i = 0; i < EXPECTED_TESTS; i++) { - putstr("ok "); - putnum(i); - putstr(" skipped\n"); + ksft_test_result_skip("fork_test\n"); } - - tests_skipped += EXPECTED_TESTS; } - print_summary(); + ksft_finished(); return 0; }