rbt_serialize_test.c revision c110d61b173a68420d19858abb80285be0dc1120
/*
* Copyright (C) 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
*
* 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.
*/
/* $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());
}