Commit graph

107 commits

Author SHA1 Message Date
Thomas Haller a75ab799e4 build: create "config-extra.h" header instead of passing directory variables via CFLAGS
1) the command line gets shorter. I frequently run `make V=1` to see
   the command line arguments for the compiler, and there is a lot
   of noise.

2) define each of these variables at one place. This makes it easy
   to verify that for all compilation units, a particular
   define has the same value. Previously that was not obvious or
   even not the case (see commit e5d1a71396
   and commit d63cf1ef2f).
   The point is to avoid redundancy.

3) not all compilation units need all defines. In fact, most modules
   would only need a few of these defines. We aimed to pass the necessary
   minium of defines to each compilation unit, but that was non-obvious
   to get right and often we set a define that wasn't used. See for example
   "src_settings_plugins_ibft_cppflags" which needlessly had "-DSYSCONFDIR".
   This question is now entirely avoided by just defining all variables in
   a header. We don't care to find the minimum, because every component
   gets anyway all defines from the header.

4) this also avoids the situation, where a module that previously did
   not use a particular define gets modified to require it. Previously,
   that would have required to identify the missing define, and add
   it to the CFLAGS of the complation unit. Since every compilation
   now includes "config-extra.h", all defines are available everywhere.

5) the fact that each define is now available in all compilation units
   could be perceived as a downside. But it isn't, because these defines
   should have a unique name and one specific value. Defining the same
   name with different values, or refer to the same value by different
   names is a bug, not a desirable feature. Since these defines should
   be unique accross the entire tree, there is no problem in providing
   them to every compilation unit.

6) the reason why we generate "config-extra.h" this way, instead of using
   AC_DEFINE() in configure.ac, is due to the particular handling of
   autoconf for directory variables. See [1].
   With meson, it would be trivial to put them into "config.h.meson".
   While that is not easy with autoconf, the "config-extra.h" workaround
   seems still preferable to me.

[1] https://www.gnu.org/software/autoconf/manual/autoconf-2.63/html_node/Installation-Directory-Variables.html
2018-07-17 17:46:39 +02:00
Thomas Haller e1c7a2b5d0 all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.

    $ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    587
    $ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    21114

One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during

  g_object_set (obj, PROPERTY, (gint) value, NULL);

However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.

Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).

A simple style guide is instead: don't use these typedefs.

No manual actions, I only ran the bash script:

  FILES=($(git ls-files '*.[hc]'))
  sed -i \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>  /\1   /g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
      "${FILES[@]}"
2018-07-11 12:02:06 +02:00
Thomas Haller f445128af4 build/meson: fix meson build for shared files
The files in shared/nm-utils are not compiled as one static library,
instead each subproject that needs (parts of) them, re-compiles the
files individually.

The major reason for that is, because we might have different compile
flags, depending on whether we build libnm-core or
libnm-util/libnm-glib. Actually, I think that is not really the case,
and maybe this should be refactored, to indeed build them all as a
static library first.

Anyway, libnm-util, libnm-glib, clients' common lib, they all need a
different set of shared files that they should compile. Refactor
"shared/meson.build" to account for that and handle it like autotools
does.

Another change is, that "shared_c_siphash_dep" no longer advertises
"include_directories: include_directories('c-siphash/src')". We don't
put c-siphash.h into the include search path. Users who need it, should
include it via "#include <c-siphash/src/c-siphash.h>". The only exception
is when building shared_n_acd library, which is not under our control.
2018-05-31 15:59:38 +02:00
Thomas Haller b7426e91db build: use default NM_BUILD_* defines for tests
Use two common defines NM_BUILD_SRCDIR and NM_BUILD_BUILDDIR
for specifying the location of srcdir and builddir.

Note that this is only relevant for tests, as they expect
a certain layout of the directories, to find files that concern
them.
2018-05-31 15:59:38 +02:00
Thomas Haller 9628aabc2f tests: use libnm via pygobject in tools/test-networkmanager-service.py
tools/test-networkmanager-service.py is our NetworkManager stub server.

