X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Ftests%2Fit_test.c;h=16815e1160bb9b6f632482ef6d29965ed759fa21;hb=5700f5bc3c5bb0e65ca84f34c7b642066d8489e2;hp=3ba9f315ceddc782e349d28214c3379d8f4e5137;hpb=e903932500fc08b143467ce5a1c2702df35d8f0f;p=fs%2Flustre-release.git diff --git a/lustre/tests/it_test.c b/lustre/tests/it_test.c index 3ba9f31..16815e1 100644 --- a/lustre/tests/it_test.c +++ b/lustre/tests/it_test.c @@ -1,7 +1,45 @@ -/* vi:set ts=8 sw=8 expandtab: */ -/* Unit test tool for interval tree. - * Written by jay +/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- + * vim:expandtab:shiftwidth=8:tabstop=8: + * + * GPL HEADER START + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License version 2 for more details (a copy is included + * in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU General Public License + * version 2 along with this program; If not, see + * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + * GPL HEADER END */ +/* + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. + * Use is subject to license terms. + */ +/* + * This file is part of Lustre, http://www.lustre.org/ + * Lustre is a trademark of Sun Microsystems, Inc. + * + * lustre/tests/it_test.c + * + * Unit test tool for interval tree. + * + * Author: jay + */ + #include #include #include @@ -25,7 +63,7 @@ static struct it_node { struct interval_node node; - struct list_head list; + cfs_list_t list; int hit, valid; } *it_array; static int it_count; @@ -46,13 +84,11 @@ static enum interval_iter cb(struct interval_node *n, void *args) static int count = 1; if (node->hit == 1) { - dprintf("NODE "__S" has ever been accessed\n", - __F(&n->in_extent)); + error("A duplicate node "__S" access found\n", + __F(&n->in_extent)); return INTERVAL_ITER_CONT; - error("duplicate node accessing found\n"); - return INTERVAL_ITER_STOP; } - + if (node->valid == 0) { error("A deleted node "__S" being accessed\n", __F(&n->in_extent)); @@ -90,23 +126,23 @@ static int it_test_search(struct interval_node *root) interval_search(root, &ext, cb, NULL); dprintf("\nverifing ..."); - + /* verify */ for (i = 0; i < it_count; i++) { n = &it_array[i]; if (n->valid == 0) continue; - if (extent_overlapped(&ext, &n->node.in_extent) && + if (extent_overlapped(&ext, &n->node.in_extent) && n->hit == 0) error("node "__S" overlaps" __S"," - "but never to be hit.\n", + "but never to be hit.\n", __F(&n->node.in_extent), __F(&ext)); - if (!extent_overlapped(&ext, &n->node.in_extent) && + if (!extent_overlapped(&ext, &n->node.in_extent) && n->hit) - error("node "__S" overlaps" __S", but hit.\n", + error("node "__S" overlaps" __S", but hit.\n", __F(&n->node.in_extent), __F(&ext)); } @@ -207,8 +243,9 @@ static enum interval_iter sanity_cb(struct interval_node *node, void *args) } if (!has) { - int count = 1; + int count; err: + count = 1; dprintf("node"__S":%llu Child list:\n", node->in_extent.start, node->in_extent.end, @@ -246,7 +283,7 @@ err: } if (nr) error("wrong tree, unbalanced!\n"); - + return 0; } @@ -302,7 +339,7 @@ static int it_test_search_hole(struct interval_node *root) return 0; } -static int contended_count = 0; +static int contended_count = 0; #define LOOP_COUNT 1000 static enum interval_iter perf_cb(struct interval_node *n, void *args) { @@ -317,7 +354,7 @@ static inline long tv_delta(struct timeval *s, struct timeval *e) long c = e->tv_sec - s->tv_sec; c *= 1000; c += (long int)(e->tv_usec - s->tv_usec) / 1000; - dprintf("\tStart: %lu:%lu -> End: %lu:%lu\n", + dprintf("\tStart: %lu:%lu -> End: %lu:%lu\n", s->tv_sec, s->tv_usec, e->tv_sec, e->tv_usec); return c; } @@ -329,7 +366,7 @@ static int it_test_performance(struct interval_node *root, unsigned long len) struct it_node *n; struct timeval start, end; unsigned long count; - + ext.start = (random() % (max_count - len)) & ALIGN_MASK; ext.end = (ext.start + len) & ALIGN_MASK; if (have_wide_lock) { @@ -342,7 +379,7 @@ static int it_test_performance(struct interval_node *root, unsigned long len) /* list */ contended_count = 0; gettimeofday(&start, NULL); - list_for_each_entry(n, &header, list) { + cfs_list_for_each_entry(n, &header, list) { if (extent_overlapped(&ext, &n->node.in_extent)) { count = LOOP_COUNT; while (count--); @@ -383,11 +420,11 @@ static struct interval_node *it_test_helper(struct interval_node *root) if (n->valid) { if (!interval_find(root, &n->node.in_extent)) error("Cannot find an existent node\n"); - dprintf("Erasing a node "__S"\n", + dprintf("Erasing a node "__S"\n", __F(&n->node.in_extent)); interval_erase(&n->node, &root); n->valid = 0; - list_del_init(&n->list); + cfs_list_del_init(&n->list); } else { __u64 low, high; low = (random() % max_count) & ALIGN_MASK; @@ -397,10 +434,10 @@ static struct interval_node *it_test_helper(struct interval_node *root) interval_set(&n->node, low, high); while (interval_insert(&n->node, &root)) interval_set(&n->node, low, ++high); - dprintf("Adding a node "__S"\n", + dprintf("Adding a node "__S"\n", __F(&n->node.in_extent)); n->valid = 1; - list_add(&n->list, &header); + cfs_list_add(&n->list, &header); } } @@ -437,9 +474,9 @@ static struct interval_node *it_test_init(int count) n->hit = 0; n->valid = 1; if (i == 0) - list_add_tail(&n->list, &header); + cfs_list_add_tail(&n->list, &header); else - list_add_tail(&n->list, &it_array[rand()%i].list); + cfs_list_add_tail(&n->list, &it_array[rand()%i].list); } return root;