Message ID | 20230405-kselftest-nolibc-v1-0-63fbcd70b202@kernel.org |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1045553vqo; Thu, 6 Apr 2023 06:58:42 -0700 (PDT) X-Google-Smtp-Source: AKy350YnMORLlcgciN0yT/UNuCNwHjb9To39996v38+BC4OCqKt/VWg3scNQDz6PixKyJNSk7c6b X-Received: by 2002:a17:90b:3e89:b0:237:ae7c:15be with SMTP id rj9-20020a17090b3e8900b00237ae7c15bemr11197124pjb.30.1680789522477; Thu, 06 Apr 2023 06:58:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680789522; cv=none; d=google.com; s=arc-20160816; b=gP5TI6cki+rA9xUPWyfBJXnhf1wladDga6bvaYLWkbFPBzrWdQjbW03g2aKG29H4BH EclJvo2/hI27g/bGayysTNoM1+lhKPJ8l6Yli1umbkEpfxPOzz0N6N6LLXW1yaiUQvr5 E6yu3nffnzr6XZ+fK/5UWpkaMWw9fKbAJF+sxnejbuRfJLd4Nut5jNkA6SonANgOoeO5 KVsVglCIRGTuhveswcsHAcvGcJROtLEDzMWJfohWm0e8JulDoKh5qhgr/KnfuGN8+/+J /lU/mxLsOa7M7NIRxOY2Dfd3MTgxIs1yx7p0Pe/j2nBw89hHgL9UX1OtLnxKRXiupZ71 gL4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:content-transfer-encoding:mime-version :message-id:date:subject:from:dkim-signature; bh=ZdTk5dJbV99L33ozPoLZlkM81uoSFRaVO2mfZ4TJCKo=; b=riIpkhom957EYOM9ixe8HXm6bXxlfYYH+yGy7VInV4xuW2KE/5m+JST9+izpZ+ahWK 5uB+sSfkFPlbqDvTw+3AppXceqMFp0RmIy2ApfnyZdo+VJRHV2qZ2R9lD8V9drPi7Vnc tGI4srvmXOSSWvbM3aQ1yRO4izHegSSwD6Y6E5PKc8uUDwUFxV5b8QUsXpmMrQqBMxYO IfHq8zG2hP1/weqVUeidnU/nk4Yrp+3Ec+vIkb/ixfq4g37xJ7E/7k+XbPnGM0mtu6fT wKPIW6LcFJOnZW/4rAwrcQsupoKwFSNXU0Ft13LTw4AR8F34GCCUO+UPAvS1P0TooVTe 4pvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IE52y9OS; 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 x3-20020a17090abc8300b0023d21d8cd42si3966161pjr.27.2023.04.06.06.58.29; Thu, 06 Apr 2023 06:58:42 -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=IE52y9OS; 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 S238890AbjDFN5s (ORCPT <rfc822;lkml4gm@gmail.com> + 99 others); Thu, 6 Apr 2023 09:57:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238889AbjDFN5n (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 6 Apr 2023 09:57:43 -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 885F7A5F7; Thu, 6 Apr 2023 06:57:22 -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 ED6C76456E; Thu, 6 Apr 2023 13:57:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE9A7C4339B; Thu, 6 Apr 2023 13:57:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680789439; bh=UK5JJfdjiAdN9kwU5At61bUGQenEJhFJVNvEndfAWkg=; h=From:Subject:Date:To:Cc:From; b=IE52y9OSvrDsq/qGBBJkmB2j05+j9lw2T2ob9/QkVqO/PyUngTEWVbSRCieWPi6R8 ZtzVpD21IS9CZ9fW/B08b6k4rc5q/5xtHRzUziAB9spTCFC6Wxo1dvmDBLpVJoSx7J 6Yic4XcYtoX669XTvda+qWSbBqgQW3fQTkr2B/I4xLrNq4upp/lLaDd0nWKy+fgcE2 jkuVjrjGpDG+l2Akpf8NnNJw6sKP9XZcKelGlqBSLaa8NfT/u8Fuep5eQFVJk7ikqv 2Go3ooxSSF8dhDzT48HEdoDEk9eBtRalrJfCD42AD3koaxq8WPN2X6fmZjh3/zILuk zXjg4uCaW9r0g== From: Mark Brown <broonie@kernel.org> Subject: [PATCH 0/2] kselftest: Support nolibc Date: Thu, 06 Apr 2023 14:56:28 +0100 Message-Id: <20230405-kselftest-nolibc-v1-0-63fbcd70b202@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIAIzPLmQC/x2N0QrCMAwAf2Xk2UCsVdBfER/aLHPB2UlShjD27 3Y+HsdxK7iYisOtW8FkUde5NDgeOuAxlaeg9o0hUDhRpDO+XKahilcs86SZkXNgoRgvPV2hZTm 5YLZUeNzDd/IqtouPyaDf/+v+2LYfjLvkRXsAAAA= To: Shuah Khan <shuah@kernel.org>, Catalin Marinas <catalin.marinas@arm.com>, Will Deacon <will@kernel.org>, "Paul E. McKenney" <paulmck@kernel.org> Cc: linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Brown <broonie@kernel.org> X-Mailer: b4 0.13-dev-00303 X-Developer-Signature: v=1; a=openpgp-sha256; l=1586; i=broonie@kernel.org; h=from:subject:message-id; bh=UK5JJfdjiAdN9kwU5At61bUGQenEJhFJVNvEndfAWkg=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBkLs+7k+k7gQDbtDEjL2cEjcLJgulQT9C2jU5yInP9 TZZJ4OmJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZC7PuwAKCRAk1otyXVSH0I4CB/ 9p1/dGEQmbpFozJZoptPdTRtXccp9r7HSg3K8nmCuP/kLeje5ebuMpUPL1EjH6C5FgEL6xd0k2Xm/C BxGBHaHGAcfydZV99U0m6C82xD3XhmXXYj0tpunoJcVfT6s09lywO6AcHzbUcxtt3No6cG4/TfNP4C YKhP0qeRkGZ2ScrmRMPxtUx3BA3eonc9qaHjkPg8OXvt422Q8hXUBK/cF0VTuAw/S5CpPgKH2lmaQO Td/y89LL/cmxWBWjunb7U+g/jF52IO0COXW7gTY1G6LbHd95h/PVAh70cZVlxqTf0mskVQD/3oo/Md iPbuJ2WbdSLRa4KxAipuF75cPI6Z8w 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: <linux-kernel.vger.kernel.org> 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?1762435554773621716?= |
Series |
kselftest: Support nolibc
|
|
Message
Mark Brown
April 6, 2023, 1:56 p.m. UTC
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.
As an example of using this I've updated the arm64 za-fork test to use
the standard kselftest.h.
Signed-off-by: Mark Brown <broonie@kernel.org>
---
Mark Brown (2):
kselftest: Support nolibc
kselftest/arm64: Convert za-fork to use kselftest.h
tools/testing/selftests/arm64/fp/Makefile | 2 +-
tools/testing/selftests/arm64/fp/za-fork.c | 88 +++--------------
tools/testing/selftests/kselftest-nolibc.h | 93 ++++++++++++++++++
tools/testing/selftests/kselftest-std.h | 151 +++++++++++++++++++++++++++++
tools/testing/selftests/kselftest.h | 149 +++-------------------------
5 files changed, 272 insertions(+), 211 deletions(-)
---
base-commit: e8d018dd0257f744ca50a729e3d042cf2ec9da65
change-id: 20230405-kselftest-nolibc-cb2ce0446d09
Best regards,
Comments
Hi Mark, On Thu, Apr 06, 2023 at 02:56:28PM +0100, Mark Brown wrote: > 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. In fact we already have vfprintf(), and printf() is based on it, so wouldn't it just be a matter of adding vprintf() that calls vfprintf() for your case ? Maybe just something like this : static int vprintf(const char *fmt, va_list args) { return vfprintf(stdout, fmt, args); } It's possible I'm missing something, but it's also possible you didn't find vfprintf() which is why I prefer to raise my hand ;-) > 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. Yeah that's ugly. In nolibc-test we now have two build targets so that we can more easily verify the compatibility between the default libc and nolibc, so my recommendation would be to stick to a common subset of both libcs, but not to rely on nolibc-specific stuff that could make tests harder to debug. Regards, Willy
On Thu, Apr 06, 2023 at 04:20:29PM +0200, Willy Tarreau wrote: > On Thu, Apr 06, 2023 at 02:56:28PM +0100, Mark Brown wrote: > > 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. > In fact we already have vfprintf(), and printf() is based on it, so > wouldn't it just be a matter of adding vprintf() that calls vfprintf() > for your case ? Maybe just something like this : > static int vprintf(const char *fmt, va_list args) > { > return vfprintf(stdout, fmt, args); > } > It's possible I'm missing something, but it's also possible you didn't > find vfprintf() which is why I prefer to raise my hand ;-) Oh, yes - I just didn't find that. Can't remember what I searched for but it didn't match. > > 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. > Yeah that's ugly. In nolibc-test we now have two build targets so that > we can more easily verify the compatibility between the default libc and > nolibc, so my recommendation would be to stick to a common subset of both > libcs, but not to rely on nolibc-specific stuff that could make tests > harder to debug. For these features we simply never want to run with a proper libc since if we use a libc which has support for the features then we can't meaningfully interact with them. We're trying to test interfaces that libc is supposed to use.
On Thu, Apr 06, 2023 at 03:32:20PM +0100, Mark Brown wrote: > On Thu, Apr 06, 2023 at 04:20:29PM +0200, Willy Tarreau wrote: > > On Thu, Apr 06, 2023 at 02:56:28PM +0100, Mark Brown wrote: > > > > 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. > > > In fact we already have vfprintf(), and printf() is based on it, so > > wouldn't it just be a matter of adding vprintf() that calls vfprintf() > > for your case ? Maybe just something like this : > > > static int vprintf(const char *fmt, va_list args) > > { > > return vfprintf(stdout, fmt, args); > > } > > > It's possible I'm missing something, but it's also possible you didn't > > find vfprintf() which is why I prefer to raise my hand ;-) > > Oh, yes - I just didn't find that. Can't remember what I searched for > but it didn't match. No problem. I just remembered it existed because we just received a new test for it a few days ago ;-) > > > 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. > > > Yeah that's ugly. In nolibc-test we now have two build targets so that > > we can more easily verify the compatibility between the default libc and > > nolibc, so my recommendation would be to stick to a common subset of both > > libcs, but not to rely on nolibc-specific stuff that could make tests > > harder to debug. > > For these features we simply never want to run with a proper libc since > if we use a libc which has support for the features then we can't > meaningfully interact with them. We're trying to test interfaces that > libc is supposed to use. Indeed, this totally makes sense then! But I think you get the idea of what I was suggesting which is to try to avoid getting trapped by a single implementation in general, by using portable stuff as much as possible. Cheers, Willy