Merge branch '46-just-use-clang-format-to-reformat-sources' into 'master'

Reformat source code with clang-format

Closes #46

See merge request isc-projects/bind9!2156

(cherry picked from commit 7099e79a9b)

4c3b063e Import Linux kernel .clang-format with small modifications
f50b1e06 Use clang-format to reformat the source files
11341c76 Update the definition files for Windows
df6c1f76 Remove tkey_test (which is no-op anyway)
This commit is contained in:
Ondřej Surý
2020-02-12 14:33:32 +00:00
parent dbe15330fe
commit c931d8e417
974 changed files with 75952 additions and 74434 deletions

View File

@@ -11,15 +11,14 @@
#if HAVE_CMOCKA
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <ctype.h>
#include <fcntl.h>
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
@@ -33,33 +32,29 @@
#include <isc/file.h>
#include <isc/hash.h>
#include <isc/mem.h>
#include <isc/mem.h>
#include <isc/os.h>
#include <isc/print.h>
#include <isc/random.h>
#include <isc/socket.h>
#include <isc/stdio.h>
#include <isc/string.h>
#include <isc/string.h>
#include <isc/task.h>
#include <isc/thread.h>
#include <isc/time.h>
#include <isc/timer.h>
#include <isc/util.h>
#include <isc/util.h>
#include <dns/compress.h>
#include <dns/fixedname.h>
#include <dns/log.h>
#include <dns/name.h>
#include <dns/name.h>
#include <dns/rbt.h>
#include <dns/result.h>
#include <dst/dst.h>
#include "dnstest.h"
#include <dst/dst.h>
typedef struct {
dns_rbt_t *rbt;
dns_rbt_t *rbt_distances;
@@ -87,20 +82,19 @@ typedef struct {
/* The full absolute names of the nodes in the tree (the tree also
* contains "." which is not included in this list).
*/
static const char * const domain_names[] = {
"c", "b", "a", "x.d.e.f", "z.d.e.f", "g.h", "i.g.h", "o.w.y.d.e.f",
"j.z.d.e.f", "p.w.y.d.e.f", "q.w.y.d.e.f", "k.g.h"
static const char *const domain_names[] = {
"c", "b", "a", "x.d.e.f",
"z.d.e.f", "g.h", "i.g.h", "o.w.y.d.e.f",
"j.z.d.e.f", "p.w.y.d.e.f", "q.w.y.d.e.f", "k.g.h"
};
static const size_t domain_names_count = (sizeof(domain_names) /
sizeof(domain_names[0]));
static const size_t domain_names_count =
(sizeof(domain_names) / sizeof(domain_names[0]));
/* These are set as the node data for the tree used in distances check
* (for the names in domain_names[] above).
*/
static const int node_distances[] = {
3, 1, 2, 2, 2, 3, 1, 2, 1, 1, 2, 2
};
static const int node_distances[] = { 3, 1, 2, 2, 2, 3, 1, 2, 1, 1, 2, 2 };
/*
* The domain order should be:
@@ -123,16 +117,18 @@ static const int node_distances[] = {
* o q
*/
static const char * const ordered_names[] = {
"a", "b", "c", "d.e.f", "x.d.e.f", "w.y.d.e.f", "o.w.y.d.e.f",
"p.w.y.d.e.f", "q.w.y.d.e.f", "z.d.e.f", "j.z.d.e.f",
"g.h", "i.g.h", "k.g.h"};
static const char *const ordered_names[] = {
"a", "b", "c", "d.e.f", "x.d.e.f",
"w.y.d.e.f", "o.w.y.d.e.f", "p.w.y.d.e.f", "q.w.y.d.e.f", "z.d.e.f",
"j.z.d.e.f", "g.h", "i.g.h", "k.g.h"
};
static const size_t ordered_names_count = (sizeof(ordered_names) /
sizeof(*ordered_names));
static const size_t ordered_names_count =
(sizeof(ordered_names) / sizeof(*ordered_names));
static int
_setup(void **state) {
_setup(void **state)
{
isc_result_t result;
UNUSED(state);
@@ -144,7 +140,8 @@ _setup(void **state) {
}
static int
_teardown(void **state) {
_teardown(void **state)
{
UNUSED(state);
dns_test_end();
@@ -152,17 +149,19 @@ _teardown(void **state) {
return (0);
}
static void
delete_data(void *data, void *arg) {
delete_data(void *data, void *arg)
{
UNUSED(arg);
isc_mem_put(dt_mctx, data, sizeof(size_t));
}
static test_context_t *
test_context_setup(void) {
test_context_setup(void)
{
test_context_t *ctx;
isc_result_t result;
size_t i;
isc_result_t result;
size_t i;
ctx = isc_mem_get(dt_mctx, sizeof(*ctx));
assert_non_null(ctx);
@@ -172,13 +171,14 @@ test_context_setup(void) {
assert_int_equal(result, ISC_R_SUCCESS);
ctx->rbt_distances = NULL;
result = dns_rbt_create(dt_mctx, delete_data, NULL, &ctx->rbt_distances);
result =
dns_rbt_create(dt_mctx, delete_data, NULL, &ctx->rbt_distances);
assert_int_equal(result, ISC_R_SUCCESS);
for (i = 0; i < domain_names_count; i++) {
size_t *n;
size_t * n;
dns_fixedname_t fname;
dns_name_t *name;
dns_name_t * name;
dns_test_namefromstring(domain_names[i], &fname);
@@ -201,7 +201,8 @@ test_context_setup(void) {
}
static void
test_context_teardown(test_context_t *ctx) {
test_context_teardown(test_context_t *ctx)
{
dns_rbt_destroy(&ctx->rbt);
dns_rbt_destroy(&ctx->rbt_distances);
@@ -212,25 +213,25 @@ test_context_teardown(test_context_t *ctx) {
* Walk the tree and ensure that all the test nodes are present.
*/
static void
check_test_data(dns_rbt_t *rbt) {
check_test_data(dns_rbt_t *rbt)
{
dns_fixedname_t fixed;
isc_result_t result;
dns_name_t *foundname;
size_t i;
isc_result_t result;
dns_name_t * foundname;
size_t i;
foundname = dns_fixedname_initname(&fixed);
for (i = 0; i < domain_names_count; i++) {
dns_fixedname_t fname;
dns_name_t *name;
size_t *n;
dns_name_t * name;
size_t * n;
dns_test_namefromstring(domain_names[i], &fname);
name = dns_fixedname_name(&fname);
n = NULL;
result = dns_rbt_findname(rbt, name, 0, foundname,
(void *) &n);
result = dns_rbt_findname(rbt, name, 0, foundname, (void *)&n);
assert_int_equal(result, ISC_R_SUCCESS);
assert_int_equal(*n, i + 1);
}
@@ -238,9 +239,10 @@ check_test_data(dns_rbt_t *rbt) {
/* Test the creation of an rbt */
static void
rbt_create(void **state) {
rbt_create(void **state)
{
test_context_t *ctx;
bool tree_ok;
bool tree_ok;
UNUSED(state);
@@ -258,7 +260,8 @@ rbt_create(void **state) {
/* Test dns_rbt_nodecount() on a tree */
static void
rbt_nodecount(void **state) {
rbt_nodecount(void **state)
{
test_context_t *ctx;
UNUSED(state);
@@ -274,13 +277,14 @@ rbt_nodecount(void **state) {
/* Test dns_rbtnode_get_distance() on a tree */
static void
rbtnode_get_distance(void **state) {
isc_result_t result;
test_context_t *ctx;
const char *name_str = "a";
dns_fixedname_t fname;
dns_name_t *name;
dns_rbtnode_t *node = NULL;
rbtnode_get_distance(void **state)
{
isc_result_t result;
test_context_t * ctx;
const char * name_str = "a";
dns_fixedname_t fname;
dns_name_t * name;
dns_rbtnode_t * node = NULL;
dns_rbtnodechain_t chain;
UNUSED(state);
@@ -294,18 +298,18 @@ rbtnode_get_distance(void **state) {
dns_rbtnodechain_init(&chain);
result = dns_rbt_findnode(ctx->rbt_distances, name, NULL,
&node, &chain, 0, NULL, NULL);
result = dns_rbt_findnode(ctx->rbt_distances, name, NULL, &node, &chain,
0, NULL, NULL);
assert_int_equal(result, ISC_R_SUCCESS);
while (node != NULL) {
const size_t *distance = (const size_t *) node->data;
const size_t *distance = (const size_t *)node->data;
if (distance != NULL)
assert_int_equal(*distance,
dns__rbtnode_getdistance(node));
result = dns_rbtnodechain_next(&chain, NULL, NULL);
if (result == ISC_R_NOMORE)
break;
break;
dns_rbtnodechain_current(&chain, NULL, NULL, &node);
}
@@ -325,12 +329,13 @@ rbtnode_get_distance(void **state) {
* 2log(n). This check verifies that the tree is balanced.
*/
static void
rbt_check_distance_random(void **state) {
dns_rbt_t *mytree = NULL;
rbt_check_distance_random(void **state)
{
dns_rbt_t * mytree = NULL;
const unsigned int log_num_nodes = 16;
isc_result_t result;
bool tree_ok;
int i;
isc_result_t result;
bool tree_ok;
int i;
UNUSED(state);
@@ -351,16 +356,16 @@ rbt_check_distance_random(void **state) {
*/
for (i = 0; i < (1 << log_num_nodes); i++) {
size_t *n;
char namebuf[34];
char namebuf[34];
n = isc_mem_get(dt_mctx, sizeof(size_t));
assert_non_null(n);
*n = i + 1;
while (1) {
int j;
int j;
dns_fixedname_t fname;
dns_name_t *name;
dns_name_t * name;
for (j = 0; j < 32; j++) {
uint32_t v = isc_random_uniform(26);
@@ -379,8 +384,7 @@ rbt_check_distance_random(void **state) {
}
/* 1 (root . node) + (1 << log_num_nodes) */
assert_int_equal(1U + (1U << log_num_nodes),
dns_rbt_nodecount(mytree));
assert_int_equal(1U + (1U << log_num_nodes), dns_rbt_nodecount(mytree));
/* The distance from each node to its sub-tree root must be less
* than 2 * log(n).
@@ -403,12 +407,13 @@ rbt_check_distance_random(void **state) {
* 2log(n). This check verifies that the tree is balanced.
*/
static void
rbt_check_distance_ordered(void **state) {
dns_rbt_t *mytree = NULL;
rbt_check_distance_ordered(void **state)
{
dns_rbt_t * mytree = NULL;
const unsigned int log_num_nodes = 16;
isc_result_t result;
bool tree_ok;
int i;
isc_result_t result;
bool tree_ok;
int i;
UNUSED(state);
@@ -428,10 +433,10 @@ rbt_check_distance_ordered(void **state) {
* name00000003.
*/
for (i = 0; i < (1 << log_num_nodes); i++) {
size_t *n;
char namebuf[14];
size_t * n;
char namebuf[14];
dns_fixedname_t fname;
dns_name_t *name;
dns_name_t * name;
n = isc_mem_get(dt_mctx, sizeof(size_t));
assert_non_null(n);
@@ -446,8 +451,7 @@ rbt_check_distance_ordered(void **state) {
}
/* 1 (root . node) + (1 << log_num_nodes) */
assert_int_equal(1U + (1U << log_num_nodes),
dns_rbt_nodecount(mytree));
assert_int_equal(1U + (1U << log_num_nodes), dns_rbt_nodecount(mytree));
/* The distance from each node to its sub-tree root must be less
* than 2 * log(n).
@@ -462,9 +466,10 @@ rbt_check_distance_ordered(void **state) {
}
static isc_result_t
insert_helper(dns_rbt_t *rbt, const char *namestr, dns_rbtnode_t **node) {
insert_helper(dns_rbt_t *rbt, const char *namestr, dns_rbtnode_t **node)
{
dns_fixedname_t fname;
dns_name_t *name;
dns_name_t * name;
dns_test_namefromstring(namestr, &fname);
name = dns_fixedname_name(&fname);
@@ -473,11 +478,12 @@ insert_helper(dns_rbt_t *rbt, const char *namestr, dns_rbtnode_t **node) {
}
static bool
compare_labelsequences(dns_rbtnode_t *node, const char *labelstr) {
dns_name_t name;
compare_labelsequences(dns_rbtnode_t *node, const char *labelstr)
{
dns_name_t name;
isc_result_t result;
char *nodestr = NULL;
bool is_equal;
char * nodestr = NULL;
bool is_equal;
dns_name_init(&name, NULL);
dns_rbt_namefromnode(node, &name);
@@ -494,10 +500,11 @@ compare_labelsequences(dns_rbtnode_t *node, const char *labelstr) {
/* Test insertion into a tree */
static void
rbt_insert(void **state) {
isc_result_t result;
rbt_insert(void **state)
{
isc_result_t result;
test_context_t *ctx;
dns_rbtnode_t *node;
dns_rbtnode_t * node;
UNUSED(state);
@@ -657,8 +664,10 @@ rbt_insert(void **state) {
* have data.
*/
static void
rbt_remove(void **state) {
isc_result_t result; size_t j;
rbt_remove(void **state)
{
isc_result_t result;
size_t j;
UNUSED(state);
@@ -668,13 +677,13 @@ rbt_remove(void **state) {
* Delete single nodes and check if the rest of the nodes exist.
*/
for (j = 0; j < ordered_names_count; j++) {
dns_rbt_t *mytree = NULL;
dns_rbtnode_t *node;
size_t i;
size_t *n;
bool tree_ok;
dns_rbt_t * mytree = NULL;
dns_rbtnode_t * node;
size_t i;
size_t * n;
bool tree_ok;
dns_rbtnodechain_t chain;
size_t start_node;
size_t start_node;
/* Create a tree. */
result = dns_rbt_create(dt_mctx, delete_data, NULL, &mytree);
@@ -690,15 +699,14 @@ rbt_remove(void **state) {
/* Check that all names exist in order. */
for (i = 0; i < ordered_names_count; i++) {
dns_fixedname_t fname;
dns_name_t *name;
dns_name_t * name;
dns_test_namefromstring(ordered_names[i], &fname);
name = dns_fixedname_name(&fname);
node = NULL;
result = dns_rbt_findnode(mytree, name, NULL,
&node, NULL,
DNS_RBTFIND_EMPTYDATA,
result = dns_rbt_findnode(mytree, name, NULL, &node,
NULL, DNS_RBTFIND_EMPTYDATA,
NULL, NULL);
assert_int_equal(result, ISC_R_SUCCESS);
@@ -716,7 +724,7 @@ rbt_remove(void **state) {
/* Now, delete the j'th node from the tree. */
{
dns_fixedname_t fname;
dns_name_t *name;
dns_name_t * name;
dns_test_namefromstring(ordered_names[j], &fname);
@@ -739,38 +747,32 @@ rbt_remove(void **state) {
* above. We start from node 1.
*/
dns_fixedname_t fname;
dns_name_t *name;
dns_name_t * name;
dns_test_namefromstring(ordered_names[0], &fname);
name = dns_fixedname_name(&fname);
node = NULL;
result = dns_rbt_findnode(mytree, name, NULL,
&node, NULL,
0,
NULL, NULL);
result = dns_rbt_findnode(mytree, name, NULL, &node,
NULL, 0, NULL, NULL);
assert_int_equal(result, ISC_R_NOTFOUND);
dns_test_namefromstring(ordered_names[1], &fname);
name = dns_fixedname_name(&fname);
node = NULL;
result = dns_rbt_findnode(mytree, name, NULL,
&node, &chain,
0,
NULL, NULL);
result = dns_rbt_findnode(mytree, name, NULL, &node,
&chain, 0, NULL, NULL);
assert_int_equal(result, ISC_R_SUCCESS);
start_node = 1;
} else {
/* Start from node 0. */
dns_fixedname_t fname;
dns_name_t *name;
dns_name_t * name;
dns_test_namefromstring(ordered_names[0], &fname);
name = dns_fixedname_name(&fname);
node = NULL;
result = dns_rbt_findnode(mytree, name, NULL,
&node, &chain,
0,
NULL, NULL);
result = dns_rbt_findnode(mytree, name, NULL, &node,
&chain, 0, NULL, NULL);
assert_int_equal(result, ISC_R_SUCCESS);
start_node = 0;
}
@@ -781,7 +783,7 @@ rbt_remove(void **state) {
*/
for (i = start_node; i < ordered_names_count; i++) {
dns_fixedname_t fname_j, fname_i;
dns_name_t *name_j, *name_i;
dns_name_t * name_j, *name_i;
dns_test_namefromstring(ordered_names[j], &fname_j);
name_j = dns_fixedname_name(&fname_j);
@@ -805,16 +807,14 @@ rbt_remove(void **state) {
* super-domain. Just skip it.
*/
if (node->data == NULL) {
result = dns_rbtnodechain_next(&chain,
NULL,
NULL);
result = dns_rbtnodechain_next(
&chain, NULL, NULL);
if (result == ISC_R_NOMORE) {
node = NULL;
} else {
dns_rbtnodechain_current(&chain,
NULL,
NULL,
&node);
dns_rbtnodechain_current(
&chain, NULL, NULL,
&node);
}
}
continue;
@@ -822,7 +822,7 @@ rbt_remove(void **state) {
assert_non_null(node);
n = (size_t *) node->data;
n = (size_t *)node->data;
if (n != NULL) {
/* printf("n=%zu, i=%zu\n", *n, i); */
assert_int_equal(*n, i);
@@ -845,15 +845,15 @@ rbt_remove(void **state) {
}
static void
insert_nodes(dns_rbt_t *mytree, char **names,
size_t *names_count, uint32_t num_names)
insert_nodes(dns_rbt_t *mytree, char **names, size_t *names_count,
uint32_t num_names)
{
uint32_t i;
uint32_t i;
dns_rbtnode_t *node;
for (i = 0; i < num_names; i++) {
size_t *n;
char namebuf[34];
char namebuf[34];
n = isc_mem_get(dt_mctx, sizeof(size_t));
assert_non_null(n);
@@ -861,10 +861,10 @@ insert_nodes(dns_rbt_t *mytree, char **names,
*n = i; /* Unused value */
while (1) {
int j;
int j;
dns_fixedname_t fname;
dns_name_t *name;
isc_result_t result;
dns_name_t * name;
isc_result_t result;
for (j = 0; j < 32; j++) {
uint32_t v = isc_random_uniform(26);
@@ -880,8 +880,8 @@ insert_nodes(dns_rbt_t *mytree, char **names,
result = dns_rbt_addnode(mytree, name, &node);
if (result == ISC_R_SUCCESS) {
node->data = n;
names[*names_count] = isc_mem_strdup(dt_mctx,
namebuf);
names[*names_count] =
isc_mem_strdup(dt_mctx, namebuf);
assert_non_null(names[*names_count]);
*names_count += 1;
break;
@@ -891,18 +891,18 @@ insert_nodes(dns_rbt_t *mytree, char **names,
}
static void
remove_nodes(dns_rbt_t *mytree, char **names,
size_t *names_count, uint32_t num_names)
remove_nodes(dns_rbt_t *mytree, char **names, size_t *names_count,
uint32_t num_names)
{
uint32_t i;
UNUSED(mytree);
for (i = 0; i < num_names; i++) {
uint32_t node;
uint32_t node;
dns_fixedname_t fname;
dns_name_t *name;
isc_result_t result;
dns_name_t * name;
isc_result_t result;
node = isc_random_uniform(*names_count);
@@ -922,7 +922,8 @@ remove_nodes(dns_rbt_t *mytree, char **names,
}
static void
check_tree(dns_rbt_t *mytree, char **names, size_t names_count) {
check_tree(dns_rbt_t *mytree, char **names, size_t names_count)
{
bool tree_ok;
UNUSED(names);
@@ -958,13 +959,14 @@ check_tree(dns_rbt_t *mytree, char **names, size_t names_count) {
* over 1024.
*/
static void
rbt_insert_and_remove(void **state) {
rbt_insert_and_remove(void **state)
{
isc_result_t result;
dns_rbt_t *mytree = NULL;
size_t *n;
char *names[1024];
size_t names_count;
int i;
dns_rbt_t * mytree = NULL;
size_t * n;
char * names[1024];
size_t names_count;
int i;
UNUSED(state);
@@ -1025,12 +1027,13 @@ rbt_insert_and_remove(void **state) {
/* Test findname return values */
static void
rbt_findname(void **state) {
isc_result_t result;
rbt_findname(void **state)
{
isc_result_t result;
test_context_t *ctx = NULL;
dns_fixedname_t fname, found;
dns_name_t *name = NULL, *foundname = NULL;
size_t *n = NULL;
dns_name_t * name = NULL, *foundname = NULL;
size_t * n = NULL;
UNUSED(state);
@@ -1044,31 +1047,27 @@ rbt_findname(void **state) {
foundname = dns_fixedname_initname(&found);
result = dns_rbt_findname(ctx->rbt, name,
DNS_RBTFIND_EMPTYDATA,
foundname, (void *) &n);
result = dns_rbt_findname(ctx->rbt, name, DNS_RBTFIND_EMPTYDATA,
foundname, (void *)&n);
assert_true(dns_name_equal(foundname, name));
assert_int_equal(result, ISC_R_SUCCESS);
/* Now without EMPTYDATA */
result = dns_rbt_findname(ctx->rbt, name, 0,
foundname, (void *) &n);
result = dns_rbt_findname(ctx->rbt, name, 0, foundname, (void *)&n);
assert_int_equal(result, ISC_R_NOTFOUND);
/* Now one that partially matches */
dns_test_namefromstring("d.e.f.g.h.i.j", &fname);
name = dns_fixedname_name(&fname);
result = dns_rbt_findname(ctx->rbt, name,
DNS_RBTFIND_EMPTYDATA,
foundname, (void *) &n);
result = dns_rbt_findname(ctx->rbt, name, DNS_RBTFIND_EMPTYDATA,
foundname, (void *)&n);
assert_int_equal(result, DNS_R_PARTIALMATCH);
/* Now one that doesn't match */
dns_test_namefromstring("1.2", &fname);
name = dns_fixedname_name(&fname);
result = dns_rbt_findname(ctx->rbt, name,
DNS_RBTFIND_EMPTYDATA,
foundname, (void *) &n);
result = dns_rbt_findname(ctx->rbt, name, DNS_RBTFIND_EMPTYDATA,
foundname, (void *)&n);
assert_int_equal(result, DNS_R_PARTIALMATCH);
assert_true(dns_name_equal(foundname, dns_rootname));
@@ -1077,12 +1076,13 @@ rbt_findname(void **state) {
/* Test addname return values */
static void
rbt_addname(void **state) {
isc_result_t result;
rbt_addname(void **state)
{
isc_result_t result;
test_context_t *ctx = NULL;
dns_fixedname_t fname;
dns_name_t *name = NULL;
size_t *n;
dns_name_t * name = NULL;
size_t * n;
UNUSED(state);
@@ -1114,11 +1114,12 @@ rbt_addname(void **state) {
/* Test deletename return values */
static void
rbt_deletename(void **state) {
isc_result_t result;
rbt_deletename(void **state)
{
isc_result_t result;
test_context_t *ctx = NULL;
dns_fixedname_t fname;
dns_name_t *name = NULL;
dns_name_t * name = NULL;
UNUSED(state);
@@ -1143,12 +1144,13 @@ rbt_deletename(void **state) {
/* Test nodechain */
static void
rbt_nodechain(void **state) {
isc_result_t result;
test_context_t *ctx;
dns_fixedname_t fname, found, expect;
dns_name_t *name, *foundname, *expected;
dns_rbtnode_t *node = NULL;
rbt_nodechain(void **state)
{
isc_result_t result;
test_context_t * ctx;
dns_fixedname_t fname, found, expect;
dns_name_t * name, *foundname, *expected;
dns_rbtnode_t * node = NULL;
dns_rbtnodechain_t chain;
UNUSED(state);
@@ -1162,8 +1164,8 @@ rbt_nodechain(void **state) {
dns_test_namefromstring("a", &fname);
name = dns_fixedname_name(&fname);
result = dns_rbt_findnode(ctx->rbt, name, NULL,
&node, &chain, 0, NULL, NULL);
result = dns_rbt_findnode(ctx->rbt, name, NULL, &node, &chain, 0, NULL,
NULL);
assert_int_equal(result, ISC_R_SUCCESS);
foundname = dns_fixedname_initname(&found);
@@ -1210,18 +1212,19 @@ rbt_nodechain(void **state) {
*/
static dns_fixedname_t *fnames;
static dns_name_t **names;
static int *values;
static dns_name_t ** names;
static int * values;
static void *
find_thread(void *arg) {
dns_rbt_t *mytree;
isc_result_t result;
find_thread(void *arg)
{
dns_rbt_t * mytree;
isc_result_t result;
dns_rbtnode_t *node;
unsigned int j, i;
unsigned int start = 0;
unsigned int j, i;
unsigned int start = 0;
mytree = (dns_rbt_t *) arg;
mytree = (dns_rbt_t *)arg;
while (start == 0)
start = random() % 4000000;
@@ -1229,13 +1232,12 @@ find_thread(void *arg) {
for (j = 0; j < 8; j++) {
for (i = start; i != start - 1; i = (i + 1) % 4000000) {
node = NULL;
result = dns_rbt_findnode(mytree, names[i], NULL,
&node, NULL,
DNS_RBTFIND_EMPTYDATA,
result = dns_rbt_findnode(mytree, names[i], NULL, &node,
NULL, DNS_RBTFIND_EMPTYDATA,
NULL, NULL);
assert_int_equal(result, ISC_R_SUCCESS);
assert_non_null(node);
assert_int_equal(values[i], (intptr_t) node->data);
assert_int_equal(values[i], (intptr_t)node->data);
}
}
@@ -1244,18 +1246,19 @@ find_thread(void *arg) {
/* Benchmark RBT implementation */
static void
benchmark(void **state) {
isc_result_t result;
char namestr[sizeof("name18446744073709551616.example.org.")];
unsigned int r;
dns_rbt_t *mytree;
benchmark(void **state)
{
isc_result_t result;
char namestr[sizeof("name18446744073709551616.example.org.")];
unsigned int r;
dns_rbt_t * mytree;
dns_rbtnode_t *node;
unsigned int i;
unsigned int maxvalue = 1000000;
isc_time_t ts1, ts2;
double t;
unsigned int nthreads;
isc_thread_t threads[32];
unsigned int i;
unsigned int maxvalue = 1000000;
isc_time_t ts1, ts2;
double t;
unsigned int nthreads;
isc_thread_t threads[32];
UNUSED(state);
@@ -1263,16 +1266,16 @@ benchmark(void **state) {
debug_mem_record = false;
fnames = (dns_fixedname_t *) malloc(4000000 * sizeof(dns_fixedname_t));
names = (dns_name_t **) malloc(4000000 * sizeof(dns_name_t *));
values = (int *) malloc(4000000 * sizeof(int));
fnames = (dns_fixedname_t *)malloc(4000000 * sizeof(dns_fixedname_t));
names = (dns_name_t **)malloc(4000000 * sizeof(dns_name_t *));
values = (int *)malloc(4000000 * sizeof(int));
for (i = 0; i < 4000000; i++) {
r = ((unsigned long) random()) % maxvalue;
snprintf(namestr, sizeof(namestr), "name%u.example.org.", r);
dns_test_namefromstring(namestr, &fnames[i]);
names[i] = dns_fixedname_name(&fnames[i]);
values[i] = r;
r = ((unsigned long)random()) % maxvalue;
snprintf(namestr, sizeof(namestr), "name%u.example.org.", r);
dns_test_namefromstring(namestr, &fnames[i]);
names[i] = dns_fixedname_name(&fnames[i]);
values[i] = r;
}
/* Create a tree. */
@@ -1286,7 +1289,7 @@ benchmark(void **state) {
node = NULL;
result = insert_helper(mytree, namestr, &node);
assert_int_equal(result, ISC_R_SUCCESS);
node->data = (void *) (intptr_t) i;
node->data = (void *)(intptr_t)i;
}
result = isc_time_now(&ts1);
@@ -1320,28 +1323,29 @@ benchmark(void **state) {
#endif /* defined(DNS_BENCHMARK_TESTS) && !defined(__SANITIZE_THREAD__) */
int
main(void) {
main(void)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(rbt_create, _setup, _teardown),
cmocka_unit_test_setup_teardown(rbt_nodecount,
_setup, _teardown),
cmocka_unit_test_setup_teardown(rbtnode_get_distance,
_setup, _teardown),
cmocka_unit_test_setup_teardown(rbt_nodecount, _setup,
_teardown),
cmocka_unit_test_setup_teardown(rbtnode_get_distance, _setup,
_teardown),
cmocka_unit_test_setup_teardown(rbt_check_distance_random,
_setup, _teardown),
cmocka_unit_test_setup_teardown(rbt_check_distance_ordered,
_setup, _teardown),
cmocka_unit_test_setup_teardown(rbt_insert, _setup, _teardown),
cmocka_unit_test_setup_teardown(rbt_remove, _setup, _teardown),
cmocka_unit_test_setup_teardown(rbt_insert_and_remove,
_setup, _teardown),
cmocka_unit_test_setup_teardown(rbt_findname,
_setup, _teardown),
cmocka_unit_test_setup_teardown(rbt_insert_and_remove, _setup,
_teardown),
cmocka_unit_test_setup_teardown(rbt_findname, _setup,
_teardown),
cmocka_unit_test_setup_teardown(rbt_addname, _setup, _teardown),
cmocka_unit_test_setup_teardown(rbt_deletename,
_setup, _teardown),
cmocka_unit_test_setup_teardown(rbt_nodechain,
_setup, _teardown),
cmocka_unit_test_setup_teardown(rbt_deletename, _setup,
_teardown),
cmocka_unit_test_setup_teardown(rbt_nodechain, _setup,
_teardown),
#if defined(DNS_BENCHMARK_TESTS) && !defined(__SANITIZE_THREAD__)
cmocka_unit_test_setup_teardown(benchmark, _setup, _teardown),
#endif /* defined(DNS_BENCHMARK_TESTS) && !defined(__SANITIZE_THREAD__) */
@@ -1355,7 +1359,8 @@ main(void) {
#include <stdio.h>
int
main(void) {
main(void)
{
printf("1..0 # Skipped: cmocka not available\n");
return (0);
}