test-dhcp-client.c revision 58587a7a0c3bf5595190486781d3bbc00654c6ef
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright (C) 2013 Intel Corporation. All rights reserved.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is free software; you can redistribute it and/or modify it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering under the terms of the GNU Lesser General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is distributed in the hope that it will be useful, but
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Lesser General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering You should have received a copy of the GNU Lesser General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
eed857b71702f8551b46b66b31fa0d08583cf23cLennart Poettering .ether_addr_octet = {'A', 'B', 'C', '1', '2', '3'}
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringtypedef int (*test_callback_recv_t)(size_t size, DHCPMessage *dhcp);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic bool verbose = false;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic test_callback_recv_t callback_recv;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poetteringstatic int test_dhcp_hangcheck(sd_event_source *s, uint64_t usec,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert_not_reached("Test case should have completed in 2 seconds");
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic void test_request_basic(sd_event *e)
8a516214c4412e8a40544bd725a6d499a30cbbbfLennart Poettering r = sd_dhcp_client_attach_event(client, e, 0);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering assert_se(sd_dhcp_client_set_request_option(NULL, 0) == -EINVAL);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering assert_se(sd_dhcp_client_set_request_address(NULL, NULL) == -EINVAL);
b4f1862df2e45aba90386887d685b8bf3c840e10Daniel Mack assert_se(sd_dhcp_client_set_index(NULL, 0) == -EINVAL);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert_se(sd_dhcp_client_set_index(client, 15) == 0);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering assert_se(sd_dhcp_client_set_index(client, -42) == -EINVAL);
e1c959948c0e31d6997bcdfbabfbd077784b2baeLennart Poettering assert_se(sd_dhcp_client_set_index(client, -1) == -EINVAL);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert_se(sd_dhcp_client_set_index(client, 0) == -EINVAL);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert_se(sd_dhcp_client_set_index(client, 1) == 0);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert_se(sd_dhcp_client_set_request_option(client,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert_se(sd_dhcp_client_set_request_option(client,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering assert_se(sd_dhcp_client_set_request_option(client,
2c27fbca2d88214bd305272308a370a962818f1eLennart Poettering assert_se(sd_dhcp_client_set_request_option(client,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert_se(sd_dhcp_client_set_request_option(client,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering assert_se(sd_dhcp_client_set_request_option(client,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert_se(sd_dhcp_client_set_request_option(client,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert_se(sd_dhcp_client_set_request_option(client,
== -EINVAL);
static void test_checksum(void)
if (verbose)
void *user_data)
switch(code) {
assert_se(s >= 0);
int dhcp_network_bind_raw_socket(int index, union sockaddr_union *link, uint32_t id, struct ether_addr mac)
return -errno;
return test_fd[0];
int res;
if (verbose)
int res, r;
if (verbose)
assert_se(r >= 0);
assert_se(r >= 0);
void *userdata) {
if (verbose)
sd_event_exit(e, 0);
int res;
if (verbose)
sizeof(test_addr_acq_ack));
if (verbose)
int res;
if (verbose)
sizeof(test_addr_acq_offer));
if (verbose)
int res, r;
if (verbose)
assert_se(r >= 0);
assert_se(r >= 0);
sd_event_loop(e);
xid = 0;
log_open();
test_addr_acq(e);