From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta1.formilux.org (mta1.formilux.org [51.159.59.229]) (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 A059727E049 for ; Sun, 4 Jan 2026 12:49:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=51.159.59.229 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767530991; cv=none; b=tDo2C2N/fG8v6aHAwBvUBP7f5zMYoctqSAdAoZ1HkVaC62kSHqjNzcRKFrSoH/3RJ88A2uQNooIBfXCSNtUKUb72jC+A1aD4Wt0mQrwy9t30Qld9zFls3JIp/x00PGIiSo/V5XELACHNriIpdBsqJm5u0UEt2Z2QfYZgMq2ffiE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767530991; c=relaxed/simple; bh=62qnksxlfvJV9Neax/xvJT0doePHkbn1A4MgAEVV5Mg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YQUvCQ+Yl/MyiPcO2iDJe3UpwSf+K+O5jggz4cxxMOUZCkmFpIN9RKkVGXdbJSJwHlB6fqbdQQtz7JZILReM/41oaDyDPSPMk+YbEDW6lrXk91lcDHEbcEVRrQWnF0tDA3FiV2g+8H/gacq7affuYLCQkgqj2gF2a4by24+/RY4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu; spf=pass smtp.mailfrom=1wt.eu; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b=ALwAwCJu; arc=none smtp.client-ip=51.159.59.229 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=1wt.eu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b="ALwAwCJu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1wt.eu; s=mail; t=1767530561; bh=KgiASPvy4PKFgGcWUjQx/SoXQU+2RV7JwYb7URyFFB4=; h=From:Message-ID:From; b=ALwAwCJuyk+8YYxpFLSxeowcZ4yqIDw3XP02kl9bKQRSTEtX1LyGNVLIqOIK1lsFL +iikvIkP9ObZJrWWXntUIx7C8FG2Sjz572qfQw+DWIzClA1TQL40/y+R+6xk7PPYtY HpGbQcwQt87IAuIeDh1gqCq1qBUT+i933CZPWNV8= Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by mta1.formilux.org (Postfix) with ESMTP id 547D8C0943; Sun, 04 Jan 2026 13:42:41 +0100 (CET) Date: Sun, 4 Jan 2026 13:42:40 +0100 From: Willy Tarreau To: Daniel Palmer Cc: Thomas =?iso-8859-1?Q?Wei=DFschuh?= , linux-kernel@vger.kernel.org Subject: Re: [PATCH 0/2] nolibc: Add fread() and fseek() Message-ID: References: <20260104083837.1390041-1-daniel@thingy.jp> <67092b7b-f4db-4439-84d6-026224a07ed1@t-8ch.de> 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=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Hi Daniel, On Sun, Jan 04, 2026 at 08:12:11PM +0900, Daniel Palmer wrote: > Hi Thomas, > > On Sun, 4 Jan 2026 at 18:11, Thomas Weißschuh wrote: > > Please also do add some tests. > > Would a single function test that exercises the new functions be > enough? Something like this: > > --- a/tools/testing/selftests/nolibc/nolibc-test.c > +++ b/tools/testing/selftests/nolibc/nolibc-test.c > @@ -877,6 +877,45 @@ int test_file_stream(void) > return 0; > } > > +int test_file_stream_wsr(void) > +{ > + const char dataout[] = "foo"; > + const size_t datasz = sizeof(dataout); > + char datain[datasz]; > + FILE *f; > + int r; > + > + f = fopen("/tmp/file_stream_test", "w+"); > + if (!f) > + return -1; > + > + r = fwrite(dataout, 1, datasz, f); > + if (r != datasz) > + goto fail; > + > + r = fseek(f, 0, SEEK_SET); > + if (r) > + goto fail; > + > + r = fread(datain, 1, datasz, f); > + if (r != datasz) > + goto fail; > + > + if (memcmp(datain, dataout, datasz) != 0) > + goto fail; > + > + r = fclose(f); > + if (r == EOF) > + return -1; > + > + return 0; > + > +fail: > + fclose(f); > + return -1; > +} > + In general it's preferable when tests focus on a specific syscall or function, so that when a failure is reported, it's easier to figure what we broke. But I agree it's not always easy, especially when resources are allocated and released, like here. I can hardly propose better. Please also keep in mind that sometimes we also want to validate certain error cases (e.g. if opening a file in read-only mode, writing to it should fail). Hoping this helps, Willy