tests: make rbtree tests unit tests
Move to a unit test, no need to build this for every platform we have. Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
abf1d36ed9
commit
9004eb68dc
6 changed files with 26 additions and 30 deletions
|
@ -1,7 +0,0 @@
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.13.1)
|
|
||||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
|
||||||
project(rbtree)
|
|
||||||
|
|
||||||
target_sources(app PRIVATE src/main.c)
|
|
|
@ -1 +0,0 @@
|
||||||
CONFIG_ZTEST=y
|
|
|
@ -1,5 +0,0 @@
|
||||||
tests:
|
|
||||||
libraries.data_structures.rbtree:
|
|
||||||
tags: rbtree
|
|
||||||
filter: not CONFIG_MISRA_SANE
|
|
||||||
platform_exclude: qemu_riscv64
|
|
5
tests/unit/rbtree/CMakeLists.txt
Normal file
5
tests/unit/rbtree/CMakeLists.txt
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
project(rbtree)
|
||||||
|
set(SOURCES main.c)
|
||||||
|
include($ENV{ZEPHYR_BASE}/subsys/testsuite/unittest.cmake)
|
|
@ -3,12 +3,12 @@
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
#include <zephyr.h>
|
|
||||||
#include <tc_util.h>
|
|
||||||
#include <ztest.h>
|
#include <ztest.h>
|
||||||
#include <sys/rb.h>
|
#include <sys/rb.h>
|
||||||
|
|
||||||
#define CHECK(n) \
|
#include "../../../lib/os/rb.c"
|
||||||
|
|
||||||
|
#define _CHECK(n) \
|
||||||
zassert_true(!!(n), "Tree check failed: [ " #n " ] @%d", __LINE__)
|
zassert_true(!!(n), "Tree check failed: [ " #n " ] @%d", __LINE__)
|
||||||
|
|
||||||
#define MAX_NODES 256
|
#define MAX_NODES 256
|
||||||
|
@ -52,8 +52,8 @@ int node_index(struct rbnode *n)
|
||||||
bool node_lessthan(struct rbnode *a, struct rbnode *b)
|
bool node_lessthan(struct rbnode *a, struct rbnode *b)
|
||||||
{
|
{
|
||||||
if (current_insertee) {
|
if (current_insertee) {
|
||||||
CHECK(a == current_insertee);
|
_CHECK(a == current_insertee);
|
||||||
CHECK(b != current_insertee);
|
_CHECK(b != current_insertee);
|
||||||
}
|
}
|
||||||
|
|
||||||
return a < b;
|
return a < b;
|
||||||
|
@ -78,7 +78,7 @@ void visit_node(struct rbnode *node, void *cookie)
|
||||||
{
|
{
|
||||||
int *nwalked = cookie;
|
int *nwalked = cookie;
|
||||||
|
|
||||||
CHECK(*nwalked < MAX_NODES);
|
_CHECK(*nwalked < MAX_NODES);
|
||||||
|
|
||||||
walked_nodes[*nwalked] = node;
|
walked_nodes[*nwalked] = node;
|
||||||
*nwalked += 1;
|
*nwalked += 1;
|
||||||
|
@ -99,20 +99,20 @@ void check_rbnode(struct rbnode *node, int blacks_above)
|
||||||
if (ch) {
|
if (ch) {
|
||||||
/* Basic tree requirement */
|
/* Basic tree requirement */
|
||||||
if (side == 0) {
|
if (side == 0) {
|
||||||
CHECK(node_lessthan(ch, node));
|
_CHECK(node_lessthan(ch, node));
|
||||||
} else {
|
} else {
|
||||||
CHECK(node_lessthan(node, ch));
|
_CHECK(node_lessthan(node, ch));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Can't have adjacent red nodes */
|
/* Can't have adjacent red nodes */
|
||||||
CHECK(z_rb_is_black(node) || z_rb_is_black(ch));
|
_CHECK(z_rb_is_black(node) || z_rb_is_black(ch));
|
||||||
|
|
||||||
/* Recurse */
|
/* Recurse */
|
||||||
check_rbnode(ch, bheight);
|
check_rbnode(ch, bheight);
|
||||||
} else {
|
} else {
|
||||||
/* All leaf nodes must be at the same black height */
|
/* All leaf nodes must be at the same black height */
|
||||||
if (last_black_height) {
|
if (last_black_height) {
|
||||||
CHECK(last_black_height == bheight);
|
_CHECK(last_black_height == bheight);
|
||||||
}
|
}
|
||||||
last_black_height = bheight;
|
last_black_height = bheight;
|
||||||
}
|
}
|
||||||
|
@ -123,8 +123,8 @@ void check_rb(void)
|
||||||
{
|
{
|
||||||
last_black_height = 0;
|
last_black_height = 0;
|
||||||
|
|
||||||
CHECK(tree.root);
|
_CHECK(tree.root);
|
||||||
CHECK(z_rb_is_black(tree.root));
|
_CHECK(z_rb_is_black(tree.root));
|
||||||
|
|
||||||
check_rbnode(tree.root, 0);
|
check_rbnode(tree.root, 0);
|
||||||
}
|
}
|
||||||
|
@ -153,10 +153,10 @@ void _check_tree(int size, int use_foreach)
|
||||||
ni = node_index(n);
|
ni = node_index(n);
|
||||||
|
|
||||||
if (last) {
|
if (last) {
|
||||||
CHECK(node_lessthan(last, n));
|
_CHECK(node_lessthan(last, n));
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECK(get_node_mask(ni));
|
_CHECK(get_node_mask(ni));
|
||||||
|
|
||||||
last = n;
|
last = n;
|
||||||
}
|
}
|
||||||
|
@ -164,15 +164,15 @@ void _check_tree(int size, int use_foreach)
|
||||||
/* Make sure all tree bits properly reflect the set of nodes we found */
|
/* Make sure all tree bits properly reflect the set of nodes we found */
|
||||||
ni = 0;
|
ni = 0;
|
||||||
for (i = 0; i < MAX_NODES; i++) {
|
for (i = 0; i < MAX_NODES; i++) {
|
||||||
CHECK(get_node_mask(i) == rb_contains(&tree, &nodes[i]));
|
_CHECK(get_node_mask(i) == rb_contains(&tree, &nodes[i]));
|
||||||
|
|
||||||
if (get_node_mask(i)) {
|
if (get_node_mask(i)) {
|
||||||
CHECK(node_index(walked_nodes[ni]) == i);
|
_CHECK(node_index(walked_nodes[ni]) == i);
|
||||||
ni++;
|
ni++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECK(ni == nwalked);
|
_CHECK(ni == nwalked);
|
||||||
|
|
||||||
if (tree.root) {
|
if (tree.root) {
|
||||||
check_rb();
|
check_rb();
|
4
tests/unit/rbtree/testcase.yaml
Normal file
4
tests/unit/rbtree/testcase.yaml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
tests:
|
||||||
|
libraries.data_structures.rbtree:
|
||||||
|
tags: rbtree
|
||||||
|
type: unit
|
Loading…
Add table
Add a link
Reference in a new issue