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


Groups > linux.kernel > #1644565 > unrolled thread

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

Started byLeno Hou <lenohou@gmail.com>
First post2017-05-18 15:50 +0200
Last post2017-05-18 18:00 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [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

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

FromLeno Hou <lenohou@gmail.com>
Date2017-05-18 15:50 +0200
Subject[PATCH v3 2/2] lib/btree.c: add testcase for in-memory b+ tree
Message-ID<tItYu-3le-17@gated-at.bofh.it>
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

[toc] | [next] | [standalone]


#1644707

FromAndy Shevchenko <andy.shevchenko@gmail.com>
Date2017-05-18 18:00 +0200
Message-ID<tIw0h-4M2-7@gated-at.bofh.it>
In reply to#1644565
On Thu, May 18, 2017 at 4:41 PM, Leno Hou <lenohou@gmail.com> wrote:
> Signed-off-by: Leno Hou <lenohou@gmail.com>
> ---

Please, address my comments.
This version doesn't look modified anyhow.

>  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
>



-- 
With Best Regards,
Andy Shevchenko

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web