Rather than randomly including one or more of <glib.h>,
<glib-object.h>, and <gio/gio.h> everywhere (and forgetting to include
"nm-glib-compat.h" most of the time), rename nm-glib-compat.h to
nm-glib.h, include <gio/gio.h> from there, and then change all .c
files in NM to include "nm-glib.h" rather than including the glib
headers directly.
(Public headers files still have to include the real glib headers,
since nm-glib.h isn't installed...)
Also, remove glib includes from header files that are already
including a base object header file (which must itself already include
the glib headers).
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.
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.
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.
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
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.
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
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
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.
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
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.
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/
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.
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).
...
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.
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>
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>
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.
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.)
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