diff options
Diffstat (limited to 'tests/zfs-tests/cmd/btree_test.c')
-rw-r--r-- | tests/zfs-tests/cmd/btree_test.c | 70 |
1 files changed, 36 insertions, 34 deletions
diff --git a/tests/zfs-tests/cmd/btree_test.c b/tests/zfs-tests/cmd/btree_test.c index aaad4e47e464..fda9229915ce 100644 --- a/tests/zfs-tests/cmd/btree_test.c +++ b/tests/zfs-tests/cmd/btree_test.c @@ -15,6 +15,7 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <sys/avl.h> #include <sys/btree.h> #include <sys/time.h> @@ -22,11 +23,11 @@ #define BUFSIZE 256 -int seed = 0; -int stress_timeout = 180; -int contents_frequency = 100; -int tree_limit = 64 * 1024; -boolean_t stress_only = B_FALSE; +static int seed = 0; +static int stress_timeout = 180; +static int contents_frequency = 100; +static int tree_limit = 64 * 1024; +static boolean_t stress_only = B_FALSE; static void usage(int exit_value) @@ -164,7 +165,7 @@ find_without_index(zfs_btree_t *bt, char *why) zfs_btree_add(bt, &i); if ((p = (u_longlong_t *)zfs_btree_find(bt, &i, NULL)) == NULL || *p != i) { - snprintf(why, BUFSIZE, "Unexpectedly found %llu\n", + (void) snprintf(why, BUFSIZE, "Unexpectedly found %llu\n", p == NULL ? 0 : *p); return (1); } @@ -172,7 +173,7 @@ find_without_index(zfs_btree_t *bt, char *why) i++; if ((p = (u_longlong_t *)zfs_btree_find(bt, &i, NULL)) != NULL) { - snprintf(why, BUFSIZE, "Found bad value: %llu\n", *p); + (void) snprintf(why, BUFSIZE, "Found bad value: %llu\n", *p); return (1); } @@ -189,10 +190,10 @@ insert_find_remove(zfs_btree_t *bt, char *why) /* Insert 'i' into the tree, and attempt to find it again. */ zfs_btree_add(bt, &i); if ((p = (u_longlong_t *)zfs_btree_find(bt, &i, &bt_idx)) == NULL) { - snprintf(why, BUFSIZE, "Didn't find value in tree\n"); + (void) snprintf(why, BUFSIZE, "Didn't find value in tree\n"); return (1); } else if (*p != i) { - snprintf(why, BUFSIZE, "Found (%llu) in tree\n", *p); + (void) snprintf(why, BUFSIZE, "Found (%llu) in tree\n", *p); return (1); } ASSERT3S(zfs_btree_numnodes(bt), ==, 1); @@ -201,7 +202,8 @@ insert_find_remove(zfs_btree_t *bt, char *why) /* Remove 'i' from the tree, and verify it is not found. */ zfs_btree_remove(bt, &i); if ((p = (u_longlong_t *)zfs_btree_find(bt, &i, &bt_idx)) != NULL) { - snprintf(why, BUFSIZE, "Found removed value (%llu)\n", *p); + (void) snprintf(why, BUFSIZE, + "Found removed value (%llu)\n", *p); return (1); } ASSERT3S(zfs_btree_numnodes(bt), ==, 0); @@ -218,7 +220,6 @@ insert_find_remove(zfs_btree_t *bt, char *why) static int drain_tree(zfs_btree_t *bt, char *why) { - uint64_t *p; avl_tree_t avl; int i = 0; int_node_t *node; @@ -230,19 +231,22 @@ drain_tree(zfs_btree_t *bt, char *why) /* Fill both trees with the same data */ for (i = 0; i < 64 * 1024; i++) { - void *ret; - u_longlong_t randval = random(); - node = malloc(sizeof (int_node_t)); - if ((p = (uint64_t *)zfs_btree_find(bt, &randval, &bt_idx)) != - NULL) { + if (zfs_btree_find(bt, &randval, &bt_idx) != NULL) { continue; } zfs_btree_add_idx(bt, &randval, &bt_idx); + node = malloc(sizeof (int_node_t)); + if (node == NULL) { + perror("malloc"); + exit(EXIT_FAILURE); + } + node->data = randval; - if ((ret = avl_find(&avl, node, &avl_idx)) != NULL) { - snprintf(why, BUFSIZE, "Found in avl: %llu\n", randval); + if (avl_find(&avl, node, &avl_idx) != NULL) { + (void) snprintf(why, BUFSIZE, + "Found in avl: %llu\n", randval); return (1); } avl_insert(&avl, node, avl_idx); @@ -314,6 +318,10 @@ stress_tree(zfs_btree_t *bt, char *why) uint64_t randval = random() % tree_limit; node = malloc(sizeof (*node)); + if (node == NULL) { + perror("malloc"); + exit(EXIT_FAILURE); + } node->data = randval; max = randval > max ? randval : max; @@ -360,9 +368,7 @@ stress_tree(zfs_btree_t *bt, char *why) if (stress_only) { zfs_btree_index_t *idx = NULL; - uint64_t *rv; - - while ((rv = zfs_btree_destroy_nodes(bt, &idx)) != NULL) + while (zfs_btree_destroy_nodes(bt, &idx) != NULL) ; zfs_btree_verify(bt); } @@ -377,15 +383,15 @@ stress_tree(zfs_btree_t *bt, char *why) static int insert_duplicate(zfs_btree_t *bt) { - uint64_t *p, i = 23456; + uint64_t i = 23456; zfs_btree_index_t bt_idx = {0}; - if ((p = (uint64_t *)zfs_btree_find(bt, &i, &bt_idx)) != NULL) { + if (zfs_btree_find(bt, &i, &bt_idx) != NULL) { fprintf(stderr, "Found value in empty tree.\n"); return (0); } zfs_btree_add_idx(bt, &i, &bt_idx); - if ((p = (uint64_t *)zfs_btree_find(bt, &i, &bt_idx)) == NULL) { + if (zfs_btree_find(bt, &i, &bt_idx) == NULL) { fprintf(stderr, "Did not find expected value.\n"); return (0); } @@ -403,10 +409,10 @@ insert_duplicate(zfs_btree_t *bt) static int remove_missing(zfs_btree_t *bt) { - uint64_t *p, i = 23456; + uint64_t i = 23456; zfs_btree_index_t bt_idx = {0}; - if ((p = (uint64_t *)zfs_btree_find(bt, &i, &bt_idx)) != NULL) { + if (zfs_btree_find(bt, &i, &bt_idx) != NULL) { fprintf(stderr, "Found value in empty tree.\n"); return (0); } @@ -422,7 +428,8 @@ do_negative_test(zfs_btree_t *bt, char *test_name) { int rval = 0; struct rlimit rlim = {0}; - setrlimit(RLIMIT_CORE, &rlim); + + (void) setrlimit(RLIMIT_CORE, &rlim); if (strcmp(test_name, "insert_duplicate") == 0) { rval = insert_duplicate(bt); @@ -486,10 +493,6 @@ main(int argc, char *argv[]) break; } } - argc -= optind; - argv += optind; - optind = 1; - if (seed == 0) { (void) gettimeofday(&tp, NULL); @@ -498,7 +501,7 @@ main(int argc, char *argv[]) srandom(seed); zfs_btree_init(); - zfs_btree_create(&bt, zfs_btree_compare, sizeof (uint64_t)); + zfs_btree_create(&bt, zfs_btree_compare, NULL, sizeof (uint64_t)); /* * This runs the named negative test. None of them should @@ -523,7 +526,6 @@ main(int argc, char *argv[]) btree_test_t *test = &test_table[0]; while (test->name) { int retval; - uint64_t *rv; char why[BUFSIZE] = {0}; zfs_btree_index_t *idx = NULL; @@ -541,7 +543,7 @@ main(int argc, char *argv[]) } /* Remove all the elements and re-verify the tree */ - while ((rv = zfs_btree_destroy_nodes(&bt, &idx)) != NULL) + while (zfs_btree_destroy_nodes(&bt, &idx) != NULL) ; zfs_btree_verify(&bt); |