This article provides the code for testing the of functions used for finding nodes.
For related subjects, please refer to the SOC Table of Contents.
The functions we will be testing in chronological order in this section are:
- of_find_node_by_name
- of_find_node_by_type
- of_find_compatible_node
- of_find_matching_node_and_match
- of_find_node_by_path
The code to be inserted into the corresponding section is as follows:
// of_find_node_by_name struct device_node *test_ofnbn; test_ofnbn = of_find_node_by_name(NULL, "test_node2"); if(NULL == &test_ofnbn){ printk(KERN_ERR "Node was not found via of_find_node_by_name \r\n"); } if(NULL != &test_ofnbn){ printk(KERN_ERR "Node was successfully found via of_find_node_by_name \r\n"); printk(KERN_ERR "Node name is: %s \r\n", test_ofnbn->name); } printk(KERN_ERR "\r\n"); // of_find_node_by_type struct device_node *test_ofnbt; test_ofnbt = of_find_node_by_type(NULL, "test_device_type1"); if(NULL == &test_ofnbt){ printk(KERN_ERR "Node was not found via of_find_node_by_type \r\n"); } if(NULL != &test_ofnbt){ printk(KERN_ERR "Node was successfully found via of_find_node_by_type \r\n"); printk(KERN_ERR "Node name is: %s \r\n", test_ofnbt->name); } printk(KERN_ERR "\r\n"); // of_find_compatible_node struct device_node *test_ofcndn; test_ofcndn = of_find_compatible_node(NULL, "test_device_type1", "fii,fii-dt-driver"); if(NULL == &test_ofcndn){ printk(KERN_ERR "Node was not found via of_find_compatible_node \r\n"); } if(NULL != &test_ofcndn){ printk(KERN_ERR "Node was successfully found via of_find_compatible_node \r\n"); printk(KERN_ERR "Node name is: %s \r\n", test_ofcndn->name); } printk(KERN_ERR "\r\n"); // of_find_matching_node_and_match const struct of_device_id *test_np; struct device_node *test_dn; test_dn = of_find_matching_node_and_match(NULL, of_match_fii_dt_driver, &test_np); if(NULL == &test_dn){ printk(KERN_ERR "Node was not found via of_find_matching_node_and_match \r\n"); } if(NULL != &test_dn){ printk(KERN_ERR "Node was successfully found via of_find_matching_node_and_match \r\n"); printk(KERN_ERR "Node name is: %s \r\n", test_dn->name); } printk(KERN_ERR "\r\n"); // of_find_node_by_path struct device_node *test_ofnbp; test_ofnbp = of_find_node_by_path("/test_node1"); if(NULL == &test_ofnbp){ printk(KERN_ERR "Node was not found via of_find_node_by_path \r\n"); } if(NULL != &test_ofnbp){ printk(KERN_ERR "Node was successfully found via of_find_node_by_path \r\n"); printk(KERN_ERR "Node name is: %s \r\n", test_ofnbp->name); }