rbt_serialize_test.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 2014-2016 Internet Systems Consortium, Inc. ("ISC")
*
* 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
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id: rbt_test.c,v 1.1.14.8 2012/02/10 16:24:37 ckb Exp $ */
/* ! \file */
#include <config.h>
#include <atf-c.h>
#include <fcntl.h>
#include <unistd.h>
#ifdef HAVE_INTTYPES_H
#include <inttypes.h> /* uintptr_t */
#endif
#include <dns/fixedname.h>
#include <dns/compress.h>
#include "dnstest.h"
#ifndef MAP_FILE
#define MAP_FILE 0
#endif
typedef struct data_holder {
int len;
const char *data;
typedef struct rbt_testdata {
const char *name;
rbt_testdata_t testdata[] = {
DATA_ITEM("one.net."),
DATA_ITEM("three.org."),
DATA_ITEM("1.edu."),
DATA_ITEM("2.edu."),
DATA_ITEM("3.edu."),
DATA_ITEM("123.edu."),
DATA_ITEM("1236.com."),
DATA_ITEM("and_so_forth.com."),
DATA_ITEM("thisisalongname.com."),
DATA_ITEM("a.b."),
DATA_ITEM("test.net."),
DATA_ITEM("whoknows.org."),
DATA_ITEM("isc.org."),
DATA_ITEM("uiop.mil."),
DATA_ITEM("last.fm."),
};
static void
}
static isc_result_t
if (result != ISC_R_SUCCESS)
return (result);
? NULL
if (ret != 1)
return (ISC_R_FAILURE);
if (ret != 1)
return (ISC_R_FAILURE);
}
return (ISC_R_SUCCESS);
}
static isc_result_t
{
printf("fixing data: data NULL\n");
else
return (ISC_R_INVALIDFILE);
printf("data invalid\n");
return (ISC_R_INVALIDFILE);
}
? NULL
: (char *)data + sizeof(data_holder_t);
return (ISC_R_SUCCESS);
}
/*
* Load test data into the RBT.
*/
static void
char buffer[1024];
isc_buffer_t b;
if (result != ISC_R_SUCCESS) {
testdatap++;
continue;
}
}
testdatap++;
}
}
/*
* Walk the tree and ensure that all the test nodes are present.
*/
static void
char buffer[1024];
char *arg;
isc_buffer_t b;
if (result != ISC_R_SUCCESS) {
testdatap++;
continue;
}
(void *) &data);
testdatap++;
}
}
static void
{
}
}
int fd;
char *base;
/*
* Serialize the tree.
*/
printf("serialization begins.\n");
&offset);
/*
* Deserialize the tree
*/
printf("deserialization begins.\n");
/*
* Map in the whole file in one go
*/
NULL, &rbt_deserialized);
/* Test to make sure we have a valid tree */
if (rbt_deserialized == NULL)
unlink("zone.bin");
dns_test_end();
}
}
int fd;
char *base, *p, *q;
isc_uint32_t r;
int i;
/* Set up map file */
&offset);
/* Read back with random fuzzing */
for (i = 0; i < 256; i++) {
/* Randomly fuzz a portion of the memory */
isc_random_get(&r);
isc_random_get(&r);
q -= (r % (q - p));
while (p++ < q) {
isc_random_get(&r);
*p = r & 0xff;
}
NULL, &rbt_deserialized);
/* Test to make sure we have a valid tree */
result == ISC_R_INVALIDFILE);
if (result != ISC_R_SUCCESS)
if (rbt_deserialized != NULL)
}
unlink("zone.bin");
dns_test_end();
}
"Test the dns_rbt_serialize_align() function.");
}
ATF_CHECK(dns_rbt_serialize_align(0) == 0);
}
/*
* Main
*/
ATF_TP_ADD_TCS(tp) {
return (atf_no_error());
}