path: root/src/test
Commit message (Collapse)AuthorAge
* 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...
* coccinelle: always use fcntl(fd, FD_DUPFD, 3) instead of dup(fd)Lennart Poettering2018-08-24
| | | | Let's avoid fds 0…2 for safety reasons.
* journal: make the compression threshold tunableAlex Gartrell2018-08-24
| | | | | Allow a user to set a number of bytes as Compress to use as the compression threshold.
* conf-parser: accept trailing backslash at the end of the file (#8941)Filipe Brandenburger2018-06-28
| | | | | | | | | | | | 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. (cherry picked from commit 4f29e0db127dce9e1a28af4d7bf88c124ba257b7)
* tests: make / private after creating a mount namespaceEvegeny Vereshchagin2018-06-28
| | | | | | so that the test never affects the root namespace. (cherry picked from commit c58fd466a313a1f93df1792822e358c67990bcdf)
* Prep v238: Uncomment now needed headers and unmask now needed functions in ↵Sven Eden2018-06-05
| | | | src/test (6/6)
* Prep v238: Remove obsolete sources and add missing new ones.Sven Eden2018-06-05
* Prep v238: Fixed files in src/shared and src/testSven Eden2018-06-04
* fd-util: add new call rearrange_stdio()Lennart Poettering2018-05-30
| | | | | | | | | | | | | | | | | | | Quite often we need to set up a number of fds as stdin/stdout/stderr of a process we are about to start. Add a generic implementation for a routine doing that that takes care to do so properly: 1. Can handle the case where stdin/stdout/stderr where previously closed, and the fds to set as stdin/stdout/stderr hence likely in the 0..2 range. handling this properly is nasty, since we need to first move the fds out of this range in order to later move them back in, to make things fully robust. 2. Can optionally open /dev/null in case for one or more of the fds, in a smart way, sharing the open file if possible between multiple of the fds. 3. Guarantees that O_CLOEXEC is not set on the three fds, even if the fds already were in the 0..2 range and hence possibly weren't moved.
* procfs-util: add APIs to get consumed CPU time and used memory from /procLennart Poettering2018-05-30
| | | | | | This is preparation for emulating the "usage_usec" keyed attribute of the "cpu.stat" property of the root cgroup from data in /proc. Similar, for emulating the "memory.current" attribute.
* khash: try to detect broken AF_ALG support in centos kernelsLennart Poettering2018-05-30
| | | | Fixes: #8278
* basic/log: make sure header is printed correctly, add testZbigniew Jędrzejewski-Szmek2018-05-30
| | | | | | | | | | | | | | | | | | If log_do_header() was called with overly long parameters, it'd generate improper output. Essentially, it'd be truncated at random point, in particular missing a newline at the end, so it'd run with the next field, usually MESSAGE=. log_do_header is called with parameters from compiled code (file name, lien nubmer, etc), so in practice this was unlikely to ever be a problem, but it is possible. In particular, if systemd was compiled from sources in some deeply nested directory (which happens for example in mock and other build roots), the filename could be very long. As a safety measure, let's truncate all parameters to 256 bytes. So we have 5 fields which are 256 bytes (plus the field name prefix), and a few other fields with fixed width. This must always fit in the 2048 byte buffer. I don't think there's much gain in calculating the required length precisely, since it's a lot of fields and a few bytes allocated on the stack don't matter.
* Fix format-truncation compile failure by typecasting USB IDs (#8250)Patrick Uiterwijk2018-05-30
| | | | | | | | | | | | | | | This patch adds safe_atoux16 for parsing an unsigned hexadecimal 16bit int, and uses that for parsing USB device and vendor IDs. This fixes a compile error with gcc-8 because while we know that USB IDs are 2 bytes, the compiler does not know that. ../src/udev/udev-builtin-hwdb.c:80:38: error: '%04X' directive output may be truncated writing between 4 and 8 bytes into a region of size between 2 and 6 [-Werror=format-truncation=] Signed-off-by: Adam Williamson <> Signed-off-by: Patrick Uiterwijk <>
* test-user-util: skip most tests for nobody if synthentization is offZbigniew Jędrzejewski-Szmek2018-05-30
| | | | | | | | | | | | When synthetisation is turned off, there's just too many ways those tests can go wrong. We are not interested in verifying that the db on disk is correct, let's just skip all checks. In the first version of this patch, I recorded if we detected a mismatch during configuration and only skipped tests in that case, but actually it is possible to change the host configuration between our configuration phase and running of the tests. It's just more robust to skip always. (This is particularly true if tests are installed.)
* test-user-util: print function delimitersZbigniew Jędrzejewski-Szmek2018-05-30
| | | | | | This makes it easier to see what is going on. Crashes may happen in a nested test_{uid,gid}_to_name_one() function, and the default backtrace doesn't show the actual string being tested.
* fs-util: move fsync_directory_of_file() into generic codeLennart Poettering2018-05-30
| | | | | This function used by the journal code is pretty useful generically, let's move it to fs-util.c to make it useful for other code too.
* tests: add a simple test for utf8_n_codepoints()Zbigniew Jędrzejewski-Szmek2018-05-30
* pid1: do not initialize join_controllers by defaultZbigniew Jędrzejewski-Szmek2018-05-30
| | | | | We're moving towards unified cgroup hierarchy where this is not necessary. This makes main.c a bit simpler.
* Move config_parse_join_controllers to shared, add testZbigniew Jędrzejewski-Szmek2018-05-30
| | | | | | config_parse_join_controllers would free the destination argument on failure, which is contrary to our normal style, where failed parsing has no effect. Moving it to shared also allows a test to be added.
* test-process-util: one more (void)Zbigniew Jędrzejewski-Szmek2018-05-30
* hash-func: add generic hash_ops implementation for hashing pathsLennart Poettering2018-05-30
| | | | | | | | | | | | | | | This is similar to string_hash_ops but operates one file system paths specifically. It will ensure that "/foo//bar" and "///foo/bar" are considered to be the same path for hashmap purposes. This makes use of the existing path_compare() API, and adds a matching hashing function for it. Note that relative and absolute paths will hash to different values, however whether the path is suffixed with a slash or not is not detected. This matches the existing path_compare() behaviour, and follows the logic that on Linux there can't be two different objects at path /foo/bar and /foo/bar/ either.
* fs-util: drop readlink_and_canonicalize()Yu Watanabe2018-05-30
* fd-util: move certain fds above fd #2 (#8129)Lennart Poettering2018-05-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds some paranoia code that moves some of the fds we allocate for longer periods of times to fds > 2 if they are allocated below this boundary. This is a paranoid safety thing, in order to avoid that external code might end up erroneously use our fds under the assumption they were valid stdin/stdout/stderr. Think: some app closes stdin/stdout/stderr and then invokes 'fprintf(stderr, …' which causes writes on our fds. This both adds the helper to do the moving as well as ports over a number of users to this new logic. Since we don't want to litter all our code with invocations of this I tried to strictly focus on fds we keep open for long periods of times only and only in code that is frequently loaded into foreign programs (under the assumptions that in our own codebase we are smart enough to always keep stdin/stdout/stderr allocated to avoid this pitfall). Specifically this means all code used by NSS and our sd-xyz API: 1. our logging APIs 2. sd-event 3. sd-bus 4. sd-resolve 5. sd-netlink This changed was inspired by this: This shows that apparently IRL there are programs that do close stdin/stdout/stderr, and we should accomodate for that. Note that this won't fix any bugs, this just makes sure that buggy programs are less likely to interfere with out own code.
* test-hashmap: test IteratedCacheVito Caputo2018-05-30
| | | | Add some rudimentary testing of the new IteratedCache