Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1644565

[PATCH v3 2/2] lib/btree.c: add testcase for in-memory b+ tree

From Leno Hou <lenohou@gmail.com>
Newsgroups linux.kernel
Subject [PATCH v3 2/2] lib/btree.c: add testcase for in-memory b+ tree
Date 2017-05-18 15:50 +0200
Message-ID <tItYu-3le-17@gated-at.bofh.it> (permalink)
References <tItYu-3le-19@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Signed-off-by: Leno Hou <lenohou@gmail.com>
---
 lib/btree_test.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)
 create mode 100644 lib/btree_test.c

diff --git a/lib/btree_test.c b/lib/btree_test.c
new file mode 100644
index 0000000..90d9048
--- /dev/null
+++ b/lib/btree_test.c
@@ -0,0 +1,77 @@
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/btree.h>
+#include <linux/types.h>
+
+#define NODES 24
+
+struct test_node {
+	u32 key;
+	u32 val;
+};
+
+static struct btree_head32 bh;
+static struct test_node nodes[NODES];
+
+static void init(void)
+{
+	int i;
+
+	for (i = 0; i < NODES; i++) {
+		nodes[i].key = i;
+		nodes[i].val = i;
+	}
+}
+static int __init btree_test_init(void)
+{
+	u32 key = 0;
+	u32 *val = NULL;
+	int i, rc;
+
+	pr_alert("btree testing\n");
+
+	init();
+	rc = btree_init32(&bh);
+
+	if (rc)
+		pr_alert("Unable initialize btree memory\n");
+
+	for (i = 0; i < NODES; i++) {
+		rc = btree_insert32(&bh,
+				nodes[i].key,
+				&nodes[i].val,
+				GFP_ATOMIC);
+
+		if (rc)
+			pr_alert("Unable to insert key into btree\n");
+	}
+
+	pr_alert("========================================\n");
+
+	btree_for_each_safe32(&bh, key, val) {
+		pr_alert("val %d\n", *val);
+	}
+
+	btree_remove32(&bh, 11);
+
+	pr_alert("========================================\n");
+	btree_for_each_safe32(&bh, key, val) {
+		pr_alert("val %d\n", *val);
+	}
+
+	return 0;
+}
+static void __exit btree_test_exit(void)
+{
+	pr_alert("test exit\n");
+	btree_destroy32(&bh);
+
+}
+
+module_init(btree_test_init);
+module_exit(btree_test_exit);
+
+MODULE_LICENSE("Dual BSD/GPL");
+MODULE_AUTHOR("Leno Hou <lenohou@gmai.com>");
+MODULE_DESCRIPTION("Simple In-memory B+ Tree test");
-- 
2.7.4

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH v3 2/2] lib/btree.c: add testcase for in-memory b+ tree Leno Hou <lenohou@gmail.com> - 2017-05-18 15:50 +0200
  Re: [PATCH v3 2/2] lib/btree.c: add testcase for in-memory b+ tree Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-05-18 18:00 +0200

csiph-web