All of lore.kernel.org
 help / color / mirror / Atom feed
From: Willy Tarreau <w@1wt.eu>
To: Daniel Palmer <daniel@thingy.jp>
Cc: "Thomas Weißschuh" <linux@weissschuh.net>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/2] nolibc: Add fread() and fseek()
Date: Sun, 4 Jan 2026 13:42:40 +0100	[thread overview]
Message-ID: <aVpgQFvq8MZyTICh@1wt.eu> (raw)
In-Reply-To: <CAFr9PX=W6QNzma0aewFLFj_y4wo=C8nb-G2FxhT8mjOTRzVofg@mail.gmail.com>

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 <linux@weissschuh.net> 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

  reply	other threads:[~2026-01-04 12:49 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-04  8:38 [PATCH 0/2] nolibc: Add fread() and fseek() Daniel Palmer
2026-01-04  8:38 ` [PATCH 1/2] tools/nolibc: Add fread() to stdio.h Daniel Palmer
2026-01-04  9:13   ` Thomas Weißschuh
2026-01-04 18:34   ` David Laight
2026-01-05  0:54     ` Daniel Palmer
2026-01-05  9:27       ` David Laight
2026-01-05  9:43         ` Daniel Palmer
2026-01-05 11:01           ` David Laight
2026-01-06 11:02             ` Thomas Weißschuh
2026-01-06 11:07               ` Willy Tarreau
2026-01-04  8:38 ` [PATCH 2/2] tools/nolibc: Add fseek() " Daniel Palmer
2026-01-04  9:11 ` [PATCH 0/2] nolibc: Add fread() and fseek() Thomas Weißschuh
2026-01-04 11:12   ` Daniel Palmer
2026-01-04 12:42     ` Willy Tarreau [this message]
2026-01-04 14:36     ` Thomas Weißschuh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aVpgQFvq8MZyTICh@1wt.eu \
    --to=w@1wt.eu \
    --cc=daniel@thingy.jp \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@weissschuh.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.