summaryrefslogtreecommitdiff
path: root/tests/stdio_test.cpp
AgeCommit message (Collapse)Author
2021-04-12Switch to libbase SilentDeathTest.Elliott Hughes
Bug: http://b/184955378 Test: treehugger Change-Id: Ie0849224074da92203340a741a86a24a4a3702c2
2021-02-18Fix some bionic death tests.Elliott Hughes
These were creating tombstones and spewing to the log. You need TEST_F() rather than TEST(), and the modern style is apparently to use `using` rather than an empty subclass. Bug: http://b/180605583 Test: run tests, check logcat Change-Id: I1e639d34854aeff6f042c24643b769a6bcfab877
2021-02-04Fix freopen() where the path is null.Elliott Hughes
This has been in the standard since C99, but we've never supported it before. It's apparently used by SPIRV-Tools. I tried implementing this the other way (with fcntl(2)) first, but eventually realized that that's more complicated and gives worse results. This implementation assumes that /proc is mounted, but so much of libc relies on that at this point that I don't think there's any realistic case where the fcntl(2) implementation would be preferable, and there are many where it's not. The fact that no-one's mentioned this until now suggests that it's not a heavily used feature anyway. I've also replaced AssertCloseOnExec() with a CloseOnExec() boolean-valued function instead, because it's really annoying getting assertion failures that don't point you at the test line in question, and instead point to some common helper code. Test: treehugger Change-Id: Ia2e53bf2664a4f782581042054ecd492830e2aed
2020-12-08Simplify and improve tempnam() and tmpnam().Elliott Hughes
They're both obsolescent in POSIX.1-2008, and you really shouldn't be using them, but since we can't actually delete them... This change makes them both obey $TMPDIR if set, and fall back to /data/local/tmp otherwise. That's as good as we've managed for anything else such as tmpfile(3). Also add some tests. Bug: http://b/174682340 Test: treehugger Change-Id: Ieef99dcc2062f84b2b7cbae046787fdfe975e772
2020-08-12Various coverage improvements.Elliott Hughes
Mostly from extra test cases, but also: * Move the fgets size < 0 assertion into fgets. * Use ELF aliases for strtoq/strtouq rather than duplicating code. * Don't check uname() succeeded, since it can't fail. Test: treehugger Change-Id: I2e6b3b88b0a3eb16bd68be68b9bc9f40d8043291
2020-06-11Update upstream OpenBSD gdtoa.Elliott Hughes
Also add a test for the bug that this fixes. Bug: http://b/152588929 Test: treehugger Change-Id: I58055b3ebaef457721bb4f5d8a8710025122b2e7
2020-01-07Explicitly test printf %s with nullptr.Elliott Hughes
I haven't found a bug, but tests are good. Bug: https://github.com/landley/toybox/issues/163 Change-Id: I57149800099abc699cc841b69a5a72aeac7c2bcc
2019-08-02Add renameat2.Elliott Hughes
Bug: http://b/127675384 Test: new tests Change-Id: Ia2e3d5679180391ca98e62fa429fa11cbf167507
2019-05-07Add SEEK_DATA and SEEK_HOLE constants.Elliott Hughes
Without pulling in <linux/fs.h>, the UAPI source of these constants, because it's full of pollution, in particular a macro called BLOCK_SIZE that breaks a lot of stuff. Test: treehugger Change-Id: I7258ec57e91c67645c2b4d0ce44850d757c4bb12
2019-05-04Revert fwalk/sfp locking to fix concurrent readsRyan Prichard
The locking can fail in a couple of ways: - A concurrent fread from an unbuffered or line-buffered file flushes the output of other line-buffered files, and if _fwalk locks every file, then the fread blocks until other file reads have completed. - __sfp can initialize a file lock while _fwalk is locking/unlocking it. For now, revert to the behavior Bionic had in previous releases. This commit reverts the file locking parts of commit 468efc80da2504f4ae7de8b5e137426d44dda9d7. Bug: http://b/131251441 Bug: http://b/130189834 Test: bionic unit tests Change-Id: I9e20b9cd8ccd14e7962f7308e174f08af72b56c6
2019-03-12bionic tests: use GTEST_SKIP.Elliott Hughes
Also be a bit more to the point in our messages, focusing on "why" not "what". Test: ran tests Change-Id: I297806c7a102bd52602dcd2fcf7a2cd34aba3a11
2019-02-05Avoid writing to a zero-capacity buffer.Elliott Hughes
Bug: http://b/120752721 Test: ran tests Change-Id: I3f03ae204ab5de40fd4402a5562c50ffe51ef998
2018-12-11Fix cert-dcl16-c clang-tidy warnings in tests.Chih-Hung Hsieh
Bug: 120614316 Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,cert-dcl16-c Change-Id: I2606dc4cdfff9c2691ed60d529971e16adb3a9ae
2018-11-13bionic tests: switch to using android-base/file.h for TemporaryFileMark Salyzyn
A matching definition of TemporaryFile exists in libbase now. Test: compile Bug: 119313545 Change-Id: I6f84dbf3af9a9c4b270a2532a36c9cb4c0f6bb8f
2018-09-06Use strerror_r(3) for the printf family %m.Elliott Hughes
There's TLS space used for unknown errno values, and a call to printf shouldn't clobber that. No-one will ever hit this in real life, but since it's easily fixed... Bug: http://b/112776560 Test: ran tests Change-Id: I8c2437f2e5214e652119791d4e162a197b049d5b
2018-08-30Add the %m GNU extension to printf/wprintf.Elliott Hughes
And remove the local hack from syslog(3). Bug: http://b/112776560 Test: ran tests Change-Id: I5807e729a978df26187ea0ee255bba4ca74220c8
2018-08-23Fix uses of readlink in tests.Christopher Ferris
readlink does not append a terminator, and a few tests assumed it did. Test: Unit tests pass. Change-Id: I3ccea4e7895cd919b45e1ca0c90aa6f0031de320
2018-08-22Test that /dev/stdin, /dev/stdout, and /dev/stderr are all present.Elliott Hughes
Bug: http://b/31824379 Test: ran tests Change-Id: I16034106eb61b9f32c9afef512c75f0b73c179b5
2018-08-02Modernize codebase by replacing NULL with nullptrYi Kong
Fixes -Wzero-as-null-pointer-constant warning. Test: m Bug: 68236239 Change-Id: I5b4123bc6709641315120a191e36cc57541349b2
2018-07-19Introduce api to track fd ownership in libc.Josh Gao
Add two functions to allow objects that own a file descriptor to enforce that only they can close their file descriptor. Use them in FILE* and DIR*. Bug: http://b/110100358 Test: bionic_unit_tests Test: aosp/master boots without errors Test: treehugger Change-Id: Iecd6e8b26c62217271e0822dc3d2d7888b091a45
2018-07-11Reimplement popen(3)/pclose(3).Elliott Hughes
pclose(3) is now an alias for fclose(3). We could add a FORTIFY check that you use pclose(3) if and only if you used popen(3), but there seems little value to that when we can just do the right thing. This patch also adds the missing locking to _fwalk --- we need to lock both the global list of FILE*s and also each FILE* we touch. POSIX says that "The popen() function shall ensure that any streams from previous popen() calls that remain open in the parent process are closed in the new child process", which we implement via _fwalk(fclose) in the child, but we might want to just make *all* popen(3) file descriptors O_CLOEXEC in all cases. Ignore fewer errors in popen(3) failure cases. Improve popen(3) test coverage. Bug: http://b/72470344 Test: ran tests Change-Id: Ic937594bf28ec88b375f7e5825b9c05f500af438
2018-03-07Call __fortify_fatal if printf sees %n.Elliott Hughes
We've ignored %n for a long time, but that's dangerous too because it makes it unclear whether the corresponding pointer argument should be supplied or not. Remove the ambiguity by just rejecting %n outright. Bug: http://b/31832608 Test: ran tests Change-Id: Ic046ad3436a30c6f8f580ea738bdcaeb01c858f8
2018-01-19Support %mc/%ms/%m[ in sscanf.Elliott Hughes
Also support the "long" (wchar_t) variants. Bug: http://b/68672236 Test: ran tests Change-Id: I060e98b4d2feb61e12986d9d51e4710b2b1d9724
2017-12-15A few more trivial tests.Elliott Hughes
Based on gaps in the list of functions not referenced by the test executable. Bug: N/A Test: ran tests Change-Id: I73c238e7cf360f94670c7cd13eb954341c940b7b
2017-12-12More scanf cleanup.Elliott Hughes
Merge CT_CCL and CT_STRING handling before we add %m. Also fix an accidental scanf/wscanf difference. Add currently-disabled tests for questionable behavior noticed during code review that isn't a regression, but should be fixed later. Bug: http://b/68672236 Bug: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=202240 Test: ran tests Change-Id: I3eec9b7dfce84f63c68426406224822c52551d64
2017-12-07Add sscanf %[ tests and fix the bug that fell out.Elliott Hughes
Strictly, POSIX says "If a '-' is in the scanlist and is not the first wide character, nor the second where the first wide character is a '^', nor the last wide character, the behavior is implementation-defined", but it seems unreasonable for swscanf to interpret `a-c` differently from sscanf. Make ours behave the same as each other by making swscanf work the same as sscanf. Bug: http://b/68672236 Test: ran tests Change-Id: Ia84805897628d7128e901b468e02504373730e61
2017-11-07Allow 32-bit fseeko/fseeko64 SEEK_CUR/SEEK_SET to exceed 2 GiBRyan Prichard
Bug: http://b/68837650 Test: /data/nativetest/bionic-unit-tests/bionic-unit-tests Test: /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static Test: /data/nativetest64/bionic-unit-tests/bionic-unit-tests Change-Id: I367e0238c31d35f76d8ad89fd0aa27ecfeb7c149
2017-11-02More printf de-duplication.Elliott Hughes
Fix the 'j' (intmax_t/uintmax_t) length qualifier in the wide variant. (With new tests that fail without this fix.) Fix a typo in the wide support for intmax_t*, which isn't testable because %n is disabled on Android (and will be removed in a later cleanup pass). Also move the public vfprintf/vfwprint functions into stdio.cpp. Bug: http://b/67371539 Test: ran tests Change-Id: Ib003599b1e9cb789044a068940b59e447f2cb7cb
2017-11-01Start de-duplicating the regular and wide printf implementations.Elliott Hughes
This patch switches to C++ (in anticipation of needing it later), removes a little duplication (via a macro for now), and ensures uniform support for %C/%lc and %S/%ls between regular and wide (with new tests). Since it's so hard to debug problems in printf (as the time I've wasted already today will testify), that's all I want to do in this change. The other 500 lines of diff can wait... (Also merge "floatio.h" into "local.h" now all the users are in forked code.) Bug: http://b/67371539 Test: ran tests Change-Id: I083353d89c32b9302d759ca6967cc6d8a62cd8a5
2017-10-31More missing _unlocked <stdio.h> functions.Elliott Hughes
Also simplify trivial one-liners like perror/puts/fputs, and clean up fread/fwrite slightly. Fix perror to match POSIX. Add basic perror and *_unlocked tests. Bug: N/A Test: ran tests Change-Id: I63f83c8e0c15c3c4096509d17421ac331b6fc23d
2017-08-09Expand swprintf tests.Dan Albert
Test: bionic unit tests Bug: None Change-Id: I36924c4bdd2fa2c25e50ef7fef5500a365721a05
2017-07-31Clean up some <stdio.h> constants.Elliott Hughes
And actually test an assertion rather than just state it in a comment. Bug: N/A Test: ran tests Change-Id: I07699483aca4aac4e089d8b99123cb5bde9b3c63
2017-07-25Use O_APPEND for stdio append mode.Elliott Hughes
"Although not explicitly required by this volume of POSIX.1-2008, a good implementation of append (a) mode would cause the O_APPEND flag to be set." Yeah, about that... Bug: N/A Test: ran tests Change-Id: I23c4bc5c1ebc92e0cb44025d2d313f321f9ffa68
2017-07-24Replace fmemopen.Elliott Hughes
A new implementation starting from the FreeBSD fmemopen rather than the OpenBSD one we used to use. The tests were arrived at by translating each sentence in http://pubs.opengroup.org/onlinepubs/9699919799/functions/fmemopen.html, plus http://man7.org/linux/man-pages/man3/fmemopen.3.html for historical GNU bugs. Bug: http://b/31304889 Test: ran tests Change-Id: Id8b168c9ecde638e9cdedbc3b8a0982fc83c7048
2017-01-11Improve fmemopen tests.Josh Gao
Tag fmemopen_NULL as a known failure, and make it reliably fail by memsetting the buffer we read to. Bug: http://b/33251022 Test: bionic-unit-tests/bionic-unit-tests64 on bullhead Test: bionic-unit-tests-glibc --gtest_filter="*memopen*" Change-Id: I381783282359851c9de47146dafbb5a291960c2a
2016-09-15Fix instances of '#if __LP64__'.Josh Gao
Triggers -Wundef, which is on in -Weverything. Bug: http://b/31496165 Change-Id: Ib06107073f7dd1d584c19c222d0430da9d35630b
2016-09-07Fix sscanf/wcstod parsing of NaNs.Elliott Hughes
The parsefloat routines -- which let us pass NaNs and infinities on to strto(f|d|ld) -- come from NetBSD. Also fix LP64's strtold to return a NaN, and fix all the architectures to return quiet NaNs. Also fix wcstof/wcstod/wcstold to use parsefloat so they support hex floats. Lots of new tests. Bug: http://b/31101647 Change-Id: Id7d46ac2d8acb8770b5e8c445e87cfabfde6f111
2016-08-10Fortify vsnprintf in more cases.Elliott Hughes
Bug: http://b/30445072 Change-Id: I1893890f0e3b56533eef053eda1bd96a0b9a5119
2016-08-05Reimplement remove(3) without the lstat(2).Elliott Hughes
This assumes that it's more likely we're unlinking a file than a directory, though even if that's not true, as long as a failed unlink(2) is cheaper than a successful lstat(2) -- which seems likely since there's no data to copy -- we still win. Change-Id: I0210e9cd3d31b8cf1813c55c810262ef327382ed
2016-08-01More stdio one-liners.Elliott Hughes
This actually turns up a bug in fmemopen, so I guess that's what I'll look at next... Change-Id: I2971ecd1b5a3a3c7f43c22d985f88e389af89e97
2016-06-09Add ctermid.Elliott Hughes
Change-Id: I7c7c815c2725df222932db923632c8b6419741ab
2016-02-05Add a test for a possible overflow in *printf.Elliott Hughes
It turns out we don't have any bugs here, but glibc does. Found while chasing down a toybox failure I saw on the host, but we may as well add the test in case we ever screw up here in future. Change-Id: Ib8dd227ed3b742dc4dab8c09dc08e6ea9a35c807
2016-02-05Add a test for snprintf on a PTHREAD_STACK_MIN-sized stack.Elliott Hughes
This is a common thing for people to want to do, snprintf requires a lot of stack for itself, and PTHREAD_STACK_MIN should be usable for realistic code. Change-Id: Ib09cfb4e0beec1c69ee0944c3ea4c5d03a94c491
2016-02-03Add fopen64/freopen64/tmpfile64 aliases.Elliott Hughes
Our fopen/freopen/tmpfile are already always O_LARGEFILE, but let's add the aliases for _LARGEFILE_SOURCE compatibility. Bug: http://b/24807045 Change-Id: I5d99b3ef3c9f27ce70f13313f6a92e96c7f21f80
2016-02-02Expose ftello64.Elliott Hughes
Also add the missing test that would have caught this. Bug: http://b/24807045 Change-Id: I756a4d825595b52396b15898e3f717156fd1ba2f
2016-01-26Fix a sign extension bug in stdio.Elliott Hughes
This also lets us test the EOVERFLOW behavior, which pointed out that the fgetpos/fsetpos return on failure has always been wrong... Bug: http://b/24807045 Change-Id: I35273eb07c8c9155af858adb27569983397580b6
2016-01-26Implement funopen64.Elliott Hughes
Bug: http://b/24807045 Change-Id: I161920978161389be34b707cc6ce8e05f760d552
2016-01-26Support _FILE_OFFSET_BITS=64 for most of <stdio.h>.Elliott Hughes
This doesn't address funopen, but does add fgetpos/fsetpos/fseeko/ftello. Bug: http://b/24807045 Change-Id: Ibff6f00df5fb699c8e8f13b91a75caf024540b73
2016-01-22Add another stdio test.Elliott Hughes
This test didn't catch anything, but it does ensure that we exercise the "lots of files" case. Bug: http://b/26747402 Change-Id: I6c51c6436029572a49190d509f131eb93b808652
2016-01-21Simplify fseek/ftell.Elliott Hughes
Another step towards _FILE_OFFSET_BITS=64 support. Bug: http://b/24807045 Change-Id: I00b83c81a7b108176c4d9437bc32611f73b7e967