Commit graph

281 commits

Author SHA1 Message Date
Thomas Haller
0b10fb15a0 test: add nmtst_assert_success() util
(cherry picked from commit f5177dbf7a)
2015-07-03 09:24:02 +02:00
Thomas Haller
fa0f53b07b macros: add nm_strstrip() util
(cherry picked from commit d6a331bd8c)
2015-07-03 09:24:02 +02:00
Thomas Haller
53223b4842 glib-compat: backport g_key_file_save_to_file()
(cherry picked from commit 69f2d22bfe)
2015-07-03 09:24:02 +02:00
Thomas Haller
3a46d1ba6e core/tests: add nm_utils_get_testing() function
Code that is testable often needs special hooks to work
both for unit-tests and production.

Add a function nm_utils_get_testing() that returns whether
the code is run as part of a unit-test.

For non-testing mode, nm_utils_get_testing() will return
zero (NM_UTILS_TEST_NONE). For unit tests, the test should call
_nm_utils_set_testing() to configure tested functions.
By specifing the @flags attribute, the test can enable/disable
specific behaviors.

https://bugzilla.gnome.org/show_bug.cgi?id=701112
(cherry picked from commit b9d8dc050a)
2015-07-03 09:24:02 +02:00
Thomas Haller
e977e55e94 test: add nmtst_create_connection_from_keyfile()
(cherry picked from commit 997fc07ca5)
2015-07-03 09:24:01 +02:00
Thomas Haller
db2fa9455d test: add nmtst_assert_resolve_relative_path_equals() function
(cherry picked from commit cbfa00219e)
2015-07-03 09:23:59 +02:00
Lubomir Rintel
55e4ab8dd6 glib-compat: include string.h
Needed for memmove().

(cherry picked from commit 2a6e8d9f3f)
2015-06-22 16:25:42 +02:00
Thomas Haller
a51d2d6149 macros: add NM_PRINT_FMT_QUOTED() macro
(cherry picked from commit 972f61fcd7)
2015-06-22 09:56:05 +02:00
Thomas Haller
fb0443def9 glib-compat: add g_ptr_array_insert()
(cherry picked from commit 2f4301bd26)
2015-06-21 15:32:11 +02:00
Thomas Haller
5daac57a23 utils: add nm_utils_is_power_of_two() macro
(cherry picked from commit 0a3c1f5774)
2015-06-21 15:30:47 +02:00
Thomas Haller
a87231abbc glib-compat: add nm_g_hash_table_replace() compat function
The newer version of g_hash_table_replace() is useful, because it
saves an additional hash table lookup.

(cherry picked from commit 2bea70e750)
2015-06-21 15:19:01 +02:00
Thomas Haller
baf5f63374 utils: add NM_FLAGS_SET(), NM_FLAGS_UNSET() and NM_FLAGS_ASSIGN() macros
(cherry picked from commit 57958b93b6)
2015-06-19 12:26:02 +02:00
Thomas Haller
1d3c143948 build: rename file "include/nm-utils-internal.h" to "nm-macros-internal.h"
We already have "nm-utils*.h" and "NetworkManagerUtils.h" headers. Rename
"include/nm-utils-internal.h" to "nm-macros-internal.h". I think that
name is better, because this file is header-only, internal, and
repository-wide.

Also, it will never contain non-header-only declarations because
there is no backing object file under "include/".
It will only contain macros and inline functions.

(cherry picked from commit b8b1a01d96)
2015-06-19 12:21:58 +02:00
Thomas Haller
88bdeecf7c utils: move NM_FLAGS_*() macros to header file "include/nm-utils-internal.h"
(cherry picked from commit dce00f0d10)
2015-06-19 12:21:58 +02:00
Lubomir Rintel
30d37abbc0 tests: call g_test_run() even when skipping the test
It will return the 77 exit code itself. For TAP output it will also generate
the proper test skip marker.

(cherry picked from commit 14f4674f64)
2015-06-19 11:52:50 +02:00
Thomas Haller
b67fbe9561 core: make nm_assert() always compile condition
Even if asserts are not enabled, still let the compiler see what we would
assert. Otherwise, we get warnings about unused variables or we migth miss
compile errors inside nm_assert().

