Commit Graph

59 Commits

Author SHA1 Message Date
Thomas Haller
9152dec99f build: disable deprecation checks for internal compilation
For internal compilation we want to be able to use deprecated
API without warnings.

Define the version min/max macros to effectively disable deprecation
warnings.

However, don't do it via CFLAGS option in the makefiles, instead hack it
to "nm-default.h". After all, *every* source file that is for internal
compilation needs to include this header as first.
2016-04-05 22:22:58 +02:00
Thomas Haller
1c932aade1 libnm-glib: allow non-verifiable NMRemoteConnection in libnm-glib 2016-03-29 11:56:27 +02:00
Thomas Haller
8bace23beb all: cleanup includes and let "nm-default.h" include "config.h"
- All internal source files (except "examples", which are not internal)
  should include "config.h" first. As also all internal source
  files should include "nm-default.h", let "config.h" be included
  by "nm-default.h" and include "nm-default.h" as first in every
  source file.
  We already wanted to include "nm-default.h" before other headers
  because it might contains some fixes (like "nm-glib.h" compatibility)
  that is required first.

- After including "nm-default.h", we optinally allow for including the
  corresponding header file for the source file at hand. The idea
  is to ensure that each header file is self contained.

- Don't include "config.h" or "nm-default.h" in any header file
  (except "nm-sd-adapt.h"). Public headers anyway must not include
  these headers, and internal headers are never included after
  "nm-default.h", as of the first previous point.

- Include all internal headers with quotes instead of angle brackets.
  In practice it doesn't matter, because in our public headers we must
  include other headers with angle brackets. As we use our public
  headers also to compile our interal source files, effectively the
  result must be the same. Still do it for consistency.

- Except for <config.h> itself. Include it with angle brackets as suggested by
  https://www.gnu.org/software/autoconf/manual/autoconf.html#Configuration-Headers
2016-02-19 17:53:25 +01:00
Thomas Haller
5170d3a760 tests: move common dbus test-runners to tools/ directory 2016-01-22 16:52:41 +01:00
Michael Biebl
a9bd5dce1c tests: use dbus-run-session instead of dbus-launch
The dbus-run-session utility was designed to run a process within a
D-Bus session, specifically for running regressions tests and is much
better suited then dbus-launch. As an additional benefit, this avoids
any X dependencies.

https://mail.gnome.org/archives/networkmanager-list/2016-January/msg00023.html
2016-01-22 16:52:41 +01:00
Thomas Haller
92f122525d libnm/tests: add tests for libnm handling invalid connections
Add test showing how libnm/libnm-glib handles invalid connections,
i.e. connections that fail nm_connection_verify(). libnm implements
settings a static types (via different NMSetting types). This makes
it unavoidable that eventually a newer server version will
expose connections that fail verification in the client.

For example, master added a new base type NMSettingTun. This setting type
was not backported to legacy libnm-glib, thus such connection will not verify.
Also, we want that newer server versions are backward compatible with older
library versions. Thus also a pre-NMSettingTun libnm version has the same
problem.

The test shows that libnm is agnostic to whether the connection verifies.
That is consistent behavior, but possibly problematic because most
accessors to connections assert against a valid connection. Thus using
the common nm_connection*() functions on an invalid connection can lead
to problems.
Also, due to the static nature of our NMSetting types, some properties
can be silently dropped and thus mangling the connection without the
library user noticing.

libnm-glib prints a g_warning() whenever parsing an invalid connection.
When an invalid connection is added initially, it is exposed to the library
user. When a connection gets later invalidated due to an update, the
connection disappears and it stays missing even if a subsequent update
makes the connection valid again.

libnm-glib's behavior indicates that we might wanted to hide invalid
connections from the user. But it's very broken there.
2015-12-26 19:09:11 +01:00
Thomas Haller
c0af56ac7a libnm/tests: use nmtstc_nm_remote_settings_new() 2015-12-26 16:43:49 +01:00
Thomas Haller
d90525ebfc libnm/tests: use nmtstc_nm_client_new() 2015-12-26 16:43:49 +01:00
Thomas Haller
db80ec05ab build: rename directory "include" to "shared"
Up to now, the "include" directory contained (only) header files that were
used project-wide by libs, core, clients, et al.

Since the directory now also contains a non-header file, the "include"
name is misleading. Instead of adding yet another directory that is
project-wide, with non-header-only content, rename the "include"
directory to "shared".
2015-12-24 11:42:37 +01:00
Thomas Haller
bc06dd9332 libnm/tests: rename test functions to follow common pattern
Like the test utility functions in nm-test-utils.h and
platform's common.h, rename the helper functions to have
a nmtst(c) prefix.
2015-12-24 11:42:37 +01:00
Thomas Haller
fa3093e167 libnm/tests: move common testing code to nm-test-libnm-utils
The unit tests for libnm and libnm-glib use a NetworkManager stub
service written in Python (test-networkmanager-service.py). As they
share the same server, it makes sense to also share the same utility
code to drive the stub.

Move the common code to include/.

Note that contrary to "nm-test-utils.h", "nm-test-libnm-utils.h" is not
a header-only file. Instead its implementation is in "nm-test-utils-impl.c".
The reason for that this split is, if we later have yet another non-header-only
test-utility, then all the implementations are in "nm-test-utils-impl.c", requiring
the tests to link only one object file.
2015-12-24 11:42:37 +01:00
Thomas Haller
70713ee197 libnm/tests: unify common test code for libnm and libnm-glib
Unify the common test code to drive the D-Bus stub service
test-networkmanager-service.py. They will be merged in the next
commit.
2015-12-24 11:42:36 +01:00
Dan Williams
4db851f852 libnm/libnm-glib: add NMClient.get_all_devices() method and AllDevices property
Mirror new NetworkManager API to return both real devices and
device placeholders.
2015-12-04 12:16:41 +01:00
Thomas Haller
7bf10a75db 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
2015-09-30 23:10:29 +02:00
Jiří Klimeš
82e4364480 tests: add a test for connection_compatible() for wired devices
Allow setting MAC address and S390 subchannels for ethernet devices in
testing NM service.
2015-09-29 09:31:41 +02:00
Lubomir Rintel
81cc4d27b1 tests: raise the mock service startup timeout
Python is just too slow on some machines. Needed around twice the previous
limit on BCM2835 with Pidora 20, let's add some safety margin too.
2015-08-17 10:53:11 +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
7a3ab5c02f test: initialize tests with nmtst_init() 2015-07-12 13:56:52 +02:00
Lubomir Rintel
c47c06470a builds: only enable TAP driver for glib >= 2.37.6
No TAP support for previous versions and --tap argument is silently ignored,
confusing the TAP driver.
2015-05-28 12:51:24 +02:00
Lubomir Rintel
6463ce5dd9 tests: use the TAP formatter
The test results in standard format are easily integrated into CI systems.
2015-05-26 13:51:45 +02:00
Lubomir Rintel
380ed63318 build: switch to parallel test harness
This will make it possible to use the TAP formatter.
2015-05-26 13:51:45 +02:00
Lubomir Rintel
d0e25ac8be tests: always spawn private d-bus
Parallel test runs would not be possible without this.
2015-05-26 13:51:44 +02:00
Thomas Haller
b0b15e4718 libnm-glib/tests: fix calling tests without valgrind
Fixes: e7356ef0a6
2015-02-09 14:51:56 +01:00
Thomas Haller
e7356ef0a6 libnm/tests: enable valgrind for libnm tests 2015-02-09 12:10:13 +01:00
Thomas Haller
76745817c3 libnm/tests: fix memleaks in test code for valgrind 2015-02-09 11:51:08 +01:00
Thomas Haller
c50f30e79c tests: enable valgrind tests for tests 2015-02-09 11:51:07 +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
3bfb163a74 all: consistently include config.h
config.h should be included from every .c file, and it should be
included before any other include. Fix that.

(As a side effect of how I did this, this also changes us to
consistently use "config.h" rather than <config.h>. To the extent that
it matters [which is not much], quotes are more correct anyway, since
we're talking about a file in our own build tree, not a system
include.)
2014-11-13 17:18:42 -05:00
Lubomir Rintel
e9bfd0e29c tests: Don't run session-long dbus daemons for tests
They require a tty or X11 displays, thus are not suitable for headless runs
(such as in mock). Furthermore, they die with the tty or X11 session, which
is somehow late -- a lot of them may accumulate. Let's kill them right away.
2014-10-24 19:16:33 +02:00
Dan Winship
48ad586209 libnm-glib: add tests of NMClient:manager-running and NMRemoteSettings:service-running
Test that the code to track whether NetworkManager is running works
correctly.
2014-08-01 12:12:42 -04:00
Dan Winship
08b91199fb libnm-glib: make test-networkmanager-service.py automatically exit with its parent
test-nm-client.c and test-remote-settings-client.c were using their
own assertion macros so they could kill the test service on assertion
failure. Except that some new code didn't get the memo and used the
g_assert* macros. Not to mention that sometimes the tests would crash
outside of an assertion macro.

We can make test-networkmanager-service.py notice that its parent has
crashed by opening a pipe between them and taking advantage of the
fact that the pipe will be automatically closed if the parent crashes.
So then test-networkmanager-service.py just has to watch for that, and
exit if the pipe closes.

Then that lets us drop the test_assert* macros and just use g_assert*
instead.
2014-08-01 12:12:42 -04:00
Dan Winship
bd8a7f74b1 libnm-glib: split out test service launching code from tests 2014-08-01 12:12:42 -04:00
Dan Winship
ade4f2e84e libnm-glib: use automake test infrastructure for test programs
Use "TESTS = tests-nm-client test-remote-settings-client" rather than
overriding "check-local".

Add a script "libnm-test-launch.sh" that will handle redirecting the
test via dbus-launch if needed.
2014-08-01 11:55:49 -04:00
Dan Winship
4f7e9bd336 libnm-glib: compile test-networkmanager-service.py path into test binaries
Rather than passing the path to the test service on the command line,
compile it into the test programs.

(Among other things, this makes it easier to run the test directly
from the command line.)
2014-08-01 11:55:49 -04:00
Thomas Haller
1de6d83e29 libnm-glib/test: add asserts to test-remote-settings-client
- register a weak references and ensure that the connection
  is removed when expected.

- disconnect the vis_new_connection_cb() handler

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-01 13:07:38 +02:00
Thomas Haller
d6b3ef0819 libnm-glib/test: fix crash in test-remote-settings-client
test_make_invisible() forgot to disconnect handler invis_removed_cb().
Later, during test_remove_connection(), the connection will be eventually
removed and the callback will corrupt the stack by writing to the '&done'
user data.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-01 13:07:38 +02:00
Dan Winship
5432ef5e52 tools: move libnm-glib's fake NM service implementations here
Move libnm-glib's test-fake-nm.py and test-remote-settings-service.py
to tools/, merge them together into a single program, and fix a few
bugs (notably some missing signal emissions in the Settings service).

