Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp3112905rdb; Wed, 15 Nov 2023 23:49:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbUmZuAwlurZc9apCoc2bUVNjCO6S9nBkHd9NVJP6rBohKfaA4mUdvn2oWEJM5R2LBLIJU X-Received: by 2002:a05:6871:750e:b0:1c8:b870:4e62 with SMTP id ny14-20020a056871750e00b001c8b8704e62mr18018110oac.52.1700120946726; Wed, 15 Nov 2023 23:49:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700120946; cv=none; d=google.com; s=arc-20160816; b=l6b7Ms5b6+XxmOTLVOVeZLjf5lImnFvX8pw6G778NkNJhJfR7ONyfBHSbVTWk5+k4q TouvXY1bx5nFKyKZxeqQkgz4xkjpZzlfqDdylkrYnJjvBNQyCqpqoAtLzrEUnBMKDPnm A7H1xSlt5JIiI9OwoXdcDNU5tp2oIQ/rAOJME/XmXlirYWyWz2mkpvC0K+grOqaViRQm BjMr5AOBtw5JxSNLZeZ3usnFuVxZgPw+YYXpNKA5mPG0U8ufBrEG2ocmXIqZx0OdqRZ0 t7GEVYjtcFkQdbTR/dEe2SCmMGJ6vYqyyTB6OIq1D8bcACf6gYUClqtW6kD4DHItinFi LgQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Dr4lpPpjUDKqHuo5JI300u4KmmEkKiudu9Qh27ejX2A=; fh=qYSE4JWoGuek8PPANgtObAomYOrd4iJoUXDlbhr3PnI=; b=UAd+WkD5o1bVmoWnnV0QMrf/dRY3WL/9AAvL5I0udgSfBCygr7tOByU7gt8uUYrI1x HCIMegZwq++XbEsx7yZHF1FTAHD/5t5EP+4Za8WET3qtlb1ZJs+Ig8l6JIMyerB9uWfD i9s+VIXvJNLU/wnEpU/8QuzZuUBS8NvHMTXM4/06OYZ6KXRtQilelDIVgkMe1/ArCrN4 3Xa9zQggi38r0RTqIsY2wn3iog7dEgnhMdPRmMYzSskf1NAFm05BysxKXD/wuvfcraZ4 gz36/JW10AbZiF5yVeCpxcOR0Vf+yUkUVMXkHU9drr2UyXkIQ72b08gtuLMOaz9RsXLJ VFaA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id s18-20020a635252000000b005bdbcf5e6c5si11252103pgl.870.2023.11.15.23.49.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 23:49:06 -0800 (PST) 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; 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 Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 26BFB810EC37; Wed, 15 Nov 2023 23:49:04 -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 S234673AbjKPHsP (ORCPT + 99 others); Thu, 16 Nov 2023 02:48:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234553AbjKPHsN (ORCPT ); Thu, 16 Nov 2023 02:48:13 -0500 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D3BD719D; Wed, 15 Nov 2023 23:48:09 -0800 (PST) Received: (from willy@localhost) by mail.home.local (8.17.1/8.17.1/Submit) id 3AG7m2HD007736; Thu, 16 Nov 2023 08:48:02 +0100 Date: Thu, 16 Nov 2023 08:48:02 +0100 From: Willy Tarreau To: Thomas =?iso-8859-1?Q?Wei=DFschuh?= Cc: Shuah Khan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH RFC 3/3] selftests/nolibc: migrate vfprintf tests to new harness Message-ID: References: <20231115-nolibc-harness-v1-0-4d61382d9bf3@weissschuh.net> <20231115-nolibc-harness-v1-3-4d61382d9bf3@weissschuh.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231115-nolibc-harness-v1-3-4d61382d9bf3@weissschuh.net> X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, 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]); Wed, 15 Nov 2023 23:49:04 -0800 (PST) On Wed, Nov 15, 2023 at 10:08:21PM +0100, Thomas Wei?schuh wrote: > Migrate part of nolibc-test.c to the new test harness. > > Signed-off-by: Thomas Wei?schuh > --- > tools/testing/selftests/nolibc/nolibc-test.c | 74 +++++++++++----------------- > 1 file changed, 28 insertions(+), 46 deletions(-) > > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c > index 6c1b42b58e3e..c0e7e090a05a 100644 > --- a/tools/testing/selftests/nolibc/nolibc-test.c > +++ b/tools/testing/selftests/nolibc/nolibc-test.c > @@ -1039,10 +1039,13 @@ int run_stdlib(int min, int max) > return ret; > } > > -#define EXPECT_VFPRINTF(c, expected, fmt, ...) \ > - ret += expect_vfprintf(llen, c, expected, fmt, ##__VA_ARGS__) > +#define ASSERT_VFPRINTF(c, expected, fmt, ...) \ > + enum RESULT res = assert_vfprintf(_metadata, c, expected, fmt, ##__VA_ARGS__); \ > + if (res == SKIPPED) SKIP(return); \ > + if (res == FAIL) FAIL(return); Please enclose this in a "do { } while (0)" block when using more than one statement, because you can be certain that sooner or later someone will put an "if" or "for" above it. This will also avoid the double colon caused by the trailing one. > -static int expect_vfprintf(int llen, int c, const char *expected, const char *fmt, ...) > +static enum RESULT assert_vfprintf(struct __test_metadata *_metadata, int c, > + const char *expected, const char *fmt, ...) > { > int ret, fd; > ssize_t w, r; > @@ -1051,25 +1054,20 @@ static int expect_vfprintf(int llen, int c, const char *expected, const char *fm > va_list args; > > fd = open("/tmp", O_TMPFILE | O_EXCL | O_RDWR, 0600); > - if (fd == -1) { > - result(llen, SKIPPED); > - return 0; > - } > + if (fd == -1) > + return SKIPPED; > > memfile = fdopen(fd, "w+"); > - if (!memfile) { > - result(llen, FAIL); > - return 1; > - } > + if (!memfile) > + return FAIL; Till now it looks easier and more readable. > va_start(args, fmt); > w = vfprintf(memfile, fmt, args); > va_end(args); > > if (w != c) { > - llen += printf(" written(%d) != %d", (int)w, c); > - result(llen, FAIL); > - return 1; > + _metadata->exe.llen += printf(" written(%d) != %d", (int)w, c); > + return FAIL; > } Here however I feel like we're already hacking internals of the test system and that doesn't seem natural nor logical. OK I understand that llen contains the lenght of the emitted message, but how should the user easily guess that it's placed into ->exe.llen, and they may or may not touch other fields there, etc ? Also the fact that the variable is prefixed with an underscore signals a warning to the user that they should not fiddle too much with its internals. I'm seeing basically two possible approaches: - one consisting in having a wrapper around printf() that transparently sets the llen field in _metadata->exe. This at least offload this knowledge from the user who can then just know they have to pass an opaque metadata argument and that's all. - one consisting in saying that such functions should not affect the test's metadata themselves and that it ought to be the caller's job instead. The function then only ought to return the printed length, and will not need the metadata at all. I tend to prefer the second option. In addition, you seem to be returning only 3 statuses (ok/skip/fail) so returning a single composite value for this is easy, e.g. (result | llen) with result made of macros only touching the high bits. If in the future more returns are needed, either a larger int or shift can be used, or we can then return pairs or structs. Regards, Willy