2 * Copyright (c) 2009,2012 Apple Inc. All Rights Reserved.
5 #include "trust/trustd/policytree.h"
9 #include <libDER/oids.h>
11 #include "securityd_regressions.h"
13 #define DUMP_POLICY_TREE 0
15 int verbose = DUMP_POLICY_TREE;
17 static bool randomly_add_children(policy_tree_t node, void *ctx) {
19 uint32_t rnd = arc4random();
25 if (rnd < 0x40000000) {
27 } else if (rnd < 0x80000000) {
29 } else if (rnd < 0xc0000000) {
31 } else if (rnd < 0xf0000000) {
39 diag("node %p add %d children", node, count);
41 for (i = 1; i <= count ; ++i) {
42 policy_tree_add_child(node, &oidAnyPolicy, NULL);
43 //diag("node %p %d/%d children added", node, i, count);
44 //policy_tree_dump(node);
49 static void tests(void)
51 policy_qualifier_t p_q = NULL;
53 ok(tree = policy_tree_create(&oidAnyPolicy, p_q),
55 if (verbose) policy_tree_dump(tree);
59 for (i = 1; i <= count ; ++i) {
60 policy_tree_add_child(tree, &oidAnyPolicy, NULL);
62 diag("node %p %d/%d children added", tree, i, count);
65 policy_tree_dump(tree);
68 for (depth = 0; tree && depth < 7; ++depth) {
71 added = policy_tree_walk_depth(tree, depth,
72 randomly_add_children, NULL);
74 diag("depth: %d %s", depth,
75 (added ? "added children" : "no children added"));
78 if (verbose) policy_tree_dump(tree);
80 diag("prune_childless depth: %d", depth);
82 policy_tree_prune_childless(&tree, depth);
85 policy_tree_dump(tree);
88 diag("tree empty at depth: %d", depth);
96 policy_tree_prune(&tree);
99 int sd_10_policytree(int argc, char *const *argv)