]>
git.ipfire.org Git - thirdparty/dhcp.git/blob - client/tests/duid_unittest.c
2 * Copyright (C) 2017-2022 Internet Systems Consortium, Inc. ("ISC")
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
14 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 * Internet Systems Consortium, Inc.
18 * Newmarket, NH 03857 USA
20 * https://www.isc.org/
26 #include <omapip/omapip_p.h>
30 /* Tests to see if the routine to read a secondary lease file
31 * for the DUID works properly. The tests:
33 * no test file - should result in no duid
35 * A test file but no DUID def, no duid
37 * Can it read a single DUID in the file?
39 * Can it find a second DUID in the file after a good lease and
40 * a badly formatted lease?
42 * Can it find a later DUID after a good one and a bad one?
43 * and to give a bit more coverage test file 1 should use LLT
44 * test file 2 should use LL and test file 3 should use LL for
45 * the first one and LLT for the third one.
53 char duid1_data
[] = {0, 1, 0, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
56 char duid2_data
[] = {0, 3, 0, 1, 15, 16, 17, 18, 19, 20};
59 char duid3_data
[] = {0, 1, 0, 1, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30};
61 ATF_TC(read_duid_test
);
63 ATF_TC_HEAD(read_duid_test
, tc
) {
64 atf_tc_set_md_var(tc
, "descr", "read secondary file looking for duid");
67 ATF_TC_BODY(read_duid_test
, tc
) {
69 static const char *srcdir
;
70 char duid_fname
[1024];
72 /* Get the srcidr so we can find our test files */
73 if (atf_tc_has_config_var(tc
, "srcdir"))
74 srcdir
= atf_tc_get_config_var(tc
, "srcdir");
75 /* point the duid file at our filename space
76 We will update it per test below */
77 path_dhclient_duid
= duid_fname
;
79 /* Initialize client globals. */
80 memset(&default_duid
, 0, sizeof(default_duid
));
82 /* Try to read a nonexistent test file
84 sprintf(duid_fname
, "%s/duidx_test.txt", srcdir
);
86 if (default_duid
.len
!= duidx_len
) {
87 atf_tc_fail("failed to properly read duid1");
90 /* Try to read test file 0
91 * This doesn't have a DUID.
93 sprintf(duid_fname
, "%s/duid0_test.txt", srcdir
);
95 if (default_duid
.len
!= duid0_len
) {
96 atf_tc_fail("failed to properly read duid0");
99 /* Try to read test file 1
100 * This has a single good LLT DUID in it
102 sprintf(duid_fname
, "%s/duid1_test.txt", srcdir
);
104 if ((default_duid
.len
!= duid1_len
) ||
105 (memcmp(default_duid
.data
, duid1_data
, duid1_len
) != 0)) {
106 atf_tc_fail("failed to properly read duid1");
109 /* Try to read test file 2
110 * This has two good LL DUIDs in it with several good and bad leases between them.
112 sprintf(duid_fname
, "%s/duid2_test.txt", srcdir
);
114 if ((default_duid
.len
!= duid2_len
) ||
115 (memcmp(default_duid
.data
, duid2_data
, duid2_len
) != 0)) {
116 atf_tc_fail("failed to properly read duid2");
119 /* Try to read test file 3
120 * This has a good LL DUID, a bad LLT DUID and a good LLT DUID
122 sprintf(duid_fname
, "%s/duid3_test.txt", srcdir
);
124 if ((default_duid
.len
!= duid3_len
) ||
125 (memcmp(default_duid
.data
, duid3_data
, duid3_len
) != 0)) {
126 atf_tc_fail("failed to properly read duid3");
133 ATF_TP_ADD_TC(tp
, read_duid_test
);
135 return (atf_no_error());