Commit Graph

71 Commits

Author SHA1 Message Date
Lubomir Rintel
ce2ea51ed0 Revert "core: avoid loading GIO modules"
This reverts commit 6a841c0cd1.

We do actually need the modules for connectivity checking.
2015-06-05 16:04:27 +02:00
Lubomir Rintel
6a841c0cd1 core: avoid loading GIO modules
Turns out the dconf modules is leaky and breaks the valgrind run. In any case,
it's not a good idea to load the modules for the daemon, it just takes time
and memory.

On a Fedora/x86_64 desktop it adds up to 5M to the RSS.
2015-06-04 14:29:10 +02:00
Thomas Haller
b8b1a01d96 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.
2015-06-01 14:47:08 +02:00
Lubomir Rintel
14f4674f64 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.
2015-05-26 13:51:44 +02:00
Thomas Haller
e0d103b1a2 test: include "nm-keyfile-internal.h" for tests under src/
Including "nm-keyfile-internal.h" before "nm-test-utils.h" enables
a few useful utilities. If we know that our test uses NetworkManagerUtils.h,
we can always include it -- as we have libnm-core available.
2015-05-20 19:03:47 +02:00
Thomas Haller
b9d8dc050a 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
2015-05-19 09:57:46 +02:00
Thomas Haller
d8d0c481b8 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.
2015-05-13 14:31:05 +02:00
Thomas Haller
f529fedd17 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
2015-05-04 09:16:31 +02:00
Thomas Haller
a2edd6445f 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 16:27:23 -05:00
Thomas Haller
7c705325a4 test: add EXIT_SKIP define 2015-05-01 16:27:23 -05:00
Thomas Haller
4ab540939c 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.
2015-04-10 18:06:20 +02:00
Thomas Haller
0aca44c857 test: fix compiler warning in g_test_assert_expected_messages_internal()
-Wformat of gcc determines that the string arguments are NULL.