(cherry picked from commit fe3e1849b7)
2015-06-19 11:52:49 +02:00
Thomas Haller
63e30f5024 build: add --enable-more-asserts configure option and nm_assert() macro
NM already has two kinds of assertions:
 - g_assert*(), conditionally compiled via #ifndef G_DISABLE_ASSERT
 - g_return*(), conditionally compiled via #ifndef G_DISABLE_CHECKS

In theory, one should be able to disable both asserts and NM should
still work correctly (and possibly more efficient). In practice,
hardly anybody is testing such a configuration and it might be broken.
Especially, we don't disable asserts for production builds, both because
of less test coverage and because it might reduce our ability to debug.

Add a new configure option --enable-more-asserts, which defines
NM_MORE_ASSERTS and nm_assert(). This is for expensive asserts,
that -- contrary to the asserts above -- are disabled by default.
This is useful for extended debugging.

(cherry picked from commit 08ecafd2bf)
2015-06-19 11:52:49 +02:00
Thomas Haller
5b068e82e5 test: fix wrong use of memcmp() in nmtst_platform_ip4_routes_equal()
And nmtst_platform_ip6_routes_equal().

As already indicated by the comment, using memcmp() doesn't really work
here. It worked up to now, because the NMPlatformIP4Route structure has no
padding at the end.

If we would have a last 'guint8' member (as we will add later),
initializing an arry of routes on the stack would not clear the bytes
from the padding and the comparison using memcmp() would fail.

(cherry picked from commit d8d0c481b8)
2015-05-13 16:07:36 +02:00
Thomas Haller
7f13cb6acb test: fix parsing of command line arguments for setting nmtst_test_quick()
glib interprets the options either as "-m arg" or "-m=arg". Fix parsing
to check for both cases.

Also, g_test_init() removes the parsed options from argv, hence we must
check our original copy in __nmtst_internal.orig_argv.

Now the following all have the same outcome:

  $ NMTST_DEBUG=no-debug,quick ./src/rdisc/tests/test-rdisc-fake
  $ ./src/rdisc/tests/test-rdisc-fake -m quick
  $ ./src/rdisc/tests/test-rdisc-fake -m=quick

Fixes: a2edd6445f
(cherry picked from commit f529fedd17)
2015-05-04 09:18:21 +02:00
Thomas Haller
1bd99ff273 test: add nmtst_test_quick()
Utility function for long-running tests to check whether
they should run. It has the same use as g_test_quick(),
but it can also be set via NMTST_DEBUG environment variable.

You can set the compile time default via

  CFLAGS='-DNMTST_TEST_QUICK=FALSE' ./configure

and overwrite it at runtime via

  NMTST_DEBUG=no-default,quick ./tests/test-my
2015-05-01 15:59:00 -05:00
Thomas Haller
a8d3cf55c4 test: add EXIT_SKIP define 2015-05-01 15:50:20 -05:00
Thomas Haller
7028c8a53f utils: add nm_clear_g_source() helper
Utility function to simplify the following common code:

    if (priv->timeout_id) {
        g_source_remove (priv->timeout_id);
        priv->timeout_id = 0;
    }

to

    nm_clear_g_source (&priv->timeout_id);

(cherry picked from commit b5beaef8fa)
2015-04-28 18:39:52 +02:00
Thomas Haller
7f7c8acbae test: print NMTST_SEED_RAND value with g_print()
For tests with assert-logging enabled, we already printed
the message with g_print(), instead of g_message().

We always want to print this value, because it is important
to reproduce a test failure. Hence, just (always) print
directly to stdout.

Also, add a leading newline, because the output was attached
to the previous line.

(cherry picked from commit 4ab540939c)
2015-04-10 18:35:42 +02:00
Thomas Haller
636c8592ce test: fix compiler warning in g_test_assert_expected_messages_internal()
-Wformat of gcc determines that the string arguments are NULL.

Fixes: 373d09b042
(cherry picked from commit 0aca44c857)
2015-04-10 18:30:24 +02:00
Thomas Haller
fd10ed1e71 test: log message at g_test_assert_expected_messages()
When disabling assert-logging with no-expect-message,
print a line at every g_test_assert_expected_messages()
invocation.

(cherry picked from commit 373d09b042)
2015-04-10 18:30:24 +02:00
Thomas Haller
fec4e68f4d tests: check for no pending expected_messages on exit of tests
On the end of the test there should be no unchecked expected
messages. Register a destructor function in nmtst to assert
against that.

