2015-10-02 12:32:42 -07:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2015-10-02 12:32:42 -07:00
|
|
|
*
|
2016-06-27 14:56:38 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
2020-09-14 16:20:40 -07:00
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2015-10-02 12:32:42 -07:00
|
|
|
*/
|
|
|
|
|
2018-10-24 21:41:30 -07:00
|
|
|
#if HAVE_CMOCKA
|
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
#include <inttypes.h>
|
Include <sched.h> where necessary for musl libc
All unit tests define the UNIT_TESTING macro, which causes <cmocka.h> to
replace malloc(), calloc(), realloc(), and free() with its own functions
tracking memory allocations. In order for this not to break
compilation, the system header declaring the prototypes for these
standard functions must be included before <cmocka.h>.
Normally, these prototypes are only present in <stdlib.h>, so we make
sure it is included before <cmocka.h>. However, musl libc also defines
the prototypes for calloc() and free() in <sched.h>, which is included
by <pthread.h>, which is included e.g. by <isc/mutex.h>. Thus, unit
tests including "dnstest.h" (which includes <isc/mem.h>, which includes
<isc/mutex.h>) after <cmocka.h> will not compile with musl libc as for
these programs, <sched.h> will be included after <cmocka.h>.
Always including <cmocka.h> after all other header files is not a
feasible solution as that causes the mock assertion macros defined in
<isc/util.h> to mangle the contents of <cmocka.h>, thus breaking
compilation. We cannot really use the __noreturn__ or analyzer_noreturn
attributes with cmocka assertion functions because they do return if the
tested condition is true. The problem is that what BIND unit tests do
is incompatible with Clang Static Analyzer's assumptions: since we use
cmocka, our custom assertion handlers are present in a shared library
(i.e. it is the cmocka library that checks the assertion condition, not
a macro in unit test code). Redefining cmocka's assertion macros in
<isc/util.h> is an ugly hack to overcome that problem - unfortunately,
this is the only way we can think of to make Clang Static Analyzer
properly process unit test code. Giving up on Clang Static Analyzer
being able to properly process unit test code is not a satisfactory
solution.
Undefining _GNU_SOURCE for unit test code could work around the problem
(musl libc's <sched.h> only defines the prototypes for calloc() and
free() when _GNU_SOURCE is defined), but doing that could introduce
discrepancies for unit tests including entire *.c files, so it is also
not a good solution.
All in all, including <sched.h> before <cmocka.h> for all affected unit
tests seems to be the most benign way of working around this musl libc
quirk. While quite an ugly solution, it achieves our goals here, which
are to keep the benefit of proper static analysis of unit test code and
to fix compilation against musl libc.
2019-07-30 21:08:40 +02:00
|
|
|
#include <sched.h> /* IWYU pragma: keep */
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <setjmp.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
2015-10-02 12:32:42 -07:00
|
|
|
#include <stdlib.h>
|
2018-10-24 21:41:30 -07:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#define UNIT_TESTING
|
|
|
|
#include <cmocka.h>
|
2015-10-02 12:32:42 -07:00
|
|
|
|
|
|
|
#include <isc/buffer.h>
|
|
|
|
#include <isc/file.h>
|
|
|
|
#include <isc/print.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <isc/stdio.h>
|
2015-10-02 12:32:42 -07:00
|
|
|
#include <isc/types.h>
|
2018-10-24 21:41:30 -07:00
|
|
|
#include <isc/util.h>
|
2015-10-02 12:32:42 -07:00
|
|
|
|
|
|
|
#include <dns/dnstap.h>
|
|
|
|
#include <dns/view.h>
|
|
|
|
|
|
|
|
#include "dnstest.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_DNSTAP
|
2019-03-22 10:36:25 +01:00
|
|
|
|
2015-10-02 12:32:42 -07:00
|
|
|
#include <protobuf-c/protobuf-c.h>
|
|
|
|
|
|
|
|
#define TAPFILE "testdata/dnstap/dnstap.file"
|
|
|
|
#define TAPSOCK "testdata/dnstap/dnstap.sock"
|
|
|
|
|
|
|
|
#define TAPSAVED "testdata/dnstap/dnstap.saved"
|
2020-02-13 14:44:37 -08:00
|
|
|
#define TAPTEXT "testdata/dnstap/dnstap.text"
|
2015-10-02 12:32:42 -07:00
|
|
|
|
2018-10-24 21:41:30 -07:00
|
|
|
static int
|
2020-02-13 14:44:37 -08:00
|
|
|
_setup(void **state) {
|
2018-10-24 21:41:30 -07:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
result = dns_test_begin(NULL, false);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-02-13 14:44:37 -08:00
|
|
|
_teardown(void **state) {
|
2018-10-24 21:41:30 -07:00
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2015-10-02 12:32:42 -07:00
|
|
|
static void
|
2018-08-07 16:46:53 +02:00
|
|
|
cleanup(void) {
|
2020-02-12 13:59:18 +01:00
|
|
|
(void)isc_file_remove(TAPFILE);
|
|
|
|
(void)isc_file_remove(TAPSOCK);
|
2015-10-02 12:32:42 -07:00
|
|
|
}
|
|
|
|
|
2018-10-24 21:41:30 -07:00
|
|
|
/* set up dnstap environment */
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
create_test(void **state) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_dtenv_t *dtenv = NULL;
|
2016-08-18 11:16:06 +10:00
|
|
|
struct fstrm_iothr_options *fopt;
|
2015-10-02 12:32:42 -07:00
|
|
|
|
2018-10-24 21:41:30 -07:00
|
|
|
UNUSED(state);
|
2015-10-02 12:32:42 -07:00
|
|
|
|
|
|
|
cleanup();
|
|
|
|
|
2016-08-18 11:16:06 +10:00
|
|
|
fopt = fstrm_iothr_options_init();
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_non_null(fopt);
|
2016-08-18 11:16:06 +10:00
|
|
|
fstrm_iothr_options_set_num_input_queues(fopt, 1);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_dt_create(dt_mctx, dns_dtmode_file, TAPFILE, &fopt, NULL,
|
|
|
|
&dtenv);
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
if (dtenv != NULL) {
|
2015-10-02 12:32:42 -07:00
|
|
|
dns_dt_detach(&dtenv);
|
2018-10-24 21:41:30 -07:00
|
|
|
}
|
|
|
|
if (fopt != NULL) {
|
2016-08-25 10:03:22 +10:00
|
|
|
fstrm_iothr_options_destroy(&fopt);
|
2018-10-24 21:41:30 -07:00
|
|
|
}
|
2015-10-02 12:32:42 -07:00
|
|
|
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_true(isc_file_exists(TAPFILE));
|
2015-10-02 12:32:42 -07:00
|
|
|
|
2016-08-25 10:03:22 +10:00
|
|
|
fopt = fstrm_iothr_options_init();
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_non_null(fopt);
|
2016-08-25 10:03:22 +10:00
|
|
|
fstrm_iothr_options_set_num_input_queues(fopt, 1);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_dt_create(dt_mctx, dns_dtmode_unix, TAPSOCK, &fopt, NULL,
|
|
|
|
&dtenv);
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
if (dtenv != NULL) {
|
2015-10-02 12:32:42 -07:00
|
|
|
dns_dt_detach(&dtenv);
|
2018-10-24 21:41:30 -07:00
|
|
|
}
|
|
|
|
if (fopt != NULL) {
|
2016-08-25 10:03:22 +10:00
|
|
|
fstrm_iothr_options_destroy(&fopt);
|
2018-10-24 21:41:30 -07:00
|
|
|
}
|
2015-10-02 12:32:42 -07:00
|
|
|
|
|
|
|
/* 'create' should succeed, but the file shouldn't exist yet */
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_false(isc_file_exists(TAPSOCK));
|
2015-10-02 12:32:42 -07:00
|
|
|
|
2016-08-25 10:03:22 +10:00
|
|
|
fopt = fstrm_iothr_options_init();
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_non_null(fopt);
|
2016-08-25 10:03:22 +10:00
|
|
|
fstrm_iothr_options_set_num_input_queues(fopt, 1);
|
|
|
|
|
2019-06-18 15:01:43 +02:00
|
|
|
result = dns_dt_create(dt_mctx, 33, TAPSOCK, &fopt, NULL, &dtenv);
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_int_equal(result, ISC_R_FAILURE);
|
|
|
|
assert_null(dtenv);
|
|
|
|
if (dtenv != NULL) {
|
2016-08-25 10:03:22 +10:00
|
|
|
dns_dt_detach(&dtenv);
|
2018-10-24 21:41:30 -07:00
|
|
|
}
|
|
|
|
if (fopt != NULL) {
|
2016-08-25 10:03:22 +10:00
|
|
|
fstrm_iothr_options_destroy(&fopt);
|
2018-10-24 21:41:30 -07:00
|
|
|
}
|
2015-10-02 12:32:42 -07:00
|
|
|
|
|
|
|
cleanup();
|
|
|
|
}
|
|
|
|
|
2018-10-24 21:41:30 -07:00
|
|
|
/* send dnstap messages */
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
send_test(void **state) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_dtenv_t *dtenv = NULL;
|
|
|
|
dns_dthandle_t *handle = NULL;
|
|
|
|
uint8_t *data;
|
|
|
|
size_t dsize;
|
|
|
|
unsigned char zone[DNS_NAME_MAXWIRE];
|
|
|
|
unsigned char qambuffer[4096], rambuffer[4096];
|
|
|
|
unsigned char qrmbuffer[4096], rrmbuffer[4096];
|
|
|
|
isc_buffer_t zb, qamsg, ramsg, qrmsg, rrmsg;
|
|
|
|
size_t qasize, qrsize, rasize, rrsize;
|
|
|
|
dns_fixedname_t zfname;
|
|
|
|
dns_name_t *zname;
|
|
|
|
dns_dtmsgtype_t dt;
|
|
|
|
dns_view_t *view = NULL;
|
|
|
|
dns_compress_t cctx;
|
|
|
|
isc_region_t zr;
|
|
|
|
isc_sockaddr_t qaddr;
|
|
|
|
isc_sockaddr_t raddr;
|
|
|
|
struct in_addr in;
|
|
|
|
isc_stdtime_t now;
|
|
|
|
isc_time_t p, f;
|
2016-08-18 11:16:06 +10:00
|
|
|
struct fstrm_iothr_options *fopt;
|
2015-10-02 12:32:42 -07:00
|
|
|
|
2018-10-24 21:41:30 -07:00
|
|
|
UNUSED(state);
|
2015-10-02 12:32:42 -07:00
|
|
|
|
|
|
|
cleanup();
|
|
|
|
|
|
|
|
result = dns_test_makeview("test", &view);
|
2019-10-31 06:50:58 -05:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2015-10-02 12:32:42 -07:00
|
|
|
|
2016-08-18 11:16:06 +10:00
|
|
|
fopt = fstrm_iothr_options_init();
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_non_null(fopt);
|
2016-08-18 11:16:06 +10:00
|
|
|
fstrm_iothr_options_set_num_input_queues(fopt, 1);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_dt_create(dt_mctx, dns_dtmode_file, TAPFILE, &fopt, NULL,
|
|
|
|
&dtenv);
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2015-10-02 12:32:42 -07:00
|
|
|
|
|
|
|
dns_dt_attach(dtenv, &view->dtenv);
|
|
|
|
view->dttypes = DNS_DTTYPE_ALL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up some test data
|
|
|
|
*/
|
2018-03-28 14:38:09 +02:00
|
|
|
zname = dns_fixedname_initname(&zfname);
|
2015-10-02 12:32:42 -07:00
|
|
|
isc_buffer_constinit(&zb, "example.com.", 12);
|
|
|
|
isc_buffer_add(&zb, 12);
|
|
|
|
result = dns_name_fromtext(zname, &zb, NULL, 0, NULL);
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2015-10-02 12:32:42 -07:00
|
|
|
|
|
|
|
memset(&zr, 0, sizeof(zr));
|
|
|
|
isc_buffer_init(&zb, zone, sizeof(zone));
|
2019-06-18 15:01:43 +02:00
|
|
|
result = dns_compress_init(&cctx, -1, dt_mctx);
|
2019-10-31 06:50:58 -05:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2015-10-02 12:32:42 -07:00
|
|
|
dns_compress_setmethods(&cctx, DNS_COMPRESS_NONE);
|
|
|
|
result = dns_name_towire(zname, &cctx, &zb);
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2015-10-02 12:32:42 -07:00
|
|
|
dns_compress_invalidate(&cctx);
|
|
|
|
isc_buffer_usedregion(&zb, &zr);
|
|
|
|
|
|
|
|
in.s_addr = inet_addr("10.53.0.1");
|
2017-02-03 17:05:58 -08:00
|
|
|
isc_sockaddr_fromin(&qaddr, &in, 2112);
|
|
|
|
in.s_addr = inet_addr("10.53.0.2");
|
|
|
|
isc_sockaddr_fromin(&raddr, &in, 2112);
|
2015-10-02 12:32:42 -07:00
|
|
|
|
|
|
|
isc_stdtime_get(&now);
|
|
|
|
isc_time_set(&p, now - 3600, 0); /* past */
|
|
|
|
isc_time_set(&f, now + 3600, 0); /* future */
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_test_getdata("testdata/dnstap/query.auth", qambuffer,
|
|
|
|
sizeof(qambuffer), &qasize);
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2015-10-02 12:32:42 -07:00
|
|
|
isc_buffer_init(&qamsg, qambuffer, qasize);
|
|
|
|
isc_buffer_add(&qamsg, qasize);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_test_getdata("testdata/dnstap/response.auth", rambuffer,
|
|
|
|
sizeof(rambuffer), &rasize);
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2015-10-02 12:32:42 -07:00
|
|
|
isc_buffer_init(&ramsg, rambuffer, rasize);
|
|
|
|
isc_buffer_add(&ramsg, rasize);
|
|
|
|
|
|
|
|
result = dns_test_getdata("testdata/dnstap/query.recursive", qrmbuffer,
|
|
|
|
sizeof(qrmbuffer), &qrsize);
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2015-10-02 12:32:42 -07:00
|
|
|
isc_buffer_init(&qrmsg, qrmbuffer, qrsize);
|
|
|
|
isc_buffer_add(&qrmsg, qrsize);
|
|
|
|
|
|
|
|
result = dns_test_getdata("testdata/dnstap/response.recursive",
|
|
|
|
rrmbuffer, sizeof(rrmbuffer), &rrsize);
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2015-10-02 12:32:42 -07:00
|
|
|
isc_buffer_init(&rrmsg, rrmbuffer, rrsize);
|
|
|
|
isc_buffer_add(&rrmsg, rrsize);
|
|
|
|
|
|
|
|
for (dt = DNS_DTTYPE_SQ; dt <= DNS_DTTYPE_TR; dt <<= 1) {
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_buffer_t *m;
|
2017-02-03 17:05:58 -08:00
|
|
|
isc_sockaddr_t *q = &qaddr, *r = &raddr;
|
2015-10-02 12:32:42 -07:00
|
|
|
|
|
|
|
switch (dt) {
|
|
|
|
case DNS_DTTYPE_AQ:
|
|
|
|
m = &qamsg;
|
|
|
|
break;
|
|
|
|
case DNS_DTTYPE_AR:
|
|
|
|
m = &ramsg;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
m = &qrmsg;
|
2018-10-24 21:41:30 -07:00
|
|
|
if ((dt & DNS_DTTYPE_RESPONSE) != 0) {
|
2015-10-02 12:32:42 -07:00
|
|
|
m = &ramsg;
|
2018-10-24 21:41:30 -07:00
|
|
|
}
|
2015-10-02 12:32:42 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
dns_dt_send(view, dt, q, r, false, &zr, &p, &f, m);
|
|
|
|
dns_dt_send(view, dt, q, r, false, &zr, NULL, &f, m);
|
|
|
|
dns_dt_send(view, dt, q, r, false, &zr, &p, NULL, m);
|
|
|
|
dns_dt_send(view, dt, q, r, false, &zr, NULL, NULL, m);
|
|
|
|
dns_dt_send(view, dt, q, r, true, &zr, &p, &f, m);
|
|
|
|
dns_dt_send(view, dt, q, r, true, &zr, NULL, &f, m);
|
|
|
|
dns_dt_send(view, dt, q, r, true, &zr, &p, NULL, m);
|
|
|
|
dns_dt_send(view, dt, q, r, true, &zr, NULL, NULL, m);
|
2015-10-02 12:32:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
dns_dt_detach(&view->dtenv);
|
|
|
|
dns_dt_detach(&dtenv);
|
|
|
|
dns_view_detach(&view);
|
|
|
|
|
2019-06-18 15:01:43 +02:00
|
|
|
result = dns_dt_open(TAPFILE, dns_dtmode_file, dt_mctx, &handle);
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2015-10-02 12:32:42 -07:00
|
|
|
|
2016-08-25 10:03:22 +10:00
|
|
|
while (dns_dt_getframe(handle, &data, &dsize) == ISC_R_SUCCESS) {
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_dtdata_t *dtdata = NULL;
|
|
|
|
isc_region_t r;
|
2015-10-02 12:32:42 -07:00
|
|
|
static dns_dtmsgtype_t expected = DNS_DTTYPE_SQ;
|
2020-02-13 14:44:37 -08:00
|
|
|
static int n = 0;
|
2015-10-02 12:32:42 -07:00
|
|
|
|
|
|
|
r.base = data;
|
|
|
|
r.length = dsize;
|
|
|
|
|
2019-06-18 15:01:43 +02:00
|
|
|
result = dns_dt_parse(dt_mctx, &r, &dtdata);
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2015-10-02 12:32:42 -07:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
n++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_int_equal(dtdata->type, expected);
|
|
|
|
if (++n % 8 == 0) {
|
2015-10-02 12:32:42 -07:00
|
|
|
expected <<= 1;
|
2018-10-24 21:41:30 -07:00
|
|
|
}
|
2015-10-02 12:32:42 -07:00
|
|
|
|
|
|
|
dns_dtdata_free(&dtdata);
|
|
|
|
}
|
|
|
|
|
2018-10-24 21:41:30 -07:00
|
|
|
if (fopt != NULL) {
|
2016-08-25 10:03:22 +10:00
|
|
|
fstrm_iothr_options_destroy(&fopt);
|
2018-10-24 21:41:30 -07:00
|
|
|
}
|
|
|
|
if (handle != NULL) {
|
2016-08-25 10:03:22 +10:00
|
|
|
dns_dt_close(&handle);
|
2018-10-24 21:41:30 -07:00
|
|
|
}
|
2015-10-02 12:32:42 -07:00
|
|
|
cleanup();
|
|
|
|
}
|
|
|
|
|
2018-10-24 21:41:30 -07:00
|
|
|
/* dnstap message to text */
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
totext_test(void **state) {
|
|
|
|
isc_result_t result;
|
2016-08-25 10:03:22 +10:00
|
|
|
dns_dthandle_t *handle = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
uint8_t *data;
|
|
|
|
size_t dsize;
|
|
|
|
FILE *fp = NULL;
|
2015-10-02 12:32:42 -07:00
|
|
|
|
2018-10-24 21:41:30 -07:00
|
|
|
UNUSED(state);
|
2015-10-02 12:32:42 -07:00
|
|
|
|
2019-06-18 15:01:43 +02:00
|
|
|
result = dns_dt_open(TAPSAVED, dns_dtmode_file, dt_mctx, &handle);
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2015-10-02 12:32:42 -07:00
|
|
|
|
|
|
|
result = isc_stdio_open(TAPTEXT, "r", &fp);
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2015-10-02 12:32:42 -07:00
|
|
|
|
2016-08-25 10:03:22 +10:00
|
|
|
while (dns_dt_getframe(handle, &data, &dsize) == ISC_R_SUCCESS) {
|
2015-10-02 12:32:42 -07:00
|
|
|
dns_dtdata_t *dtdata = NULL;
|
|
|
|
isc_buffer_t *b = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_region_t r;
|
|
|
|
char s[BUFSIZ], *p;
|
2015-10-02 12:32:42 -07:00
|
|
|
|
|
|
|
r.base = data;
|
|
|
|
r.length = dsize;
|
|
|
|
|
|
|
|
/* read the corresponding line of text */
|
|
|
|
p = fgets(s, sizeof(s), fp);
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_ptr_equal(p, s);
|
|
|
|
if (p == NULL) {
|
2015-10-02 12:32:42 -07:00
|
|
|
break;
|
2018-10-24 21:41:30 -07:00
|
|
|
}
|
2015-10-02 12:32:42 -07:00
|
|
|
|
|
|
|
p = strchr(p, '\n');
|
2018-10-24 21:41:30 -07:00
|
|
|
if (p != NULL) {
|
2015-10-02 12:32:42 -07:00
|
|
|
*p = '\0';
|
2018-10-24 21:41:30 -07:00
|
|
|
}
|
2015-10-02 12:32:42 -07:00
|
|
|
|
|
|
|
/* parse dnstap frame */
|
2019-06-18 15:01:43 +02:00
|
|
|
result = dns_dt_parse(dt_mctx, &r, &dtdata);
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2015-10-02 12:32:42 -07:00
|
|
|
continue;
|
2018-10-24 21:41:30 -07:00
|
|
|
}
|
2015-10-02 12:32:42 -07:00
|
|
|
|
2019-06-18 15:01:43 +02:00
|
|
|
isc_buffer_allocate(dt_mctx, &b, 2048);
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_non_null(b);
|
|
|
|
if (b == NULL) {
|
2015-10-02 12:32:42 -07:00
|
|
|
break;
|
2018-10-24 21:41:30 -07:00
|
|
|
}
|
2015-10-02 12:32:42 -07:00
|
|
|
|
|
|
|
/* convert to text and compare */
|
|
|
|
result = dns_dt_datatotext(dtdata, &b);
|
2018-10-24 21:41:30 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2015-10-02 12:32:42 -07:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
assert_string_equal((char *)isc_buffer_base(b), s);
|
2015-10-02 12:32:42 -07:00
|
|
|
|
|
|
|
dns_dtdata_free(&dtdata);
|
|
|
|
isc_buffer_free(&b);
|
|
|
|
}
|
|
|
|
|
2018-10-24 21:41:30 -07:00
|
|
|
if (handle != NULL) {
|
2016-08-25 10:03:22 +10:00
|
|
|
dns_dt_close(&handle);
|
2018-10-24 21:41:30 -07:00
|
|
|
}
|
2015-10-02 12:32:42 -07:00
|
|
|
cleanup();
|
|
|
|
}
|
2018-10-24 21:41:30 -07:00
|
|
|
#endif /* HAVE_DNSTAP */
|
|
|
|
|
|
|
|
int
|
2020-02-13 14:44:37 -08:00
|
|
|
main(void) {
|
2018-10-24 21:41:30 -07:00
|
|
|
#if HAVE_DNSTAP
|
|
|
|
const struct CMUnitTest tests[] = {
|
|
|
|
cmocka_unit_test_setup_teardown(create_test, _setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(send_test, _setup, _teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(totext_test, _setup, _teardown),
|
|
|
|
};
|
|
|
|
|
2019-03-14 13:40:14 +01:00
|
|
|
/* make sure text conversion gets the right local time */
|
|
|
|
setenv("TZ", "PST8", 1);
|
|
|
|
|
2018-10-24 21:41:30 -07:00
|
|
|
return (cmocka_run_group_tests(tests, NULL, NULL));
|
2020-02-13 21:48:23 +01:00
|
|
|
#else /* if HAVE_DNSTAP */
|
2018-10-24 21:41:30 -07:00
|
|
|
print_message("1..0 # Skip dnstap not enabled\n");
|
|
|
|
#endif /* HAVE_DNSTAP */
|
2015-10-02 12:32:42 -07:00
|
|
|
}
|
|
|
|
|
2018-10-24 21:41:30 -07:00
|
|
|
#else /* HAVE_CMOCKA */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-10-02 12:32:42 -07:00
|
|
|
|
2018-10-24 21:41:30 -07:00
|
|
|
int
|
2020-02-13 14:44:37 -08:00
|
|
|
main(void) {
|
2018-10-24 21:41:30 -07:00
|
|
|
printf("1..0 # Skipped: cmocka not available\n");
|
|
|
|
return (0);
|
2015-10-02 12:32:42 -07:00
|
|
|
}
|
2018-10-24 21:41:30 -07:00
|
|
|
|
|
|
|
#endif /* HAVE_CMOCKA */
|