]>
Commit | Line | Data |
---|---|---|
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 | ||
0c2f9b84 | 24 | static void test_link(Manager *manager, struct udev_device *loopback) { |
0617ffab | 25 | Link *link = NULL; |
f579559b | 26 | |
12e0f830 TG |
27 | assert_se(link_new(manager, loopback, &link) >= 0); |
28 | assert_se(link); | |
f579559b TG |
29 | } |
30 | ||
02b59d57 | 31 | static void test_load_config(Manager *manager) { |
7c99d940 TG |
32 | /* TODO: should_reload, is false if the config dirs do not exist, so |
33 | * so we can't do this test here, move it to a test for paths_check_timestamps | |
34 | * directly | |
35 | * | |
12e0f830 | 36 | * assert_se(network_should_reload(manager) == true); |
7c99d940 | 37 | */ |
12e0f830 TG |
38 | assert_se(manager_load_config(manager) >= 0); |
39 | assert_se(manager_should_reload(manager) == false); | |
f579559b TG |
40 | } |
41 | ||
42 | static void test_network_get(Manager *manager, struct udev_device *loopback) { | |
43 | Network *network; | |
44 | ||
45 | /* let's assume that the test machine does not have a .network file | |
46 | that applies to the loopback device... */ | |
12e0f830 TG |
47 | assert_se(network_get(manager, loopback, &network) == -ENOENT); |
48 | assert_se(!network); | |
f579559b TG |
49 | } |
50 | ||
51 | int main(void) { | |
52 | _cleanup_manager_free_ Manager *manager = NULL; | |
53 | struct udev *udev; | |
54 | struct udev_device *loopback; | |
55 | ||
12e0f830 | 56 | assert_se(manager_new(&manager) >= 0); |
f579559b | 57 | |
02b59d57 | 58 | test_load_config(manager); |
f579559b TG |
59 | |
60 | udev = udev_new(); | |
12e0f830 | 61 | assert_se(udev); |
f579559b TG |
62 | |
63 | loopback = udev_device_new_from_syspath(udev, "/sys/class/net/lo"); | |
12e0f830 TG |
64 | assert_se(loopback); |
65 | assert_se(udev_device_get_ifindex(loopback) == 1); | |
f579559b TG |
66 | |
67 | test_network_get(manager, loopback); | |
68 | ||
0c2f9b84 | 69 | test_link(manager, loopback); |
f579559b | 70 | |
12e0f830 TG |
71 | assert_se(manager_udev_listen(manager) >= 0); |
72 | assert_se(manager_udev_enumerate_links(manager) >= 0); | |
73 | assert_se(manager_rtnl_listen(manager) >= 0); | |
f579559b TG |
74 | |
75 | udev_device_unref(loopback); | |
76 | udev_unref(udev); | |
77 | } |