Commit graph

126 commits

Author SHA1 Message Date
Peter Elliott 420f78ca8b Tests: Add tests for posix_memalign(3) and aligned_alloc(3) 2022-05-20 22:18:54 +02:00
Tim Schumacher 66170ff632 Tests: Add a test for printf truncation 2022-04-14 03:12:56 +04:30
Idan Horowitz 086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Kenneth Myhra 4a57be824c Userland+Tests: Convert File::read_link() from String to ErrorOr<String>
This converts the return value of File::read_link() from String to
ErrorOr<String>.

The rest of the change is to support the potential of an Error being
returned and subsequent release of the value when no Error is returned.
Unfortunately at this stage none of the places affected can utililize
our TRY() macro.
2022-03-24 11:57:51 +01:00
Daniel Bertalan ea52ba9fdc LibC: Set saved_str to null in strtok_r if no tokens were found
If we do not do this, the next call to strtok_r will start tokenizing
(and possibly modifying!) the memory pointed to by `saved_ptr`.
2022-03-08 23:30:47 +01:00
Tim Schumacher 8ebc749191 Tests: Include limits.h for PATH_MAX in realpath tests 2022-03-08 22:00:28 +01:00
Tim Schumacher f748586393 Tests: Include limits.h for MB_LEN_MAX in wchar tests 2022-03-08 22:00:28 +01:00
Peter Ross 34108547b6 AK: Print NaN and infinite numbers in PrintfImplementation 2022-03-02 11:40:37 +01:00
Peter Ross 6c06b70911 LibC: Set PRI[xX]8/PRI[xX]16 macros to x and X
Described in:
  <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/
    inttypes.h.html>

The macros were first added in a7a456002e,
but it is not clear why the PRIx16/32 macros were defined as 'b' & 'w'.
PrintfImplementation was never able to parse these values.
2022-03-02 11:40:37 +01:00
Timur Sultanov ffbd630ca6 AK: Add tests for integer values formatting in printf 2022-02-28 14:08:24 +01:00
Peter Ross 5b32b46ebc LibC: Do not write value when scanf assignment value is suppressed
This change has the positive side-effect of causing scanf to *segfault*
when a NULL pointer argument is passed to scanf.
e.g. sscanf(str, "%d", NULL);
2022-02-20 00:13:08 +03:30
Peter Ross 31079a56d7 LibC: Do not include suppressed assignments in scanf return value 2022-02-20 00:13:08 +03:30
Max Wipfli f3cf1b33d7 Tests: Add test for LibC mkdir() 2022-02-13 21:58:26 +02:00
Timothy Flynn 010ec36d20 LibC: Ensure most time tests run under UTC
This ensures these tests pass even if the user has changed the system
time zone away from UTC.
2022-01-25 18:39:36 +00:00
Timothy Flynn b1ea585149 LibC: Implement tzset with time zone awareness in accordance with POSIX 2022-01-25 18:39:36 +00:00
Daniel Bertalan 6e00dd64a1 Tests: Test whether stdio streams are flushed correctly on exit 2022-01-16 14:59:21 -08:00
Michel Hermier 1af072e0f3 LibC: Make *alloc return NULL in case of failure (POSIX) 2022-01-16 11:18:04 +01:00
mjz19910 10ec98dd38 Everywhere: Fix spelling mistakes 2022-01-07 15:44:42 +01:00
Jesse Buhagiar 2de7f2021d LibC: Support X modifier for scanf
This was currently crashing Half-Life because it was a considered an
"Unknown" specifier. We can use the same case statement as the regular
hex format conversion (lower case 'x'), as the backend
to convert the number already supports upper/lower case input, hence
we get it for free :^)
2022-01-02 08:10:08 +02:00
Michel Hermier 682f89d5bc LibC: Allow multiple includes of <assert.h>
ISO C requires in section 7.2:
The assert macro is redefined according to the current state of NDEBUG
each time that <assert.h> is included.

Also add tests for `assert` multiple inclusion accordingly.
2021-12-23 17:53:46 -08:00
Michel Hermier 4c6e826c05 LibTest: Add EXPECT_CRASH_WITH_SIGNAL 2021-12-19 14:22:06 -08:00
Michel Hermier c22c1900c0 Tests: Add test for raise 2021-12-19 14:22:06 -08:00
Michel Hermier 0ec35d6d81 Tests: Add test for assert 2021-12-19 14:22:06 -08:00
Michel Hermier 181f759dc9 Tests: Add test for abort 2021-12-19 14:22:06 -08:00
Jelle Raaijmakers a44978b9b0 LibC: Fix %n conversion specifier in scanf() format
Also add a test to prevent this from happening again. There were two
bugs:

* The number of bytes just after processing the last value was written,
  instead of the number of bytes after skipping remaining whitespace.
  Confirmed by testing against GNU's `scanf()` since the man page
  leaves something to be desired.

* The number of bytes was written to the wrong variable argument; i.e.
  the first argument was overwritten.
