typedefstruct device_tree_ctxt { struct device_tree_idevice_tree* tree; /* The root test node is not necessarily the rot of the device tree */ struct device_tree_inode* root_node;
} DeviceTreeTest_t;
TEST_F_SETUP(DeviceTreeTest) { struct device_tree_inode_iter* iter = NULL;
/* This is the compatible string of the root test node */ constchar* root_compat = TEST_NODE_COMPAT;
rc = device_tree_idevice_tree_get_compatible_nodes(_state->tree,
root_compat, &iter);
ASSERT_EQ(rc, NO_ERROR);
ASSERT_NE(iter, NULL);
/* Check the property's value using the u64 helper */
uint64_t prop_value_u64 = 0;
rc = device_tree_prop_get_u64(prop, &prop_value_u64);
EXPECT_EQ(rc, NO_ERROR);
EXPECT_EQ(prop_value_u64, 0xCAFED00D12345678);
/* Check that we can't use the u32 helper for a u64 */
uint32_t prop_value_u32 = 0;
rc = device_tree_prop_get_u32(prop, &prop_value_u32);
EXPECT_EQ(rc, DT_ERROR_INVALID_ARGS);
test_abort: if (prop) {
device_tree_prop_release(&prop);
} if (node) {
device_tree_inode_release(&node);
}
}
/* Get a node */ int rc = device_tree_inode_get_subnode(_state->root_node, "chosen", &node);
ASSERT_EQ(rc, NO_ERROR);
ASSERT_NE(node, NULL);
/* Get an iterator over the node's properties */
rc = device_tree_inode_get_props(node, &prop_iter);
ASSERT_EQ(rc, NO_ERROR);
ASSERT_NE(prop_iter, NULL);
/* Iterate over the properties */ constchar* expected_prop_names[] = {"kaslr-seed", "bootargs", NULL}; int expected_rc[] = {NO_ERROR, NO_ERROR, DT_ERROR_PROP_NOT_FOUND}; for (size_t i = 0; i < countof(expected_prop_names); i++) { /* Advance the property iterator */
rc = device_tree_iprop_iter_get_next_prop(prop_iter, &prop);
ASSERT_EQ(rc, expected_rc[i]);
if (rc != NO_ERROR) { /* *propisonlynon-nullifthereisaproperty,sononeedto *releasehere
*/ continue;
} /* If there was a property, check its name */ constchar* prop_name = NULL;
size_t len;
ASSERT_NE(prop, NULL);
rc = device_tree_prop_get_name(prop, &prop_name, &len);
ASSERT_EQ(rc, NO_ERROR);
ASSERT_NE((char*)prop_name, NULL);
EXPECT_EQ(strcmp(prop_name, expected_prop_names[i]), 0);
EXPECT_EQ(len, strlen(expected_prop_names[i]));
device_tree_prop_release(&prop);
}
test_abort: if (prop_iter) {
device_tree_iprop_iter_release(&prop_iter);
} if (node) {
device_tree_inode_release(&node);
} if (prop) {
device_tree_prop_release(&prop);
}
}
/* Get an iterator over the root node's subnodes */ int rc = device_tree_inode_get_subnodes(_state->root_node, &node_iter);
ASSERT_EQ(rc, NO_ERROR);
ASSERT_NE(node_iter, NULL);
/* Iterate over the subnodes */ int expected_rc[] = {NO_ERROR, NO_ERROR, DT_ERROR_NODE_NOT_FOUND}; constchar* subnode_names[] = {"chosen", "interrupt-controller@DEADBEEF",
NULL}; constchar* subnode_props[] = {"kaslr-seed", "reg", NULL}; for (size_t i = 0; i < countof(subnode_names); i++) { /* Advance the node iterator */
rc = device_tree_inode_iter_get_next_node(node_iter, &subnode);
ASSERT_EQ(rc, expected_rc[i]);
if (rc != NO_ERROR) { /* *subnode_propisonlynon-nullifthereisaproperty,sononeed *toreleasehere
*/ continue;
} /* If there was a node, check its name */
ASSERT_NE(subnode, NULL); constchar* subnode_name = NULL;
rc = device_tree_inode_get_name(subnode, &subnode_name);
ASSERT_EQ(rc, NO_ERROR);
ASSERT_NE((char*)subnode_name, NULL);
EXPECT_EQ(strcmp(subnode_name, subnode_names[i]), 0);
/* Check for a property that the node is expected to have */
rc = device_tree_inode_get_prop(subnode, subnode_props[i],
&subnode_prop);
ASSERT_EQ(rc, NO_ERROR);
ASSERT_NE(subnode_prop, NULL);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.