From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (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 3584E328273 for ; Tue, 17 Feb 2026 10:48:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771325292; cv=none; b=lanV95xZ/zHc18iYg8G/8F3mH5WQ6Pjm+wMkg4eStX+h6z8tAQxTOOoL21QoYmAAAjBhzj0QJpJaWQUwgiM2IXQ7shNftsLEPQbru49NgRGEW0kp3Z9UqLVGGdFwkRc2jxDpPEHJA80MSW3mr06Xva7iPtlrjeVuvOw8xdQmSKA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771325292; c=relaxed/simple; bh=RbKdaYC7QIEadniOjoSgdUT7QZHVAPMLclvcY439DCU=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eP6Slol3ai0zbWg0WarT9j+swcNCOANxt2xLkPapTE3vaHLS4kC7t+0BdiwDrzfF0eX5ApFIeVNqEox9A2Cya7/yT9w15Xzzj6T8YRmYvugqTWEwBdk36vU6fPl34icrHsS/xKr34GiXd0FEcvcB7lutBmBRazA8rMzbv5QVlac= 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=IwerYrZI; arc=none smtp.client-ip=209.85.221.49 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="IwerYrZI" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-4359a302794so2886442f8f.1 for ; Tue, 17 Feb 2026 02:48:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771325289; x=1771930089; 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=/os9ztjeTrGaMrD+uvsqGJ1P+mv3n3k2lrIjBCVKIag=; b=IwerYrZIP0OKTkVuKTzmZdTFE1QkN09iN8oN/zSlz5HjHk67QQWn/zpKPSFqVjCLT8 b8JWCzSab0G9gd+az5w+BhVdg6OyqJRJVhGynPr4Q3cYdhjSF9WJHDkC8GIbMPK4iwHN Lj0mz4lcrAfG82BLrg89pUcKSoDLx0JO6S+IofViCqa6XX5eH7cCfZ3NuLMtKZRM+480 mnaFK9KczRihUgxKBl0L5+2JRuXXc7uRH8LEEeELav+VLVArmoD1EIUSQ3OkMkRinAUA zIhrqdR8sR21IxNMdOB5Ga3SLM4N0R7pBVvTZw92mv57l15wIIItLU3973n9pL2Ihemn o9Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771325289; x=1771930089; 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=/os9ztjeTrGaMrD+uvsqGJ1P+mv3n3k2lrIjBCVKIag=; b=uiz10t0u+Um/RYgAkzOPWIrtxBmnMd7ZTAFwWUgNcfFGUXEcz3u0MpVJXvFsGMWUpG 8rMkJJNgLGyPfTbvKGaYbbartkoPP6UK9ES83dUcgxnz2WfOD3s05+08dhS3Aacqdbxl /B0zfE3MvG2+i1zJ6sj9afsVT6Z1iYe3a+GydyZvfumrladdCm1oLIlf5KnHLUuqlIr/ PPiaDo5YSvmmHjxWVGUac2dVuxbAQRDaADv3nxQHV2lwiEekyhEvS1R2JTynYCKVjs+I fKGwBnKx5eiCd6J/oudrK1xqx8phiw8dxrHejv1kSZHDTaWddYHopul77KihuMZDD0Y4 WMCw== X-Forwarded-Encrypted: i=1; AJvYcCVZA5FUs9Rk2XCqrc+e4SJS9Lu5iwaEXN0VT0a924F/XVLaPZZXWG7K2Sl5pX0s1bdnLLxRh7OK0vvDnDs=@vger.kernel.org X-Gm-Message-State: AOJu0Yzk/4fIcnGZ4CETmLYFc2kP2HesCBiVnwnTXgNhgjHmQS+QW9FH ndtkMwf+QZzMHyGjxlfryzS8cvTU/btJvL0fMFBRQ+BzJ1cjLilUjvnw X-Gm-Gg: AZuq6aL4BZRbnbUF9RZEPjlcbHr9O70NNeqY/Ktz3/PffX1r3yRJ/M8YxacHeiJEaaW yzQ15wlhdq54klzoSf8A2hLYVeyxZK7wkjStJ/VkomYB8EXZGiM/2ddnUp1Qy53cyEAJU4Uzue0 r11RkWsBecZBvEveQjv5Sf0gbmNRlV+3YHqcOdAQULvW7/02X8t6at9XK/NfShxCOClAUymRArQ sO783cylpbPeYYFweKuno1SWP4tczYOyNQJZDu7UvDStbTDYbvxLRs/Dm4pq8J9/iJ713Ln/Bdy MN/8nUEziLSmYsV3uiZlnb2QXAaUFXG7ncejDAc9prdMX/S09bA1slS3wQWxFqzzpnii+/oUw9h tsxTLyXVay4ditEh0lXzM3/ktRh32ifaAixu/yRh2SrzFAGdsUn+D1ak4POqrbk8L+dtt0wFmJ3 hKXKYyVu3aVFBC5yu3lOh1SULvsGBNskKmPKU2ZtIU1/aXFfpX2pyeO1pTHs52uKQi X-Received: by 2002:a05:6000:2510:b0:42b:3246:1681 with SMTP id ffacd0b85a97d-4379db64295mr18299703f8f.18.1771325289235; Tue, 17 Feb 2026 02:48:09 -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 ffacd0b85a97d-43796a74704sm35909508f8f.16.2026.02.17.02.48.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Feb 2026 02:48:08 -0800 (PST) Date: Tue, 17 Feb 2026 10:48:07 +0000 From: David Laight To: Thomas =?UTF-8?B?V2Vpw59zY2h1aA==?= Cc: Willy Tarreau , linux-kernel@vger.kernel.org, Cheng Li Subject: Re: [PATCH v2 next 09/11] selftests/nolibc: Improve reporting of vfprintf() errors Message-ID: <20260217104807.7eb7752a@pumpkin> In-Reply-To: References: <20260206191121.3602-1-david.laight.linux@gmail.com> <20260206191121.3602-10-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 Mon, 16 Feb 2026 21:05:40 +0100 Thomas Wei=C3=9Fschuh wrote: > On 2026-02-06 19:11:19+0000, david.laight.linux@gmail.com wrote: > > From: David Laight > >=20 > > Check the string matches before checking the returned length. > > Only print the string once when it matches. > > Normally the length is that of the expected string, make it easier > > to write tests by treating a length of zero as being that of the > > expected output. > > Additionally check that nothing beyond the end is written. > >=20 > > This also correctly returns 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 > > Signed-off-by: David Laight > > --- > >=20 > > Changes for v2: > > - Formally patch 5, otherwise unchanged. > >=20 > > tools/testing/selftests/nolibc/nolibc-test.c | 27 ++++++++++++++++---- > > 1 file changed, 22 insertions(+), 5 deletions(-) > >=20 > > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testi= ng/selftests/nolibc/nolibc-test.c > > index 3c5a226dad3a..9378a1f26c34 100644 > > --- a/tools/testing/selftests/nolibc/nolibc-test.c > > +++ b/tools/testing/selftests/nolibc/nolibc-test.c > > @@ -1567,28 +1567,45 @@ int run_stdlib(int min, int max) > > =20 > > static int expect_vfprintf(int llen, int c, const char *expected, cons= t char *fmt, ...) > > { > > + unsigned int i; > > char buf[100]; > > va_list args; > > ssize_t w; > > int ret; > > =20 > > + for (i =3D 0; i < sizeof(buf); i++) > > + buf[i] =3D i; =20 >=20 > Some of these values are valid ascii characters. > An out-of-bounds write may be missed if the test happens to print the > correct character. Another poison value would avoid this issue. I wanted to use different values just in case the test wrote the value I'd picked to two adjacent locations. I could use a (bad) random value (eg the time(NULL) & 0xff) so that an overwrite of the chosen value would be picked up by different run. >=20 > > =20 > > va_start(args, fmt); > > - /* Only allow writing 21 bytes, to test truncation */ > > + /* Only allow writing 20 bytes, to test truncation */ > > w =3D vsnprintf(buf, 21, fmt, args); > > va_end(args); > > =20 > > + llen +=3D printf(" \"%s\"", buf); > > + ret =3D strcmp(expected, buf); > > + if (ret) { > > + llen +=3D printf(" should be \"%s\"", expected); > > + result(llen, FAIL); > > + return 1; > > + } > > + if (!c) > > + c =3D strlen(expected); =20 >=20 > This patch does multiple different things again. Please split them up. > Specifically I am not a fan of allowing to pass '0' here. > While it is slightly more convenient when writing the tests, > it increases the opportunity for errors and makes the tests less clear > when reading them. I definitely wanted the invalid string output on failure. Not being able to see why a test failed is a PITA. Reporting the length error only makes sense when the output is truncated, and the 'truncation length' is a property of expect_vfprintf() not the test itself (and I had to increase it for the octal tests). One option is to remove the 'c' parameter completely and require the test include the un-truncated output for the truncation tests. There is no reason for any of them to be horribly long. Then add a parameter for 'run this test' (like all the other tests) so that some tests can be excluded/changed when is_nolibc isn't set. David >=20 > > if (w !=3D c) { > > llen +=3D printf(" written(%d) !=3D %d", (int)w, c); > > result(llen, FAIL); > > return 1; > > } > > =20 > > - llen +=3D printf(" \"%s\" =3D \"%s\"", expected, buf); > > - ret =3D strncmp(expected, buf, c); > > + for (i =3D c + 1; i < sizeof(buf); i++) { > > + if (buf[i] - i) { =20 >=20 > With a fixed poison value the check above wouldn't look this weird. >=20 > > + llen +=3D printf(" overwrote buf[%d] with 0x%x", i, buf[i]); > > + result(llen, FAIL); > > + return 1; > > + } > > + } > > =20 > > - result(llen, ret ? FAIL : OK); > > - return ret; > > + result(llen, OK); > > + return 0; > > } > > =20 > > static int test_scanf(void) > > --=20 > > 2.39.5 > > =20