Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp3327059rdb; Thu, 16 Nov 2023 06:47:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IGzADdx7ZxOhZErhWxdLxeeLkxZhaVomtyPHV5ukHdlwVKVsHDUbV/weivyZfC0wLn3lRvC X-Received: by 2002:a17:902:bd4c:b0:1bd:ca80:6fe6 with SMTP id b12-20020a170902bd4c00b001bdca806fe6mr2070638plx.41.1700146023789; Thu, 16 Nov 2023 06:47:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700146023; cv=none; d=google.com; s=arc-20160816; b=s3r5WmGyed82JhXWgHDI54WQD3dDbTAQUDlr7CQSufParQ/qLr4ue8R79kx4vsjoRf WQXWg9PnZ+zvnycrRab2npYFpC76Hi7tX8oTS1HGjy0i1rZ7/ULqV/4qYfHsK+tot1fE SYcKvMJ6Q9mjVpLkStPEYa3IR/DvmpqQH07D+piI9Ia7qWHgTHJXjuF37LJsiMzRlGTS GoifzZFaOduT2xZP/Mr+AroknppeLPh4pAaQ5Wfxc6Lm9zRiLPF3eDgyCtfsQxzdIxVM oGNhUoa+BYGS2dugLU56zcj5M1kPe8Za7r5laNtbWz4+gGa7FZLiE8uBwHHO6sT0pBCt ZEvw== 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:dkim-signature; bh=bF1oSeegir7IldyKTNWJhsNqemAyzhdVzuoNUt9By3I=; fh=pTx9fEY7ua+lm7qrJvkJuQzqwoXTh0iZZAyDx4UpkYw=; b=WokvwA1qtWEQw/uUSyjKGkRid2Y2B+im06F5h18BRzo41OTPzLdMcM+q0hHKI/C1vU 9DwzIE3Ea+fgOR3eVixWrGhA91iATmcvk2OgnZljqi2L5sQ/I1bo73mTrhIDoRlYFkIW XZMEKE1sPCvV5OieCzHJpJ2rnlIG0NbuTcaPzOlvWpX+vE/Gvy31BowWqEk2oLbG4vug dkOgKwTfVStOspbDLFTnvMpf03cgfdtMsACN5kZd8qvcaLm0fCxnGmf2bGqMKE8egVF8 G258e8oUdceLHAOr+/XGIpMWxg3GOHyA1svj3FiuxY22Sqr8EqtDmoh1f+TkoqgOdr/g zEUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=COVB0B60; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id p10-20020a170902eaca00b001b6ae9f8bb1si11963497pld.75.2023.11.16.06.47.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 06:47:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=COVB0B60; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 8A954821ADA3; Thu, 16 Nov 2023 06:47:02 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345309AbjKPOrB (ORCPT + 99 others); Thu, 16 Nov 2023 09:47:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345317AbjKPOq7 (ORCPT ); Thu, 16 Nov 2023 09:46:59 -0500 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93FE3193; Thu, 16 Nov 2023 06:46:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1700146014; bh=JbWBECiAQCY4MXhVgY7RhNNqBPGkB2Zc4z1rLidUoxQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=COVB0B60ejVWjhUMlunPsI7O/6q83X6VDG1SAaJQWy0tyfy33duuE4kZMLEWZS2DO 8J/eORSl4LKHZjMxh+XZ8Q3+73cUWiRJk3FjTFnwh2BVEeUz6smHHTQ+XSITqKBf0m ExEkBF98/W5D0IHr+Q831Iie40g0bAfx7UYQRFdA= Date: Thu, 16 Nov 2023 15:46:54 +0100 From: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= To: Willy Tarreau Cc: Shuah Khan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH RFC 2/3] selftests/nolibc: migrate startup tests to new harness Message-ID: <57215bf9-b063-4306-892d-56765e81413e@t-8ch.de> References: <20231115-nolibc-harness-v1-0-4d61382d9bf3@weissschuh.net> <20231115-nolibc-harness-v1-2-4d61382d9bf3@weissschuh.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 16 Nov 2023 06:47:02 -0800 (PST) On 2023-11-16 08:33:27+0100, Willy Tarreau wrote: > On Wed, Nov 15, 2023 at 10:08:20PM +0100, Thomas Weißschuh wrote: > > Migrate part of nolibc-test.c to the new test harness. > > > > Signed-off-by: Thomas Weißschuh > > A few points, mostly questions and food for thoughts. > > > -static void putcharn(char c, size_t n) > > -{ > > - char buf[64]; > > - > > - memset(buf, c, n); > > - buf[n] = '\0'; > > - fputs(buf, stdout); > > -} > > - > > Ah now I see how the other one came from :-) My comment about the size > check still stands anyway, especially when placed in an include file. > > > +#if defined(NOLIBC) > > + > > +#define ASSUME_NOLIBC(stmt) > > + > > +#else /* defined(NOLIBC) */ > > + > > +/* differ from nolibc, both glibc and musl have no global _auxv */ > > +unsigned long *_auxv = (void *)-1; > > +#define ASSUME_NOLIBC(stmt) SKIP(stmt) > > + > > +#endif /* defined(NOLIBC) */ > > + > > I've seen below how it's used and don't find this very clear. In general, > passing a statement as an argument to a macro, especially control statements > such as "return" is a bit difficult to grasp. If the macro is only used for > this, maybe it should integrate the return statement and be called something > like "RETURN_UNLESS_NOLIBC()" which is quite explicit this time. If you really > need to keep the statement adjustable, then most likely that calling the > macro "UNLESS_NOLIBC()" would help, because I understand more naturally > that the following will perform a return if we're not on nolibc: > > UNLESS_NOLIBC(return); > > than: > > ASSUME_NOLIBC(return); The statement arguments is modelled after SKIP() from kselftest_harness.h. But the wrapper you proposed is indeed much better, I'll switch to that. > > > - for (test = min; test >= 0 && test <= max; test++) { > > - int llen = 0; /* line length */ > > + if (brk) > > + return brk; > > > > - /* avoid leaving empty lines below, this will insert holes into > > - * test numbers. > > - */ > > - switch (test + __LINE__ + 1) { > > - CASE_TEST(argc); EXPECT_GE(1, test_argc, 1); break; > > - CASE_TEST(argv_addr); EXPECT_PTRGT(1, test_argv, brk); break; > > - CASE_TEST(argv_environ); EXPECT_PTRLT(1, test_argv, environ); break; > > - CASE_TEST(argv_total); EXPECT_EQ(1, environ - test_argv - 1, test_argc ?: 1); break; > > - CASE_TEST(argv0_addr); EXPECT_PTRGT(1, argv0, brk); break; > > - CASE_TEST(argv0_str); EXPECT_STRNZ(1, argv0 > brk ? argv0 : NULL); break; > > - CASE_TEST(argv0_len); EXPECT_GE(1, argv0 > brk ? strlen(argv0) : 0, 1); break; > > - CASE_TEST(environ_addr); EXPECT_PTRGT(1, environ, brk); break; > > - CASE_TEST(environ_envp); EXPECT_PTREQ(1, environ, test_envp); break; > > - CASE_TEST(environ_auxv); EXPECT_PTRLT(test_auxv != (void *)-1, environ, test_auxv); break; > > - CASE_TEST(environ_total); EXPECT_GE(test_auxv != (void *)-1, (void *)test_auxv - (void *)environ - 1, env_total); break; > > - CASE_TEST(environ_HOME); EXPECT_PTRNZ(1, getenv("HOME")); break; > > - CASE_TEST(auxv_addr); EXPECT_PTRGT(test_auxv != (void *)-1, test_auxv, brk); break; > > - CASE_TEST(auxv_AT_UID); EXPECT_EQ(1, getauxval(AT_UID), getuid()); break; > > - CASE_TEST(constructor); EXPECT_EQ(1, constructor_test_value, 2); break; > > - CASE_TEST(linkage_errno); EXPECT_PTREQ(1, linkage_test_errno_addr(), &errno); break; > > - CASE_TEST(linkage_constr); EXPECT_EQ(1, linkage_test_constructor_test_value, 6); break; > > - case __LINE__: > > - return ret; /* must be last */ > > - /* note: do not set any defaults so as to permit holes above */ > > - } > > - } > > - return ret; > > + brk = sbrk(0); > > + > > + if (brk == (void *)-1) > > + brk = &end; > > + > > + return brk; > > } > > > > +TEST(startup, argc) { ASSERT_GE(test_argc, 1); } > > +TEST(startup, argv_addr) { ASSERT_GT((void *)test_argv, pbrk()); } > > +TEST(startup, argv_environ) { ASSERT_LT(test_argv, environ); } > > +TEST(startup, argv_total) { ASSERT_EQ(environ - test_argv - 1, test_argc ?: 1); } > > +TEST(startup, argv0_addr) { ASSERT_GT((void *)argv0, pbrk()); } > > +TEST(startup, argv0_str) { ASSERT_STRNZ((void *)argv0 > pbrk() ? argv0 : NULL); } > > +TEST(startup, argv0_len) { ASSERT_GE((void *)argv0 > pbrk() ? strlen(argv0) : 0U, 1U); } > > +TEST(startup, environ_addr) { ASSERT_GT((void *)environ, pbrk()); } > > +TEST(startup, environ_envp) { ASSERT_EQ(environ, test_envp); } > > +TEST(startup, environ_auxv) { > > + ASSUME_NOLIBC(return); > > + ASSERT_LT((void *)environ, (void *)_auxv); > > +} > > +TEST(startup, environ_total) { > > + ASSUME_NOLIBC(return); > > + /* kernel at least passes HOME and TERM, shell passes more */ > > + ASSERT_GE((void *)_auxv - (void *)environ - 1, 2); > > +} > > +TEST(startup, environ_HOME) { ASSERT_NE(getenv("HOME"), NULL); } > > +TEST(startup, auxv_addr) { > > + ASSUME_NOLIBC(return); > > + ASSERT_GT((void *)_auxv, pbrk()); > > +} > > +TEST(startup, auxv_AT_UID) { ASSERT_EQ(getauxval(AT_UID), getuid()); } > > +TEST(startup, constructor) { ASSERT_EQ(constructor_test_value, 2); } > > +TEST(startup, linkage_errno) { ASSERT_EQ(linkage_test_errno_addr(), &errno); } > > +TEST(startup, linkage_constr) { ASSERT_EQ(linkage_test_constructor_test_value, 6); } > > I do appreciate the much lower indent level that still manages to > enumerate tests easily. But given that test suites are grouped, shouldn't > we go a bit further and state that TEST() operates on the suite defined > by the TEST_SUITE macro that must be defined before it ? This way you would > have: > > #define TEST_SUITE startup > TEST(argc) { ASSERT_GE(test_argc, 1); } > TEST(argv_addr) { ASSERT_GT((void *)test_argv, pbrk()); } > ... > #undef TEST_SUITE > > One thing that was not immediately obvious to me upon first read was > if TEST() defines or executes a test (i.e. "test" is both a noun and a > verb). Of course, spending 10 more seconds on the patch makes it obvious > it's a definition, but maybe following the same logic we have with > run_test_suite(), we should place the verb in front, for example > "DEF_TEST()" which then makes it quite unambiguous. Any opinion ? The TEST() macro is modelled after kselftest_harness (which only takes one argument, as it doesn't support suites) and google test which works the same as the new TEST(). So I would prefer to keep the name. As for specifying the suite via a macro: I like that it saves even more indentation but at the same time it feels a bit too implicit. I'm not sure...