[PATCH v3] libio: Add test case for fflush

Florian Weimer fweimer@redhat.com
Tue Nov 19 11:41:52 GMT 2024


* Frédéric Bérat:

> diff --git a/libio/tst-fflush-NULL.c b/libio/tst-fflush-NULL.c
> new file mode 100644
> index 0000000000..23c741e0dc
> --- /dev/null
> +++ b/libio/tst-fflush-NULL.c
> @@ -0,0 +1,23 @@
> +/* Test that fflush (FILE) and fflush (NULL) are semantically equivalent.

Should mention this is the fflush (NULL) part.

> +#define FILE_FLUSH_TYPE 1

It's strange that the NULL test uses 1 and the regular test uses 0. 8-)

> +#define S_FLUSH_TYPE "NULL"
> +
> +#include "tst-fflush-skeleton.c"
> diff --git a/libio/tst-fflush-skeleton.c b/libio/tst-fflush-skeleton.c
> new file mode 100644
> index 0000000000..6ad21650d0
> --- /dev/null
> +++ b/libio/tst-fflush-skeleton.c
> @@ -0,0 +1,184 @@
> +/* Test that fflush (FILE) and fflush (NULL) are semantically equivalent.

> +#define FILE_UNCHANGED 0
> +#define FILE_CHANGED 1

FILE_UNCHANGED is unsed, and FILE_CHANGED is barely used, either.
You could use a bool, I think.  Maybe print it via (int) changed,
so that you don't run into type compatibility diagnostics with GCC.

> +struct

struct file_tracking?

> +{
> +  FILE *file;
> +  char *name;
> +  int fd;
> +  char *mfile;
> +} files[TEST_FILE_COUNT];
> +
> +static void
> +base_init (int file)
> +{
> +  files[file].file = NULL;
> +  files[file].fd = -1;
> +  files[file].name = NULL;
> +  files[file].mfile = NULL;
> +}

With the above:

  files[file] = (struct file_tracking) { .fd = -1, };

We use the trailing comma to indicate that the list of fields is not
exaustive.

(Just a suggestion, of course.)

> +
> +static void
> +file_init (int file)
> +{
> +  int fd = -1;
> +
> +  base_init (file);
> +
> +  if (file >= TEST_FILE_COUNT)
> +    return;
> +
> +  xclose (create_temp_file ("tst-fflush", &files[file].name));
> +
> +  fd = xopen (files[file].name, O_RDONLY, 0);
> +  files[file].mfile = (char *) xmmap (NULL, CONTENT_SZ_MAX, PROT_READ,
> +				      MAP_SHARED, fd);

The (char *) cast is not required.

> +#include <support/test-driver.c>
> diff --git a/libio/tst-fflush.c b/libio/tst-fflush.c
> new file mode 100644
> index 0000000000..66236cea17
> --- /dev/null
> +++ b/libio/tst-fflush.c
> @@ -0,0 +1,23 @@
> +/* Test that fflush (FILE) and fflush (NULL) are semantically equivalent.

Should mention this is the fflush (FILE) part.

Thanks,
Florian



More information about the Libc-alpha mailing list