From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 476FE3A0EB8 for ; Thu, 26 Feb 2026 10:12:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772100771; cv=none; b=aAzINL9H3KEQko+kQU12rGJX662tiee9z+1bsE4MyRH0SIaLbFJwvdzEu4o22qyg76K9aB3fvGMYBgb3MbzhVx+5ko6D2gr5QhfDt5jqjf+PzGkDN2PytWJMo+kaWl/g8e13rZaQ6u60FORjHIw/QL8Mm3BBaw+4wIqvU8zerEA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772100771; c=relaxed/simple; bh=d1+6OcKW6UDCbm8aEt9Drn4bMKWXWfHnWB+oxT9prsw=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=E0uM/5x/R7+nHDKxBJxHNcazlSs9Q+NM9PJ2Xd5273/xdxdFKwYfLQi0XmaXTaZe9Ht2icokWOkRIBV/T1+GVZrX0nfRO88OxXuefyefifUoLIWSxeWHgohxadcjToXmRGnaQpgQahjCmKcRevjkNG2ga29hy/ah0S8NNZ9hxDA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gjgSyFYA; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gjgSyFYA" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-483487335c2so6054875e9.2 for ; Thu, 26 Feb 2026 02:12:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772100769; x=1772705569; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=1TsbvPi6B+omi6tCz5q0T/TH7HgblVZd9ZkyEyHT+ho=; b=gjgSyFYA/gFQtiI7hhoxxIQs0Au41aUKh4pxJtuQg/FUy9Z87daIHc/2g7/C2XE4Td not3S+Q8uLpT39VBx60KEjzSvi+57qiV1Dkc3895/5zcrMxoORThKhGZQRdaUJ0rIBeq O7QbvUnQ7YLg39avPtJHDYIXJUmU/BcmauMznLxmums5PFeJU7qoynYLnIn3rrE7Ntam 5WJbS95wG95E+5FXKkvf9Te1BQvtHunpCEPG9y/4B87fcbFUQSzRV7jcVbN3/CEqC4tg vcuQX+bkOkGWAIvA6hQNDkisi9h8lh1Y56FLfSByWUZoEQDeyFi3wdnmwB/rkU3k4QxT rlQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772100769; x=1772705569; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=1TsbvPi6B+omi6tCz5q0T/TH7HgblVZd9ZkyEyHT+ho=; b=UyP9GuROy/kdaknsLM16bnZdSXNDNIU5ifqF5lnwNefd93ERWMhyHWpSSKWTGSY+En rNlOiiLFnTFbAZMc03EayF8FJ0NCR6EwUBfKDF93u2XG0A/e+7Qj0o5C9bw3eG1jbLqa baDjOoAcIIainjY4XJBFPsjuTQOY/kjd1f4uWqJ2+jd9xaxF35GkBaQ0LgUbYeCgcPwa 4r7e4mnRdwLps3y5VH49jzrpRML0aFEdDJqJL3u1KV0UzREK4CNmV4OkHDJ2mbWCMNMY Mh+IcBZ9y5nBl/7uYiTdN0qhgmWufAtJqM8QNcbUBziBNE7+2B3c7qd8wCc+ITKsI4Oj srXw== X-Forwarded-Encrypted: i=1; AJvYcCVorTEOq93Raq+/l9e+uzIX60f0ADfMtDqmf3+dgXOGrWyT8eK2HPDUOq7AIlXJV5uPKPtd0FYEU8c17zQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yw1UnDVPxvNdAq+38Uu1lRKM+u+1DLu9dPIb4Qw9+q9yXM2GENE Yjbrir23venUQXWGpEb/GWBpRZlKxcC8F9z/JLAo3Qlmc7sdCLX1OiES X-Gm-Gg: ATEYQzz6wsbF6MiEI1m56NdCAkP0HDr6wZ5hMmNRBdOmC6TFZuuEIiwEZVWvgh41A2O XUcY4Sc2cPbO2YKaLKUiNqtVqiUNJtPx+dLOuQCRr0S1+CtKuyVZ0LsKsNMLarwh16NcndciRSe 2KzPdaep6cUE9JMxFFmYE2wVIFoqJuZtUr1BsEzCtgI1X8inGXNhAXJg8DSSbMXjEOWL/1O5Bpr fh0EzKW31hC7htN43x1RVnKV3o57hZfaZ+f9TF83DT0VLuRRUeeja0Cmy+tDoiINghfBd83+vX8 2ostZQbve98fOZ/Zjo9pNb7j44sPHfu2f78EOPLvOU5/vM2ezi8J7FHSQA+0OhFhnPWF0bRwFm2 kQFig8AD7x+CwKLE776c7vpv+yUMuaLDwYymxbjoQzBULY0B75qT8MO6rfYTZ+BF7SanYFuwJ4r SshFP1v2pX1QyN2Xhyl0gi2CIoDea5WKSXv6MbO0zK8UM95IQ+p9KEG20B46tDWXsW X-Received: by 2002:a05:600c:8a16:10b0:47e:e4ff:e2ac with SMTP id 5b1f17b1804b1-483a9603c2dmr230572635e9.33.1772100768250; Thu, 26 Feb 2026 02:12:48 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-483bfbb6d16sm47033875e9.5.2026.02.26.02.12.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 02:12:47 -0800 (PST) Date: Thu, 26 Feb 2026 10:12:46 +0000 From: David Laight To: Thomas =?UTF-8?B?V2Vpw59zY2h1aA==?= Cc: Willy Tarreau , linux-kernel@vger.kernel.org, Cheng Li Subject: Re: [PATCH v3 next 04/17] selftests/nolibc: Improve reporting of vfprintf() errors Message-ID: <20260226101246.07bab7af@pumpkin> In-Reply-To: References: <20260223101735.2922-1-david.laight.linux@gmail.com> <20260223101735.2922-5-david.laight.linux@gmail.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Wed, 25 Feb 2026 22:56:03 +0100 Thomas Wei=C3=9Fschuh wrote: ...=20 > > Increase the size limit from 20 to 25 characters, changing the tests to > > match. This is needed to test octal conversions later on. =20 >=20 > Then please do this right before the addition of the octal conversion. I also kept hitting the limit trying to write other tests. It is very easy to hit 20 chars when testing precision (three %6.2d is too long) Although I think the tests were written with that change done later. I put it early so that I wouldn't have to change new tests that tested truncation. Perhaps I should justify the change because it lets tests check longer data, not just octal? I will then use longer test output in some of the other patches. >=20 > > Append a '+' to the printed output (after the final ") when the output > > is truncated. > >=20 > > Additionally check that nothing beyond the end is written. > > The "width_trunc" test (#14) now fails because e90ce42e81381 > > ("tools/nolibc: implement width padding in printf()") doesn't > > correctly update the space in the buffer when adding pad characters. > > This will be addressed in a later patch. =20 >=20 > The build bots will yell at us for this. > Instead mark the test as skipped until it is fixed. The build bots won't bleat - it is a run-time error. But I can disable it. I'm not sure there is a #define for 'broken' and there isn't room for comments on the test cases. So it might just be a literal 0. >=20 > > Also correctly return 1 (the number of errors) when strcmp() > > fails rather than the return value from strncmp() which is the > > signed difference between the mismatching characters. =20 >=20 > Please split these different steps into dedicated commits. > Yes, the testcases are going to be rewritten a bunch of times, > but that does not matter. >=20 > > Signed-off-by: David Laight > > --- > >=20 > > For v3: > > - Patch 9 in v2, patch 5 in v1.. > > - Increase the size limit to 25 in preparation for testing octal. > > - Change the way truncated fprintf() are handled. > > - Allow for tests being skipped. > > - Use a fixed value (0xa5) for the canary when detecting overwrites. > >=20 > > tools/testing/selftests/nolibc/nolibc-test.c | 91 ++++++++++++++------ > > 1 file changed, 64 insertions(+), 27 deletions(-) > >=20 > > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testi= ng/selftests/nolibc/nolibc-test.c > > index 0e8b3b9a86ef..029ed63e1ae4 100644 > > --- a/tools/testing/selftests/nolibc/nolibc-test.c > > +++ b/tools/testing/selftests/nolibc/nolibc-test.c > > @@ -1660,33 +1660,70 @@ int run_stdlib(int min, int max) > > return ret; > > } > > =20 > > -#define EXPECT_VFPRINTF(c, expected, fmt, ...) \ > > - ret +=3D expect_vfprintf(llen, c, expected, fmt, ##__VA_ARGS__) > > +#define EXPECT_VFPRINTF(cond, expected, fmt, ...) \ > > + ret +=3D expect_vfprintf(llen, cond, expected, fmt, ##__VA_ARGS__) > > =20 > > -static int expect_vfprintf(int llen, int c, const char *expected, cons= t char *fmt, ...) > > +#define VFPRINTF_LEN 25 =20 >=20 > This is only used within expect_vfprintf(), so it can be a local variable. I used it to size buf[] so it needs to be an 'integer constant expression'. The only simple way to do that is with a #define - which isn't scoped. >=20 > > + > > +static int expect_vfprintf(int llen, int cond, const char *expected, c= onst char *fmt, ...) > > { > > - char buf[100]; > > + ssize_t written, expected_len; > > + char buf[VFPRINTF_LEN + 80]; > > + unsigned int cmp_len; > > va_list args; > > - ssize_t w; > > - int ret; > > =20 > > + if (!cond) { > > + result(llen, SKIPPED); > > + return 0; > > + } =20 >=20 > The other EXPECT_*() macros evaluate the condition in the macro, not the > corresponding function. I'm not entirely sure why that is, but please > keep it consistent. Most of the other ones call the function in the #define and just report the success/fail in the function. The SKIP test has to be before the function call - so has to be in the #define. For vfprintf (should be snprintf) the test is in the function. So really it should be TEST_SNPRINTF(). The only other similar one is EXPECT_STRTOX(). But I can change it for consistency. I might just re-post patches to this file. The later patches will depend on it, but that won't matter if it get applied. Where do these patches get applied to? So I can base new versions on the changes. I guess they'll get picked up into 'next' fairly quickly. David