Also call nmtst_free() in the destructor. That way, we always release
the allocated data without requiring the test to do it explicitly.

(cherry picked from commit bb90127c2a)
2015-04-10 18:30:09 +02:00
Thomas Haller
0074bf032b test: add description of test behavior to nm-test-utils.h
(cherry picked from commit 745f2aceac)
2015-04-10 18:25:41 +02:00
Thomas Haller
897ac18bbb test: add option in nmtst_platform_ip4_routes_equal() to ignore ordering
Same for nmtst_platform_ip6_routes_equal().

It's useful to check for equal routes ignoring the ordering.

(cherry picked from commit 57453189e0)

Conflicts:
	src/tests/test-route-manager.c
2015-04-09 11:21:08 +02:00
Thomas Haller
643d412688 test: setup logging during nmtst_init_assert_logging()
Before, when having a test with nmtst_init_assert_logging(),
the caller was expected to setup logging separately according
to the log level that the test asserts against.

Since 5e74891b58, the logging
level can be reset via NMTST_DEBUG also for tests that
assert logging. In this case, it would be useful, if the test
would not overwrite the logging level that is set externally
via NMTST_DEBUG.

Instead, let the test pass the logging configuration to
nmtst_init_assert_logging(), and nmtst will setup logging
-- either according to NMTST_DEBUG or as passed in.

This way, setting the log level works also for no-expect-message
tests:

  NMTST_DEBUG="debug,no-expect-message,log-level=TRACE" $TEST

(cherry picked from commit b6d3b98655)
2015-04-09 08:22:28 +02:00
Thomas Haller
c0534e9a6d test: fix enabling DEBUG logging for tests
For glog messages to print any debug messages, we must set G_MESSAGES_DEBUG.
nmtst does this for us if we set @is_debug. But fix the condition to
also set G_MESSAGES_DEBUG if set set c_log_level to DEBUG or TRACE.

(cherry picked from commit 3abeb7f2b9)
2015-04-09 08:22:28 +02:00
Thomas Haller
ad5159156a test: fix parsing of NMTST_SEED_RAND
(cherry picked from commit 0a2c0d12e8)
2015-04-09 08:22:28 +02:00
Thomas Haller
ba43bfc0b7 test: change message about random seed in nmtst
Make it clear, that you can overwrite the seed by setting the
environment variable NMTST_SEED_RAND.

(cherry picked from commit 44a963c894)
2015-04-09 08:22:28 +02:00
Thomas Haller
6c63fe5028 test: fix printing error in nmtst_assert_connection_equals()
(cherry picked from commit 3790d8db2e)
2015-03-20 13:32:32 +01:00
Thomas Haller
669a8484c6 test: fix __NMTST_LOG() macro to allow format-string-only argument
We want to be able to call __NMTST_LOG(g_message, "hallo"); without
additional format string arguments.

(cherry picked from commit 94cc7ca4f8)
2015-03-20 13:32:29 +01:00
Thomas Haller
2d20640967 libgsystem: update copy of gsystem-local-alloc.h
Taken from libgsystem:src/gsystem-local-alloc.c
(commit ad3a28c5f2520d0688730aa83eaee815fb9a5762).

(cherry picked from commit 0429ed85ad)
2015-03-20 12:53:26 +01:00
Thomas Haller
d1c79fbe93 all: add macro NM_DEFINE_SINGLETON_GETTER()
(cherry picked from commit e725887c3a)
2015-03-13 11:50:50 +01:00
Thomas Haller
2eb71b6229 libnm/tests: fix memleaks in tests for valgrind
(cherry picked from commit ae73320b8c)
2015-03-13 11:50:04 +01:00
Thomas Haller
8c6348c6e2 test: fix setup of logging for no-expect-message
Tests with assert-logging would never overwrite the logging level,
even if no-expect-message was set. Allow resetting the logging level
if no-expect-message is mixed with explicitly setting up logging.

    NMTST_DEBUG='log-level=DEBUG,log-domains=ALL,no-expect-message' make check -C src/tests/config/

