Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2872442rdb; Wed, 15 Nov 2023 13:08:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IGLolm8/2i9ao4bcSFRSQZJh79KCoDY7+gt4vyxImJ+IUAc3vHlPwQU3wWbega7RqPjlci/ X-Received: by 2002:a05:6e02:1d0a:b0:359:30b1:425e with SMTP id i10-20020a056e021d0a00b0035930b1425emr20602458ila.25.1700082524820; Wed, 15 Nov 2023 13:08:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700082524; cv=none; d=google.com; s=arc-20160816; b=qjEDhu2pR/knZQzGv8lWgj21GaBgiKue+Ro/mGGZ04Mc7Mpm53+hVpR41qA5yP8qps 1aj2rsE1CWkXFx5f+JFkWsHwkaw3STFrxZVniKGWNw2UkVM3nqTr2j+qWStP8yLIcJXt XvP476RSQ5S/AUgUwjiV0Q0T6wDBkbolE2Gi5ePQ7W9fZpGEpDqzKehsdVDH3MUZogF4 b/kY6vth3gKI4NjqBSiVb96hnmMNRCcykWa74u3hYItdV3ABsyYw3YTXhm9rlhkoci/J vdZ3mB+f8UNy6HvjT/nIpP4rPfoTy5qCTlykBJUJhJ6ne6V/cHUvbzCY7puqBEiJtapt qGnA== 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=acFy0p8JVEqjBf229B0TvWbzrbK40WkVuuKGRkYrWco=; fh=Qbk0RS4bf6GjbhGkpgFoVgYg5V+1DfWcZ6CAErfO2MQ=; b=tmEq7KWDSCdIcvgrOCgS6rp/Xphp74wpCHWC5wZLIY1PwoGMNJluoAsgP2vFY4uBPY 3zpqe5yGFFzi9drcHscFOxcINjnUmwwf0s1Y4C59MZbkkL1Stlco+bdx+X3dYLTVbYBY d6mnEiyCJY2AjjHWzSJL5yXdT3GxErRGI8EQbwoXoU2scOcsVARPETA/MFFS7K5RJ7dt iYWZkn0lbscf7tddYctZgqab/Dv75qT3i+F5O5bxdFPMvmi5lHMYT8I20LthZPlsrkeX Qng3yds32Ltb2ngqQTZ7HPXzgD7/AVB2yG9Xx/HzSs9QFSotu/NSFgzHZHq//VRhHIkt boaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=QxQFiyVs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id bx22-20020a056a02051600b0059d48c43152si11666501pgb.40.2023.11.15.13.08.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 13:08:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=QxQFiyVs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 75AC78104516; Wed, 15 Nov 2023 13:08:42 -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 S1344828AbjKOVIf (ORCPT + 99 others); Wed, 15 Nov 2023 16:08:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235606AbjKOVIa (ORCPT ); Wed, 15 Nov 2023 16:08:30 -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 5ABBAB7; Wed, 15 Nov 2023 13:08:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1700082503; bh=l0DjQT50wWPCx8bAIk7vWf2LX6LEwzHNYtmJlA8L6J0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=QxQFiyVsIc6a5YV70upXPlmTRX4ZkcpR0v8ekrkfswJGaLF2P/0k24GAnrzTFbT7c j9IXsg6HyOtECGGmtWxa3NLU+qqTvrzdRKUlSSC+L4H2mgF4IMw5jxroh8vxY0Nbki fHm/MF7imxuvdmmGYaYZgqY6sYsWhd1nBQsXIhxc= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 15 Nov 2023 22:08:21 +0100 Subject: [PATCH RFC 3/3] selftests/nolibc: migrate vfprintf tests to new harness MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20231115-nolibc-harness-v1-3-4d61382d9bf3@weissschuh.net> References: <20231115-nolibc-harness-v1-0-4d61382d9bf3@weissschuh.net> In-Reply-To: <20231115-nolibc-harness-v1-0-4d61382d9bf3@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1700082502; l=4412; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=l0DjQT50wWPCx8bAIk7vWf2LX6LEwzHNYtmJlA8L6J0=; b=D5ubOmECihDPDmd+UIRvHxT53OEDtxVHsJ8JxG5/5/6M0grUKMZjRz3CZcM3KiTTNpKB0bKp7 iBnTQFNFLhQCExPNZs6sZVF7T6HxzJEll+TB2zy9EwZStzdAmVmzyaB X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= 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 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]); Wed, 15 Nov 2023 13:08:42 -0800 (PST) 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); -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; 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; } fflush(memfile); @@ -1080,46 +1078,30 @@ static int expect_vfprintf(int llen, int c, const char *expected, const char *fm fclose(memfile); if (r != w) { - llen += printf(" written(%d) != read(%d)", (int)w, (int)r); - result(llen, FAIL); - return 1; + _metadata->exe.llen += printf(" written(%d) != read(%d)", (int)w, (int)r); + return FAIL; } buf[r] = '\0'; - llen += printf(" \"%s\" = \"%s\"", expected, buf); + _metadata->exe.llen += printf(" \"%s\" = \"%s\"", expected, buf); ret = strncmp(expected, buf, c); - result(llen, ret ? FAIL : OK); - return ret; + return ret ? FAIL : OK; } -static int run_vfprintf(int min, int max) +TEST(vfprintf, empty) { ASSERT_VFPRINTF(0, "", ""); } +TEST(vfprintf, simple) { ASSERT_VFPRINTF(3, "foo", "foo"); } +TEST(vfprintf, string) { ASSERT_VFPRINTF(3, "foo", "%s", "foo"); } +TEST(vfprintf, number) { ASSERT_VFPRINTF(4, "1234", "%d", 1234); } +TEST(vfprintf, negnumber) { ASSERT_VFPRINTF(5, "-1234", "%d", -1234); } +TEST(vfprintf, unsigned) { ASSERT_VFPRINTF(5, "12345", "%u", 12345); } +TEST(vfprintf, char) { ASSERT_VFPRINTF(1, "c", "%c", 'c'); } +TEST(vfprintf, hex) { ASSERT_VFPRINTF(1, "f", "%x", 0xf); } +TEST(vfprintf, pointer) { ASSERT_VFPRINTF(3, "0x1", "%p", (void *) 0x1); } + +int run_vfprintf(int min, int max) { - int test; - int ret = 0; - - for (test = min; test >= 0 && test <= max; test++) { - int llen = 0; /* line length */ - - /* avoid leaving empty lines below, this will insert holes into - * test numbers. - */ - switch (test + __LINE__ + 1) { - CASE_TEST(empty); EXPECT_VFPRINTF(0, "", ""); break; - CASE_TEST(simple); EXPECT_VFPRINTF(3, "foo", "foo"); break; - CASE_TEST(string); EXPECT_VFPRINTF(3, "foo", "%s", "foo"); break; - CASE_TEST(number); EXPECT_VFPRINTF(4, "1234", "%d", 1234); break; - CASE_TEST(negnumber); EXPECT_VFPRINTF(5, "-1234", "%d", -1234); break; - CASE_TEST(unsigned); EXPECT_VFPRINTF(5, "12345", "%u", 12345); break; - CASE_TEST(char); EXPECT_VFPRINTF(1, "c", "%c", 'c'); break; - CASE_TEST(hex); EXPECT_VFPRINTF(1, "f", "%x", 0xf); break; - CASE_TEST(pointer); EXPECT_VFPRINTF(3, "0x1", "%p", (void *) 0x1); break; - case __LINE__: - return ret; /* must be last */ - /* note: do not set any defaults so as to permit holes above */ - } - } - return ret; + return run_test_suite("vfprintf", min, max); } static int smash_stack(void) -- 2.42.1