2021-10-24 22:43:27 -07:00
Jelle Raaijmakers 00f36fc5ae Tests: Print full 32-byte range of values in TestScanf
We are trying to show 8 u32 values, each of which needs at most 8
hexadecimal characters to be shown entirely.
2021-10-24 22:43:27 -07:00
Jelle Raaijmakers e71e9de61f Tests: Reword 'output' to 'return value' in TestScanf 2021-10-24 22:43:27 -07:00
Jelle Raaijmakers e3f17401cb Tests: Use correct argument count for value conformance in TestScanf 2021-10-24 22:43:27 -07:00
Tim Schumacher 65bcee3c62 Tests: Only test truthiness for iswctype 2021-10-24 22:40:11 -07:00
Tim Schumacher 9e3e4a692d Tests: Use proper comparison macros for wctype 2021-10-24 22:40:11 -07:00
Tim Schumacher 79bcfa967b LibC: Fix up mblen 2021-10-22 13:28:56 -07:00
Tim Schumacher 8df6955838 LibC: Fix up mbtowc
One more proper implementation and one less FIXME.
2021-10-22 13:28:56 -07:00
Tim Schumacher 89afd4d063 LibC: Implement mbsnrtowcs 2021-10-21 23:57:32 -07:00
Tim Schumacher 552ae77f0d LibC: Implement wcsnrtombs 2021-10-21 23:57:32 -07:00
Tim Schumacher e618602433 LibC: Implement mbrlen 2021-10-21 23:47:20 -07:00
Daniel Bertalan 13e6d9d71a LibC: Implement wcslcpy 2021-10-17 17:09:58 +01:00
Tim Schumacher 420bdccf0b LibC: Implement mbsrtowcs 2021-10-15 21:50:19 -07:00
Tim Schumacher b0babd062e LibC: Implement wcsrtombs 2021-10-15 21:50:19 -07:00
Daniel Bertalan c8367df746 LibC: Implement wcrtomb
This function converts a single wide character into its multibyte
representation (UTF-8 in our case). It is called from libc++'s
`std::basic_ostream<wchar_t>::flush`, which gets called at program exit
from a global destructor in order to flush `std::wcout`.
2021-10-15 21:50:19 -07:00
Tim Schumacher 4b423a5ec7 LibC: Implement twalk 2021-10-15 21:50:19 -07:00
Tim Schumacher 7448626bae LibC: Implement tfind and tsearch 2021-10-15 21:50:19 -07:00
Tim Schumacher 7af7fc8c16 Everywhere: Fix more Copyright header inconsistencies 2021-10-04 11:10:09 +01:00
Tim Schumacher 4302e7ac26 Tests: Add tests for mbrtowc 2021-10-03 11:13:50 +00:00
Tim Schumacher e7f99edefa Tests: Add a test for mbsinit 2021-10-03 11:13:50 +00:00
Tim Schumacher 05b283f552 LibC: Implement wmemmove 2021-10-03 05:28:51 +00:00
Tim Schumacher fa1208edfd LibC: Implement wmemset 2021-10-03 05:28:51 +00:00
Tim Schumacher 485c0ef691 LibC: Implement wmemcpy 2021-10-03 05:28:51 +00:00
Tim Schumacher 0ca1df4dc6 LibC: Implement wmemchr 2021-10-03 05:28:51 +00:00
Tim Schumacher 5ac2e84264 LibC: Implement wcsstr 2021-10-03 05:28:51 +00:00
Tim Schumacher 1b078f87b7 LibC: Implement wcspbrk 2021-10-03 05:28:51 +00:00
Tim Schumacher b8c756a53a LibC: Primitively implement wcscoll
At the moment, sorting like LC_COLLATE=C would do is better than
nothing.
2021-09-18 02:57:56 +00:00
Tim Schumacher 42031f026a LibC: Implement towctrans 2021-09-17 22:59:51 +00:00
Tim Schumacher 8c7b566629 LibC: Implement iswctype 2021-09-17 22:59:51 +00:00
Tim Schumacher ff0ab8b9a9 LibC: Implement wctrans 2021-09-17 22:59:51 +00:00
Tim Schumacher 7b17230d7a LibC: Implement wctype 2021-09-17 22:59:51 +00:00
Ali Mohammad Pur 97e97bccab Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safe 2021-09-06 01:53:26 +02:00
Brian Gianforcaro 782e7834c3 Tests: Reduce the execution time of the LibC TestQSort test
Executing 100 times vs 10 times doesn't increase test coverage
substantial, this API is stable and more iterations is just a
waste of time.

Without KVM this test is a clear outlier in runtime during CI:

```
START  LibC/TestQsort (106/172)
PASS   LibC/TestQsort (41.233692s)
```
2021-09-05 22:17:28 +02:00
Andrew Kaster b3e3e4d45d Tests: Convert remaining LibC tests to LibTest
Convert them to using outln instead of printf at the same time.
2021-09-01 13:44:24 +02:00
Jean-Baptiste Boric c97f7ea23b Tests: Test setjmp/sigsetjmp LibC functions
Since there are no real users of these functions in Serenity's
userland and this is my third attempt at this... This time, the great
LibTest test suite will make sure that I do it right!
2021-08-26 00:54:23 +02:00
Daniel Bertalan 6821cd45ed Tests: Fix compile errors on Clang
Since Clang enables a couple of warnings that we don't have in GCC,
these were not caught before. Included fixes:

- Use correct printf format string for `size_t`
- Don't compare Nonnull(Ref|Own)Ptr` to nullptr
- Fix unsigned int& => unsigned long& conversion
2021-07-14 13:12:25 +02:00
Andrew Kaster 2ca1193d9a Userland+Tests: Convert test_io to be LibTest based
Add a few extra tests as well, to make sure we don't have any future
TmpFs regressions.
2021-07-11 19:42:00 +02:00
Gunnar Beutner 75ba74a216 Tests: Build all tests on x86_64
This builds some previously-disabled tests for x86_64.
2021-07-07 15:29:18 +02:00
Andrew Kaster d0447f23b8 Tests+Base: Convert stack-smash to be LibTest based and stop skipping it
Now that the test is converted to be LibTest based, we can remove it
from the exclude list in /home/anon/.config/Tests.ini.

Prior to this it would crash and fail because it was signaled instead of
returning normally with exit code 0.
2021-07-06 17:22:45 +02:00
Gunnar Beutner c81b3e1ee3 LibC: Implement strerror_r()
This implements the XSI-compliant version of strerror_r() - as opposed
to the GNU-specific variant.

The function explicitly saves errno so as to not accidentally change it
with one of the calls to other functions.
2021-05-25 17:36:02 +02:00
Lenny Maiorani 2b64d163cd Tests: static vs non-static constexpr variables
Problem:
- `static` variables consume memory and sometimes are less
  optimizable.
- `static const` variables can be `constexpr`, usually.
- `static` function-local variables require an initialization check
  every time the function is run.

Solution:
- If a global `static` variable is only used in a single function then
  move it into the function and make it non-`static` and `constexpr`.
- Make all global `static` variables `constexpr` instead of `const`.
- Change function-local `static const[expr]` variables to be just
  `constexpr`.
2021-05-19 21:21:03 +01:00
Gunnar Beutner fcaf98361f AK: Turn ByteBuffer into a value type
Previously ByteBuffer would internally hold a RefPtr to the byte
buffer and would behave like a reference type, i.e. copying a
ByteBuffer would not create a duplicate byte buffer, but rather
two objects which refer to the same internal buffer.

This also changes ByteBuffer so that it has some internal capacity
much like the Vector<T> type. Unlike Vector<T> however a byte
buffer's data may be uninitialized.

With this commit ByteBuffer makes use of the kmalloc_good_size()
API to pick an optimal allocation size for its internal buffer.
2021-05-16 17:49:42 +02:00
Jean-Baptiste Boric eecf7a2097 LibC: Move mman.h to sys/mman.h
POSIX mandates that it is placed there.
2021-05-14 22:24:02 +02:00
Jean-Baptiste Boric e16894af5a LibC: Do not include errno.h inside unistd.h
POSIX does not mandate this, therefore let's not do it.
2021-05-14 22:24:02 +02:00
sin-ack 60eb4adac2 Tests: Add InodeWatcher and FileWatcher tests
This patch adds some rudimentary tests for InodeWatcher.  It tests the
basic functionality, but maybe there are corner cases I haven't caught.
Additionally, this is our first LibCore test. :^)
2021-05-12 22:38:20 +02:00
Brian Gianforcaro fd0dbd1ebf Tests: Establish root Tests directory, move Userland/Tests there
With the goal of centralizing all tests in the system, this is a
first step to establish a Tests sub-tree. It will contain all of
the unit tests and test harnesses for the various components in the
system.
2021-05-06 17:54:28 +02:00
Ben Wiederhake 29eceebdbf Tests: Build automatically, fix compilation errors 2020-08-02 17:15:36 +02:00
AnotherTest 1ad51325ad Kernel+LibC: Implement 'memmem'
This commit adds an implementation of memmem, using the Bitap text
search algorithm for needles smaller than 32 bytes, and a naive loop
search for longer needles.
2020-08-01 08:39:26 +02:00
Sahan Fernando 0ba9651e6e LibC: Replace Berkley's qsort() with AK::dual_pivot_quick_sort() wrapper 2020-07-03 19:29:36 +02:00
Ben Wiederhake 4bff3defa8 LibC: strtod accuracy tests no longer need to skip 2020-05-11 10:52:24 +02:00
Ben Wiederhake c19d5943f1 LibC: Demonstrate strtod inaccuracy
See also #1979.
2020-05-11 10:52:24 +02:00
Andreas Kling 998765a7a6 LibC: The exec() family of functions should not search "." by default
We should only execute the filename verbatim if it contains a slash (/)
character somewhere. Otherwise, we need to look through the entries in
the PATH environment variable.

This fixes an issue where you could easily "override" system programs
by placing them in a directory you control, and then waiting for
someone to come there and run e.g "ls" :^)

Test: LibC/exec-should-not-search-current-directory.cpp
2020-02-01 16:14:09 +01:00