NetworkManager uses libnm(-core) heavily, for example to decide whether
a connection verifies (nm_connection_verify()) and for normalizing
connections (nm_connection_normalize()).

If the stub server wants to mimic NetworkManager, it also must use these
function. Luckily, we already can do so, by loading libnm using python
GObject introspection.

We already correctly set GI_TYPELIB_PATH search path, so that the
correct libnm is loaded -- provided that we build with introspection
enabled.

We still need to gracefully fail, if starting the stub server fails.
That requries some extra effort. If the stub server notices that
something is missing, it shall exit with status 77. That will cause
the tests to g_test_skip().
2018-05-11 16:51:20 +02:00
Beniamino Galvani 1b5925ce88 all: remove consecutive empty lines
Normalize coding style by removing consecutive empty lines from C
sources and headers.

https://github.com/NetworkManager/NetworkManager/pull/108
2018-04-30 16:24:52 +02:00
Beniamino Galvani 0136915211 build: meson: add prefix to test names
There are multiple tests with the same in different directories; add a
unique prefix to test names so that it is clear from the output which
one is running.
2018-04-12 09:21:10 +02:00
Beniamino Galvani 0c39a02ce0 build: meson: enable all tests again
Some tests were disabled because they failed when run in parallel.
Now that we use the wrapper script they succeed and can be enabled
again.
2018-04-12 09:21:10 +02:00
Beniamino Galvani a2479b95c0 build: meson: use run-nm-test.sh to run tests
Like autotools, use the wrapper script 'run-nm-test.sh' that starts a
separate D-Bus session when needed.
2018-04-12 09:21:10 +02:00
Thomas Haller 65049f6736 libnm/tests: fix compilation of test-general
../libnm/tests/test-general.c: In function ‘test_fixup_vendor_string’:
    ../libnm/tests/test-general.c:70:3: error: initializer element is not constant
       T_DATA ("3Com", "3Com"),
       ^
    ../libnm/tests/test-general.c:70:3: error: (near initialization for ‘data[0]’)
    ../libnm/tests/test-general.c: In function ‘test_fixup_product_string’:
    ../libnm/tests/test-general.c:365:3: error: initializer element is not constant
       T_DATA  ("10/100BaseTX [RTL81xx]", "RTL81xx"),
    ...

Fixes: 817fce917b
2018-02-26 14:42:09 +01:00
Thomas Haller 817fce917b libnm/tests: avoid compiler message about -fvar-tracking-assignments in test-general.c
CC       libnm/tests/libnm_tests_test_general-test-general.o
    libnm/tests/test-general.c: In function ‘test_fixup_product_string’:
    libnm/tests/test-general.c:328:1: note: variable tracking size limit exceeded with -fvar-tracking-assignments, retrying without
     test_fixup_product_string (void)
     ^~~~~~~~~~~~~~~~~~~~~~~~~

Fixes: 8e32d8fc23
2018-02-26 13:14:40 +01:00
Lubomir Rintel 4c963d719c libnm/utils: drop part after a dash in product name
It's always garbage.

At this point we seem to reasonably handle all product names that come
from hwdb.
2018-02-23 19:47:19 +01:00
Lubomir Rintel 0c151ae39d libnm/utils: extend the product fixup phrase list
The product names are generally of rather poor quality. The product name
is no place to enumerate product capabilities, the bus it's attached on
and similar nonsense.
2018-02-23 19:47:19 +01:00
Lubomir Rintel e22b1c1d94 libnm/utils: ignore parts of vendor name after a slash
At this point the test suite also contains all network vendor names
known to hwdb.
2018-02-23 19:47:19 +01:00
Lubomir Rintel f7805ab602 libnm/utils: deal with the square brackets on producr/vendor fixup
If there's a [<string>] that survived the substitution, then the string
is supposed to be a short form that is generally preferrable.

