Whamcloud - gitweb
LU-7323 test: Unknown symbol mb_cache_create (err 0)" on RHEL7
[fs/lustre-release.git] / lustre / tests / it_test.c
index b5697b8..2777143 100644 (file)
@@ -1,12 +1,54 @@
-/* vi:set ts=8 sw=8 expandtab: */
-/* Unit test tool for interval tree.
- * Written by jay <jxiong@clusterfs.com> 
+/*
+ * 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 <jxiong@clusterfs.com>
+ */
+#include <inttypes.h>
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <time.h>
 #include <sys/time.h>
 
+#include <linux/types.h>
+
+#define EXPORT_SYMBOL(s)
+
 #include <../ldlm/interval_tree.c>
 
 #define dprintf(fmt, args...) //printf(fmt, ##args)
         abort();                                        \
 } while(0)
 
-#define __F(ext)         (ext)->start, (ext)->end
-#define __S              "[%llx:%llx]"
-
 #define ALIGN_SIZE       4096
 #define ALIGN_MASK       (~(ALIGN_SIZE - 1))
 
 static struct it_node {
         struct interval_node node;
-        struct list_head list;
+       struct list_head list;
         int hit, valid;
 } *it_array;
 static int it_count;
-static CFS_LIST_HEAD(header);
+static struct list_head header = LIST_HEAD_INIT(header);
 static unsigned long max_count = ULONG_MAX & ALIGN_MASK;
 static int have_wide_lock = 0;
 
@@ -45,16 +84,16 @@ 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 [%#jx:%#jx] access found\n",
+                     (uintmax_t)n->in_extent.start,
+                     (uintmax_t)n->in_extent.end);
                 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));
+               error("A deleted node [%#jx:%#jx] being accessed\n",
+                     (uintmax_t)n->in_extent.start,
+                     (uintmax_t)n->in_extent.end);
                 return INTERVAL_ITER_STOP;
         }
 
@@ -62,7 +101,8 @@ static enum interval_iter cb(struct interval_node *n, void *args)
                 dprintf("\n");
                 count = 1;
         }
-        dprintf(""__S" ", __F(&n->in_extent));
+       dprintf("[%#jx:%#jx] ", (uintmax_t)n->in_extent.start,
+               (uintmax_t)n->in_extent.end);
         fflush(stdout);
 
         node->hit = 1;
@@ -83,31 +123,33 @@ static int it_test_search(struct interval_node *root)
                 if (ext.end > max_count)
                         ext.end = max_count;
 
-                dprintf("\n\nSearching the node overlapped "__S" ..\n",
-                        __F(&ext));
+               dprintf("\n\nSearching the node overlapped [%#jx:%#jx] ..\n",
+                       (uintmax_t)ext.start, (uintmax_t)ext.end);
 
                 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", 
-                                      __F(&n->node.in_extent),
-                                      __F(&ext));
+                               error("node [%#jx:%#jx] overlaps [%#jx:%#jx],"
+                                      "but never to be hit.\n",
+                                     (uintmax_t)n->node.in_extent.start,
+                                     (uintmax_t)n->node.in_extent.end,
+                                     (uintmax_t)ext.start, (uintmax_t)ext.end);
 
-                        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", 
-                                      __F(&n->node.in_extent),
-                                      __F(&ext));
+                               error("node [%#jx:%#jx] overlaps [%#jx:%#jx], but hit.\n",
+                                     (uintmax_t)n->node.in_extent.start,
+                                     (uintmax_t)n->node.in_extent.end,
+                                     (uintmax_t)ext.start, (uintmax_t)ext.end);
                 }
                 if (err) error("search error\n");
                 dprintf("ok.\n");
@@ -129,11 +171,12 @@ static int it_test_iterate(struct interval_node *root)
         for (i = 0; i < it_count; i++) {
                 if (it_array[i].valid == 0)
                         continue;
-                if (it_array[i].hit == 0)
-                        error("Node "__S" is not accessed\n",
-                              __F(&it_array[i].node.in_extent));
-        }
-
+               if (it_array[i].hit == 0) {
+                       error("Node [%#jx:%#jx] is not accessed\n",
+                             (uintmax_t)it_array[i].node.in_extent.start,
+                             (uintmax_t)it_array[i].node.in_extent.end);
+               }
+       }
         return 0;
 }
 
@@ -167,11 +210,14 @@ static int it_test_find(struct interval_node *root)
                         continue;
 
                 ext = &it_array[idx].node.in_extent;
