linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Leno Hou <lenohou@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: andy.shevchenko@gmail.com, akpm@linux-foundation.org,
	Leno Hou <lenohou@gmail.com>
Subject: [PATCH v3 2/2] lib/btree.c: add testcase for in-memory b+ tree
Date: Thu, 18 May 2017 21:41:07 +0800	[thread overview]
Message-ID: <1495114867-3400-2-git-send-email-lenohou@gmail.com> (raw)
In-Reply-To: <1495114867-3400-1-git-send-email-lenohou@gmail.com>

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

  reply	other threads:[~2017-05-18 13:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-18 13:41 [PATCH v3 1/2] lib/btree.c: optimise the code by previously getpos function Leno Hou
2017-05-18 13:41 ` Leno Hou [this message]
2017-05-18 15:51   ` [PATCH v3 2/2] lib/btree.c: add testcase for in-memory b+ tree Andy Shevchenko
  -- strict thread matches above, loose matches on Subject: below --
2017-05-18  8:35 [PATCH v3 1/2] lib/btree.c: optimise the code by previously getpos function Leno Hou
2017-05-18  8:35 ` [PATCH v3 2/2] lib/btree.c: add testcase for in-memory b+ tree Leno Hou
2017-05-18 10:00   ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1495114867-3400-2-git-send-email-lenohou@gmail.com \
    --to=lenohou@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).