From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailtransmit05.runbox.com (mailtransmit05.runbox.com [185.226.149.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19B36481DD for ; Mon, 23 Feb 2026 10:18:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.38 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771841912; cv=none; b=KYdyuG6WBm7cDQGGdzas4pAQYTf6cIHHP47nmjI4yDEY4eL8iAyRroYXwMlnr17wqPj+BcDNRUZsb0bhIv/jIcUE4ed1g+F575JO2YqvmsJITgZ2QNDKmEp+RE1ROJMPYEYxzduNaUqqYVgsPK6wcjr+hWsYxWPqOkVlhsEBEx4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771841912; c=relaxed/simple; bh=i52GsPClS/raYu7wS07JcgwRCb2w1MP6wWosENa1BwQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=P8Bs2hr4j+2J/H9hnZDGlKqE+zUp6VqutP+uoyZoTYfotc3aOUVN0qCO1LvGBao/51vRAR+zm4ZkjL2VhcCtve/8Ia84CrsOYJu2dOZzd+gWlqrhFmvWcN7H5EApPmRowOXGfNpq7v87s23khrwanOiNYamdNeumKExh/eEI4NU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=runbox.com; dkim=pass (2048-bit key) header.d=runbox.com header.i=@runbox.com header.b=ntxVDmnS; arc=none smtp.client-ip=185.226.149.38 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=runbox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=runbox.com header.i=@runbox.com header.b="ntxVDmnS" Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit05.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1vuT1G-00GoEL-KX; Mon, 23 Feb 2026 11:18:26 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=runbox.com; s=selector2; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To :Message-Id:Date:Subject:Cc:To:From; bh=H03YtWQaaNeDoJiqRc1AtoHEopKeSBB0Vi+p+4SHhkE=; b=ntxVDmnSN8FQ6tTlwMw+bZSXq2 pYqAV0gTp7skKcni2YPpb0fkLL86D4SOV6GpvCQnFpLZ9yLkMKCEI+3/wzS5AUhiodmW3yPqtk8lO fLrKu94cJ6SCSL5EKkQFDvcUzQ/3z+BFG65hUA+6m/OT1st3J+5wsAGdmMyDQtPXQUo051OGVuWTt yaL4KYKaV3Q+7mF0/MI1emlEbtNQKAaYUTsRVnk5ZcLrn5ntBu3vyAl6foNGkrL3EtZvHN/JAwtc8 pURi/oljGraDaNe/aMCyGKV1wdiDP/hPudtoEwU9pF2baHW7gxH+ggKBBCURqD5Bvyzv55MG+c1F9 aEIWVQ+g==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vuT1G-0005Qb-AZ; Mon, 23 Feb 2026 11:18:26 +0100 Received: by submission02.runbox with esmtpsa [Authenticated ID (1493616)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1vuT17-006AjD-5Z; Mon, 23 Feb 2026 11:18:17 +0100 From: david.laight.linux@gmail.com To: Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , linux-kernel@vger.kernel.org, Cheng Li Cc: David Laight Subject: [PATCH v3 next 17/17] selftests/nolibc: Use printf variable field widths and precisions Date: Mon, 23 Feb 2026 10:17:35 +0000 Message-Id: <20260223101735.2922-18-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260223101735.2922-1-david.laight.linux@gmail.com> References: <20260223101735.2922-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: David Laight Now that printf supports '*' for field widths and precisions then can be used to simplify the test output. - aligning the "[OK]" strings. - reporting the expected sprintf() output when there is a mismatch. Acked-by: Willy Tarreau Signed-off-by: David Laight --- Changes for v3: - Change code in expect_vfprintf() (code added in v3). tools/testing/selftests/nolibc/nolibc-test.c | 26 ++++---------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index b1f27fb1dd74..6c043e5e1220 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -156,21 +156,6 @@ static const char *errorname(int err) } } -static void align_result(size_t llen) -{ - const size_t align = 64; - char buf[align]; - size_t n; - - if (llen >= align) - return; - - n = align - llen; - memset(buf, ' ', n); - buf[n] = '\0'; - fputs(buf, stdout); -} - enum RESULT { OK, FAIL, @@ -188,8 +173,10 @@ static void result(int llen, enum RESULT r) else msg = " [FAIL]"; - align_result(llen); - puts(msg); + llen = 64 - llen; + if (llen < 0) + llen = 0; + printf("%*s%s\n", llen, "", msg); } /* The tests below are intended to be used by the macroes, which evaluate @@ -1699,10 +1686,7 @@ static int expect_vfprintf(int llen, int cond, const char *expected, const char } if (memcmp(expected, buf, cmp_len) || buf[cmp_len]) { - /* Copy and truncate until "%.*s" supported */ - memcpy(buf, expected, cmp_len); - buf[cmp_len] = 0; - llen += printf(" should be \"%s\"", buf); + llen += printf(" should be \"%.*s\"", VFPRINTF_LEN, expected); result(llen, FAIL); return 1; } -- 2.39.5