Fixes: 373d09b042
2015-04-10 15:06:23 +02:00
Thomas Haller
373d09b042 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.
2015-04-09 16:39:13 +02:00
Thomas Haller
745f2aceac test: add description of test behavior to nm-test-utils.h 2015-04-09 16:39:13 +02:00
Thomas Haller
57453189e0 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.
2015-04-08 14:39:16 +02:00
Thomas Haller
b6d3b98655 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
2015-04-08 14:39:16 +02:00
Thomas Haller
3abeb7f2b9 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.
2015-04-08 14:39:16 +02:00
Thomas Haller
0a2c0d12e8 test: fix parsing of NMTST_SEED_RAND 2015-04-08 14:39:15 +02:00
Thomas Haller
44a963c894 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.
2015-04-08 14:39:15 +02:00
Thomas Haller
a5ea98005f test: print connections as keyfile on failure of nmtst_assert_connection_equals()
If the assertion nmtst_assert_connection_equals() is about to fail,
dump out the offending connections as keyfile.
2015-03-20 13:19:20 +01:00
Thomas Haller
3790d8db2e test: fix printing error in nmtst_assert_connection_equals() 2015-03-20 13:19:20 +01:00
Thomas Haller
94cc7ca4f8 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.
2015-03-20 13:19:15 +01:00
Thomas Haller
997fc07ca5 test: add nmtst_create_connection_from_keyfile() 2015-03-12 18:16:58 +01:00
Thomas Haller
cbfa00219e test: add nmtst_assert_resolve_relative_path_equals() function 2015-03-12 18:12:25 +01:00
Lubomir Rintel
f981407a02 core: pass ifindex as parameter to nm_ip6_config_new() 2015-02-27 16:50:09 +01:00
Dan Williams
84f54f0a5f core: pass ifindex as parameter to nm_ip4_config_new() 2015-02-27 16:50:09 +01:00
Thomas Haller
ec1e8017af test: fix defining nmtst_create_minimal_connection() without including nm-setting-connection.h 2015-02-26 10:21:35 +01:00
Thomas Haller
5e74891b58 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/
2015-02-16 16:09:40 +01:00
Thomas Haller
ae73320b8c libnm/tests: fix memleaks in tests for valgrind 2015-02-09 11:51:07 +01:00
Thomas Haller
bb90127c2a 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.
2015-01-07 22:47:27 +01:00
Jiří Klimeš
6603e7ffde 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).
...
2014-12-15 14:11:03 +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
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
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
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
Lubomir Rintel
33866e4030 core: Move NMPlatformSource to nm-types.h
...and rename it while at it. It's going to be useful outside nm-platform,
to weight MTU options from various sources.
2014-10-20 12:41:50 +02:00
Thomas Haller
884040fa8f nmtst: improve nmtst_assert_connection_verifies_without_normalization()
If the assertion in verifies_without_normalization() fails due to
@was_modified, the error message is not helpful.
Assert first against the content of the connection. This prints
most likely the settings that were actually modified.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-12 20:11:31 +02:00
Thomas Haller
54ed36e3c0 nmtst: fix compiler warnings and make initialization of macro variables explict
clang warns about uninitialized variables @__cur_setting_name and
@__cur_property_name as used inside @__code. Before calling to @__code,
explicitly initialize the values.

    Making all in tests
    make[4]: Entering directory `./NetworkManager/libnm-core/tests'
      CC       test-general.o
    test-general.c:2730:24: error: variable '__cur_property_name' is uninitialized when used here [-Werror,-Wuninitialized]
                                  NMTST_VARIANT_DROP_PROPERTY (NM_SETTING_CONNECTION_SETTING_NAME,
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../../include/nm-test-utils.h:1079:20: note: expanded from macro 'NMTST_VARIANT_DROP_PROPERTY'
                                && !strcmp (__cur_property_name, __property_name)) \
                                            ^~~~~~~~~~~~~~~~~~~
    ../../include/nm-test-utils.h:1023:3: note: expanded from macro 'NMTST_VARIANT_EDITOR'
                    __code; \
                    ^
    test-general.c:2729:2: note: variable '__cur_property_name' is declared here
            NMTST_VARIANT_EDITOR (connection_dict,
            ^
    ../../include/nm-test-utils.h:1015:3: note: expanded from macro 'NMTST_VARIANT_EDITOR'
                    const char *__cur_setting_name, *__cur_property_name; \
                    ^
    [...]

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-09-22 16:34:18 +02:00
Thomas Haller
1aeb0c6df3 nmtst: move #endif to hide NMTST_VARIANT_* macros if not needed
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-09-22 16:32:01 +02:00
Dan Winship
58f278fbfb nmtst: add NMTST_VARIANT_EDITOR()
Several test programs create connection hashes and then modify them in
various ways. This becomes much more complicated with GVariants, since
they are immutable. Add NMTST_VARIANT_EDITOR() to simplify the process
of iterating the old variant and building a new, slightly-modified one.
2014-09-18 11:51:09 -04:00
Dan Winship
504c292d73 libnm-core: clean up nm_connection_replace_settings()'s semantics
On failure, nm_connection_replace_settings() would leave the
connection in an undefined state. Fix it so that either (a) the
settings are replaced and the resulting connection is valid and we
return TRUE, or (b) the connection is untouched and we return FALSE
and an error. (And add a test case for this.)
2014-09-04 09:17:37 -04:00
Dan Williams
448254f761 ibft: add settings plugin for reading iBFT configuration (bgo #734009)
Instead of handling iBFT (iSCSI Boot Firmware Table) in the ifcfg-rh plugin,
create a new plugin for it.  This allows all distributions to use iBFT
configuration, and makes both iBFT handling and ifcfg-rh less complicated.

The plugin (like the old ifcfg-rh code) creates read-only connections backed
by the data exported by iscsiadm.  The plugin does not support adding new
connections or modifying existing connections (since the iBFT data is
read-only anyway).  Instead, users should change their iBFT data through
the normal firmware interfaces.

Unmanaged devices can be configured through NetworkManager.conf and the
normal 'keyfile' mechanisms.

(In the future, we'll read this data directly from the kernel's
/sys/firmware/ibft/ethernetX directory instead of iscsiadm, since the
kernel has all the information we need and that's where iscsiadm gets
it from anyway.)

https://bugzilla.gnome.org/show_bug.cgi?id=734009
2014-08-29 18:46:11 -05:00
Thomas Haller
043ab29ca9 nmtst: add assertion functions for verify() connection
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-22 15:24:30 +02:00
Thomas Haller
80e1b05c31 nmtst: add nmtst_assert_connection_equals() function
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-22 15:24:30 +02:00
Thomas Haller
0da0293f7e nmtst: add nmtst_connection_normalize() function
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-22 15:24:30 +02:00
Dan Winship
e1ba13a426 libnm-core, libnm, core: make NMConnection an interface
The fact that NMRemoteConnection has to be an NMConnection and
therefore can't be an NMObject means that it needs to reimplement bits
of NMObject functionality (and likewise NMObject needs some special
magic to deal with it). Likewise, we will need a daemon-side
equivalent of NMObject as part of the gdbus port, and we would want
NMSettingsConnection to be able to inherit from this as well.

Solve this problem by making NMConnection into an interface, and
having NMRemoteConnection and NMSettingsConnection implement it. (We
use some hacks to keep the GHashTable of NMSettings objects inside
nm-connection.c rather than having to be implemented by the
implementations.)

Since NMConnection is no longer an instantiable type, this adds
NMSimpleConnection to replace the various non-D-Bus-based uses of
NMConnection throughout the code. nm_connection_new() becomes
nm_simple_connection_new(), nm_connection_new_from_hash() becomes
nm_simple_connection_new_from_hash(), and nm_connection_duplicate()
becomes nm_simple_connection_new_clone().
2014-08-16 10:17:53 -04:00
Dan Winship
32c26a859b libnm-core: move some fake NMConnection methods over to NMSetting
nm_connection_lookup_setting_type() and
nm_connection_lookup_setting_type_by_quark() have nothing to do with
NMConnection. So move them to NMSetting (and rename them to
nm_setting_lookup_type() and nm_setting_lookup_type_by_quark()).
2014-08-16 10:17:53 -04:00
Dan Winship
c81fb49aa5 all: fix up multiple-include-guard defines
Previously, src/nm-ip4-config.h, libnm/nm-ip4-config.h, and
libnm-glib/nm-ip4-config.h all used "NM_IP4_CONFIG_H" as an include
guard, which meant that nm-test-utils.h could not tell which of them
was being included (and so, eg, if you tried to include
nm-ip4-config.h in a libnm test, it would fail to compile because
nm-test-utils.h was referring to symbols in src/nm-ip4-config.h).

Fix this by changing the include guards in the non-API-stable parts of
the tree:

  - libnm-glib/nm-ip4-config.h remains   NM_IP4_CONFIG_H
  - libnm/nm-ip4-config.h now uses     __NM_IP4_CONFIG_H__
  - src/nm-ip4-config.h now uses       __NETWORKMANAGER_IP4_CONFIG_H__

And likewise for all other headers.

The two non-"nm"-prefixed headers, libnm/NetworkManager.h and
src/NetworkManagerUtils.h are now __NETWORKMANAGER_H__ and
__NETWORKMANAGER_UTILS_H__ respectively, which, while not entirely
consistent with the general scheme, do still mostly make sense in
isolation.
2014-08-16 10:17:14 -04:00
Thomas Haller
df2711f197 nmtst: fix memory leak in nmtst_create_minimal_connection()
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-07 22:26:28 +02:00
Thomas Haller
d83f3777ad nmtst: add nmtst_create_minimal_connection() function
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-07 15:43:43 -04:00