diff options
author | Shawn Routhier <sar@isc.org> | 2014-06-05 14:55:01 -0700 |
---|---|---|
committer | Shawn Routhier <sar@isc.org> | 2014-06-05 14:55:01 -0700 |
commit | 250f7134bbe06f5014ab12dfd8a459c9b39e17cb (patch) | |
tree | 1c133ba8b68a77c044bd8259e52f9afd9e5e607e /common/tests | |
parent | 0ab4a716125d7945645bc0b3935c052edee0e97d (diff) | |
download | isc-dhcp-250f7134bbe06f5014ab12dfd8a459c9b39e17cb.tar.gz |
[master] Add support for pool thresholds
Add support to set high and low thresholds for pools for
v4 and v6. A message will be emitted when the usage of
the pool first exceeds the high threshold. More messages
will be skipped until the usage has gone below the low
threshold and then back above the high threshold.
Diffstat (limited to 'common/tests')
-rw-r--r-- | common/tests/Makefile.am | 8 | ||||
-rw-r--r-- | common/tests/Makefile.in | 31 | ||||
-rw-r--r-- | common/tests/misc_unittest.c | 166 |
3 files changed, 200 insertions, 5 deletions
diff --git a/common/tests/Makefile.am b/common/tests/Makefile.am index 18456be8..08d76fc3 100644 --- a/common/tests/Makefile.am +++ b/common/tests/Makefile.am @@ -8,7 +8,7 @@ ATF_TESTS = if HAVE_ATF -ATF_TESTS += alloc_unittest dns_unittest +ATF_TESTS += alloc_unittest dns_unittest misc_unittest alloc_unittest_SOURCES = test_alloc.c $(top_srcdir)/tests/t_api_dhcp.c alloc_unittest_LDADD = $(ATF_LDFLAGS) @@ -22,6 +22,12 @@ dns_unittest_LDADD += ../libdhcp.a \ ../../omapip/libomapi.a ../../bind/lib/libirs.a \ ../../bind/lib/libdns.a ../../bind/lib/libisccfg.a ../../bind/lib/libisc.a +misc_unittest_SOURCES = misc_unittest.c $(top_srcdir)/tests/t_api_dhcp.c +misc_unittest_LDADD = $(ATF_LDFLAGS) +misc_unittest_LDADD += ../libdhcp.a \ + ../../omapip/libomapi.a ../../bind/lib/libirs.a \ + ../../bind/lib/libdns.a ../../bind/lib/libisccfg.a ../../bind/lib/libisc.a + check: $(ATF_TESTS) atf-run | atf-report diff --git a/common/tests/Makefile.in b/common/tests/Makefile.in index 76b0ac8a..8a5d3f1e 100644 --- a/common/tests/Makefile.in +++ b/common/tests/Makefile.in @@ -77,7 +77,7 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -@HAVE_ATF_TRUE@am__append_1 = alloc_unittest dns_unittest +@HAVE_ATF_TRUE@am__append_1 = alloc_unittest dns_unittest misc_unittest check_PROGRAMS = $(am__EXEEXT_2) subdir = common/tests DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ @@ -91,7 +91,7 @@ CONFIG_HEADER = $(top_builddir)/includes/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = @HAVE_ATF_TRUE@am__EXEEXT_1 = alloc_unittest$(EXEEXT) \ -@HAVE_ATF_TRUE@ dns_unittest$(EXEEXT) +@HAVE_ATF_TRUE@ dns_unittest$(EXEEXT) misc_unittest$(EXEEXT) am__EXEEXT_2 = $(am__EXEEXT_1) am__alloc_unittest_SOURCES_DIST = test_alloc.c \ $(top_srcdir)/tests/t_api_dhcp.c @@ -114,6 +114,16 @@ dns_unittest_OBJECTS = $(am_dns_unittest_OBJECTS) @HAVE_ATF_TRUE@ ../../bind/lib/libirs.a ../../bind/lib/libdns.a \ @HAVE_ATF_TRUE@ ../../bind/lib/libisccfg.a \ @HAVE_ATF_TRUE@ ../../bind/lib/libisc.a +am__misc_unittest_SOURCES_DIST = misc_unittest.c \ + $(top_srcdir)/tests/t_api_dhcp.c +@HAVE_ATF_TRUE@am_misc_unittest_OBJECTS = misc_unittest.$(OBJEXT) \ +@HAVE_ATF_TRUE@ t_api_dhcp.$(OBJEXT) +misc_unittest_OBJECTS = $(am_misc_unittest_OBJECTS) +@HAVE_ATF_TRUE@misc_unittest_DEPENDENCIES = $(am__DEPENDENCIES_1) \ +@HAVE_ATF_TRUE@ ../libdhcp.a ../../omapip/libomapi.a \ +@HAVE_ATF_TRUE@ ../../bind/lib/libirs.a ../../bind/lib/libdns.a \ +@HAVE_ATF_TRUE@ ../../bind/lib/libisccfg.a \ +@HAVE_ATF_TRUE@ ../../bind/lib/libisc.a AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false @@ -146,9 +156,11 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@) am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = -SOURCES = $(alloc_unittest_SOURCES) $(dns_unittest_SOURCES) +SOURCES = $(alloc_unittest_SOURCES) $(dns_unittest_SOURCES) \ + $(misc_unittest_SOURCES) DIST_SOURCES = $(am__alloc_unittest_SOURCES_DIST) \ - $(am__dns_unittest_SOURCES_DIST) + $(am__dns_unittest_SOURCES_DIST) \ + $(am__misc_unittest_SOURCES_DIST) RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ ctags-recursive dvi-recursive html-recursive info-recursive \ install-data-recursive install-dvi-recursive \ @@ -334,6 +346,12 @@ ATF_TESTS = $(am__append_1) @HAVE_ATF_TRUE@ ../../bind/lib/libdns.a \ @HAVE_ATF_TRUE@ ../../bind/lib/libisccfg.a \ @HAVE_ATF_TRUE@ ../../bind/lib/libisc.a +@HAVE_ATF_TRUE@misc_unittest_SOURCES = misc_unittest.c $(top_srcdir)/tests/t_api_dhcp.c +@HAVE_ATF_TRUE@misc_unittest_LDADD = $(ATF_LDFLAGS) ../libdhcp.a \ +@HAVE_ATF_TRUE@ ../../omapip/libomapi.a ../../bind/lib/libirs.a \ +@HAVE_ATF_TRUE@ ../../bind/lib/libdns.a \ +@HAVE_ATF_TRUE@ ../../bind/lib/libisccfg.a \ +@HAVE_ATF_TRUE@ ../../bind/lib/libisc.a all: all-recursive .SUFFIXES: @@ -380,6 +398,10 @@ dns_unittest$(EXEEXT): $(dns_unittest_OBJECTS) $(dns_unittest_DEPENDENCIES) $(EX @rm -f dns_unittest$(EXEEXT) $(AM_V_CCLD)$(LINK) $(dns_unittest_OBJECTS) $(dns_unittest_LDADD) $(LIBS) +misc_unittest$(EXEEXT): $(misc_unittest_OBJECTS) $(misc_unittest_DEPENDENCIES) $(EXTRA_misc_unittest_DEPENDENCIES) + @rm -f misc_unittest$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(misc_unittest_OBJECTS) $(misc_unittest_LDADD) $(LIBS) + mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -387,6 +409,7 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dns_unittest.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc_unittest.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@ diff --git a/common/tests/misc_unittest.c b/common/tests/misc_unittest.c new file mode 100644 index 00000000..6cefa6e7 --- /dev/null +++ b/common/tests/misc_unittest.c @@ -0,0 +1,166 @@ +/* + * Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC") + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include <config.h> +#include <atf-c.h> +#include "dhcpd.h" + +struct basic_test { + int count; + int used_0; + int used_25; + int used_50; + int used_75; + int used_100; +}; + +struct basic_test basic_values[] = + {{ 0, 0, 0, 0, 0, 0}, + { 10, 0, 2, 5, 7, 10}, + { 20, 0, 5, 10, 15, 20}, + { 50, 0, 12, 25, 37, 50}, + { 100, 0, 25, 50, 75, 100}, + { 1000, 0, 250, 500, 750, 1000}, + { 10000, 0, 2500, 5000, 7500, 10000}, + { 100000, 0, 25000, 50000, 75000, 100000}, + { 1000000, 0, 250000, 500000, 750000, 1000000}, + { 10000000, 0, 2500000, 5000000, 7500000, 10000000}, + { 100000000, 0, 25000000, 50000000, 75000000, 100000000}, + {1000000000, 0, 250000000, 500000000, 750000000, 1000000000}, + {2000000000, 0, 500000000, 1000000000, 1500000000, 2000000000}, + {-1, 0, 0, 0, 0, 0}}; + +ATF_TC(find_percent_basic); + +ATF_TC_HEAD(find_percent_basic, tc) +{ + atf_tc_set_md_var(tc, "descr", "Verify basic percent calculation."); +} + +/* This test does a simple check to see if we get the right value + * given a count and a percnetage of that count + */ +ATF_TC_BODY(find_percent_basic, tc) +{ + struct basic_test *basic_value; + int used; + + for (basic_value = &basic_values[0]; + basic_value->count != -1; + basic_value++) { + used = FIND_PERCENT(basic_value->count, 0); + if (used != basic_value->used_0) { + atf_tc_fail("Wrong value for 0 - count: %d, used %d", + basic_value->count, used); + } + + used = FIND_PERCENT(basic_value->count, 25); + if (used != basic_value->used_25) { + atf_tc_fail("Wrong value for 25 - count: %d, used %d", + basic_value->count, used); + } + + used = FIND_PERCENT(basic_value->count, 50); + if (used != basic_value->used_50) { + atf_tc_fail("Wrong value for 50 - count: %d, used %d", + basic_value->count, used); + } + + used = FIND_PERCENT(basic_value->count, 75); + if (used != basic_value->used_75) { + atf_tc_fail("Wrong value for 75 - count: %d, used %d", + basic_value->count, used); + } + + used = FIND_PERCENT(basic_value->count, 100); + if (used != basic_value->used_100) { + atf_tc_fail("Wrong value for 100 - count: %d, used %d", + basic_value->count, used); + } + } + return; +} + +ATF_TC(find_percent_adv); + +ATF_TC_HEAD(find_percent_adv, tc) +{ + atf_tc_set_md_var(tc, "descr", "Verify advanced percent calculation."); +} + +/* This test tries some more complicated items, such as using the macro + * in a function or passing expressions into macro + */ +ATF_TC_BODY(find_percent_adv, tc) +{ + if (FIND_PERCENT(10*10, 10) != 10) { + atf_tc_fail("Wrong value for adv 1"); + } + + if (FIND_PERCENT(20*20, 80) != 320) { + atf_tc_fail("Wrong value for adv 2"); + } + + if (FIND_PERCENT(1000000*1000, 50) != 500000000) { + atf_tc_fail("Wrong value for adv 3"); + } + + if (FIND_PERCENT(100+100, 10) != 20) { + atf_tc_fail("Wrong value for adv 4"); + } + + if (FIND_PERCENT(1000+2000, 90) != 2700) { + atf_tc_fail("Wrong value for adv 5"); + } + + if (FIND_PERCENT(10000 - 8000, 70) != 1400) { + atf_tc_fail("Wrong value for adv 6"); + } + + if (FIND_PERCENT(2000000000 / 1000, 25) != 500000) { + atf_tc_fail("Wrong value for adv 7"); + } + + if (FIND_PERCENT(10*10, 10)/2 != 5) { + atf_tc_fail("Wrong value for adv 8"); + } + + if (FIND_PERCENT(100*10, 50) * 2 != 1000) { + atf_tc_fail("Wrong value for adv 9"); + } + + if (FIND_PERCENT(100*10, 50) * 2 > 1000) { + atf_tc_fail("Wrong value for adv 10"); + } + + if (FIND_PERCENT(100+100, 20) * 2 < 60) { + atf_tc_fail("Wrong value for adv 11"); + } + + return; +} + + +/* This macro defines main() method that will call specified + test cases. tp and simple_test_case names can be whatever you want + as long as it is a valid variable identifier. */ +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, find_percent_basic); + ATF_TP_ADD_TC(tp, find_percent_adv); + + return (atf_no_error()); +} |