Although they are currently only used by libnm-glib's tests, they are
generic enough that they could be used by other code in the future
(and in particular, they will be used by libnm's tests as well).
2014-07-30 15:56:29 -04:00
Thomas Haller
faa6c34db1 libnm-glib: evaluate assert check only once in test-remote-settings-client
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-07-21 12:20:56 +02:00
Dan Winship
396610d14a libnm-glib: fix assertion-failure messages in test-remote-settings-client
test-remote-setting-client uses a macro:

    #define test_assert(condition) \
    do { \
        if (!G_LIKELY (condition)) \
            cleanup (); \
        g_assert (condition); \
    } while (0)

where cleanup() kills the fake remote-settings service and unrefs
settings. However, in many cases, "condition" would involve a test
against a connection that was owned by settings, so if the check
failed, the connection would end up getting freed by cleanup(), and so
then the second invocation of condition would result in the program
aborting on a failed check somewhere else (eg, "invalid unclassed
pointer in cast to 'NMConnection'") rather than displaying the failed
assertion that had gotten us to that point.

Fix this by not unreffing settings from cleanup(); in the normal exit
case we can just have main() unref it, and in the assertion-failed
case, we don't need to free things anyway.
2014-07-20 08:58:56 -04:00
Dan Winship
30c74c6007 build: more srcdir!=builddir fixes
nm-version.h was getting disted, making srcdir!=builddir work for
tarball builds, but not for git builds.

Also, remove "-I${top_builddir}/include" from all Makefile.ams, since
there's nothing generated in include/ any more.
2014-07-15 11:37:19 -04:00
Dan Winship
3aad3124f1 libnm-glib: drop separate test library
Previously, we built a second copy of libnm-glib that was hacked to
use the session bus rather than the system bus, for use by the test
programs. Rather than doing that, just have test-nm-client explicitly
override the choice of bus. (test-remote-settings-client was actually
already doing this, although it leaked the bus after.)
2014-07-15 09:44:55 -04:00
Dan Winship
cb7e1893e7 libnm-util, libnm-glib: standardize copyright/license headers
- Remove list of authors from files that had them; these serve no
  purpose except to quickly get out of date (and were only used in
  libnm-util and not libnm-glib anyway).

- Just say "Copyright", not "(C) Copyright" or "Copyright (C)"

- Put copyright statement after the license, not before

- Remove "NetworkManager - Network link manager" from the few files
  that contained it, and "libnm_glib -- Access network status &
  information from glib applications" from the many files that
  contained it.

- Remove vim modeline from nm-device-olpc-mesh.[ch], add emacs modeline
  to files that were missing it.
2014-07-15 09:44:54 -04:00
Thomas Haller
734203e12e libnm-glib/tests: remove waiting time for initializing NMClient
This waiting time significantly increases the runtime of the tests.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-07-08 19:01:01 +02:00
Jiří Klimeš
98ae6e06d2 all: g_type_init() has been deprecated in GLib 2.35.0
g_type_init() deprecation:
https://bugzilla.gnome.org/show_bug.cgi?id=686161
2014-05-27 16:58:21 +02:00
Dan Winship
1d0b50c2c4 build: add some missing -DNM_VERSION_MAX_ALLOWED
Add -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE to a bunch of
Makefile.ams that were missing it and might eventually need it.
2014-04-07 11:30:18 -04:00
Dan Williams
bce1fc7c3b libnm-glib: add testing framework and testcases
Add a fake NM service and test various aspects of the new NM D-Bus
properties.
2014-01-23 17:46:20 -06:00
Thomas Haller
6868076e3c test: launch dbus for test-remote-settings-client
Running `make check` on systems without running dbus failed
in test-remote-settings-client.c:383

    make[4]: Entering directory `/tmp/NetworkManager/libnm-glib/tests'
    /tmp/NetworkManager/libnm-glib/tests/test-remote-settings-client /tmp/NetworkManager/libnm-glib/tests test-remote-settings-service.py

    ** (/tmp/NetworkManager/libnm-glib/tests/.libs/lt-test-remote-settings-client:26983): WARNING **: Error connecting to D-Bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
    make[4]: *** [check-local] Trace/breakpoint trap (core dumped)

Modify the Makefile to start the dbus-daemon, if it is not yet
running.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-10-04 17:02:43 +02:00
Dan Winship
bfce3f7dc8 build: switch from $(INCLUDES) to $(AM_CPPFLAGS) to make automake happy
Unfortunately, $(AM_CPPFLAGS) gets overridden by per-target _CPPFLAGS
variables, which $(INCLUDES) did not, so this requires some additional
changes.

In most places, I have just gotten rid of the per-target _CPPFLAGS
variables; in directories with a single target, the per-target
variable is unnecessary, and in directories with multiple targets, the
per-target variable is often undesirable, since it forces some files
to be compiled twice, even though there ends up being no difference
between the two files.
2013-08-22 11:49:16 -04:00
Dan Williams
c41bd34570 libnm-glib: add support for new connection unsaved functionality 2013-05-28 12:26:56 -05:00