path: root/src/test
Commit message (Collapse)AuthorAge
* test: add test for 'thread safety' of libudevYu Watanabe2018-10-29
| | | | | | This adds a test for 715a970548d03fed18dc66c411c8b42ff21029cf. (cherry picked from commit cb3e926a5da4f73b48f71b541febe646bc1008d7)
* test: add tests for $SYSTEMD_MEMPOOL=Yu Watanabe2018-10-29
| | | | | | | This adds tests for b4f607433cac749b617e15b3d5d122322ed2bc71 and 205c085bc36c2c61a09dc40621d8561b135d9b57 (#9792). (cherry picked from commit 3ffd12bfbe9f91b392d80fbf6a8b2def2a13bf6d)
* basic/proc-cmdline: allow parsing of cmdline from a stringZbigniew Jędrzejewski-Szmek2018-10-29
| | | | | | | | | | | Comes with tests. Also add direct test for $SYSTEMD_PROC_CMDLINE. In test-proc-cmdline, "true" was masquerading as PROC_CMDLINE_STRIP_RD_PREFIX, fix that. Also, reorder functions to match call order. (cherry picked from commit 9a135c084ae6d06734ec3380f0eafdecd7c216f8)
* Introduce free_and_strndup and use it in bus-message.cZbigniew Jędrzejewski-Szmek2018-10-29
| | | | | | | | | | | | | | | | v2: fix error in free_and_strndup() When the orignal and copied message were the same, but shorter than specified length l, memory read past the end of the buffer would be performed. A test case is included: a string that had an embedded NUL ("q\0") is used to replace "q". v3: Fix one more bug in free_and_strndup and add tests. v4: Some style fixed based on review, one more use of free_and_replace, and make the tests more comprehensive. (cherry picked from commit 7f546026abbdc56c453a577e52d57159458c3e9c)
* exec-util: in execute_directories, support initial exec environmentDimitri John Ledkov2018-10-29
| | | | (cherry picked from commit 78ec1bb436fb18df3b56212c442cc4775a136d1a)
* importd, basic/string-util: use case-insensitive comparison for HTTP headersDongsu Park2018-10-29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | According to RFC2616[1], HTTP header names are case-insensitive. So it's totally valid to have a header starting with either `Date:` or `date:`. However, when systemd-importd pulls an image from an HTTP server, it parses HTTP headers by comparing header names as-is, without any conversion. That causes failures when some HTTP servers return headers with different combinations of upper-/lower-cases. An example: returns `Etag: "pe89so9oir60"`, while returns `ETag: "f03372edea9a1e7232e282c346099857"`. Since systemd-importd expects to see `ETag`, the etag for the Container Linux image is correctly interpreted as a part of the hidden file name. However, it cannot parse etag for Flatcar Linux, so the etag the Flatcar Linux image is not appended to the hidden file name. ``` $ sudo ls -al /var/lib/machines/ -r--r--r-- 1 root root 3303014400 Aug 21 20:07 '.raw-https:\x2f\x2falpha\x2erelease\x2ecore-os\x2enet\x2famd64-usr\x2fcurrent\x2fcoreos_developer_container\x2ebin\x2ebz2.\x22f03372edea9a1e7232e282c346099857\x22.raw' -r--r--r-- 1 root root 3303014400 Aug 17 06:15 '.raw-https:\x2f\x2falpha\x2erelease\x2eflatcar-linux\x2enet\x2famd64-usr\x2fcurrent\x2fflatcar_developer_container\x2ebin\x2ebz2.raw' ``` As a result, when the Flatcar image is removed and downloaded again, systemd-importd is not able to determine if the file has been already downloaded, so it always download it again. Then it fails to rename it to an expected name, because there's already a hidden file. To fix this issue, let's introduce a new helper function `memory_startswith_no_case()`, which compares memory regions in a case-insensitive way. Use this function in `curl_header_strdup()`. See also [1]: (cherry picked from commit 21224070e802878f81c342835364880ef1a63e88)
* test: add a reproducer of issue #9549Yu Watanabe2018-10-29
| | | | (cherry picked from commit a6e964712c53b877543cf18aff59ae99cffc1f50)
* Prep v239: Mask unneeded test in test-strip-ansiSven Eden2018-09-29
| | | | | | | | | | | | | | The final test use the outcome of the already masked part that utilizes terminal_urlify_path(). That function is masked, because it is nowhere used within elogind. The previously unmasked final test used the outcome of that already masked part and therefore crashed. Bug: Closes: Signed-of-by: Sven Eden <>
* Prep v239: Do not test terminal_urlify_path()Sven Eden2018-08-24
| | | | elogind doesn't need and thus does not support it.
* Prep v239: Do not test ioprio_class_from_to_string()Sven Eden2018-08-24
| | | | elogind doesn't need and thus does not support it.
* Prep v239: Mask unneedd tests test_copy_atomic() and assert_equal_fd()Sven Eden2018-08-24
* Prep v239: Remove os-util.[hc] - We do not need anything in there.Sven Eden2018-08-24
* Prep v239: Mask all unneeded functions in the new format-table.[hc] files.Sven Eden2018-08-24
* Prep v239: Unmask delete_chars()Sven Eden2018-08-24
* Prep v239: Fix conf-parser.[hc], it got a bit mangled by migration.Sven Eden2018-08-24
* Prep v239: Uncomment header inclusions that are new or needed now.Sven Eden2018-08-24
* Prep v239: Add missing updates that evaded migration.Sven Eden2018-08-24
* Build system: Fix various issues that came from errornous migration.Sven Eden2018-08-24
| | | | | | | No matter how much advanced is, there are plenty possibilities where upstream changes can be transported wrong. Mainly adding something we then have to mask out. But at the end of the day this is actually wanted, so we do not miss important changes.
* test-sizeof: another aproach to _Float128 availability detectionZbigniew Jędrzejewski-Szmek2018-08-24
* Drop copyrights tags for "systemd authors"Zbigniew Jędrzejewski-Szmek2018-08-24
* tree-wide: drop copyright headers from frequent contributorsZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | Fixes #9320. for p in Shapovalov Chevalier Rozhkov Sievers Mack Herrmann Schmidt Rudenberg Sahani Landden Andersen Watanabe; do git grep -e 'Copyright.*'$p -l|xargs perl -i -0pe 's|/([*][*])?[*]\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\s*[*]([*][*])?/\n*|\n|gms; s|\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\n*|\n|gms' done
* Correct a number of trivial typos.Chris Lamb2018-08-24
* Drop my copyright headersZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | perl -i -0pe 's/\s*Copyright © .... Zbigniew Jędrzejewski.*?\n/\n/gms' man/*xml git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/(#\n)?# +Copyright © [0-9, -]+ Zbigniew Jędrzejewski.*?\n//gms' git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/\s*\/\*\*\*\s+Copyright © [0-9, -]+ Zbigniew Jędrzejewski[^\n]*?\s*\*\*\*\/\s*/\n\n/gms' git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/\s+Copyright © [0-9, -]+ Zbigniew Jędrzejewski[^\n]*//gms'
* tree-wide: beautify remaining copyright statementsLennart Poettering2018-08-24
| | | | | | Let's unify an beautify our remaining copyright statements, with a unicode ©. This means our copyright statements are now always formatted the same way. Yay.
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-08-24
| | | | | | | | | | | These lines are generally out-of-date, incomplete and unnecessary. With SPDX and git repository much more accurate and fine grained information about licensing and authorship is available, hence let's drop the per-file copyright notice. Of course, removing copyright lines of others is problematic, hence this commit only removes my own lines and leaves all others untouched. It might be nicer if sooner or later those could go away too, making git the only and accurate source of authorship information.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | This part of the copyright blurb stems from the GPL use recommendations: The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.
* copy: rework copy_file_atomic() to copy the specified file via O_TMPFILE if ↵Lennart Poettering2018-08-24
| | | | possible
* 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
* 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:
* 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.