Commit Graph

97 Commits

Author SHA1 Message Date
Thomas Haller
f591aa41c6 tests: add "/bin:/sbin" to "$PATH" for unit tests
We call `tc` from iproute2, which commonly is at "/sbin/tc".
That might not be in the "$PATH" of a regular user, and consequently
we fail to run the test.

Work around that by always adding "/bin" and "/sbin" to the $PATH.
2021-02-15 13:58:48 +01:00
Thomas Haller
8d6bd2f6c0 shared/tests: add nmtst_rand_perm_strv() helper 2021-02-10 18:23:44 +01:00
Thomas Haller
826d4fd7a9 shared/tests: add nmtst_ip_address_new() helper 2021-02-10 18:23:44 +01:00
Thomas Haller
66eccf7ad7 all: add "nm-default-systemd{,-shared}.h" as replacement for "nm-default.h" 2021-02-09 12:38:18 +01:00
Thomas Haller
6cbc2d715f shared/tests: don't include "nm-default.h" in test utils and remove compile check
Remove the check for NETWORKMANAGER_COMPILATION and NETWORKMANAGER_COMPILATION_TEST
define. We will no longer define that, and the check will be wrong.
2021-02-09 12:38:16 +01:00
Thomas Haller
779ee32263 shared/tests: add nmtst_main_loop_run_assert() helper 2021-01-27 10:18:13 +01:00
Thomas Haller
977ea352a0 all: update deprecated SPDX license identifiers
These SPDX license identifiers are deprecated ([1]). Update them.

[1] https://spdx.org/licenses/

  sed \
     -e '1 s%^/\* SPDX-License-Identifier: \(GPL-2.0\|LGPL-2.1\)+ \*/$%/* SPDX-License-Identifier: \1-or-later */%' \
     -e '1,2 s%^\(--\|#\|//\) SPDX-License-Identifier: \(GPL-2.0\|LGPL-2.1\)+$%\1 SPDX-License-Identifier: \2-or-later%' \
     -i \
     $(git grep -l SPDX-License-Identifier -- \
         ':(exclude)shared/c-*/' \
         ':(exclude)shared/n-*/' \
         ':(exclude)shared/systemd/src' \
         ':(exclude)src/systemd/src')
2021-01-05 09:46:21 +01:00
Thomas Haller
230250e629 shared/tests: add nmtst_main_context_iterate_until_full() helper 2020-11-03 14:31:20 +01:00
Thomas Haller
ca2b79d9aa shared/tests: add nmtst_g_source_nop() helper 2020-11-03 14:31:19 +01:00
Thomas Haller
6cb6888404 platform/tests: better handling "timeout_msec" argument in nmtst_main_context_iterate_until()
nmtst_main_context_iterate_until() is a macro, and we don't want to restrict the
valid integer type (or range) of the "timeout_msec" argument.

