convert rdatasetstats_test
This commit is contained in:
@@ -21,7 +21,7 @@ atf_test_program{name='rbt_serialize_test', is_exclusive=true}
|
||||
atf_test_program{name='rbt_test'}
|
||||
atf_test_program{name='rdata_test'}
|
||||
tap_test_program{name='rdataset_test'}
|
||||
atf_test_program{name='rdatasetstats_test'}
|
||||
tap_test_program{name='rdatasetstats_test'}
|
||||
atf_test_program{name='resolver_test'}
|
||||
tap_test_program{name='result_test'}
|
||||
atf_test_program{name='rsa_test'}
|
||||
|
||||
@@ -206,9 +206,9 @@ rdataset_test@EXEEXT@: rdataset_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS} ${CMOCKA_LIBS}
|
||||
|
||||
rdatasetstats_test@EXEEXT@: rdatasetstats_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
rdatasetstats_test.@O@ dnstest.@O@ ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \
|
||||
${LDFLAGS} -o $@ rdatasetstats_test.@O@ dnstest.@O@ \
|
||||
${DNSLIBS} ${ISCLIBS} ${LIBS} ${CMOCKA_LIBS}
|
||||
|
||||
resolver_test@EXEEXT@: resolver_test.@O@ dnstest.@O@ \
|
||||
${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
|
||||
@@ -9,40 +9,67 @@
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/print.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/stats.h>
|
||||
|
||||
#include "dnstest.h"
|
||||
|
||||
/*
|
||||
* Helper functions
|
||||
*/
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
set_typestats(dns_stats_t *stats, dns_rdatatype_t type,
|
||||
bool stale)
|
||||
{
|
||||
set_typestats(dns_stats_t *stats, dns_rdatatype_t type, bool stale) {
|
||||
dns_rdatastatstype_t which;
|
||||
unsigned int attributes;
|
||||
|
||||
attributes = 0;
|
||||
if (stale) attributes |= DNS_RDATASTATSTYPE_ATTR_STALE;
|
||||
if (stale) {
|
||||
attributes |= DNS_RDATASTATSTYPE_ATTR_STALE;
|
||||
}
|
||||
which = DNS_RDATASTATSTYPE_VALUE(type, attributes);
|
||||
dns_rdatasetstats_increment(stats, which);
|
||||
|
||||
attributes = DNS_RDATASTATSTYPE_ATTR_NXRRSET;
|
||||
if (stale) attributes |= DNS_RDATASTATSTYPE_ATTR_STALE;
|
||||
if (stale) {
|
||||
attributes |= DNS_RDATASTATSTYPE_ATTR_STALE;
|
||||
}
|
||||
which = DNS_RDATASTATSTYPE_VALUE(type, attributes);
|
||||
dns_rdatasetstats_increment(stats, which);
|
||||
}
|
||||
@@ -53,7 +80,9 @@ set_nxdomainstats(dns_stats_t *stats, bool stale) {
|
||||
unsigned int attributes;
|
||||
|
||||
attributes = DNS_RDATASTATSTYPE_ATTR_NXDOMAIN;
|
||||
if (stale) attributes |= DNS_RDATASTATSTYPE_ATTR_STALE;
|
||||
if (stale) {
|
||||
attributes |= DNS_RDATASTATSTYPE_ATTR_STALE;
|
||||
}
|
||||
which = DNS_RDATASTATSTYPE_VALUE(0, attributes);
|
||||
dns_rdatasetstats_increment(stats, which);
|
||||
}
|
||||
@@ -80,10 +109,11 @@ checkit1(dns_rdatastatstype_t which, uint64_t value, void *arg) {
|
||||
ATTRIBUTE_SET(DNS_RDATASTATSTYPE_ATTR_NXDOMAIN) ? "X" : " ",
|
||||
type, (unsigned)value);
|
||||
#endif
|
||||
if ((attributes & DNS_RDATASTATSTYPE_ATTR_STALE) == 0)
|
||||
ATF_REQUIRE_EQ(value, 1);
|
||||
else
|
||||
ATF_REQUIRE_EQ(value, 0);
|
||||
if ((attributes & DNS_RDATASTATSTYPE_ATTR_STALE) == 0) {
|
||||
assert_int_equal(value, 1);
|
||||
} else {
|
||||
assert_int_equal(value, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -107,31 +137,27 @@ checkit2(dns_rdatastatstype_t which, uint64_t value, void *arg) {
|
||||
ATTRIBUTE_SET(DNS_RDATASTATSTYPE_ATTR_NXDOMAIN) ? "X" : " ",
|
||||
type, (unsigned)value);
|
||||
#endif
|
||||
if ((attributes & DNS_RDATASTATSTYPE_ATTR_STALE) == 0)
|
||||
ATF_REQUIRE_EQ(value, 0);
|
||||
else
|
||||
ATF_REQUIRE_EQ(value, 1);
|
||||
if ((attributes & DNS_RDATASTATSTYPE_ATTR_STALE) == 0) {
|
||||
assert_int_equal(value, 0);
|
||||
} else {
|
||||
assert_int_equal(value, 1);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Individual unit tests
|
||||
*/
|
||||
|
||||
ATF_TC(rdatasetstats);
|
||||
ATF_TC_HEAD(rdatasetstats, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test that rdatasetstats counters are properly set");
|
||||
}
|
||||
ATF_TC_BODY(rdatasetstats, tc) {
|
||||
/* test that rdatasetstats counters are properly set */
|
||||
static void
|
||||
rdatasetstats(void **state) {
|
||||
unsigned int i;
|
||||
dns_stats_t *stats = NULL;
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = dns_test_begin(NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_rdatasetstats_create(mctx, &stats);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/* First 256 types. */
|
||||
for (i = 0; i <= 255; i++)
|
||||
@@ -160,14 +186,26 @@ ATF_TC_BODY(rdatasetstats, tc) {
|
||||
dns_rdatasetstats_dump(stats, checkit2, NULL, 1);
|
||||
|
||||
dns_stats_detach(&stats);
|
||||
dns_test_end();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, rdatasetstats);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(rdatasetstats,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user