glibc/glibc-upstream-2.39-124.patch
Arjun Shankar 2a30b8f4b2 Sync with upstream branch release/2.39/master
Upstream commit: dcaf51b41e259387602774829c45222d0507f90a

- elf: Change ldconfig auxcache magic number (bug 32231)
- Make tst-strtod-underflow type-generic
- Add crt1-2.0.o for glibc 2.0 compatibility tests
- Add tests of more strtod special cases
- Add more tests of strtod end pointer
- Make tst-strtod2 and tst-strtod5 type-generic
- powerpc64le: Build new strtod tests with long double ABI flags (bug 32145)
- Do not set errno for overflowing NaN payload in strtod/nan (bug 32045)
- Improve NaN payload testing
- Make __strtod_internal tests type-generic
- Fix strtod subnormal rounding (bug 30220)
- More thoroughly test underflow / errno in tst-strtod-round
- Test errno setting on strtod overflow in tst-strtod-round
- Add tests of fread
- stdio-common: Add new test for fdopen
- libio: Attempt wide backup free only for non-legacy code
- debug: Fix read error handling in pcprofiledump
- elf: Fix tst-dlopen-tlsreinit1.out test dependency
- elf: Avoid re-initializing already allocated TLS in dlopen (bug 31717)
- elf: Clarify and invert second argument of _dl_allocate_tls_init
- elf: Support recursive use of dynamic TLS in interposed malloc
- nptl: Use <support/check.h> facilities in tst-setuid3
- posix: Use <support/check.h> facilities in tst-truncate and tst-truncate64
- ungetc: Fix backup buffer leak on program exit [BZ #27821]
- ungetc: Fix uninitialized read when putting into unused streams [BZ #27821]
- Make tst-ungetc use libsupport
- stdio-common: Add test for vfscanf with matches longer than INT_MAX [BZ #27650]
- support: Add FAIL test failure helper
- string: strerror, strsignal cannot use buffer after dlmopen (bug 32026)
- Define __libc_initial for the static libc
- x86: Fix bug in strchrnul-evex512 [BZ #32078]
- Adjust check-local-headers test for libaudit 4.0
- x32/cet: Support shadow stack during startup for Linux 6.10
- x86-64: Remove sysdeps/x86_64/x32/dl-machine.h
- support: Add options list terminator to the test driver
- manual/stdio: Further clarify putc, putwc, getc, and getwc
- Fix name space violation in fortify wrappers (bug 32052)
- resolv: Fix tst-resolv-short-response for older GCC (bug 32042)
- Add mremap tests
- mremap: Update manual entry
- linux: Update the mremap C implementation [BZ #31968]
- Enhanced test coverage for strncmp, wcsncmp
- Enhance test coverage for strnlen, wcsnlen

Resolves: RHEL-57776
Resolves: RHEL-57777
Resolves: RHEL-61392
2024-11-20 17:12:17 +01:00

166 lines
4.8 KiB
Diff

commit d8b4fc3653ca08912a6dec57a3ba36a2db779488
Author: Joseph Myers <josmyers@redhat.com>
Date: Tue Sep 24 14:06:22 2024 +0000
Add tests of fread
There seem to be no glibc tests specifically for the fread function.
Add basic tests of that function.
Tested for x86_64.
(cherry picked from commit d14c977c65aac7db35bb59380ef99d6582c4f930)
diff --git a/stdio-common/Makefile b/stdio-common/Makefile
index 5f3bd4662340eee9..c822434293b7e809 100644
--- a/stdio-common/Makefile
+++ b/stdio-common/Makefile
@@ -216,6 +216,7 @@ tests := \
tst-fmemopen4 \
tst-fphex \
tst-fphex-wide \
+ tst-fread \
tst-fseek \
tst-fwrite \
tst-gets \
diff --git a/stdio-common/tst-fread.c b/stdio-common/tst-fread.c
new file mode 100644
index 0000000000000000..4d9a7895f66a7980
--- /dev/null
+++ b/stdio-common/tst-fread.c
@@ -0,0 +1,134 @@
+/* Test fread.
+ Copyright (C) 2024 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <support/check.h>
+#include <support/support.h>
+#include <support/temp_file.h>
+#include <support/test-driver.h>
+#include <support/xstdio.h>
+#include <support/xunistd.h>
+
+int
+do_test (void)
+{
+ char *temp_dir = support_create_temp_directory ("tst-fread");
+ char *file1 = xasprintf ("%s/file1", temp_dir);
+ support_write_file_string (file1, "file1");
+ add_temp_file (file1);
+ FILE *fp;
+ size_t ret;
+ char buf[1024];
+
+ verbose_printf ("test single-byte reads\n");
+ fp = xfopen (file1, "r");
+ memset (buf, 0, sizeof buf);
+ ret = fread (buf, 1, 2, fp);
+ TEST_COMPARE (ret, 2);
+ TEST_COMPARE (buf[0], 'f');
+ TEST_COMPARE (buf[1], 'i');
+ TEST_COMPARE (feof (fp), 0);
+ TEST_COMPARE (ftell (fp), 2);
+ memset (buf, 0, sizeof buf);
+ ret = fread (buf, 1, 3, fp);
+ TEST_COMPARE (ret, 3);
+ TEST_COMPARE (buf[0], 'l');
+ TEST_COMPARE (buf[1], 'e');
+ TEST_COMPARE (buf[2], '1');
+ TEST_COMPARE (ftell (fp), 5);
+ TEST_COMPARE (feof (fp), 0);
+ memset (buf, 0, sizeof buf);
+ ret = fread (buf, 1, 1, fp);
+ TEST_COMPARE (ret, 0);
+ TEST_COMPARE (!!feof (fp), 1);
+ TEST_COMPARE (ferror (fp), 0);
+ TEST_COMPARE (ftell (fp), 5);
+ xfclose (fp);
+
+ verbose_printf ("test single-byte reads, EOF part way through\n");
+ fp = xfopen (file1, "r");
+ memset (buf, 0, sizeof buf);
+ ret = fread (buf, 1, sizeof buf, fp);
+ TEST_COMPARE (ret, 5);
+ TEST_COMPARE (buf[0], 'f');
+ TEST_COMPARE (buf[1], 'i');
+ TEST_COMPARE (buf[2], 'l');
+ TEST_COMPARE (buf[3], 'e');
+ TEST_COMPARE (buf[4], '1');
+ TEST_COMPARE (!!feof (fp), 1);
+ TEST_COMPARE (ferror (fp), 0);
+ TEST_COMPARE (ftell (fp), 5);
+ xfclose (fp);
+
+ verbose_printf ("test multi-byte reads\n");
+ fp = xfopen (file1, "r");
+ memset (buf, 0, sizeof buf);
+ ret = fread (buf, 2, 2, fp);
+ TEST_COMPARE (ret, 2);
+ TEST_COMPARE (buf[0], 'f');
+ TEST_COMPARE (buf[1], 'i');
+ TEST_COMPARE (buf[2], 'l');
+ TEST_COMPARE (buf[3], 'e');
+ TEST_COMPARE (feof (fp), 0);
+ TEST_COMPARE (ftell (fp), 4);
+ memset (buf, 0, sizeof buf);
+ ret = fread (buf, 3, 3, fp);
+ TEST_COMPARE (ret, 0);
+ /* The bytes written for a partial element read are unspecified. */
+ TEST_COMPARE (!!feof (fp), 1);
+ TEST_COMPARE (ferror (fp), 0);
+ TEST_COMPARE (ftell (fp), 5);
+ xfclose (fp);
+
+ verbose_printf ("test read error\n");
+ fp = xfopen (file1, "r");
+ xclose (fileno (fp));
+ memset (buf, 0, sizeof buf);
+ ret = fread (buf, 1, sizeof buf, fp);
+ TEST_COMPARE (ret, 0);
+ TEST_COMPARE (feof (fp), 0);
+ TEST_COMPARE (!!ferror (fp), 1);
+ fclose (fp);
+
+ verbose_printf ("test zero size\n");
+ fp = xfopen (file1, "r");
+ ret = fread (buf, 0, SIZE_MAX, fp);
+ TEST_COMPARE (ret, 0);
+ TEST_COMPARE (feof (fp), 0);
+ TEST_COMPARE (ferror (fp), 0);
+ TEST_COMPARE (ftell (fp), 0);
+ xfclose (fp);
+
+ verbose_printf ("test zero items\n");
+ fp = xfopen (file1, "r");
+ ret = fread (buf, SIZE_MAX, 0, fp);
+ TEST_COMPARE (ret, 0);
+ TEST_COMPARE (feof (fp), 0);
+ TEST_COMPARE (ferror (fp), 0);
+ TEST_COMPARE (ftell (fp), 0);
+ xfclose (fp);
+
+ free (temp_dir);
+ free (file1);
+ return 0;
+}
+
+#include <support/test-driver.c>