selftest.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. /*
  2. * Self tests for device tree subsystem
  3. */
  4. #define pr_fmt(fmt) "### dt-test ### " fmt
  5. #include <linux/clk.h>
  6. #include <linux/err.h>
  7. #include <linux/errno.h>
  8. #include <linux/module.h>
  9. #include <linux/of.h>
  10. #include <linux/of_fdt.h>
  11. #include <linux/of_irq.h>
  12. #include <linux/of_platform.h>
  13. #include <linux/list.h>
  14. #include <linux/mutex.h>
  15. #include <linux/slab.h>
  16. #include <linux/device.h>
  17. static struct selftest_results {
  18. int passed;
  19. int failed;
  20. } selftest_results;
  21. #define NO_OF_NODES 2
  22. static struct device_node *nodes[NO_OF_NODES];
  23. static int last_node_index;
  24. #define selftest(result, fmt, ...) { \
  25. if (!(result)) { \
  26. selftest_results.failed++; \
  27. pr_err("FAIL %s():%i " fmt, __func__, __LINE__, ##__VA_ARGS__); \
  28. } else { \
  29. selftest_results.passed++; \
  30. pr_debug("pass %s():%i\n", __func__, __LINE__); \
  31. } \
  32. }
  33. static void __init of_selftest_find_node_by_name(void)
  34. {
  35. struct device_node *np;
  36. np = of_find_node_by_path("/testcase-data");
  37. selftest(np && !strcmp("/testcase-data", np->full_name),
  38. "find /testcase-data failed\n");
  39. of_node_put(np);
  40. /* Test if trailing '/' works */
  41. np = of_find_node_by_path("/testcase-data/");
  42. selftest(!np, "trailing '/' on /testcase-data/ should fail\n");
  43. np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
  44. selftest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", np->full_name),
  45. "find /testcase-data/phandle-tests/consumer-a failed\n");
  46. of_node_put(np);
  47. np = of_find_node_by_path("testcase-alias");
  48. selftest(np && !strcmp("/testcase-data", np->full_name),
  49. "find testcase-alias failed\n");
  50. of_node_put(np);
  51. /* Test if trailing '/' works on aliases */
  52. np = of_find_node_by_path("testcase-alias/");
  53. selftest(!np, "trailing '/' on testcase-alias/ should fail\n");
  54. np = of_find_node_by_path("testcase-alias/phandle-tests/consumer-a");
  55. selftest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", np->full_name),
  56. "find testcase-alias/phandle-tests/consumer-a failed\n");
  57. of_node_put(np);
  58. np = of_find_node_by_path("/testcase-data/missing-path");
  59. selftest(!np, "non-existent path returned node %s\n", np->full_name);
  60. of_node_put(np);
  61. np = of_find_node_by_path("missing-alias");
  62. selftest(!np, "non-existent alias returned node %s\n", np->full_name);
  63. of_node_put(np);
  64. np = of_find_node_by_path("testcase-alias/missing-path");
  65. selftest(!np, "non-existent alias with relative path returned node %s\n", np->full_name);
  66. of_node_put(np);
  67. }
  68. static void __init of_selftest_dynamic(void)
  69. {
  70. struct device_node *np;
  71. struct property *prop;
  72. np = of_find_node_by_path("/testcase-data");
  73. if (!np) {
  74. pr_err("missing testcase data\n");
  75. return;
  76. }
  77. /* Array of 4 properties for the purpose of testing */
  78. prop = kzalloc(sizeof(*prop) * 4, GFP_KERNEL);
  79. if (!prop) {
  80. selftest(0, "kzalloc() failed\n");
  81. return;
  82. }
  83. /* Add a new property - should pass*/
  84. prop->name = "new-property";
  85. prop->value = "new-property-data";
  86. prop->length = strlen(prop->value);
  87. selftest(of_add_property(np, prop) == 0, "Adding a new property failed\n");
  88. /* Try to add an existing property - should fail */
  89. prop++;
  90. prop->name = "new-property";
  91. prop->value = "new-property-data-should-fail";
  92. prop->length = strlen(prop->value);
  93. selftest(of_add_property(np, prop) != 0,
  94. "Adding an existing property should have failed\n");
  95. /* Try to modify an existing property - should pass */
  96. prop->value = "modify-property-data-should-pass";
  97. prop->length = strlen(prop->value);
  98. selftest(of_update_property(np, prop) == 0,
  99. "Updating an existing property should have passed\n");
  100. /* Try to modify non-existent property - should pass*/
  101. prop++;
  102. prop->name = "modify-property";
  103. prop->value = "modify-missing-property-data-should-pass";
  104. prop->length = strlen(prop->value);
  105. selftest(of_update_property(np, prop) == 0,
  106. "Updating a missing property should have passed\n");
  107. /* Remove property - should pass */
  108. selftest(of_remove_property(np, prop) == 0,
  109. "Removing a property should have passed\n");
  110. /* Adding very large property - should pass */
  111. prop++;
  112. prop->name = "large-property-PAGE_SIZEx8";
  113. prop->length = PAGE_SIZE * 8;
  114. prop->value = kzalloc(prop->length, GFP_KERNEL);
  115. selftest(prop->value != NULL, "Unable to allocate large buffer\n");
  116. if (prop->value)
  117. selftest(of_add_property(np, prop) == 0,
  118. "Adding a large property should have passed\n");
  119. }
  120. static void __init of_selftest_parse_phandle_with_args(void)
  121. {
  122. struct device_node *np;
  123. struct of_phandle_args args;
  124. int i, rc;
  125. np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
  126. if (!np) {
  127. pr_err("missing testcase data\n");
  128. return;
  129. }
  130. rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells");
  131. selftest(rc == 7, "of_count_phandle_with_args() returned %i, expected 7\n", rc);
  132. for (i = 0; i < 8; i++) {
  133. bool passed = true;
  134. rc = of_parse_phandle_with_args(np, "phandle-list",
  135. "#phandle-cells", i, &args);
  136. /* Test the values from tests-phandle.dtsi */
  137. switch (i) {
  138. case 0:
  139. passed &= !rc;
  140. passed &= (args.args_count == 1);
  141. passed &= (args.args[0] == (i + 1));
  142. break;
  143. case 1:
  144. passed &= !rc;
  145. passed &= (args.args_count == 2);
  146. passed &= (args.args[0] == (i + 1));
  147. passed &= (args.args[1] == 0);
  148. break;
  149. case 2:
  150. passed &= (rc == -ENOENT);
  151. break;
  152. case 3:
  153. passed &= !rc;
  154. passed &= (args.args_count == 3);
  155. passed &= (args.args[0] == (i + 1));
  156. passed &= (args.args[1] == 4);
  157. passed &= (args.args[2] == 3);
  158. break;
  159. case 4:
  160. passed &= !rc;
  161. passed &= (args.args_count == 2);
  162. passed &= (args.args[0] == (i + 1));
  163. passed &= (args.args[1] == 100);
  164. break;
  165. case 5:
  166. passed &= !rc;
  167. passed &= (args.args_count == 0);
  168. break;
  169. case 6:
  170. passed &= !rc;
  171. passed &= (args.args_count == 1);
  172. passed &= (args.args[0] == (i + 1));
  173. break;
  174. case 7:
  175. passed &= (rc == -ENOENT);
  176. break;
  177. default:
  178. passed = false;
  179. }
  180. selftest(passed, "index %i - data error on node %s rc=%i\n",
  181. i, args.np->full_name, rc);
  182. }
  183. /* Check for missing list property */
  184. rc = of_parse_phandle_with_args(np, "phandle-list-missing",
  185. "#phandle-cells", 0, &args);
  186. selftest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
  187. rc = of_count_phandle_with_args(np, "phandle-list-missing",
  188. "#phandle-cells");
  189. selftest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
  190. /* Check for missing cells property */
  191. rc = of_parse_phandle_with_args(np, "phandle-list",
  192. "#phandle-cells-missing", 0, &args);
  193. selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  194. rc = of_count_phandle_with_args(np, "phandle-list",
  195. "#phandle-cells-missing");
  196. selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  197. /* Check for bad phandle in list */
  198. rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle",
  199. "#phandle-cells", 0, &args);
  200. selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  201. rc = of_count_phandle_with_args(np, "phandle-list-bad-phandle",
  202. "#phandle-cells");
  203. selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  204. /* Check for incorrectly formed argument list */
  205. rc = of_parse_phandle_with_args(np, "phandle-list-bad-args",
  206. "#phandle-cells", 1, &args);
  207. selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  208. rc = of_count_phandle_with_args(np, "phandle-list-bad-args",
  209. "#phandle-cells");
  210. selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  211. }
  212. static void __init of_selftest_property_match_string(void)
  213. {
  214. struct device_node *np;
  215. int rc;
  216. np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
  217. if (!np) {
  218. pr_err("No testcase data in device tree\n");
  219. return;
  220. }
  221. rc = of_property_match_string(np, "phandle-list-names", "first");
  222. selftest(rc == 0, "first expected:0 got:%i\n", rc);
  223. rc = of_property_match_string(np, "phandle-list-names", "second");
  224. selftest(rc == 1, "second expected:0 got:%i\n", rc);
  225. rc = of_property_match_string(np, "phandle-list-names", "third");
  226. selftest(rc == 2, "third expected:0 got:%i\n", rc);
  227. rc = of_property_match_string(np, "phandle-list-names", "fourth");
  228. selftest(rc == -ENODATA, "unmatched string; rc=%i", rc);
  229. rc = of_property_match_string(np, "missing-property", "blah");
  230. selftest(rc == -EINVAL, "missing property; rc=%i", rc);
  231. rc = of_property_match_string(np, "empty-property", "blah");
  232. selftest(rc == -ENODATA, "empty property; rc=%i", rc);
  233. rc = of_property_match_string(np, "unterminated-string", "blah");
  234. selftest(rc == -EILSEQ, "unterminated string; rc=%i", rc);
  235. }
  236. static void __init of_selftest_parse_interrupts(void)
  237. {
  238. struct device_node *np;
  239. struct of_phandle_args args;
  240. int i, rc;
  241. np = of_find_node_by_path("/testcase-data/interrupts/interrupts0");
  242. if (!np) {
  243. pr_err("missing testcase data\n");
  244. return;
  245. }
  246. for (i = 0; i < 4; i++) {
  247. bool passed = true;
  248. args.args_count = 0;
  249. rc = of_irq_parse_one(np, i, &args);
  250. passed &= !rc;
  251. passed &= (args.args_count == 1);
  252. passed &= (args.args[0] == (i + 1));
  253. selftest(passed, "index %i - data error on node %s rc=%i\n",
  254. i, args.np->full_name, rc);
  255. }
  256. of_node_put(np);
  257. np = of_find_node_by_path("/testcase-data/interrupts/interrupts1");
  258. if (!np) {
  259. pr_err("missing testcase data\n");
  260. return;
  261. }
  262. for (i = 0; i < 4; i++) {
  263. bool passed = true;
  264. args.args_count = 0;
  265. rc = of_irq_parse_one(np, i, &args);
  266. /* Test the values from tests-phandle.dtsi */
  267. switch (i) {
  268. case 0:
  269. passed &= !rc;
  270. passed &= (args.args_count == 1);
  271. passed &= (args.args[0] == 9);
  272. break;
  273. case 1:
  274. passed &= !rc;
  275. passed &= (args.args_count == 3);
  276. passed &= (args.args[0] == 10);
  277. passed &= (args.args[1] == 11);
  278. passed &= (args.args[2] == 12);
  279. break;
  280. case 2:
  281. passed &= !rc;
  282. passed &= (args.args_count == 2);
  283. passed &= (args.args[0] == 13);
  284. passed &= (args.args[1] == 14);
  285. break;
  286. case 3:
  287. passed &= !rc;
  288. passed &= (args.args_count == 2);
  289. passed &= (args.args[0] == 15);
  290. passed &= (args.args[1] == 16);
  291. break;
  292. default:
  293. passed = false;
  294. }
  295. selftest(passed, "index %i - data error on node %s rc=%i\n",
  296. i, args.np->full_name, rc);
  297. }
  298. of_node_put(np);
  299. }
  300. static void __init of_selftest_parse_interrupts_extended(void)
  301. {
  302. struct device_node *np;
  303. struct of_phandle_args args;
  304. int i, rc;
  305. np = of_find_node_by_path("/testcase-data/interrupts/interrupts-extended0");
  306. if (!np) {
  307. pr_err("missing testcase data\n");
  308. return;
  309. }
  310. for (i = 0; i < 7; i++) {
  311. bool passed = true;
  312. rc = of_irq_parse_one(np, i, &args);
  313. /* Test the values from tests-phandle.dtsi */
  314. switch (i) {
  315. case 0:
  316. passed &= !rc;
  317. passed &= (args.args_count == 1);
  318. passed &= (args.args[0] == 1);
  319. break;
  320. case 1:
  321. passed &= !rc;
  322. passed &= (args.args_count == 3);
  323. passed &= (args.args[0] == 2);
  324. passed &= (args.args[1] == 3);
  325. passed &= (args.args[2] == 4);
  326. break;
  327. case 2:
  328. passed &= !rc;
  329. passed &= (args.args_count == 2);
  330. passed &= (args.args[0] == 5);
  331. passed &= (args.args[1] == 6);
  332. break;
  333. case 3:
  334. passed &= !rc;
  335. passed &= (args.args_count == 1);
  336. passed &= (args.args[0] == 9);
  337. break;
  338. case 4:
  339. passed &= !rc;
  340. passed &= (args.args_count == 3);
  341. passed &= (args.args[0] == 10);
  342. passed &= (args.args[1] == 11);
  343. passed &= (args.args[2] == 12);
  344. break;
  345. case 5:
  346. passed &= !rc;
  347. passed &= (args.args_count == 2);
  348. passed &= (args.args[0] == 13);
  349. passed &= (args.args[1] == 14);
  350. break;
  351. case 6:
  352. passed &= !rc;
  353. passed &= (args.args_count == 1);
  354. passed &= (args.args[0] == 15);
  355. break;
  356. default:
  357. passed = false;
  358. }
  359. selftest(passed, "index %i - data error on node %s rc=%i\n",
  360. i, args.np->full_name, rc);
  361. }
  362. of_node_put(np);
  363. }
  364. static struct of_device_id match_node_table[] = {
  365. { .data = "A", .name = "name0", }, /* Name alone is lowest priority */
  366. { .data = "B", .type = "type1", }, /* followed by type alone */
  367. { .data = "Ca", .name = "name2", .type = "type1", }, /* followed by both together */
  368. { .data = "Cb", .name = "name2", }, /* Only match when type doesn't match */
  369. { .data = "Cc", .name = "name2", .type = "type2", },
  370. { .data = "E", .compatible = "compat3" },
  371. { .data = "G", .compatible = "compat2", },
  372. { .data = "H", .compatible = "compat2", .name = "name5", },
  373. { .data = "I", .compatible = "compat2", .type = "type1", },
  374. { .data = "J", .compatible = "compat2", .type = "type1", .name = "name8", },
  375. { .data = "K", .compatible = "compat2", .name = "name9", },
  376. {}
  377. };
  378. static struct {
  379. const char *path;
  380. const char *data;
  381. } match_node_tests[] = {
  382. { .path = "/testcase-data/match-node/name0", .data = "A", },
  383. { .path = "/testcase-data/match-node/name1", .data = "B", },
  384. { .path = "/testcase-data/match-node/a/name2", .data = "Ca", },
  385. { .path = "/testcase-data/match-node/b/name2", .data = "Cb", },
  386. { .path = "/testcase-data/match-node/c/name2", .data = "Cc", },
  387. { .path = "/testcase-data/match-node/name3", .data = "E", },
  388. { .path = "/testcase-data/match-node/name4", .data = "G", },
  389. { .path = "/testcase-data/match-node/name5", .data = "H", },
  390. { .path = "/testcase-data/match-node/name6", .data = "G", },
  391. { .path = "/testcase-data/match-node/name7", .data = "I", },
  392. { .path = "/testcase-data/match-node/name8", .data = "J", },
  393. { .path = "/testcase-data/match-node/name9", .data = "K", },
  394. };
  395. static void __init of_selftest_match_node(void)
  396. {
  397. struct device_node *np;
  398. const struct of_device_id *match;
  399. int i;
  400. for (i = 0; i < ARRAY_SIZE(match_node_tests); i++) {
  401. np = of_find_node_by_path(match_node_tests[i].path);
  402. if (!np) {
  403. selftest(0, "missing testcase node %s\n",
  404. match_node_tests[i].path);
  405. continue;
  406. }
  407. match = of_match_node(match_node_table, np);
  408. if (!match) {
  409. selftest(0, "%s didn't match anything\n",
  410. match_node_tests[i].path);
  411. continue;
  412. }
  413. if (strcmp(match->data, match_node_tests[i].data) != 0) {
  414. selftest(0, "%s got wrong match. expected %s, got %s\n",
  415. match_node_tests[i].path, match_node_tests[i].data,
  416. (const char *)match->data);
  417. continue;
  418. }
  419. selftest(1, "passed");
  420. }
  421. }
  422. static void __init of_selftest_platform_populate(void)
  423. {
  424. int irq;
  425. struct device_node *np, *child;
  426. struct platform_device *pdev;
  427. struct of_device_id match[] = {
  428. { .compatible = "test-device", },
  429. {}
  430. };
  431. np = of_find_node_by_path("/testcase-data");
  432. of_platform_populate(np, of_default_bus_match_table, NULL, NULL);
  433. /* Test that a missing irq domain returns -EPROBE_DEFER */
  434. np = of_find_node_by_path("/testcase-data/testcase-device1");
  435. pdev = of_find_device_by_node(np);
  436. selftest(pdev, "device 1 creation failed\n");
  437. irq = platform_get_irq(pdev, 0);
  438. selftest(irq == -EPROBE_DEFER, "device deferred probe failed - %d\n", irq);
  439. /* Test that a parsing failure does not return -EPROBE_DEFER */
  440. np = of_find_node_by_path("/testcase-data/testcase-device2");
  441. pdev = of_find_device_by_node(np);
  442. selftest(pdev, "device 2 creation failed\n");
  443. irq = platform_get_irq(pdev, 0);
  444. selftest(irq < 0 && irq != -EPROBE_DEFER, "device parsing error failed - %d\n", irq);
  445. np = of_find_node_by_path("/testcase-data/platform-tests");
  446. if (!np) {
  447. pr_err("No testcase data in device tree\n");
  448. return;
  449. }
  450. for_each_child_of_node(np, child) {
  451. struct device_node *grandchild;
  452. of_platform_populate(child, match, NULL, NULL);
  453. for_each_child_of_node(child, grandchild)
  454. selftest(of_find_device_by_node(grandchild),
  455. "Could not create device for node '%s'\n",
  456. grandchild->name);
  457. }
  458. }
  459. /**
  460. * update_node_properties - adds the properties
  461. * of np into dup node (present in live tree) and
  462. * updates parent of children of np to dup.
  463. *
  464. * @np: node already present in live tree
  465. * @dup: node present in live tree to be updated
  466. */
  467. static void update_node_properties(struct device_node *np,
  468. struct device_node *dup)
  469. {
  470. struct property *prop;
  471. struct device_node *child;
  472. for_each_property_of_node(np, prop)
  473. of_add_property(dup, prop);
  474. for_each_child_of_node(np, child)
  475. child->parent = dup;
  476. }
  477. /**
  478. * attach_node_and_children - attaches nodes
  479. * and its children to live tree
  480. *
  481. * @np: Node to attach to live tree
  482. */
  483. static int attach_node_and_children(struct device_node *np)
  484. {
  485. struct device_node *next, *root = np, *dup;
  486. if (!np) {
  487. pr_warn("%s: No tree to attach; not running tests\n",
  488. __func__);
  489. return -ENODATA;
  490. }
  491. /* skip root node */
  492. np = np->child;
  493. /* storing a copy in temporary node */
  494. dup = np;
  495. while (dup) {
  496. nodes[last_node_index++] = dup;
  497. dup = dup->sibling;
  498. }
  499. dup = NULL;
  500. while (np) {
  501. next = np->allnext;
  502. dup = of_find_node_by_path(np->full_name);
  503. if (dup)
  504. update_node_properties(np, dup);
  505. else {
  506. np->child = NULL;
  507. if (np->parent == root)
  508. np->parent = of_allnodes;
  509. of_attach_node(np);
  510. }
  511. np = next;
  512. }
  513. return 0;
  514. }
  515. /**
  516. * selftest_data_add - Reads, copies data from
  517. * linked tree and attaches it to the live tree
  518. */
  519. static int __init selftest_data_add(void)
  520. {
  521. void *selftest_data;
  522. struct device_node *selftest_data_node;
  523. extern uint8_t __dtb_testcases_begin[];
  524. extern uint8_t __dtb_testcases_end[];
  525. const int size = __dtb_testcases_end - __dtb_testcases_begin;
  526. if (!size || !of_allnodes) {
  527. pr_warn("%s: No testcase data to attach; not running tests\n",
  528. __func__);
  529. return -ENODATA;
  530. }
  531. /* creating copy */
  532. selftest_data = kmemdup(__dtb_testcases_begin, size, GFP_KERNEL);
  533. if (!selftest_data) {
  534. pr_warn("%s: Failed to allocate memory for selftest_data; "
  535. "not running tests\n", __func__);
  536. return -ENOMEM;
  537. }
  538. of_fdt_unflatten_tree(selftest_data, &selftest_data_node);
  539. /* attach the sub-tree to live tree */
  540. return attach_node_and_children(selftest_data_node);
  541. }
  542. /**
  543. * detach_node_and_children - detaches node
  544. * and its children from live tree
  545. *
  546. * @np: Node to detach from live tree
  547. */
  548. static void detach_node_and_children(struct device_node *np)
  549. {
  550. while (np->child)
  551. detach_node_and_children(np->child);
  552. while (np->sibling)
  553. detach_node_and_children(np->sibling);
  554. of_detach_node(np);
  555. }
  556. /**
  557. * selftest_data_remove - removes the selftest data
  558. * nodes from the live tree
  559. */
  560. static void selftest_data_remove(void)
  561. {
  562. struct device_node *np;
  563. struct property *prop;
  564. while (last_node_index >= 0) {
  565. if (nodes[last_node_index]) {
  566. np = of_find_node_by_path(nodes[last_node_index]->full_name);
  567. if (strcmp(np->full_name, "/aliases") != 0) {
  568. detach_node_and_children(np->child);
  569. of_detach_node(np);
  570. } else {
  571. for_each_property_of_node(np, prop) {
  572. if (strcmp(prop->name, "testcase-alias") == 0)
  573. of_remove_property(np, prop);
  574. }
  575. }
  576. }
  577. last_node_index--;
  578. }
  579. }
  580. static int __init of_selftest(void)
  581. {
  582. struct device_node *np;
  583. int res;
  584. /* adding data for selftest */
  585. res = selftest_data_add();
  586. if (res)
  587. return res;
  588. np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
  589. if (!np) {
  590. pr_info("No testcase data in device tree; not running tests\n");
  591. return 0;
  592. }
  593. of_node_put(np);
  594. pr_info("start of selftest - you will see error messages\n");
  595. of_selftest_find_node_by_name();
  596. of_selftest_dynamic();
  597. of_selftest_parse_phandle_with_args();
  598. of_selftest_property_match_string();
  599. of_selftest_parse_interrupts();
  600. of_selftest_parse_interrupts_extended();
  601. of_selftest_match_node();
  602. of_selftest_platform_populate();
  603. pr_info("end of selftest - %i passed, %i failed\n",
  604. selftest_results.passed, selftest_results.failed);
  605. /* removing selftest data from live tree */
  606. selftest_data_remove();
  607. return 0;
  608. }
  609. late_initcall(of_selftest);