summaryrefslogtreecommitdiff
path: root/libc/test/src/stdio
AgeCommit message (Collapse)Author
2025-11-18[libc] Fix -Wshorten-64-to-32 in fileop_test. (#168451)Alexey Samsonov
Explicitly cast 0 to size_t type to match fread() return type. This follows the pattern used elsewhere in this file, and fixes -Wshorten-64-to-32 warnings when building the test.
2025-11-05[libc] Add printf error handling (with fixes #2) (#166517)Marcell Leleszi
https://github.com/llvm/llvm-project/issues/159474 Another try of trying to land https://github.com/llvm/llvm-project/pull/166382 - Fix some leftover tests checking for specific errnos - Guard errno checking tests to not run on the GPU @michaelrj-google
2025-11-04Revert commit d8e5698 and 15b19c7 (#166498)Kewen Meng
2025-11-05[libc] Fix fprintf_test assuming specific errnos. (#166479)Michael Jones
The patch #166382 fixed most of these, but missed the fprintf_test ones.
2025-11-04[libc] Fix printf long double bugs (#166474)Michael Jones
Found in testing against abseil. Two bugs were found: 1) SHIFT_AMOUNT in float_converter<long double> would sometimes be negative causing an underflow when passed as the amount to left shift by for BigInt. 2) is_lowest_block had an off-by-one because it was adding 1 to the block index. Both are fixed and there are new tests to catch regressions.
2025-11-04[libc] Add printf error handling (with fixes) (#166382)Marcell Leleszi
https://github.com/llvm/llvm-project/issues/159474 Resubmitting https://github.com/llvm/llvm-project/pull/162876 with fixes as it broke some buildbots: - Fix comparisons of integer expressions of different signedness - Not check for specific errnos in tests, as they might not be available on all platforms
2025-11-03Revert "[libc] Add printf error handling" (#166232)Kewen Meng
2025-11-03[libc] Add printf error handling (#162876)Marcell Leleszi
[#159474](https://github.com/llvm/llvm-project/issues/159474) - All printf variants set errno and consistently return -1 on error, instead of returning various predefined error codes - Return value overflow handling is added
2025-10-22Revert "[libc] Add -Werror for libc tests" (#164684)lntue
Reverts llvm/llvm-project#160413
2025-10-22[libc] Add -Werror for libc tests (#160413)Vinay Deshmukh
Relates to https://github.com/llvm/llvm-project/issues/119281 Note: 1) As this PR enables `-Werror` for `libc` tests, it's very likely some downstream CI's may fail / start failing, so it's very likely this PR may need to be reverted and re-applied. P.S. I do not have merge permissions, so I will need one of the reviews to merge it for me. Thank you!
2025-09-18[libc][bazel] Add (v)asprintf targets and tests (#159476)Michael Jones
2025-09-05[libc] Use anonymous namespace for test helper code (#157203)Roland McGrath
Tests can be at top-level or inside an anonymous namespace, doesn't matter. But putting their helper code inside anonymous namespaces both makes the code compatible with compiling using -Wmissing-declarations and might let the compiler optimize the test good a bit better.
2025-07-21[libc][stdio] Separate temporary files for unit test and hermetic test in ↵lntue
stdio test suite. (#149740)
2025-06-17Fix/reapply "[libc] Migrate stdio tests to ErrnoCheckingTest. (#144134)Alexey Samsonov
This reverts commit 92a116c4ef822950f8c57eaa5164c844c73a1f7e with a fix for fgets test - convert nullptr to fgets return type (char*), since the matcher is pedantic.
2025-06-13Revert "Fix/reapply "[libc] Migrate stdio tests to ErrnoCheckingTest."" ↵Alexey Samsonov
(#144129) Reverts llvm/llvm-project#143972 - matcher seems to be pedantic for fgets tests, reverting to verify and fix.
2025-06-13[libc] Fix bugs found when testing with all headers (#144049)William Huynh
Fixes a couple of bugs found when building. The PR to enable the headers can be found here: #144114. - math.yaml: float128 guard - wchar.yaml: __restrict keyword order
2025-06-13Fix/reapply "[libc] Migrate stdio tests to ErrnoCheckingTest." (#143972)Alexey Samsonov
This reverts commit a93e55e57ed00a55f822c64e3520c7c732b58480 and fixes build and test failures: * Proper include added to setvbuf_test.cpp * fgetc/fgetc_unlocked/fgets tests are ported to ErrnoSetterMatcher and are made more precise. This fixes inconsistencies between expectations in regular and GPU builds - ErrnoSetterMatcher is configured to omit errno matching on GPUs, as fgetc implementation on GPU doesn't set errno, in contrast to Linux.
2025-06-12[libc] Implement perror (#143624)Michael Jones
The perror function writes an error message directly to stderr. This patch adds an implementation, tests, and header generation details.
2025-06-11Revert "[libc] Migrate stdio tests to ErrnoCheckingTest." (#143829)Alexey Samsonov
Reverts llvm/llvm-project#143802. Follow-up fix 3c7af175e51c3ab08ac3c442146c2b822f38c01e wasn't robust enough and itself got reverted.
2025-06-11Revert "[libc] Fix stdio tests after #143802" (#143824)Kewen12
Reverts llvm/llvm-project#143810 This PR breaks our buildbot: https://lab.llvm.org/buildbot/#/builders/10/builds/7159 revert to unblock downstream merge.
2025-06-11[libc] Fix stdio tests after #143802 (#143810)Michael Jones
In #143802 the stdio test cleanup missed a few places where errno was being set to a failing value, and one where the framework needed to included.
2025-06-11[libc] Migrate stdio tests to ErrnoCheckingTest. (#143802)Alexey Samsonov
Reduce the direct use of libc_errno in stdio unit tests by adopting ErrnoCheckingTest where appropriate. Also removes the libc_errno.h inclusions from stdlib.h tests that were accidentally added in d87eea35fac5a34a841c637db8908128409a184e
2025-06-11[libc] Move libc_errno.h to libc/src/__support and make ↵lntue
LIBC_ERRNO_MODE_SYSTEM to be header-only. (#143187) This is the first step in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
2025-03-17[libc] Templatize the scanf Reader interface (#131037)Petr Hosek
This allows specializing the implementation for different targets without including unnecessary logic and is similar to #111559 which did the same for printf Writer interface.
2025-03-14[libc] Fix implicit conversion warnings in tests. (#131362)lntue
2025-03-12[libc] Template the writing mode for the writer class (#111559)Joseph Huber
Summary: Currently we dispatch the writing mode off of a runtime enum passed in by the constructor. This causes very unfortunate codegen for the GPU targets where we get worst-case codegen because of the unused function pointer for `sprintf`. Instead, this patch moves all of this to a template so it can be masked out. This results in no dynamic stack and uses 60 VGPRs instead of 117. It also compiles about 5x as fast.
2025-03-10[libc] Add `-Wno-sign-conversion` & re-attempt `-Wconversion` (#129811)Vinay Deshmukh
Relates to https://github.com/llvm/llvm-project/issues/119281#issuecomment-2699470459
2025-03-05Revert "[libc] Enable -Wconversion for tests. (#127523)"Augie Fackler
This reverts commit 1e6e845d49a336e9da7ca6c576ec45c0b419b5f6 because it changed the 1st parameter of adjust() to be unsigned, but libc itself calls adjust() with a negative argument in align_backward() in op_generic.h.
2025-03-04[libc] Enable -Wconversion for tests. (#127523)Vinay Deshmukh
Relates to: #119281
2025-02-22[libc] Fix scanf dependencies on the GPU buildJoseph Huber
Summary: The GPU build doesn't have `file` as a struct but does use these targets. We need to add an escape for this.
2025-02-21[libc] Skip scanf internals when no file available (#128097)Michael Jones
A temporary fix based on discussions in #128079 Currently, baremetal targets are failing to build because the scanf internals require FILE* (either from the system's libc or our libc). Normally we'd just turn off the broken entrypoint, but since the scanf internals are built separately that doesn't work. This patch adds extra conditions to building those internals, which we can hopefully remove once we have a proper way to build scanf for embedded.
2025-02-20[libc] Fix scanf cmake for targets without FILE (#128056)Michael Jones
Another followup fix to #121215 The new cmake wouldn't define the readerat all if the target wasn't GPU or didn't have a definition of FILE. This patch rewrites the cmake to be more general. As a followup, I'd like to make `use_system_file` consistent between /test and /src. Currently in /src it includes the `COMPILE_OPTIONS` and in /test it does not.
2025-02-06[libc][minor] Fix assertion in LlvmLibcFILETest.SimpleFileOperations (#126109)Alan Zhao
The file descriptor of the first opened file is not necessarily 3, so we change the assertion so that it's >= 0 (i.e. not an error.) Fixes #126106
2025-02-04[libc] Alternative algorithm for decimal FP printf (#123643)Simon Tatham
The existing options for bin→dec float conversion are all based on the Ryū algorithm, which generates 9 output digits at a time using a table lookup. For users who can't afford the space cost of the table, the table-lookup subroutine is replaced with one that computes the needed table entry on demand, but the algorithm is otherwise unmodified. The performance problem with computing table entries on demand is that now you need to calculate a power of 10 for each 9 digits you output. But if you're calculating a custom power of 10 anyway, it's easier to just compute one, and multiply the _whole_ mantissa by it. This patch adds a header file alongside `float_dec_converter.h`, which replaces the whole Ryū system instead of just the table-lookup routine, implementing this alternative simpler algorithm. The result is accurate enough to satisfy (minimally) the accuracy demands of IEEE 754-2019 even in 128-bit long double. The new float128 test cases demonstrate this by testing the cases closest to the 39-digit rounding boundary. In my tests of generating 39 output digits (the maximum number supported by this algorithm) this code is also both faster and smaller than the USE_DYADIC_FLOAT version of the existing Ryū code.
2024-11-11[libc] Clean up skipped and failing cmake (#115400)Michael Jones
I normally run my cmake with LIBC_CMAKE_VERBOSE_LOGGING set to ON so I can debug build issues more easily. One of the effects of this is I see which tests/entrypoints are skipped on my machine. This patch fixes up the tests and entrypoints that were skipped, but easily fixed. These were: libc.src.pthread.pthread_spin_destroy libc.src.pthread.pthread_spin_init libc.src.pthread.pthread_spin_lock libc.src.pthread.pthread_spin_trylock libc.src.pthread.pthread_spin_unlock (entrypoints were just missing) libc.src.wchar.btowc (I forgot to finish it) libc.test.src.sys.statvfs.linux.statvfs_test libc.test.src.sys.statvfs.linux.fstatvfs_test (Incorrect includes for rmdir, needed some cleanup) libc.test.integration.src.unistd.execve_test (wrong dep for errno) libc.test.src.math.smoke.fmaf_test (add_fp_unittest doesn't support flags) libc.test.src.stdio.scanf_core.converter_test (needed to be moved away from string_reader, further cleanup needed)
2024-11-01[libc] Remove the #include <stdlib.h> header (#114453)Job Henandez Lara
2024-10-18[libc] Scanf shouldn't match just "0x" for hex int (#112440)Michael Jones
Scanf parsing reads the longest possibly valid prefix for a given conversion. Then, it performs the conversion on that string. In the case of "0xZ" with a hex conversion (either "%x" or "%i") the longest possibly valid prefix is "0x", which makes it the "input item" (per the standard). The sequence "0x" is not a "matching sequence" for a hex conversion, meaning it results in a matching failure, and parsing ends. This is because to know that there's no valid digit after "0x" it reads the 'Z', but it can only put back one character (the 'Z') leaving it with consuming an invalid sequence. (inspired by a thread on the libc-coord mailing list: https://www.openwall.com/lists/libc-coord/2024/10/15/1, see 7.32.6.2 in the standard for more details.)
2024-10-02[libc] Enable dyadic float for float printf (#110765)Michael Jones
Dyadic floats were an existing option for float to string conversion, but it had become stale. This patch fixes it up as well as adding proper config options and test support. Due to the test changes this is a followup to #110759
2024-10-01[libc] clean up sprintf macros and float tests (#110759)Michael Jones
The sprintf tests have a macro named "ASSERT_STREQ_LEN" which was used in about half of the tests. This patch moves all of the tests which can to using that macro. This patch also enables long double tests for %e and %g, since those never got finished. There's still some work to do enabling long double testing for long doubles other than the intel 80 bit format, but that can land in a followup. The `#ifdef LIBC_COPT_FLOAT_TO_STR_REDUCED_PRECISION` lines are for a followup patch.
2024-10-01[libc][stdio] Use proxy headers of stdio.h in src and test folders. (#110067)lntue
https://github.com/llvm/llvm-project/issues/60481
2024-10-01[libc] Fix race conditions in sprintf_test. (#110624)lntue
2024-09-26[libc] Fix 'fgets' test on the GPU for some C libraries (#110118)Joseph Huber
Summary: The GPU handling for a lot of `FILE *` functions pretty much just forwards it to the host via RPC. This test checks for implementation defined behavior, which sometimes passes and sometimes doesn't. We just disable it here so it works on the standard semantics. We do this forwarding primarily for interopt w/ the host if the user is compiling from an offloading language (e.g. CUDA).
2024-09-19[libc] Add printf strerror conversion (%m) (#105891)Michael Jones
This patch adds the %m conversion to printf, which prints the strerror(errno). Explanation of why is below, this patch also updates the docs, tests, and build system to accomodate this. The standard for syslog in posix specifies it uses the same format as printf, but adds %m which prints the error message string for the current value of errno. For ease of implementation, it's standard practice for libc implementers to just add %m to printf instead of creating a separate parser for syslog.
2024-08-28[libc] Disable failing scanf test on AMDGPU temporarilyJoseph Huber
Summary: This test currently fails in the `amdgpu-attributor` pass. I haven't figured out anything beyond that yet as it's difficult to reduce.
2024-08-26[libc] Fix file collision causing test flake (#106119)Michael Jones
In patch #105293 tests for vfscanf were added, meant to be identical to the fscanf tests. Unfortunately, the author forgot to rename the target file causing an occasional test flake where one test writes to the file while the other is trying to read it. This patch fixes the issue by renaming the target test file for the vfscanf test.
2024-08-26[libc] Implement 'vfscanf' and 'vscanf' (#105293)Joseph Huber
Summary: These are simply forwarding the vlist to the existing helper.
2024-08-02[libc] Fix printf handling of INT_MIN width (#101729)Michael Jones
Prevously, if INT_MIN was passed as a wildcard width to a printf conversion the parser would attempt to negate it to get the positive width (and set the left justify flag), but it would underflow and the width would be treated as 0. This patch corrects the issue by instead treating a width of INT_MIN as identical to -INT_MAX. Also includes docs changes to explain this behavior and adding b to the list of int conversions.
2024-08-01[libc] Implement vasprintf and asprintf (#98824)Tsz Chan
[libc] Implement vasprintf and asprintf --------- Co-authored-by: Izaak Schroeder <izaak.schroeder@gmail.com>
2024-07-31[libc] Add vsscanf function (#101402)Joseph Huber
Summary: Adds support for the `vsscanf` function similar to `sscanf`. Based off of https://github.com/llvm/llvm-project/pull/97529.
2024-07-24[libc] Enable 'sscanf' on the GPU #100211Joseph Huber
Summary: We can enable the sscanf function on the GPU now. This required adding the configs to the scanf list so that the GPU build didn't do float conversions.