Commit graph

60 commits

Author SHA1 Message Date
Elliott Hughes
4e62055462 Add a missing strtol() family test and a hex benchmark.
Benchmark added to test an optimization I'll send round next, test added
when an even bigger refactoring (as part of a more interesting
optimization) broke strtol() in a way the strtol() tests didn't notice.

Test: treehugger
Change-Id: Ic974900021107938dbbbe98648960adb102d9595
2023-12-11 16:57:03 -08:00
Elliott Hughes
95646e6666 Add ASSERT_ERRNO and EXPECT_ERRNO (and use them).
We've talked about this many times in the past, but partners struggle to
understand "expected 38, got 22" in these contexts, and I always have to
go and check the header files just to be sure I'm sure.

I actually think the glibc geterrorname_np() function (which would
return "ENOSYS" rather than "Function not implemented") would be more
helpful, but I'll have to go and implement that first, and then come
back.

Being forced to go through all our errno assertions did also make me
want to use a more consistent style for our ENOSYS assertions in
particular --- there's a particularly readable idiom, and I'll also come
back and move more of those checks to the most readable idiom.

I've added a few missing `errno = 0`s before tests, and removed a few
stray `errno = 0`s from tests that don't actually make assertions about
errno, since I had to look at every single reference to errno anyway.

Test: treehugger
Change-Id: Iba7c56f2adc30288c3e00ade106635e515e88179
2023-09-21 14:15:59 -07:00
zijunzhao
5a918d922b Nullability check for stdlib module.
Bugs: b/245972273
Test: None

Change-Id: Ib33a5359a924c21888f268158c4d7f824740dd55
2022-12-02 21:00:02 +00:00
Elliott Hughes
1f462dec34 Add %b and %B support to the scanf/wscanf and strto*/wcsto* families.
Coming to C23 via WG14 N2630.

This one is a little interesting, because it actually changes existing
behavior. Previously "0b101" would be parsed as "0", "b", "101" by these
functions. I'm led to believe that glibc plans to actually have separate
versions of these functions for C23 and pre-C23, so callers can have the
behavior they (implicitly) specify by virtue of which -std= they compile
with. Android has never really done anything like that, and I'm pretty
sure app developers have more than enough to worry about with API levels
without having to deal with the cartesian product of API level and C
standard.

Therefore, my plan A is "if you're running on Android >= U, you get C23
behavior". My plan B in the (I think unlikely) event that that actually
causes trouble for anyone is "if you're _targeting_ Android >= U, you
get C23 behavior". I don't think we'd actually want to have two versions
of each of these functions under any circumstances --- that seems by far
the most confusing option.

Test: treehugger
Change-Id: I0bbb30315d3fabd306905ad1484361f5d8745935
2022-08-11 00:25:08 +00:00
Florian Mayer
750dcd326e Use SKIP_WITH_HWASAN macro from libbase.
Change-Id: I83681d2191bf4184e52d84d1107d61065927bb24
2022-04-15 16:14:56 -07:00
Elliott Hughes
b6b7e2ee2e Add the missing '--' to shell invocations.
This came up with POSIX recently. Doesn't seem like it matters since
everyone's had this wrong for 40 years, but "meh" --- it's a trivial
fix, and it's strictly correct even if nobody needs this, so let's just
do it...

