test-network.c revision 12e0f830f592ec4c6bb49ac7ae1e0e84f74105e3
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering/***
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering This file is part of systemd.
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering Copyright 2013 Tom Gundersen <teg@jklm.no>
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering systemd is free software; you can redistribute it and/or modify it
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering under the terms of the GNU Lesser General Public License as published by
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering (at your option) any later version.
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering systemd is distributed in the hope that it will be useful, but
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering Lesser General Public License for more details.
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering You should have received a copy of the GNU Lesser General Public License
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering***/
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering#include "networkd.h"
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic void test_link(struct udev_device *loopback) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering _cleanup_manager_free_ Manager *manager = NULL;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering Link *link = NULL;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering manager_new(&manager);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert_se(link_new(manager, loopback, &link) >= 0);
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering assert_se(link);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic void test_load_config(Manager *manager) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering/* TODO: should_reload, is false if the config dirs do not exist, so
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack * so we can't do this test here, move it to a test for paths_check_timestamps
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering * directly
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering *
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering * assert_se(network_should_reload(manager) == true);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering*/
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert_se(manager_load_config(manager) >= 0);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert_se(manager_should_reload(manager) == false);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringstatic void test_network_get(Manager *manager, struct udev_device *loopback) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering Network *network;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering /* let's assume that the test machine does not have a .network file
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering that applies to the loopback device... */
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert_se(network_get(manager, loopback, &network) == -ENOENT);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert_se(!network);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
3f9da416457c4265b8f1179516a32ad1a987ff7dLennart Poetteringint main(void) {
4f10118016f9b2fd7e1d26c9ef7d91eb33fba694Lennart Poettering _cleanup_manager_free_ Manager *manager = NULL;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering struct udev *udev;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering struct udev_device *loopback;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert_se(manager_new(&manager) >= 0);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering test_load_config(manager);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering udev = udev_new();
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert_se(udev);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering loopback = udev_device_new_from_syspath(udev, "/sys/class/net/lo");
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert_se(loopback);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert_se(udev_device_get_ifindex(loopback) == 1);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering test_network_get(manager, loopback);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering test_link(loopback);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert_se(manager_udev_listen(manager) >= 0);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert_se(manager_udev_enumerate_links(manager) >= 0);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert_se(manager_rtnl_listen(manager) >= 0);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering udev_device_unref(loopback);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering udev_unref(udev);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering}
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering