unittest.c 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Self tests for device tree subsystem
  4. */
  5. #define pr_fmt(fmt) "### dt-test ### " fmt
  6. #include <linux/bootmem.h>
  7. #include <linux/clk.h>
  8. #include <linux/err.h>
  9. #include <linux/errno.h>
  10. #include <linux/hashtable.h>
  11. #include <linux/libfdt.h>
  12. #include <linux/of.h>
  13. #include <linux/of_fdt.h>
  14. #include <linux/of_irq.h>
  15. #include <linux/of_platform.h>
  16. #include <linux/list.h>
  17. #include <linux/mutex.h>
  18. #include <linux/slab.h>
  19. #include <linux/device.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/i2c.h>
  22. #include <linux/i2c-mux.h>
  23. #include <linux/bitops.h>
  24. #include "of_private.h"
  25. static struct unittest_results {
  26. int passed;
  27. int failed;
  28. } unittest_results;
  29. #define unittest(result, fmt, ...) ({ \
  30. bool failed = !(result); \
  31. if (failed) { \
  32. unittest_results.failed++; \
  33. pr_err("FAIL %s():%i " fmt, __func__, __LINE__, ##__VA_ARGS__); \
  34. } else { \
  35. unittest_results.passed++; \
  36. pr_debug("pass %s():%i\n", __func__, __LINE__); \
  37. } \
  38. failed; \
  39. })
  40. static void __init of_unittest_find_node_by_name(void)
  41. {
  42. struct device_node *np;
  43. const char *options, *name;
  44. np = of_find_node_by_path("/testcase-data");
  45. name = kasprintf(GFP_KERNEL, "%pOF", np);
  46. unittest(np && !strcmp("/testcase-data", name),
  47. "find /testcase-data failed\n");
  48. of_node_put(np);
  49. kfree(name);
  50. /* Test if trailing '/' works */
  51. np = of_find_node_by_path("/testcase-data/");
  52. unittest(!np, "trailing '/' on /testcase-data/ should fail\n");
  53. np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
  54. name = kasprintf(GFP_KERNEL, "%pOF", np);
  55. unittest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", name),
  56. "find /testcase-data/phandle-tests/consumer-a failed\n");
  57. of_node_put(np);
  58. kfree(name);
  59. np = of_find_node_by_path("testcase-alias");
  60. name = kasprintf(GFP_KERNEL, "%pOF", np);
  61. unittest(np && !strcmp("/testcase-data", name),
  62. "find testcase-alias failed\n");
  63. of_node_put(np);
  64. kfree(name);
  65. /* Test if trailing '/' works on aliases */
  66. np = of_find_node_by_path("testcase-alias/");
  67. unittest(!np, "trailing '/' on testcase-alias/ should fail\n");
  68. np = of_find_node_by_path("testcase-alias/phandle-tests/consumer-a");
  69. name = kasprintf(GFP_KERNEL, "%pOF", np);
  70. unittest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", name),
  71. "find testcase-alias/phandle-tests/consumer-a failed\n");
  72. of_node_put(np);
  73. kfree(name);
  74. np = of_find_node_by_path("/testcase-data/missing-path");
  75. unittest(!np, "non-existent path returned node %pOF\n", np);
  76. of_node_put(np);
  77. np = of_find_node_by_path("missing-alias");
  78. unittest(!np, "non-existent alias returned node %pOF\n", np);
  79. of_node_put(np);
  80. np = of_find_node_by_path("testcase-alias/missing-path");
  81. unittest(!np, "non-existent alias with relative path returned node %pOF\n", np);
  82. of_node_put(np);
  83. np = of_find_node_opts_by_path("/testcase-data:testoption", &options);
  84. unittest(np && !strcmp("testoption", options),
  85. "option path test failed\n");
  86. of_node_put(np);
  87. np = of_find_node_opts_by_path("/testcase-data:test/option", &options);
  88. unittest(np && !strcmp("test/option", options),
  89. "option path test, subcase #1 failed\n");
  90. of_node_put(np);
  91. np = of_find_node_opts_by_path("/testcase-data/testcase-device1:test/option", &options);
  92. unittest(np && !strcmp("test/option", options),
  93. "option path test, subcase #2 failed\n");
  94. of_node_put(np);
  95. np = of_find_node_opts_by_path("/testcase-data:testoption", NULL);
  96. unittest(np, "NULL option path test failed\n");
  97. of_node_put(np);
  98. np = of_find_node_opts_by_path("testcase-alias:testaliasoption",
  99. &options);
  100. unittest(np && !strcmp("testaliasoption", options),
  101. "option alias path test failed\n");
  102. of_node_put(np);
  103. np = of_find_node_opts_by_path("testcase-alias:test/alias/option",
  104. &options);
  105. unittest(np && !strcmp("test/alias/option", options),
  106. "option alias path test, subcase #1 failed\n");
  107. of_node_put(np);
  108. np = of_find_node_opts_by_path("testcase-alias:testaliasoption", NULL);
  109. unittest(np, "NULL option alias path test failed\n");
  110. of_node_put(np);
  111. options = "testoption";
  112. np = of_find_node_opts_by_path("testcase-alias", &options);
  113. unittest(np && !options, "option clearing test failed\n");
  114. of_node_put(np);
  115. options = "testoption";
  116. np = of_find_node_opts_by_path("/", &options);
  117. unittest(np && !options, "option clearing root node test failed\n");
  118. of_node_put(np);
  119. }
  120. static void __init of_unittest_dynamic(void)
  121. {
  122. struct device_node *np;
  123. struct property *prop;
  124. np = of_find_node_by_path("/testcase-data");
  125. if (!np) {
  126. pr_err("missing testcase data\n");
  127. return;
  128. }
  129. /* Array of 4 properties for the purpose of testing */
  130. prop = kzalloc(sizeof(*prop) * 4, GFP_KERNEL);
  131. if (!prop) {
  132. unittest(0, "kzalloc() failed\n");
  133. return;
  134. }
  135. /* Add a new property - should pass*/
  136. prop->name = "new-property";
  137. prop->value = "new-property-data";
  138. prop->length = strlen(prop->value);
  139. unittest(of_add_property(np, prop) == 0, "Adding a new property failed\n");
  140. /* Try to add an existing property - should fail */
  141. prop++;
  142. prop->name = "new-property";
  143. prop->value = "new-property-data-should-fail";
  144. prop->length = strlen(prop->value);
  145. unittest(of_add_property(np, prop) != 0,
  146. "Adding an existing property should have failed\n");
  147. /* Try to modify an existing property - should pass */
  148. prop->value = "modify-property-data-should-pass";
  149. prop->length = strlen(prop->value);
  150. unittest(of_update_property(np, prop) == 0,
  151. "Updating an existing property should have passed\n");
  152. /* Try to modify non-existent property - should pass*/
  153. prop++;
  154. prop->name = "modify-property";
  155. prop->value = "modify-missing-property-data-should-pass";
  156. prop->length = strlen(prop->value);
  157. unittest(of_update_property(np, prop) == 0,
  158. "Updating a missing property should have passed\n");
  159. /* Remove property - should pass */
  160. unittest(of_remove_property(np, prop) == 0,
  161. "Removing a property should have passed\n");
  162. /* Adding very large property - should pass */
  163. prop++;
  164. prop->name = "large-property-PAGE_SIZEx8";
  165. prop->length = PAGE_SIZE * 8;
  166. prop->value = kzalloc(prop->length, GFP_KERNEL);
  167. unittest(prop->value != NULL, "Unable to allocate large buffer\n");
  168. if (prop->value)
  169. unittest(of_add_property(np, prop) == 0,
  170. "Adding a large property should have passed\n");
  171. }
  172. static int __init of_unittest_check_node_linkage(struct device_node *np)
  173. {
  174. struct device_node *child;
  175. int count = 0, rc;
  176. for_each_child_of_node(np, child) {
  177. if (child->parent != np) {
  178. pr_err("Child node %s links to wrong parent %s\n",
  179. child->name, np->name);
  180. rc = -EINVAL;
  181. goto put_child;
  182. }
  183. rc = of_unittest_check_node_linkage(child);
  184. if (rc < 0)
  185. goto put_child;
  186. count += rc;
  187. }
  188. return count + 1;
  189. put_child:
  190. of_node_put(child);
  191. return rc;
  192. }
  193. static void __init of_unittest_check_tree_linkage(void)
  194. {
  195. struct device_node *np;
  196. int allnode_count = 0, child_count;
  197. if (!of_root)
  198. return;
  199. for_each_of_allnodes(np)
  200. allnode_count++;
  201. child_count = of_unittest_check_node_linkage(of_root);
  202. unittest(child_count > 0, "Device node data structure is corrupted\n");
  203. unittest(child_count == allnode_count,
  204. "allnodes list size (%i) doesn't match sibling lists size (%i)\n",
  205. allnode_count, child_count);
  206. pr_debug("allnodes list size (%i); sibling lists size (%i)\n", allnode_count, child_count);
  207. }
  208. static void __init of_unittest_printf_one(struct device_node *np, const char *fmt,
  209. const char *expected)
  210. {
  211. unsigned char *buf;
  212. int buf_size;
  213. int size, i;
  214. buf_size = strlen(expected) + 10;
  215. buf = kmalloc(buf_size, GFP_KERNEL);
  216. if (!buf)
  217. return;
  218. /* Baseline; check conversion with a large size limit */
  219. memset(buf, 0xff, buf_size);
  220. size = snprintf(buf, buf_size - 2, fmt, np);
  221. /* use strcmp() instead of strncmp() here to be absolutely sure strings match */
  222. unittest((strcmp(buf, expected) == 0) && (buf[size+1] == 0xff),
  223. "sprintf failed; fmt='%s' expected='%s' rslt='%s'\n",
  224. fmt, expected, buf);
  225. /* Make sure length limits work */
  226. size++;
  227. for (i = 0; i < 2; i++, size--) {
  228. /* Clear the buffer, and make sure it works correctly still */
  229. memset(buf, 0xff, buf_size);
  230. snprintf(buf, size+1, fmt, np);
  231. unittest(strncmp(buf, expected, size) == 0 && (buf[size+1] == 0xff),
  232. "snprintf failed; size=%i fmt='%s' expected='%s' rslt='%s'\n",
  233. size, fmt, expected, buf);
  234. }
  235. kfree(buf);
  236. }
  237. static void __init of_unittest_printf(void)
  238. {
  239. struct device_node *np;
  240. const char *full_name = "/testcase-data/platform-tests/test-device@1/dev@100";
  241. char phandle_str[16] = "";
  242. np = of_find_node_by_path(full_name);
  243. if (!np) {
  244. unittest(np, "testcase data missing\n");
  245. return;
  246. }
  247. num_to_str(phandle_str, sizeof(phandle_str), np->phandle);
  248. of_unittest_printf_one(np, "%pOF", full_name);
  249. of_unittest_printf_one(np, "%pOFf", full_name);
  250. of_unittest_printf_one(np, "%pOFp", phandle_str);
  251. of_unittest_printf_one(np, "%pOFP", "dev@100");
  252. of_unittest_printf_one(np, "ABC %pOFP ABC", "ABC dev@100 ABC");
  253. of_unittest_printf_one(np, "%10pOFP", " dev@100");
  254. of_unittest_printf_one(np, "%-10pOFP", "dev@100 ");
  255. of_unittest_printf_one(of_root, "%pOFP", "/");
  256. of_unittest_printf_one(np, "%pOFF", "----");
  257. of_unittest_printf_one(np, "%pOFPF", "dev@100:----");
  258. of_unittest_printf_one(np, "%pOFPFPc", "dev@100:----:dev@100:test-sub-device");
  259. of_unittest_printf_one(np, "%pOFc", "test-sub-device");
  260. of_unittest_printf_one(np, "%pOFC",
  261. "\"test-sub-device\",\"test-compat2\",\"test-compat3\"");
  262. }
  263. struct node_hash {
  264. struct hlist_node node;
  265. struct device_node *np;
  266. };
  267. static DEFINE_HASHTABLE(phandle_ht, 8);
  268. static void __init of_unittest_check_phandles(void)
  269. {
  270. struct device_node *np;
  271. struct node_hash *nh;
  272. struct hlist_node *tmp;
  273. int i, dup_count = 0, phandle_count = 0;
  274. for_each_of_allnodes(np) {
  275. if (!np->phandle)
  276. continue;
  277. hash_for_each_possible(phandle_ht, nh, node, np->phandle) {
  278. if (nh->np->phandle == np->phandle) {
  279. pr_info("Duplicate phandle! %i used by %pOF and %pOF\n",
  280. np->phandle, nh->np, np);
  281. dup_count++;
  282. break;
  283. }
  284. }
  285. nh = kzalloc(sizeof(*nh), GFP_KERNEL);
  286. if (WARN_ON(!nh))
  287. return;
  288. nh->np = np;
  289. hash_add(phandle_ht, &nh->node, np->phandle);
  290. phandle_count++;
  291. }
  292. unittest(dup_count == 0, "Found %i duplicates in %i phandles\n",
  293. dup_count, phandle_count);
  294. /* Clean up */
  295. hash_for_each_safe(phandle_ht, i, tmp, nh, node) {
  296. hash_del(&nh->node);
  297. kfree(nh);
  298. }
  299. }
  300. static void __init of_unittest_parse_phandle_with_args(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/phandle-tests/consumer-a");
  306. if (!np) {
  307. pr_err("missing testcase data\n");
  308. return;
  309. }
  310. rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells");
  311. unittest(rc == 7, "of_count_phandle_with_args() returned %i, expected 7\n", rc);
  312. for (i = 0; i < 8; i++) {
  313. bool passed = true;
  314. rc = of_parse_phandle_with_args(np, "phandle-list",
  315. "#phandle-cells", i, &args);
  316. /* Test the values from tests-phandle.dtsi */
  317. switch (i) {
  318. case 0:
  319. passed &= !rc;
  320. passed &= (args.args_count == 1);
  321. passed &= (args.args[0] == (i + 1));
  322. break;
  323. case 1:
  324. passed &= !rc;
  325. passed &= (args.args_count == 2);
  326. passed &= (args.args[0] == (i + 1));
  327. passed &= (args.args[1] == 0);
  328. break;
  329. case 2:
  330. passed &= (rc == -ENOENT);
  331. break;
  332. case 3:
  333. passed &= !rc;
  334. passed &= (args.args_count == 3);
  335. passed &= (args.args[0] == (i + 1));
  336. passed &= (args.args[1] == 4);
  337. passed &= (args.args[2] == 3);
  338. break;
  339. case 4:
  340. passed &= !rc;
  341. passed &= (args.args_count == 2);
  342. passed &= (args.args[0] == (i + 1));
  343. passed &= (args.args[1] == 100);
  344. break;
  345. case 5:
  346. passed &= !rc;
  347. passed &= (args.args_count == 0);
  348. break;
  349. case 6:
  350. passed &= !rc;
  351. passed &= (args.args_count == 1);
  352. passed &= (args.args[0] == (i + 1));
  353. break;
  354. case 7:
  355. passed &= (rc == -ENOENT);
  356. break;
  357. default:
  358. passed = false;
  359. }
  360. unittest(passed, "index %i - data error on node %pOF rc=%i\n",
  361. i, args.np, rc);
  362. }
  363. /* Check for missing list property */
  364. rc = of_parse_phandle_with_args(np, "phandle-list-missing",
  365. "#phandle-cells", 0, &args);
  366. unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
  367. rc = of_count_phandle_with_args(np, "phandle-list-missing",
  368. "#phandle-cells");
  369. unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
  370. /* Check for missing cells property */
  371. rc = of_parse_phandle_with_args(np, "phandle-list",
  372. "#phandle-cells-missing", 0, &args);
  373. unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  374. rc = of_count_phandle_with_args(np, "phandle-list",
  375. "#phandle-cells-missing");
  376. unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  377. /* Check for bad phandle in list */
  378. rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle",
  379. "#phandle-cells", 0, &args);
  380. unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  381. rc = of_count_phandle_with_args(np, "phandle-list-bad-phandle",
  382. "#phandle-cells");
  383. unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  384. /* Check for incorrectly formed argument list */
  385. rc = of_parse_phandle_with_args(np, "phandle-list-bad-args",
  386. "#phandle-cells", 1, &args);
  387. unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  388. rc = of_count_phandle_with_args(np, "phandle-list-bad-args",
  389. "#phandle-cells");
  390. unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  391. }
  392. static void __init of_unittest_parse_phandle_with_args_map(void)
  393. {
  394. struct device_node *np, *p0, *p1, *p2, *p3;
  395. struct of_phandle_args args;
  396. int i, rc;
  397. np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-b");
  398. if (!np) {
  399. pr_err("missing testcase data\n");
  400. return;
  401. }
  402. p0 = of_find_node_by_path("/testcase-data/phandle-tests/provider0");
  403. if (!p0) {
  404. pr_err("missing testcase data\n");
  405. return;
  406. }
  407. p1 = of_find_node_by_path("/testcase-data/phandle-tests/provider1");
  408. if (!p1) {
  409. pr_err("missing testcase data\n");
  410. return;
  411. }
  412. p2 = of_find_node_by_path("/testcase-data/phandle-tests/provider2");
  413. if (!p2) {
  414. pr_err("missing testcase data\n");
  415. return;
  416. }
  417. p3 = of_find_node_by_path("/testcase-data/phandle-tests/provider3");
  418. if (!p3) {
  419. pr_err("missing testcase data\n");
  420. return;
  421. }
  422. rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells");
  423. unittest(rc == 7, "of_count_phandle_with_args() returned %i, expected 7\n", rc);
  424. for (i = 0; i < 8; i++) {
  425. bool passed = true;
  426. rc = of_parse_phandle_with_args_map(np, "phandle-list",
  427. "phandle", i, &args);
  428. /* Test the values from tests-phandle.dtsi */
  429. switch (i) {
  430. case 0:
  431. passed &= !rc;
  432. passed &= (args.np == p1);
  433. passed &= (args.args_count == 1);
  434. passed &= (args.args[0] == 1);
  435. break;
  436. case 1:
  437. passed &= !rc;
  438. passed &= (args.np == p3);
  439. passed &= (args.args_count == 3);
  440. passed &= (args.args[0] == 2);
  441. passed &= (args.args[1] == 5);
  442. passed &= (args.args[2] == 3);
  443. break;
  444. case 2:
  445. passed &= (rc == -ENOENT);
  446. break;
  447. case 3:
  448. passed &= !rc;
  449. passed &= (args.np == p0);
  450. passed &= (args.args_count == 0);
  451. break;
  452. case 4:
  453. passed &= !rc;
  454. passed &= (args.np == p1);
  455. passed &= (args.args_count == 1);
  456. passed &= (args.args[0] == 3);
  457. break;
  458. case 5:
  459. passed &= !rc;
  460. passed &= (args.np == p0);
  461. passed &= (args.args_count == 0);
  462. break;
  463. case 6:
  464. passed &= !rc;
  465. passed &= (args.np == p2);
  466. passed &= (args.args_count == 2);
  467. passed &= (args.args[0] == 15);
  468. passed &= (args.args[1] == 0x20);
  469. break;
  470. case 7:
  471. passed &= (rc == -ENOENT);
  472. break;
  473. default:
  474. passed = false;
  475. }
  476. unittest(passed, "index %i - data error on node %s rc=%i\n",
  477. i, args.np->full_name, rc);
  478. }
  479. /* Check for missing list property */
  480. rc = of_parse_phandle_with_args_map(np, "phandle-list-missing",
  481. "phandle", 0, &args);
  482. unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
  483. /* Check for missing cells,map,mask property */
  484. rc = of_parse_phandle_with_args_map(np, "phandle-list",
  485. "phandle-missing", 0, &args);
  486. unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  487. /* Check for bad phandle in list */
  488. rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-phandle",
  489. "phandle", 0, &args);
  490. unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  491. /* Check for incorrectly formed argument list */
  492. rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-args",
  493. "phandle", 1, &args);
  494. unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  495. }
  496. static void __init of_unittest_property_string(void)
  497. {
  498. const char *strings[4];
  499. struct device_node *np;
  500. int rc;
  501. np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
  502. if (!np) {
  503. pr_err("No testcase data in device tree\n");
  504. return;
  505. }
  506. rc = of_property_match_string(np, "phandle-list-names", "first");
  507. unittest(rc == 0, "first expected:0 got:%i\n", rc);
  508. rc = of_property_match_string(np, "phandle-list-names", "second");
  509. unittest(rc == 1, "second expected:1 got:%i\n", rc);
  510. rc = of_property_match_string(np, "phandle-list-names", "third");
  511. unittest(rc == 2, "third expected:2 got:%i\n", rc);
  512. rc = of_property_match_string(np, "phandle-list-names", "fourth");
  513. unittest(rc == -ENODATA, "unmatched string; rc=%i\n", rc);
  514. rc = of_property_match_string(np, "missing-property", "blah");
  515. unittest(rc == -EINVAL, "missing property; rc=%i\n", rc);
  516. rc = of_property_match_string(np, "empty-property", "blah");
  517. unittest(rc == -ENODATA, "empty property; rc=%i\n", rc);
  518. rc = of_property_match_string(np, "unterminated-string", "blah");
  519. unittest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
  520. /* of_property_count_strings() tests */
  521. rc = of_property_count_strings(np, "string-property");
  522. unittest(rc == 1, "Incorrect string count; rc=%i\n", rc);
  523. rc = of_property_count_strings(np, "phandle-list-names");
  524. unittest(rc == 3, "Incorrect string count; rc=%i\n", rc);
  525. rc = of_property_count_strings(np, "unterminated-string");
  526. unittest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
  527. rc = of_property_count_strings(np, "unterminated-string-list");
  528. unittest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc);
  529. /* of_property_read_string_index() tests */
  530. rc = of_property_read_string_index(np, "string-property", 0, strings);
  531. unittest(rc == 0 && !strcmp(strings[0], "foobar"), "of_property_read_string_index() failure; rc=%i\n", rc);
  532. strings[0] = NULL;
  533. rc = of_property_read_string_index(np, "string-property", 1, strings);
  534. unittest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
  535. rc = of_property_read_string_index(np, "phandle-list-names", 0, strings);
  536. unittest(rc == 0 && !strcmp(strings[0], "first"), "of_property_read_string_index() failure; rc=%i\n", rc);
  537. rc = of_property_read_string_index(np, "phandle-list-names", 1, strings);
  538. unittest(rc == 0 && !strcmp(strings[0], "second"), "of_property_read_string_index() failure; rc=%i\n", rc);
  539. rc = of_property_read_string_index(np, "phandle-list-names", 2, strings);
  540. unittest(rc == 0 && !strcmp(strings[0], "third"), "of_property_read_string_index() failure; rc=%i\n", rc);
  541. strings[0] = NULL;
  542. rc = of_property_read_string_index(np, "phandle-list-names", 3, strings);
  543. unittest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
  544. strings[0] = NULL;
  545. rc = of_property_read_string_index(np, "unterminated-string", 0, strings);
  546. unittest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
  547. rc = of_property_read_string_index(np, "unterminated-string-list", 0, strings);
  548. unittest(rc == 0 && !strcmp(strings[0], "first"), "of_property_read_string_index() failure; rc=%i\n", rc);
  549. strings[0] = NULL;
  550. rc = of_property_read_string_index(np, "unterminated-string-list", 2, strings); /* should fail */
  551. unittest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
  552. strings[1] = NULL;
  553. /* of_property_read_string_array() tests */
  554. rc = of_property_read_string_array(np, "string-property", strings, 4);
  555. unittest(rc == 1, "Incorrect string count; rc=%i\n", rc);
  556. rc = of_property_read_string_array(np, "phandle-list-names", strings, 4);
  557. unittest(rc == 3, "Incorrect string count; rc=%i\n", rc);
  558. rc = of_property_read_string_array(np, "unterminated-string", strings, 4);
  559. unittest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
  560. /* -- An incorrectly formed string should cause a failure */
  561. rc = of_property_read_string_array(np, "unterminated-string-list", strings, 4);
  562. unittest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc);
  563. /* -- parsing the correctly formed strings should still work: */
  564. strings[2] = NULL;
  565. rc = of_property_read_string_array(np, "unterminated-string-list", strings, 2);
  566. unittest(rc == 2 && strings[2] == NULL, "of_property_read_string_array() failure; rc=%i\n", rc);
  567. strings[1] = NULL;
  568. rc = of_property_read_string_array(np, "phandle-list-names", strings, 1);
  569. unittest(rc == 1 && strings[1] == NULL, "Overwrote end of string array; rc=%i, str='%s'\n", rc, strings[1]);
  570. }
  571. #define propcmp(p1, p2) (((p1)->length == (p2)->length) && \
  572. (p1)->value && (p2)->value && \
  573. !memcmp((p1)->value, (p2)->value, (p1)->length) && \
  574. !strcmp((p1)->name, (p2)->name))
  575. static void __init of_unittest_property_copy(void)
  576. {
  577. #ifdef CONFIG_OF_DYNAMIC
  578. struct property p1 = { .name = "p1", .length = 0, .value = "" };
  579. struct property p2 = { .name = "p2", .length = 5, .value = "abcd" };
  580. struct property *new;
  581. new = __of_prop_dup(&p1, GFP_KERNEL);
  582. unittest(new && propcmp(&p1, new), "empty property didn't copy correctly\n");
  583. kfree(new->value);
  584. kfree(new->name);
  585. kfree(new);
  586. new = __of_prop_dup(&p2, GFP_KERNEL);
  587. unittest(new && propcmp(&p2, new), "non-empty property didn't copy correctly\n");
  588. kfree(new->value);
  589. kfree(new->name);
  590. kfree(new);
  591. #endif
  592. }
  593. static void __init of_unittest_changeset(void)
  594. {
  595. #ifdef CONFIG_OF_DYNAMIC
  596. struct property *ppadd, padd = { .name = "prop-add", .length = 1, .value = "" };
  597. struct property *ppname_n1, pname_n1 = { .name = "name", .length = 3, .value = "n1" };
  598. struct property *ppname_n2, pname_n2 = { .name = "name", .length = 3, .value = "n2" };
  599. struct property *ppname_n21, pname_n21 = { .name = "name", .length = 3, .value = "n21" };
  600. struct property *ppupdate, pupdate = { .name = "prop-update", .length = 5, .value = "abcd" };
  601. struct property *ppremove;
  602. struct device_node *n1, *n2, *n21, *nchangeset, *nremove, *parent, *np;
  603. struct of_changeset chgset;
  604. n1 = __of_node_dup(NULL, "n1");
  605. unittest(n1, "testcase setup failure\n");
  606. n2 = __of_node_dup(NULL, "n2");
  607. unittest(n2, "testcase setup failure\n");
  608. n21 = __of_node_dup(NULL, "n21");
  609. unittest(n21, "testcase setup failure %p\n", n21);
  610. nchangeset = of_find_node_by_path("/testcase-data/changeset");
  611. nremove = of_get_child_by_name(nchangeset, "node-remove");
  612. unittest(nremove, "testcase setup failure\n");
  613. ppadd = __of_prop_dup(&padd, GFP_KERNEL);
  614. unittest(ppadd, "testcase setup failure\n");
  615. ppname_n1 = __of_prop_dup(&pname_n1, GFP_KERNEL);
  616. unittest(ppname_n1, "testcase setup failure\n");
  617. ppname_n2 = __of_prop_dup(&pname_n2, GFP_KERNEL);
  618. unittest(ppname_n2, "testcase setup failure\n");
  619. ppname_n21 = __of_prop_dup(&pname_n21, GFP_KERNEL);
  620. unittest(ppname_n21, "testcase setup failure\n");
  621. ppupdate = __of_prop_dup(&pupdate, GFP_KERNEL);
  622. unittest(ppupdate, "testcase setup failure\n");
  623. parent = nchangeset;
  624. n1->parent = parent;
  625. n2->parent = parent;
  626. n21->parent = n2;
  627. ppremove = of_find_property(parent, "prop-remove", NULL);
  628. unittest(ppremove, "failed to find removal prop");
  629. of_changeset_init(&chgset);
  630. unittest(!of_changeset_attach_node(&chgset, n1), "fail attach n1\n");
  631. unittest(!of_changeset_add_property(&chgset, n1, ppname_n1), "fail add prop name\n");
  632. unittest(!of_changeset_attach_node(&chgset, n2), "fail attach n2\n");
  633. unittest(!of_changeset_add_property(&chgset, n2, ppname_n2), "fail add prop name\n");
  634. unittest(!of_changeset_detach_node(&chgset, nremove), "fail remove node\n");
  635. unittest(!of_changeset_add_property(&chgset, n21, ppname_n21), "fail add prop name\n");
  636. unittest(!of_changeset_attach_node(&chgset, n21), "fail attach n21\n");
  637. unittest(!of_changeset_add_property(&chgset, parent, ppadd), "fail add prop prop-add\n");
  638. unittest(!of_changeset_update_property(&chgset, parent, ppupdate), "fail update prop\n");
  639. unittest(!of_changeset_remove_property(&chgset, parent, ppremove), "fail remove prop\n");
  640. unittest(!of_changeset_apply(&chgset), "apply failed\n");
  641. of_node_put(nchangeset);
  642. /* Make sure node names are constructed correctly */
  643. unittest((np = of_find_node_by_path("/testcase-data/changeset/n2/n21")),
  644. "'%pOF' not added\n", n21);
  645. of_node_put(np);
  646. unittest(!of_changeset_revert(&chgset), "revert failed\n");
  647. of_changeset_destroy(&chgset);
  648. #endif
  649. }
  650. static void __init of_unittest_parse_interrupts(void)
  651. {
  652. struct device_node *np;
  653. struct of_phandle_args args;
  654. int i, rc;
  655. np = of_find_node_by_path("/testcase-data/interrupts/interrupts0");
  656. if (!np) {
  657. pr_err("missing testcase data\n");
  658. return;
  659. }
  660. for (i = 0; i < 4; i++) {
  661. bool passed = true;
  662. args.args_count = 0;
  663. rc = of_irq_parse_one(np, i, &args);
  664. passed &= !rc;
  665. passed &= (args.args_count == 1);
  666. passed &= (args.args[0] == (i + 1));
  667. unittest(passed, "index %i - data error on node %pOF rc=%i\n",
  668. i, args.np, rc);
  669. }
  670. of_node_put(np);
  671. np = of_find_node_by_path("/testcase-data/interrupts/interrupts1");
  672. if (!np) {
  673. pr_err("missing testcase data\n");
  674. return;
  675. }
  676. for (i = 0; i < 4; i++) {
  677. bool passed = true;
  678. args.args_count = 0;
  679. rc = of_irq_parse_one(np, i, &args);
  680. /* Test the values from tests-phandle.dtsi */
  681. switch (i) {
  682. case 0:
  683. passed &= !rc;
  684. passed &= (args.args_count == 1);
  685. passed &= (args.args[0] == 9);
  686. break;
  687. case 1:
  688. passed &= !rc;
  689. passed &= (args.args_count == 3);
  690. passed &= (args.args[0] == 10);
  691. passed &= (args.args[1] == 11);
  692. passed &= (args.args[2] == 12);
  693. break;
  694. case 2:
  695. passed &= !rc;
  696. passed &= (args.args_count == 2);
  697. passed &= (args.args[0] == 13);
  698. passed &= (args.args[1] == 14);
  699. break;
  700. case 3:
  701. passed &= !rc;
  702. passed &= (args.args_count == 2);
  703. passed &= (args.args[0] == 15);
  704. passed &= (args.args[1] == 16);
  705. break;
  706. default:
  707. passed = false;
  708. }
  709. unittest(passed, "index %i - data error on node %pOF rc=%i\n",
  710. i, args.np, rc);
  711. }
  712. of_node_put(np);
  713. }
  714. static void __init of_unittest_parse_interrupts_extended(void)
  715. {
  716. struct device_node *np;
  717. struct of_phandle_args args;
  718. int i, rc;
  719. np = of_find_node_by_path("/testcase-data/interrupts/interrupts-extended0");
  720. if (!np) {
  721. pr_err("missing testcase data\n");
  722. return;
  723. }
  724. for (i = 0; i < 7; i++) {
  725. bool passed = true;
  726. rc = of_irq_parse_one(np, i, &args);
  727. /* Test the values from tests-phandle.dtsi */
  728. switch (i) {
  729. case 0:
  730. passed &= !rc;
  731. passed &= (args.args_count == 1);
  732. passed &= (args.args[0] == 1);
  733. break;
  734. case 1:
  735. passed &= !rc;
  736. passed &= (args.args_count == 3);
  737. passed &= (args.args[0] == 2);
  738. passed &= (args.args[1] == 3);
  739. passed &= (args.args[2] == 4);
  740. break;
  741. case 2:
  742. passed &= !rc;
  743. passed &= (args.args_count == 2);
  744. passed &= (args.args[0] == 5);
  745. passed &= (args.args[1] == 6);
  746. break;
  747. case 3:
  748. passed &= !rc;
  749. passed &= (args.args_count == 1);
  750. passed &= (args.args[0] == 9);
  751. break;
  752. case 4:
  753. passed &= !rc;
  754. passed &= (args.args_count == 3);
  755. passed &= (args.args[0] == 10);
  756. passed &= (args.args[1] == 11);
  757. passed &= (args.args[2] == 12);
  758. break;
  759. case 5:
  760. passed &= !rc;
  761. passed &= (args.args_count == 2);
  762. passed &= (args.args[0] == 13);
  763. passed &= (args.args[1] == 14);
  764. break;
  765. case 6:
  766. passed &= !rc;
  767. passed &= (args.args_count == 1);
  768. passed &= (args.args[0] == 15);
  769. break;
  770. default:
  771. passed = false;
  772. }
  773. unittest(passed, "index %i - data error on node %pOF rc=%i\n",
  774. i, args.np, rc);
  775. }
  776. of_node_put(np);
  777. }
  778. static const struct of_device_id match_node_table[] = {
  779. { .data = "A", .name = "name0", }, /* Name alone is lowest priority */
  780. { .data = "B", .type = "type1", }, /* followed by type alone */
  781. { .data = "Ca", .name = "name2", .type = "type1", }, /* followed by both together */
  782. { .data = "Cb", .name = "name2", }, /* Only match when type doesn't match */
  783. { .data = "Cc", .name = "name2", .type = "type2", },
  784. { .data = "E", .compatible = "compat3" },
  785. { .data = "G", .compatible = "compat2", },
  786. { .data = "H", .compatible = "compat2", .name = "name5", },
  787. { .data = "I", .compatible = "compat2", .type = "type1", },
  788. { .data = "J", .compatible = "compat2", .type = "type1", .name = "name8", },
  789. { .data = "K", .compatible = "compat2", .name = "name9", },
  790. {}
  791. };
  792. static struct {
  793. const char *path;
  794. const char *data;
  795. } match_node_tests[] = {
  796. { .path = "/testcase-data/match-node/name0", .data = "A", },
  797. { .path = "/testcase-data/match-node/name1", .data = "B", },
  798. { .path = "/testcase-data/match-node/a/name2", .data = "Ca", },
  799. { .path = "/testcase-data/match-node/b/name2", .data = "Cb", },
  800. { .path = "/testcase-data/match-node/c/name2", .data = "Cc", },
  801. { .path = "/testcase-data/match-node/name3", .data = "E", },
  802. { .path = "/testcase-data/match-node/name4", .data = "G", },
  803. { .path = "/testcase-data/match-node/name5", .data = "H", },
  804. { .path = "/testcase-data/match-node/name6", .data = "G", },
  805. { .path = "/testcase-data/match-node/name7", .data = "I", },
  806. { .path = "/testcase-data/match-node/name8", .data = "J", },
  807. { .path = "/testcase-data/match-node/name9", .data = "K", },
  808. };
  809. static void __init of_unittest_match_node(void)
  810. {
  811. struct device_node *np;
  812. const struct of_device_id *match;
  813. int i;
  814. for (i = 0; i < ARRAY_SIZE(match_node_tests); i++) {
  815. np = of_find_node_by_path(match_node_tests[i].path);
  816. if (!np) {
  817. unittest(0, "missing testcase node %s\n",
  818. match_node_tests[i].path);
  819. continue;
  820. }
  821. match = of_match_node(match_node_table, np);
  822. if (!match) {
  823. unittest(0, "%s didn't match anything\n",
  824. match_node_tests[i].path);
  825. continue;
  826. }
  827. if (strcmp(match->data, match_node_tests[i].data) != 0) {
  828. unittest(0, "%s got wrong match. expected %s, got %s\n",
  829. match_node_tests[i].path, match_node_tests[i].data,
  830. (const char *)match->data);
  831. continue;
  832. }
  833. unittest(1, "passed");
  834. }
  835. }
  836. static struct resource test_bus_res = {
  837. .start = 0xfffffff8,
  838. .end = 0xfffffff9,
  839. .flags = IORESOURCE_MEM,
  840. };
  841. static const struct platform_device_info test_bus_info = {
  842. .name = "unittest-bus",
  843. };
  844. static void __init of_unittest_platform_populate(void)
  845. {
  846. int irq, rc;
  847. struct device_node *np, *child, *grandchild;
  848. struct platform_device *pdev, *test_bus;
  849. const struct of_device_id match[] = {
  850. { .compatible = "test-device", },
  851. {}
  852. };
  853. np = of_find_node_by_path("/testcase-data");
  854. of_platform_default_populate(np, NULL, NULL);
  855. /* Test that a missing irq domain returns -EPROBE_DEFER */
  856. np = of_find_node_by_path("/testcase-data/testcase-device1");
  857. pdev = of_find_device_by_node(np);
  858. unittest(pdev, "device 1 creation failed\n");
  859. irq = platform_get_irq(pdev, 0);
  860. unittest(irq == -EPROBE_DEFER, "device deferred probe failed - %d\n", irq);
  861. /* Test that a parsing failure does not return -EPROBE_DEFER */
  862. np = of_find_node_by_path("/testcase-data/testcase-device2");
  863. pdev = of_find_device_by_node(np);
  864. unittest(pdev, "device 2 creation failed\n");
  865. irq = platform_get_irq(pdev, 0);
  866. unittest(irq < 0 && irq != -EPROBE_DEFER, "device parsing error failed - %d\n", irq);
  867. np = of_find_node_by_path("/testcase-data/platform-tests");
  868. unittest(np, "No testcase data in device tree\n");
  869. if (!np)
  870. return;
  871. test_bus = platform_device_register_full(&test_bus_info);
  872. rc = PTR_ERR_OR_ZERO(test_bus);
  873. unittest(!rc, "testbus registration failed; rc=%i\n", rc);
  874. if (rc)
  875. return;
  876. test_bus->dev.of_node = np;
  877. /*
  878. * Add a dummy resource to the test bus node after it is
  879. * registered to catch problems with un-inserted resources. The
  880. * DT code doesn't insert the resources, and it has caused the
  881. * kernel to oops in the past. This makes sure the same bug
  882. * doesn't crop up again.
  883. */
  884. platform_device_add_resources(test_bus, &test_bus_res, 1);
  885. of_platform_populate(np, match, NULL, &test_bus->dev);
  886. for_each_child_of_node(np, child) {
  887. for_each_child_of_node(child, grandchild)
  888. unittest(of_find_device_by_node(grandchild),
  889. "Could not create device for node '%s'\n",
  890. grandchild->name);
  891. }
  892. of_platform_depopulate(&test_bus->dev);
  893. for_each_child_of_node(np, child) {
  894. for_each_child_of_node(child, grandchild)
  895. unittest(!of_find_device_by_node(grandchild),
  896. "device didn't get destroyed '%s'\n",
  897. grandchild->name);
  898. }
  899. platform_device_unregister(test_bus);
  900. of_node_put(np);
  901. }
  902. /**
  903. * update_node_properties - adds the properties
  904. * of np into dup node (present in live tree) and
  905. * updates parent of children of np to dup.
  906. *
  907. * @np: node already present in live tree
  908. * @dup: node present in live tree to be updated
  909. */
  910. static void update_node_properties(struct device_node *np,
  911. struct device_node *dup)
  912. {
  913. struct property *prop;
  914. struct device_node *child;
  915. for_each_property_of_node(np, prop)
  916. of_add_property(dup, prop);
  917. for_each_child_of_node(np, child)
  918. child->parent = dup;
  919. }
  920. /**
  921. * attach_node_and_children - attaches nodes
  922. * and its children to live tree
  923. *
  924. * @np: Node to attach to live tree
  925. */
  926. static int attach_node_and_children(struct device_node *np)
  927. {
  928. struct device_node *next, *dup, *child;
  929. unsigned long flags;
  930. const char *full_name;
  931. full_name = kasprintf(GFP_KERNEL, "%pOF", np);
  932. dup = of_find_node_by_path(full_name);
  933. kfree(full_name);
  934. if (dup) {
  935. update_node_properties(np, dup);
  936. return 0;
  937. }
  938. child = np->child;
  939. np->child = NULL;
  940. mutex_lock(&of_mutex);
  941. raw_spin_lock_irqsave(&devtree_lock, flags);
  942. np->sibling = np->parent->child;
  943. np->parent->child = np;
  944. of_node_clear_flag(np, OF_DETACHED);
  945. raw_spin_unlock_irqrestore(&devtree_lock, flags);
  946. __of_attach_node_sysfs(np);
  947. mutex_unlock(&of_mutex);
  948. while (child) {
  949. next = child->sibling;
  950. attach_node_and_children(child);
  951. child = next;
  952. }
  953. return 0;
  954. }
  955. /**
  956. * unittest_data_add - Reads, copies data from
  957. * linked tree and attaches it to the live tree
  958. */
  959. static int __init unittest_data_add(void)
  960. {
  961. void *unittest_data;
  962. struct device_node *unittest_data_node, *np;
  963. /*
  964. * __dtb_testcases_begin[] and __dtb_testcases_end[] are magically
  965. * created by cmd_dt_S_dtb in scripts/Makefile.lib
  966. */
  967. extern uint8_t __dtb_testcases_begin[];
  968. extern uint8_t __dtb_testcases_end[];
  969. const int size = __dtb_testcases_end - __dtb_testcases_begin;
  970. int rc;
  971. if (!size) {
  972. pr_warn("%s: No testcase data to attach; not running tests\n",
  973. __func__);
  974. return -ENODATA;
  975. }
  976. /* creating copy */
  977. unittest_data = kmemdup(__dtb_testcases_begin, size, GFP_KERNEL);
  978. if (!unittest_data) {
  979. pr_warn("%s: Failed to allocate memory for unittest_data; "
  980. "not running tests\n", __func__);
  981. return -ENOMEM;
  982. }
  983. of_fdt_unflatten_tree(unittest_data, NULL, &unittest_data_node);
  984. if (!unittest_data_node) {
  985. pr_warn("%s: No tree to attach; not running tests\n", __func__);
  986. return -ENODATA;
  987. }
  988. /*
  989. * This lock normally encloses of_resolve_phandles()
  990. */
  991. of_overlay_mutex_lock();
  992. rc = of_resolve_phandles(unittest_data_node);
  993. if (rc) {
  994. pr_err("%s: Failed to resolve phandles (rc=%i)\n", __func__, rc);
  995. of_overlay_mutex_unlock();
  996. return -EINVAL;
  997. }
  998. if (!of_root) {
  999. of_root = unittest_data_node;
  1000. for_each_of_allnodes(np)
  1001. __of_attach_node_sysfs(np);
  1002. of_aliases = of_find_node_by_path("/aliases");
  1003. of_chosen = of_find_node_by_path("/chosen");
  1004. of_overlay_mutex_unlock();
  1005. return 0;
  1006. }
  1007. /* attach the sub-tree to live tree */
  1008. np = unittest_data_node->child;
  1009. while (np) {
  1010. struct device_node *next = np->sibling;
  1011. np->parent = of_root;
  1012. attach_node_and_children(np);
  1013. np = next;
  1014. }
  1015. of_overlay_mutex_unlock();
  1016. return 0;
  1017. }
  1018. #ifdef CONFIG_OF_OVERLAY
  1019. static int __init overlay_data_apply(const char *overlay_name, int *overlay_id);
  1020. static int unittest_probe(struct platform_device *pdev)
  1021. {
  1022. struct device *dev = &pdev->dev;
  1023. struct device_node *np = dev->of_node;
  1024. if (np == NULL) {
  1025. dev_err(dev, "No OF data for device\n");
  1026. return -EINVAL;
  1027. }
  1028. dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
  1029. of_platform_populate(np, NULL, NULL, &pdev->dev);
  1030. return 0;
  1031. }
  1032. static int unittest_remove(struct platform_device *pdev)
  1033. {
  1034. struct device *dev = &pdev->dev;
  1035. struct device_node *np = dev->of_node;
  1036. dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
  1037. return 0;
  1038. }
  1039. static const struct of_device_id unittest_match[] = {
  1040. { .compatible = "unittest", },
  1041. {},
  1042. };
  1043. static struct platform_driver unittest_driver = {
  1044. .probe = unittest_probe,
  1045. .remove = unittest_remove,
  1046. .driver = {
  1047. .name = "unittest",
  1048. .of_match_table = of_match_ptr(unittest_match),
  1049. },
  1050. };
  1051. /* get the platform device instantiated at the path */
  1052. static struct platform_device *of_path_to_platform_device(const char *path)
  1053. {
  1054. struct device_node *np;
  1055. struct platform_device *pdev;
  1056. np = of_find_node_by_path(path);
  1057. if (np == NULL)
  1058. return NULL;
  1059. pdev = of_find_device_by_node(np);
  1060. of_node_put(np);
  1061. return pdev;
  1062. }
  1063. /* find out if a platform device exists at that path */
  1064. static int of_path_platform_device_exists(const char *path)
  1065. {
  1066. struct platform_device *pdev;
  1067. pdev = of_path_to_platform_device(path);
  1068. platform_device_put(pdev);
  1069. return pdev != NULL;
  1070. }
  1071. #if IS_BUILTIN(CONFIG_I2C)
  1072. /* get the i2c client device instantiated at the path */
  1073. static struct i2c_client *of_path_to_i2c_client(const char *path)
  1074. {
  1075. struct device_node *np;
  1076. struct i2c_client *client;
  1077. np = of_find_node_by_path(path);
  1078. if (np == NULL)
  1079. return NULL;
  1080. client = of_find_i2c_device_by_node(np);
  1081. of_node_put(np);
  1082. return client;
  1083. }
  1084. /* find out if a i2c client device exists at that path */
  1085. static int of_path_i2c_client_exists(const char *path)
  1086. {
  1087. struct i2c_client *client;
  1088. client = of_path_to_i2c_client(path);
  1089. if (client)
  1090. put_device(&client->dev);
  1091. return client != NULL;
  1092. }
  1093. #else
  1094. static int of_path_i2c_client_exists(const char *path)
  1095. {
  1096. return 0;
  1097. }
  1098. #endif
  1099. enum overlay_type {
  1100. PDEV_OVERLAY,
  1101. I2C_OVERLAY
  1102. };
  1103. static int of_path_device_type_exists(const char *path,
  1104. enum overlay_type ovtype)
  1105. {
  1106. switch (ovtype) {
  1107. case PDEV_OVERLAY:
  1108. return of_path_platform_device_exists(path);
  1109. case I2C_OVERLAY:
  1110. return of_path_i2c_client_exists(path);
  1111. }
  1112. return 0;
  1113. }
  1114. static const char *unittest_path(int nr, enum overlay_type ovtype)
  1115. {
  1116. const char *base;
  1117. static char buf[256];
  1118. switch (ovtype) {
  1119. case PDEV_OVERLAY:
  1120. base = "/testcase-data/overlay-node/test-bus";
  1121. break;
  1122. case I2C_OVERLAY:
  1123. base = "/testcase-data/overlay-node/test-bus/i2c-test-bus";
  1124. break;
  1125. default:
  1126. buf[0] = '\0';
  1127. return buf;
  1128. }
  1129. snprintf(buf, sizeof(buf) - 1, "%s/test-unittest%d", base, nr);
  1130. buf[sizeof(buf) - 1] = '\0';
  1131. return buf;
  1132. }
  1133. static int of_unittest_device_exists(int unittest_nr, enum overlay_type ovtype)
  1134. {
  1135. const char *path;
  1136. path = unittest_path(unittest_nr, ovtype);
  1137. switch (ovtype) {
  1138. case PDEV_OVERLAY:
  1139. return of_path_platform_device_exists(path);
  1140. case I2C_OVERLAY:
  1141. return of_path_i2c_client_exists(path);
  1142. }
  1143. return 0;
  1144. }
  1145. static const char *overlay_name_from_nr(int nr)
  1146. {
  1147. static char buf[256];
  1148. snprintf(buf, sizeof(buf) - 1,
  1149. "overlay_%d", nr);
  1150. buf[sizeof(buf) - 1] = '\0';
  1151. return buf;
  1152. }
  1153. static const char *bus_path = "/testcase-data/overlay-node/test-bus";
  1154. /* it is guaranteed that overlay ids are assigned in sequence */
  1155. #define MAX_UNITTEST_OVERLAYS 256
  1156. static unsigned long overlay_id_bits[BITS_TO_LONGS(MAX_UNITTEST_OVERLAYS)];
  1157. static int overlay_first_id = -1;
  1158. static void of_unittest_track_overlay(int id)
  1159. {
  1160. if (overlay_first_id < 0)
  1161. overlay_first_id = id;
  1162. id -= overlay_first_id;
  1163. /* we shouldn't need that many */
  1164. BUG_ON(id >= MAX_UNITTEST_OVERLAYS);
  1165. overlay_id_bits[BIT_WORD(id)] |= BIT_MASK(id);
  1166. }
  1167. static void of_unittest_untrack_overlay(int id)
  1168. {
  1169. if (overlay_first_id < 0)
  1170. return;
  1171. id -= overlay_first_id;
  1172. BUG_ON(id >= MAX_UNITTEST_OVERLAYS);
  1173. overlay_id_bits[BIT_WORD(id)] &= ~BIT_MASK(id);
  1174. }
  1175. static void of_unittest_destroy_tracked_overlays(void)
  1176. {
  1177. int id, ret, defers, ovcs_id;
  1178. if (overlay_first_id < 0)
  1179. return;
  1180. /* try until no defers */
  1181. do {
  1182. defers = 0;
  1183. /* remove in reverse order */
  1184. for (id = MAX_UNITTEST_OVERLAYS - 1; id >= 0; id--) {
  1185. if (!(overlay_id_bits[BIT_WORD(id)] & BIT_MASK(id)))
  1186. continue;
  1187. ovcs_id = id + overlay_first_id;
  1188. ret = of_overlay_remove(&ovcs_id);
  1189. if (ret == -ENODEV) {
  1190. pr_warn("%s: no overlay to destroy for #%d\n",
  1191. __func__, id + overlay_first_id);
  1192. continue;
  1193. }
  1194. if (ret != 0) {
  1195. defers++;
  1196. pr_warn("%s: overlay destroy failed for #%d\n",
  1197. __func__, id + overlay_first_id);
  1198. continue;
  1199. }
  1200. overlay_id_bits[BIT_WORD(id)] &= ~BIT_MASK(id);
  1201. }
  1202. } while (defers > 0);
  1203. }
  1204. static int __init of_unittest_apply_overlay(int overlay_nr, int unittest_nr,
  1205. int *overlay_id)
  1206. {
  1207. const char *overlay_name;
  1208. int ret;
  1209. overlay_name = overlay_name_from_nr(overlay_nr);
  1210. ret = overlay_data_apply(overlay_name, overlay_id);
  1211. if (!ret) {
  1212. unittest(0, "could not apply overlay \"%s\"\n",
  1213. overlay_name);
  1214. return ret;
  1215. }
  1216. of_unittest_track_overlay(*overlay_id);
  1217. return 0;
  1218. }
  1219. /* apply an overlay while checking before and after states */
  1220. static int __init of_unittest_apply_overlay_check(int overlay_nr,
  1221. int unittest_nr, int before, int after,
  1222. enum overlay_type ovtype)
  1223. {
  1224. int ret, ovcs_id;
  1225. /* unittest device must not be in before state */
  1226. if (of_unittest_device_exists(unittest_nr, ovtype) != before) {
  1227. unittest(0, "%s with device @\"%s\" %s\n",
  1228. overlay_name_from_nr(overlay_nr),
  1229. unittest_path(unittest_nr, ovtype),
  1230. !before ? "enabled" : "disabled");
  1231. return -EINVAL;
  1232. }
  1233. ovcs_id = 0;
  1234. ret = of_unittest_apply_overlay(overlay_nr, unittest_nr, &ovcs_id);
  1235. if (ret != 0) {
  1236. /* of_unittest_apply_overlay already called unittest() */
  1237. return ret;
  1238. }
  1239. /* unittest device must be to set to after state */
  1240. if (of_unittest_device_exists(unittest_nr, ovtype) != after) {
  1241. unittest(0, "%s failed to create @\"%s\" %s\n",
  1242. overlay_name_from_nr(overlay_nr),
  1243. unittest_path(unittest_nr, ovtype),
  1244. !after ? "enabled" : "disabled");
  1245. return -EINVAL;
  1246. }
  1247. return 0;
  1248. }
  1249. /* apply an overlay and then revert it while checking before, after states */
  1250. static int __init of_unittest_apply_revert_overlay_check(int overlay_nr,
  1251. int unittest_nr, int before, int after,
  1252. enum overlay_type ovtype)
  1253. {
  1254. int ret, ovcs_id;
  1255. /* unittest device must be in before state */
  1256. if (of_unittest_device_exists(unittest_nr, ovtype) != before) {
  1257. unittest(0, "%s with device @\"%s\" %s\n",
  1258. overlay_name_from_nr(overlay_nr),
  1259. unittest_path(unittest_nr, ovtype),
  1260. !before ? "enabled" : "disabled");
  1261. return -EINVAL;
  1262. }
  1263. /* apply the overlay */
  1264. ovcs_id = 0;
  1265. ret = of_unittest_apply_overlay(overlay_nr, unittest_nr, &ovcs_id);
  1266. if (ret != 0) {
  1267. /* of_unittest_apply_overlay already called unittest() */
  1268. return ret;
  1269. }
  1270. /* unittest device must be in after state */
  1271. if (of_unittest_device_exists(unittest_nr, ovtype) != after) {
  1272. unittest(0, "%s failed to create @\"%s\" %s\n",
  1273. overlay_name_from_nr(overlay_nr),
  1274. unittest_path(unittest_nr, ovtype),
  1275. !after ? "enabled" : "disabled");
  1276. return -EINVAL;
  1277. }
  1278. ret = of_overlay_remove(&ovcs_id);
  1279. if (ret != 0) {
  1280. unittest(0, "%s failed to be destroyed @\"%s\"\n",
  1281. overlay_name_from_nr(overlay_nr),
  1282. unittest_path(unittest_nr, ovtype));
  1283. return ret;
  1284. }
  1285. /* unittest device must be again in before state */
  1286. if (of_unittest_device_exists(unittest_nr, PDEV_OVERLAY) != before) {
  1287. unittest(0, "%s with device @\"%s\" %s\n",
  1288. overlay_name_from_nr(overlay_nr),
  1289. unittest_path(unittest_nr, ovtype),
  1290. !before ? "enabled" : "disabled");
  1291. return -EINVAL;
  1292. }
  1293. return 0;
  1294. }
  1295. /* test activation of device */
  1296. static void __init of_unittest_overlay_0(void)
  1297. {
  1298. /* device should enable */
  1299. if (of_unittest_apply_overlay_check(0, 0, 0, 1, PDEV_OVERLAY))
  1300. return;
  1301. unittest(1, "overlay test %d passed\n", 0);
  1302. }
  1303. /* test deactivation of device */
  1304. static void __init of_unittest_overlay_1(void)
  1305. {
  1306. /* device should disable */
  1307. if (of_unittest_apply_overlay_check(1, 1, 1, 0, PDEV_OVERLAY))
  1308. return;
  1309. unittest(1, "overlay test %d passed\n", 1);
  1310. }
  1311. /* test activation of device */
  1312. static void __init of_unittest_overlay_2(void)
  1313. {
  1314. /* device should enable */
  1315. if (of_unittest_apply_overlay_check(2, 2, 0, 1, PDEV_OVERLAY))
  1316. return;
  1317. unittest(1, "overlay test %d passed\n", 2);
  1318. }
  1319. /* test deactivation of device */
  1320. static void __init of_unittest_overlay_3(void)
  1321. {
  1322. /* device should disable */
  1323. if (of_unittest_apply_overlay_check(3, 3, 1, 0, PDEV_OVERLAY))
  1324. return;
  1325. unittest(1, "overlay test %d passed\n", 3);
  1326. }
  1327. /* test activation of a full device node */
  1328. static void __init of_unittest_overlay_4(void)
  1329. {
  1330. /* device should disable */
  1331. if (of_unittest_apply_overlay_check(4, 4, 0, 1, PDEV_OVERLAY))
  1332. return;
  1333. unittest(1, "overlay test %d passed\n", 4);
  1334. }
  1335. /* test overlay apply/revert sequence */
  1336. static void __init of_unittest_overlay_5(void)
  1337. {
  1338. /* device should disable */
  1339. if (of_unittest_apply_revert_overlay_check(5, 5, 0, 1, PDEV_OVERLAY))
  1340. return;
  1341. unittest(1, "overlay test %d passed\n", 5);
  1342. }
  1343. /* test overlay application in sequence */
  1344. static void __init of_unittest_overlay_6(void)
  1345. {
  1346. int i, ov_id[2], ovcs_id;
  1347. int overlay_nr = 6, unittest_nr = 6;
  1348. int before = 0, after = 1;
  1349. const char *overlay_name;
  1350. /* unittest device must be in before state */
  1351. for (i = 0; i < 2; i++) {
  1352. if (of_unittest_device_exists(unittest_nr + i, PDEV_OVERLAY)
  1353. != before) {
  1354. unittest(0, "%s with device @\"%s\" %s\n",
  1355. overlay_name_from_nr(overlay_nr + i),
  1356. unittest_path(unittest_nr + i,
  1357. PDEV_OVERLAY),
  1358. !before ? "enabled" : "disabled");
  1359. return;
  1360. }
  1361. }
  1362. /* apply the overlays */
  1363. for (i = 0; i < 2; i++) {
  1364. overlay_name = overlay_name_from_nr(overlay_nr + i);
  1365. if (!overlay_data_apply(overlay_name, &ovcs_id)) {
  1366. unittest(0, "could not apply overlay \"%s\"\n",
  1367. overlay_name);
  1368. return;
  1369. }
  1370. ov_id[i] = ovcs_id;
  1371. of_unittest_track_overlay(ov_id[i]);
  1372. }
  1373. for (i = 0; i < 2; i++) {
  1374. /* unittest device must be in after state */
  1375. if (of_unittest_device_exists(unittest_nr + i, PDEV_OVERLAY)
  1376. != after) {
  1377. unittest(0, "overlay @\"%s\" failed @\"%s\" %s\n",
  1378. overlay_name_from_nr(overlay_nr + i),
  1379. unittest_path(unittest_nr + i,
  1380. PDEV_OVERLAY),
  1381. !after ? "enabled" : "disabled");
  1382. return;
  1383. }
  1384. }
  1385. for (i = 1; i >= 0; i--) {
  1386. ovcs_id = ov_id[i];
  1387. if (of_overlay_remove(&ovcs_id)) {
  1388. unittest(0, "%s failed destroy @\"%s\"\n",
  1389. overlay_name_from_nr(overlay_nr + i),
  1390. unittest_path(unittest_nr + i,
  1391. PDEV_OVERLAY));
  1392. return;
  1393. }
  1394. of_unittest_untrack_overlay(ov_id[i]);
  1395. }
  1396. for (i = 0; i < 2; i++) {
  1397. /* unittest device must be again in before state */
  1398. if (of_unittest_device_exists(unittest_nr + i, PDEV_OVERLAY)
  1399. != before) {
  1400. unittest(0, "%s with device @\"%s\" %s\n",
  1401. overlay_name_from_nr(overlay_nr + i),
  1402. unittest_path(unittest_nr + i,
  1403. PDEV_OVERLAY),
  1404. !before ? "enabled" : "disabled");
  1405. return;
  1406. }
  1407. }
  1408. unittest(1, "overlay test %d passed\n", 6);
  1409. }
  1410. /* test overlay application in sequence */
  1411. static void __init of_unittest_overlay_8(void)
  1412. {
  1413. int i, ov_id[2], ovcs_id;
  1414. int overlay_nr = 8, unittest_nr = 8;
  1415. const char *overlay_name;
  1416. /* we don't care about device state in this test */
  1417. /* apply the overlays */
  1418. for (i = 0; i < 2; i++) {
  1419. overlay_name = overlay_name_from_nr(overlay_nr + i);
  1420. if (!overlay_data_apply(overlay_name, &ovcs_id)) {
  1421. unittest(0, "could not apply overlay \"%s\"\n",
  1422. overlay_name);
  1423. return;
  1424. }
  1425. ov_id[i] = ovcs_id;
  1426. of_unittest_track_overlay(ov_id[i]);
  1427. }
  1428. /* now try to remove first overlay (it should fail) */
  1429. ovcs_id = ov_id[0];
  1430. if (!of_overlay_remove(&ovcs_id)) {
  1431. unittest(0, "%s was destroyed @\"%s\"\n",
  1432. overlay_name_from_nr(overlay_nr + 0),
  1433. unittest_path(unittest_nr,
  1434. PDEV_OVERLAY));
  1435. return;
  1436. }
  1437. /* removing them in order should work */
  1438. for (i = 1; i >= 0; i--) {
  1439. ovcs_id = ov_id[i];
  1440. if (of_overlay_remove(&ovcs_id)) {
  1441. unittest(0, "%s not destroyed @\"%s\"\n",
  1442. overlay_name_from_nr(overlay_nr + i),
  1443. unittest_path(unittest_nr,
  1444. PDEV_OVERLAY));
  1445. return;
  1446. }
  1447. of_unittest_untrack_overlay(ov_id[i]);
  1448. }
  1449. unittest(1, "overlay test %d passed\n", 8);
  1450. }
  1451. /* test insertion of a bus with parent devices */
  1452. static void __init of_unittest_overlay_10(void)
  1453. {
  1454. int ret;
  1455. char *child_path;
  1456. /* device should disable */
  1457. ret = of_unittest_apply_overlay_check(10, 10, 0, 1, PDEV_OVERLAY);
  1458. if (unittest(ret == 0,
  1459. "overlay test %d failed; overlay application\n", 10))
  1460. return;
  1461. child_path = kasprintf(GFP_KERNEL, "%s/test-unittest101",
  1462. unittest_path(10, PDEV_OVERLAY));
  1463. if (unittest(child_path, "overlay test %d failed; kasprintf\n", 10))
  1464. return;
  1465. ret = of_path_device_type_exists(child_path, PDEV_OVERLAY);
  1466. kfree(child_path);
  1467. unittest(ret, "overlay test %d failed; no child device\n", 10);
  1468. }
  1469. /* test insertion of a bus with parent devices (and revert) */
  1470. static void __init of_unittest_overlay_11(void)
  1471. {
  1472. int ret;
  1473. /* device should disable */
  1474. ret = of_unittest_apply_revert_overlay_check(11, 11, 0, 1,
  1475. PDEV_OVERLAY);
  1476. unittest(ret == 0, "overlay test %d failed; overlay apply\n", 11);
  1477. }
  1478. #if IS_BUILTIN(CONFIG_I2C) && IS_ENABLED(CONFIG_OF_OVERLAY)
  1479. struct unittest_i2c_bus_data {
  1480. struct platform_device *pdev;
  1481. struct i2c_adapter adap;
  1482. };
  1483. static int unittest_i2c_master_xfer(struct i2c_adapter *adap,
  1484. struct i2c_msg *msgs, int num)
  1485. {
  1486. struct unittest_i2c_bus_data *std = i2c_get_adapdata(adap);
  1487. (void)std;
  1488. return num;
  1489. }
  1490. static u32 unittest_i2c_functionality(struct i2c_adapter *adap)
  1491. {
  1492. return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
  1493. }
  1494. static const struct i2c_algorithm unittest_i2c_algo = {
  1495. .master_xfer = unittest_i2c_master_xfer,
  1496. .functionality = unittest_i2c_functionality,
  1497. };
  1498. static int unittest_i2c_bus_probe(struct platform_device *pdev)
  1499. {
  1500. struct device *dev = &pdev->dev;
  1501. struct device_node *np = dev->of_node;
  1502. struct unittest_i2c_bus_data *std;
  1503. struct i2c_adapter *adap;
  1504. int ret;
  1505. if (np == NULL) {
  1506. dev_err(dev, "No OF data for device\n");
  1507. return -EINVAL;
  1508. }
  1509. dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
  1510. std = devm_kzalloc(dev, sizeof(*std), GFP_KERNEL);
  1511. if (!std) {
  1512. dev_err(dev, "Failed to allocate unittest i2c data\n");
  1513. return -ENOMEM;
  1514. }
  1515. /* link them together */
  1516. std->pdev = pdev;
  1517. platform_set_drvdata(pdev, std);
  1518. adap = &std->adap;
  1519. i2c_set_adapdata(adap, std);
  1520. adap->nr = -1;
  1521. strlcpy(adap->name, pdev->name, sizeof(adap->name));
  1522. adap->class = I2C_CLASS_DEPRECATED;
  1523. adap->algo = &unittest_i2c_algo;
  1524. adap->dev.parent = dev;
  1525. adap->dev.of_node = dev->of_node;
  1526. adap->timeout = 5 * HZ;
  1527. adap->retries = 3;
  1528. ret = i2c_add_numbered_adapter(adap);
  1529. if (ret != 0) {
  1530. dev_err(dev, "Failed to add I2C adapter\n");
  1531. return ret;
  1532. }
  1533. return 0;
  1534. }
  1535. static int unittest_i2c_bus_remove(struct platform_device *pdev)
  1536. {
  1537. struct device *dev = &pdev->dev;
  1538. struct device_node *np = dev->of_node;
  1539. struct unittest_i2c_bus_data *std = platform_get_drvdata(pdev);
  1540. dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
  1541. i2c_del_adapter(&std->adap);
  1542. return 0;
  1543. }
  1544. static const struct of_device_id unittest_i2c_bus_match[] = {
  1545. { .compatible = "unittest-i2c-bus", },
  1546. {},
  1547. };
  1548. static struct platform_driver unittest_i2c_bus_driver = {
  1549. .probe = unittest_i2c_bus_probe,
  1550. .remove = unittest_i2c_bus_remove,
  1551. .driver = {
  1552. .name = "unittest-i2c-bus",
  1553. .of_match_table = of_match_ptr(unittest_i2c_bus_match),
  1554. },
  1555. };
  1556. static int unittest_i2c_dev_probe(struct i2c_client *client,
  1557. const struct i2c_device_id *id)
  1558. {
  1559. struct device *dev = &client->dev;
  1560. struct device_node *np = client->dev.of_node;
  1561. if (!np) {
  1562. dev_err(dev, "No OF node\n");
  1563. return -EINVAL;
  1564. }
  1565. dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
  1566. return 0;
  1567. };
  1568. static int unittest_i2c_dev_remove(struct i2c_client *client)
  1569. {
  1570. struct device *dev = &client->dev;
  1571. struct device_node *np = client->dev.of_node;
  1572. dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
  1573. return 0;
  1574. }
  1575. static const struct i2c_device_id unittest_i2c_dev_id[] = {
  1576. { .name = "unittest-i2c-dev" },
  1577. { }
  1578. };
  1579. static struct i2c_driver unittest_i2c_dev_driver = {
  1580. .driver = {
  1581. .name = "unittest-i2c-dev",
  1582. },
  1583. .probe = unittest_i2c_dev_probe,
  1584. .remove = unittest_i2c_dev_remove,
  1585. .id_table = unittest_i2c_dev_id,
  1586. };
  1587. #if IS_BUILTIN(CONFIG_I2C_MUX)
  1588. static int unittest_i2c_mux_select_chan(struct i2c_mux_core *muxc, u32 chan)
  1589. {
  1590. return 0;
  1591. }
  1592. static int unittest_i2c_mux_probe(struct i2c_client *client,
  1593. const struct i2c_device_id *id)
  1594. {
  1595. int i, nchans;
  1596. struct device *dev = &client->dev;
  1597. struct i2c_adapter *adap = to_i2c_adapter(dev->parent);
  1598. struct device_node *np = client->dev.of_node, *child;
  1599. struct i2c_mux_core *muxc;
  1600. u32 reg, max_reg;
  1601. dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
  1602. if (!np) {
  1603. dev_err(dev, "No OF node\n");
  1604. return -EINVAL;
  1605. }
  1606. max_reg = (u32)-1;
  1607. for_each_child_of_node(np, child) {
  1608. if (of_property_read_u32(child, "reg", &reg))
  1609. continue;
  1610. if (max_reg == (u32)-1 || reg > max_reg)
  1611. max_reg = reg;
  1612. }
  1613. nchans = max_reg == (u32)-1 ? 0 : max_reg + 1;
  1614. if (nchans == 0) {
  1615. dev_err(dev, "No channels\n");
  1616. return -EINVAL;
  1617. }
  1618. muxc = i2c_mux_alloc(adap, dev, nchans, 0, 0,
  1619. unittest_i2c_mux_select_chan, NULL);
  1620. if (!muxc)
  1621. return -ENOMEM;
  1622. for (i = 0; i < nchans; i++) {
  1623. if (i2c_mux_add_adapter(muxc, 0, i, 0)) {
  1624. dev_err(dev, "Failed to register mux #%d\n", i);
  1625. i2c_mux_del_adapters(muxc);
  1626. return -ENODEV;
  1627. }
  1628. }
  1629. i2c_set_clientdata(client, muxc);
  1630. return 0;
  1631. };
  1632. static int unittest_i2c_mux_remove(struct i2c_client *client)
  1633. {
  1634. struct device *dev = &client->dev;
  1635. struct device_node *np = client->dev.of_node;
  1636. struct i2c_mux_core *muxc = i2c_get_clientdata(client);
  1637. dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
  1638. i2c_mux_del_adapters(muxc);
  1639. return 0;
  1640. }
  1641. static const struct i2c_device_id unittest_i2c_mux_id[] = {
  1642. { .name = "unittest-i2c-mux" },
  1643. { }
  1644. };
  1645. static struct i2c_driver unittest_i2c_mux_driver = {
  1646. .driver = {
  1647. .name = "unittest-i2c-mux",
  1648. },
  1649. .probe = unittest_i2c_mux_probe,
  1650. .remove = unittest_i2c_mux_remove,
  1651. .id_table = unittest_i2c_mux_id,
  1652. };
  1653. #endif
  1654. static int of_unittest_overlay_i2c_init(void)
  1655. {
  1656. int ret;
  1657. ret = i2c_add_driver(&unittest_i2c_dev_driver);
  1658. if (unittest(ret == 0,
  1659. "could not register unittest i2c device driver\n"))
  1660. return ret;
  1661. ret = platform_driver_register(&unittest_i2c_bus_driver);
  1662. if (unittest(ret == 0,
  1663. "could not register unittest i2c bus driver\n"))
  1664. return ret;
  1665. #if IS_BUILTIN(CONFIG_I2C_MUX)
  1666. ret = i2c_add_driver(&unittest_i2c_mux_driver);
  1667. if (unittest(ret == 0,
  1668. "could not register unittest i2c mux driver\n"))
  1669. return ret;
  1670. #endif
  1671. return 0;
  1672. }
  1673. static void of_unittest_overlay_i2c_cleanup(void)
  1674. {
  1675. #if IS_BUILTIN(CONFIG_I2C_MUX)
  1676. i2c_del_driver(&unittest_i2c_mux_driver);
  1677. #endif
  1678. platform_driver_unregister(&unittest_i2c_bus_driver);
  1679. i2c_del_driver(&unittest_i2c_dev_driver);
  1680. }
  1681. static void __init of_unittest_overlay_i2c_12(void)
  1682. {
  1683. /* device should enable */
  1684. if (of_unittest_apply_overlay_check(12, 12, 0, 1, I2C_OVERLAY))
  1685. return;
  1686. unittest(1, "overlay test %d passed\n", 12);
  1687. }
  1688. /* test deactivation of device */
  1689. static void __init of_unittest_overlay_i2c_13(void)
  1690. {
  1691. /* device should disable */
  1692. if (of_unittest_apply_overlay_check(13, 13, 1, 0, I2C_OVERLAY))
  1693. return;
  1694. unittest(1, "overlay test %d passed\n", 13);
  1695. }
  1696. /* just check for i2c mux existence */
  1697. static void of_unittest_overlay_i2c_14(void)
  1698. {
  1699. }
  1700. static void __init of_unittest_overlay_i2c_15(void)
  1701. {
  1702. /* device should enable */
  1703. if (of_unittest_apply_overlay_check(15, 15, 0, 1, I2C_OVERLAY))
  1704. return;
  1705. unittest(1, "overlay test %d passed\n", 15);
  1706. }
  1707. #else
  1708. static inline void of_unittest_overlay_i2c_14(void) { }
  1709. static inline void of_unittest_overlay_i2c_15(void) { }
  1710. #endif
  1711. static void __init of_unittest_overlay(void)
  1712. {
  1713. struct device_node *bus_np = NULL;
  1714. if (platform_driver_register(&unittest_driver)) {
  1715. unittest(0, "could not register unittest driver\n");
  1716. goto out;
  1717. }
  1718. bus_np = of_find_node_by_path(bus_path);
  1719. if (bus_np == NULL) {
  1720. unittest(0, "could not find bus_path \"%s\"\n", bus_path);
  1721. goto out;
  1722. }
  1723. if (of_platform_default_populate(bus_np, NULL, NULL)) {
  1724. unittest(0, "could not populate bus @ \"%s\"\n", bus_path);
  1725. goto out;
  1726. }
  1727. if (!of_unittest_device_exists(100, PDEV_OVERLAY)) {
  1728. unittest(0, "could not find unittest0 @ \"%s\"\n",
  1729. unittest_path(100, PDEV_OVERLAY));
  1730. goto out;
  1731. }
  1732. if (of_unittest_device_exists(101, PDEV_OVERLAY)) {
  1733. unittest(0, "unittest1 @ \"%s\" should not exist\n",
  1734. unittest_path(101, PDEV_OVERLAY));
  1735. goto out;
  1736. }
  1737. unittest(1, "basic infrastructure of overlays passed");
  1738. /* tests in sequence */
  1739. of_unittest_overlay_0();
  1740. of_unittest_overlay_1();
  1741. of_unittest_overlay_2();
  1742. of_unittest_overlay_3();
  1743. of_unittest_overlay_4();
  1744. of_unittest_overlay_5();
  1745. of_unittest_overlay_6();
  1746. of_unittest_overlay_8();
  1747. of_unittest_overlay_10();
  1748. of_unittest_overlay_11();
  1749. #if IS_BUILTIN(CONFIG_I2C)
  1750. if (unittest(of_unittest_overlay_i2c_init() == 0, "i2c init failed\n"))
  1751. goto out;
  1752. of_unittest_overlay_i2c_12();
  1753. of_unittest_overlay_i2c_13();
  1754. of_unittest_overlay_i2c_14();
  1755. of_unittest_overlay_i2c_15();
  1756. of_unittest_overlay_i2c_cleanup();
  1757. #endif
  1758. of_unittest_destroy_tracked_overlays();
  1759. out:
  1760. of_node_put(bus_np);
  1761. }
  1762. #else
  1763. static inline void __init of_unittest_overlay(void) { }
  1764. #endif
  1765. #ifdef CONFIG_OF_OVERLAY
  1766. /*
  1767. * __dtb_ot_begin[] and __dtb_ot_end[] are created by cmd_dt_S_dtb
  1768. * in scripts/Makefile.lib
  1769. */
  1770. #define OVERLAY_INFO_EXTERN(name) \
  1771. extern uint8_t __dtb_##name##_begin[]; \
  1772. extern uint8_t __dtb_##name##_end[]
  1773. #define OVERLAY_INFO(overlay_name, expected) \
  1774. { .dtb_begin = __dtb_##overlay_name##_begin, \
  1775. .dtb_end = __dtb_##overlay_name##_end, \
  1776. .expected_result = expected, \
  1777. .name = #overlay_name, \
  1778. }
  1779. struct overlay_info {
  1780. uint8_t *dtb_begin;
  1781. uint8_t *dtb_end;
  1782. int expected_result;
  1783. int overlay_id;
  1784. char *name;
  1785. };
  1786. OVERLAY_INFO_EXTERN(overlay_base);
  1787. OVERLAY_INFO_EXTERN(overlay);
  1788. OVERLAY_INFO_EXTERN(overlay_0);
  1789. OVERLAY_INFO_EXTERN(overlay_1);
  1790. OVERLAY_INFO_EXTERN(overlay_2);
  1791. OVERLAY_INFO_EXTERN(overlay_3);
  1792. OVERLAY_INFO_EXTERN(overlay_4);
  1793. OVERLAY_INFO_EXTERN(overlay_5);
  1794. OVERLAY_INFO_EXTERN(overlay_6);
  1795. OVERLAY_INFO_EXTERN(overlay_7);
  1796. OVERLAY_INFO_EXTERN(overlay_8);
  1797. OVERLAY_INFO_EXTERN(overlay_9);
  1798. OVERLAY_INFO_EXTERN(overlay_10);
  1799. OVERLAY_INFO_EXTERN(overlay_11);
  1800. OVERLAY_INFO_EXTERN(overlay_12);
  1801. OVERLAY_INFO_EXTERN(overlay_13);
  1802. OVERLAY_INFO_EXTERN(overlay_15);
  1803. OVERLAY_INFO_EXTERN(overlay_bad_phandle);
  1804. OVERLAY_INFO_EXTERN(overlay_bad_symbol);
  1805. /* order of entries is hard-coded into users of overlays[] */
  1806. static struct overlay_info overlays[] = {
  1807. OVERLAY_INFO(overlay_base, -9999),
  1808. OVERLAY_INFO(overlay, 0),
  1809. OVERLAY_INFO(overlay_0, 0),
  1810. OVERLAY_INFO(overlay_1, 0),
  1811. OVERLAY_INFO(overlay_2, 0),
  1812. OVERLAY_INFO(overlay_3, 0),
  1813. OVERLAY_INFO(overlay_4, 0),
  1814. OVERLAY_INFO(overlay_5, 0),
  1815. OVERLAY_INFO(overlay_6, 0),
  1816. OVERLAY_INFO(overlay_7, 0),
  1817. OVERLAY_INFO(overlay_8, 0),
  1818. OVERLAY_INFO(overlay_9, 0),
  1819. OVERLAY_INFO(overlay_10, 0),
  1820. OVERLAY_INFO(overlay_11, 0),
  1821. OVERLAY_INFO(overlay_12, 0),
  1822. OVERLAY_INFO(overlay_13, 0),
  1823. OVERLAY_INFO(overlay_15, 0),
  1824. OVERLAY_INFO(overlay_bad_phandle, -EINVAL),
  1825. OVERLAY_INFO(overlay_bad_symbol, -EINVAL),
  1826. {}
  1827. };
  1828. static struct device_node *overlay_base_root;
  1829. static void * __init dt_alloc_memory(u64 size, u64 align)
  1830. {
  1831. return memblock_virt_alloc(size, align);
  1832. }
  1833. /*
  1834. * Create base device tree for the overlay unittest.
  1835. *
  1836. * This is called from very early boot code.
  1837. *
  1838. * Do as much as possible the same way as done in __unflatten_device_tree
  1839. * and other early boot steps for the normal FDT so that the overlay base
  1840. * unflattened tree will have the same characteristics as the real tree
  1841. * (such as having memory allocated by the early allocator). The goal
  1842. * is to test "the real thing" as much as possible, and test "test setup
  1843. * code" as little as possible.
  1844. *
  1845. * Have to stop before resolving phandles, because that uses kmalloc.
  1846. */
  1847. void __init unittest_unflatten_overlay_base(void)
  1848. {
  1849. struct overlay_info *info;
  1850. u32 data_size;
  1851. void *new_fdt;
  1852. u32 size;
  1853. info = &overlays[0];
  1854. if (info->expected_result != -9999) {
  1855. pr_err("No dtb 'overlay_base' to attach\n");
  1856. return;
  1857. }
  1858. data_size = info->dtb_end - info->dtb_begin;
  1859. if (!data_size) {
  1860. pr_err("No dtb 'overlay_base' to attach\n");
  1861. return;
  1862. }
  1863. size = fdt_totalsize(info->dtb_begin);
  1864. if (size != data_size) {
  1865. pr_err("dtb 'overlay_base' header totalsize != actual size");
  1866. return;
  1867. }
  1868. new_fdt = dt_alloc_memory(size, roundup_pow_of_two(FDT_V17_SIZE));
  1869. if (!new_fdt) {
  1870. pr_err("alloc for dtb 'overlay_base' failed");
  1871. return;
  1872. }
  1873. memcpy(new_fdt, info->dtb_begin, size);
  1874. __unflatten_device_tree(new_fdt, NULL, &overlay_base_root,
  1875. dt_alloc_memory, true);
  1876. }
  1877. /*
  1878. * The purpose of of_unittest_overlay_data_add is to add an
  1879. * overlay in the normal fashion. This is a test of the whole
  1880. * picture, instead of testing individual elements.
  1881. *
  1882. * A secondary purpose is to be able to verify that the contents of
  1883. * /proc/device-tree/ contains the updated structure and values from
  1884. * the overlay. That must be verified separately in user space.
  1885. *
  1886. * Return 0 on unexpected error.
  1887. */
  1888. static int __init overlay_data_apply(const char *overlay_name, int *overlay_id)
  1889. {
  1890. struct overlay_info *info;
  1891. int found = 0;
  1892. int k;
  1893. int ret;
  1894. u32 size;
  1895. for (k = 0, info = overlays; info && info->name; info++, k++) {
  1896. if (!strcmp(overlay_name, info->name)) {
  1897. found = 1;
  1898. break;
  1899. }
  1900. }
  1901. if (!found) {
  1902. pr_err("no overlay data for %s\n", overlay_name);
  1903. return 0;
  1904. }
  1905. size = info->dtb_end - info->dtb_begin;
  1906. if (!size)
  1907. pr_err("no overlay data for %s\n", overlay_name);
  1908. ret = of_overlay_fdt_apply(info->dtb_begin, size, &info->overlay_id);
  1909. if (overlay_id)
  1910. *overlay_id = info->overlay_id;
  1911. if (ret < 0)
  1912. goto out;
  1913. pr_debug("%s applied\n", overlay_name);
  1914. out:
  1915. if (ret != info->expected_result)
  1916. pr_err("of_overlay_fdt_apply() expected %d, ret=%d, %s\n",
  1917. info->expected_result, ret, overlay_name);
  1918. return (ret == info->expected_result);
  1919. }
  1920. /*
  1921. * The purpose of of_unittest_overlay_high_level is to add an overlay
  1922. * in the normal fashion. This is a test of the whole picture,
  1923. * instead of individual elements.
  1924. *
  1925. * The first part of the function is _not_ normal overlay usage; it is
  1926. * finishing splicing the base overlay device tree into the live tree.
  1927. */
  1928. static __init void of_unittest_overlay_high_level(void)
  1929. {
  1930. struct device_node *last_sibling;
  1931. struct device_node *np;
  1932. struct device_node *of_symbols;
  1933. struct device_node *overlay_base_symbols;
  1934. struct device_node **pprev;
  1935. struct property *prop;
  1936. if (!overlay_base_root) {
  1937. unittest(0, "overlay_base_root not initialized\n");
  1938. return;
  1939. }
  1940. /*
  1941. * Could not fixup phandles in unittest_unflatten_overlay_base()
  1942. * because kmalloc() was not yet available.
  1943. */
  1944. of_overlay_mutex_lock();
  1945. of_resolve_phandles(overlay_base_root);
  1946. of_overlay_mutex_unlock();
  1947. /*
  1948. * do not allow overlay_base to duplicate any node already in
  1949. * tree, this greatly simplifies the code
  1950. */
  1951. /*
  1952. * remove overlay_base_root node "__local_fixups", after
  1953. * being used by of_resolve_phandles()
  1954. */
  1955. pprev = &overlay_base_root->child;
  1956. for (np = overlay_base_root->child; np; np = np->sibling) {
  1957. if (!of_node_cmp(np->name, "__local_fixups__")) {
  1958. *pprev = np->sibling;
  1959. break;
  1960. }
  1961. pprev = &np->sibling;
  1962. }
  1963. /* remove overlay_base_root node "__symbols__" if in live tree */
  1964. of_symbols = of_get_child_by_name(of_root, "__symbols__");
  1965. if (of_symbols) {
  1966. /* will have to graft properties from node into live tree */
  1967. pprev = &overlay_base_root->child;
  1968. for (np = overlay_base_root->child; np; np = np->sibling) {
  1969. if (!of_node_cmp(np->name, "__symbols__")) {
  1970. overlay_base_symbols = np;
  1971. *pprev = np->sibling;
  1972. break;
  1973. }
  1974. pprev = &np->sibling;
  1975. }
  1976. }
  1977. for (np = overlay_base_root->child; np; np = np->sibling) {
  1978. if (of_get_child_by_name(of_root, np->name)) {
  1979. unittest(0, "illegal node name in overlay_base %s",
  1980. np->name);
  1981. return;
  1982. }
  1983. }
  1984. /*
  1985. * overlay 'overlay_base' is not allowed to have root
  1986. * properties, so only need to splice nodes into main device tree.
  1987. *
  1988. * root node of *overlay_base_root will not be freed, it is lost
  1989. * memory.
  1990. */
  1991. for (np = overlay_base_root->child; np; np = np->sibling)
  1992. np->parent = of_root;
  1993. mutex_lock(&of_mutex);
  1994. for (last_sibling = np = of_root->child; np; np = np->sibling)
  1995. last_sibling = np;
  1996. if (last_sibling)
  1997. last_sibling->sibling = overlay_base_root->child;
  1998. else
  1999. of_root->child = overlay_base_root->child;
  2000. for_each_of_allnodes_from(overlay_base_root, np)
  2001. __of_attach_node_sysfs(np);
  2002. if (of_symbols) {
  2003. struct property *new_prop;
  2004. for_each_property_of_node(overlay_base_symbols, prop) {
  2005. new_prop = __of_prop_dup(prop, GFP_KERNEL);
  2006. if (!new_prop) {
  2007. unittest(0, "__of_prop_dup() of '%s' from overlay_base node __symbols__",
  2008. prop->name);
  2009. goto err_unlock;
  2010. }
  2011. if (__of_add_property(of_symbols, new_prop)) {
  2012. /* "name" auto-generated by unflatten */
  2013. if (!strcmp(new_prop->name, "name"))
  2014. continue;
  2015. unittest(0, "duplicate property '%s' in overlay_base node __symbols__",
  2016. prop->name);
  2017. goto err_unlock;
  2018. }
  2019. if (__of_add_property_sysfs(of_symbols, new_prop)) {
  2020. unittest(0, "unable to add property '%s' in overlay_base node __symbols__ to sysfs",
  2021. prop->name);
  2022. goto err_unlock;
  2023. }
  2024. }
  2025. }
  2026. mutex_unlock(&of_mutex);
  2027. /* now do the normal overlay usage test */
  2028. unittest(overlay_data_apply("overlay", NULL),
  2029. "Adding overlay 'overlay' failed\n");
  2030. unittest(overlay_data_apply("overlay_bad_phandle", NULL),
  2031. "Adding overlay 'overlay_bad_phandle' failed\n");
  2032. unittest(overlay_data_apply("overlay_bad_symbol", NULL),
  2033. "Adding overlay 'overlay_bad_symbol' failed\n");
  2034. return;
  2035. err_unlock:
  2036. mutex_unlock(&of_mutex);
  2037. }
  2038. #else
  2039. static inline __init void of_unittest_overlay_high_level(void) {}
  2040. #endif
  2041. static int __init of_unittest(void)
  2042. {
  2043. struct device_node *np;
  2044. int res;
  2045. /* adding data for unittest */
  2046. res = unittest_data_add();
  2047. if (res)
  2048. return res;
  2049. if (!of_aliases)
  2050. of_aliases = of_find_node_by_path("/aliases");
  2051. np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
  2052. if (!np) {
  2053. pr_info("No testcase data in device tree; not running tests\n");
  2054. return 0;
  2055. }
  2056. of_node_put(np);
  2057. pr_info("start of unittest - you will see error messages\n");
  2058. of_unittest_check_tree_linkage();
  2059. of_unittest_check_phandles();
  2060. of_unittest_find_node_by_name();
  2061. of_unittest_dynamic();
  2062. of_unittest_parse_phandle_with_args();
  2063. of_unittest_parse_phandle_with_args_map();
  2064. of_unittest_printf();
  2065. of_unittest_property_string();
  2066. of_unittest_property_copy();
  2067. of_unittest_changeset();
  2068. of_unittest_parse_interrupts();
  2069. of_unittest_parse_interrupts_extended();
  2070. of_unittest_match_node();
  2071. of_unittest_platform_populate();
  2072. of_unittest_overlay();
  2073. /* Double check linkage after removing testcase data */
  2074. of_unittest_check_tree_linkage();
  2075. of_unittest_overlay_high_level();
  2076. pr_info("end of unittest - %i passed, %i failed\n",
  2077. unittest_results.passed, unittest_results.failed);
  2078. return 0;
  2079. }
  2080. late_initcall(of_unittest);