Commit Graph

93 Commits

Author SHA1 Message Date
Thomas Haller
998772805c nmtst: refactor NMTST_BUSY_WAIT() and rename to NMTST_WAIT*() 2015-11-27 14:22:06 +01:00
Thomas Haller
c97f7b54fe nmtst: support shorthand "NMTST_DEBUG=TRACE" to set logging level 2015-11-27 14:22:05 +01:00
Thomas Haller
73cb579108 nmtst: support -p and -s arguments from gtestutils via $NMTST_DEBUG
For tests based on glib's test framework, you can select which tests to
run by passing -p/-s on the command line.

Usually, we want to invoke our tests via `make check` which conveniently
calls valgrind (run-test-valgrind.sh) or spawns a private D-Bus server
(libnm-test-launch.sh, libnm-glib-test-launch.sh). At that point, it is
not directly possible to specify command line arguments for the tests,
which is why it is convenient to specify arguments via $NMTST_DEBUG
environment variable.

Parse "p" and "s" arguments from $NMTST_DEBUG and pass them to g_test_init()
to select which tests to run.

  NMTST_DEBUG=p=/core/general/test_setting_ip4_changed_signal ./libnm-core/tests/test-general

However, there is a problem here: in gtestutils, -p/-s conflicts with --tap,
which is how our Makefile invokes the tests. Thus the new options explicitly
don't work when being called during `make check`. Which makes this much
less useful. I only noticed that afterwards, so still keep the patch
because it might still be convenient during developing tests to set the
environment variable once, and then repeatedly spawn the tests, without
specifying -p/-s.
2015-11-24 09:46:06 +01:00
Thomas Haller
a6a2fd7eef nmtst: pass -m=quick when specifying quick test in $NMTST_DEBUG
When the environment variable indicates that we want to run quick
tests, pass "-m=quick" to g_test_init().
2015-11-24 09:42:05 +01:00
Thomas Haller
c8174f0f9f nmtst: detect whether the test runs as tap test
Same as gtestutils does, look for --tap command line argument.
2015-11-24 09:35:01 +01:00
Thomas Haller
5031fc3c71 nmtst: initialize g_test_init() after parsing NMTST_DEBUG 2015-11-24 09:12:42 +01:00
Thomas Haller
1cf69d9724 tests: fix error message in nmtst_assert_ip6_address()
Fixes: 09983442bd
2015-11-02 18:19:05 +01:00
Thomas Haller
ea0e36b61d test: disable g_log_set_always_fatal() for non-assert tests on older glib versions
This fixes test-failure for src/platform/tests/test-link-fake on older
systems.
2015-11-02 15:36:01 +01:00
Thomas Haller
9369fac8ca core: add nm_utils_to_string_buffer global buffer
Having a static string buffer for convenience is useful not only
for platform. Define the string buffer in NetworkManagerUtils.h,
so that all to-string functions can reuse *one* buffer.

Of course, this has the potential danger, that different
to-string method might reuse the same buffer. Hence, low-level
library functions are adviced to use their own buffer, because
an upper level might already use the global buffer for another
string.
2015-11-02 13:57:01 +01:00
Thomas Haller
a2d59f5f10 platform: add buffer argument to platform to-string functions
Arguably, it is more convenient to use the static buffer as
it saves typing.

But having such a low-level function use a static buffer also
limits the way how to use it. As it was, you could not avoid
using the static buffer.

E.g. you cannot do:

  char buf[100];

  _LOGD ("nmp-object: %s; platform-link: %s",
         nmp_object_to_string (nmpobj, buf, sizeof(buf)),
         nm_platform_link_to_string (link));

This will fail for non-obvious reasons because both
to-string functions end up using the same static buffer.

Also change the to-string implementations to accept NULL
as valid and return it as "(null)".

https://bugzilla.gnome.org/show_bug.cgi?id=756427
2015-11-01 17:28:08 +01:00
Thomas Haller
88a2f1c93b tests: handle no_expect_message also for tests without assert-logging 2015-11-01 17:28:07 +01:00
Thomas Haller
d5ef08e01e tests: add nmtst_rand_perm() utility 2015-11-01 17:28:07 +01:00
Thomas Haller
09983442bd tests: add nmtst_assert_ip4_address() and nmtst_assert_ip6_address() utility method 2015-11-01 17:28:07 +01:00
Thomas Haller
0d5428b1bd test: add nmtst_get_rand_int() helper 2015-10-14 12:52:07 +02:00
Thomas Haller
9fdc5e6596 libnm-util/test: use "nm-test-utils.h" in test-setting-dcb 2015-10-10 19:41:42 +02:00
Thomas Haller
19c3ea948a all: make use of new header file "nm-default.h" 2015-08-05 15:32:40 +02:00
Dan Winship
3452ee2a0e all: rename nm-glib-compat.h to nm-glib.h, use everywhere
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).
2015-07-24 13:25:47 -04:00
Thomas Haller
cf4b1a0c3d test: add nmtst_platform_ip4_route() utils 2015-07-14 13:36:50 +02:00
Thomas Haller
904e961464 all: remove #if GLIB_CHECK_VERSION conditionals around g_type_init()
g_type_init() is now provided by nm-glib-compat.h as nm_g_type_init().
2015-07-12 13:56:52 +02:00
Thomas Haller
aefea43380 nmtst: add function nmtst_assert_str_has_substr() 2015-07-12 13:56:52 +02:00
Thomas Haller
f5177dbf7a test: add nmtst_assert_success() util 2015-07-02 15:50:03 +02:00
Thomas Haller
4eb48d8c87 test: add NMTST_BUSY_WAIT() util 2015-06-23 16:46:09 +02:00
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