(Geoff Clare pointed out that my app compat concern "what if someone's
relying on this bug to pass flags to the shell?" isn't relevant because
while you can indeed do that, you then can't pass a command!)

Bug: https://austingroupbugs.net/view.php?id=1440
Test: treehugger
Change-Id: I64f6440da55e2dc29d0136ee62007197d2f00d46
2021-11-04 17:29:35 -07:00
Colin Cross
4c5595c968 Replace local MUSL define with global ANDROID_HOST_MUSL
Bug: 190084016
Test: m USE_HOST_MUSL=true bionic-unit-tests-glibc
Change-Id: I56b23576cb24912112d2ae56d8ecc2e3716982fe
2021-08-16 16:44:24 -07:00
Colin Cross
7da20341e9 Build bionic unit tests for musl
Modify bionic unit tests that are built for glibc so that they also
build against musl.  They don't all pass though:

With glibc:
 2 SLOW TESTS
 4 TIMEOUT TESTS
313 FAILED TESTS
  YOU HAVE 2 DISABLED TESTS

With musl:
11 SLOW TESTS
11 TIMEOUT TESTS
363 FAILED TESTS
  YOU HAVE 2 DISABLED TESTS

Bug: 190084016
Test: m bionic-unit-tests-glibc with musl
Test: atest bionic-unit-tests-static
Test: atest --host bionic-unit-tests-glibc with glibc
Change-Id: I79b6eab04fed3cc4392450df5eef2579412edfe1
2021-08-12 11:13:11 -07:00
Elliott Hughes
141b917018 Switch to libbase SilentDeathTest.
Bug: http://b/184955378
Test: treehugger
Change-Id: Ie0849224074da92203340a741a86a24a4a3702c2
2021-04-12 10:01:20 -07:00
Elliott Hughes
bbbe27ff6e Improve system() coverage.
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-03-08 14:07:01 -08:00
Elliott Hughes
f9cfecf3d4 Fix freopen() where the path is null.
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
2021-02-04 17:01:55 -08:00
Elliott Hughes
7cebf835f3 Various coverage improvements.
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-08-12 15:52:14 -07:00
Elliott Hughes
8fe1fcd804 Merge "Reimplement realpath." 2020-01-23 20:34:15 +00:00
Elliott Hughes
75064c177f Initialize __progname correctly.
setprogname() does a basename, but we were initializing __progname
directly. Stop doing that, and add some tests.

Test: treehugger
Change-Id: I06f306ade4161b2f0c7e314a3b1b30c9420117b7
2020-01-23 08:28:48 -08:00
Elliott Hughes
22fb267ad6 Reimplement realpath.
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
2020-01-22 18:30:50 -08:00
Christopher Ferris
a22f5d5175 Make aligned_alloc match the standard.
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-03-01 23:56:23 -08:00
Elliott Hughes
18181e6a0a Updates for glibc 2.17.
Bug: http://b/111358231
Test: builds
Change-Id: I542b2a9acc74261ad12b78e4add0f3ae77c3656c
2019-01-30 13:52:36 -08:00
Elliott Hughes
72a54a41a7 Make stdlib.getloadavg more resiliant.
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-12-18 14:47:25 -08:00
Mark Salyzyn
68a3bcc249 bionic tests: switch to using android-base/file.h for TemporaryFile
A matching definition of TemporaryFile exists in libbase now.

Test: compile
Bug: 119313545
Change-Id: I6f84dbf3af9a9c4b270a2532a36c9cb4c0f6bb8f
2018-11-13 10:57:28 -08:00
Evgenii Stepanov
acd6f4f9f5 Disable a few bionic tests under HWASan.
* 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-11-06 16:59:25 -08:00
Elliott Hughes
2d0b28bc0d Add getloadavg(3).
Lets us build ninja with bionic.

Bug: N/A
Test: ran tests
Change-Id: I97eef1247d794b58a2b9aee4851551632e5a4e48
2018-10-23 11:23:00 -07:00
Yi Kong
32bc0fcf69 Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning.

Test: m
Bug: 68236239
Change-Id: I5b4123bc6709641315120a191e36cc57541349b2
2018-08-02 18:09:44 -07:00
Christopher Ferris
cae21a9b53 Add aligned_alloc to libc.
Bug: 72969374

Test: Bionic unit tests pass.
Test: Malloc debug unit tests pass.
Change-Id: I235985bbc638855d94249c97c98f14ab2924bda0
(cherry picked from commit d69ee59594)
2018-02-07 06:57:14 -08:00
Elliott Hughes
cb239bda65 Simplify atoi*/strto* for signed integers.
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-21 17:44:22 -08:00
Elliott Hughes
f61a06e598 Use std::to_string instead of std::stringstream.
Bug: N/A
Test: ran tests
Change-Id: Ifeb7cf9517bcc05459e7ce316eb7604042510935
2017-12-19 16:11:37 -08:00
Elliott Hughes
1921dce886 Refactor the ato* and strto* family.
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-19 13:55:54 -08:00
Elliott Hughes
a7f12944d4 A few more trivial tests.
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-15 13:55:53 -08:00
Aleksandra Tsvetkova
608b4514cb A few new bionic tests.
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-12-07 15:44:20 -08:00
Elliott Hughes
728cde5be9 Add trivial ttyname(3) test.
Bug: N/A
Test: ran tests
Change-Id: Id5bf51a9c50db0fdbc9df0225165e87e698d0c83
2017-11-08 21:53:50 -08:00
Elliott Hughes
00d8a8b779 Trivial tests for <inttypes.h>/<stdlib.h> *abs and *div functions.
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-09-07 17:01:37 -07:00
George Burgess IV
95bd4884b5 libc fortify: error on realpath(NULL, foo)
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-08-14 14:48:55 -07:00
Elliott Hughes
f826a37b95 Apply recent strto* fix, add new tests.
The behavior with "0xy" was wrong: we'd swallow the 'x'.

Bug: N/A
Test: ran tests
Change-Id: I2464d22a2408e99880303876306f18a25c390ad9
2017-07-13 09:35:15 -07:00
Christopher Ferris
3a32d95e28 Update posix_memalign testing.
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
2017-06-15 14:18:08 -07:00
Dan Albert
f634655e64 Fix wcsto* where strings begin with whitespace.
The libc++ tests caught this.

Test: adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests
Bug: None
Change-Id: I14864e006f6cf9de3f96acac6aa3eb235894f2b1
2016-12-02 13:03:30 -08:00
Elliott Hughes
7f0849fd11 Fix sscanf/wcstod parsing of NaNs.
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-09-07 15:01:54 -07:00
Elliott Hughes
6f6f9058fa Implement mblen(3).
Change-Id: I65948ea5b9ecd63f966ba767ad6db4a2effc4700
2016-04-28 16:41:29 -07:00
Elliott Hughes
df143f8576 Add POSIX getsubopt(3).
Bug: http://b/27952303
Change-Id: I8a816477545dadcbd5c055714e76263574446b6f
2016-04-04 17:34:04 -07:00
Elliott Hughes
33697a0c43 Factor out the waiting for children in bionic tests.
Change-Id: I4a1e51b6920b33dc892d447f5bd6d10f1cb2704a
2016-01-26 13:13:52 -08:00
Elliott Hughes
274afe8f0e Add POSIX lcong48.
Change-Id: I821046816661d77275cb02c8c99d526bb41afb9c
2014-11-06 14:14:37 -08:00
Yabin Cui
9df70403d9 make all bionic death tests not dumpable
Bug: 18067305

Change-Id: Ia1ecacf47eddecc9bc58aaac779e0c218f463179
2014-11-06 11:09:03 -08:00
Elliott Hughes
89aaaffbf8 Extra strtod/strtof tests.
Check that libc doesn't suffer from a couple of bugs that affected
Java in the past.

Bug: 2206701
Change-Id: I9eb64d7ff2fa0b79e93079b897a5fb78bef866be
2014-10-28 17:54:23 -07:00
Elliott Hughes
31e072fc9b Update our FreeBSD realpath(3) to upstream head.
Change-Id: I8c89728184ecd2c1a28a05cefa84a5037d28b552
2014-09-30 16:40:41 -07:00
Elliott Hughes
31165edf57 CLOEXEC support in fdopen, freopen, and mkostemp/mkostemps.
Change-Id: I74ea88e0d4973d6ab3c57da7d8bb643c31592b14
2014-09-23 18:21:52 -07:00
Elliott Hughes
b05ec5ae93 Pull in upstream fixes to reject invalid bases.
Also add tests to make sure the full set works correctly.

Change-Id: I3e7f237f12c9c93e1185a97c9717803e7e55a73c
2014-09-23 14:53:10 -07:00
Elliott Hughes
4916706cfe Fix linkage of grantpt(3).
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-25 19:55:23 -07:00
Elliott Hughes
76c241b091 Implement rand/srand in terms of random/srandom.
Code developed for glibc or older versions of bionic might expect more
randomness than the BSD implementation provides.

Bug: 15829381
Change-Id: Ia5a908a816e0a5f0639f514107a6384a51ec157e
2014-07-14 12:02:22 -07:00
Elliott Hughes
a0beeeabbc Get the full set of PRNG functions in <stdlib.h>
Bug: https://code.google.com/p/android/issues/detail?id=58888
Change-Id: I435250bdae302e8bd7e29977d0fde7b9afbfca5e
2014-06-12 14:37:31 -07:00
Elliott Hughes
063525c61d Consistently use #if defined(__BIONIC__) in tests.
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-05-13 11:19:57 -07:00
Dan Albert
b8425c549a Adds quick_exit(3) and at_quick_exit(3) from freebsd
Change-Id: I4fe88abd8f7b8aa45e58aeb2529d59a8d555d338
2014-04-29 19:17:00 -07:00
Elliott Hughes
9f525644df Implement _Exit(3).
Change-Id: Ida6ac844cc87d38c9645b197dd8188bb73e27dbe
2014-04-08 17:16:13 -07:00