unittest.c 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480
  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 = kcalloc(4, sizeof(*prop), 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) + 1;
  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) + 1;
  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) + 1;
  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) + 1;
  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, 0);
  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. overlay_name = overlay_name_from_nr(overlay_nr);
  1209. if (!overlay_data_apply(overlay_name, overlay_id)) {
  1210. unittest(0, "could not apply overlay \"%s\"\n",
  1211. overlay_name);
  1212. return -EFAULT;
  1213. }
  1214. of_unittest_track_overlay(*overlay_id);
  1215. return 0;
  1216. }
  1217. /* apply an overlay while checking before and after states */
  1218. static int __init of_unittest_apply_overlay_check(int overlay_nr,
  1219. int unittest_nr, int before, int after,
  1220. enum overlay_type ovtype)
  1221. {
  1222. int ret, ovcs_id;
  1223. /* unittest device must not be in before state */
  1224. if (of_unittest_device_exists(unittest_nr, ovtype) != before) {
  1225. unittest(0, "%s with device @\"%s\" %s\n",
  1226. overlay_name_from_nr(overlay_nr),
  1227. unittest_path(unittest_nr, ovtype),
  1228. !before ? "enabled" : "disabled");
  1229. return -EINVAL;
  1230. }
  1231. ovcs_id = 0;
  1232. ret = of_unittest_apply_overlay(overlay_nr, unittest_nr, &ovcs_id);
  1233. if (ret != 0) {
  1234. /* of_unittest_apply_overlay already called unittest() */
  1235. return ret;
  1236. }
  1237. /* unittest device must be to set to after state */
  1238. if (of_unittest_device_exists(unittest_nr, ovtype) != after) {
  1239. unittest(0, "%s failed to create @\"%s\" %s\n",
  1240. overlay_name_from_nr(overlay_nr),
  1241. unittest_path(unittest_nr, ovtype),
  1242. !after ? "enabled" : "disabled");
  1243. return -EINVAL;
  1244. }
  1245. return 0;
  1246. }
  1247. /* apply an overlay and then revert it while checking before, after states */
  1248. static int __init of_unittest_apply_revert_overlay_check(int overlay_nr,
  1249. int unittest_nr, int before, int after,
  1250. enum overlay_type ovtype)
  1251. {
  1252. int ret, ovcs_id;
  1253. /* unittest device must be in before state */
  1254. if (of_unittest_device_exists(unittest_nr, ovtype) != before) {
  1255. unittest(0, "%s with device @\"%s\" %s\n",
  1256. overlay_name_from_nr(overlay_nr),
  1257. unittest_path(unittest_nr, ovtype),
  1258. !before ? "enabled" : "disabled");
  1259. return -EINVAL;
  1260. }
  1261. /* apply the overlay */
  1262. ovcs_id = 0;
  1263. ret = of_unittest_apply_overlay(overlay_nr, unittest_nr, &ovcs_id);
  1264. if (ret != 0) {
  1265. /* of_unittest_apply_overlay already called unittest() */
  1266. return ret;
  1267. }
  1268. /* unittest device must be in after state */
  1269. if (of_unittest_device_exists(unittest_nr, ovtype) != after) {
  1270. unittest(0, "%s failed to create @\"%s\" %s\n",
  1271. overlay_name_from_nr(overlay_nr),
  1272. unittest_path(unittest_nr, ovtype),
  1273. !after ? "enabled" : "disabled");
  1274. return -EINVAL;
  1275. }
  1276. ret = of_overlay_remove(&ovcs_id);
  1277. if (ret != 0) {
  1278. unittest(0, "%s failed to be destroyed @\"%s\"\n",
  1279. overlay_name_from_nr(overlay_nr),
  1280. unittest_path(unittest_nr, ovtype));
  1281. return ret;
  1282. }
  1283. /* unittest device must be again in before state */
  1284. if (of_unittest_device_exists(unittest_nr, PDEV_OVERLAY) != before) {
  1285. unittest(0, "%s with device @\"%s\" %s\n",
  1286. overlay_name_from_nr(overlay_nr),
  1287. unittest_path(unittest_nr, ovtype),
  1288. !before ? "enabled" : "disabled");
  1289. return -EINVAL;
  1290. }
  1291. return 0;
  1292. }
  1293. /* test activation of device */
  1294. static void __init of_unittest_overlay_0(void)
  1295. {
  1296. /* device should enable */
  1297. if (of_unittest_apply_overlay_check(0, 0, 0, 1, PDEV_OVERLAY))
  1298. return;
  1299. unittest(1, "overlay test %d passed\n", 0);
  1300. }
  1301. /* test deactivation of device */
  1302. static void __init of_unittest_overlay_1(void)
  1303. {
  1304. /* device should disable */
  1305. if (of_unittest_apply_overlay_check(1, 1, 1, 0, PDEV_OVERLAY))
  1306. return;
  1307. unittest(1, "overlay test %d passed\n", 1);
  1308. }
  1309. /* test activation of device */
  1310. static void __init of_unittest_overlay_2(void)
  1311. {
  1312. /* device should enable */
  1313. if (of_unittest_apply_overlay_check(2, 2, 0, 1, PDEV_OVERLAY))
  1314. return;
  1315. unittest(1, "overlay test %d passed\n", 2);
  1316. }
  1317. /* test deactivation of device */
  1318. static void __init of_unittest_overlay_3(void)
  1319. {
  1320. /* device should disable */
  1321. if (of_unittest_apply_overlay_check(3, 3, 1, 0, PDEV_OVERLAY))
  1322. return;
  1323. unittest(1, "overlay test %d passed\n", 3);
  1324. }
  1325. /* test activation of a full device node */
  1326. static void __init of_unittest_overlay_4(void)
  1327. {
  1328. /* device should disable */
  1329. if (of_unittest_apply_overlay_check(4, 4, 0, 1, PDEV_OVERLAY))
  1330. return;
  1331. unittest(1, "overlay test %d passed\n", 4);
  1332. }
  1333. /* test overlay apply/revert sequence */
  1334. static void __init of_unittest_overlay_5(void)
  1335. {
  1336. /* device should disable */
  1337. if (of_unittest_apply_revert_overlay_check(5, 5, 0, 1, PDEV_OVERLAY))
  1338. return;
  1339. unittest(1, "overlay test %d passed\n", 5);
  1340. }
  1341. /* test overlay application in sequence */
  1342. static void __init of_unittest_overlay_6(void)
  1343. {
  1344. int i, ov_id[2], ovcs_id;
  1345. int overlay_nr = 6, unittest_nr = 6;
  1346. int before = 0, after = 1;
  1347. const char *overlay_name;
  1348. /* unittest device must be in before state */
  1349. for (i = 0; i < 2; i++) {
  1350. if (of_unittest_device_exists(unittest_nr + i, PDEV_OVERLAY)
  1351. != before) {
  1352. unittest(0, "%s with device @\"%s\" %s\n",
  1353. overlay_name_from_nr(overlay_nr + i),
  1354. unittest_path(unittest_nr + i,
  1355. PDEV_OVERLAY),
  1356. !before ? "enabled" : "disabled");
  1357. return;
  1358. }
  1359. }
  1360. /* apply the overlays */
  1361. for (i = 0; i < 2; i++) {
  1362. overlay_name = overlay_name_from_nr(overlay_nr + i);
  1363. if (!overlay_data_apply(overlay_name, &ovcs_id)) {
  1364. unittest(0, "could not apply overlay \"%s\"\n",
  1365. overlay_name);
  1366. return;
  1367. }
  1368. ov_id[i] = ovcs_id;
  1369. of_unittest_track_overlay(ov_id[i]);
  1370. }
  1371. for (i = 0; i < 2; i++) {
  1372. /* unittest device must be in after state */
  1373. if (of_unittest_device_exists(unittest_nr + i, PDEV_OVERLAY)
  1374. != after) {
  1375. unittest(0, "overlay @\"%s\" failed @\"%s\" %s\n",
  1376. overlay_name_from_nr(overlay_nr + i),
  1377. unittest_path(unittest_nr + i,
  1378. PDEV_OVERLAY),
  1379. !after ? "enabled" : "disabled");
  1380. return;
  1381. }
  1382. }
  1383. for (i = 1; i >= 0; i--) {
  1384. ovcs_id = ov_id[i];
  1385. if (of_overlay_remove(&ovcs_id)) {
  1386. unittest(0, "%s failed destroy @\"%s\"\n",
  1387. overlay_name_from_nr(overlay_nr + i),
  1388. unittest_path(unittest_nr + i,
  1389. PDEV_OVERLAY));
  1390. return;
  1391. }
  1392. of_unittest_untrack_overlay(ov_id[i]);
  1393. }
  1394. for (i = 0; i < 2; i++) {
  1395. /* unittest device must be again in before state */
  1396. if (of_unittest_device_exists(unittest_nr + i, PDEV_OVERLAY)
  1397. != before) {
  1398. unittest(0, "%s with device @\"%s\" %s\n",
  1399. overlay_name_from_nr(overlay_nr + i),
  1400. unittest_path(unittest_nr + i,
  1401. PDEV_OVERLAY),
  1402. !before ? "enabled" : "disabled");
  1403. return;
  1404. }
  1405. }
  1406. unittest(1, "overlay test %d passed\n", 6);
  1407. }
  1408. /* test overlay application in sequence */
  1409. static void __init of_unittest_overlay_8(void)
  1410. {
  1411. int i, ov_id[2], ovcs_id;
  1412. int overlay_nr = 8, unittest_nr = 8;
  1413. const char *overlay_name;
  1414. /* we don't care about device state in this test */
  1415. /* apply the overlays */
  1416. for (i = 0; i < 2; i++) {
  1417. overlay_name = overlay_name_from_nr(overlay_nr + i);
  1418. if (!overlay_data_apply(overlay_name, &ovcs_id)) {
  1419. unittest(0, "could not apply overlay \"%s\"\n",
  1420. overlay_name);
  1421. return;
  1422. }
  1423. ov_id[i] = ovcs_id;
  1424. of_unittest_track_overlay(ov_id[i]);
  1425. }
  1426. /* now try to remove first overlay (it should fail) */
  1427. ovcs_id = ov_id[0];
  1428. if (!of_overlay_remove(&ovcs_id)) {
  1429. unittest(0, "%s was destroyed @\"%s\"\n",
  1430. overlay_name_from_nr(overlay_nr + 0),
  1431. unittest_path(unittest_nr,
  1432. PDEV_OVERLAY));
  1433. return;
  1434. }
  1435. /* removing them in order should work */
  1436. for (i = 1; i >= 0; i--) {
  1437. ovcs_id = ov_id[i];
  1438. if (of_overlay_remove(&ovcs_id)) {
  1439. unittest(0, "%s not destroyed @\"%s\"\n",
  1440. overlay_name_from_nr(overlay_nr + i),
  1441. unittest_path(unittest_nr,
  1442. PDEV_OVERLAY));
  1443. return;
  1444. }
  1445. of_unittest_untrack_overlay(ov_id[i]);
  1446. }
  1447. unittest(1, "overlay test %d passed\n", 8);
  1448. }
  1449. /* test insertion of a bus with parent devices */
  1450. static void __init of_unittest_overlay_10(void)
  1451. {
  1452. int ret;
  1453. char *child_path;
  1454. /* device should disable */
  1455. ret = of_unittest_apply_overlay_check(10, 10, 0, 1, PDEV_OVERLAY);
  1456. if (unittest(ret == 0,
  1457. "overlay test %d failed; overlay application\n", 10))
  1458. return;
  1459. child_path = kasprintf(GFP_KERNEL, "%s/test-unittest101",
  1460. unittest_path(10, PDEV_OVERLAY));
  1461. if (unittest(child_path, "overlay test %d failed; kasprintf\n", 10))
  1462. return;
  1463. ret = of_path_device_type_exists(child_path, PDEV_OVERLAY);
  1464. kfree(child_path);
  1465. unittest(ret, "overlay test %d failed; no child device\n", 10);
  1466. }
  1467. /* test insertion of a bus with parent devices (and revert) */
  1468. static void __init of_unittest_overlay_11(void)
  1469. {
  1470. int ret;
  1471. /* device should disable */
  1472. ret = of_unittest_apply_revert_overlay_check(11, 11, 0, 1,
  1473. PDEV_OVERLAY);
  1474. unittest(ret == 0, "overlay test %d failed; overlay apply\n", 11);
  1475. }
  1476. #if IS_BUILTIN(CONFIG_I2C) && IS_ENABLED(CONFIG_OF_OVERLAY)
  1477. struct unittest_i2c_bus_data {
  1478. struct platform_device *pdev;
  1479. struct i2c_adapter adap;
  1480. };
  1481. static int unittest_i2c_master_xfer(struct i2c_adapter *adap,
  1482. struct i2c_msg *msgs, int num)
  1483. {
  1484. struct unittest_i2c_bus_data *std = i2c_get_adapdata(adap);
  1485. (void)std;
  1486. return num;
  1487. }
  1488. static u32 unittest_i2c_functionality(struct i2c_adapter *adap)
  1489. {
  1490. return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
  1491. }
  1492. static const struct i2c_algorithm unittest_i2c_algo = {
  1493. .master_xfer = unittest_i2c_master_xfer,
  1494. .functionality = unittest_i2c_functionality,
  1495. };
  1496. static int unittest_i2c_bus_probe(struct platform_device *pdev)
  1497. {
  1498. struct device *dev = &pdev->dev;
  1499. struct device_node *np = dev->of_node;
  1500. struct unittest_i2c_bus_data *std;
  1501. struct i2c_adapter *adap;
  1502. int ret;
  1503. if (np == NULL) {
  1504. dev_err(dev, "No OF data for device\n");
  1505. return -EINVAL;
  1506. }
  1507. dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
  1508. std = devm_kzalloc(dev, sizeof(*std), GFP_KERNEL);
  1509. if (!std) {
  1510. dev_err(dev, "Failed to allocate unittest i2c data\n");
  1511. return -ENOMEM;
  1512. }
  1513. /* link them together */
  1514. std->pdev = pdev;
  1515. platform_set_drvdata(pdev, std);
  1516. adap = &std->adap;
  1517. i2c_set_adapdata(adap, std);
  1518. adap->nr = -1;
  1519. strlcpy(adap->name, pdev->name, sizeof(adap->name));
  1520. adap->class = I2C_CLASS_DEPRECATED;
  1521. adap->algo = &unittest_i2c_algo;
  1522. adap->dev.parent = dev;
  1523. adap->dev.of_node = dev->of_node;
  1524. adap->timeout = 5 * HZ;
  1525. adap->retries = 3;
  1526. ret = i2c_add_numbered_adapter(adap);
  1527. if (ret != 0) {
  1528. dev_err(dev, "Failed to add I2C adapter\n");
  1529. return ret;
  1530. }
  1531. return 0;
  1532. }
  1533. static int unittest_i2c_bus_remove(struct platform_device *pdev)
  1534. {
  1535. struct device *dev = &pdev->dev;
  1536. struct device_node *np = dev->of_node;
  1537. struct unittest_i2c_bus_data *std = platform_get_drvdata(pdev);
  1538. dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
  1539. i2c_del_adapter(&std->adap);
  1540. return 0;
  1541. }
  1542. static const struct of_device_id unittest_i2c_bus_match[] = {
  1543. { .compatible = "unittest-i2c-bus", },
  1544. {},
  1545. };
  1546. static struct platform_driver unittest_i2c_bus_driver = {
  1547. .probe = unittest_i2c_bus_probe,
  1548. .remove = unittest_i2c_bus_remove,
  1549. .driver = {
  1550. .name = "unittest-i2c-bus",
  1551. .of_match_table = of_match_ptr(unittest_i2c_bus_match),
  1552. },
  1553. };
  1554. static int unittest_i2c_dev_probe(struct i2c_client *client,
  1555. const struct i2c_device_id *id)
  1556. {
  1557. struct device *dev = &client->dev;
  1558. struct device_node *np = client->dev.of_node;
  1559. if (!np) {
  1560. dev_err(dev, "No OF node\n");
  1561. return -EINVAL;
  1562. }
  1563. dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
  1564. return 0;
  1565. };
  1566. static int unittest_i2c_dev_remove(struct i2c_client *client)
  1567. {
  1568. struct device *dev = &client->dev;
  1569. struct device_node *np = client->dev.of_node;
  1570. dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
  1571. return 0;
  1572. }
  1573. static const struct i2c_device_id unittest_i2c_dev_id[] = {
  1574. { .name = "unittest-i2c-dev" },
  1575. { }
  1576. };
  1577. static struct i2c_driver unittest_i2c_dev_driver = {
  1578. .driver = {
  1579. .name = "unittest-i2c-dev",
  1580. },
  1581. .probe = unittest_i2c_dev_probe,
  1582. .remove = unittest_i2c_dev_remove,
  1583. .id_table = unittest_i2c_dev_id,
  1584. };
  1585. #if IS_BUILTIN(CONFIG_I2C_MUX)
  1586. static int unittest_i2c_mux_select_chan(struct i2c_mux_core *muxc, u32 chan)
  1587. {
  1588. return 0;
  1589. }
  1590. static int unittest_i2c_mux_probe(struct i2c_client *client,
  1591. const struct i2c_device_id *id)
  1592. {
  1593. int i, nchans;
  1594. struct device *dev = &client->dev;
  1595. struct i2c_adapter *adap = to_i2c_adapter(dev->parent);
  1596. struct device_node *np = client->dev.of_node, *child;
  1597. struct i2c_mux_core *muxc;
  1598. u32 reg, max_reg;
  1599. dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
  1600. if (!np) {
  1601. dev_err(dev, "No OF node\n");
  1602. return -EINVAL;
  1603. }
  1604. max_reg = (u32)-1;
  1605. for_each_child_of_node(np, child) {
  1606. if (of_property_read_u32(child, "reg", &reg))
  1607. continue;
  1608. if (max_reg == (u32)-1 || reg > max_reg)
  1609. max_reg = reg;
  1610. }
  1611. nchans = max_reg == (u32)-1 ? 0 : max_reg + 1;
  1612. if (nchans == 0) {
  1613. dev_err(dev, "No channels\n");
  1614. return -EINVAL;
  1615. }
  1616. muxc = i2c_mux_alloc(adap, dev, nchans, 0, 0,
  1617. unittest_i2c_mux_select_chan, NULL);
  1618. if (!muxc)
  1619. return -ENOMEM;
  1620. for (i = 0; i < nchans; i++) {
  1621. if (i2c_mux_add_adapter(muxc, 0, i, 0)) {
  1622. dev_err(dev, "Failed to register mux #%d\n", i);
  1623. i2c_mux_del_adapters(muxc);
  1624. return -ENODEV;
  1625. }
  1626. }
  1627. i2c_set_clientdata(client, muxc);
  1628. return 0;
  1629. };
  1630. static int unittest_i2c_mux_remove(struct i2c_client *client)
  1631. {
  1632. struct device *dev = &client->dev;
  1633. struct device_node *np = client->dev.of_node;
  1634. struct i2c_mux_core *muxc = i2c_get_clientdata(client);
  1635. dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
  1636. i2c_mux_del_adapters(muxc);
  1637. return 0;
  1638. }
  1639. static const struct i2c_device_id unittest_i2c_mux_id[] = {
  1640. { .name = "unittest-i2c-mux" },
  1641. { }
  1642. };
  1643. static struct i2c_driver unittest_i2c_mux_driver = {
  1644. .driver = {
  1645. .name = "unittest-i2c-mux",
  1646. },
  1647. .probe = unittest_i2c_mux_probe,
  1648. .remove = unittest_i2c_mux_remove,
  1649. .id_table = unittest_i2c_mux_id,
  1650. };
  1651. #endif
  1652. static int of_unittest_overlay_i2c_init(void)
  1653. {
  1654. int ret;
  1655. ret = i2c_add_driver(&unittest_i2c_dev_driver);
  1656. if (unittest(ret == 0,
  1657. "could not register unittest i2c device driver\n"))
  1658. return ret;
  1659. ret = platform_driver_register(&unittest_i2c_bus_driver);
  1660. if (unittest(ret == 0,
  1661. "could not register unittest i2c bus driver\n"))
  1662. return ret;
  1663. #if IS_BUILTIN(CONFIG_I2C_MUX)
  1664. ret = i2c_add_driver(&unittest_i2c_mux_driver);
  1665. if (unittest(ret == 0,
  1666. "could not register unittest i2c mux driver\n"))
  1667. return ret;
  1668. #endif
  1669. return 0;
  1670. }
  1671. static void of_unittest_overlay_i2c_cleanup(void)
  1672. {
  1673. #if IS_BUILTIN(CONFIG_I2C_MUX)
  1674. i2c_del_driver(&unittest_i2c_mux_driver);
  1675. #endif
  1676. platform_driver_unregister(&unittest_i2c_bus_driver);
  1677. i2c_del_driver(&unittest_i2c_dev_driver);
  1678. }
  1679. static void __init of_unittest_overlay_i2c_12(void)
  1680. {
  1681. /* device should enable */
  1682. if (of_unittest_apply_overlay_check(12, 12, 0, 1, I2C_OVERLAY))
  1683. return;
  1684. unittest(1, "overlay test %d passed\n", 12);
  1685. }
  1686. /* test deactivation of device */
  1687. static void __init of_unittest_overlay_i2c_13(void)
  1688. {
  1689. /* device should disable */
  1690. if (of_unittest_apply_overlay_check(13, 13, 1, 0, I2C_OVERLAY))
  1691. return;
  1692. unittest(1, "overlay test %d passed\n", 13);
  1693. }
  1694. /* just check for i2c mux existence */
  1695. static void of_unittest_overlay_i2c_14(void)
  1696. {
  1697. }
  1698. static void __init of_unittest_overlay_i2c_15(void)
  1699. {
  1700. /* device should enable */
  1701. if (of_unittest_apply_overlay_check(15, 15, 0, 1, I2C_OVERLAY))
  1702. return;
  1703. unittest(1, "overlay test %d passed\n", 15);
  1704. }
  1705. #else
  1706. static inline void of_unittest_overlay_i2c_14(void) { }
  1707. static inline void of_unittest_overlay_i2c_15(void) { }
  1708. #endif
  1709. static void __init of_unittest_overlay(void)
  1710. {
  1711. struct device_node *bus_np = NULL;
  1712. if (platform_driver_register(&unittest_driver)) {
  1713. unittest(0, "could not register unittest driver\n");
  1714. goto out;
  1715. }
  1716. bus_np = of_find_node_by_path(bus_path);
  1717. if (bus_np == NULL) {
  1718. unittest(0, "could not find bus_path \"%s\"\n", bus_path);
  1719. goto out;
  1720. }
  1721. if (of_platform_default_populate(bus_np, NULL, NULL)) {
  1722. unittest(0, "could not populate bus @ \"%s\"\n", bus_path);
  1723. goto out;
  1724. }
  1725. if (!of_unittest_device_exists(100, PDEV_OVERLAY)) {
  1726. unittest(0, "could not find unittest0 @ \"%s\"\n",
  1727. unittest_path(100, PDEV_OVERLAY));
  1728. goto out;
  1729. }
  1730. if (of_unittest_device_exists(101, PDEV_OVERLAY)) {
  1731. unittest(0, "unittest1 @ \"%s\" should not exist\n",
  1732. unittest_path(101, PDEV_OVERLAY));
  1733. goto out;
  1734. }
  1735. unittest(1, "basic infrastructure of overlays passed");
  1736. /* tests in sequence */
  1737. of_unittest_overlay_0();
  1738. of_unittest_overlay_1();
  1739. of_unittest_overlay_2();
  1740. of_unittest_overlay_3();
  1741. of_unittest_overlay_4();
  1742. of_unittest_overlay_5();
  1743. of_unittest_overlay_6();
  1744. of_unittest_overlay_8();
  1745. of_unittest_overlay_10();
  1746. of_unittest_overlay_11();
  1747. #if IS_BUILTIN(CONFIG_I2C)
  1748. if (unittest(of_unittest_overlay_i2c_init() == 0, "i2c init failed\n"))
  1749. goto out;
  1750. of_unittest_overlay_i2c_12();
  1751. of_unittest_overlay_i2c_13();
  1752. of_unittest_overlay_i2c_14();
  1753. of_unittest_overlay_i2c_15();
  1754. of_unittest_overlay_i2c_cleanup();
  1755. #endif
  1756. of_unittest_destroy_tracked_overlays();
  1757. out:
  1758. of_node_put(bus_np);
  1759. }
  1760. #else
  1761. static inline void __init of_unittest_overlay(void) { }
  1762. #endif
  1763. #ifdef CONFIG_OF_OVERLAY
  1764. /*
  1765. * __dtb_ot_begin[] and __dtb_ot_end[] are created by cmd_dt_S_dtb
  1766. * in scripts/Makefile.lib
  1767. */
  1768. #define OVERLAY_INFO_EXTERN(name) \
  1769. extern uint8_t __dtb_##name##_begin[]; \
  1770. extern uint8_t __dtb_##name##_end[]
  1771. #define OVERLAY_INFO(overlay_name, expected) \
  1772. { .dtb_begin = __dtb_##overlay_name##_begin, \
  1773. .dtb_end = __dtb_##overlay_name##_end, \
  1774. .expected_result = expected, \
  1775. .name = #overlay_name, \
  1776. }
  1777. struct overlay_info {
  1778. uint8_t *dtb_begin;
  1779. uint8_t *dtb_end;
  1780. int expected_result;
  1781. int overlay_id;
  1782. char *name;
  1783. };
  1784. OVERLAY_INFO_EXTERN(overlay_base);
  1785. OVERLAY_INFO_EXTERN(overlay);
  1786. OVERLAY_INFO_EXTERN(overlay_0);
  1787. OVERLAY_INFO_EXTERN(overlay_1);
  1788. OVERLAY_INFO_EXTERN(overlay_2);
  1789. OVERLAY_INFO_EXTERN(overlay_3);
  1790. OVERLAY_INFO_EXTERN(overlay_4);
  1791. OVERLAY_INFO_EXTERN(overlay_5);
  1792. OVERLAY_INFO_EXTERN(overlay_6);
  1793. OVERLAY_INFO_EXTERN(overlay_7);
  1794. OVERLAY_INFO_EXTERN(overlay_8);
  1795. OVERLAY_INFO_EXTERN(overlay_9);
  1796. OVERLAY_INFO_EXTERN(overlay_10);
  1797. OVERLAY_INFO_EXTERN(overlay_11);
  1798. OVERLAY_INFO_EXTERN(overlay_12);
  1799. OVERLAY_INFO_EXTERN(overlay_13);
  1800. OVERLAY_INFO_EXTERN(overlay_15);
  1801. OVERLAY_INFO_EXTERN(overlay_bad_phandle);
  1802. OVERLAY_INFO_EXTERN(overlay_bad_symbol);
  1803. /* order of entries is hard-coded into users of overlays[] */
  1804. static struct overlay_info overlays[] = {
  1805. OVERLAY_INFO(overlay_base, -9999),
  1806. OVERLAY_INFO(overlay, 0),
  1807. OVERLAY_INFO(overlay_0, 0),
  1808. OVERLAY_INFO(overlay_1, 0),
  1809. OVERLAY_INFO(overlay_2, 0),
  1810. OVERLAY_INFO(overlay_3, 0),
  1811. OVERLAY_INFO(overlay_4, 0),
  1812. OVERLAY_INFO(overlay_5, 0),
  1813. OVERLAY_INFO(overlay_6, 0),
  1814. OVERLAY_INFO(overlay_7, 0),
  1815. OVERLAY_INFO(overlay_8, 0),
  1816. OVERLAY_INFO(overlay_9, 0),
  1817. OVERLAY_INFO(overlay_10, 0),
  1818. OVERLAY_INFO(overlay_11, 0),
  1819. OVERLAY_INFO(overlay_12, 0),
  1820. OVERLAY_INFO(overlay_13, 0),
  1821. OVERLAY_INFO(overlay_15, 0),
  1822. OVERLAY_INFO(overlay_bad_phandle, -EINVAL),
  1823. OVERLAY_INFO(overlay_bad_symbol, -EINVAL),
  1824. {}
  1825. };
  1826. static struct device_node *overlay_base_root;
  1827. static void * __init dt_alloc_memory(u64 size, u64 align)
  1828. {
  1829. return memblock_virt_alloc(size, align);
  1830. }
  1831. /*
  1832. * Create base device tree for the overlay unittest.
  1833. *
  1834. * This is called from very early boot code.
  1835. *
  1836. * Do as much as possible the same way as done in __unflatten_device_tree
  1837. * and other early boot steps for the normal FDT so that the overlay base
  1838. * unflattened tree will have the same characteristics as the real tree
  1839. * (such as having memory allocated by the early allocator). The goal
  1840. * is to test "the real thing" as much as possible, and test "test setup
  1841. * code" as little as possible.
  1842. *
  1843. * Have to stop before resolving phandles, because that uses kmalloc.
  1844. */
  1845. void __init unittest_unflatten_overlay_base(void)
  1846. {
  1847. struct overlay_info *info;
  1848. u32 data_size;
  1849. void *new_fdt;
  1850. u32 size;
  1851. info = &overlays[0];
  1852. if (info->expected_result != -9999) {
  1853. pr_err("No dtb 'overlay_base' to attach\n");
  1854. return;
  1855. }
  1856. data_size = info->dtb_end - info->dtb_begin;
  1857. if (!data_size) {
  1858. pr_err("No dtb 'overlay_base' to attach\n");
  1859. return;
  1860. }
  1861. size = fdt_totalsize(info->dtb_begin);
  1862. if (size != data_size) {
  1863. pr_err("dtb 'overlay_base' header totalsize != actual size");
  1864. return;
  1865. }
  1866. new_fdt = dt_alloc_memory(size, roundup_pow_of_two(FDT_V17_SIZE));
  1867. if (!new_fdt) {
  1868. pr_err("alloc for dtb 'overlay_base' failed");
  1869. return;
  1870. }
  1871. memcpy(new_fdt, info->dtb_begin, size);
  1872. __unflatten_device_tree(new_fdt, NULL, &overlay_base_root,
  1873. dt_alloc_memory, true);
  1874. }
  1875. /*
  1876. * The purpose of of_unittest_overlay_data_add is to add an
  1877. * overlay in the normal fashion. This is a test of the whole
  1878. * picture, instead of testing individual elements.
  1879. *
  1880. * A secondary purpose is to be able to verify that the contents of
  1881. * /proc/device-tree/ contains the updated structure and values from
  1882. * the overlay. That must be verified separately in user space.
  1883. *
  1884. * Return 0 on unexpected error.
  1885. */
  1886. static int __init overlay_data_apply(const char *overlay_name, int *overlay_id)
  1887. {
  1888. struct overlay_info *info;
  1889. int found = 0;
  1890. int k;
  1891. int ret;
  1892. u32 size;
  1893. for (k = 0, info = overlays; info && info->name; info++, k++) {
  1894. if (!strcmp(overlay_name, info->name)) {
  1895. found = 1;
  1896. break;
  1897. }
  1898. }
  1899. if (!found) {
  1900. pr_err("no overlay data for %s\n", overlay_name);
  1901. return 0;
  1902. }
  1903. size = info->dtb_end - info->dtb_begin;
  1904. if (!size)
  1905. pr_err("no overlay data for %s\n", overlay_name);
  1906. ret = of_overlay_fdt_apply(info->dtb_begin, size, &info->overlay_id);
  1907. if (overlay_id)
  1908. *overlay_id = info->overlay_id;
  1909. if (ret < 0)
  1910. goto out;
  1911. pr_debug("%s applied\n", overlay_name);
  1912. out:
  1913. if (ret != info->expected_result)
  1914. pr_err("of_overlay_fdt_apply() expected %d, ret=%d, %s\n",
  1915. info->expected_result, ret, overlay_name);
  1916. return (ret == info->expected_result);
  1917. }
  1918. /*
  1919. * The purpose of of_unittest_overlay_high_level is to add an overlay
  1920. * in the normal fashion. This is a test of the whole picture,
  1921. * instead of individual elements.
  1922. *
  1923. * The first part of the function is _not_ normal overlay usage; it is
  1924. * finishing splicing the base overlay device tree into the live tree.
  1925. */
  1926. static __init void of_unittest_overlay_high_level(void)
  1927. {
  1928. struct device_node *last_sibling;
  1929. struct device_node *np;
  1930. struct device_node *of_symbols;
  1931. struct device_node *overlay_base_symbols;
  1932. struct device_node **pprev;
  1933. struct property *prop;
  1934. if (!overlay_base_root) {
  1935. unittest(0, "overlay_base_root not initialized\n");
  1936. return;
  1937. }
  1938. /*
  1939. * Could not fixup phandles in unittest_unflatten_overlay_base()
  1940. * because kmalloc() was not yet available.
  1941. */
  1942. of_overlay_mutex_lock();
  1943. of_resolve_phandles(overlay_base_root);
  1944. of_overlay_mutex_unlock();
  1945. /*
  1946. * do not allow overlay_base to duplicate any node already in
  1947. * tree, this greatly simplifies the code
  1948. */
  1949. /*
  1950. * remove overlay_base_root node "__local_fixups", after
  1951. * being used by of_resolve_phandles()
  1952. */
  1953. pprev = &overlay_base_root->child;
  1954. for (np = overlay_base_root->child; np; np = np->sibling) {
  1955. if (!of_node_cmp(np->name, "__local_fixups__")) {
  1956. *pprev = np->sibling;
  1957. break;
  1958. }
  1959. pprev = &np->sibling;
  1960. }
  1961. /* remove overlay_base_root node "__symbols__" if in live tree */
  1962. of_symbols = of_get_child_by_name(of_root, "__symbols__");
  1963. if (of_symbols) {
  1964. /* will have to graft properties from node into live tree */
  1965. pprev = &overlay_base_root->child;
  1966. for (np = overlay_base_root->child; np; np = np->sibling) {
  1967. if (!of_node_cmp(np->name, "__symbols__")) {
  1968. overlay_base_symbols = np;
  1969. *pprev = np->sibling;
  1970. break;
  1971. }
  1972. pprev = &np->sibling;
  1973. }
  1974. }
  1975. for (np = overlay_base_root->child; np; np = np->sibling) {
  1976. if (of_get_child_by_name(of_root, np->name)) {
  1977. unittest(0, "illegal node name in overlay_base %s",
  1978. np->name);
  1979. return;
  1980. }
  1981. }
  1982. /*
  1983. * overlay 'overlay_base' is not allowed to have root
  1984. * properties, so only need to splice nodes into main device tree.
  1985. *
  1986. * root node of *overlay_base_root will not be freed, it is lost
  1987. * memory.
  1988. */
  1989. for (np = overlay_base_root->child; np; np = np->sibling)
  1990. np->parent = of_root;
  1991. mutex_lock(&of_mutex);
  1992. for (last_sibling = np = of_root->child; np; np = np->sibling)
  1993. last_sibling = np;
  1994. if (last_sibling)
  1995. last_sibling->sibling = overlay_base_root->child;
  1996. else
  1997. of_root->child = overlay_base_root->child;
  1998. for_each_of_allnodes_from(overlay_base_root, np)
  1999. __of_attach_node_sysfs(np);
  2000. if (of_symbols) {
  2001. struct property *new_prop;
  2002. for_each_property_of_node(overlay_base_symbols, prop) {
  2003. new_prop = __of_prop_dup(prop, GFP_KERNEL);
  2004. if (!new_prop) {
  2005. unittest(0, "__of_prop_dup() of '%s' from overlay_base node __symbols__",
  2006. prop->name);
  2007. goto err_unlock;
  2008. }
  2009. if (__of_add_property(of_symbols, new_prop)) {
  2010. /* "name" auto-generated by unflatten */
  2011. if (!strcmp(new_prop->name, "name"))
  2012. continue;
  2013. unittest(0, "duplicate property '%s' in overlay_base node __symbols__",
  2014. prop->name);
  2015. goto err_unlock;
  2016. }
  2017. if (__of_add_property_sysfs(of_symbols, new_prop)) {
  2018. unittest(0, "unable to add property '%s' in overlay_base node __symbols__ to sysfs",
  2019. prop->name);
  2020. goto err_unlock;
  2021. }
  2022. }
  2023. }
  2024. mutex_unlock(&of_mutex);
  2025. /* now do the normal overlay usage test */
  2026. unittest(overlay_data_apply("overlay", NULL),
  2027. "Adding overlay 'overlay' failed\n");
  2028. unittest(overlay_data_apply("overlay_bad_phandle", NULL),
  2029. "Adding overlay 'overlay_bad_phandle' failed\n");
  2030. unittest(overlay_data_apply("overlay_bad_symbol", NULL),
  2031. "Adding overlay 'overlay_bad_symbol' failed\n");
  2032. return;
  2033. err_unlock:
  2034. mutex_unlock(&of_mutex);
  2035. }
  2036. #else
  2037. static inline __init void of_unittest_overlay_high_level(void) {}
  2038. #endif
  2039. static int __init of_unittest(void)
  2040. {
  2041. struct device_node *np;
  2042. int res;
  2043. /* adding data for unittest */
  2044. res = unittest_data_add();
  2045. if (res)
  2046. return res;
  2047. if (!of_aliases)
  2048. of_aliases = of_find_node_by_path("/aliases");
  2049. np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
  2050. if (!np) {
  2051. pr_info("No testcase data in device tree; not running tests\n");
  2052. return 0;
  2053. }
  2054. of_node_put(np);
  2055. pr_info("start of unittest - you will see error messages\n");
  2056. of_unittest_check_tree_linkage();
  2057. of_unittest_check_phandles();
  2058. of_unittest_find_node_by_name();
  2059. of_unittest_dynamic();
  2060. of_unittest_parse_phandle_with_args();
  2061. of_unittest_parse_phandle_with_args_map();
  2062. of_unittest_printf();
  2063. of_unittest_property_string();
  2064. of_unittest_property_copy();
  2065. of_unittest_changeset();
  2066. of_unittest_parse_interrupts();
  2067. of_unittest_parse_interrupts_extended();
  2068. of_unittest_match_node();
  2069. of_unittest_platform_populate();
  2070. of_unittest_overlay();
  2071. /* Double check linkage after removing testcase data */
  2072. of_unittest_check_tree_linkage();
  2073. of_unittest_overlay_high_level();
  2074. pr_info("end of unittest - %i passed, %i failed\n",
  2075. unittest_results.passed, unittest_results.failed);
  2076. return 0;
  2077. }
  2078. late_initcall(of_unittest);