unittest.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889
  1. /*
  2. * Self tests for device tree subsystem
  3. */
  4. #define pr_fmt(fmt) "### dt-test ### " fmt
  5. #include <linux/clk.h>
  6. #include <linux/err.h>
  7. #include <linux/errno.h>
  8. #include <linux/hashtable.h>
  9. #include <linux/module.h>
  10. #include <linux/of.h>
  11. #include <linux/of_fdt.h>
  12. #include <linux/of_irq.h>
  13. #include <linux/of_platform.h>
  14. #include <linux/list.h>
  15. #include <linux/mutex.h>
  16. #include <linux/slab.h>
  17. #include <linux/device.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/of_platform.h>
  20. #include <linux/i2c.h>
  21. #include <linux/i2c-mux.h>
  22. #include "of_private.h"
  23. static struct selftest_results {
  24. int passed;
  25. int failed;
  26. } selftest_results;
  27. #define selftest(result, fmt, ...) ({ \
  28. bool failed = !(result); \
  29. if (failed) { \
  30. selftest_results.failed++; \
  31. pr_err("FAIL %s():%i " fmt, __func__, __LINE__, ##__VA_ARGS__); \
  32. } else { \
  33. selftest_results.passed++; \
  34. pr_debug("pass %s():%i\n", __func__, __LINE__); \
  35. } \
  36. failed; \
  37. })
  38. static void __init of_selftest_find_node_by_name(void)
  39. {
  40. struct device_node *np;
  41. const char *options;
  42. np = of_find_node_by_path("/testcase-data");
  43. selftest(np && !strcmp("/testcase-data", np->full_name),
  44. "find /testcase-data failed\n");
  45. of_node_put(np);
  46. /* Test if trailing '/' works */
  47. np = of_find_node_by_path("/testcase-data/");
  48. selftest(!np, "trailing '/' on /testcase-data/ should fail\n");
  49. np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
  50. selftest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", np->full_name),
  51. "find /testcase-data/phandle-tests/consumer-a failed\n");
  52. of_node_put(np);
  53. np = of_find_node_by_path("testcase-alias");
  54. selftest(np && !strcmp("/testcase-data", np->full_name),
  55. "find testcase-alias failed\n");
  56. of_node_put(np);
  57. /* Test if trailing '/' works on aliases */
  58. np = of_find_node_by_path("testcase-alias/");
  59. selftest(!np, "trailing '/' on testcase-alias/ should fail\n");
  60. np = of_find_node_by_path("testcase-alias/phandle-tests/consumer-a");
  61. selftest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", np->full_name),
  62. "find testcase-alias/phandle-tests/consumer-a failed\n");
  63. of_node_put(np);
  64. np = of_find_node_by_path("/testcase-data/missing-path");
  65. selftest(!np, "non-existent path returned node %s\n", np->full_name);
  66. of_node_put(np);
  67. np = of_find_node_by_path("missing-alias");
  68. selftest(!np, "non-existent alias returned node %s\n", np->full_name);
  69. of_node_put(np);
  70. np = of_find_node_by_path("testcase-alias/missing-path");
  71. selftest(!np, "non-existent alias with relative path returned node %s\n", np->full_name);
  72. of_node_put(np);
  73. np = of_find_node_opts_by_path("/testcase-data:testoption", &options);
  74. selftest(np && !strcmp("testoption", options),
  75. "option path test failed\n");
  76. of_node_put(np);
  77. np = of_find_node_opts_by_path("/testcase-data:test/option", &options);
  78. selftest(np && !strcmp("test/option", options),
  79. "option path test, subcase #1 failed\n");
  80. of_node_put(np);
  81. np = of_find_node_opts_by_path("/testcase-data:testoption", NULL);
  82. selftest(np, "NULL option path test failed\n");
  83. of_node_put(np);
  84. np = of_find_node_opts_by_path("testcase-alias:testaliasoption",
  85. &options);
  86. selftest(np && !strcmp("testaliasoption", options),
  87. "option alias path test failed\n");
  88. of_node_put(np);
  89. np = of_find_node_opts_by_path("testcase-alias:test/alias/option",
  90. &options);
  91. selftest(np && !strcmp("test/alias/option", options),
  92. "option alias path test, subcase #1 failed\n");
  93. of_node_put(np);
  94. np = of_find_node_opts_by_path("testcase-alias:testaliasoption", NULL);
  95. selftest(np, "NULL option alias path test failed\n");
  96. of_node_put(np);
  97. options = "testoption";
  98. np = of_find_node_opts_by_path("testcase-alias", &options);
  99. selftest(np && !options, "option clearing test failed\n");
  100. of_node_put(np);
  101. options = "testoption";
  102. np = of_find_node_opts_by_path("/", &options);
  103. selftest(np && !options, "option clearing root node test failed\n");
  104. of_node_put(np);
  105. }
  106. static void __init of_selftest_dynamic(void)
  107. {
  108. struct device_node *np;
  109. struct property *prop;
  110. np = of_find_node_by_path("/testcase-data");
  111. if (!np) {
  112. pr_err("missing testcase data\n");
  113. return;
  114. }
  115. /* Array of 4 properties for the purpose of testing */
  116. prop = kzalloc(sizeof(*prop) * 4, GFP_KERNEL);
  117. if (!prop) {
  118. selftest(0, "kzalloc() failed\n");
  119. return;
  120. }
  121. /* Add a new property - should pass*/
  122. prop->name = "new-property";
  123. prop->value = "new-property-data";
  124. prop->length = strlen(prop->value);
  125. selftest(of_add_property(np, prop) == 0, "Adding a new property failed\n");
  126. /* Try to add an existing property - should fail */
  127. prop++;
  128. prop->name = "new-property";
  129. prop->value = "new-property-data-should-fail";
  130. prop->length = strlen(prop->value);
  131. selftest(of_add_property(np, prop) != 0,
  132. "Adding an existing property should have failed\n");
  133. /* Try to modify an existing property - should pass */
  134. prop->value = "modify-property-data-should-pass";
  135. prop->length = strlen(prop->value);
  136. selftest(of_update_property(np, prop) == 0,
  137. "Updating an existing property should have passed\n");
  138. /* Try to modify non-existent property - should pass*/
  139. prop++;
  140. prop->name = "modify-property";
  141. prop->value = "modify-missing-property-data-should-pass";
  142. prop->length = strlen(prop->value);
  143. selftest(of_update_property(np, prop) == 0,
  144. "Updating a missing property should have passed\n");
  145. /* Remove property - should pass */
  146. selftest(of_remove_property(np, prop) == 0,
  147. "Removing a property should have passed\n");
  148. /* Adding very large property - should pass */
  149. prop++;
  150. prop->name = "large-property-PAGE_SIZEx8";
  151. prop->length = PAGE_SIZE * 8;
  152. prop->value = kzalloc(prop->length, GFP_KERNEL);
  153. selftest(prop->value != NULL, "Unable to allocate large buffer\n");
  154. if (prop->value)
  155. selftest(of_add_property(np, prop) == 0,
  156. "Adding a large property should have passed\n");
  157. }
  158. static int __init of_selftest_check_node_linkage(struct device_node *np)
  159. {
  160. struct device_node *child;
  161. int count = 0, rc;
  162. for_each_child_of_node(np, child) {
  163. if (child->parent != np) {
  164. pr_err("Child node %s links to wrong parent %s\n",
  165. child->name, np->name);
  166. return -EINVAL;
  167. }
  168. rc = of_selftest_check_node_linkage(child);
  169. if (rc < 0)
  170. return rc;
  171. count += rc;
  172. }
  173. return count + 1;
  174. }
  175. static void __init of_selftest_check_tree_linkage(void)
  176. {
  177. struct device_node *np;
  178. int allnode_count = 0, child_count;
  179. if (!of_root)
  180. return;
  181. for_each_of_allnodes(np)
  182. allnode_count++;
  183. child_count = of_selftest_check_node_linkage(of_root);
  184. selftest(child_count > 0, "Device node data structure is corrupted\n");
  185. selftest(child_count == allnode_count, "allnodes list size (%i) doesn't match"
  186. "sibling lists size (%i)\n", allnode_count, child_count);
  187. pr_debug("allnodes list size (%i); sibling lists size (%i)\n", allnode_count, child_count);
  188. }
  189. struct node_hash {
  190. struct hlist_node node;
  191. struct device_node *np;
  192. };
  193. static DEFINE_HASHTABLE(phandle_ht, 8);
  194. static void __init of_selftest_check_phandles(void)
  195. {
  196. struct device_node *np;
  197. struct node_hash *nh;
  198. struct hlist_node *tmp;
  199. int i, dup_count = 0, phandle_count = 0;
  200. for_each_of_allnodes(np) {
  201. if (!np->phandle)
  202. continue;
  203. hash_for_each_possible(phandle_ht, nh, node, np->phandle) {
  204. if (nh->np->phandle == np->phandle) {
  205. pr_info("Duplicate phandle! %i used by %s and %s\n",
  206. np->phandle, nh->np->full_name, np->full_name);
  207. dup_count++;
  208. break;
  209. }
  210. }
  211. nh = kzalloc(sizeof(*nh), GFP_KERNEL);
  212. if (WARN_ON(!nh))
  213. return;
  214. nh->np = np;
  215. hash_add(phandle_ht, &nh->node, np->phandle);
  216. phandle_count++;
  217. }
  218. selftest(dup_count == 0, "Found %i duplicates in %i phandles\n",
  219. dup_count, phandle_count);
  220. /* Clean up */
  221. hash_for_each_safe(phandle_ht, i, tmp, nh, node) {
  222. hash_del(&nh->node);
  223. kfree(nh);
  224. }
  225. }
  226. static void __init of_selftest_parse_phandle_with_args(void)
  227. {
  228. struct device_node *np;
  229. struct of_phandle_args args;
  230. int i, rc;
  231. np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
  232. if (!np) {
  233. pr_err("missing testcase data\n");
  234. return;
  235. }
  236. rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells");
  237. selftest(rc == 7, "of_count_phandle_with_args() returned %i, expected 7\n", rc);
  238. for (i = 0; i < 8; i++) {
  239. bool passed = true;
  240. rc = of_parse_phandle_with_args(np, "phandle-list",
  241. "#phandle-cells", i, &args);
  242. /* Test the values from tests-phandle.dtsi */
  243. switch (i) {
  244. case 0:
  245. passed &= !rc;
  246. passed &= (args.args_count == 1);
  247. passed &= (args.args[0] == (i + 1));
  248. break;
  249. case 1:
  250. passed &= !rc;
  251. passed &= (args.args_count == 2);
  252. passed &= (args.args[0] == (i + 1));
  253. passed &= (args.args[1] == 0);
  254. break;
  255. case 2:
  256. passed &= (rc == -ENOENT);
  257. break;
  258. case 3:
  259. passed &= !rc;
  260. passed &= (args.args_count == 3);
  261. passed &= (args.args[0] == (i + 1));
  262. passed &= (args.args[1] == 4);
  263. passed &= (args.args[2] == 3);
  264. break;
  265. case 4:
  266. passed &= !rc;
  267. passed &= (args.args_count == 2);
  268. passed &= (args.args[0] == (i + 1));
  269. passed &= (args.args[1] == 100);
  270. break;
  271. case 5:
  272. passed &= !rc;
  273. passed &= (args.args_count == 0);
  274. break;
  275. case 6:
  276. passed &= !rc;
  277. passed &= (args.args_count == 1);
  278. passed &= (args.args[0] == (i + 1));
  279. break;
  280. case 7:
  281. passed &= (rc == -ENOENT);
  282. break;
  283. default:
  284. passed = false;
  285. }
  286. selftest(passed, "index %i - data error on node %s rc=%i\n",
  287. i, args.np->full_name, rc);
  288. }
  289. /* Check for missing list property */
  290. rc = of_parse_phandle_with_args(np, "phandle-list-missing",
  291. "#phandle-cells", 0, &args);
  292. selftest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
  293. rc = of_count_phandle_with_args(np, "phandle-list-missing",
  294. "#phandle-cells");
  295. selftest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
  296. /* Check for missing cells property */
  297. rc = of_parse_phandle_with_args(np, "phandle-list",
  298. "#phandle-cells-missing", 0, &args);
  299. selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  300. rc = of_count_phandle_with_args(np, "phandle-list",
  301. "#phandle-cells-missing");
  302. selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  303. /* Check for bad phandle in list */
  304. rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle",
  305. "#phandle-cells", 0, &args);
  306. selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  307. rc = of_count_phandle_with_args(np, "phandle-list-bad-phandle",
  308. "#phandle-cells");
  309. selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  310. /* Check for incorrectly formed argument list */
  311. rc = of_parse_phandle_with_args(np, "phandle-list-bad-args",
  312. "#phandle-cells", 1, &args);
  313. selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  314. rc = of_count_phandle_with_args(np, "phandle-list-bad-args",
  315. "#phandle-cells");
  316. selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  317. }
  318. static void __init of_selftest_property_string(void)
  319. {
  320. const char *strings[4];
  321. struct device_node *np;
  322. int rc;
  323. np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
  324. if (!np) {
  325. pr_err("No testcase data in device tree\n");
  326. return;
  327. }
  328. rc = of_property_match_string(np, "phandle-list-names", "first");
  329. selftest(rc == 0, "first expected:0 got:%i\n", rc);
  330. rc = of_property_match_string(np, "phandle-list-names", "second");
  331. selftest(rc == 1, "second expected:1 got:%i\n", rc);
  332. rc = of_property_match_string(np, "phandle-list-names", "third");
  333. selftest(rc == 2, "third expected:2 got:%i\n", rc);
  334. rc = of_property_match_string(np, "phandle-list-names", "fourth");
  335. selftest(rc == -ENODATA, "unmatched string; rc=%i\n", rc);
  336. rc = of_property_match_string(np, "missing-property", "blah");
  337. selftest(rc == -EINVAL, "missing property; rc=%i\n", rc);
  338. rc = of_property_match_string(np, "empty-property", "blah");
  339. selftest(rc == -ENODATA, "empty property; rc=%i\n", rc);
  340. rc = of_property_match_string(np, "unterminated-string", "blah");
  341. selftest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
  342. /* of_property_count_strings() tests */
  343. rc = of_property_count_strings(np, "string-property");
  344. selftest(rc == 1, "Incorrect string count; rc=%i\n", rc);
  345. rc = of_property_count_strings(np, "phandle-list-names");
  346. selftest(rc == 3, "Incorrect string count; rc=%i\n", rc);
  347. rc = of_property_count_strings(np, "unterminated-string");
  348. selftest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
  349. rc = of_property_count_strings(np, "unterminated-string-list");
  350. selftest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc);
  351. /* of_property_read_string_index() tests */
  352. rc = of_property_read_string_index(np, "string-property", 0, strings);
  353. selftest(rc == 0 && !strcmp(strings[0], "foobar"), "of_property_read_string_index() failure; rc=%i\n", rc);
  354. strings[0] = NULL;
  355. rc = of_property_read_string_index(np, "string-property", 1, strings);
  356. selftest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
  357. rc = of_property_read_string_index(np, "phandle-list-names", 0, strings);
  358. selftest(rc == 0 && !strcmp(strings[0], "first"), "of_property_read_string_index() failure; rc=%i\n", rc);
  359. rc = of_property_read_string_index(np, "phandle-list-names", 1, strings);
  360. selftest(rc == 0 && !strcmp(strings[0], "second"), "of_property_read_string_index() failure; rc=%i\n", rc);
  361. rc = of_property_read_string_index(np, "phandle-list-names", 2, strings);
  362. selftest(rc == 0 && !strcmp(strings[0], "third"), "of_property_read_string_index() failure; rc=%i\n", rc);
  363. strings[0] = NULL;
  364. rc = of_property_read_string_index(np, "phandle-list-names", 3, strings);
  365. selftest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
  366. strings[0] = NULL;
  367. rc = of_property_read_string_index(np, "unterminated-string", 0, strings);
  368. selftest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
  369. rc = of_property_read_string_index(np, "unterminated-string-list", 0, strings);
  370. selftest(rc == 0 && !strcmp(strings[0], "first"), "of_property_read_string_index() failure; rc=%i\n", rc);
  371. strings[0] = NULL;
  372. rc = of_property_read_string_index(np, "unterminated-string-list", 2, strings); /* should fail */
  373. selftest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
  374. strings[1] = NULL;
  375. /* of_property_read_string_array() tests */
  376. rc = of_property_read_string_array(np, "string-property", strings, 4);
  377. selftest(rc == 1, "Incorrect string count; rc=%i\n", rc);
  378. rc = of_property_read_string_array(np, "phandle-list-names", strings, 4);
  379. selftest(rc == 3, "Incorrect string count; rc=%i\n", rc);
  380. rc = of_property_read_string_array(np, "unterminated-string", strings, 4);
  381. selftest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
  382. /* -- An incorrectly formed string should cause a failure */
  383. rc = of_property_read_string_array(np, "unterminated-string-list", strings, 4);
  384. selftest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc);
  385. /* -- parsing the correctly formed strings should still work: */
  386. strings[2] = NULL;
  387. rc = of_property_read_string_array(np, "unterminated-string-list", strings, 2);
  388. selftest(rc == 2 && strings[2] == NULL, "of_property_read_string_array() failure; rc=%i\n", rc);
  389. strings[1] = NULL;
  390. rc = of_property_read_string_array(np, "phandle-list-names", strings, 1);
  391. selftest(rc == 1 && strings[1] == NULL, "Overwrote end of string array; rc=%i, str='%s'\n", rc, strings[1]);
  392. }
  393. #define propcmp(p1, p2) (((p1)->length == (p2)->length) && \
  394. (p1)->value && (p2)->value && \
  395. !memcmp((p1)->value, (p2)->value, (p1)->length) && \
  396. !strcmp((p1)->name, (p2)->name))
  397. static void __init of_selftest_property_copy(void)
  398. {
  399. #ifdef CONFIG_OF_DYNAMIC
  400. struct property p1 = { .name = "p1", .length = 0, .value = "" };
  401. struct property p2 = { .name = "p2", .length = 5, .value = "abcd" };
  402. struct property *new;
  403. new = __of_prop_dup(&p1, GFP_KERNEL);
  404. selftest(new && propcmp(&p1, new), "empty property didn't copy correctly\n");
  405. kfree(new->value);
  406. kfree(new->name);
  407. kfree(new);
  408. new = __of_prop_dup(&p2, GFP_KERNEL);
  409. selftest(new && propcmp(&p2, new), "non-empty property didn't copy correctly\n");
  410. kfree(new->value);
  411. kfree(new->name);
  412. kfree(new);
  413. #endif
  414. }
  415. static void __init of_selftest_changeset(void)
  416. {
  417. #ifdef CONFIG_OF_DYNAMIC
  418. struct property *ppadd, padd = { .name = "prop-add", .length = 0, .value = "" };
  419. struct property *ppupdate, pupdate = { .name = "prop-update", .length = 5, .value = "abcd" };
  420. struct property *ppremove;
  421. struct device_node *n1, *n2, *n21, *nremove, *parent, *np;
  422. struct of_changeset chgset;
  423. n1 = __of_node_dup(NULL, "/testcase-data/changeset/n1");
  424. selftest(n1, "testcase setup failure\n");
  425. n2 = __of_node_dup(NULL, "/testcase-data/changeset/n2");
  426. selftest(n2, "testcase setup failure\n");
  427. n21 = __of_node_dup(NULL, "%s/%s", "/testcase-data/changeset/n2", "n21");
  428. selftest(n21, "testcase setup failure %p\n", n21);
  429. nremove = of_find_node_by_path("/testcase-data/changeset/node-remove");
  430. selftest(nremove, "testcase setup failure\n");
  431. ppadd = __of_prop_dup(&padd, GFP_KERNEL);
  432. selftest(ppadd, "testcase setup failure\n");
  433. ppupdate = __of_prop_dup(&pupdate, GFP_KERNEL);
  434. selftest(ppupdate, "testcase setup failure\n");
  435. parent = nremove->parent;
  436. n1->parent = parent;
  437. n2->parent = parent;
  438. n21->parent = n2;
  439. n2->child = n21;
  440. ppremove = of_find_property(parent, "prop-remove", NULL);
  441. selftest(ppremove, "failed to find removal prop");
  442. of_changeset_init(&chgset);
  443. selftest(!of_changeset_attach_node(&chgset, n1), "fail attach n1\n");
  444. selftest(!of_changeset_attach_node(&chgset, n2), "fail attach n2\n");
  445. selftest(!of_changeset_detach_node(&chgset, nremove), "fail remove node\n");
  446. selftest(!of_changeset_attach_node(&chgset, n21), "fail attach n21\n");
  447. selftest(!of_changeset_add_property(&chgset, parent, ppadd), "fail add prop\n");
  448. selftest(!of_changeset_update_property(&chgset, parent, ppupdate), "fail update prop\n");
  449. selftest(!of_changeset_remove_property(&chgset, parent, ppremove), "fail remove prop\n");
  450. mutex_lock(&of_mutex);
  451. selftest(!of_changeset_apply(&chgset), "apply failed\n");
  452. mutex_unlock(&of_mutex);
  453. /* Make sure node names are constructed correctly */
  454. selftest((np = of_find_node_by_path("/testcase-data/changeset/n2/n21")),
  455. "'%s' not added\n", n21->full_name);
  456. of_node_put(np);
  457. mutex_lock(&of_mutex);
  458. selftest(!of_changeset_revert(&chgset), "revert failed\n");
  459. mutex_unlock(&of_mutex);
  460. of_changeset_destroy(&chgset);
  461. #endif
  462. }
  463. static void __init of_selftest_parse_interrupts(void)
  464. {
  465. struct device_node *np;
  466. struct of_phandle_args args;
  467. int i, rc;
  468. np = of_find_node_by_path("/testcase-data/interrupts/interrupts0");
  469. if (!np) {
  470. pr_err("missing testcase data\n");
  471. return;
  472. }
  473. for (i = 0; i < 4; i++) {
  474. bool passed = true;
  475. args.args_count = 0;
  476. rc = of_irq_parse_one(np, i, &args);
  477. passed &= !rc;
  478. passed &= (args.args_count == 1);
  479. passed &= (args.args[0] == (i + 1));
  480. selftest(passed, "index %i - data error on node %s rc=%i\n",
  481. i, args.np->full_name, rc);
  482. }
  483. of_node_put(np);
  484. np = of_find_node_by_path("/testcase-data/interrupts/interrupts1");
  485. if (!np) {
  486. pr_err("missing testcase data\n");
  487. return;
  488. }
  489. for (i = 0; i < 4; i++) {
  490. bool passed = true;
  491. args.args_count = 0;
  492. rc = of_irq_parse_one(np, i, &args);
  493. /* Test the values from tests-phandle.dtsi */
  494. switch (i) {
  495. case 0:
  496. passed &= !rc;
  497. passed &= (args.args_count == 1);
  498. passed &= (args.args[0] == 9);
  499. break;
  500. case 1:
  501. passed &= !rc;
  502. passed &= (args.args_count == 3);
  503. passed &= (args.args[0] == 10);
  504. passed &= (args.args[1] == 11);
  505. passed &= (args.args[2] == 12);
  506. break;
  507. case 2:
  508. passed &= !rc;
  509. passed &= (args.args_count == 2);
  510. passed &= (args.args[0] == 13);
  511. passed &= (args.args[1] == 14);
  512. break;
  513. case 3:
  514. passed &= !rc;
  515. passed &= (args.args_count == 2);
  516. passed &= (args.args[0] == 15);
  517. passed &= (args.args[1] == 16);
  518. break;
  519. default:
  520. passed = false;
  521. }
  522. selftest(passed, "index %i - data error on node %s rc=%i\n",
  523. i, args.np->full_name, rc);
  524. }
  525. of_node_put(np);
  526. }
  527. static void __init of_selftest_parse_interrupts_extended(void)
  528. {
  529. struct device_node *np;
  530. struct of_phandle_args args;
  531. int i, rc;
  532. np = of_find_node_by_path("/testcase-data/interrupts/interrupts-extended0");
  533. if (!np) {
  534. pr_err("missing testcase data\n");
  535. return;
  536. }
  537. for (i = 0; i < 7; i++) {
  538. bool passed = true;
  539. rc = of_irq_parse_one(np, i, &args);
  540. /* Test the values from tests-phandle.dtsi */
  541. switch (i) {
  542. case 0:
  543. passed &= !rc;
  544. passed &= (args.args_count == 1);
  545. passed &= (args.args[0] == 1);
  546. break;
  547. case 1:
  548. passed &= !rc;
  549. passed &= (args.args_count == 3);
  550. passed &= (args.args[0] == 2);
  551. passed &= (args.args[1] == 3);
  552. passed &= (args.args[2] == 4);
  553. break;
  554. case 2:
  555. passed &= !rc;
  556. passed &= (args.args_count == 2);
  557. passed &= (args.args[0] == 5);
  558. passed &= (args.args[1] == 6);
  559. break;
  560. case 3:
  561. passed &= !rc;
  562. passed &= (args.args_count == 1);
  563. passed &= (args.args[0] == 9);
  564. break;
  565. case 4:
  566. passed &= !rc;
  567. passed &= (args.args_count == 3);
  568. passed &= (args.args[0] == 10);
  569. passed &= (args.args[1] == 11);
  570. passed &= (args.args[2] == 12);
  571. break;
  572. case 5:
  573. passed &= !rc;
  574. passed &= (args.args_count == 2);
  575. passed &= (args.args[0] == 13);
  576. passed &= (args.args[1] == 14);
  577. break;
  578. case 6:
  579. passed &= !rc;
  580. passed &= (args.args_count == 1);
  581. passed &= (args.args[0] == 15);
  582. break;
  583. default:
  584. passed = false;
  585. }
  586. selftest(passed, "index %i - data error on node %s rc=%i\n",
  587. i, args.np->full_name, rc);
  588. }
  589. of_node_put(np);
  590. }
  591. static struct of_device_id match_node_table[] = {
  592. { .data = "A", .name = "name0", }, /* Name alone is lowest priority */
  593. { .data = "B", .type = "type1", }, /* followed by type alone */
  594. { .data = "Ca", .name = "name2", .type = "type1", }, /* followed by both together */
  595. { .data = "Cb", .name = "name2", }, /* Only match when type doesn't match */
  596. { .data = "Cc", .name = "name2", .type = "type2", },
  597. { .data = "E", .compatible = "compat3" },
  598. { .data = "G", .compatible = "compat2", },
  599. { .data = "H", .compatible = "compat2", .name = "name5", },
  600. { .data = "I", .compatible = "compat2", .type = "type1", },
  601. { .data = "J", .compatible = "compat2", .type = "type1", .name = "name8", },
  602. { .data = "K", .compatible = "compat2", .name = "name9", },
  603. {}
  604. };
  605. static struct {
  606. const char *path;
  607. const char *data;
  608. } match_node_tests[] = {
  609. { .path = "/testcase-data/match-node/name0", .data = "A", },
  610. { .path = "/testcase-data/match-node/name1", .data = "B", },
  611. { .path = "/testcase-data/match-node/a/name2", .data = "Ca", },
  612. { .path = "/testcase-data/match-node/b/name2", .data = "Cb", },
  613. { .path = "/testcase-data/match-node/c/name2", .data = "Cc", },
  614. { .path = "/testcase-data/match-node/name3", .data = "E", },
  615. { .path = "/testcase-data/match-node/name4", .data = "G", },
  616. { .path = "/testcase-data/match-node/name5", .data = "H", },
  617. { .path = "/testcase-data/match-node/name6", .data = "G", },
  618. { .path = "/testcase-data/match-node/name7", .data = "I", },
  619. { .path = "/testcase-data/match-node/name8", .data = "J", },
  620. { .path = "/testcase-data/match-node/name9", .data = "K", },
  621. };
  622. static void __init of_selftest_match_node(void)
  623. {
  624. struct device_node *np;
  625. const struct of_device_id *match;
  626. int i;
  627. for (i = 0; i < ARRAY_SIZE(match_node_tests); i++) {
  628. np = of_find_node_by_path(match_node_tests[i].path);
  629. if (!np) {
  630. selftest(0, "missing testcase node %s\n",
  631. match_node_tests[i].path);
  632. continue;
  633. }
  634. match = of_match_node(match_node_table, np);
  635. if (!match) {
  636. selftest(0, "%s didn't match anything\n",
  637. match_node_tests[i].path);
  638. continue;
  639. }
  640. if (strcmp(match->data, match_node_tests[i].data) != 0) {
  641. selftest(0, "%s got wrong match. expected %s, got %s\n",
  642. match_node_tests[i].path, match_node_tests[i].data,
  643. (const char *)match->data);
  644. continue;
  645. }
  646. selftest(1, "passed");
  647. }
  648. }
  649. struct device test_bus = {
  650. .init_name = "unittest-bus",
  651. };
  652. static void __init of_selftest_platform_populate(void)
  653. {
  654. int irq, rc;
  655. struct device_node *np, *child, *grandchild;
  656. struct platform_device *pdev;
  657. struct of_device_id match[] = {
  658. { .compatible = "test-device", },
  659. {}
  660. };
  661. np = of_find_node_by_path("/testcase-data");
  662. of_platform_populate(np, of_default_bus_match_table, NULL, NULL);
  663. /* Test that a missing irq domain returns -EPROBE_DEFER */
  664. np = of_find_node_by_path("/testcase-data/testcase-device1");
  665. pdev = of_find_device_by_node(np);
  666. selftest(pdev, "device 1 creation failed\n");
  667. irq = platform_get_irq(pdev, 0);
  668. selftest(irq == -EPROBE_DEFER, "device deferred probe failed - %d\n", irq);
  669. /* Test that a parsing failure does not return -EPROBE_DEFER */
  670. np = of_find_node_by_path("/testcase-data/testcase-device2");
  671. pdev = of_find_device_by_node(np);
  672. selftest(pdev, "device 2 creation failed\n");
  673. irq = platform_get_irq(pdev, 0);
  674. selftest(irq < 0 && irq != -EPROBE_DEFER, "device parsing error failed - %d\n", irq);
  675. if (selftest(np = of_find_node_by_path("/testcase-data/platform-tests"),
  676. "No testcase data in device tree\n"));
  677. return;
  678. if (selftest(!(rc = device_register(&test_bus)),
  679. "testbus registration failed; rc=%i\n", rc));
  680. return;
  681. for_each_child_of_node(np, child) {
  682. of_platform_populate(child, match, NULL, &test_bus);
  683. for_each_child_of_node(child, grandchild)
  684. selftest(of_find_device_by_node(grandchild),
  685. "Could not create device for node '%s'\n",
  686. grandchild->name);
  687. }
  688. of_platform_depopulate(&test_bus);
  689. for_each_child_of_node(np, child) {
  690. for_each_child_of_node(child, grandchild)
  691. selftest(!of_find_device_by_node(grandchild),
  692. "device didn't get destroyed '%s'\n",
  693. grandchild->name);
  694. }
  695. device_unregister(&test_bus);
  696. of_node_put(np);
  697. }
  698. /**
  699. * update_node_properties - adds the properties
  700. * of np into dup node (present in live tree) and
  701. * updates parent of children of np to dup.
  702. *
  703. * @np: node already present in live tree
  704. * @dup: node present in live tree to be updated
  705. */
  706. static void update_node_properties(struct device_node *np,
  707. struct device_node *dup)
  708. {
  709. struct property *prop;
  710. struct device_node *child;
  711. for_each_property_of_node(np, prop)
  712. of_add_property(dup, prop);
  713. for_each_child_of_node(np, child)
  714. child->parent = dup;
  715. }
  716. /**
  717. * attach_node_and_children - attaches nodes
  718. * and its children to live tree
  719. *
  720. * @np: Node to attach to live tree
  721. */
  722. static int attach_node_and_children(struct device_node *np)
  723. {
  724. struct device_node *next, *dup, *child;
  725. unsigned long flags;
  726. dup = of_find_node_by_path(np->full_name);
  727. if (dup) {
  728. update_node_properties(np, dup);
  729. return 0;
  730. }
  731. child = np->child;
  732. np->child = NULL;
  733. mutex_lock(&of_mutex);
  734. raw_spin_lock_irqsave(&devtree_lock, flags);
  735. np->sibling = np->parent->child;
  736. np->parent->child = np;
  737. of_node_clear_flag(np, OF_DETACHED);
  738. raw_spin_unlock_irqrestore(&devtree_lock, flags);
  739. __of_attach_node_sysfs(np);
  740. mutex_unlock(&of_mutex);
  741. while (child) {
  742. next = child->sibling;
  743. attach_node_and_children(child);
  744. child = next;
  745. }
  746. return 0;
  747. }
  748. /**
  749. * selftest_data_add - Reads, copies data from
  750. * linked tree and attaches it to the live tree
  751. */
  752. static int __init selftest_data_add(void)
  753. {
  754. void *selftest_data;
  755. struct device_node *selftest_data_node, *np;
  756. extern uint8_t __dtb_testcases_begin[];
  757. extern uint8_t __dtb_testcases_end[];
  758. const int size = __dtb_testcases_end - __dtb_testcases_begin;
  759. int rc;
  760. if (!size) {
  761. pr_warn("%s: No testcase data to attach; not running tests\n",
  762. __func__);
  763. return -ENODATA;
  764. }
  765. /* creating copy */
  766. selftest_data = kmemdup(__dtb_testcases_begin, size, GFP_KERNEL);
  767. if (!selftest_data) {
  768. pr_warn("%s: Failed to allocate memory for selftest_data; "
  769. "not running tests\n", __func__);
  770. return -ENOMEM;
  771. }
  772. of_fdt_unflatten_tree(selftest_data, &selftest_data_node);
  773. if (!selftest_data_node) {
  774. pr_warn("%s: No tree to attach; not running tests\n", __func__);
  775. return -ENODATA;
  776. }
  777. of_node_set_flag(selftest_data_node, OF_DETACHED);
  778. rc = of_resolve_phandles(selftest_data_node);
  779. if (rc) {
  780. pr_err("%s: Failed to resolve phandles (rc=%i)\n", __func__, rc);
  781. return -EINVAL;
  782. }
  783. if (!of_root) {
  784. of_root = selftest_data_node;
  785. for_each_of_allnodes(np)
  786. __of_attach_node_sysfs(np);
  787. of_aliases = of_find_node_by_path("/aliases");
  788. of_chosen = of_find_node_by_path("/chosen");
  789. return 0;
  790. }
  791. /* attach the sub-tree to live tree */
  792. np = selftest_data_node->child;
  793. while (np) {
  794. struct device_node *next = np->sibling;
  795. np->parent = of_root;
  796. attach_node_and_children(np);
  797. np = next;
  798. }
  799. return 0;
  800. }
  801. #ifdef CONFIG_OF_OVERLAY
  802. static int selftest_probe(struct platform_device *pdev)
  803. {
  804. struct device *dev = &pdev->dev;
  805. struct device_node *np = dev->of_node;
  806. if (np == NULL) {
  807. dev_err(dev, "No OF data for device\n");
  808. return -EINVAL;
  809. }
  810. dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name);
  811. of_platform_populate(np, NULL, NULL, &pdev->dev);
  812. return 0;
  813. }
  814. static int selftest_remove(struct platform_device *pdev)
  815. {
  816. struct device *dev = &pdev->dev;
  817. struct device_node *np = dev->of_node;
  818. dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name);
  819. return 0;
  820. }
  821. static struct of_device_id selftest_match[] = {
  822. { .compatible = "selftest", },
  823. {},
  824. };
  825. static struct platform_driver selftest_driver = {
  826. .probe = selftest_probe,
  827. .remove = selftest_remove,
  828. .driver = {
  829. .name = "selftest",
  830. .owner = THIS_MODULE,
  831. .of_match_table = of_match_ptr(selftest_match),
  832. },
  833. };
  834. /* get the platform device instantiated at the path */
  835. static struct platform_device *of_path_to_platform_device(const char *path)
  836. {
  837. struct device_node *np;
  838. struct platform_device *pdev;
  839. np = of_find_node_by_path(path);
  840. if (np == NULL)
  841. return NULL;
  842. pdev = of_find_device_by_node(np);
  843. of_node_put(np);
  844. return pdev;
  845. }
  846. /* find out if a platform device exists at that path */
  847. static int of_path_platform_device_exists(const char *path)
  848. {
  849. struct platform_device *pdev;
  850. pdev = of_path_to_platform_device(path);
  851. platform_device_put(pdev);
  852. return pdev != NULL;
  853. }
  854. #if IS_BUILTIN(CONFIG_I2C)
  855. /* get the i2c client device instantiated at the path */
  856. static struct i2c_client *of_path_to_i2c_client(const char *path)
  857. {
  858. struct device_node *np;
  859. struct i2c_client *client;
  860. np = of_find_node_by_path(path);
  861. if (np == NULL)
  862. return NULL;
  863. client = of_find_i2c_device_by_node(np);
  864. of_node_put(np);
  865. return client;
  866. }
  867. /* find out if a i2c client device exists at that path */
  868. static int of_path_i2c_client_exists(const char *path)
  869. {
  870. struct i2c_client *client;
  871. client = of_path_to_i2c_client(path);
  872. if (client)
  873. put_device(&client->dev);
  874. return client != NULL;
  875. }
  876. #else
  877. static int of_path_i2c_client_exists(const char *path)
  878. {
  879. return 0;
  880. }
  881. #endif
  882. enum overlay_type {
  883. PDEV_OVERLAY,
  884. I2C_OVERLAY
  885. };
  886. static int of_path_device_type_exists(const char *path,
  887. enum overlay_type ovtype)
  888. {
  889. switch (ovtype) {
  890. case PDEV_OVERLAY:
  891. return of_path_platform_device_exists(path);
  892. case I2C_OVERLAY:
  893. return of_path_i2c_client_exists(path);
  894. }
  895. return 0;
  896. }
  897. static const char *selftest_path(int nr, enum overlay_type ovtype)
  898. {
  899. const char *base;
  900. static char buf[256];
  901. switch (ovtype) {
  902. case PDEV_OVERLAY:
  903. base = "/testcase-data/overlay-node/test-bus";
  904. break;
  905. case I2C_OVERLAY:
  906. base = "/testcase-data/overlay-node/test-bus/i2c-test-bus";
  907. break;
  908. default:
  909. buf[0] = '\0';
  910. return buf;
  911. }
  912. snprintf(buf, sizeof(buf) - 1, "%s/test-selftest%d", base, nr);
  913. buf[sizeof(buf) - 1] = '\0';
  914. return buf;
  915. }
  916. static int of_selftest_device_exists(int selftest_nr, enum overlay_type ovtype)
  917. {
  918. const char *path;
  919. path = selftest_path(selftest_nr, ovtype);
  920. switch (ovtype) {
  921. case PDEV_OVERLAY:
  922. return of_path_platform_device_exists(path);
  923. case I2C_OVERLAY:
  924. return of_path_i2c_client_exists(path);
  925. }
  926. return 0;
  927. }
  928. static const char *overlay_path(int nr)
  929. {
  930. static char buf[256];
  931. snprintf(buf, sizeof(buf) - 1,
  932. "/testcase-data/overlay%d", nr);
  933. buf[sizeof(buf) - 1] = '\0';
  934. return buf;
  935. }
  936. static const char *bus_path = "/testcase-data/overlay-node/test-bus";
  937. static int of_selftest_apply_overlay(int selftest_nr, int overlay_nr,
  938. int *overlay_id)
  939. {
  940. struct device_node *np = NULL;
  941. int ret, id = -1;
  942. np = of_find_node_by_path(overlay_path(overlay_nr));
  943. if (np == NULL) {
  944. selftest(0, "could not find overlay node @\"%s\"\n",
  945. overlay_path(overlay_nr));
  946. ret = -EINVAL;
  947. goto out;
  948. }
  949. ret = of_overlay_create(np);
  950. if (ret < 0) {
  951. selftest(0, "could not create overlay from \"%s\"\n",
  952. overlay_path(overlay_nr));
  953. goto out;
  954. }
  955. id = ret;
  956. ret = 0;
  957. out:
  958. of_node_put(np);
  959. if (overlay_id)
  960. *overlay_id = id;
  961. return ret;
  962. }
  963. /* apply an overlay while checking before and after states */
  964. static int of_selftest_apply_overlay_check(int overlay_nr, int selftest_nr,
  965. int before, int after, enum overlay_type ovtype)
  966. {
  967. int ret;
  968. /* selftest device must not be in before state */
  969. if (of_selftest_device_exists(selftest_nr, ovtype) != before) {
  970. selftest(0, "overlay @\"%s\" with device @\"%s\" %s\n",
  971. overlay_path(overlay_nr),
  972. selftest_path(selftest_nr, ovtype),
  973. !before ? "enabled" : "disabled");
  974. return -EINVAL;
  975. }
  976. ret = of_selftest_apply_overlay(overlay_nr, selftest_nr, NULL);
  977. if (ret != 0) {
  978. /* of_selftest_apply_overlay already called selftest() */
  979. return ret;
  980. }
  981. /* selftest device must be to set to after state */
  982. if (of_selftest_device_exists(selftest_nr, ovtype) != after) {
  983. selftest(0, "overlay @\"%s\" failed to create @\"%s\" %s\n",
  984. overlay_path(overlay_nr),
  985. selftest_path(selftest_nr, ovtype),
  986. !after ? "enabled" : "disabled");
  987. return -EINVAL;
  988. }
  989. return 0;
  990. }
  991. /* apply an overlay and then revert it while checking before, after states */
  992. static int of_selftest_apply_revert_overlay_check(int overlay_nr,
  993. int selftest_nr, int before, int after,
  994. enum overlay_type ovtype)
  995. {
  996. int ret, ov_id;
  997. /* selftest device must be in before state */
  998. if (of_selftest_device_exists(selftest_nr, ovtype) != before) {
  999. selftest(0, "overlay @\"%s\" with device @\"%s\" %s\n",
  1000. overlay_path(overlay_nr),
  1001. selftest_path(selftest_nr, ovtype),
  1002. !before ? "enabled" : "disabled");
  1003. return -EINVAL;
  1004. }
  1005. /* apply the overlay */
  1006. ret = of_selftest_apply_overlay(overlay_nr, selftest_nr, &ov_id);
  1007. if (ret != 0) {
  1008. /* of_selftest_apply_overlay already called selftest() */
  1009. return ret;
  1010. }
  1011. /* selftest device must be in after state */
  1012. if (of_selftest_device_exists(selftest_nr, ovtype) != after) {
  1013. selftest(0, "overlay @\"%s\" failed to create @\"%s\" %s\n",
  1014. overlay_path(overlay_nr),
  1015. selftest_path(selftest_nr, ovtype),
  1016. !after ? "enabled" : "disabled");
  1017. return -EINVAL;
  1018. }
  1019. ret = of_overlay_destroy(ov_id);
  1020. if (ret != 0) {
  1021. selftest(0, "overlay @\"%s\" failed to be destroyed @\"%s\"\n",
  1022. overlay_path(overlay_nr),
  1023. selftest_path(selftest_nr, ovtype));
  1024. return ret;
  1025. }
  1026. /* selftest device must be again in before state */
  1027. if (of_selftest_device_exists(selftest_nr, PDEV_OVERLAY) != before) {
  1028. selftest(0, "overlay @\"%s\" with device @\"%s\" %s\n",
  1029. overlay_path(overlay_nr),
  1030. selftest_path(selftest_nr, ovtype),
  1031. !before ? "enabled" : "disabled");
  1032. return -EINVAL;
  1033. }
  1034. return 0;
  1035. }
  1036. /* test activation of device */
  1037. static void of_selftest_overlay_0(void)
  1038. {
  1039. int ret;
  1040. /* device should enable */
  1041. ret = of_selftest_apply_overlay_check(0, 0, 0, 1, PDEV_OVERLAY);
  1042. if (ret != 0)
  1043. return;
  1044. selftest(1, "overlay test %d passed\n", 0);
  1045. }
  1046. /* test deactivation of device */
  1047. static void of_selftest_overlay_1(void)
  1048. {
  1049. int ret;
  1050. /* device should disable */
  1051. ret = of_selftest_apply_overlay_check(1, 1, 1, 0, PDEV_OVERLAY);
  1052. if (ret != 0)
  1053. return;
  1054. selftest(1, "overlay test %d passed\n", 1);
  1055. }
  1056. /* test activation of device */
  1057. static void of_selftest_overlay_2(void)
  1058. {
  1059. int ret;
  1060. /* device should enable */
  1061. ret = of_selftest_apply_overlay_check(2, 2, 0, 1, PDEV_OVERLAY);
  1062. if (ret != 0)
  1063. return;
  1064. selftest(1, "overlay test %d passed\n", 2);
  1065. }
  1066. /* test deactivation of device */
  1067. static void of_selftest_overlay_3(void)
  1068. {
  1069. int ret;
  1070. /* device should disable */
  1071. ret = of_selftest_apply_overlay_check(3, 3, 1, 0, PDEV_OVERLAY);
  1072. if (ret != 0)
  1073. return;
  1074. selftest(1, "overlay test %d passed\n", 3);
  1075. }
  1076. /* test activation of a full device node */
  1077. static void of_selftest_overlay_4(void)
  1078. {
  1079. int ret;
  1080. /* device should disable */
  1081. ret = of_selftest_apply_overlay_check(4, 4, 0, 1, PDEV_OVERLAY);
  1082. if (ret != 0)
  1083. return;
  1084. selftest(1, "overlay test %d passed\n", 4);
  1085. }
  1086. /* test overlay apply/revert sequence */
  1087. static void of_selftest_overlay_5(void)
  1088. {
  1089. int ret;
  1090. /* device should disable */
  1091. ret = of_selftest_apply_revert_overlay_check(5, 5, 0, 1, PDEV_OVERLAY);
  1092. if (ret != 0)
  1093. return;
  1094. selftest(1, "overlay test %d passed\n", 5);
  1095. }
  1096. /* test overlay application in sequence */
  1097. static void of_selftest_overlay_6(void)
  1098. {
  1099. struct device_node *np;
  1100. int ret, i, ov_id[2];
  1101. int overlay_nr = 6, selftest_nr = 6;
  1102. int before = 0, after = 1;
  1103. /* selftest device must be in before state */
  1104. for (i = 0; i < 2; i++) {
  1105. if (of_selftest_device_exists(selftest_nr + i, PDEV_OVERLAY)
  1106. != before) {
  1107. selftest(0, "overlay @\"%s\" with device @\"%s\" %s\n",
  1108. overlay_path(overlay_nr + i),
  1109. selftest_path(selftest_nr + i,
  1110. PDEV_OVERLAY),
  1111. !before ? "enabled" : "disabled");
  1112. return;
  1113. }
  1114. }
  1115. /* apply the overlays */
  1116. for (i = 0; i < 2; i++) {
  1117. np = of_find_node_by_path(overlay_path(overlay_nr + i));
  1118. if (np == NULL) {
  1119. selftest(0, "could not find overlay node @\"%s\"\n",
  1120. overlay_path(overlay_nr + i));
  1121. return;
  1122. }
  1123. ret = of_overlay_create(np);
  1124. if (ret < 0) {
  1125. selftest(0, "could not create overlay from \"%s\"\n",
  1126. overlay_path(overlay_nr + i));
  1127. return;
  1128. }
  1129. ov_id[i] = ret;
  1130. }
  1131. for (i = 0; i < 2; i++) {
  1132. /* selftest device must be in after state */
  1133. if (of_selftest_device_exists(selftest_nr + i, PDEV_OVERLAY)
  1134. != after) {
  1135. selftest(0, "overlay @\"%s\" failed @\"%s\" %s\n",
  1136. overlay_path(overlay_nr + i),
  1137. selftest_path(selftest_nr + i,
  1138. PDEV_OVERLAY),
  1139. !after ? "enabled" : "disabled");
  1140. return;
  1141. }
  1142. }
  1143. for (i = 1; i >= 0; i--) {
  1144. ret = of_overlay_destroy(ov_id[i]);
  1145. if (ret != 0) {
  1146. selftest(0, "overlay @\"%s\" failed destroy @\"%s\"\n",
  1147. overlay_path(overlay_nr + i),
  1148. selftest_path(selftest_nr + i,
  1149. PDEV_OVERLAY));
  1150. return;
  1151. }
  1152. }
  1153. for (i = 0; i < 2; i++) {
  1154. /* selftest device must be again in before state */
  1155. if (of_selftest_device_exists(selftest_nr + i, PDEV_OVERLAY)
  1156. != before) {
  1157. selftest(0, "overlay @\"%s\" with device @\"%s\" %s\n",
  1158. overlay_path(overlay_nr + i),
  1159. selftest_path(selftest_nr + i,
  1160. PDEV_OVERLAY),
  1161. !before ? "enabled" : "disabled");
  1162. return;
  1163. }
  1164. }
  1165. selftest(1, "overlay test %d passed\n", 6);
  1166. }
  1167. /* test overlay application in sequence */
  1168. static void of_selftest_overlay_8(void)
  1169. {
  1170. struct device_node *np;
  1171. int ret, i, ov_id[2];
  1172. int overlay_nr = 8, selftest_nr = 8;
  1173. /* we don't care about device state in this test */
  1174. /* apply the overlays */
  1175. for (i = 0; i < 2; i++) {
  1176. np = of_find_node_by_path(overlay_path(overlay_nr + i));
  1177. if (np == NULL) {
  1178. selftest(0, "could not find overlay node @\"%s\"\n",
  1179. overlay_path(overlay_nr + i));
  1180. return;
  1181. }
  1182. ret = of_overlay_create(np);
  1183. if (ret < 0) {
  1184. selftest(0, "could not create overlay from \"%s\"\n",
  1185. overlay_path(overlay_nr + i));
  1186. return;
  1187. }
  1188. ov_id[i] = ret;
  1189. }
  1190. /* now try to remove first overlay (it should fail) */
  1191. ret = of_overlay_destroy(ov_id[0]);
  1192. if (ret == 0) {
  1193. selftest(0, "overlay @\"%s\" was destroyed @\"%s\"\n",
  1194. overlay_path(overlay_nr + 0),
  1195. selftest_path(selftest_nr,
  1196. PDEV_OVERLAY));
  1197. return;
  1198. }
  1199. /* removing them in order should work */
  1200. for (i = 1; i >= 0; i--) {
  1201. ret = of_overlay_destroy(ov_id[i]);
  1202. if (ret != 0) {
  1203. selftest(0, "overlay @\"%s\" not destroyed @\"%s\"\n",
  1204. overlay_path(overlay_nr + i),
  1205. selftest_path(selftest_nr,
  1206. PDEV_OVERLAY));
  1207. return;
  1208. }
  1209. }
  1210. selftest(1, "overlay test %d passed\n", 8);
  1211. }
  1212. /* test insertion of a bus with parent devices */
  1213. static void of_selftest_overlay_10(void)
  1214. {
  1215. int ret;
  1216. char *child_path;
  1217. /* device should disable */
  1218. ret = of_selftest_apply_overlay_check(10, 10, 0, 1, PDEV_OVERLAY);
  1219. if (selftest(ret == 0,
  1220. "overlay test %d failed; overlay application\n", 10))
  1221. return;
  1222. child_path = kasprintf(GFP_KERNEL, "%s/test-selftest101",
  1223. selftest_path(10, PDEV_OVERLAY));
  1224. if (selftest(child_path, "overlay test %d failed; kasprintf\n", 10))
  1225. return;
  1226. ret = of_path_device_type_exists(child_path, PDEV_OVERLAY);
  1227. kfree(child_path);
  1228. if (selftest(ret, "overlay test %d failed; no child device\n", 10))
  1229. return;
  1230. }
  1231. /* test insertion of a bus with parent devices (and revert) */
  1232. static void of_selftest_overlay_11(void)
  1233. {
  1234. int ret;
  1235. /* device should disable */
  1236. ret = of_selftest_apply_revert_overlay_check(11, 11, 0, 1,
  1237. PDEV_OVERLAY);
  1238. if (selftest(ret == 0,
  1239. "overlay test %d failed; overlay application\n", 11))
  1240. return;
  1241. }
  1242. #if IS_BUILTIN(CONFIG_I2C) && IS_ENABLED(CONFIG_OF_OVERLAY)
  1243. struct selftest_i2c_bus_data {
  1244. struct platform_device *pdev;
  1245. struct i2c_adapter adap;
  1246. };
  1247. static int selftest_i2c_master_xfer(struct i2c_adapter *adap,
  1248. struct i2c_msg *msgs, int num)
  1249. {
  1250. struct selftest_i2c_bus_data *std = i2c_get_adapdata(adap);
  1251. (void)std;
  1252. return num;
  1253. }
  1254. static u32 selftest_i2c_functionality(struct i2c_adapter *adap)
  1255. {
  1256. return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
  1257. }
  1258. static const struct i2c_algorithm selftest_i2c_algo = {
  1259. .master_xfer = selftest_i2c_master_xfer,
  1260. .functionality = selftest_i2c_functionality,
  1261. };
  1262. static int selftest_i2c_bus_probe(struct platform_device *pdev)
  1263. {
  1264. struct device *dev = &pdev->dev;
  1265. struct device_node *np = dev->of_node;
  1266. struct selftest_i2c_bus_data *std;
  1267. struct i2c_adapter *adap;
  1268. int ret;
  1269. if (np == NULL) {
  1270. dev_err(dev, "No OF data for device\n");
  1271. return -EINVAL;
  1272. }
  1273. dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name);
  1274. std = devm_kzalloc(dev, sizeof(*std), GFP_KERNEL);
  1275. if (!std) {
  1276. dev_err(dev, "Failed to allocate selftest i2c data\n");
  1277. return -ENOMEM;
  1278. }
  1279. /* link them together */
  1280. std->pdev = pdev;
  1281. platform_set_drvdata(pdev, std);
  1282. adap = &std->adap;
  1283. i2c_set_adapdata(adap, std);
  1284. adap->nr = -1;
  1285. strlcpy(adap->name, pdev->name, sizeof(adap->name));
  1286. adap->class = I2C_CLASS_DEPRECATED;
  1287. adap->algo = &selftest_i2c_algo;
  1288. adap->dev.parent = dev;
  1289. adap->dev.of_node = dev->of_node;
  1290. adap->timeout = 5 * HZ;
  1291. adap->retries = 3;
  1292. ret = i2c_add_numbered_adapter(adap);
  1293. if (ret != 0) {
  1294. dev_err(dev, "Failed to add I2C adapter\n");
  1295. return ret;
  1296. }
  1297. return 0;
  1298. }
  1299. static int selftest_i2c_bus_remove(struct platform_device *pdev)
  1300. {
  1301. struct device *dev = &pdev->dev;
  1302. struct device_node *np = dev->of_node;
  1303. struct selftest_i2c_bus_data *std = platform_get_drvdata(pdev);
  1304. dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name);
  1305. i2c_del_adapter(&std->adap);
  1306. return 0;
  1307. }
  1308. static struct of_device_id selftest_i2c_bus_match[] = {
  1309. { .compatible = "selftest-i2c-bus", },
  1310. {},
  1311. };
  1312. static struct platform_driver selftest_i2c_bus_driver = {
  1313. .probe = selftest_i2c_bus_probe,
  1314. .remove = selftest_i2c_bus_remove,
  1315. .driver = {
  1316. .name = "selftest-i2c-bus",
  1317. .of_match_table = of_match_ptr(selftest_i2c_bus_match),
  1318. },
  1319. };
  1320. static int selftest_i2c_dev_probe(struct i2c_client *client,
  1321. const struct i2c_device_id *id)
  1322. {
  1323. struct device *dev = &client->dev;
  1324. struct device_node *np = client->dev.of_node;
  1325. if (!np) {
  1326. dev_err(dev, "No OF node\n");
  1327. return -EINVAL;
  1328. }
  1329. dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name);
  1330. return 0;
  1331. };
  1332. static int selftest_i2c_dev_remove(struct i2c_client *client)
  1333. {
  1334. struct device *dev = &client->dev;
  1335. struct device_node *np = client->dev.of_node;
  1336. dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name);
  1337. return 0;
  1338. }
  1339. static const struct i2c_device_id selftest_i2c_dev_id[] = {
  1340. { .name = "selftest-i2c-dev" },
  1341. { }
  1342. };
  1343. static struct i2c_driver selftest_i2c_dev_driver = {
  1344. .driver = {
  1345. .name = "selftest-i2c-dev",
  1346. .owner = THIS_MODULE,
  1347. },
  1348. .probe = selftest_i2c_dev_probe,
  1349. .remove = selftest_i2c_dev_remove,
  1350. .id_table = selftest_i2c_dev_id,
  1351. };
  1352. #if IS_BUILTIN(CONFIG_I2C_MUX)
  1353. struct selftest_i2c_mux_data {
  1354. int nchans;
  1355. struct i2c_adapter *adap[];
  1356. };
  1357. static int selftest_i2c_mux_select_chan(struct i2c_adapter *adap,
  1358. void *client, u32 chan)
  1359. {
  1360. return 0;
  1361. }
  1362. static int selftest_i2c_mux_probe(struct i2c_client *client,
  1363. const struct i2c_device_id *id)
  1364. {
  1365. int ret, i, nchans, size;
  1366. struct device *dev = &client->dev;
  1367. struct i2c_adapter *adap = to_i2c_adapter(dev->parent);
  1368. struct device_node *np = client->dev.of_node, *child;
  1369. struct selftest_i2c_mux_data *stm;
  1370. u32 reg, max_reg;
  1371. dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name);
  1372. if (!np) {
  1373. dev_err(dev, "No OF node\n");
  1374. return -EINVAL;
  1375. }
  1376. max_reg = (u32)-1;
  1377. for_each_child_of_node(np, child) {
  1378. ret = of_property_read_u32(child, "reg", &reg);
  1379. if (ret)
  1380. continue;
  1381. if (max_reg == (u32)-1 || reg > max_reg)
  1382. max_reg = reg;
  1383. }
  1384. nchans = max_reg == (u32)-1 ? 0 : max_reg + 1;
  1385. if (nchans == 0) {
  1386. dev_err(dev, "No channels\n");
  1387. return -EINVAL;
  1388. }
  1389. size = offsetof(struct selftest_i2c_mux_data, adap[nchans]);
  1390. stm = devm_kzalloc(dev, size, GFP_KERNEL);
  1391. if (!stm) {
  1392. dev_err(dev, "Out of memory\n");
  1393. return -ENOMEM;
  1394. }
  1395. stm->nchans = nchans;
  1396. for (i = 0; i < nchans; i++) {
  1397. stm->adap[i] = i2c_add_mux_adapter(adap, dev, client,
  1398. 0, i, 0, selftest_i2c_mux_select_chan, NULL);
  1399. if (!stm->adap[i]) {
  1400. dev_err(dev, "Failed to register mux #%d\n", i);
  1401. for (i--; i >= 0; i--)
  1402. i2c_del_mux_adapter(stm->adap[i]);
  1403. return -ENODEV;
  1404. }
  1405. }
  1406. i2c_set_clientdata(client, stm);
  1407. return 0;
  1408. };
  1409. static int selftest_i2c_mux_remove(struct i2c_client *client)
  1410. {
  1411. struct device *dev = &client->dev;
  1412. struct device_node *np = client->dev.of_node;
  1413. struct selftest_i2c_mux_data *stm = i2c_get_clientdata(client);
  1414. int i;
  1415. dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name);
  1416. for (i = stm->nchans - 1; i >= 0; i--)
  1417. i2c_del_mux_adapter(stm->adap[i]);
  1418. return 0;
  1419. }
  1420. static const struct i2c_device_id selftest_i2c_mux_id[] = {
  1421. { .name = "selftest-i2c-mux" },
  1422. { }
  1423. };
  1424. static struct i2c_driver selftest_i2c_mux_driver = {
  1425. .driver = {
  1426. .name = "selftest-i2c-mux",
  1427. .owner = THIS_MODULE,
  1428. },
  1429. .probe = selftest_i2c_mux_probe,
  1430. .remove = selftest_i2c_mux_remove,
  1431. .id_table = selftest_i2c_mux_id,
  1432. };
  1433. #endif
  1434. static int of_selftest_overlay_i2c_init(void)
  1435. {
  1436. int ret;
  1437. ret = i2c_add_driver(&selftest_i2c_dev_driver);
  1438. if (selftest(ret == 0,
  1439. "could not register selftest i2c device driver\n"))
  1440. return ret;
  1441. ret = platform_driver_register(&selftest_i2c_bus_driver);
  1442. if (selftest(ret == 0,
  1443. "could not register selftest i2c bus driver\n"))
  1444. return ret;
  1445. #if IS_BUILTIN(CONFIG_I2C_MUX)
  1446. ret = i2c_add_driver(&selftest_i2c_mux_driver);
  1447. if (selftest(ret == 0,
  1448. "could not register selftest i2c mux driver\n"))
  1449. return ret;
  1450. #endif
  1451. return 0;
  1452. }
  1453. static void of_selftest_overlay_i2c_cleanup(void)
  1454. {
  1455. #if IS_BUILTIN(CONFIG_I2C_MUX)
  1456. i2c_del_driver(&selftest_i2c_mux_driver);
  1457. #endif
  1458. platform_driver_unregister(&selftest_i2c_bus_driver);
  1459. i2c_del_driver(&selftest_i2c_dev_driver);
  1460. }
  1461. static void of_selftest_overlay_i2c_12(void)
  1462. {
  1463. int ret;
  1464. /* device should enable */
  1465. ret = of_selftest_apply_overlay_check(12, 12, 0, 1, I2C_OVERLAY);
  1466. if (ret != 0)
  1467. return;
  1468. selftest(1, "overlay test %d passed\n", 12);
  1469. }
  1470. /* test deactivation of device */
  1471. static void of_selftest_overlay_i2c_13(void)
  1472. {
  1473. int ret;
  1474. /* device should disable */
  1475. ret = of_selftest_apply_overlay_check(13, 13, 1, 0, I2C_OVERLAY);
  1476. if (ret != 0)
  1477. return;
  1478. selftest(1, "overlay test %d passed\n", 13);
  1479. }
  1480. /* just check for i2c mux existence */
  1481. static void of_selftest_overlay_i2c_14(void)
  1482. {
  1483. }
  1484. static void of_selftest_overlay_i2c_15(void)
  1485. {
  1486. int ret;
  1487. /* device should enable */
  1488. ret = of_selftest_apply_overlay_check(16, 15, 0, 1, I2C_OVERLAY);
  1489. if (ret != 0)
  1490. return;
  1491. selftest(1, "overlay test %d passed\n", 15);
  1492. }
  1493. #else
  1494. static inline void of_selftest_overlay_i2c_14(void) { }
  1495. static inline void of_selftest_overlay_i2c_15(void) { }
  1496. #endif
  1497. static void __init of_selftest_overlay(void)
  1498. {
  1499. struct device_node *bus_np = NULL;
  1500. int ret;
  1501. ret = platform_driver_register(&selftest_driver);
  1502. if (ret != 0) {
  1503. selftest(0, "could not register selftest driver\n");
  1504. goto out;
  1505. }
  1506. bus_np = of_find_node_by_path(bus_path);
  1507. if (bus_np == NULL) {
  1508. selftest(0, "could not find bus_path \"%s\"\n", bus_path);
  1509. goto out;
  1510. }
  1511. ret = of_platform_populate(bus_np, of_default_bus_match_table,
  1512. NULL, NULL);
  1513. if (ret != 0) {
  1514. selftest(0, "could not populate bus @ \"%s\"\n", bus_path);
  1515. goto out;
  1516. }
  1517. if (!of_selftest_device_exists(100, PDEV_OVERLAY)) {
  1518. selftest(0, "could not find selftest0 @ \"%s\"\n",
  1519. selftest_path(100, PDEV_OVERLAY));
  1520. goto out;
  1521. }
  1522. if (of_selftest_device_exists(101, PDEV_OVERLAY)) {
  1523. selftest(0, "selftest1 @ \"%s\" should not exist\n",
  1524. selftest_path(101, PDEV_OVERLAY));
  1525. goto out;
  1526. }
  1527. selftest(1, "basic infrastructure of overlays passed");
  1528. /* tests in sequence */
  1529. of_selftest_overlay_0();
  1530. of_selftest_overlay_1();
  1531. of_selftest_overlay_2();
  1532. of_selftest_overlay_3();
  1533. of_selftest_overlay_4();
  1534. of_selftest_overlay_5();
  1535. of_selftest_overlay_6();
  1536. of_selftest_overlay_8();
  1537. of_selftest_overlay_10();
  1538. of_selftest_overlay_11();
  1539. #if IS_BUILTIN(CONFIG_I2C)
  1540. if (selftest(of_selftest_overlay_i2c_init() == 0, "i2c init failed\n"))
  1541. goto out;
  1542. of_selftest_overlay_i2c_12();
  1543. of_selftest_overlay_i2c_13();
  1544. of_selftest_overlay_i2c_14();
  1545. of_selftest_overlay_i2c_15();
  1546. of_selftest_overlay_i2c_cleanup();
  1547. #endif
  1548. out:
  1549. of_node_put(bus_np);
  1550. }
  1551. #else
  1552. static inline void __init of_selftest_overlay(void) { }
  1553. #endif
  1554. static int __init of_selftest(void)
  1555. {
  1556. struct device_node *np;
  1557. int res;
  1558. /* adding data for selftest */
  1559. res = selftest_data_add();
  1560. if (res)
  1561. return res;
  1562. if (!of_aliases)
  1563. of_aliases = of_find_node_by_path("/aliases");
  1564. np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
  1565. if (!np) {
  1566. pr_info("No testcase data in device tree; not running tests\n");
  1567. return 0;
  1568. }
  1569. of_node_put(np);
  1570. pr_info("start of selftest - you will see error messages\n");
  1571. of_selftest_check_tree_linkage();
  1572. of_selftest_check_phandles();
  1573. of_selftest_find_node_by_name();
  1574. of_selftest_dynamic();
  1575. of_selftest_parse_phandle_with_args();
  1576. of_selftest_property_string();
  1577. of_selftest_property_copy();
  1578. of_selftest_changeset();
  1579. of_selftest_parse_interrupts();
  1580. of_selftest_parse_interrupts_extended();
  1581. of_selftest_match_node();
  1582. of_selftest_platform_populate();
  1583. of_selftest_overlay();
  1584. /* Double check linkage after removing testcase data */
  1585. of_selftest_check_tree_linkage();
  1586. pr_info("end of selftest - %i passed, %i failed\n",
  1587. selftest_results.passed, selftest_results.failed);
  1588. return 0;
  1589. }
  1590. late_initcall(of_selftest);