summaryrefslogtreecommitdiff
path: root/src/test
Commit message (Collapse)AuthorAge
* test-sizeof: also print float types from ISO/IEC TS 18661-3Zbigniew Jędrzejewski-Szmek2018-08-24
|
* test-alloc-util: add casts to bools from p ointersZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | C++03: "An rvalue of arithmetic, enumeration, pointer, or pointer to member type can be converted to an rvalue of type bool. A zero value, null pointer value, or null member pointer value is converted to false; any other value is converted to true" C should behave the same because pointers are scalars in C, but let's verify that.
* test-alloc-util: add a "test" for bool castsZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | Just in case ;) There is no good place, test-alloc-util.c is as good as any, and it's quite short so far, so let's add this there.
* parse-util: add permille parser + testsMarc Kleine-Budde2018-08-24
|
* basic/utf8: add ascii_is_valid_n()Zbigniew Jędrzejewski-Szmek2018-08-24
|
* test-bus-util: add a simple test for bus_request_name_async_may_reload_dbus()Zbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | | | | This shows a minor memleak: ==1883== 24 bytes in 1 blocks are definitely lost in loss record 1 of 1 ==1883== at 0x4C2DBAB: malloc (vg_replace_malloc.c:299) ==1883== by 0x4E9D385: malloc_multiply (alloc-util.h:69) ==1883== by 0x4EA2959: bus_request_name_async_may_reload_dbus (bus-util.c:1841) ==1883== by ... The exchange of messages is truncated at two different points: once right after the first callback is requested, and the second time after the full sequence has run (usually resulting in an error because of policy).
* main: split out reading of /proc/sys/fs/nr_open into its own functionLennart Poettering2018-08-24
| | | | | This doesn't really reduce the code size over all, but it does make main.c shorter and more readable, and that's always a good thing.
* basic/log: add the log_struct terminator to macroZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | This way all callers do not need to specify it. Exhaustively tested by running test-log under valgrind ;)
* test-ellipsize: add tests for ellipsize_mem, fix bugsZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | | | | | First, ellipsize() and ellipsize_mem() should not read past the input buffer. Those functions take an explicit length for the input data, so they should not assume that the buffer is terminated by a nul. Second, ellipsization was off in various cases where wide on multi-byte characters were used. We had some basic test for ellipsize(), but apparently it wasn't enough to catch more serious cases. Should fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=8686.
* conf-parser: remove redundant utf8-validity checkYu Watanabe2018-08-24
|
* conf-parse: use path_simplify_and_warn() in config_parse_path()Yu Watanabe2018-08-24
|
* path-util: make path_make_relative() support path including dotsYu Watanabe2018-08-24
|
* path-util: introduce path_simplify()Yu Watanabe2018-08-24
| | | | | | | | The function is similar to path_kill_slashes() but also removes initial './', trailing '/.', and '/./' in the path. When the second argument of path_simplify() is false, then it behaves as the same as path_kill_slashes(). Hence, this also replaces path_kill_slashes() with path_simplify().
* basic: set errno in raw_clone() on sparcMike Gilbert2018-08-24
| | | | | | | | sparc sets the carry bit when a syscall fails. Use this information to set errno and return -1 as appropriate. The added test case calls raw_clone() with flags known to be invalid according to the clone(2) manpage.
* process-util: also filter non-printable characters in get_process_com()Lennart Poettering2018-08-24
| | | | | | | | | | | | We already do that in get_process_cmdline(), which is very similar in behaviour otherwise. Hence, let's be safe and also filter them in get_process_comm(). Let's try to retain as much information as we can though and escape rather than suppress unprintable characters. Let's not increase comm names beyond the kernel limit on such names however. Also see discussion about this here: https://marc.info/?l=linux-api&m=152649570404881&w=2
* string-util: tweak cellescape() a bitLennart Poettering2018-08-24
| | | | | | | | | | | | | For short buffer sizes cellescape() was a bit wasteful, as it might suffice to to drop a single character to find enough place for the full four byte ellipsis, if that one character was a four character escape. With this rework we'll guarantee to drop the minimum number of characters from the end to fit in the ellipsis. If the buffers we write to are large this doesn't matter much. However, if they are short (as they are when talking about the process comm field) then it starts to matter that we put as much information as we can in the space we get.
* missing: define kernel internal limit TASK_COMM_LEN in userspace tooLennart Poettering2018-08-24
| | | | | We already use it at two places, and we are about to add one too. Arbitrary literally hardcoded limits suck.
* basic/string-util: add a convenience function to cescape mostly-ascii fieldsZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | It's not supposed to be the most efficient, but instead fast and simple to use. I kept the logic in ellipsize_mem() to use unicode ellipsis even in non-unicode locales. I'm not quite convinced things should be this way, especially that with this patch it'd actually be simpler to always use "…" in unicode locale and "..." otherwise, but Lennart wanted it this way for some reason.
* string-util: add new memory_startswith() helperLennart Poettering2018-08-24
| | | | | We have code like this at various placer, let's make things shorter and more readable with a helper for it.
* conf-files: beef up conf-files.[ch] a bitLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | | | | | | | | | | | | This adds fozr new flags: - If CONF_FILES_DIRECTORY is specified conf_file_list() and friends will look for directories only. - Similar CONF_FILES_REGULAR means we'll look only for regular files. - If CONF_FILES_BASENAME is specified the resulting list will contain only the basenames of all discovered files or directories, not the full paths. - If CONF_FILES_FILTER_MASKED is specified the resulting list will have masked entries removed (i.e. those symlinked to /dev/null and suchlike) These four flags are useful for discovering portable service profile information. While we are at it, also improve a couple of other things: - More debug logging - use path_hash_ops instead of string_hash_ops when putting together the path lists
* os-util: add helpers for finding /etc/os-releaseLennart Poettering2018-08-24
| | | | | Place this new helpers in a new source file os-util.[ch], and move the existing and related call path_is_os_tree() to it as well.
* fd-util: add new helper call fd_duplicate_data_fd()Lennart Poettering2018-08-24
| | | | | | | | | | | | This call creates an fd from another fd containing the same data. Specifically, repeated read() on the returned fd should return the same data as the original fd. This call is useful when we want to copy data out of disk images and suchlike, and want to be pass fds with the data around without having to keep the disk image continously mounted. The implementation tries to be somewhat smart and tries to prefer memfds/pipes over files in /tmp or /var/tmp based on the size of the data, but has appropropriate fallbacks in place.
* test-sizeof: show that a small 64 field is not enough to force the enum to ↵Zbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | | | | | be 64 bits On both 32 and 64 bits, the result is: enum Enum → 32 bits, unsigned enum BigEnum → 32 bits, unsigned enum BigEnum2 → 64 bits, unsigned big_enum2_pos → 4 big_enum2_neg → 8 The last two lines show that even if the enum is 64 bit, and the field of an enum is defined with UINT64_C(), the field can still be smaller.
* test-copy: remove unnecessary initializationZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | Initializing just some of the values doesn't make sense. We should handle them all in the same way. In those tests there are no jumps, all steps are covered with assert_se(), so we know everything will be set if we get to the end of the function. And _not_ initializing those variables has the advantage that it allows valgrind to catch potential initalization errors in the function being tested.
* tree-wide: do not wrap assert_se in extra parenthesesZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | We were inconsitently using them in some cases, but in majority not. Using assignment in assert_se is very common, not an exception like in 'if', so let's drop the extra parens everywhere.
* fs-util,test: add helper to remove tempfilesZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | This simplifies the use of tempfiles in tests and fixes "leaked" temporary files in test-fileio, test-catalog, test-conf-parser. Not the whole tree is converted.
* test: use _cleanup_hashmap_free_ instread of _cleanup_(hashmap_freep)Yu Watanabe2018-08-24
|
* test: do not call alloca() inside the list of argumentsYu Watanabe2018-08-24
|
* hexdecoct: ignore whitespace within the input hexadecimal text of unhexmem()Yu Watanabe2018-08-24
|
* conf-parser: accept trailing backslash at the end of the file (#8941)Filipe Brandenburger2018-08-24
| | | | | | | | | | This makes it behave the same whether there is a blank line or not at the end of the file. This is also consistent with the behavior of the shell on a shell script that ends on a trailing backslash at the last line. Added tests to test_config_parse(), which only pass if the corresponding change to config_parse() is included.
* test: add tests for signal_from_string()Yu Watanabe2018-08-24
|
* test: add tests for signal_from_string()Yu Watanabe2018-08-24
|
* test: add tests for signal_from_string()Yu Watanabe2018-08-24
|
* set: drop unused set_make() function (#8879)Yu Watanabe2018-08-24
| | | | | The function causes compiler error when built with '-Ddebug=hashmap', and is not used anymore. Let's drop it.
* parse-util: add explicit parsers for MTU valuesLennart Poettering2018-08-24
| | | | | | | | | We use MTUs all over the place, let's add a unified, strict parser for it, that takes MTU ranges into account. We already have parse_ifindex() close-by, hence this appears to be a natural addition, in particular as the range checking is not entirely trivial to do, as it depends on the protocol used.
* string-util: teach strip_tab_ansi() to deal with CSO sequencesLennart Poettering2018-08-24
| | | | | | | | With the recent terminal_urlify() APIs we'll now sometimes generate clickable link CSO sequences. Hence we should also be able to remove them again from strings. This beefs up the logic to do so. Follow-up for: 23b27b39d2a3a002ad827a2e8a9872a51495d797
* test: drop unused variablesYu Watanabe2018-08-24
| | | | Follow-up for 49eb36596b72e568d4b9b785cd4544e58c89bdee.
* tree-wide: drop spurious newlines (#8764)Lennart Poettering2018-08-24
| | | | | | | | | Double newlines (i.e. one empty lines) are great to structure code. But let's avoid triple newlines (i.e. two empty lines), quadruple newlines, quintuple newlines, …, that's just spurious whitespace. It's an easy way to drop 121 lines of code, and keeps the coding style of our sources a bit tigther.
* fs-util: add new CHASE_STEP flag to chase_symlinks()Lennart Poettering2018-08-24
| | | | | | | | If the flag is set only a single step of the normalization is executed, and the resulting path is returned. This allows callers to normalize piecemeal, taking into account every single intermediary path of the normalization.
* test-locale-util: show special glyphsZbigniew Jędrzejewski-Szmek2018-08-24
| | | | This is mostly useful as a sanity check.
* test-utf8: add a smoke test for utf8_console_width()Zbigniew Jędrzejewski-Szmek2018-08-24
|
* basic: add minimalistic table formatterLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | We have plenty of code in our codebase that outputs tables to the console, and all is homegrown and awful. Let's replace it with a generic implementation that can do automatically what the old implementations did manually. Features: 1. Ellipsation (for fields overly long) and alignment (for fields overly short) 2. Sorting of rows 3. automatically copies formatting from the same cell in the row above 4. Heavy use of varargs to make putting together tables easy 5. can expand and compress tables, with weights 6. Has a minimal understanding of unicode wide characters in order to match unicode strings to character cell terminals. 7. Columns can be reordered and individually turned off. 8. pretty printing for various data types And more.
* string-util: tweak ellipsation a bitLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | | | | This primarily changes to things: 1. Ellipsation to 0, 1 or 2 characters is now supported. Previously we'd hit an assert if the new lengths was < 3, this is now permitted. The result strings won't show too much info still of course, but the code becomes a bit more generic and robust to use. 2. If a UTF-8 mode is disabled and the input string is pure ASCII, then "..." is used for ellipsation, otherwise (as before) "…". This means on a pure-ASCII system we should remain pure-ASCII, matching behaviour otherwise exposed with special_glyph() and friends. Note that we'll use "…" for ellipsiation as soon as either the locale settings indicate an UTF-8 mode or the input string already contains non-ASCII unicode characters. Testing for these special cases is improved.
* util-lib: introduce new empty_or_root() helper (#8746)Lennart Poettering2018-08-24
| | | | | | | | We check the same condition at various places. Let's add a trivial, common helper for this, and use it everywhere. It's not going to make things much faster or much shorter, but I think a lot more readable
* test-execute: make find invocation a bit more efficent, increase timeoutZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | We go through the whole file system, so this test can take arbitrary time. But this test is still quite useful, so let's at least try to make it more efficent by not descending at all into the directories we would filter out later on anyway. Also increase the timeout, in case the previous step doesn't help enough.
* path-util: document a few other special cases for last_path_component()Lennart Poettering2018-08-24
|
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
* fd-util: introduce fd_reopen() helper for reopening an fdLennart Poettering2018-08-24
| | | | | | We have the same code for this in place at various locations, let's unify that. Also, let's repurpose test-fs-util.c as a test for this new helper cal..
* tree-wide: warn when a directory path already exists but has bad mode/owner/typeZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | | | | | | | | | | | | When we are attempting to create directory somewhere in the bowels of /var/lib and get an error that it already exists, it can be quite hard to diagnose what is wrong (especially for a user who is not aware that the directory must have the specified owner, and permissions not looser than what was requested). Let's print a warning in most cases. A warning is appropriate, because such state is usually a sign of borked installation and needs to be resolved by the adminstrator. $ build/test-fs-util Path "/tmp/test-readlink_and_make_absolute" already exists and is not a directory, refusing. (or) Directory "/tmp/test-readlink_and_make_absolute" already exists, but has mode 0775 that is too permissive (0755 was requested), refusing. (or) Directory "/tmp/test-readlink_and_make_absolute" already exists, but is owned by 1001:1000 (1000:1000 was requested), refusing. Assertion 'mkdir_safe(tempdir, 0755, getuid(), getgid(), MKDIR_WARN_MODE) >= 0' failed at ../src/test/test-fs-util.c:320, function test_readlink_and_make_absolute(). Aborting. No functional change except for the new log lines.
* basic/mkdir: convert bool flag to enumZbigniew Jędrzejewski-Szmek2018-08-24
| | | | In preparation for subsequent changes...