Commit graph

296 commits

Author SHA1 Message Date
Thomas Haller
243d0facb8 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.

(cherry picked from commit 73cb579108)
2015-11-24 11:14:48 +01:00
Thomas Haller
7eed71d860 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().

(cherry picked from commit a6a2fd7eef)
2015-11-24 11:14:47 +01:00
Thomas Haller
8bdb2aaeea nmtst: detect whether the test runs as tap test
Same as gtestutils does, look for --tap command line argument.

(cherry picked from commit c8174f0f9f)
2015-11-24 11:14:46 +01:00
Thomas Haller
c3aafd9dab nmtst: initialize g_test_init() after parsing NMTST_DEBUG
(cherry picked from commit 5031fc3c71)
2015-11-24 11:14:42 +01:00
Lubomir Rintel
faea1ff074 release: bump version to 1.0.8 2015-11-23 17:54:42 +01:00
Thomas Haller
4297db4f4c macros: add nm_sprintf_buf() helper macro
(cherry picked from commit abd607257b)
2015-11-20 15:15:18 +01:00
Beniamino Galvani
18770ece53 macros: avoid signed overflow in nm_utils_is_power_of_two()
If __x is signed and its value is the minimum allowed for the type,
(__x - 1) causes a signed overflow, which has an undefined
behavior. Compiling with -fsanitize=undefined produces the warnings:

test-general.c:4499:619: runtime error: signed integer overflow: -2147483648 - 1 cannot be represented in type 'int'
test-general.c:4506:681: runtime error: signed integer overflow: -2147483648 - 1 cannot be represented in type 'TEST_IS_POWER_OF_TWP_ENUM_SIGNED'
test-general.c:4501:619: runtime error: signed integer overflow: -9223372036854775808 - 1 cannot be represented in type 'long int'
test-general.c:4509:691: runtime error: signed integer overflow: -9223372036854775808 - 1 cannot be represented in type 'TEST_IS_POWER_OF_TWP_ENUM_UNSIGNED_64'

Change the order of expressions to avoid this.

Fixes: 0a3c1f5774
(cherry picked from commit bc9d034775)
2015-11-15 11:18:48 +01:00
Glenn Washburn
6a9d8c7fa4 build: disable Pragmas for pre 4.6 gcc
Gcc 4.6 introduced Pragma "GCC diagnostic" (https://gcc.gnu.org/gcc-4.6/changes.html)
Don't use them for older gcc.

[thaller@redhat.com: modified original patch]

https://bugzilla.gnome.org/show_bug.cgi?id=757910
(cherry picked from commit 6263703286)
2015-11-13 17:20:58 +01:00
Thomas Haller
6f06ec0aba macros: remove early return from nm_clear_g_signal_handler()
It is valid to call nm_clear_g_signal_handler() with missing
@self argument if (and only if) the @id is unspecified as well.

Remove the check for @self to get an assertion in case @id
is missing *and* @self is invalid. In this case,
g_signal_handler_disconnect() will raise a g_critical() for us.

Fixes: c33416178f
(cherry picked from commit 76958f94d4)
2015-10-12 11:14:33 +02:00
Jiří Klimeš
23313d711f macros: allow NULL pointer in nm_clear_g_signal_handler()
It does not make sense to issue an error. This should be a helper function.
"NetworkManager[18341]: nm_clear_g_signal_handler: assertion 'G_IS_OBJECT (self)' failed"
error started since commit e6d7fee5a6 due to that.

(cherry picked from commit c33416178f)
2015-10-12 11:14:31 +02:00
Thomas Haller
720c53f9f1 macros: add nm_clear_g_signal_handler() helper 2015-10-02 18:51:15 +02:00
Thomas Haller
e0ca2bdb63 build: extract version macros from "nm-version.h" to new header file "nm-version-macros.h"
For libnm library, "nm-dbus-interface.h" contains defines like the D-Bus
paths of NetworkManager. It is desirable to have this header usable without
having a dependency on "glib.h", for example for a QT application. For that,
commit c0852964a8 removed that dependancy.

For libnm-glib library, the analog to "nm-dbus-interface.h" is
"NetworkManager.h", and the same applies there. Commit
159e827a72 removed that include.
However, that broke build on PackageKit [1] which expected to get the
version macros by including "NetworkManager.h". So at least for libnm-glib,
we need to preserve old behavior so that a user including
"NetworkManager.h" gets the version macros, but not "glib.h".

Extract the version macros to a new header file "nm-version-macros.h".
This header doesn't include "glib.h" and can be included from
"NetworkManager.h". This gives as previous behavior and a glib-free
include.

For libnm we still don't include "nm-version-macros.h" to "nm-dbus-interface.h".
Very few users will actually need the version macros, but not using
libnm.
Users that use libnm, should just include (libnm's) "NetworkManager.h" to
get all headers.
As a special case, a user who doesn't want to use glib/libnm, but still
needs both "nm-dbus-interface.h" and "nm-version-macros.h", can include
them both separately.

[1] https://github.com/hughsie/PackageKit/issues/85

Fixes: 4545a7fe96
(cherry picked from commit 7bf10a75db)
2015-09-30 23:35:52 +02:00
Thomas Haller
6d2a1edc38 macros: use short-circuit evaluation in NM_IN_SET()
All current users of NM_IN_SET() would rather use short-circuit evalation
(or don't care). It seems that doing it by default seems favorable.

The only downside is, that this might have somewhat unexpected behavior
to a user who expects a regular function (which would evaluate always
all arguments).

Fixes: 7860ef959a
(cherry picked from commit 96cacc07e8)
2015-08-12 16:07:22 +02:00
Thomas Haller
69b276d6d1 macros: rework NM_IN_SET() macro to expand to a plain logical expression
Let the preprocessor do more work, but generate a simple expression that
the compiler can optimize (presumably) better.

(cherry picked from commit 7860ef959a)
2015-08-12 16:07:02 +02:00
Thomas Haller
ba44a92f52 test: add nmtst_platform_ip4_route() utils
(cherry picked from commit cf4b1a0c3d)
2015-07-14 13:44:57 +02:00
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