-                dprintf("Try to find "__S"\n", __F(ext));
-                if (!interval_find(root, ext))
-                        error("interval_find, try to find "__S"\n", __F(ext));
-        }
-        return 0;
+               dprintf("Try to find [%#jx:%#jx]\n", (uintmax_t)ext->start,
+                       (uintmax_t)ext->end);
+               if (!interval_find(root, ext)) {
+                       error("interval_find, try to find [%#jx:%#jx]\n",
+                             (uintmax_t)ext->start, (uintmax_t)ext->end);
+               }
+       }
+       return 0;
 }
 
 /* sanity test is tightly coupled with implementation, so when you changed
@@ -191,7 +237,7 @@ static enum interval_iter sanity_cb(struct interval_node *node, void *args)
 
                 if (tmp->in_max_high > max_high) {
                         dprintf("max high sanity check, max_high is %llu,"
-                                "child max_high: %llu"__S"\n",
+                               "child max_high: %llu[%#jx:%#jx]\n",
                                 max_high, tmp->in_max_high,
                                 __F(&tmp->in_extent));
                         goto err;
@@ -206,15 +252,16 @@ static enum interval_iter sanity_cb(struct interval_node *node, void *args)
         }
 
         if (!has) {
-                int count = 1;
+                int count;
 err:
-                dprintf("node"__S":%llu Child list:\n",
+                count = 1;
+               dprintf("node[%#jx:%#jx]:%llu Child list:\n",
                         node->in_extent.start,
                         node->in_extent.end,
                         node->in_max_high);
 
                 interval_for_each(tmp, node) {
-                        dprintf(""__S":%llu ",
+                       dprintf("[%#jx:%#jx]:%llu ",
                                 __F(&tmp->in_extent),
                                 tmp->in_max_high);
                         if (count++ == 8) {
@@ -245,7 +292,7 @@ err:
         }
         if (nr)
                 error("wrong tree, unbalanced!\n");
-        
+
         return 0;
 }
 
@@ -273,15 +320,20 @@ static int it_test_search_hole(struct interval_node *root)
         ext2 = ext;
 
         interval_expand(root, &ext, NULL);
-        dprintf("Extending "__S" to .."__S"\n", __F(&ext2), __F(&ext));
+       dprintf("Extending [%#jx:%#jx] to ..[%#jx:%#jx]\n",
+               (uintmax_t)ext2.start, (uintmax_t)ext2.end,
+               (uintmax_t)ext.start, (uintmax_t)ext.end);
         for (i = 0; i < it_count; i++) {
                 n = &it_array[i];
                 if (n->valid == 0)
                         continue;
 
                 if (extent_overlapped(&ext, &n->node.in_extent)) {
-                        error("Extending "__S" to .."__S" overlaps node"__S"\n",
-                                __F(&ext2), __F(&ext), __F(&n->node.in_extent));
+                       error("Extending [%#jx:%#jx] to ..[%#jx:%#jx] overlaps node[%#jx:%#jx]\n",
+                             (uintmax_t)ext2.start, (uintmax_t)ext2.end,
+                             (uintmax_t)ext.start, (uintmax_t)ext.end,
+                             (uintmax_t)n->node.in_extent.start,
+                             (uintmax_t)n->node.in_extent.end);
                 }
 
                 if (n->node.in_extent.end < ext2.start)
@@ -294,14 +346,15 @@ static int it_test_search_hole(struct interval_node *root)
         /* only expanding high right now */
         if (ext2.start != ext.start || high != ext.end) {
                 ext2.start = low, ext2.end = high;
-                error("Real extending result:"__S", expected:"__S"\n",
-                       __F(&ext), __F(&ext2));
+               error("Real extending result:[%#jx:%#jx], expected:[%#jx:%#jx]\n",
+                     (uintmax_t)ext.start, (uintmax_t)ext.end,
+                     (uintmax_t)ext2.start, (uintmax_t)ext2.end);
         }
 
         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)
 {
@@ -316,7 +369,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;
 }
@@ -328,7 +381,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) {
@@ -336,12 +389,13 @@ static int it_test_performance(struct interval_node *root, unsigned long len)
                 ext.end = max_count;
         }
 
-        dprintf("Extent search"__S"\n", __F(&ext));
+       dprintf("Extent search[%#jx:%#jx]\n", (uintmax_t)ext.start,
+               (uintmax_t)ext.end);
 
         /* list */
         contended_count = 0;
         gettimeofday(&start, NULL);
-        list_for_each_entry(n, &header, list) {
+       list_for_each_entry(n, &header, list) {
                 if (extent_overlapped(&ext, &n->node.in_extent)) {
                         count = LOOP_COUNT;
                         while (count--);
@@ -382,11 +436,12 @@ 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", 
-                                __F(&n->node.in_extent));
+                       dprintf("Erasing a node [%#jx:%#jx]\n",
+                               (uintmax_t)n->node.in_extent.start,
+                               (uintmax_t)n->node.in_extent.end);
                         interval_erase(&n->node, &root);
                         n->valid = 0;
-                        list_del_init(&n->list);
+                       list_del_init(&n->list);
                 } else {
                         __u64 low, high;
                         low = (random() % max_count) & ALIGN_MASK;
@@ -396,10 +451,11 @@ 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", 
-                                __F(&n->node.in_extent));
+                       dprintf("Adding a node [%#jx:%#jx]\n",
+                               (uintmax_t)n->node.in_extent.start,
+                               (uintmax_t)n->node.in_extent.end);
                         n->valid = 1;
-                        list_add(&n->list, &header);
+                       list_add(&n->list, &header);
                 }
         }
 
@@ -436,9 +492,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);
+                       list_add_tail(&n->list, &header);
                 else
-                        list_add_tail(&n->list, &it_array[rand()%i].list);
+                       list_add_tail(&n->list, &it_array[rand()%i].list);
         }
 
         return root;