That's great in theory, but actually it's rather often pure garbage for
product names. Let's prefer it just for vendors and provide an option to
drop it (will be useful for fixing up product names).
2018-02-23 19:47:19 +01:00
Lubomir Rintel 280d095fdf libnm/utils: ignore stuff in parentheses for vendor/product fixups
It's always useless.
2018-02-23 19:47:19 +01:00
Lubomir Rintel e974261e89 libnm/utils: add more phrases to vendor fixup list
Along with known correctly fixed up vendor names.
2018-02-23 19:47:19 +01:00
Lubomir Rintel 8e32d8fc23 libnm/utils: split out vendor fixup
The hwdb generally contains the strings of rather poor quality,
especially when it comes to sensibly presenting them to the user and
they need various cleanups.

While the following patches add fixups, this one splits out vendor
fixups, because it turns out that a different set of fixups is needed
than for products.
2018-02-23 19:47:19 +01:00
Iñigo Martínez 5e16bcf268 meson: Improve dependency system
Some targets are missing dependencies on some generated sources in
the meson port. These makes the build to fail due to missing source
files on a highly parallelized build.

These dependencies have been resolved by taking advantage of meson's
internal dependencies which can be used to pass source files,
include directories, libraries and compiler flags.

One of such internal dependencies called `core_dep` was already in
use. However, in order to avoid any confusion with another new
internal dependency called `nm_core_dep`, which is used to include
directories and source files from the `libnm-core` directory, the
`core_dep` dependency has been renamed to `nm_dep`.

These changes have allowed minimizing the build details which are
inherited by using those dependencies. The parallelized build has
also been improved.
2018-01-10 12:20:17 +01:00
Thomas Haller 22ef6a507a build: refine the NETWORKMANAGER_COMPILATION define
Note that:

 - we compile some source files multiple times. Most notably those
   under "shared/".

 - we include a default header "shared/nm-default.h" in every source
   file. This header is supposed to setup a common environment by defining
   and including parts that are commonly used. As we always include the
   same header, the header must behave differently depending
   one whether the compilation is for libnm-core, NetworkManager or
   libnm-glib. E.g. it must include <glib/gi18n.h> or <glib/gi18n-lib.h>
   depending on whether we compile a library or an application.

For that, the source files need the NETWORKMANAGER_COMPILATION #define
to behave accordingly.

Extend the define to be composed of flags. These flags are all named
NM_NETWORKMANAGER_COMPILATION_WITH_*, they indicate which part of the
build are available. E.g. when building libnm-core.la itself, then
WITH_LIBNM_CORE, WITH_LIBNM_CORE_INTERNAL, and WITH_LIBNM_CORE_PRIVATE
are available. When building NetworkManager, WITH_LIBNM_CORE_PRIVATE
is not available but the internal parts are still accessible. When
building nmcli, only WITH_LIBNM_CORE (the public part) is available.
This granularily controls the build.
2018-01-08 12:38:53 +01:00
Lubomir Rintel 6672c5e92e all: get rid of a handful of unused-but-set variables 2017-12-18 13:29:32 +01:00
Iñigo Martínez 0735b35dd0 build: use template files for enum types' sources generation
Source files for enum types are generated by passing segments of the
source code of the files to the `glib-mkenums` command.

This patch removes those parameters where source code is used from
meson build files by moving those segmeents to template files.

https://mail.gnome.org/archives/networkmanager-list/2017-December/msg00057.html
2017-12-18 11:25:06 +01:00
Iñigo Martínez d849366230 build: rename unit tests with the test- pattern
There are some tests located in different directories which are
using the same name. To avoid any confussion a prefix was used to
name the test and the target.

This patch uses the prefix just for the target, to avoid any
collision that may happen, and uses the `test-` pattern as the
name.

https://mail.gnome.org/archives/networkmanager-list/2017-December/msg00051.html
2017-12-14 20:07:38 +01:00
Iñigo Martínez 03637ad8b5 build: add initial support for meson build system
meson is a build system focused on speed an ease of use, which
helps speeding up the software development. This patch adds meson
support along autotools.

[thaller@redhat.com: rebased patch and adjusted for iwd support]

