summaryrefslogtreecommitdiff
path: root/src/tests
Commit message (Collapse)AuthorAgeFilesLines
* libnm/match: extend syntax for match patterns with '|', '&', '!' and '\\'Thomas Haller2020-06-261-1/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For simple matches like match.interface-name, match.driver, and match.path, arguably what we had was fine. There each element (like "eth*") is a wildcard for a single name (like "eth1"). However, for match.kernel-command-line, the elements match individual command line options, so we should have more flexibility of whether a parameter is optional or mandatory. Extend the syntax for that. - the elements can now be prefixed by either '|' or '&'. This makes optional or mandatory elements, respectively. The entire match evaluates to true if all mandatory elements match (if any) and at least one of the optional elements (if any). As before, if neither '|' nor '&' is specified, then the element is optional (that means, "foo" is the same as "|foo"). - the exclamation mark is still used to invert the match. If used alone (like "!foo") it is a shortcut for defining a mandatory match ("&!foo"). - the backslash can now be used to escape the special characters above. Basically, the special characters ('|', '&', '!') are stripped from the start of the element. If what is left afterwards is a backslash, it also gets stripped and the remainder is the pattern. For example, "\\&foo" has the pattern "&foo" where '&' is no longer treated specially. This special handling of the backslash is only done at the beginning of the element (after the optional special characters). The remaining string is part of the pattern, where backslashes might have their own meaning. This change is mostly backward compatible, except for existing matches that started with one of the special characters '|', '&', '!', and '\\'. (cherry picked from commit 824ad6275df1f00daa57a002c46a87257ef218a2)
* core/tests: add unit test for nm_utils_kernel_cmdline_match_check()Thomas Haller2020-06-261-0/+34
| | | | (cherry picked from commit fa56e52a4f07a33408d3f3b47bbbc80d63c03c60)
* all: reformat python files with python blackSayed Shah2020-06-151-16/+35
| | | | | | Part of !537. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/537
* meson: merge branch 'inigomartinez/meson-license'Thomas Haller2020-03-282-0/+4
|\ | | | | | | | | | | | | | | | | | | Add SPDX license headers for meson files. As far as I can tell, according to RELICENSE.md file, almost everybody who contributed to the meson files agreed to the LGPL-2.1+ licensing. This entails the vast majority of code in question. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/397
| * license: Add license using SPDX identifiers to meson build filesIñigo Martínez2020-02-172-0/+4
| | | | | | | | | | License is missing in meson build files. This has been added using SPDX identifiers and licensed under LGPL-2.1+.
* | tests: replace NMTST_SWAP() by new NM_SWAP() macroThomas Haller2020-03-262-2/+2
| | | | | | | | | | | | | | NMTST_SWAP() used memcpy() for copying the value, while NM_SWAP() uses a temporary variable with typeof(). I think the latter is preferable. Also, the macro is essentially doing the same thing.
* | all: use nm_clear_g_free() instead of g_clear_pointer()Thomas Haller2020-03-231-3/+3
| | | | | | | | | | | | | | | | | | I think it's preferable to use nm_clear_g_free() instead of g_clear_pointer(, g_free). The reasons are not very strong, but I think it is overall preferable to have a shorthand for this frequently used functionality. sed 's/\<g_clear_pointer *(\([^;]*\), *\(g_free\) *)/nm_clear_g_free (\1)/g' $(git grep -l g_clear_pointer) -i
* | all: unify spelling of "fall-through" comment for switch statementsThomas Haller2020-02-211-2/+2
|/ | | | | We used "/* fall through */" and "/* fall-through */" inconsistently. Rename to use only one variant.
* all: rename time related function to spell out nsec/usec/msec/secThomas Haller2019-12-132-9/+9
| | | | | | The abbreviations "ns" and "ms" seem not very clear to me. Spell them out to nsec/msec. Also, in parts we already used the longer abbreviations, so it wasn't consistent.
* core: fix IAID endianness in client-id generation testBeniamino Galvani2019-12-021-1/+3
| | | | | | Fixes: 6f16e524be3c ('core: support ipvX.dhcp-iaid properties') https://bugzilla.redhat.com/show_bug.cgi?id=1778640
* core: remove 'legacy_unstable_byteorder' argument from client-id helpersBeniamino Galvani2019-12-021-2/+1
| | | | | The argument has no effect because the order only influences IAID generation.
* shared: add nm_utils_monotonic_timestamp_from_boottime() utilThomas Haller2019-11-201-0/+3
| | | | | We sometimes have a CLOCK_BOOTTIME and need to convert it to NetworkManager's monotonic timestamps.
* core: support ipvX.dhcp-iaid propertiesBeniamino Galvani2019-11-111-2/+3
|
* all: unify format of our Copyright source code commentsThomas Haller2019-10-023-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ```bash readarray -d '' FILES < <( git ls-files -z \ ':(exclude)po' \ ':(exclude)shared/c-rbtree' \ ':(exclude)shared/c-list' \ ':(exclude)shared/c-siphash' \ ':(exclude)shared/c-stdaux' \ ':(exclude)shared/n-acd' \ ':(exclude)shared/n-dhcp4' \ ':(exclude)src/systemd/src' \ ':(exclude)shared/systemd/src' \ ':(exclude)m4' \ ':(exclude)COPYING*' ) sed \ -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[-–] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C1pyright#\5 - \7#\9/' \ -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[,] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C2pyright#\5, \7#\9/' \ -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C3pyright#\5#\7/' \ -e 's/^Copyright \(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/C4pyright#\1#\3/' \ -i \ "${FILES[@]}" echo ">>> untouched Copyright lines" git grep Copyright "${FILES[@]}" echo ">>> Copyright lines with unusual extra" git grep '\<C[0-9]pyright#' "${FILES[@]}" | grep -i reserved sed \ -e 's/\<C[0-9]pyright#\([^#]*\)#\(.*\)$/Copyright (C) \1 \2/' \ -i \ "${FILES[@]}" ``` https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/298
* meson: Improve the src build fileIñigo Martínez2019-10-012-10/+14
| | | | | | | | | | | | The targets that involve the use of the `NetworkManager` library, built in the `src` build file have been improved by applying a set of changes: - Indentation has been fixed. - Set of objects used in targets have been grouped together. - Aritificial dependencies used to group dependencies and custom compiler flags have been removed and their use replaced with proper dependencies and compiler flags to avoid any confussion.
* meson: Use dependency for nm-default headerIñigo Martínez2019-10-011-2/+1
| | | | | | | | | | | | | The `nm-default.h` header is used widely in the code by many targets. This header includes different headers and needs different libraries depending the compilation flags. A new set of `*nm_default_dep` dependencies have been created to ease the inclusion of different directorires and libraries. This allows cleaner build files and avoiding linking unnecessary libraries so this has been applied allowing the removal of some dependencies involving the linking of unnecessary libraries.
* all: manually drop code comments with file descriptionThomas Haller2019-10-0110-12/+2
|
* core: log the content of "/var/lib/NetworkManager/no-auto-default.state"Thomas Haller2019-09-261-1/+1
| | | | | | To understand why a profile gets not created, it's necessary to see the content of "/var/lib/NetworkManager/no-auto-default.state". Log it.
* all: SPDX header conversionLubomir Rintel2019-09-1011-154/+11
| | | | | $ find * -type f |xargs perl contrib/scripts/spdx.pl $ git rm contrib/scripts/spdx.pl
* core/tests: avoid deprecated g_main_run()/g_main_loop_unref() in testThomas Haller2019-09-031-3/+2
| | | | | | | | | These are deprecated. Also, they are nowadays implemented as macros that expand to #define g_main_run(loop) g_main_loop_run(loop) GLIB_DEPRECATED_MACRO_IN_2_26_FOR(g_main_loop_run) This can cause compilation failure (in some environments).
* core: fix adding objects to NMIPConfig with @append_forceBeniamino Galvani2019-08-281-3/+1
| | | | | | | If the @append_force argument is set and the object is already in the list, it must be moved at the end. Fixes: 22edeb5b691b ('core: track addresses for NMIP4Config/NMIP6Config via NMDedupMultiIndex')
* core: add test to show nm_ipX_config_replace() bugBeniamino Galvani2019-08-281-0/+44
| | | | | | | | Add test to show a wrong result of ip_ipX_config_replace() due to a bug in _nm_ip_config_add_obj(). When an address is added to the tail of the index and another address with the same id already exists, the existing object is left at the same place, breaking the order of addresses.
* src/tests: show exit status in test failure of test_nm_utils_kill_child()Thomas Haller2019-06-131-1/+6
| | | | | This test keeps randomly failing. Rework is, so that we see the actual exit status in the output of the failed test.
* all: drop emacs file variables from source filesThomas Haller2019-06-1112-12/+0
| | | | | | | | | | | | | | | | | | | | | | We no longer add these. If you use Emacs, configure it yourself. Also, due to our "smart-tab" usage the editor anyway does a subpar job handling our tabs. However, on the upside every user can choose whatever tab-width he/she prefers. If "smart-tabs" are used properly (like we do), every tab-width will work. No manual changes, just ran commands: F=($(git grep -l -e '-\*-')) sed '1 { /\/\* *-\*- *[mM]ode.*\*\/$/d }' -i "${F[@]}" sed '1,4 { /^\(#\|--\|dnl\) *-\*- [mM]ode/d }' -i "${F[@]}" Check remaining lines with: git grep -e '-\*-' The ultimate purpose of this is to cleanup our files and eventually use SPDX license identifiers. For that, first get rid of the boilerplate lines.
* tests/trivial: rename nmtst_get_rand_int() to nmtst_get_rand_uint32()Thomas Haller2019-06-113-16/+16
| | | | | | | | nmtst_get_rand_int() was originally named that way, because it calls g_rand_int(). But I think if a function returns an uint32, it should also be named that way. Rename.
* src/tests: rename core's "test-general*" to "test-core*"Thomas Haller2019-05-193-5/+5
|
* logging: use static buffer in nm_logging_all_domains_to_string()Thomas Haller2019-05-171-0/+13
| | | | | | | | | | | | | | | | | | | | | Don't create a heap allocated GString to hold the static result of nm_logging_all_domains_to_string(). Instead, use a static buffer of the exactly required size. The main reason to do this, is to get the exact size of "_all_logging_domains_to_str" buffer. This is the upper boundary for the size of a string buffer to hold all domain names. We will need that boundary in the next commit. The attractive thing here is that we will have a unit-test failure if this boundery no longer matches (--with-more-asserts). That means, this boundary is guarded by unit tests and we don't accidentally get it wrong when the domains change. Also, take care to initialize the buffer in a thread-safe manner. It's easy enough to get right, so there is no excuse for having non-thread-safe code in logging.
* build/meson: rename "nm_core_dep" to "libnm_core_dep"Thomas Haller2019-04-181-1/+1
| | | | | | | The library is called "libnm_core". So the dependency should be called "libnm_core_dep", like in all other cases. (cherry picked from commit c27ad37c278461fd783b6db56844683ab3088345)
* libnm,shared: bzero secrets on failure in nm_utils_base64secret_decode()Thomas Haller2019-04-121-3/+3
| | | | | Now that unbase64mem_full() understands a secure flag, we can get this right.
* core: assert for valid NM_DEVICE_DEVICE_TYPE settingThomas Haller2019-03-111-0/+1
| | | | (cherry picked from commit 7dd44d6dc894ac262f6825d1b992376a92f9f1e5)
* build/meson: increase timeouts for some testsThomas Haller2019-02-232-0/+2
| | | | | | | | | | | | | | | | | | The defaults for test timeouts in meson is 30 seconds. That is not long enough when running $ NMTST_USE_VALGRIND=1 ninja -C build test Note that meson supports --timeout-multiplier, and automatically increases the timeout when running under valgrind. However, meson does not understand that we are running tests under valgrind via NMTST_USE_VALGRIND=1 environment variable. Timeouts are really not expected to be reached and are a mean of last resort. Hence, increasing the timeout to a large value is likely to have no effect or to fix test failures where the timeout was too rigid. It's unlikely that the test indeed hangs and the increase of timeout causes a unnecessary increase of waittime before aborting.
* all: move nm_utils_bin2hexstr_full() to sharedBeniamino Galvani2019-02-211-5/+5
| | | | reuse++
* systemd: define strerror() in sd-adapt header to nm_strerror_native()Thomas Haller2019-02-121-0/+6
| | | | | Systemd uses strerror() extensively. Patch the function to use the thread-safe nm_strerror_native().
* all: cache errno in local variable before using itThomas Haller2019-02-121-1/+2
|
* all: drop unnecessary includes of <errno.h> and <string.h>Thomas Haller2019-02-127-12/+0
| | | | | "nm-macros-interal.h" already includes <errno.h> and <string.h>. No need to include it everywhere else too.
* tests: avoid "-Wmissing-braces" warning in ↵Thomas Haller2019-02-081-2/+2
| | | | | | | | | | | | | test_nm_utils_dhcp_client_id_systemd_node_specific() [1/2] Compiling C object 'src/tests/a4ccf2d@@test-general@exe/test-general.c.o'. ../src/tests/test-general.c: In function ‘test_nm_utils_dhcp_client_id_systemd_node_specific’: ../src/tests/test-general.c:2056:16: warning: missing braces around initializer [-Wmissing-braces] } d_array[] = { ^ ../src/tests/test-general.c:2058:20: .machine_id = { 0xcb, 0xc2, 0x2e, 0x47, 0x41, 0x8e, 0x40, 0x2a, 0xa7, 0xb3, 0x0d, 0xea, 0x92, 0x83, 0x94, 0xef }, {
* tests: avoid "-Wduplicate-decl-specifier" warning in ↵Thomas Haller2019-02-081-1/+1
| | | | | | | | | | | | | | | test_duplicate_decl_specifier() The test should check the behavior with "const typeof(a)" in a macro, where "a" itself is const. For that we don't need a double const declaration of v2. Also, that fixes an actual compiler warning: ../src/tests/test-general.c: In function ‘test_duplicate_decl_specifier’: ../src/tests/test-general.c:1669:8: warning: duplicate ‘const’ declaration specifier [-Wduplicate-decl-specifier] const const int v2 = 3; ^~~~~
* logging: make nm-logging thread-safeThomas Haller2019-02-051-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | NetworkManager is single-threaded and uses a mainloop. However, sometimes we may need multiple threads. For example, we will need to write sysctl values asynchronously, using the glib thread-pool. For that to work, we also need to switch the network-namespace of the thread-pool thread. We want to use NMPNetns for that. Hence it's better to have NMPNetns thread-safe, instead of coming up with a duplicate implementation. But NMPNetns may want to log, so we also need nm-logging thread-safe. In general, code under "shared/nm-utils" and nm-logging should be usable from multiple threads. It's simpler to make this code thread-safe than re-implementing it. Also, it's a bad limitation to be unable to log from other threads. If there is an error, the best we can often do is to log about it. Make nm-logging thread-safe. Actually, we only need to be able to log from multiple threads. We don't need to setup or configure logging from multiple threads. This restriction allows us to access logging from the main-thread without any thread-synchronization (because all changes in the logging setup are also done from the main-thread). So, while logging from other threads requires a mutex, logging from the main-thread is lock-free.
* tests: don't use alloca() in testsThomas Haller2019-01-151-2/+2
| | | | | | | | | | | | The only purpose of using alloca() to avoid the overhead of heap-allocation and possible save a line in source code for managing/freeing the heap allocation. For tests we don't care about performance, and (in this case) the code does not get any shorter. Avoid alloca() in tests, because alloca() is something to search for when reviewing code for stack overflows. No need to have such false positives show up in tests.
* shared: add nm_utils_strbuf_append_bin() helperThomas Haller2019-01-141-4/+80
| | | | | | Add a version of nm_utils_strbuf_append_*() that does not care about NUL terminate strings, but accept any binary data. That makes it useful for writing a binary buffer.
* systemd: expose unbase64mem() as nm_sd_utils_unbase64mem()Thomas Haller2019-01-021-0/+96
| | | | | | | | | | | | | | | glib has an base64 implementation, but g_base64_decode() et al. gives no way to detect invalid encodings. All invalid codes are silently ignored. That is not suitable for strictly validating user input. Instead of reimplementing of copy-pasting the code from somewhere, reuse systemd's unbase64mem(). But don't use "hexdecoct.h" directly. Instead, add a single accessor function to our "nm-sd-utils-shared.h" gateway. We want to be careful about which bits from systemd we use, because otherwise re-importing systemd code becomes fragile as you don't know which relevant parts changed.
* systemd: move basic systemd library to shared/nm-utilsThomas Haller2019-01-023-3/+13
| | | | | | | | | | | | | | | | For better or worse, we already pull in large parts of systemd sources. I need a base64 decode implementation (because glib's g_base64_decode() cannot reject invalid encodings). Instead of coming up with my own or copy-paste if from somewhere, reuse systemd's unbase64mem(). But for that, make systemd's basic bits an independent static library first because I will need it in libnm-core. This doesn't really change anything except making "libnm-systemd-core.la" an indpendent static library that could be used from "libnm-core". We shall still be mindful about which internal code of systemd we use, and only access functionality that is exposed via "systemd/nm-sd-utils-shared.h".
* build: meson: Add trailing commasIñigo Martínez2018-12-202-7/+7
| | | | | | | Add missing trailing commas that avoids getting noise when another file/parameter is added and eases reviewing changes[0]. [0] https://gitlab.gnome.org/GNOME/dconf/merge_requests/11#note_291585
* core: fix match spec behavior for a list of all "except:"Thomas Haller2018-12-111-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the spec specifies only negative matches (and none of them matches), then the result shall be positive. Meaning: [connection*] match-device=except:dhcp-plugin:dhclient [connection*] match-device=except:interface-name:eth0 [.config] enabled=except:nm-version:1.14 should be the same as: [connection*] match-device=*,except:dhcp-plugin:dhclient [connection*] match-device=*,except:interface-name:eth0 [.config] enabled=*,except:nm-version:1.14 and match by default. Previously, such specs would never yield a positive match, which seems wrong. Note that "except:" already has a special meaning. It is not merely "not:". That is because we don't support "and:" nor grouping, but all matches are combined by an implicit "or:". With such a meaning, having a "not:" would be unclear to define. Instead it is defined that any "except:" match always wins and makes the entire condition to explicitly not match. As such, it makes sense to treat a match that only consists of "except:" matches special. This is a change in behavior, but the alternative meaning makes little sense.
* src/tests: add test for except match specThomas Haller2018-12-111-0/+4
|
* libnm: add nm_connectivity_state_cmp() helperThomas Haller2018-12-111-0/+57
|
* all: make use of NM_MAKE_STRV() macroThomas Haller2018-12-012-37/+44
|
* core: add checks on connection default propertiesBeniamino Galvani2018-12-013-22/+35
| | | | | | | | | | Add a new CON_DEFAULT() macro that places a property name into a special section used at runtime to check whether it is a supported connection default. Unfortunately, this mechanism doesn't work for plugins so we have to enumerate the connection defaults from plugins in the daemon using another CON_DEFAULT_NOP() macro.
* config: warn about unknown keys in config filesBeniamino Galvani2018-12-012-5/+49
| | | | | Emit a warning when we find an unsupported option in a configuration file.
* core: add nm_utils_create_dhcp_iaid() utilThomas Haller2018-11-291-0/+4
| | | | | Split out nm_utils_create_dhcp_iaid(), we will need it later. This is also a re-implementation of systemd's dhcp_identifier_set_iaid().