summaryrefslogtreecommitdiff
path: root/src/test/test-util.c
Commit message (Collapse)AuthorAge
* 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
* 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: https://www.gnu.org/licenses/gpl-howto.en.html 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.
* 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.
* 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.
* Prep v238: Uncomment now needed headers and unmask now needed functions in ↵Sven Eden2018-06-05
| | | | src/test (6/6)
* log: minimize includes in log.hLennart Poettering2018-05-30
| | | | | | | | | | | | | | | | | | | | | | | | | | log.h really should only include the bare minimum of other headers, as it is really pulled into pretty much everything else and already in itself one of the most basic pieces of code we have. Let's hence drop inclusion of: 1. sd-id128.h because it's entirely unneeded in current log.h 2. errno.h, dito. 3. sys/signalfd.h which we can replace by a simple struct forward declaration 4. process-util.h which was needed for getpid_cached() which we now hide in a funciton log_emergency_level() instead, which nicely abstracts the details away. 5. sys/socket.h which was needed for struct iovec, but a simple struct forward declaration suffices for that too. Ultimately this actually makes our source tree larger (since users of the functionality above must now include it themselves, log.h won't do that for them), but I think it helps to untangle our web of includes a tiny bit. (Background: I'd like to isolate the generic bits of src/basic/ enough so that we can do a git submodule import into casync for it)
* Prep v236 : Add missing SPDX-License-Identifier (8/9) src/testSven Eden2018-03-26
|
* test-util: silence clang warning about unaligned accessZbigniew Jędrzejewski-Szmek2017-11-01
|
* Prep v233.3: Add all possible coverage tests for elogindSven Eden2017-07-20
|
* Remove src/testAndy Wingo2015-04-19
|
* util: rework word parsing and c unescaping codeLennart Poettering2015-03-26
| | | | | | | | | | | When parsing words from input files, optionally automatically unescape the passed strings, controllable via a new flags parameter. Make use of this in tmpfiles, and port everything else over, too. This improves parsing quite a bit, since we no longer have to process the same string multiple times with different calls, where an earlier call might corrupt the input for a later call.
* test-util: remove superfluous constThomas Hindoe Paaboel Andersen2015-02-12
|
* util: rework strappenda(), and rename it strjoina()Lennart Poettering2015-02-03
| | | | | | After all it is now much more like strjoin() than strappend(). At the same time, add support for NULL sentinels, even if they are normally not necessary.
* tests: use assert_se instead of assertRonny Chevalier2015-01-22
| | | | Otherwise they can be optimized away with -DNDEBUG
* Assorted format fixesZbigniew Jędrzejewski-Szmek2015-01-22
| | | | | Types used for pids and uids in various interfaces are unpredictable. Too bad.
* util: make http url validity checks more generic, and move them to util.cLennart Poettering2015-01-20
|
* import-raw: when downloading raw images, generate sparse files if we canLennart Poettering2015-01-19
|
* shared/util: respect buffer boundary on incomplete escape sequencesZbigniew Jędrzejewski-Szmek2015-01-11
| | | | | | | | | | cunescape_length_with_prefix() is called with the length as an argument, so it cannot rely on the buffer being NUL terminated. Move the length check before accessing the memory. When an incomplete escape sequence was given at the end of the buffer, c_l_w_p() would read past the end of the buffer. Fix this and add a test.
* test-util: make sure that masking and overriding worksZbigniew Jędrzejewski-Szmek2015-01-11
|
* Implement masking and overriding of generatorsZbigniew Jędrzejewski-Szmek2015-01-11
| | | | | | | | | | | | | | | | | | | | | | Sometimes it is necessary to stop a generator from running. Either because of a bug, or for testing, or some other reason. The only way to do that would be to rename or chmod the generator binary, which is inconvenient and does not survive upgrades. Allow masking and overriding generators similarly to units and other configuration files. For the systemd instance, masking would be more common, rather than overriding generators. For the user instances, it may also be useful for users to have generators in $XDG_CONFIG_HOME to augment or override system-wide generators. Directories are searched according to the usual scheme (/usr/lib, /usr/local/lib, /run, /etc), and files with the same name in higher priority directories override files with the same name in lower priority directories. Empty files and links to /dev/null mask a given name. https://bugs.freedesktop.org/show_bug.cgi?id=87230
* Simplify execute_directory()Zbigniew Jędrzejewski-Szmek2015-01-11
| | | | | | | | | Remove the optional sepearate opening of the directory, it would be just too complicated with the change to multiple directories. Move the middle of execute_directory() to a seperate function to make it easier to grok.
* logind: unify how we cast between uid_t and pointers for hashmap keysLennart Poettering2015-01-09
|
* util: make use of kcmp() to compare fds, if it is availableLennart Poettering2015-01-07
|
* macro: add DIV_ROUND_UP()David Herrmann2014-12-30
| | | | | | | | | | | | | | | | This macro calculates A / B but rounds up instead of down. We explicitly do *NOT* use: (A + B - 1) / A as it suffers from an integer overflow, even though the passed values are properly tested against overflow. Our test-cases show this behavior. Instead, we use: A / B + !!(A % B) Note that on "Real CPUs" this does *NOT* result in two divisions. Instead, instructions like idivl@x86 provide both, the quotient and the remainder. Therefore, both algorithms should perform equally well (I didn't verify this, though).
* test: wait for cloned thread to exitFilipe Brandenburger2014-12-25
| | | | | | | | | | | | | | | | | | In test_raw_clone, make sure the cloned thread calls _exit() and in the parent thread call waitpid(..., __WCLONE) to wait for the child thread to terminate, otherwise there is a race condition where the child thread will log to the console after the test process has already exited and the assertion from the child thread might not be enforced. The absence of this patch might also create problems for other tests that would be added after this one, since potentially both parent and child would run those tests as the child would continue running. Tested by confirming that the logs from the child are printed before the test terminates and that a false assertion in the child aborts the test with a core dump. [zj: also add check for the return value.]
* test: only use assert_se in test_raw_cloneFilipe Brandenburger2014-12-25
| | | | The asserts used in the tests should never be allowed to be optimized away.
* Treat a trailing backslash as an errorZbigniew Jędrzejewski-Szmek2014-12-18
| | | | | | | | | | | | | | | | | | Commit a2a5291b3f5 changed the parser to reject unfinished quoted strings. Unfortunately it introduced an error where a trailing backslash would case an infinite loop. Of course this must fixed, but the question is what to to instead. Allowing trailing backslashes and treating them as normal characters would be one option, but this seems suboptimal. First, there would be inconsistency between handling of quoting and of backslashes. Second, a trailing backslash is most likely an error, at it seems better to point it out to the user than to try to continue. Updated rules: ExecStart=/bin/echo \\ → OK, prints a backslash ExecStart=/bin/echo \ → error ExecStart=/bin/echo "x → error ExecStart=/bin/echo "x"y → error
* core: use raw_clone instead of fork in signal handlerZbigniew Jędrzejewski-Szmek2014-12-18
| | | | | | | | | | | | fork() is not async-signal-safe and calling it from the signal handler could result in a deadlock when at_fork() handlers are called. Using the raw clone() syscall sidesteps that problem. The tricky part is that raise() does not work, since getpid() does not work. Add raw_getpid() to get the real pid, and use kill() instead of raise(). https://bugs.freedesktop.org/show_bug.cgi?id=86604
* util: when using basename() for creating temporary files, verify the ↵Lennart Poettering2014-12-12
| | | | | | | | resulting name is actually valid Also, rename filename_is_safe() to filename_is_valid(), since it actually does a full validation for what the kernel will accept as file name, it's not just a heuristic.
* test: fix some tests when running inside a containerJan Synacek2014-12-10
|
* sd-bus: get rid of PID starttime conceptLennart Poettering2014-12-09
| | | | As kdbus no longer exports this, remove all traces from sd-bus too
* util: add function getting proc environJakub Filak2014-11-27
| | | | | On the contrary of env, the added function returns all characters cescaped, because it improves reproducibility.
* util: add functions getting proc cwd and rootJakub Filak2014-11-21
| | | | | | | /proc/[pid]/cwd and /proc/[pid]/root are symliks to corresponding directories The added functions returns values of that symlinks.
* tests: fix minor memory leakLennart Poettering2014-11-20
|
* util: rework /proc/cmdline parser to use unquote_first_word()Lennart Poettering2014-11-07
|
* test: only use assert_seThomas Hindoe Paaboel Andersen2014-10-04
| | | | | The asserts used in the tests should never be allowed to be optimized away
* util: add alloca_align()David Herrmann2014-09-22
| | | | | | | | | | The alloca_align() helper is the alloca() equivalent of posix_memalign(). As there is no such function provided by glibc, we simply account for additional memory and return a pointer offset into the allocated memory to grant the alignment. Furthermore, alloca0_align() is added, which simply clears the allocated memory.
* test-util: make valgrind happyDavid Herrmann2014-09-22
| | | | | Properly free all temporary resources to make valgrind not complain about lost records.
* test: fix mem-leak in fdopen() testDavid Herrmann2014-09-11
| | | | | | We must free FILE* after function return to not leak resources. Note that this also closes our fd as fdopen() takes ownership of it. Reported by Philippe De Swert (via coverity).
* macro: use unique variable names for math-macrosDavid Herrmann2014-08-28
| | | | | | | | | | | | | Similar to container_of(), we now use unique variable names for the bascic math macros MAX, MIN, CLAMP, LESS_BY. Furthermore, unit tests are added to verify they work as expected. For a rationale, see: commit fb835651aff79a1e7fc5795086c9b26e59a8e6ca Author: David Herrmann <dh.herrmann@gmail.com> Date: Fri Aug 22 14:41:37 2014 +0200 shared: make container_of() use unique variable names
* shared: make container_of() use unique variable namesDavid Herrmann2014-08-27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If you stack container_of() macros, you will get warnings due to shadowing variables of the parent context. To avoid this, use unique names for variables. Two new helpers are added: UNIQ: This evaluates to a truly unique value never returned by any evaluation of this macro. It's a shortcut for __COUNTER__. UNIQ_T: Takes two arguments and concatenates them. It is a shortcut for CONCATENATE, but meant to defined typed local variables. As you usually want to use variables that you just defined, you need to reference the same unique value at least two times. However, UNIQ returns a new value on each evaluation, therefore, you have to pass the unique values into the macro like this: #define my_macro(a, b) __max_macro(UNIQ, UNIQ, (a), (b)) #define __my_macro(uniqa, uniqb, a, b) ({ typeof(a) UNIQ_T(A, uniqa) = (a); typeof(b) UNIQ_T(B, uniqb) = (b); MY_UNSAFE_MACRO(UNIQ_T(A, uniqa), UNIQ_T(B, uniqb)); }) This way, MY_UNSAFE_MACRO() can safely evaluate it's arguments multiple times as they are local variables. But you can also stack invocations to the macro my_macro() without clashing names. This is the same as if you did: #define my_macro(a, b) __max_macro(__COUNTER__, __COUNTER__, (a), (b)) #define __my_macro(prefixa, prefixb, a, b) ({ typeof(a) CONCATENATE(A, prefixa) = (a); typeof(b) CONCATENATE(B, prefixb) = (b); MY_UNSAFE_MACRO(CONCATENATE(A, prefixa), CONCATENATE(B, prefixb)); }) ...but in my opinion, the first macro is easier to write and read. This patch starts by converting container_of() to use this new helper. Other macros may follow (like MIN, MAX, CLAMP, ...).
* test-util: use assert_se() for call to safe_mkdir with side effectFilipe Brandenburger2014-08-26
| | | | | | | Otherwise it gets optimized out when CPPFLAGS='-DNDEBUG' is used. Tested: - make check TESTS='test-util' CPPFLAGS='-DNDEBUG'
* shared: add MAXSIZE() and use it in resolvedDavid Herrmann2014-08-22
| | | | | | | | | | | The MAXSIZE() macro takes two types and returns the size of the larger one. It is much simpler to use than MAX(sizeof(A), sizeof(B)) and also avoids any compiler-extensions, unlike CONST_MAX() and MAX() (which are needed to avoid evaluating arguments more than once). This was suggested by Daniele Nicolodi <daniele@grinta.net>. Also make resolved use this macro instead of CONST_MAX(). This enhances readability quite a bit.
* CONST_MAX breaks gcc on fedora 20 with optimiztationLennart Poettering2014-08-20
|
* sysusers: add another column to sysusers files for the home directoryLennart Poettering2014-08-19
|
* tests: add tests for util.cRonny Chevalier2014-08-18
| | | | | | | | | | | add tests for: - is_symlink - pid_is_unwaited - pid_is_alive - search_and_fopen - search_and_fopen_nulstr - glob_exists - execute_directory
* macro: add CONST_MAX() macroDavid Herrmann2014-08-15
| | | | | | | | | | | | | | | The CONST_MAX() macro is similar to MAX(), but verifies that both arguments have the same type and are constant expressions. Furthermore, the result of CONST_MAX() is again a constant-expression. CONST_MAX() avoids any statement-expressions and other non-trivial expression-types. This avoids rather arbitrary restrictions in both GCC and LLVM, which both either fail with statement-expressions inside type-declarations or statement-expressions inside static-const initializations. If anybody knows how to circumvent this, please feel free to unify CONST_MAX() and MAX().
* test: fix strtod test for realDavid Herrmann2014-08-15
| | | | | | | | The "0,5" syntax was actually right. The real problem is, the test should only run if the local system has the de_DE.UTF-8 locale. Therefore, skip the tests if setlocale() fails. This is kinda ugly, as it is done silently, but we cannot skip partial tests with the current infrastructure. Should be fine this way.