https://mail.gnome.org/archives/networkmanager-list/2017-December/msg00022.html
2017-12-13 15:48:50 +01:00
Thomas Haller e255ad2a03 libnm: move fixup_desc_string() to nm-libnm-utils.c 2017-05-19 12:45:45 +02:00
Thomas Haller 8df944c7e4 libnm: add testable libnm/nm-libnm-utils.c file
Previously, internal parts of libnm were not testable.
Instead, add "libnm/nm-libnm-utils.c" and "libnm/libnm-utils.la"
to contain code that can be statically linked with a new
test "libnm/tests/test-general".
2017-05-19 12:45:45 +02:00
Lubomir Rintel dfa90861e8 libnm/tests: increase timeout in nm-client test
Otherwise the test may fail in valgrind.
2016-11-14 20:22:23 +01:00
Lubomir Rintel bbed63213a libnm/tests: work around ObjectManager bogus warning
We should eventually fix this in Gio, but I guess we need to keep the
workaround for the time being anyway.
2016-11-10 16:48:48 +01:00
Lubomir Rintel ed21a820a7 libnm/tests: connection might not be gone at the time manager signals removal
The assumption is not too useful to the library user anyway -- it could easily
be that there's some other link to the object in the object tree.

More importantly, when the objects are managed by the object manager,
we don't destroy the object until we see it actually removed on the
D-Bus. That makes more sense anyway.
2016-11-10 16:48:47 +01:00
Thomas Haller 7aefbcb622 build: merge "libnm/tests/Makefile.am" into toplevel Makefile 2016-10-19 17:16:08 +02:00
Thomas Haller cd98705d21 tests: combine "run-test-valgrind.sh" and "run-test-dbus-session.sh" in "run-nm-test.sh"
No need to have two test-runners. Combine them, and call tests always
via "tools/run-nm-test.sh".

Yes, this brings an overhead, that we now always invoke the test with
a test wrapper script, also --without-vagrind. Previously, that was only
necessary for libnm tests that require their own D-Bus session.

Later we will do non-recursive Makefiles, thus all tests should have the
same LOG_COMPILER.
2016-10-19 15:26:30 +02:00
Thomas Haller 274de2555b build/trivial: rename VALGRIND_RULES in Makefile.am to NM_LOG_COMPILER 2016-10-19 15:26:30 +02:00
Thomas Haller a83eb773ce all: modify line separator comments to be 80 chars wide
sed 's#^/\*\{5\}\*\+/$#/*****************************************************************************/#' $(git grep -l '\*\{5\}' | grep '\.[hc]$') -i
2016-10-03 12:01:15 +02:00
Thomas Haller 2c02f3a8cf shared/tests: build "nm-utils/nm-vpn-plugin-utils.c"
For testing, add a build target to build those files too.
2016-06-16 10:45:54 +02:00
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 4aa7e09d1f libnm: be more accepting for invalid connections from NetworkManager
Relax our error checking which will allow us to try harder to
make the best out of whatever NetworkManager sends us.

Also, drop the g_warning(). First, now we really don't expect this
function to fail. And even in that case, raising a g_warning() from
the library is not very friendly to the user of libnm.
2016-03-26 12:10:54 +01:00
Thomas Haller c5786f3839 libnm/tests: extend tests for handling invalid connections in NMClient 2016-03-26 12:10:53 +01:00
Lubomir Rintel 84c42aac1b test-nm-client: fix the remaining counter
We're expecting four callbacks: a client::devices change,
client::active-connections change, client::activate callback,
and a device::active-connection change.

We only hook the second one in the callback to the first one, and
only if client::active-connections is not set already. If it is
(when running slowly in valgrind), we just decrement the counter.

However, as the counter is one less than it should be, it would
underflow and we wait forever* instead.

For the value of forever=20s, given that's the timeout of the
mockup service.
2016-03-17 17:37:06 +01: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
Dan Williams 3254965067 libnm,tests: fix error leak 2016-01-21 11:31:31 -06: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 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
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