Message ID | 20230928-ktap-exec-v1-1-1013a2db0426@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3405422vqu; Thu, 28 Sep 2023 08:42:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTb04psILmTycz8LqH0z9IPzNOlhGE7HB04tM6z9DYIBK7J6vM8qC3ev/AbqS0E89Ouzc5 X-Received: by 2002:a17:903:18f:b0:1bf:69af:b4e4 with SMTP id z15-20020a170903018f00b001bf69afb4e4mr1668591plg.37.1695915723812; Thu, 28 Sep 2023 08:42:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695915723; cv=none; d=google.com; s=arc-20160816; b=SBjv363ipvHNh3KCtj3MGX3Lh3+K2JUdtEsKetSCN8YaBiT6zFWcw1Vz4IA4DAVi6R APnI7Y8dq1mLhXfsYF4kTbPqHF83KlU7/f3s/9OrWJ4SutAdfcUhM6ClCBQuazgP+EM0 TlIyr3OlPLeQIcWUspsbG0JRGpUKABMp5D0am6tUxIVDvmu5anMtN6DrNrc2JVeWcyU1 /oVm24ynwwon84Zbbp0+UR8TJLLgQOC6ZtsQMk4aiIBL0opU8oA4pZ/1EgOIPBqyKuJl haIcKOxIFR2AxdBIhSy7F72pDDSFWlnRuOVX8gSkR/VffB6xWPMAQyCA98Plps9oBzB9 KV6A== 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=ZBvzOuD8Fr4XtQ4fyCtWwoG6AEeanacXTbZYCGDnSQg=; fh=HNO8AQ2wPERiB9M+3D/S5zvibjMNIWsQe/l/z6GzIow=; b=vEVarqQottAuR5H8Wp/9JF/LfM8Rsc7Qt3vznjaezhWXoGQEZ6/WNkcA5ljP/pQzXE Uqcu2bpA8FFY8HVlKvnF1YFWcInjdm7IEXFVBmSZPbaiyvn4STlMsXs3yT8YLKSXcRB7 dHBZn65GSOnFntIVsv+1BjtYXt0YuMk/G6U4je8SwLaBTFrRwTWg1KNBPaO0S7a48DJo PxowLwjZh8JxpcSaowLR6nzX5sYun9aY029uR2LhFKsvVXrxJ2pXJbjLNx1MKUCE4dNg ucwgdrlLBidUdf/soNwKRutqkzkWbu2mMvPE1nunr8CPfevF9P3DXA+/CGNcBXtOivfO 7NOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BZQIp7cN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id kp11-20020a170903280b00b001bf095dfb7asi17570335plb.231.2023.09.28.08.42.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 08:42:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BZQIp7cN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 544FB801B180; Thu, 28 Sep 2023 07:38:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230390AbjI1Oid (ORCPT <rfc822;pwkd43@gmail.com> + 21 others); Thu, 28 Sep 2023 10:38:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230201AbjI1Oi3 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 28 Sep 2023 10:38:29 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E5BA136; Thu, 28 Sep 2023 07:38:26 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5255C433C8; Thu, 28 Sep 2023 14:38:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695911906; bh=q8UFTGCW+PEFQaExarcKjuMastWfb/GcwHIY56H9Tcw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=BZQIp7cN2GL57vChOU1kT8bhTIHyB461hx5VZi7EQHsucGSvA9HIFgljqIkq95OkW IapfOzlVzrqPm3gZkrIYLzry6pCbW8Kc7JGUXZ2DFiZQnrJOxUXcUtEupIgSJZmELh 9piUigJVyNW4S/Qn23Qz5inxoA++YG7wr/P5dS3S2ypSplxnXdcDo7TFWXslxuoeVX kOQqIpdkbBW9/3L0vXy6+tAMfe5otOlq9G8eA4aeZrbDEhOjrqPjxhsC5qLSIdggQF iP+QB3U8QFWreajhTBTyT51Urc00S1OlJpdwS8wphP9Vc7KyrTsn6QANcFNfaKFrsu e0m8ZBWmcE6cg== From: Mark Brown <broonie@kernel.org> Date: Thu, 28 Sep 2023 16:38:11 +0200 Subject: [PATCH 1/2] kselftest: Add a ksft_perror() helper MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230928-ktap-exec-v1-1-1013a2db0426@kernel.org> References: <20230928-ktap-exec-v1-0-1013a2db0426@kernel.org> In-Reply-To: <20230928-ktap-exec-v1-0-1013a2db0426@kernel.org> To: Shuah Khan <shuah@kernel.org>, Eric Biederman <ebiederm@xmission.com>, Kees Cook <keescook@chromium.org> Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Mark Brown <broonie@kernel.org> X-Mailer: b4 0.13-dev-099c9 X-Developer-Signature: v=1; a=openpgp-sha256; l=1471; i=broonie@kernel.org; h=from:subject:message-id; bh=q8UFTGCW+PEFQaExarcKjuMastWfb/GcwHIY56H9Tcw=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlFY/dyR2RkI4Mf3AjCLdtgSIbCYIqcP2/TW/+f QjOYN+RisqJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZRWP3QAKCRAk1otyXVSH 0LZxB/9rF9qh6VkytpRTD4uzNLpwiQHxuWBhc9JCr9kLoPxnRbAJTvaRe530xMNWvRPC0cIWeDk hhw6WbIo53maSZJl56bQngArBk29ZLRxINJrFzslh7L2PqNf2uFuvOAPN9hrej6d8cxWWUR+KMh LjCExIZCY8nR+W/+OqzUxP9ZjUv3nhIQ6yl5AkhLKfrPYDO9wP2iTjwuaHK160uXwZcwYCRytgh l9Jwk4IupXGCV3vZ6Eggv6zf1fJL1EBkjAc9V40uMaVKwznhKA9ANctrnmLFGnDK/luMYGZc0g8 fGyy026bp0/uCnZAzkF+UE96ngvOl/uimO47/k9nHs22kiy7 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 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: <linux-kernel.vger.kernel.org> 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]); Thu, 28 Sep 2023 07:38:50 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778296526506539959 X-GMAIL-MSGID: 1778296526506539959 |
Series |
kselftest/exec: Convert execveat test to KTAP output
|
|
Commit Message
Mark Brown
Sept. 28, 2023, 2:38 p.m. UTC
The standard library perror() function provides a convenient way to print
an error message based on the current errno but this doesn't play nicely
with KTAP output. Provide a helper which does an equivalent thing in a KTAP
compatible format.
nolibc doesn't have a strerror() and adding the table of strings required
doesn't seem like a good fit for what it's trying to do so when we're using
that only print the errno.
Signed-off-by: Mark Brown <broonie@kernel.org>
---
tools/testing/selftests/kselftest.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
Comments
On Thu, Sep 28, 2023 at 04:38:11PM +0200, Mark Brown wrote: > The standard library perror() function provides a convenient way to print > an error message based on the current errno but this doesn't play nicely > with KTAP output. Provide a helper which does an equivalent thing in a KTAP > compatible format. > > nolibc doesn't have a strerror() and adding the table of strings required > doesn't seem like a good fit for what it's trying to do so when we're using > that only print the errno. > > Signed-off-by: Mark Brown <broonie@kernel.org> Oh, interesting... what environment ends up without strerror()? Reviewed-by: Kees Cook <keescook@chromium.org>
On Thu, Sep 28, 2023 at 05:48:22PM -0700, Kees Cook wrote: > > nolibc doesn't have a strerror() and adding the table of strings required > > doesn't seem like a good fit for what it's trying to do so when we're using > > that only print the errno. > Oh, interesting... what environment ends up without strerror()? Like I say it's for nolibc - it's just some header files (all in the kernel source), while it generally aims to be libc compatible it's intentionally very small.
On Fri, Sep 29, 2023 at 09:50:53AM +0200, Mark Brown wrote: > On Thu, Sep 28, 2023 at 05:48:22PM -0700, Kees Cook wrote: > > > > nolibc doesn't have a strerror() and adding the table of strings required > > > doesn't seem like a good fit for what it's trying to do so when we're using > > > that only print the errno. > > > Oh, interesting... what environment ends up without strerror()? > > Like I say it's for nolibc - it's just some header files (all in the > kernel source), while it generally aims to be libc compatible it's > intentionally very small. Right, I mean, how would one normally encounter this environment? Running the selftests on m68k userspace or something?
On Fri, Sep 29, 2023 at 10:31:56AM -0700, Kees Cook wrote: > On Fri, Sep 29, 2023 at 09:50:53AM +0200, Mark Brown wrote: > > Like I say it's for nolibc - it's just some header files (all in the > > kernel source), while it generally aims to be libc compatible it's > > intentionally very small. > Right, I mean, how would one normally encounter this environment? Running > the selftests on m68k userspace or something? There's a bunch of selftests that cover interfaces that are intended to be used by libc which are built with nolibc in order to avoid the tests and glibc stomping over each other.
diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h index 529d29a35900..af9f1202d423 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h @@ -48,6 +48,7 @@ #include <stdlib.h> #include <unistd.h> #include <stdarg.h> +#include <string.h> #include <stdio.h> #endif @@ -155,6 +156,19 @@ static inline void ksft_print_msg(const char *msg, ...) va_end(args); } +static inline void ksft_perror(const char *msg) +{ +#ifndef NOLIBC + ksft_print_msg("%s: %s (%d)\n", msg, strerror(errno), errno); +#else + /* + * nolibc doesn't provide strerror() and it seems + * inappropriate to add one, just print the errno. + */ + ksft_print_msg("%s: %d)\n", msg, errno); +#endif +} + static inline void ksft_test_result_pass(const char *msg, ...) { int saved_errno = errno;