In particular, if the user calculates a timeout with "timestamp_msec -
now_msec", the resulting "timeout_msec" might be a negative gint64.
We should handle that gracefully, and not let it be cast to a huge
unsigned int.
2020-10-23 17:11:54 +02:00
Thomas Haller
dd7ce063fb tests: add nmtst_get_rand_one_case_in() helper 2020-10-23 17:11:53 +02:00
Thomas Haller
88071abb43 all: unify comment style for SPDX-License-Identifier tag
Our coding style recommends C style comments (/* */) instead of C++
(//). Also, systemd (which we partly fork) uses C style comments for
the SPDX-License-Identifier.

Unify the style.

  $ sed -i '1 s#// SPDX-License-Identifier: \([^ ]\+\)$#/* SPDX-License-Identifier: \1 */#' -- $(git ls-files -- '*.[hc]' '*.[hc]pp')
2020-09-29 16:50:53 +02:00
Thomas Haller
740b092fda format: replace tabs for indentation in code comments
sed -i \
     -e 's/^'$'\t'' \*/     */g' \
     -e 's/^'$'\t\t'' \*/         */g' \
     -e 's/^'$'\t\t\t'' \*/             */g' \
     -e 's/^'$'\t\t\t\t'' \*/                 */g' \
     -e 's/^'$'\t\t\t\t\t'' \*/                     */g' \
     -e 's/^'$'\t\t\t\t\t\t'' \*/                         */g' \
     -e 's/^'$'\t\t\t\t\t\t\t'' \*/                             */g' \
     $(git ls-files -- '*.[hc]')
2020-09-28 16:07:52 +02:00
Antonio Cardace
328fb90f3e all: reformat all with new clang-format style
Run:

    ./contrib/scripts/nm-code-format.sh -i
    ./contrib/scripts/nm-code-format.sh -i

Yes, it needs to run twice because the first run doesn't yet produce the
final result.

Signed-off-by: Antonio Cardace <acardace@redhat.com>
2020-09-28 16:07:51 +02:00
Thomas Haller
6efd4e2efa tests: use in_addr_t type for IPv4 addresses in test helpers 2020-09-24 09:43:58 +02:00
Thomas Haller
adb78bd471 tests: mark static variables in test helpers as thread local
We should avoid static variables in general, but for test helpers they
are often convenient.

Mark them as thread local to make them safer to use. The only downsides
may only be some runtime overhead, which is negligible for unit tests.
2020-09-24 09:43:57 +02:00
Thomas Haller
426a4c9d50 all: replace cleanup macro "gs_unref_keyfile" by "nm_auto_unref_keyfile" 2020-09-02 17:46:43 +02:00
Thomas Haller
6bf5f014c8 shared: change NM_SWAP() macro to take pointer arguments
This makes the macro more function like. Also, taking a pointer
makes it a bit clearer that this possibly changes the value.

Of course, it's not a big difference to before, but this
form seems slightly preferable to me.
2020-08-06 18:12:01 +02:00
Thomas Haller
77c000aa0b shared/tests: add nmtst_assert_ip_address() 2020-08-05 10:22:10 +02:00
Thomas Haller
b2df6fde30 shared/tests: add nmtst_stable_rand()
Generate a list of pseudo random numbers, the important part here is that
the result is stable and independent of endianness.
2020-07-24 16:03:15 +02:00
Thomas Haller
3f19c1fa52 shared/tests: add nmtst_assert_variant_bytestring() helper 2020-06-11 12:00:49 +02:00
Thomas Haller
e2f83d4e92 keyfile: add NMKeyfileHandlerFlags
nm_keyfile_read() and nm_keyfile_write() will be public API.
As such, it must be flexible and extendible for future needs.
There is already the handler callback that fully solves this
(e.g. a future handler event could request whether a certain
behavior is enabled or not).

As additional possibility for future extension, add a flags
argument. Currently no flags are implemented.
2020-06-05 09:17:21 +02:00
Antonio Cardace
93e38cbe56 nm-setting-bridge: add 'group-address' bridge option
Also add related unit test.

https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-04-06 09:56:11 +02:00
Thomas Haller
5f6dfcfc92 shared/tests: add nmtst_get_rand_word_length()
Will be used to get a random number with a certain distribution,
that suitable to generate input values.
2020-04-04 19:51:34 +02:00
Thomas Haller
a4da47bc47 shared/tests: add nmtst_get_rand_size() 2020-04-03 11:31:12 +02:00
Thomas Haller
6f9a478b7d tests: replace NMTST_SWAP() by new NM_SWAP() macro
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.
2020-03-26 21:28:56 +01:00
Thomas Haller
0d4eedda07 shared/tests: add nmtst_get_rand_uint64() util 2020-02-10 19:11:50 +01:00
Thomas Haller
8f3b43f009 all: use nm_utils_ipaddr_is_valid() instead of nm_utils_ipaddr_valid()
We should use the same "is-valid" function everywhere.

Since nm_utils_ipaddr_valid() is part of libnm, it does not qualify.

Use nm_utils_ipaddr_is_valid() instead.
2020-01-28 11:17:41 +01:00
Thomas Haller
f2baa10bb8 shared/tests: add nmtst_main_context_iterate_until() helper
Like nmtst_main_context_iterate_until_assert(), but allows to
run into timeout.
2020-01-28 10:54:14 +01:00
Thomas Haller
90bb46c8ee shared/tests/trivial: rename nmtst_main_context_iterate_until() to nmtst_main_context_iterate_until_assert()
nmtst_main_context_iterate_until*() iterates until the condition is
satisfied. If that doesn't happen within timeout, it fails an assertion.

Rename the function to make that clearer.
2020-01-28 10:54:14 +01:00
Thomas Haller
eceaa39a1e shared/tests: use nmtst_g_source_set_boolean_true() in nmtst_main_context_iterate_until() 2020-01-28 10:54:14 +01:00
Thomas Haller
c4690eeeff shared/tests: add nmtst_main_context_assert_no_dispatch() helper 2020-01-28 10:54:14 +01:00
Thomas Haller
0008c6c801 shared/tests: add nmtst_g_source_set_boolean_true() helper 2020-01-28 10:54:14 +01:00
Thomas Haller
71fb823a43 shared/tests: add nmtst_context_busy_watcher_wait() helper 2020-01-28 10:54:14 +01:00
Thomas Haller
d944761f83 shared/tests: add nmtst_file_set_contents_size() helper 2020-01-16 12:40:01 +01:00
Thomas Haller
bd9b253540 all: rename time related function to spell out nsec/usec/msec/sec
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.
2019-12-13 16:54:40 +01:00
Thomas Haller
88ef02ec33 shared/tests: add nmtst_main_context_iterate_until() helper 2019-11-07 11:34:36 +01:00
Thomas Haller
3b69f02164 all: unify format of our Copyright source code comments
```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
2019-10-02 17:03:52 +02:00
Thomas Haller
c1559dae3f shared: add nmtst_g_source_assert_not_called() helper 2019-09-30 16:00:45 +02:00
Lubomir Rintel
24028a2246 all: SPDX header conversion
$ find * -type f |xargs perl contrib/scripts/spdx.pl
  $ git rm contrib/scripts/spdx.pl
2019-09-10 11:19:56 +02:00
Thomas Haller
a265892385 shared/tests: add nmtst_keyfile_get_num_keys() helper 2019-08-27 10:44:23 +02:00
Thomas Haller
441dd1f3c8 libnm: add nm_connection_to_dbus_full() with options argument
No options are implemented yet.
2019-06-28 16:48:17 +02:00
Thomas Haller
c0e075c902 all: drop emacs file variables from source files
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.
2019-06-11 10:04:00 +02:00
Thomas Haller
98ec22d4be shared: add nmtst_get_rand_uint() helper 2019-06-11 08:25:10 +02:00
Thomas Haller
d7932ee5f1 tests/trivial: rename nmtst_get_rand_int() to nmtst_get_rand_uint32()
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.
2019-06-11 08:25:10 +02:00
Thomas Haller
b927287c7d shared/utils: add nmtst_assert_setting_dbus_roundtrip() util 2019-05-23 18:09:49 +02:00
Thomas Haller
892440c4ab shared/tests: add nmtst_assert_setting_is_equal() util 2019-05-23 18:09:49 +02:00
Thomas Haller
ae7f32e03b shared/tests: add nmtst_variant_from_string() util 2019-05-23 18:09:49 +02:00
Lubomir Rintel
5801f89f4d all: goodbye libnm-glib
This removes libnm-glib, libnm-glib-vpn, and libnm-util for good.
The it has been replaced with libnm since NetworkManager 1.0, disabled
by default since 1.12 and no up-to-date distributions ship it for years
now.

Removing the libraries allows us to:

* Remove the horrible hacks that were in place to deal with accidental use
  of both the new and old library in a single process.
* Relief the translators of maintenance burden of similar yet different
  strings.
* Get rid of known bad code without chances of ever getting fixed
  (libnm-glib/nm-object.c and libnm-glib/nm-object-cache.c)
* Generally lower the footprint of the releases and our workspace

If there are some really really legacy users; they can just build
libnm-glib and friends from the NetworkManager-1.16 distribution. The
D-Bus API is stable and old libnm-glib will keep working forever.

https://github.com/NetworkManager/NetworkManager/pull/308
2019-04-16 15:52:27 +02:00
Lubomir Rintel
b027723e00 Revert "all: goodbye libnm-glib"
We need this for a little little longer :(

This reverts commit 1de8383ad9.
2019-04-03 08:52:38 +02:00