The scheduler priq implementation was taking advantage of a subtle
behavior of the way the tree presents the order of its arguments (the
node being inserted is always first). But it turns out the tree got
that wrong in one spot.
As this was subtle voodoo to begin with, it should have been
documented first. Similarly add a little code to the test case to
guarantee this in the future.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
Works mostly like the list enumeration macros. Implemented by fairly
clever alloca trickery and some subtle "next node" logic. More
convenient for many uses, can be early-exited, but has somewhat larger
code size than rb_walk().
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This patch fixes a coverity issue with the post increment of ni inside
an zassert call. There might be side effects of non-debug builds that
would cause the code to not do the right thing.
Coverity-ID: 185391
Signed-off-by: Andy Gross <andy.gross@linaro.org>
1. Add a tag in the testcase.yaml to deal with the following error from
sanitycheck:
E: tests/lib/rbtree/testcase.yaml: can't load (skipping):
<NotMappingError: error code 6: Value: None is not of a
mapping type: Path: '/'>
2. Reduced the MAX_NODES so the test will build on small memory systems
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Returns true if the specified node is in the tree. Allows the tree to
be used for "set" style semantics along with a lessthan_fn that simply
compares the nodes by their address.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
Test for the rbtree balanced tree.
The theory here is that the test uses a PRNG to randomly build and
modify trees build from an array of node objects (whose comparison
operator is just their memory address). It begins with tiny node
sets, so as to catch edge cases (e.g. nodes being the root, or a leaf,
or parent/child) in the balancing algorithm before increasing the size
and continuing.
At each iteration the resulting tree is walked, verifying that it
contains exactly the nodes that we expect it should, that they appear
in the correct sorted order in the walk, that their local structure
matches a correct binary tree, and that the red/black rules are
followed always:
* The root must be black
* Red nodes can have only black children
* The path from the root to any NULL child pointer in the tree must
cross the same number of black nodes.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>