]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/test-network.c
networkd: add a basic network daemon
[thirdparty/systemd.git] / src / network / test-network.c
CommitLineData
f579559b
TG
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2013 Tom Gundersen <teg@jklm.no>
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
22#include "networkd.h"
23
24static void test_link(struct udev_device *loopback) {
25 _cleanup_manager_free_ Manager *manager = NULL;
26 _cleanup_link_free_ Link *link = NULL;
27
28 manager_new(&manager);
29
30 assert(link_new(manager, loopback, &link) >= 0);
31 assert(link);
32}
33
34static void test_network_load(Manager *manager) {
35 assert(network_should_reload(manager) == true);
36 assert(network_load(manager) >= 0);
37 assert(network_should_reload(manager) == false);
38}
39
40static void test_network_get(Manager *manager, struct udev_device *loopback) {
41 Network *network;
42
43 /* let's assume that the test machine does not have a .network file
44 that applies to the loopback device... */
45 assert(network_get(manager, loopback, &network) == -ENOENT);
46 assert(!network);
47}
48
49int main(void) {
50 _cleanup_manager_free_ Manager *manager = NULL;
51 struct udev *udev;
52 struct udev_device *loopback;
53
54 assert(manager_new(&manager) >= 0);
55
56 test_network_load(manager);
57
58 udev = udev_new();
59 assert(udev);
60
61 loopback = udev_device_new_from_syspath(udev, "/sys/class/net/lo");
62 assert(loopback);
63 assert(udev_device_get_ifindex(loopback) == 1);
64
65 test_network_get(manager, loopback);
66
67 test_link(loopback);
68
69 assert(manager_udev_enumerate_links(manager) >= 0);
70 assert(manager_udev_listen(manager) >= 0);
71
72 udev_device_unref(loopback);
73 udev_unref(udev);
74}