(cherry picked from commit 5e74891b58)
2015-02-16 16:21:01 +01:00
Thomas Haller
dfb25b6c4a all: move STRLEN() macro to global header nm-utils-internal.h
https://bugzilla.gnome.org/show_bug.cgi?id=741651
(cherry picked from commit 422fbf48b9)
2014-12-18 17:38:35 +01:00
Jiří Klimeš
7ee93a0029 tests: mute coverity for CHECKED_RETURN (CWE-252) in tests
Error: CHECKED_RETURN (CWE-252): [#def12]
NetworkManager-0.9.11.0/libnm-core/tests/test-general.c:348: check_return: Calling "nm_setting_verify" without checking return value (as is done elsewhere 37 out of 45 times).
...

(cherry picked from commit 6603e7ffde)
2014-12-16 21:47:01 +01:00
Dan Winship
3b86cc047e libnm: remove nm_utils_init() from the public API
Remove nm_utils_init() from the public API, and just do it as a
constructor instead.
2014-12-04 08:39:54 -05:00
Thomas Haller
dcb25a37a5 glib-compat: sync local definition of g_clear_pointer() with upstream glib and remove atomic operations
Upstream glib changed g_clear_pointer() not to use atomic functions.
Update or local definition to b1dd594a22e3499caafdeccd7fa223a032b9e177
glib/gmem.h (glib 2.41.3).

(fixup whitespace to match our style).

See also the related bug https://bugzilla.gnome.org/show_bug.cgi?id=733969
from glib.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-12 11:11:41 +01:00
Dan Winship
99d0fe3006 core: fix new NMIP4Config and NMIP6Config properties
The AddressData and RouteData marshalling code were still using the
types from an earlier version of the branch. Fix that.
2014-11-07 11:09:35 -05:00
Thomas Haller
6a59ab0b86 all: add macro NM_IN_SET
Copied from systemd's macro IN_SET from /src/shared/macro.h

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-07 15:19:05 +01:00
Dan Winship
d16905df63 libnm-core, libnm, core: add AddressData and RouteData properties
Add AddressData and RouteData properties to NMSettingIPConfig and
NMIP[46]Config. These are like the existing "addresses" and "routes"
properties, but using strings and containing additional attributes,
like NMIPAddress and NMIPRoute.

This only affects the D-Bus representations; there are no API changes
to NMSettingIP{,4,6}Config or NMIP{4,6}Config as a result of this; the
additional information is just added to the existing 'addresses' and
'routes' properties.

NMSettingIP4Config and NMSettingIP6Config now always generate both
old-style data ('addresses', 'address-labels', 'routes') and new-style
data ('address-data', 'gateway', 'route-data') when serializing to
D-Bus, for backward compatibility. When deserializing, they will fill
in the 'addresses' and 'routes' properties from the new-style data if
it is present (ignoring the old-style data), or from the old-style
data if the new-style isn't present.

The daemon-side NMIP4Config and NMIP6Config always emit changes for
both 'Addresses'/'Routes' and 'AddressData'/'RouteData'. The
libnm-side classes initially listen for changes on both properties,
but start ignoring the 'Addresses' and 'Routes' properties once they
know the daemon is also providing 'AddressData' and 'RouteData'.
2014-11-07 07:49:40 -05:00
Dan Winship
21c8a6b20e libnm-core, all: merge IPv4 and IPv6 address/route types
Merge NMIP4Address and NMIP6Address into NMIPAddress, and NMIP4Route
and NMIP6Route into NMIPRoute. The new types represent IP addresses as
strings, rather than in binary, and so are address-family agnostic.
2014-11-07 07:49:40 -05:00
Thomas Haller
e2179f0911 all: add macros to suppress compiler warnings
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-31 21:00:50 +01:00
Thomas Haller
b77567b225 build: fix -Wstrict-prototypes warnings
We disabled -Wstrict-prototypes in commit
db9b1df0e4 .
Fix compiler warnings.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-29 12:30:11 +01:00
Dan Winship
b1bcfa8fed libnm-core: add nm-errors.[ch]
Add nm-errors.[ch], and move libnm-core's two error domains
(NMConnectionError and NMCryptoError) there.

NMCryptoError wasn't previously visible, but it can be returned from
some public API, so it should be.
2014-10-22 08:29:08 -04:00
Dan Winship
7e548d962a nmtst: fix a bug in NMTST_VARIANT_EDITOR
NMTST_VARIANT_EDITOR would crash if you tried to drop different
properties (or two different settings).
2014-10-21 09:45:23 -04:00