1
2
3
4
5
6
7
8
9#include <common.h>
10#include <errno.h>
11#include <dm.h>
12#include <fdtdec.h>
13#include <malloc.h>
14#include <dm/device-internal.h>
15#include <dm/root.h>
16#include <dm/util.h>
17#include <dm/test.h>
18#include <dm/uclass-internal.h>
19#include <test/ut.h>
20
21DECLARE_GLOBAL_DATA_PTR;
22
23enum {
24 TEST_INTVAL1 = 0,
25 TEST_INTVAL2 = 3,
26 TEST_INTVAL3 = 6,
27 TEST_INTVAL_MANUAL = 101112,
28 TEST_INTVAL_PRE_RELOC = 7,
29};
30
31static const struct dm_test_pdata test_pdata[] = {
32 { .ping_add = TEST_INTVAL1, },
33 { .ping_add = TEST_INTVAL2, },
34 { .ping_add = TEST_INTVAL3, },
35};
36
37static const struct dm_test_pdata test_pdata_manual = {
38 .ping_add = TEST_INTVAL_MANUAL,
39};
40
41static const struct dm_test_pdata test_pdata_pre_reloc = {
42 .ping_add = TEST_INTVAL_PRE_RELOC,
43};
44
45U_BOOT_DEVICE(dm_test_info1) = {
46 .name = "test_drv",
47 .platdata = &test_pdata[0],
48};
49
50U_BOOT_DEVICE(dm_test_info2) = {
51 .name = "test_drv",
52 .platdata = &test_pdata[1],
53};
54
55U_BOOT_DEVICE(dm_test_info3) = {
56 .name = "test_drv",
57 .platdata = &test_pdata[2],
58};
59
60static struct driver_info driver_info_manual = {
61 .name = "test_manual_drv",
62 .platdata = &test_pdata_manual,
63};
64
65static struct driver_info driver_info_pre_reloc = {
66 .name = "test_pre_reloc_drv",
67 .platdata = &test_pdata_pre_reloc,
68};
69
70static struct driver_info driver_info_act_dma = {
71 .name = "test_act_dma_drv",
72};
73
74void dm_leak_check_start(struct unit_test_state *uts)
75{
76 uts->start = mallinfo();
77 if (!uts->start.uordblks)
78 puts("Warning: Please add '#define DEBUG' to the top of common/dlmalloc.c\n");
79}
80
81int dm_leak_check_end(struct unit_test_state *uts)
82{
83 struct mallinfo end;
84 int id, diff;
85
86
87 for (id = UCLASS_ROOT + 1; id < UCLASS_COUNT; id++) {
88 struct uclass *uc;
89
90 uc = uclass_find(id);
91 if (!uc)
92 continue;
93 ut_assertok(uclass_destroy(uc));
94 }
95
96 end = mallinfo();
97 diff = end.uordblks - uts->start.uordblks;
98 if (diff > 0)
99 printf("Leak: lost %#xd bytes\n", diff);
100 else if (diff < 0)
101 printf("Leak: gained %#xd bytes\n", -diff);
102 ut_asserteq(uts->start.uordblks, end.uordblks);
103
104 return 0;
105}
106
107
108static int dm_test_autobind(struct unit_test_state *uts)
109{
110 struct dm_test_state *dms = uts->priv;
111 struct udevice *dev;
112
113
114
115
116
117 ut_assert(dms->root);
118 ut_asserteq(1, list_count_items(&gd->uclass_root));
119 ut_asserteq(0, list_count_items(&gd->dm_root->child_head));
120 ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_POST_BIND]);
121
122 ut_assertok(dm_scan_platdata(false));
123
124
125 ut_assert(1 < list_count_items(&gd->uclass_root));
126 ut_assert(0 < list_count_items(&gd->dm_root->child_head));
127
128
129 ut_asserteq(3, dm_testdrv_op_count[DM_TEST_OP_POST_BIND]);
130
131
132 list_for_each_entry(dev, &gd->dm_root->child_head, sibling_node)
133 ut_assert(!(dev->flags & DM_FLAG_ACTIVATED));
134
135
136 ut_assert(dm_testdrv_op_count[DM_TEST_OP_BIND] == 3);
137
138 return 0;
139}
140DM_TEST(dm_test_autobind, 0);
141
142
143static int dm_test_autobind_uclass_pdata_alloc(struct unit_test_state *uts)
144{
145 struct dm_test_perdev_uc_pdata *uc_pdata;
146 struct udevice *dev;
147 struct uclass *uc;
148
149 ut_assertok(uclass_get(UCLASS_TEST, &uc));
150 ut_assert(uc);
151
152
153
154
155
156 ut_assert(uc->uc_drv->per_device_platdata_auto_alloc_size);
157
158 for (uclass_find_first_device(UCLASS_TEST, &dev);
159 dev;
160 uclass_find_next_device(&dev)) {
161 ut_assert(dev);
162
163 uc_pdata = dev_get_uclass_platdata(dev);
164 ut_assert(uc_pdata);
165 }
166
167 return 0;
168}
169DM_TEST(dm_test_autobind_uclass_pdata_alloc, DM_TESTF_SCAN_PDATA);
170
171
172static int dm_test_autobind_uclass_pdata_valid(struct unit_test_state *uts)
173{
174 struct dm_test_perdev_uc_pdata *uc_pdata;
175 struct udevice *dev;
176
177
178
179
180
181 for (uclass_find_first_device(UCLASS_TEST, &dev);
182 dev;
183 uclass_find_next_device(&dev)) {
184 ut_assert(dev);
185
186 uc_pdata = dev_get_uclass_platdata(dev);
187 ut_assert(uc_pdata);
188 ut_assert(uc_pdata->intval1 == TEST_UC_PDATA_INTVAL1);
189 ut_assert(uc_pdata->intval2 == TEST_UC_PDATA_INTVAL2);
190 ut_assert(uc_pdata->intval3 == TEST_UC_PDATA_INTVAL3);
191 }
192
193 return 0;
194}
195DM_TEST(dm_test_autobind_uclass_pdata_valid, DM_TESTF_SCAN_PDATA);
196
197
198static int dm_test_autoprobe(struct unit_test_state *uts)
199{
200 struct dm_test_state *dms = uts->priv;
201 int expected_base_add;
202 struct udevice *dev;
203 struct uclass *uc;
204 int i;
205
206 ut_assertok(uclass_get(UCLASS_TEST, &uc));
207 ut_assert(uc);
208
209 ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_INIT]);
210 ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_PRE_PROBE]);
211 ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_POST_PROBE]);
212
213
214 ut_assert(dms->root->flags & DM_FLAG_ACTIVATED);
215
216
217
218
219
220
221 for (i = 0; i < 3; i++) {
222 ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev));
223 ut_assert(dev);
224 ut_assertf(!(dev->flags & DM_FLAG_ACTIVATED),
225 "Driver %d/%s already activated", i, dev->name);
226
227
228 ut_assertok(uclass_get_device(UCLASS_TEST, i, &dev));
229 ut_assert(dev);
230 ut_assert(dev->flags & DM_FLAG_ACTIVATED);
231
232
233 if (!i)
234 ut_assert(dms->root->flags & DM_FLAG_ACTIVATED);
235 }
236
237
238
239
240
241 ut_asserteq(3, dm_testdrv_op_count[DM_TEST_OP_POST_PROBE]);
242 ut_asserteq(3, dm_testdrv_op_count[DM_TEST_OP_PRE_PROBE]);
243
244
245 expected_base_add = 0;
246 for (i = 0; i < 3; i++) {
247 struct dm_test_uclass_perdev_priv *priv;
248 struct dm_test_pdata *pdata;
249
250 ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev));
251 ut_assert(dev);
252
253 priv = dev_get_uclass_priv(dev);
254 ut_assert(priv);
255 ut_asserteq(expected_base_add, priv->base_add);
256
257 pdata = dev->platdata;
258 expected_base_add += pdata->ping_add;
259 }
260
261 return 0;
262}
263DM_TEST(dm_test_autoprobe, DM_TESTF_SCAN_PDATA);
264
265
266static int dm_test_platdata(struct unit_test_state *uts)
267{
268 const struct dm_test_pdata *pdata;
269 struct udevice *dev;
270 int i;
271
272 for (i = 0; i < 3; i++) {
273 ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev));
274 ut_assert(dev);
275 pdata = dev->platdata;
276 ut_assert(pdata->ping_add == test_pdata[i].ping_add);
277 }
278
279 return 0;
280}
281DM_TEST(dm_test_platdata, DM_TESTF_SCAN_PDATA);
282
283
284static int dm_test_lifecycle(struct unit_test_state *uts)
285{
286 struct dm_test_state *dms = uts->priv;
287 int op_count[DM_TEST_OP_COUNT];
288 struct udevice *dev, *test_dev;
289 int pingret;
290 int ret;
291
292 memcpy(op_count, dm_testdrv_op_count, sizeof(op_count));
293
294 ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
295 &dev));
296 ut_assert(dev);
297 ut_assert(dm_testdrv_op_count[DM_TEST_OP_BIND]
298 == op_count[DM_TEST_OP_BIND] + 1);
299 ut_assert(!dev->priv);
300
301
302 dms->force_fail_alloc = 1;
303 ret = device_probe(dev);
304 ut_assert(ret == -ENOMEM);
305 ut_assert(dm_testdrv_op_count[DM_TEST_OP_PROBE]
306 == op_count[DM_TEST_OP_PROBE] + 1);
307 ut_assert(!dev->priv);
308
309
310 dms->force_fail_alloc = 0;
311 ut_assertok(device_probe(dev));
312 ut_assert(dm_testdrv_op_count[DM_TEST_OP_PROBE]
313 == op_count[DM_TEST_OP_PROBE] + 2);
314 ut_assert(dev->priv);
315
316
317 ut_assertok(uclass_find_device(UCLASS_TEST, 3, &test_dev));
318 ut_assert(dev == test_dev);
319
320
321 ut_assertok(test_ping(dev, 100, &pingret));
322 ut_assert(pingret == 102);
323
324
325 ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_PRE_REMOVE]);
326 ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
327 ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_PRE_REMOVE]);
328
329 ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_UNBIND]);
330 ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_PRE_UNBIND]);
331 ut_assertok(device_unbind(dev));
332 ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_UNBIND]);
333 ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_PRE_UNBIND]);
334
335 return 0;
336}
337DM_TEST(dm_test_lifecycle, DM_TESTF_SCAN_PDATA | DM_TESTF_PROBE_TEST);
338
339
340static int dm_test_ordering(struct unit_test_state *uts)
341{
342 struct dm_test_state *dms = uts->priv;
343 struct udevice *dev, *dev_penultimate, *dev_last, *test_dev;
344 int pingret;
345
346 ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
347 &dev));
348 ut_assert(dev);
349
350
351 ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
352 &dev_penultimate));
353 ut_assert(dev_penultimate);
354 ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
355 &dev_last));
356 ut_assert(dev_last);
357
358
359 ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
360 ut_assertok(device_unbind(dev));
361
362
363 ut_assertok(uclass_find_device(UCLASS_TEST, 3, &test_dev));
364 ut_assert(dev_penultimate == test_dev);
365 ut_assertok(uclass_find_device(UCLASS_TEST, 4, &test_dev));
366 ut_assert(dev_last == test_dev);
367
368
369 ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
370 &dev));
371 ut_assert(dev);
372
373
374 ut_assertok(test_ping(dev, 100, &pingret));
375 ut_assert(pingret == 102);
376
377
378 ut_assertok(device_remove(dev_penultimate, DM_REMOVE_NORMAL));
379 ut_assertok(device_unbind(dev_penultimate));
380 ut_assertok(device_remove(dev_last, DM_REMOVE_NORMAL));
381 ut_assertok(device_unbind(dev_last));
382
383
384 ut_assertok(uclass_find_device(UCLASS_TEST, 3, &test_dev));
385 ut_assert(dev == test_dev);
386
387
388 ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
389 ut_assertok(device_unbind(dev));
390
391 return 0;
392}
393DM_TEST(dm_test_ordering, DM_TESTF_SCAN_PDATA);
394
395
396int dm_check_operations(struct unit_test_state *uts, struct udevice *dev,
397 uint32_t base, struct dm_test_priv *priv)
398{
399 int expected;
400 int pingret;
401
402
403 ut_assertok(testfdt_ping(dev, 10, &pingret));
404 ut_assert(dev->priv);
405 ut_assert(dev->platdata);
406
407 expected = 10 + base;
408 ut_asserteq(expected, pingret);
409
410
411 ut_assertok(testfdt_ping(dev, 20, &pingret));
412 expected = 20 + base;
413 ut_asserteq(expected, pingret);
414
415
416 priv = dev->priv;
417 ut_asserteq(DM_TEST_START_TOTAL + 10 + 20 + base * 2,
418 priv->ping_total);
419
420 return 0;
421}
422
423
424static int dm_test_operations(struct unit_test_state *uts)
425{
426 struct udevice *dev;
427 int i;
428
429
430
431
432
433 for (i = 0; i < ARRAY_SIZE(test_pdata); i++) {
434 uint32_t base;
435
436 ut_assertok(uclass_get_device(UCLASS_TEST, i, &dev));
437
438
439
440
441
442
443 base = test_pdata[i].ping_add;
444 debug("dev=%d, base=%d\n", i, base);
445
446 ut_assert(!dm_check_operations(uts, dev, base, dev->priv));
447 }
448
449 return 0;
450}
451DM_TEST(dm_test_operations, DM_TESTF_SCAN_PDATA);
452
453
454static int dm_test_remove(struct unit_test_state *uts)
455{
456 struct udevice *dev;
457 int i;
458
459 for (i = 0; i < 3; i++) {
460 ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev));
461 ut_assert(dev);
462 ut_assertf(dev->flags & DM_FLAG_ACTIVATED,
463 "Driver %d/%s not activated", i, dev->name);
464 ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
465 ut_assertf(!(dev->flags & DM_FLAG_ACTIVATED),
466 "Driver %d/%s should have deactivated", i,
467 dev->name);
468 ut_assert(!dev->priv);
469 }
470
471 return 0;
472}
473DM_TEST(dm_test_remove, DM_TESTF_SCAN_PDATA | DM_TESTF_PROBE_TEST);
474
475
476static int dm_test_leak(struct unit_test_state *uts)
477{
478 int i;
479
480 for (i = 0; i < 2; i++) {
481 struct udevice *dev;
482 int ret;
483 int id;
484
485 dm_leak_check_start(uts);
486
487 ut_assertok(dm_scan_platdata(false));
488 ut_assertok(dm_scan_fdt(gd->fdt_blob, false));
489
490
491 for (id = UCLASS_ROOT; id < UCLASS_COUNT; id++) {
492 for (ret = uclass_first_device(UCLASS_TEST, &dev);
493 dev;
494 ret = uclass_next_device(&dev))
495 ;
496 ut_assertok(ret);
497 }
498
499 ut_assertok(dm_leak_check_end(uts));
500 }
501
502 return 0;
503}
504DM_TEST(dm_test_leak, 0);
505
506
507static int dm_test_uclass(struct unit_test_state *uts)
508{
509 struct uclass *uc;
510
511 ut_assertok(uclass_get(UCLASS_TEST, &uc));
512 ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_INIT]);
513 ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_DESTROY]);
514 ut_assert(uc->priv);
515
516 ut_assertok(uclass_destroy(uc));
517 ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_INIT]);
518 ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_DESTROY]);
519
520 return 0;
521}
522DM_TEST(dm_test_uclass, 0);
523
524
525
526
527
528
529
530
531
532
533
534
535
536static int create_children(struct unit_test_state *uts, struct udevice *parent,
537 int count, int key, struct udevice *child[])
538{
539 struct udevice *dev;
540 int i;
541
542 for (i = 0; i < count; i++) {
543 struct dm_test_pdata *pdata;
544
545 ut_assertok(device_bind_by_name(parent, false,
546 &driver_info_manual, &dev));
547 pdata = calloc(1, sizeof(*pdata));
548 pdata->ping_add = key + i;
549 dev->platdata = pdata;
550 if (child)
551 child[i] = dev;
552 }
553
554 return 0;
555}
556
557#define NODE_COUNT 10
558
559static int dm_test_children(struct unit_test_state *uts)
560{
561 struct dm_test_state *dms = uts->priv;
562 struct udevice *top[NODE_COUNT];
563 struct udevice *child[NODE_COUNT];
564 struct udevice *grandchild[NODE_COUNT];
565 struct udevice *dev;
566 int total;
567 int ret;
568 int i;
569
570
571 dms->skip_post_probe = 1;
572
573 ut_assert(NODE_COUNT > 5);
574
575
576 ut_assertok(create_children(uts, dms->root, NODE_COUNT, 0, top));
577
578
579 ut_assertok(create_children(uts, top[2], NODE_COUNT, 2, NULL));
580 ut_assertok(create_children(uts, top[5], NODE_COUNT, 5, child));
581
582
583 for (i = 0; i < NODE_COUNT; i++)
584 ut_assertok(create_children(uts, child[i], NODE_COUNT, 50 * i,
585 i == 2 ? grandchild : NULL));
586
587
588 total = NODE_COUNT * (3 + NODE_COUNT);
589 ut_asserteq(total, dm_testdrv_op_count[DM_TEST_OP_BIND]);
590
591
592 ut_assertok(uclass_get_device(UCLASS_TEST,
593 NODE_COUNT * 3 + 2 * NODE_COUNT, &dev));
594 ut_asserteq_ptr(grandchild[0], dev);
595
596
597
598
599
600 ut_asserteq(3, dm_testdrv_op_count[DM_TEST_OP_PROBE]);
601
602
603 for (i = 1; i < NODE_COUNT; i++)
604 ut_assertok(device_probe(grandchild[i]));
605
606 ut_asserteq(2 + NODE_COUNT, dm_testdrv_op_count[DM_TEST_OP_PROBE]);
607
608
609 for (ret = uclass_first_device(UCLASS_TEST, &dev);
610 dev;
611 ret = uclass_next_device(&dev))
612 ;
613 ut_assertok(ret);
614
615 ut_asserteq(total, dm_testdrv_op_count[DM_TEST_OP_PROBE]);
616
617
618 ut_assertok(device_remove(top[2], DM_REMOVE_NORMAL));
619 ut_asserteq(NODE_COUNT + 1, dm_testdrv_op_count[DM_TEST_OP_REMOVE]);
620 dm_testdrv_op_count[DM_TEST_OP_REMOVE] = 0;
621
622
623 ut_assertok(uclass_get_device(UCLASS_TEST, 5, &dev));
624 ut_asserteq_ptr(dev, top[5]);
625 ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
626 ut_asserteq(1 + NODE_COUNT * (1 + NODE_COUNT),
627 dm_testdrv_op_count[DM_TEST_OP_REMOVE]);
628
629
630 ut_assertok(device_unbind(top[2]));
631 ut_asserteq(NODE_COUNT + 1, dm_testdrv_op_count[DM_TEST_OP_UNBIND]);
632 dm_testdrv_op_count[DM_TEST_OP_UNBIND] = 0;
633
634
635 ut_assertok(uclass_get_device(UCLASS_TEST, 5, &dev));
636 ut_asserteq_ptr(dev, top[6]);
637 ut_assertok(device_unbind(top[5]));
638 ut_asserteq(1 + NODE_COUNT * (1 + NODE_COUNT),
639 dm_testdrv_op_count[DM_TEST_OP_UNBIND]);
640
641 return 0;
642}
643DM_TEST(dm_test_children, 0);
644
645
646static int dm_test_pre_reloc(struct unit_test_state *uts)
647{
648 struct dm_test_state *dms = uts->priv;
649 struct udevice *dev;
650
651
652 ut_asserteq(-EPERM, device_bind_by_name(dms->root, true,
653 &driver_info_manual, &dev));
654
655
656 ut_assertok(device_bind_by_name(dms->root, true,
657 &driver_info_pre_reloc, &dev));
658
659 return 0;
660}
661DM_TEST(dm_test_pre_reloc, 0);
662
663
664
665
666
667static int dm_test_remove_active_dma(struct unit_test_state *uts)
668{
669 struct dm_test_state *dms = uts->priv;
670 struct udevice *dev;
671
672 ut_assertok(device_bind_by_name(dms->root, false, &driver_info_act_dma,
673 &dev));
674 ut_assert(dev);
675
676
677 ut_assertok(device_probe(dev));
678
679
680 ut_asserteq(true, device_active(dev));
681
682
683 dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
684
685
686 ut_asserteq(false, device_active(dev));
687
688
689 ut_assertok(device_probe(dev));
690
691
692 ut_asserteq(true, device_active(dev));
693
694
695 ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
696
697
698 ut_asserteq(false, device_active(dev));
699
700
701
702
703
704 ut_assertok(device_unbind(dev));
705 ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
706 &dev));
707 ut_assert(dev);
708
709
710 ut_assertok(device_probe(dev));
711
712
713 ut_asserteq(true, device_active(dev));
714
715
716 dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
717
718
719 ut_asserteq(true, device_active(dev));
720
721 return 0;
722}
723DM_TEST(dm_test_remove_active_dma, 0);
724
725static int dm_test_uclass_before_ready(struct unit_test_state *uts)
726{
727 struct uclass *uc;
728
729 ut_assertok(uclass_get(UCLASS_TEST, &uc));
730
731 gd->dm_root = NULL;
732 gd->dm_root_f = NULL;
733 memset(&gd->uclass_root, '\0', sizeof(gd->uclass_root));
734
735 ut_asserteq_ptr(NULL, uclass_find(UCLASS_TEST));
736
737 return 0;
738}
739DM_TEST(dm_test_uclass_before_ready, 0);
740
741static int dm_test_uclass_devices_find(struct unit_test_state *uts)
742{
743 struct udevice *dev;
744 int ret;
745
746 for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
747 dev;
748 ret = uclass_find_next_device(&dev)) {
749 ut_assert(!ret);
750 ut_assert(dev);
751 }
752
753 return 0;
754}
755DM_TEST(dm_test_uclass_devices_find, DM_TESTF_SCAN_PDATA);
756
757static int dm_test_uclass_devices_find_by_name(struct unit_test_state *uts)
758{
759 struct udevice *finddev;
760 struct udevice *testdev;
761 int findret, ret;
762
763
764
765
766
767
768
769
770
771
772
773
774 for (ret = uclass_find_first_device(UCLASS_TEST_FDT, &testdev);
775 testdev;
776 ret = uclass_find_next_device(&testdev)) {
777 ut_assertok(ret);
778 ut_assert(testdev);
779
780 findret = uclass_find_device_by_name(UCLASS_TEST_FDT,
781 testdev->name,
782 &finddev);
783
784 ut_assertok(findret);
785 ut_assert(testdev);
786 ut_asserteq_str(testdev->name, finddev->name);
787 ut_asserteq_ptr(testdev, finddev);
788 }
789
790 return 0;
791}
792DM_TEST(dm_test_uclass_devices_find_by_name, DM_TESTF_SCAN_FDT);
793
794static int dm_test_uclass_devices_get(struct unit_test_state *uts)
795{
796 struct udevice *dev;
797 int ret;
798
799 for (ret = uclass_first_device(UCLASS_TEST, &dev);
800 dev;
801 ret = uclass_next_device(&dev)) {
802 ut_assert(!ret);
803 ut_assert(dev);
804 ut_assert(device_active(dev));
805 }
806
807 return 0;
808}
809DM_TEST(dm_test_uclass_devices_get, DM_TESTF_SCAN_PDATA);
810
811static int dm_test_uclass_devices_get_by_name(struct unit_test_state *uts)
812{
813 struct udevice *finddev;
814 struct udevice *testdev;
815 int ret, findret;
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833 for (ret = uclass_first_device(UCLASS_TEST_FDT, &testdev);
834 testdev;
835 ret = uclass_next_device(&testdev)) {
836 ut_assertok(ret);
837 ut_assert(testdev);
838 ut_assert(device_active(testdev));
839
840 findret = uclass_get_device_by_name(UCLASS_TEST_FDT,
841 testdev->name,
842 &finddev);
843
844 ut_assertok(findret);
845 ut_assert(finddev);
846 ut_assert(device_active(finddev));
847 ut_asserteq_str(testdev->name, finddev->name);
848 ut_asserteq_ptr(testdev, finddev);
849 }
850
851 return 0;
852}
853DM_TEST(dm_test_uclass_devices_get_by_name, DM_TESTF_SCAN_FDT);
854
855static int dm_test_device_get_uclass_id(struct unit_test_state *uts)
856{
857 struct udevice *dev;
858
859 ut_assertok(uclass_get_device(UCLASS_TEST, 0, &dev));
860 ut_asserteq(UCLASS_TEST, device_get_uclass_id(dev));
861
862 return 0;
863}
864DM_TEST(dm_test_device_get_uclass_id, DM_TESTF_SCAN_PDATA);
865