Commit 7726885a authored by Thomas Markwalder's avatar Thomas Markwalder
Browse files

[v4_1_esv] Updated common/tests Makefiles to build new unit tests

    Merges in rt20558_b.  This was a manual merge.
parent 250a8a15
...@@ -2211,9 +2211,10 @@ void set_option (universe, options, option, op) ...@@ -2211,9 +2211,10 @@ void set_option (universe, options, option, op)
(memcmp(oc->option->format, "Dc", 2) == 0))) { (memcmp(oc->option->format, "Dc", 2) == 0))) {
case 1: case 1:
/* Only one is "Dc", this won't work /* Only one is "Dc", this won't work
* Not sure if you make this occur, but just * Not sure if you can make this occur, but just
* in case. */ * in case. */
log_error ("Both options must be Dc format"); log_error ("Both options must be Dc format");
option_cache_dereference (&noc, MDL);
return; return;
case 2: case 2:
/* Both are "Dc", change the code */ /* Both are "Dc", change the code */
......
...@@ -8,13 +8,18 @@ ATF_TESTS = ...@@ -8,13 +8,18 @@ ATF_TESTS =
if HAVE_ATF if HAVE_ATF
ATF_TESTS += alloc_unittest ATF_TESTS += alloc_unittest ns_name_unittest
alloc_unittest_SOURCES = test_alloc.c $(top_srcdir)/tests/t_api_dhcp.c alloc_unittest_SOURCES = test_alloc.c $(top_srcdir)/tests/t_api_dhcp.c
alloc_unittest_LDADD = $(ATF_LDFLAGS) alloc_unittest_LDADD = $(ATF_LDFLAGS)
alloc_unittest_LDADD += ../libdhcp.a \ alloc_unittest_LDADD += ../libdhcp.a \
../../omapip/libomapi.a ../../dst/libdst.a ../../minires/libres.a ../../omapip/libomapi.a ../../dst/libdst.a ../../minires/libres.a
ns_name_unittest_SOURCES = ns_name_test.c $(top_srcdir)/tests/t_api_dhcp.c
ns_name_unittest_LDADD = $(ATF_LDFLAGS)
ns_name_unittest_LDADD += ../libdhcp.a \
../../omapip/libomapi.a ../../dst/libdst.a ../../minires/libres.a
check: $(ATF_TESTS) check: $(ATF_TESTS)
atf-run | atf-report atf-run | atf-report
......
...@@ -77,7 +77,7 @@ PRE_UNINSTALL = : ...@@ -77,7 +77,7 @@ PRE_UNINSTALL = :
POST_UNINSTALL = : POST_UNINSTALL = :
build_triplet = @build@ build_triplet = @build@
host_triplet = @host@ host_triplet = @host@
@HAVE_ATF_TRUE@am__append_1 = alloc_unittest @HAVE_ATF_TRUE@am__append_1 = alloc_unittest ns_name_unittest
check_PROGRAMS = $(am__EXEEXT_2) check_PROGRAMS = $(am__EXEEXT_2)
subdir = common/tests subdir = common/tests
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
...@@ -90,7 +90,8 @@ mkinstalldirs = $(install_sh) -d ...@@ -90,7 +90,8 @@ mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/includes/config.h CONFIG_HEADER = $(top_builddir)/includes/config.h
CONFIG_CLEAN_FILES = CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES = CONFIG_CLEAN_VPATH_FILES =
@HAVE_ATF_TRUE@am__EXEEXT_1 = alloc_unittest$(EXEEXT) @HAVE_ATF_TRUE@am__EXEEXT_1 = alloc_unittest$(EXEEXT) \
@HAVE_ATF_TRUE@ ns_name_unittest$(EXEEXT)
am__EXEEXT_2 = $(am__EXEEXT_1) am__EXEEXT_2 = $(am__EXEEXT_1)
am__alloc_unittest_SOURCES_DIST = test_alloc.c \ am__alloc_unittest_SOURCES_DIST = test_alloc.c \
$(top_srcdir)/tests/t_api_dhcp.c $(top_srcdir)/tests/t_api_dhcp.c
...@@ -101,6 +102,14 @@ am__DEPENDENCIES_1 = ...@@ -101,6 +102,14 @@ am__DEPENDENCIES_1 =
@HAVE_ATF_TRUE@alloc_unittest_DEPENDENCIES = $(am__DEPENDENCIES_1) \ @HAVE_ATF_TRUE@alloc_unittest_DEPENDENCIES = $(am__DEPENDENCIES_1) \
@HAVE_ATF_TRUE@ ../libdhcp.a ../../omapip/libomapi.a \ @HAVE_ATF_TRUE@ ../libdhcp.a ../../omapip/libomapi.a \
@HAVE_ATF_TRUE@ ../../dst/libdst.a ../../minires/libres.a @HAVE_ATF_TRUE@ ../../dst/libdst.a ../../minires/libres.a
am__ns_name_unittest_SOURCES_DIST = ns_name_test.c \
$(top_srcdir)/tests/t_api_dhcp.c
@HAVE_ATF_TRUE@am_ns_name_unittest_OBJECTS = ns_name_test.$(OBJEXT) \
@HAVE_ATF_TRUE@ t_api_dhcp.$(OBJEXT)
ns_name_unittest_OBJECTS = $(am_ns_name_unittest_OBJECTS)
@HAVE_ATF_TRUE@ns_name_unittest_DEPENDENCIES = $(am__DEPENDENCIES_1) \
@HAVE_ATF_TRUE@ ../libdhcp.a ../../omapip/libomapi.a \
@HAVE_ATF_TRUE@ ../../dst/libdst.a ../../minires/libres.a
AM_V_P = $(am__v_P_@AM_V@) AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false am__v_P_0 = false
...@@ -133,8 +142,9 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@) ...@@ -133,8 +142,9 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@)
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_0 = @echo " CCLD " $@;
am__v_CCLD_1 = am__v_CCLD_1 =
SOURCES = $(alloc_unittest_SOURCES) SOURCES = $(alloc_unittest_SOURCES) $(ns_name_unittest_SOURCES)
DIST_SOURCES = $(am__alloc_unittest_SOURCES_DIST) DIST_SOURCES = $(am__alloc_unittest_SOURCES_DIST) \
$(am__ns_name_unittest_SOURCES_DIST)
RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \
ctags-recursive dvi-recursive html-recursive info-recursive \ ctags-recursive dvi-recursive html-recursive info-recursive \
install-data-recursive install-dvi-recursive \ install-data-recursive install-dvi-recursive \
...@@ -311,6 +321,10 @@ ATF_TESTS = $(am__append_1) ...@@ -311,6 +321,10 @@ ATF_TESTS = $(am__append_1)
@HAVE_ATF_TRUE@alloc_unittest_LDADD = $(ATF_LDFLAGS) ../libdhcp.a \ @HAVE_ATF_TRUE@alloc_unittest_LDADD = $(ATF_LDFLAGS) ../libdhcp.a \
@HAVE_ATF_TRUE@ ../../omapip/libomapi.a ../../dst/libdst.a \ @HAVE_ATF_TRUE@ ../../omapip/libomapi.a ../../dst/libdst.a \
@HAVE_ATF_TRUE@ ../../minires/libres.a @HAVE_ATF_TRUE@ ../../minires/libres.a
@HAVE_ATF_TRUE@ns_name_unittest_SOURCES = ns_name_test.c $(top_srcdir)/tests/t_api_dhcp.c
@HAVE_ATF_TRUE@ns_name_unittest_LDADD = $(ATF_LDFLAGS) ../libdhcp.a \
@HAVE_ATF_TRUE@ ../../omapip/libomapi.a ../../dst/libdst.a \
@HAVE_ATF_TRUE@ ../../minires/libres.a
all: all-recursive all: all-recursive
.SUFFIXES: .SUFFIXES:
...@@ -353,12 +367,17 @@ alloc_unittest$(EXEEXT): $(alloc_unittest_OBJECTS) $(alloc_unittest_DEPENDENCIES ...@@ -353,12 +367,17 @@ alloc_unittest$(EXEEXT): $(alloc_unittest_OBJECTS) $(alloc_unittest_DEPENDENCIES
@rm -f alloc_unittest$(EXEEXT) @rm -f alloc_unittest$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(alloc_unittest_OBJECTS) $(alloc_unittest_LDADD) $(LIBS) $(AM_V_CCLD)$(LINK) $(alloc_unittest_OBJECTS) $(alloc_unittest_LDADD) $(LIBS)
ns_name_unittest$(EXEEXT): $(ns_name_unittest_OBJECTS) $(ns_name_unittest_DEPENDENCIES) $(EXTRA_ns_name_unittest_DEPENDENCIES)
@rm -f ns_name_unittest$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(ns_name_unittest_OBJECTS) $(ns_name_unittest_LDADD) $(LIBS)
mostlyclean-compile: mostlyclean-compile:
-rm -f *.$(OBJEXT) -rm -f *.$(OBJEXT)
distclean-compile: distclean-compile:
-rm -f *.tab.c -rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ns_name_test.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t_api_dhcp.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t_api_dhcp.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_alloc.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_alloc.Po@am__quote@
......
/*
* Copyright (c) 2014 by Internet Systems Consortium, Inc. ("ISC")
*
* Tests the newly added functions: MRns_name_compress_list and
* MRns_name_uncompress_list. These two functions rely on most of
* the other functions in ns_name.c. If these tests pass, then the
* majority of those functions work.
*
* This is not exhaustive test of these functions, much more could be
* done.
*/
#include "config.h"
#include <atf-c.h>
#include "dhcpd.h"
ATF_TC(MRns_name_list_funcs);
ATF_TC_HEAD(MRns_name_list_funcs, tc) {
atf_tc_set_md_var(tc, "descr", "MRns_name list funcs test, "
"compress from text, decompress to text");
}
void concat_lists (const char* label, struct data_string* list1,
struct data_string* list2, const char *refbuf, size_t reflen);
ATF_TC_BODY(MRns_name_list_funcs, tc) {
const char text_list[] = "one.two.com,three.two.com,four.two.com";
unsigned char comp_list[] = {
0x03,0x6f,0x6e,0x65,0x03,0x74,0x77,0x6f,0x03,0x63,0x6f,
0x6d,0x00,0x05,0x74,0x68,0x72,0x65,0x65,0xc0,0x04,0x04,
0x66,0x6f,0x75,0x72,0xc0,0x04};
unsigned char compbuf[sizeof(comp_list)];
char textbuf[sizeof(text_list)];
int ret;
memset(compbuf, 0x00, sizeof(compbuf));
/* Compress the reference text list */
ret = MRns_name_compress_list(text_list, sizeof(text_list),
compbuf, sizeof(compbuf));
/* Verify compressed length is correct */
ATF_REQUIRE_MSG((ret == sizeof(compbuf)), "compressed len %d wrong", ret);
/* Verify compressed content is correct */
ATF_REQUIRE_MSG((memcmp(comp_list, compbuf, sizeof(compbuf)) == 0),
"compressed buffer content wrong");
/* Decompress the new compressed list */
ret = MRns_name_uncompress_list(compbuf, ret, textbuf, sizeof(textbuf));
/* Verify decompressed length is correct */
ATF_REQUIRE_MSG((ret == strlen(text_list)),
"uncompressed len %d wrong", ret);
/* Verify decompressed content is correct */
ATF_REQUIRE_MSG((memcmp(textbuf, text_list, sizeof(textbuf)) == 0),
"uncompressed buffer content wrong");
}
ATF_TC(concat_dclists);
ATF_TC_HEAD(concat_dclists, tc) {
atf_tc_set_md_var(tc, "descr", "concat_dclists function test, "
"permutate concating empty and non-empty lists");
}
ATF_TC_BODY(concat_dclists, tc) {
/* Compressed list version of "booya.com" */
const char data[] =
{0x05, 0x62, 0x6f, 0x6f, 0x79, 0x61, 0x03, 0x63, 0x6f, 0x6d, 0x00 };
/* Concatenation of data with itself */
const char data2[] =
{0x05, 0x62, 0x6f, 0x6f, 0x79, 0x61, 0x03, 0x63, 0x6f, 0x6d, 0x00,
0xc0, 0x00 };
struct data_string nonempty;
struct data_string empty;
/* Make a non-empty compressed list from data[] */
nonempty.len = sizeof(data);
buffer_allocate(&(nonempty.buffer), nonempty.len, MDL);
memcpy(nonempty.buffer->data, data, nonempty.len);
nonempty.data = nonempty.buffer->data;
/* Permutate NULL with non-empty list */
concat_lists("null + null", NULL, NULL, "", 1);
concat_lists("null + nonempty", NULL, &nonempty, data, sizeof(data));
concat_lists("nonempty + null", &nonempty, NULL, data, sizeof(data));
/* Permutate zeroed-out list with non-empty list */
memset (&empty, 0x00, sizeof(struct data_string));
concat_lists("zero-list + zero-list", &empty, &empty, "", 1);
concat_lists("zero-list + nonempty", &empty, &nonempty, data, sizeof(data));
concat_lists("nonempty + zero-list", &nonempty, &empty, data, sizeof(data));
/* Create an empty list which is a buffer with 1 null in it */
/* Make sure those work the same as zeroed out data_strings */
buffer_allocate (&empty.buffer, 1, MDL);
empty.len = 1;
empty.data = empty.buffer->data;
/* Permutate with empty list */
concat_lists("empty + empty", &empty, &empty, "", 1);
concat_lists("empty + nonempty", &empty, &nonempty, data, sizeof(data));
concat_lists("nonempty + empty", &nonempty, &empty, data, sizeof(data));
/* Permutate with list len of 0 */
empty.len = 0;
concat_lists("zero-len + zero-len", &empty, &empty, "", 1);
concat_lists("zero-len + nonempty", &empty, &nonempty, data, sizeof(data));
concat_lists("nonempty + zero-len", &nonempty, &empty, data, sizeof(data));
/* Lastly, make sure two non-empty lists concat correctly */
concat_lists("nonempty + nonempty", &nonempty, &nonempty,
data2, sizeof(data2));
data_string_forget(&empty, MDL);
data_string_forget(&nonempty, MDL);
}
/* Helper function which tests concatenating two compressed lists
*
* \param label text to print in error message
* \param list1 data_string containing first list
* \param list2 data_string containing second list
* \param refbuf buffer containing the expected concatentated data
* \param reflen length of the expected data
*/
void concat_lists (const char* label, struct data_string* list1,
struct data_string* list2, const char *refbuf, size_t reflen)
{
struct data_string result;
int rc;
memset (&result, 0x00, sizeof(struct data_string));
rc = concat_dclists (&result, list1, list2);
ATF_REQUIRE_MSG((rc >= 0), "%s concat_dclists call failed %d",
label, rc);
ATF_REQUIRE_MSG(result.len == reflen, "%s result len: %d incorrect",
label, result.len);
if (refbuf != NULL) {
ATF_REQUIRE_MSG((memcmp(result.data, refbuf, reflen) == 0),
"%s content is incorrect", label);
}
data_string_forget(&result, MDL);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, MRns_name_list_funcs);
ATF_TP_ADD_TC(tp, concat_dclists);
return (atf_no_error());
}
...@@ -4516,7 +4516,7 @@ int concat_dclists (struct data_string* result, ...@@ -4516,7 +4516,7 @@ int concat_dclists (struct data_string* result,
int i; int i;
/* If not empty, uncompress first list into the uncompressed buffer */ /* If not empty, uncompress first list into the uncompressed buffer */
if ((list1->data) && (list1->len)) { if (list1 && (list1->data) && (list1->len)) {
list_len = MRns_name_uncompress_list(list1->data, list1->len, list_len = MRns_name_uncompress_list(list1->data, list1->len,
uncomp, sizeof(uncompbuf)); uncomp, sizeof(uncompbuf));
if (list_len < 0) { if (list_len < 0) {
...@@ -4530,7 +4530,7 @@ int concat_dclists (struct data_string* result, ...@@ -4530,7 +4530,7 @@ int concat_dclists (struct data_string* result,
} }
/* If not empty, uncompress second list into the uncompressed buffer */ /* If not empty, uncompress second list into the uncompressed buffer */
if ((list2->data) && (list2->len)) { if (list2 && (list2->data) && (list2->len)) {
/* If first list wasn't empty, add a comma */ /* If first list wasn't empty, add a comma */
if (uncomp_len > 0) { if (uncomp_len > 0) {
*uncomp++ = ','; *uncomp++ = ',';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment