Patchwork [v2,03/11] rbtree/test: test rbtree_postorder_for_each_entry_safe()

login
register
mail settings
Submitter Cody P Schafer
Date Nov. 7, 2013, 1:42 a.m.
Message ID <1383788572-25938-4-git-send-email-cody@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/289098/
State Not Applicable
Headers show

Comments

Cody P Schafer - Nov. 7, 2013, 1:42 a.m.
Signed-off-by: Cody P Schafer <cody@linux.vnet.ibm.com>
---
 lib/rbtree_test.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
Michel Lespinasse - Nov. 7, 2013, 11:54 a.m.
On Wed, Nov 6, 2013 at 5:42 PM, Cody P Schafer <cody@linux.vnet.ibm.com> wrote:
> Signed-off-by: Cody P Schafer <cody@linux.vnet.ibm.com>
> ---
>  lib/rbtree_test.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/lib/rbtree_test.c b/lib/rbtree_test.c
> index df6c125..8b3c9dc 100644
> --- a/lib/rbtree_test.c
> +++ b/lib/rbtree_test.c
> @@ -114,6 +114,16 @@ static int black_path_count(struct rb_node *rb)
>         return count;
>  }
>
> +static void check_postorder_foreach(int nr_nodes)
> +{
> +       struct test_node *cur, *n;
> +       int count = 0;
> +       rbtree_postorder_for_each_entry_safe(cur, n, &root, rb)
> +               count++;
> +
> +       WARN_ON_ONCE(count != nr_nodes);
> +}
> +
>  static void check_postorder(int nr_nodes)
>  {
>         struct rb_node *rb;
> @@ -148,6 +158,7 @@ static void check(int nr_nodes)
>         WARN_ON_ONCE(count < (1 << black_path_count(rb_last(&root))) - 1);
>
>         check_postorder(nr_nodes);
> +       check_postorder_foreach(nr_nodes);
>  }
>
>  static void check_augmented(int nr_nodes)
> --
> 1.8.4.2

Looks reasonable if we need the rbtree_postorder_for_each_entry_safe
macro - but as I mentioned in 01/11, I would prefer if we could do
without that API.

Acked-by: Michel Lespinasse <walken@google.com>

Patch

diff --git a/lib/rbtree_test.c b/lib/rbtree_test.c
index df6c125..8b3c9dc 100644
--- a/lib/rbtree_test.c
+++ b/lib/rbtree_test.c
@@ -114,6 +114,16 @@  static int black_path_count(struct rb_node *rb)
 	return count;
 }
 
+static void check_postorder_foreach(int nr_nodes)
+{
+	struct test_node *cur, *n;
+	int count = 0;
+	rbtree_postorder_for_each_entry_safe(cur, n, &root, rb)
+		count++;
+
+	WARN_ON_ONCE(count != nr_nodes);
+}
+
 static void check_postorder(int nr_nodes)
 {
 	struct rb_node *rb;
@@ -148,6 +158,7 @@  static void check(int nr_nodes)
 	WARN_ON_ONCE(count < (1 << black_path_count(rb_last(&root))) - 1);
 
 	check_postorder(nr_nodes);
+	check_postorder_foreach(nr_nodes);
 }
 
 static void check_augmented(int nr_nodes)