summaryrefslogtreecommitdiff
path: root/tests/stdlib_test.cpp
AgeCommit message (Collapse)Author
2021-04-12Switch to libbase SilentDeathTest.Elliott Hughes
Bug: http://b/184955378 Test: treehugger Change-Id: Ie0849224074da92203340a741a86a24a4a3702c2
2021-03-08Improve system() coverage.Elliott Hughes
There's a weird POSIX special case that we implement but don't test. Found from looking through the coverage data. Test: treehugger Change-Id: I74f5f57c4d8062034a3f6e986f9e57091bfc7f7c
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-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-01-23Merge "Reimplement realpath."Elliott Hughes
2020-01-23Initialize __progname correctly.Elliott Hughes
setprogname() does a basename, but we were initializing __progname directly. Stop doing that, and add some tests. Test: treehugger Change-Id: I06f306ade4161b2f0c7e314a3b1b30c9420117b7
2020-01-22Reimplement realpath.Elliott Hughes
Use O_PATH like musl to let the kernel do the hard work, rather than the traditional BSD manual scheme. Also add the most obvious missing tests from reading the man page, plus a non-obvious test for deleted files. Bug: http://b/131435126 Test: treehugger Change-Id: Ie8a8986fea55f045952a81afee377ce8288a49d5
2019-03-01Make aligned_alloc match the standard.Christopher Ferris
Jemalloc does not verify that the size parameter is a multiple of alignment. Fix this since it only went into P. Fix the unit tests, and fix malloc debug/malloc hooks to handle this new restrictive behavior. Bug: 126944692 Test: Ran bionic unit tests. Test: Ran bionic unit tests with malloc hooks enabled (no new tests fail). Test: Ran bionic unit tests with malloc debug enabled (no new tests fail). Test: Ran malloc debug unit tests. Change-Id: I4d50785928815679c781ca729f998454d76b9192
2019-01-30Updates for glibc 2.17.Elliott Hughes
Bug: http://b/111358231 Test: builds Change-Id: I542b2a9acc74261ad12b78e4add0f3ae77c3656c
2018-12-18Make stdlib.getloadavg more resiliant.Elliott Hughes
Using rint(3) gave us a step where if one side was 1.4 and the other was 1.5, that would be 1 and 2 respectively. So instead use a simple difference. Also log more detail in case this doesn't fix the flakiness. Bug: http://b/121156651 Test: ran tests Change-Id: Ib5b2eb05d2b1eb8c4a10b182a8703510a3ef0cea
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-11-06Disable a few bionic tests under HWASan.Evgenii Stepanov
* HWASan report invalid use of the allocator api (like alignment not being power of two, or allocation size too large) in a way tests do not expect. * Code in .preinit_array runs before HWASan shadow is initialized and needs to be excluded from instrumentation. * It looks that mm system calls (mmap/mprotect/etc) will not allow tagged pointers. In fact, the use of mprotect on malloc()ed memory is doubtful - one can imagine some kind of speculative load from such memory, as compiler knows that it is addressable. Bug: 114279110 Test: bionic-unit-tests with hwasan Change-Id: I6ba4b46a0d554de77c923ad134cf156ce4ddba1b
2018-10-23Add getloadavg(3).Elliott Hughes
Lets us build ninja with bionic. Bug: N/A Test: ran tests Change-Id: I97eef1247d794b58a2b9aee4851551632e5a4e48
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-02-07Add aligned_alloc to libc.Christopher Ferris
Bug: 72969374 Test: Bionic unit tests pass. Test: Malloc debug unit tests pass. Change-Id: I235985bbc638855d94249c97c98f14ab2924bda0 (cherry picked from commit d69ee59594088c0d92ba9273188ef53ea5e6cd6a)
2017-12-21Simplify atoi*/strto* for signed integers.Elliott Hughes
Make the cost of strto<signed> closer to the cost of strto<unsigned> by removing an `if` from the inner loop. Previously a signed conversion cost 10ns more than an unsigned one. After: BM_inttypes_strtoimax 81 ns 81 ns 8603362 BM_inttypes_strtoumax 78 ns 78 ns 8967174 BM_stdlib_strtol 81 ns 81 ns 8685537 BM_stdlib_strtoll 81 ns 81 ns 8685481 BM_stdlib_strtoul 78 ns 78 ns 8962569 BM_stdlib_strtoull 78 ns 78 ns 8972023 Bug: N/A Test: ran tests, benchmarks Change-Id: I72dd5499427b6a940bd94c4d6f727f7efe134d7e
2017-12-19Use std::to_string instead of std::stringstream.Elliott Hughes
Bug: N/A Test: ran tests Change-Id: Ifeb7cf9517bcc05459e7ce316eb7604042510935
2017-12-19Refactor the ato* and strto* family.Elliott Hughes
There are no meaningful changes here, just a minimal conversion to two C++ templates to make further changes easier. Bug: N/A Test: ran tests, benchmarks Change-Id: I958fbf17a85f19dd8f17bfb4bbb9314d220daa3b
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-07A few new bionic tests.Aleksandra Tsvetkova
Trivial tests for <alloca.h> and <byteswap.h>, plus slightly improved test coverage for <inttypes.h> and <stdlib.h>. Bug: N/A Test: ran tests Change-Id: Idac4141ffc760c4f7756332477ce5112950d61a5 Signed-off-by: Aleksandra Tsvetkova <aleksandra.tsvetkova@intel.com>
2017-11-08Add trivial ttyname(3) test.Elliott Hughes
Bug: N/A Test: ran tests Change-Id: Id5bf51a9c50db0fdbc9df0225165e87e698d0c83
2017-09-07Trivial tests for <inttypes.h>/<stdlib.h> *abs and *div functions.Elliott Hughes
Because I want something to copy & paste into the NDK support library test that's slightly better than taking the address of the function... Bug: https://github.com/android-ndk/ndk/issues/502 Test: ran tests Change-Id: If43089d16691d6a4dcf5d972450b14ed85bbca81
2017-08-14libc fortify: error on realpath(NULL, foo)George Burgess IV
I've half a mind to make this a warning instead, since this sort of call isn't UB. That said: - if the user really wants this (I can't imagine why they would), they can just put NULL in a non-const variable, - we're slowly moving to -Werror ~everywhere anyway, and - it's presumably easier to change this from an error to a warning than the other way around Bug: 12231437 Test: m checkbuild on bullhead internal master. No new CtsBionicTestCases failures. Change-Id: Ie8bf5a3455f663686fda4a7450fb35d147fa745e
2017-07-13Apply recent strto* fix, add new tests.Elliott Hughes
The behavior with "0xy" was wrong: we'd swallow the 'x'. Bug: N/A Test: ran tests Change-Id: I2464d22a2408e99880303876306f18a25c390ad9
2017-06-15Update posix_memalign testing.Christopher Ferris
Move all tests into stdlib_test.cpp since that's where the definition lives in bionic. Add a sweep test and a various size test. Test: Run new unit tests on glibc and angler. Change-Id: Ief1301f402bea82ce90240500dd6a01636dbdbae
2016-12-02Fix wcsto* where strings begin with whitespace.Dan Albert
The libc++ tests caught this. Test: adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests Bug: None Change-Id: I14864e006f6cf9de3f96acac6aa3eb235894f2b1
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-04-28Implement mblen(3).Elliott Hughes
Change-Id: I65948ea5b9ecd63f966ba767ad6db4a2effc4700
2016-04-04Add POSIX getsubopt(3).Elliott Hughes
Bug: http://b/27952303 Change-Id: I8a816477545dadcbd5c055714e76263574446b6f
2016-01-26Factor out the waiting for children in bionic tests.Elliott Hughes
Change-Id: I4a1e51b6920b33dc892d447f5bd6d10f1cb2704a
2014-11-06Add POSIX lcong48.Elliott Hughes
Change-Id: I821046816661d77275cb02c8c99d526bb41afb9c
2014-11-06make all bionic death tests not dumpableYabin Cui
Bug: 18067305 Change-Id: Ia1ecacf47eddecc9bc58aaac779e0c218f463179
2014-10-28Extra strtod/strtof tests.Elliott Hughes
Check that libc doesn't suffer from a couple of bugs that affected Java in the past. Bug: 2206701 Change-Id: I9eb64d7ff2fa0b79e93079b897a5fb78bef866be
2014-09-30Update our FreeBSD realpath(3) to upstream head.Elliott Hughes
Change-Id: I8c89728184ecd2c1a28a05cefa84a5037d28b552
2014-09-23CLOEXEC support in fdopen, freopen, and mkostemp/mkostemps.Elliott Hughes
Change-Id: I74ea88e0d4973d6ab3c57da7d8bb643c31592b14
2014-09-23Pull in upstream fixes to reject invalid bases.Elliott Hughes
Also add tests to make sure the full set works correctly. Change-Id: I3e7f237f12c9c93e1185a97c9717803e7e55a73c
2014-07-25Fix linkage of grantpt(3).Elliott Hughes
Also clean up the implementation of all the pty functions, add tests, and fix the stub implementations of ttyname(3) and ttyname_r(3). Bug: https://code.google.com/p/android/issues/detail?id=58888 Change-Id: I0fb36438cd1abf8d4e87c29415f03db9ba13c3c2
2014-07-14Implement rand/srand in terms of random/srandom.Elliott Hughes
Code developed for glibc or older versions of bionic might expect more randomness than the BSD implementation provides. Bug: 15829381 Change-Id: Ia5a908a816e0a5f0639f514107a6384a51ec157e
2014-06-12Get the full set of PRNG functions in <stdlib.h>Elliott Hughes
Bug: https://code.google.com/p/android/issues/detail?id=58888 Change-Id: I435250bdae302e8bd7e29977d0fde7b9afbfca5e
2014-05-13Consistently use #if defined(__BIONIC__) in tests.Elliott Hughes
I've also switched some tests to be positive rather than negative, because !defined is slightly harder to reason about and there are only two cases: bionic and glibc. Change-Id: I8d3ac40420ca5aead3e88c69cf293f267273c8ef
2014-04-29Adds quick_exit(3) and at_quick_exit(3) from freebsdDan Albert
Change-Id: I4fe88abd8f7b8aa45e58aeb2529d59a8d555d338
2014-04-08Implement _Exit(3).Elliott Hughes
Change-Id: Ida6ac844cc87d38c9645b197dd8188bb73e27dbe
2014-03-17Use the float/double assert macros.Christopher Ferris
The normal ASSERT_EQ macros don't work quite right for float/double values, and result in false failures. Use the correct macros instead. Bug: 13511379 Change-Id: Ic2feee7f3d3569f57b6453b8fa95222846c625cd
2014-03-12Ensure we always have symbols for atof, strtof, strtold.Elliott Hughes
We'll need a better implementation of strtold for LP64, but all our long double functions are currently broken for LP64 anyway so this isn't a regression. Change-Id: I2bdebac11245d31521d5fa09a16331c03dc4339c
2014-03-12Include what you use.Elliott Hughes
Don't rely on transitive includes. (Even though that works fine in AOSP.) Change-Id: Ifc06575e4aea383cfff24d6c5c14fc0a7aabdf2b
2014-03-11Add a basic unit test for system(3).Elliott Hughes
Change-Id: Ibc5ac21f3663685d89ce261b58d6ea386fc1ff88
2014-02-24Added mkstemp64Calin Juravle
Bug: 13076637 Change-Id: I41bf28ab3e6c7325470781e9323eeec023483df5
2013-11-18Fix pthread_join.Elliott Hughes
Let the kernel keep pthread_internal_t::tid updated, including across forks and for the main thread. This then lets us fix pthread_join to only return after the thread has really exited. Also fix the thread attributes of the main thread so we don't unmap the main thread's stack (which is really owned by the dynamic linker and contains things like environment variables), which fixes crashes when joining with an exited main thread and also fixes problems reported publicly with accessing environment variables after the main thread exits (for which I've added a new unit test). In passing I also fixed a bug where if the clone(2) inside pthread_create(3) fails, we'd unmap the child's stack and TLS (which contains the mutex) and then try to unlock the mutex. Boom! It wasn't until after I'd uploaded the fix for this that I came across a new public bug reporting this exact failure. Bug: 8206355 Bug: 11693195 Bug: https://code.google.com/p/android/issues/detail?id=57421 Bug: https://code.google.com/p/android/issues/detail?id=62392 Change-Id: I2af9cf6e8ae510a67256ad93cad891794ed0580b
2013-04-11Switch to current FreeBSD qsort.Elliott Hughes
Change-Id: Ic46cd0b663dc5fa78c99dd38db0bfe849a25e789
2013-03-01Move realpath.c to upstream-freebsd.Elliott Hughes
This is actually a slightly newer upstream version than the one I originally pulled. Hopefully now it's in upstream-freebsd it will be easier to track upstream, though I still need to sit down and write the necessary scripts at some point. Bug: 5110679 Change-Id: I87e563f0f95aa8e68b45578e2a8f448bbf827a33