summaryrefslogtreecommitdiff
path: root/Tests/LibCore
AgeCommit message (Collapse)Author
2022-07-27LibCore: Implement four-digit modes for `FilePermissionsMask` parsingTim Schumacher
2022-07-27LibCore: Implement the 'X' modifier into `FilePermissionMask`Tim Schumacher
2022-07-12Everywhere: Add sv suffix to strings relying on StringView(char const*)sin-ack
Each of these strings would previously rely on StringView's char const* constructor overload, which would call __builtin_strlen on the string. Since we now have operator ""sv, we can replace these with much simpler versions. This opens the door to being able to remove StringView(char const*). No functional changes.
2022-04-21LibCore: Introduce SharedSingleProducerCircularQueuekleines Filmröllchen
This new class with an admittedly long OOP-y name provides a circular queue in shared memory. The queue is a lock-free synchronous queue implemented with atomics, and its implementation is significantly simplified by only accounting for one producer (and multiple consumers). It is intended to be used as a producer-consumer communication datastructure across processes. The original motivation behind this class is efficient short-period transfer of audio data in userspace. This class includes formal proofs of several correctness properties of the main queue operations `enqueue` and `dequeue`. These proofs are not 100% complete in their existing form as the invariants they depend on are "handwaved". This seems fine to me right now, as any proof is better than no proof :^). Anyways, the proofs should build confidence that the implemented algorithms, which are only roughly based on existing work, operate correctly in even the worst-case concurrency scenarios.
2022-04-16LibCore+Everywhere: Make Core::Stream read_line() return StringViewSam Atkins
Similar reasoning to making Core::Stream::read() return Bytes, except that every user of read_line() creates a StringView from the result, so let's just return one right away.
2022-04-16LibCore+Everywhere: Make Core::Stream::read() return BytesSam Atkins
A mistake I've repeatedly made is along these lines: ```c++ auto nread = TRY(source_file->read(buffer)); TRY(destination_file->write(buffer)); ``` It's a little clunky to have to create a Bytes or StringView from the buffer's data pointer and the nread, and easy to forget and just use the buffer. So, this patch changes the read() function to return a Bytes of the data that were just read. The other read_foo() methods will be modified in the same way in subsequent commits. Fixes #13687
2022-02-16LibCore+Tests: Add SeekableStream::truncate()Sam Atkins
2022-02-14LibCore+Tests: Remove Core::UDPSocket :^)sin-ack
2022-02-06LibCore+Userland: Remove Core::TCPSocket :^)sin-ack
This was deprecated in favor of Core::Stream::TCPSocket, and now has no users.
2022-02-06LibCore: Remove Core::LocalSocket :^)sin-ack
2022-01-24Everywhere: Convert ByteBuffer factory methods from Optional -> ErrorOrSam Atkins
Apologies for the enormous commit, but I don't see a way to split this up nicely. In the vast majority of cases it's a simple change. A few extra places can use TRY instead of manual error checking though. :^)
2022-01-24LibCore: Improve handling of parsing errors in FilePermissionsMaskXavier Defrang
2022-01-24LibCore: Restore support for multiple symbolic classesXavier Defrang
Reverts recent change introduced to support implicit symbolic permission which broke the parser when multiple classes are specified. The state machine must assume it's dealing with classes until an operation character is consumed.
2022-01-23LibCore: Allow EventLoops to run on multiple threads safelykleines Filmröllchen
The event loop system was previously very singletony to the point that there's only a single event loop stack per process and only one event loop (the topmost) can run at a time. This commit simply makes the event loop stack and related structures thread-local so that each thread has an isolated event loop system. Some things are kept at a global level and synchronized with the new MutexProtected: The main event loop needs to still be obtainable from anywhere, as it closes down the application when it exits. The ID allocator is global as IDs should not be shared even between threads. And for the inspector server connection, the same as for the main loop holds. Note that currently, the wake pipe is only created by the main thread, so notifications don't work on other threads. This removes the temporary mutex fix for notifiers, introduced in 0631d3fed5623c1f2b0d6085ab24e4dd69c6ce99 .
2022-01-20Tests: Add should_error_when_connection_fails test to TestLibCoreStreamsin-ack
This test makes sure that Socket classes such as TCPSocket properly return an error when connection fails rather than crashing or creating an invalid object.
2022-01-20Tests: Fix the TestLibCoreStream local_socket_write testsin-ack
Accidentally regressed this test during the Core::LocalServer refactor, and didn't catch it since TestLibCoreStream is disabled in the CI right now. We have to wait for some data to become available, as pending_bytes will immediately return 0 and a 0-sized read immediately returns.
2022-01-15LibCore+LibIPC+Everywhere: Return Stream::LocalSocket from LocalServersin-ack
This change unfortunately cannot be atomically made without a single commit changing everything. Most of the important changes are in LibIPC/Connection.cpp, LibIPC/ServerConnection.cpp and LibCore/LocalServer.cpp. The notable changes are: - IPCCompiler now generates the decode and decode_message functions such that they take a Core::Stream::LocalSocket instead of the socket fd. - IPC::Decoder now uses the receive_fd method of LocalSocket instead of doing system calls directly on the fd. - IPC::ConnectionBase and related classes now use the Stream API functions. - IPC::ServerConnection no longer constructs the socket itself; instead, a convenience macro, IPC_CLIENT_CONNECTION, is used in place of C_OBJECT and will generate a static try_create factory function for the ServerConnection subclass. The subclass is now responsible for passing the socket constructed in this function to its ServerConnection base; the socket is passed as the first argument to the constructor (as a NonnullOwnPtr<Core::Stream::LocalServer>) before any other arguments. - The functionality regarding taking over sockets from SystemServer has been moved to LibIPC/SystemServerTakeover.cpp. The Core::LocalSocket implementation of this functionality hasn't been deleted due to my intention of removing this class in the near future and to reduce noise on this (already quite noisy) PR.
2022-01-14Tests: Remove some temporary files when finished using themAndreas Kling
Leaving files in /tmp uses memory, which accumulates over time if you do something weird like leaving `run-tests` going all day long. :^)
2022-01-13LibCore+Userland+Tests: Convert Stream APIs to construct on heapsin-ack
As per previous discussion, it was decided that the Stream classes should be constructed on the heap. While I don't personally agree with this change, it does have the benefit of avoiding Function object reconstructions due to the lambda passed to Notifier pointing to a stale object reference. This also has the benefit of not having to "box" objects for virtual usage, as the objects come pre-boxed. However, it means that we now hit the heap everytime we construct a TCPSocket for instance, which might not be desirable.
2022-01-01LibCore: Add FilePermissionsMaskXavier Defrang
This class parses UNIX file permissions definitions in numeric (octal) or symbolic (ugoa+rwx) format and can apply them on a given file mode.
2022-01-01Tests/LibCore: Add regression test for the read_until_any_of OOB readDaniel Bertalan
2021-12-28LibCore: Fix race conditions in TestLibCoreStreamAndreas Kling
It was possible for the "local_socket_read" and "local_socket_write" tests to fail because we had exited the EventLoop before BackgroundAction got around to invoking the completion callback. The crash happened when trying to deferred_invoke() on the background thread, calling Core::EventLoop::current() after said EventLoop had returned from exec(). Fix this by not passing a completion callback, since we didn't need one in the first place.
2021-12-27LibCore+Services: Make TCPServer propagate errorsSam Atkins
2021-12-16Tests: Implement tests for the Serenity Stream APIsin-ack
2021-12-12LibCore: Add support for range-based for loops on LineIteratorsSahan Fernando
2021-11-30LibCore: Fix relative seeking in IODeviceArne Elster
The recently introduced read buffer in IODevice broke relative seeking. The amount of data in the buffer wouldn't get taken into account.
2021-11-26Tests: Fix TestLibCoreArgsParser with add_positional_argument API changeBrian Gianforcaro
Since we no longer populate a Vector<String> the lifetime of the strings in all of these tests is now messed up, as the Vector<StringView> now points to free'd memory. We attempt to fix this for the unit tests, by saving the results in a RAII type that should live as long as the test wants to validate some output of the ArgParser.
2021-11-26Userland: Use Core::ArgsParser's Vector<StringView> API everywhereAndreas Kling
...and remove the Vector<String> variant since there are no remaining users of this API.
2021-09-02Tests: Remove all file(GLOB) from CMakeLists in TestsAndrew Kaster
Using a file(GLOB) to find all the test files in a directory is an easy hack to get things started, but has some drawbacks. Namely, if you add a test, it won't be found again without re-running CMake. `ninja` seems to do this automatically, but it would be nice to one day stop seeing it rechecking our globbed directories.
2021-09-02Tests: Add tests for Core::deferred_invokesin-ack
2021-08-20LibCore: Make Core::File::open() return OSError in case of failureAndreas Kling
2021-06-22LibCore: Add unit test for File::read_linecoderdreams
2021-06-13LibC: Make `getopt` modify `argv` againJelle Raaijmakers
A POSIX-compatibility fix was introduced in 64740a0214 to make the compilation of the `diffutils` port work, which expected a `char* const* argv` signature. And indeed, the POSIX spec does not mention permutation of `argv`: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getopt.html However, most implementations do modify `argv` as evidenced by documentation such as: https://refspecs.linuxbase.org/LSB_5.0.0/LSB-Core-generic /LSB-Core-generic/libutil-getopt-3.html "The function prototype was aligned with POSIX 1003.1-2008 (ISO/IEC 9945-2009) despite the fact that it modifies argv, and the library maintainers are unwilling to change this." Change the behavior back to permutate `argc` to allow for the following command line argument order to work again: unzip ./file.zip -o target-dir Without this change, `./file.zip` in the example above would have been ignored completely.
2021-06-08LibCore/ArgsParser: Learn how to stop on first non-optionJelle Raaijmakers
We need this for utilities like `env`, that do not gain anything by parsing the options passed to the command they are supposed to execute.
2021-06-08LibCore/ArgsParser: Add test suiteJelle Raaijmakers
This adds a very basic test suite for ArgsParser that we can use to set a baseline of functionality that we want to make sure keeps working.
2021-05-12Tests: Add InodeWatcher and FileWatcher testssin-ack
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. :^)