Blame view

test/dm/test-fdt.c 25.1 KB
83d290c56   Tom Rini   SPDX: Convert all...
1
  // SPDX-License-Identifier: GPL-2.0+
2e7d35d2a   Simon Glass   dm: Add basic tests
2
3
  /*
   * Copyright (c) 2013 Google, Inc
2e7d35d2a   Simon Glass   dm: Add basic tests
4
5
6
7
8
9
10
11
12
13
   */
  
  #include <common.h>
  #include <dm.h>
  #include <errno.h>
  #include <fdtdec.h>
  #include <malloc.h>
  #include <asm/io.h>
  #include <dm/test.h>
  #include <dm/root.h>
985615725   Simon Glass   dm: core: Test uc...
14
  #include <dm/device-internal.h>
61b29b826   Simon Glass   dm: core: Require...
15
  #include <dm/devres.h>
2e7d35d2a   Simon Glass   dm: Add basic tests
16
17
  #include <dm/uclass-internal.h>
  #include <dm/util.h>
2ea4d0db7   Mario Six   test: Add tests f...
18
19
  #include <dm/lists.h>
  #include <dm/of_access.h>
e721b882e   Joe Hershberger   test: Generalize ...
20
  #include <test/ut.h>
2e7d35d2a   Simon Glass   dm: Add basic tests
21
22
  
  DECLARE_GLOBAL_DATA_PTR;
54c5d08a0   Heiko Schocher   dm: rename device...
23
  static int testfdt_drv_ping(struct udevice *dev, int pingval, int *pingret)
2e7d35d2a   Simon Glass   dm: Add basic tests
24
25
26
27
28
29
30
31
32
33
34
35
36
  {
  	const struct dm_test_pdata *pdata = dev->platdata;
  	struct dm_test_priv *priv = dev_get_priv(dev);
  
  	*pingret = pingval + pdata->ping_add;
  	priv->ping_total += *pingret;
  
  	return 0;
  }
  
  static const struct test_ops test_ops = {
  	.ping = testfdt_drv_ping,
  };
54c5d08a0   Heiko Schocher   dm: rename device...
37
  static int testfdt_ofdata_to_platdata(struct udevice *dev)
2e7d35d2a   Simon Glass   dm: Add basic tests
38
39
  {
  	struct dm_test_pdata *pdata = dev_get_platdata(dev);
e160f7d43   Simon Glass   dm: core: Replace...
40
  	pdata->ping_add = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
2e7d35d2a   Simon Glass   dm: Add basic tests
41
  					"ping-add", -1);
e160f7d43   Simon Glass   dm: core: Replace...
42
  	pdata->base = fdtdec_get_addr(gd->fdt_blob, dev_of_offset(dev),
eb9ef5fee   Simon Glass   dm: Use an explic...
43
  				      "ping-expect");
2e7d35d2a   Simon Glass   dm: Add basic tests
44
45
46
  
  	return 0;
  }
54c5d08a0   Heiko Schocher   dm: rename device...
47
  static int testfdt_drv_probe(struct udevice *dev)
2e7d35d2a   Simon Glass   dm: Add basic tests
48
49
50
51
  {
  	struct dm_test_priv *priv = dev_get_priv(dev);
  
  	priv->ping_total += DM_TEST_START_TOTAL;
83c7e434c   Simon Glass   dm: core: Allow u...
52
53
  	/*
  	 * If this device is on a bus, the uclass_flag will be set before
d92878aa4   Bin Meng   test: dm: core: A...
54
55
56
57
  	 * calling this function. In the meantime the uclass_postp is
  	 * initlized to a value -1. These are used respectively by
  	 * dm_test_bus_child_pre_probe_uclass() and
  	 * dm_test_bus_child_post_probe_uclass().
83c7e434c   Simon Glass   dm: core: Allow u...
58
59
  	 */
  	priv->uclass_total += priv->uclass_flag;
d92878aa4   Bin Meng   test: dm: core: A...
60
  	priv->uclass_postp = -1;
83c7e434c   Simon Glass   dm: core: Allow u...
61

2e7d35d2a   Simon Glass   dm: Add basic tests
62
63
  	return 0;
  }
ae7f45130   Simon Glass   dm: Rename struct...
64
  static const struct udevice_id testfdt_ids[] = {
2e7d35d2a   Simon Glass   dm: Add basic tests
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  	{
  		.compatible = "denx,u-boot-fdt-test",
  		.data = DM_TEST_TYPE_FIRST },
  	{
  		.compatible = "google,another-fdt-test",
  		.data = DM_TEST_TYPE_SECOND },
  	{ }
  };
  
  U_BOOT_DRIVER(testfdt_drv) = {
  	.name	= "testfdt_drv",
  	.of_match	= testfdt_ids,
  	.id	= UCLASS_TEST_FDT,
  	.ofdata_to_platdata = testfdt_ofdata_to_platdata,
  	.probe	= testfdt_drv_probe,
  	.ops	= &test_ops,
  	.priv_auto_alloc_size = sizeof(struct dm_test_priv),
  	.platdata_auto_alloc_size = sizeof(struct dm_test_pdata),
  };
2786cd740   Bin Meng   test: dm: core: A...
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
  static const struct udevice_id testfdt1_ids[] = {
  	{
  		.compatible = "denx,u-boot-fdt-test1",
  		.data = DM_TEST_TYPE_FIRST },
  	{ }
  };
  
  U_BOOT_DRIVER(testfdt1_drv) = {
  	.name	= "testfdt1_drv",
  	.of_match	= testfdt1_ids,
  	.id	= UCLASS_TEST_FDT,
  	.ofdata_to_platdata = testfdt_ofdata_to_platdata,
  	.probe	= testfdt_drv_probe,
  	.ops	= &test_ops,
  	.priv_auto_alloc_size = sizeof(struct dm_test_priv),
  	.platdata_auto_alloc_size = sizeof(struct dm_test_pdata),
  	.flags = DM_FLAG_PRE_RELOC,
  };
2e7d35d2a   Simon Glass   dm: Add basic tests
102
  /* From here is the testfdt uclass code */
54c5d08a0   Heiko Schocher   dm: rename device...
103
  int testfdt_ping(struct udevice *dev, int pingval, int *pingret)
2e7d35d2a   Simon Glass   dm: Add basic tests
104
105
106
107
108
109
110
111
112
113
114
115
  {
  	const struct test_ops *ops = device_get_ops(dev);
  
  	if (!ops->ping)
  		return -ENOSYS;
  
  	return ops->ping(dev, pingval, pingret);
  }
  
  UCLASS_DRIVER(testfdt) = {
  	.name		= "testfdt",
  	.id		= UCLASS_TEST_FDT,
9cc36a2b8   Simon Glass   dm: core: Add a f...
116
  	.flags		= DM_UC_FLAG_SEQ_ALIAS,
2e7d35d2a   Simon Glass   dm: Add basic tests
117
  };
985615725   Simon Glass   dm: core: Test uc...
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
  struct dm_testprobe_pdata {
  	int probe_err;
  };
  
  static int testprobe_drv_probe(struct udevice *dev)
  {
  	struct dm_testprobe_pdata *pdata = dev_get_platdata(dev);
  
  	return pdata->probe_err;
  }
  
  static const struct udevice_id testprobe_ids[] = {
  	{ .compatible = "denx,u-boot-probe-test" },
  	{ }
  };
  
  U_BOOT_DRIVER(testprobe_drv) = {
  	.name	= "testprobe_drv",
  	.of_match	= testprobe_ids,
  	.id	= UCLASS_TEST_PROBE,
  	.probe	= testprobe_drv_probe,
  	.platdata_auto_alloc_size	= sizeof(struct dm_testprobe_pdata),
  };
  
  UCLASS_DRIVER(testprobe) = {
  	.name		= "testprobe",
  	.id		= UCLASS_TEST_PROBE,
  	.flags		= DM_UC_FLAG_SEQ_ALIAS,
  };
dc12ebbbd   Simon Glass   dm: test: Add a t...
147
148
149
150
151
152
  struct dm_testdevres_pdata {
  	void *ptr;
  };
  
  struct dm_testdevres_priv {
  	void *ptr;
42a0ce576   Simon Glass   dm: devres: Add a...
153
  	void *ptr_ofdata;
dc12ebbbd   Simon Glass   dm: test: Add a t...
154
155
156
157
158
159
160
161
162
163
  };
  
  static int testdevres_drv_bind(struct udevice *dev)
  {
  	struct dm_testdevres_pdata *pdata = dev_get_platdata(dev);
  
  	pdata->ptr = devm_kmalloc(dev, TEST_DEVRES_SIZE, 0);
  
  	return 0;
  }
42a0ce576   Simon Glass   dm: devres: Add a...
164
165
166
167
168
169
170
171
  static int testdevres_drv_ofdata_to_platdata(struct udevice *dev)
  {
  	struct dm_testdevres_priv *priv = dev_get_priv(dev);
  
  	priv->ptr_ofdata = devm_kmalloc(dev, TEST_DEVRES_SIZE3, 0);
  
  	return 0;
  }
dc12ebbbd   Simon Glass   dm: test: Add a t...
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
  static int testdevres_drv_probe(struct udevice *dev)
  {
  	struct dm_testdevres_priv *priv = dev_get_priv(dev);
  
  	priv->ptr = devm_kmalloc(dev, TEST_DEVRES_SIZE2, 0);
  
  	return 0;
  }
  
  static const struct udevice_id testdevres_ids[] = {
  	{ .compatible = "denx,u-boot-devres-test" },
  	{ }
  };
  
  U_BOOT_DRIVER(testdevres_drv) = {
  	.name	= "testdevres_drv",
  	.of_match	= testdevres_ids,
  	.id	= UCLASS_TEST_DEVRES,
  	.bind	= testdevres_drv_bind,
42a0ce576   Simon Glass   dm: devres: Add a...
191
  	.ofdata_to_platdata	= testdevres_drv_ofdata_to_platdata,
dc12ebbbd   Simon Glass   dm: test: Add a t...
192
193
194
195
196
197
198
199
200
201
  	.probe	= testdevres_drv_probe,
  	.platdata_auto_alloc_size	= sizeof(struct dm_testdevres_pdata),
  	.priv_auto_alloc_size	= sizeof(struct dm_testdevres_priv),
  };
  
  UCLASS_DRIVER(testdevres) = {
  	.name		= "testdevres",
  	.id		= UCLASS_TEST_DEVRES,
  	.flags		= DM_UC_FLAG_SEQ_ALIAS,
  };
e721b882e   Joe Hershberger   test: Generalize ...
202
  int dm_check_devices(struct unit_test_state *uts, int num_devices)
2e7d35d2a   Simon Glass   dm: Add basic tests
203
  {
54c5d08a0   Heiko Schocher   dm: rename device...
204
  	struct udevice *dev;
2e7d35d2a   Simon Glass   dm: Add basic tests
205
206
  	int ret;
  	int i;
2e7d35d2a   Simon Glass   dm: Add basic tests
207
208
209
210
  	/*
  	 * Now check that the ping adds are what we expect. This is using the
  	 * ping-add property in each node.
  	 */
1ca7e2062   Simon Glass   dm: Provide a fun...
211
  	for (i = 0; i < num_devices; i++) {
2e7d35d2a   Simon Glass   dm: Add basic tests
212
213
214
215
216
217
  		uint32_t base;
  
  		ret = uclass_get_device(UCLASS_TEST_FDT, i, &dev);
  		ut_assert(!ret);
  
  		/*
eb9ef5fee   Simon Glass   dm: Use an explic...
218
219
220
221
  		 * Get the 'ping-expect' property, which tells us what the
  		 * ping add should be. We don't use the platdata because we
  		 * want to test the code that sets that up
  		 * (testfdt_drv_probe()).
2e7d35d2a   Simon Glass   dm: Add basic tests
222
  		 */
e160f7d43   Simon Glass   dm: core: Replace...
223
  		base = fdtdec_get_addr(gd->fdt_blob, dev_of_offset(dev),
eb9ef5fee   Simon Glass   dm: Use an explic...
224
  				       "ping-expect");
2e7d35d2a   Simon Glass   dm: Add basic tests
225
226
  		debug("dev=%d, base=%d: %s
  ", i, base,
e160f7d43   Simon Glass   dm: core: Replace...
227
  		      fdt_get_name(gd->fdt_blob, dev_of_offset(dev), NULL));
2e7d35d2a   Simon Glass   dm: Add basic tests
228

e721b882e   Joe Hershberger   test: Generalize ...
229
  		ut_assert(!dm_check_operations(uts, dev, base,
2e7d35d2a   Simon Glass   dm: Add basic tests
230
231
232
233
234
  					       dev_get_priv(dev)));
  	}
  
  	return 0;
  }
1ca7e2062   Simon Glass   dm: Provide a fun...
235
236
  
  /* Test that FDT-based binding works correctly */
e721b882e   Joe Hershberger   test: Generalize ...
237
  static int dm_test_fdt(struct unit_test_state *uts)
1ca7e2062   Simon Glass   dm: Provide a fun...
238
  {
2786cd740   Bin Meng   test: dm: core: A...
239
  	const int num_devices = 8;
1ca7e2062   Simon Glass   dm: Provide a fun...
240
241
242
243
244
245
246
247
248
249
250
251
252
  	struct udevice *dev;
  	struct uclass *uc;
  	int ret;
  	int i;
  
  	ret = dm_scan_fdt(gd->fdt_blob, false);
  	ut_assert(!ret);
  
  	ret = uclass_get(UCLASS_TEST_FDT, &uc);
  	ut_assert(!ret);
  
  	/* These are num_devices compatible root-level device tree nodes */
  	ut_asserteq(num_devices, list_count_items(&uc->dev_head));
f8a85449e   Simon Glass   dm: core: Allocat...
253
  	/* Each should have platform data but no private data */
1ca7e2062   Simon Glass   dm: Provide a fun...
254
255
256
257
  	for (i = 0; i < num_devices; i++) {
  		ret = uclass_find_device(UCLASS_TEST_FDT, i, &dev);
  		ut_assert(!ret);
  		ut_assert(!dev_get_priv(dev));
f8a85449e   Simon Glass   dm: core: Allocat...
258
  		ut_assert(dev->platdata);
1ca7e2062   Simon Glass   dm: Provide a fun...
259
  	}
e721b882e   Joe Hershberger   test: Generalize ...
260
  	ut_assertok(dm_check_devices(uts, num_devices));
1ca7e2062   Simon Glass   dm: Provide a fun...
261
262
263
  
  	return 0;
  }
2e7d35d2a   Simon Glass   dm: Add basic tests
264
  DM_TEST(dm_test_fdt, 0);
00606d7e3   Simon Glass   dm: Allow drivers...
265

a93eb577b   Michal Simek   dm: core: Add tes...
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
  static int dm_test_alias_highest_id(struct unit_test_state *uts)
  {
  	int ret;
  
  	ret = dev_read_alias_highest_id("eth");
  	ut_asserteq(5, ret);
  
  	ret = dev_read_alias_highest_id("gpio");
  	ut_asserteq(2, ret);
  
  	ret = dev_read_alias_highest_id("pci");
  	ut_asserteq(2, ret);
  
  	ret = dev_read_alias_highest_id("i2c");
  	ut_asserteq(0, ret);
  
  	ret = dev_read_alias_highest_id("deadbeef");
  	ut_asserteq(-1, ret);
  
  	return 0;
  }
  DM_TEST(dm_test_alias_highest_id, 0);
e721b882e   Joe Hershberger   test: Generalize ...
288
  static int dm_test_fdt_pre_reloc(struct unit_test_state *uts)
00606d7e3   Simon Glass   dm: Allow drivers...
289
290
291
292
293
294
295
296
297
  {
  	struct uclass *uc;
  	int ret;
  
  	ret = dm_scan_fdt(gd->fdt_blob, true);
  	ut_assert(!ret);
  
  	ret = uclass_get(UCLASS_TEST_FDT, &uc);
  	ut_assert(!ret);
2786cd740   Bin Meng   test: dm: core: A...
298
299
300
301
302
303
  	/*
  	 * These are 2 pre-reloc devices:
  	 * one with "u-boot,dm-pre-reloc" property (a-test node), and the other
  	 * one whose driver marked with DM_FLAG_PRE_RELOC flag (h-test node).
  	 */
  	ut_asserteq(2, list_count_items(&uc->dev_head));
00606d7e3   Simon Glass   dm: Allow drivers...
304
305
306
307
  
  	return 0;
  }
  DM_TEST(dm_test_fdt_pre_reloc, 0);
5a66a8ff8   Simon Glass   dm: Introduce dev...
308
309
  
  /* Test that sequence numbers are allocated properly */
e721b882e   Joe Hershberger   test: Generalize ...
310
  static int dm_test_fdt_uclass_seq(struct unit_test_state *uts)
5a66a8ff8   Simon Glass   dm: Introduce dev...
311
312
313
314
315
316
  {
  	struct udevice *dev;
  
  	/* A few basic santiy tests */
  	ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 3, true, &dev));
  	ut_asserteq_str("b-test", dev->name);
9cc36a2b8   Simon Glass   dm: core: Add a f...
317
  	ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 8, true, &dev));
5a66a8ff8   Simon Glass   dm: Introduce dev...
318
319
320
321
322
323
324
325
326
327
328
329
  	ut_asserteq_str("a-test", dev->name);
  
  	ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 5,
  						       true, &dev));
  	ut_asserteq_ptr(NULL, dev);
  
  	/* Test aliases */
  	ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 6, &dev));
  	ut_asserteq_str("e-test", dev->name);
  
  	ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 7,
  						       true, &dev));
1ca7e2062   Simon Glass   dm: Provide a fun...
330
331
332
333
  	/*
  	 * Note that c-test nodes are not probed since it is not a top-level
  	 * node
  	 */
5a66a8ff8   Simon Glass   dm: Introduce dev...
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
  	ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 3, &dev));
  	ut_asserteq_str("b-test", dev->name);
  
  	/*
  	 * d-test wants sequence number 3 also, but it can't have it because
  	 * b-test gets it first.
  	 */
  	ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 2, &dev));
  	ut_asserteq_str("d-test", dev->name);
  
  	/* d-test actually gets 0 */
  	ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 0, &dev));
  	ut_asserteq_str("d-test", dev->name);
  
  	/* initially no one wants seq 1 */
  	ut_asserteq(-ENODEV, uclass_get_device_by_seq(UCLASS_TEST_FDT, 1,
  						      &dev));
  	ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 0, &dev));
9cc36a2b8   Simon Glass   dm: core: Add a f...
352
  	ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 4, &dev));
5a66a8ff8   Simon Glass   dm: Introduce dev...
353
354
355
  
  	/* But now that it is probed, we can find it */
  	ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 1, &dev));
9cc36a2b8   Simon Glass   dm: core: Add a f...
356
  	ut_asserteq_str("f-test", dev->name);
5a66a8ff8   Simon Glass   dm: Introduce dev...
357
358
359
360
  
  	return 0;
  }
  DM_TEST(dm_test_fdt_uclass_seq, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
f4cdead24   Simon Glass   dm: Allow a devic...
361
362
  
  /* Test that we can find a device by device tree offset */
e721b882e   Joe Hershberger   test: Generalize ...
363
  static int dm_test_fdt_offset(struct unit_test_state *uts)
f4cdead24   Simon Glass   dm: Allow a devic...
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
  {
  	const void *blob = gd->fdt_blob;
  	struct udevice *dev;
  	int node;
  
  	node = fdt_path_offset(blob, "/e-test");
  	ut_assert(node > 0);
  	ut_assertok(uclass_get_device_by_of_offset(UCLASS_TEST_FDT, node,
  						   &dev));
  	ut_asserteq_str("e-test", dev->name);
  
  	/* This node should not be bound */
  	node = fdt_path_offset(blob, "/junk");
  	ut_assert(node > 0);
  	ut_asserteq(-ENODEV, uclass_get_device_by_of_offset(UCLASS_TEST_FDT,
  							    node, &dev));
  
  	/* This is not a top level node so should not be probed */
1ca7e2062   Simon Glass   dm: Provide a fun...
382
  	node = fdt_path_offset(blob, "/some-bus/c-test@5");
f4cdead24   Simon Glass   dm: Allow a devic...
383
384
385
386
387
388
  	ut_assert(node > 0);
  	ut_asserteq(-ENODEV, uclass_get_device_by_of_offset(UCLASS_TEST_FDT,
  							    node, &dev));
  
  	return 0;
  }
86b54ece8   Simon Glass   dm: test: Disable...
389
390
  DM_TEST(dm_test_fdt_offset,
  	DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE);
985615725   Simon Glass   dm: core: Test uc...
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
  
  /**
   * Test various error conditions with uclass_first_device() and
   * uclass_next_device()
   */
  static int dm_test_first_next_device(struct unit_test_state *uts)
  {
  	struct dm_testprobe_pdata *pdata;
  	struct udevice *dev, *parent = NULL;
  	int count;
  	int ret;
  
  	/* There should be 4 devices */
  	for (ret = uclass_first_device(UCLASS_TEST_PROBE, &dev), count = 0;
  	     dev;
  	     ret = uclass_next_device(&dev)) {
  		count++;
  		parent = dev_get_parent(dev);
  		}
  	ut_assertok(ret);
  	ut_asserteq(4, count);
  
  	/* Remove them and try again, with an error on the second one */
  	ut_assertok(uclass_get_device(UCLASS_TEST_PROBE, 1, &dev));
  	pdata = dev_get_platdata(dev);
  	pdata->probe_err = -ENOMEM;
  	device_remove(parent, DM_REMOVE_NORMAL);
  	ut_assertok(uclass_first_device(UCLASS_TEST_PROBE, &dev));
  	ut_asserteq(-ENOMEM, uclass_next_device(&dev));
  	ut_asserteq_ptr(dev, NULL);
  
  	/* Now an error on the first one */
  	ut_assertok(uclass_get_device(UCLASS_TEST_PROBE, 0, &dev));
  	pdata = dev_get_platdata(dev);
  	pdata->probe_err = -ENOENT;
  	device_remove(parent, DM_REMOVE_NORMAL);
  	ut_asserteq(-ENOENT, uclass_first_device(UCLASS_TEST_PROBE, &dev));
  
  	return 0;
  }
  DM_TEST(dm_test_first_next_device, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
95ce385a4   Simon Glass   dm: core: Add ucl...
432

3cf0fba4f   Simon Glass   dm: core: Allow i...
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
  /* Test iteration through devices in a uclass */
  static int dm_test_uclass_foreach(struct unit_test_state *uts)
  {
  	struct udevice *dev;
  	struct uclass *uc;
  	int count;
  
  	count = 0;
  	uclass_id_foreach_dev(UCLASS_TEST_FDT, dev, uc)
  		count++;
  	ut_asserteq(8, count);
  
  	count = 0;
  	uclass_foreach_dev(dev, uc)
  		count++;
  	ut_asserteq(8, count);
  
  	return 0;
  }
  DM_TEST(dm_test_uclass_foreach, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
95ce385a4   Simon Glass   dm: core: Add ucl...
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
  /**
   * check_devices() - Check return values and pointers
   *
   * This runs through a full sequence of uclass_first_device_check()...
   * uclass_next_device_check() checking that the return values and devices
   * are correct.
   *
   * @uts: Test state
   * @devlist: List of expected devices
   * @mask: Indicates which devices should return an error. Device n should
   *	  return error (-NOENT - n) if bit n is set, or no error (i.e. 0) if
   *	  bit n is clear.
   */
  static int check_devices(struct unit_test_state *uts,
  			 struct udevice *devlist[], int mask)
  {
  	int expected_ret;
  	struct udevice *dev;
  	int i;
  
  	expected_ret = (mask & 1) ? -ENOENT : 0;
  	mask >>= 1;
  	ut_asserteq(expected_ret,
  		    uclass_first_device_check(UCLASS_TEST_PROBE, &dev));
  	for (i = 0; i < 4; i++) {
  		ut_asserteq_ptr(devlist[i], dev);
  		expected_ret = (mask & 1) ? -ENOENT - (i + 1) : 0;
  		mask >>= 1;
  		ut_asserteq(expected_ret, uclass_next_device_check(&dev));
  	}
  	ut_asserteq_ptr(NULL, dev);
  
  	return 0;
  }
  
  /* Test uclass_first_device_check() and uclass_next_device_check() */
  static int dm_test_first_next_ok_device(struct unit_test_state *uts)
  {
  	struct dm_testprobe_pdata *pdata;
  	struct udevice *dev, *parent = NULL, *devlist[4];
  	int count;
  	int ret;
  
  	/* There should be 4 devices */
  	count = 0;
  	for (ret = uclass_first_device_check(UCLASS_TEST_PROBE, &dev);
  	     dev;
  	     ret = uclass_next_device_check(&dev)) {
  		ut_assertok(ret);
  		devlist[count++] = dev;
  		parent = dev_get_parent(dev);
  		}
  	ut_asserteq(4, count);
  	ut_assertok(uclass_first_device_check(UCLASS_TEST_PROBE, &dev));
  	ut_assertok(check_devices(uts, devlist, 0));
  
  	/* Remove them and try again, with an error on the second one */
  	pdata = dev_get_platdata(devlist[1]);
  	pdata->probe_err = -ENOENT - 1;
  	device_remove(parent, DM_REMOVE_NORMAL);
  	ut_assertok(check_devices(uts, devlist, 1 << 1));
  
  	/* Now an error on the first one */
  	pdata = dev_get_platdata(devlist[0]);
  	pdata->probe_err = -ENOENT - 0;
  	device_remove(parent, DM_REMOVE_NORMAL);
  	ut_assertok(check_devices(uts, devlist, 3 << 0));
  
  	/* Now errors on all */
  	pdata = dev_get_platdata(devlist[2]);
  	pdata->probe_err = -ENOENT - 2;
  	pdata = dev_get_platdata(devlist[3]);
  	pdata->probe_err = -ENOENT - 3;
  	device_remove(parent, DM_REMOVE_NORMAL);
  	ut_assertok(check_devices(uts, devlist, 0xf << 0));
  
  	return 0;
  }
  DM_TEST(dm_test_first_next_ok_device, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
e8d529182   Mario Six   core: ofnode: Fix...
532
533
534
535
536
537
538
  
  static const struct udevice_id fdt_dummy_ids[] = {
  	{ .compatible = "denx,u-boot-fdt-dummy", },
  	{ }
  };
  
  UCLASS_DRIVER(fdt_dummy) = {
507cef3d1   Eugeniu Rosca   test: dm: Fix wro...
539
  	.name		= "fdt-dummy",
e8d529182   Mario Six   core: ofnode: Fix...
540
541
542
543
544
545
546
547
548
549
550
551
552
  	.id		= UCLASS_TEST_DUMMY,
  	.flags		= DM_UC_FLAG_SEQ_ALIAS,
  };
  
  U_BOOT_DRIVER(fdt_dummy_drv) = {
  	.name	= "fdt_dummy_drv",
  	.of_match	= fdt_dummy_ids,
  	.id	= UCLASS_TEST_DUMMY,
  };
  
  static int dm_test_fdt_translation(struct unit_test_state *uts)
  {
  	struct udevice *dev;
641067fb0   Fabien Dessenne   dm: core: Introdu...
553
  	fdt32_t dma_addr[2];
e8d529182   Mario Six   core: ofnode: Fix...
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
  
  	/* Some simple translations */
  	ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
  	ut_asserteq_str("dev@0,0", dev->name);
  	ut_asserteq(0x8000, dev_read_addr(dev));
  
  	ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 1, true, &dev));
  	ut_asserteq_str("dev@1,100", dev->name);
  	ut_asserteq(0x9000, dev_read_addr(dev));
  
  	ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 2, true, &dev));
  	ut_asserteq_str("dev@2,200", dev->name);
  	ut_asserteq(0xA000, dev_read_addr(dev));
  
  	/* No translation for busses with #size-cells == 0 */
  	ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 3, true, &dev));
  	ut_asserteq_str("dev@42", dev->name);
  	ut_asserteq(0x42, dev_read_addr(dev));
641067fb0   Fabien Dessenne   dm: core: Introdu...
572
573
574
575
576
577
578
579
580
581
  	/* dma address translation */
  	ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
  	dma_addr[0] = cpu_to_be32(0);
  	dma_addr[1] = cpu_to_be32(0);
  	ut_asserteq(0x10000000, dev_translate_dma_address(dev, dma_addr));
  
  	ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 1, true, &dev));
  	dma_addr[0] = cpu_to_be32(1);
  	dma_addr[1] = cpu_to_be32(0x100);
  	ut_asserteq(0x20000000, dev_translate_dma_address(dev, dma_addr));
e8d529182   Mario Six   core: ofnode: Fix...
582
583
584
  	return 0;
  }
  DM_TEST(dm_test_fdt_translation, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
30a90f56c   Álvaro Fernández Rojas   dm: core: add fun...
585

30a90f56c   Álvaro Fernández Rojas   dm: core: add fun...
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
  static int dm_test_fdt_remap_addr_flat(struct unit_test_state *uts)
  {
  	struct udevice *dev;
  	fdt_addr_t addr;
  	void *paddr;
  
  	ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
  
  	addr = devfdt_get_addr(dev);
  	ut_asserteq(0x8000, addr);
  
  	paddr = map_physmem(addr, 0, MAP_NOCACHE);
  	ut_assertnonnull(paddr);
  	ut_asserteq_ptr(paddr, devfdt_remap_addr(dev));
  
  	return 0;
  }
  DM_TEST(dm_test_fdt_remap_addr_flat,
  	DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE);
795988204   Álvaro Fernández Rojas   dm: core: add fun...
605
606
607
608
  static int dm_test_fdt_remap_addr_index_flat(struct unit_test_state *uts)
  {
  	struct udevice *dev;
  	fdt_addr_t addr;
f5b904796   Sekhar Nori   dm: core: add sup...
609
  	fdt_size_t size;
795988204   Álvaro Fernández Rojas   dm: core: add fun...
610
611
612
  	void *paddr;
  
  	ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
f5b904796   Sekhar Nori   dm: core: add sup...
613
  	addr = devfdt_get_addr_size_index(dev, 0, &size);
795988204   Álvaro Fernández Rojas   dm: core: add fun...
614
  	ut_asserteq(0x8000, addr);
f5b904796   Sekhar Nori   dm: core: add sup...
615
  	ut_asserteq(0x1000, size);
795988204   Álvaro Fernández Rojas   dm: core: add fun...
616
617
618
619
620
621
622
623
624
625
626
627
628
629
  
  	paddr = map_physmem(addr, 0, MAP_NOCACHE);
  	ut_assertnonnull(paddr);
  	ut_asserteq_ptr(paddr, devfdt_remap_addr_index(dev, 0));
  
  	return 0;
  }
  DM_TEST(dm_test_fdt_remap_addr_index_flat,
  	DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE);
  
  static int dm_test_fdt_remap_addr_name_flat(struct unit_test_state *uts)
  {
  	struct udevice *dev;
  	fdt_addr_t addr;
f5b904796   Sekhar Nori   dm: core: add sup...
630
  	fdt_size_t size;
795988204   Álvaro Fernández Rojas   dm: core: add fun...
631
632
633
  	void *paddr;
  
  	ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
f5b904796   Sekhar Nori   dm: core: add sup...
634
  	addr = devfdt_get_addr_size_name(dev, "sandbox-dummy-0", &size);
795988204   Álvaro Fernández Rojas   dm: core: add fun...
635
  	ut_asserteq(0x8000, addr);
f5b904796   Sekhar Nori   dm: core: add sup...
636
  	ut_asserteq(0x1000, size);
795988204   Álvaro Fernández Rojas   dm: core: add fun...
637
638
639
640
641
642
643
644
645
  
  	paddr = map_physmem(addr, 0, MAP_NOCACHE);
  	ut_assertnonnull(paddr);
  	ut_asserteq_ptr(paddr, devfdt_remap_addr_name(dev, "sandbox-dummy-0"));
  
  	return 0;
  }
  DM_TEST(dm_test_fdt_remap_addr_name_flat,
  	DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE);
30a90f56c   Álvaro Fernández Rojas   dm: core: add fun...
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
  static int dm_test_fdt_remap_addr_live(struct unit_test_state *uts)
  {
  	struct udevice *dev;
  	fdt_addr_t addr;
  	void *paddr;
  
  	ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
  
  	addr = dev_read_addr(dev);
  	ut_asserteq(0x8000, addr);
  
  	paddr = map_physmem(addr, 0, MAP_NOCACHE);
  	ut_assertnonnull(paddr);
  	ut_asserteq_ptr(paddr, dev_remap_addr(dev));
  
  	return 0;
  }
  DM_TEST(dm_test_fdt_remap_addr_live,
  	DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
2ea4d0db7   Mario Six   test: Add tests f...
665

795988204   Álvaro Fernández Rojas   dm: core: add fun...
666
667
668
669
  static int dm_test_fdt_remap_addr_index_live(struct unit_test_state *uts)
  {
  	struct udevice *dev;
  	fdt_addr_t addr;
f5b904796   Sekhar Nori   dm: core: add sup...
670
  	fdt_size_t size;
795988204   Álvaro Fernández Rojas   dm: core: add fun...
671
672
673
  	void *paddr;
  
  	ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
f5b904796   Sekhar Nori   dm: core: add sup...
674
  	addr = dev_read_addr_size_index(dev, 0, &size);
795988204   Álvaro Fernández Rojas   dm: core: add fun...
675
  	ut_asserteq(0x8000, addr);
f5b904796   Sekhar Nori   dm: core: add sup...
676
  	ut_asserteq(0x1000, size);
795988204   Álvaro Fernández Rojas   dm: core: add fun...
677
678
679
680
681
682
683
684
685
686
687
688
689
690
  
  	paddr = map_physmem(addr, 0, MAP_NOCACHE);
  	ut_assertnonnull(paddr);
  	ut_asserteq_ptr(paddr, dev_remap_addr_index(dev, 0));
  
  	return 0;
  }
  DM_TEST(dm_test_fdt_remap_addr_index_live,
  	DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  
  static int dm_test_fdt_remap_addr_name_live(struct unit_test_state *uts)
  {
  	struct udevice *dev;
  	fdt_addr_t addr;
f5b904796   Sekhar Nori   dm: core: add sup...
691
  	fdt_size_t size;
795988204   Álvaro Fernández Rojas   dm: core: add fun...
692
693
694
  	void *paddr;
  
  	ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
f5b904796   Sekhar Nori   dm: core: add sup...
695
  	addr = dev_read_addr_size_name(dev, "sandbox-dummy-0", &size);
795988204   Álvaro Fernández Rojas   dm: core: add fun...
696
  	ut_asserteq(0x8000, addr);
f5b904796   Sekhar Nori   dm: core: add sup...
697
  	ut_asserteq(0x1000, size);
795988204   Álvaro Fernández Rojas   dm: core: add fun...
698
699
700
701
702
703
704
705
706
  
  	paddr = map_physmem(addr, 0, MAP_NOCACHE);
  	ut_assertnonnull(paddr);
  	ut_asserteq_ptr(paddr, dev_remap_addr_name(dev, "sandbox-dummy-0"));
  
  	return 0;
  }
  DM_TEST(dm_test_fdt_remap_addr_name_live,
  	DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
2ea4d0db7   Mario Six   test: Add tests f...
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
  static int dm_test_fdt_livetree_writing(struct unit_test_state *uts)
  {
  	struct udevice *dev;
  	ofnode node;
  
  	if (!of_live_active()) {
  		printf("Live tree not active; ignore test
  ");
  		return 0;
  	}
  
  	/* Test enabling devices */
  
  	node = ofnode_path("/usb@2");
  
  	ut_assert(!of_device_is_available(ofnode_to_np(node)));
  	ofnode_set_enabled(node, true);
  	ut_assert(of_device_is_available(ofnode_to_np(node)));
  
  	device_bind_driver_to_node(dm_root(), "usb_sandbox", "usb@2", node,
  				   &dev);
  	ut_assertok(uclass_find_device_by_seq(UCLASS_USB, 2, true, &dev));
  
  	/* Test string property setting */
  
  	ut_assert(device_is_compatible(dev, "sandbox,usb"));
  	ofnode_write_string(node, "compatible", "gdsys,super-usb");
  	ut_assert(device_is_compatible(dev, "gdsys,super-usb"));
  	ofnode_write_string(node, "compatible", "sandbox,usb");
  	ut_assert(device_is_compatible(dev, "sandbox,usb"));
  
  	/* Test setting generic properties */
  
  	/* Non-existent in DTB */
  	ut_asserteq(FDT_ADDR_T_NONE, dev_read_addr(dev));
  	/* reg = 0x42, size = 0x100 */
  	ut_assertok(ofnode_write_prop(node, "reg", 8,
  				      "\x00\x00\x00\x42\x00\x00\x01\x00"));
  	ut_asserteq(0x42, dev_read_addr(dev));
  
  	/* Test disabling devices */
  
  	device_remove(dev, DM_REMOVE_NORMAL);
  	device_unbind(dev);
  
  	ut_assert(of_device_is_available(ofnode_to_np(node)));
  	ofnode_set_enabled(node, false);
  	ut_assert(!of_device_is_available(ofnode_to_np(node)));
  
  	return 0;
  }
  DM_TEST(dm_test_fdt_livetree_writing, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
172942a4a   Mario Six   test: Add tests f...
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
  
  static int dm_test_fdt_disable_enable_by_path(struct unit_test_state *uts)
  {
  	ofnode node;
  
  	if (!of_live_active()) {
  		printf("Live tree not active; ignore test
  ");
  		return 0;
  	}
  
  	node = ofnode_path("/usb@2");
  
  	/* Test enabling devices */
  
  	ut_assert(!of_device_is_available(ofnode_to_np(node)));
  	dev_enable_by_path("/usb@2");
  	ut_assert(of_device_is_available(ofnode_to_np(node)));
  
  	/* Test disabling devices */
  
  	ut_assert(of_device_is_available(ofnode_to_np(node)));
  	dev_disable_by_path("/usb@2");
  	ut_assert(!of_device_is_available(ofnode_to_np(node)));
  
  	return 0;
  }
  DM_TEST(dm_test_fdt_disable_enable_by_path, DM_TESTF_SCAN_PDATA |
  					    DM_TESTF_SCAN_FDT);
d0b4f68d1   Simon Glass   dm: core: Export ...
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
  
  /* Test a few uclass phandle functions */
  static int dm_test_fdt_phandle(struct unit_test_state *uts)
  {
  	struct udevice *back, *dev, *dev2;
  
  	ut_assertok(uclass_find_first_device(UCLASS_PANEL_BACKLIGHT, &back));
  	ut_asserteq(-ENOENT, uclass_find_device_by_phandle(UCLASS_REGULATOR,
  							back, "missing", &dev));
  	ut_assertok(uclass_find_device_by_phandle(UCLASS_REGULATOR, back,
  						  "power-supply", &dev));
  	ut_asserteq(0, device_active(dev));
  	ut_asserteq_str("ldo1", dev->name);
  	ut_assertok(uclass_get_device_by_phandle(UCLASS_REGULATOR, back,
  						 "power-supply", &dev2));
  	ut_asserteq_ptr(dev, dev2);
  
  	return 0;
  }
  DM_TEST(dm_test_fdt_phandle, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
3abe11153   Simon Glass   dm: core: Add a f...
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
  
  /* Test device_find_first_child_by_uclass() */
  static int dm_test_first_child(struct unit_test_state *uts)
  {
  	struct udevice *i2c, *dev, *dev2;
  
  	ut_assertok(uclass_first_device_err(UCLASS_I2C, &i2c));
  	ut_assertok(device_find_first_child_by_uclass(i2c, UCLASS_RTC, &dev));
  	ut_asserteq_str("rtc@43", dev->name);
  	ut_assertok(device_find_child_by_name(i2c, "rtc@43", &dev2));
  	ut_asserteq_ptr(dev, dev2);
  	ut_assertok(device_find_child_by_name(i2c, "rtc@61", &dev2));
  	ut_asserteq_str("rtc@61", dev2->name);
  
  	ut_assertok(device_find_first_child_by_uclass(i2c, UCLASS_I2C_EEPROM,
  						      &dev));
  	ut_asserteq_str("eeprom@2c", dev->name);
  	ut_assertok(device_find_child_by_name(i2c, "eeprom@2c", &dev2));
  	ut_asserteq_ptr(dev, dev2);
  
  	ut_asserteq(-ENODEV, device_find_first_child_by_uclass(i2c,
  							UCLASS_VIDEO, &dev));
  	ut_asserteq(-ENODEV, device_find_child_by_name(i2c, "missing", &dev));
  
  	return 0;
  }
  DM_TEST(dm_test_first_child, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
a1b17e4f4   Simon Glass   dm: core: Add a f...
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
  
  /* Test integer functions in dm_read_...() */
  static int dm_test_read_int(struct unit_test_state *uts)
  {
  	struct udevice *dev;
  	u32 val32;
  	s32 sval;
  	uint val;
  
  	ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev));
  	ut_asserteq_str("a-test", dev->name);
  	ut_assertok(dev_read_u32(dev, "int-value", &val32));
  	ut_asserteq(1234, val32);
  
  	ut_asserteq(-EINVAL, dev_read_u32(dev, "missing", &val32));
  	ut_asserteq(6, dev_read_u32_default(dev, "missing", 6));
  
  	ut_asserteq(1234, dev_read_u32_default(dev, "int-value", 6));
  	ut_asserteq(1234, val32);
  
  	ut_asserteq(-EINVAL, dev_read_s32(dev, "missing", &sval));
  	ut_asserteq(6, dev_read_s32_default(dev, "missing", 6));
  
  	ut_asserteq(-1234, dev_read_s32_default(dev, "uint-value", 6));
  	ut_assertok(dev_read_s32(dev, "uint-value", &sval));
  	ut_asserteq(-1234, sval);
  
  	val = 0;
  	ut_asserteq(-EINVAL, dev_read_u32u(dev, "missing", &val));
  	ut_assertok(dev_read_u32u(dev, "uint-value", &val));
  	ut_asserteq(-1234, val);
  
  	return 0;
  }
  DM_TEST(dm_test_read_int, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
50162348f   Simon Glass   dm: core: Add a f...
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
  
  /* Test iteration through devices by drvdata */
  static int dm_test_uclass_drvdata(struct unit_test_state *uts)
  {
  	struct udevice *dev;
  
  	ut_assertok(uclass_first_device_drvdata(UCLASS_TEST_FDT,
  						DM_TEST_TYPE_FIRST, &dev));
  	ut_asserteq_str("a-test", dev->name);
  
  	ut_assertok(uclass_first_device_drvdata(UCLASS_TEST_FDT,
  						DM_TEST_TYPE_SECOND, &dev));
  	ut_asserteq_str("d-test", dev->name);
  
  	ut_asserteq(-ENODEV, uclass_first_device_drvdata(UCLASS_TEST_FDT,
  							 DM_TEST_TYPE_COUNT,
  							 &dev));
  
  	return 0;
  }
  DM_TEST(dm_test_uclass_drvdata, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
f262d4ca4   Simon Glass   dm: core: Add a w...
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
  
  /* Test device_first_child_ofdata_err(), etc. */
  static int dm_test_child_ofdata(struct unit_test_state *uts)
  {
  	struct udevice *bus, *dev;
  	int count;
  
  	ut_assertok(uclass_first_device_err(UCLASS_TEST_BUS, &bus));
  	count = 0;
  	device_foreach_child_ofdata_to_platdata(dev, bus) {
  		ut_assert(dev->flags & DM_FLAG_PLATDATA_VALID);
  		ut_assert(!(dev->flags & DM_FLAG_ACTIVATED));
  		count++;
  	}
  	ut_asserteq(3, count);
  
  	return 0;
  }
  DM_TEST(dm_test_child_ofdata, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
903e83ee8   Simon Glass   dm: core: Add a w...
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
  
  /* Test device_first_child_err(), etc. */
  static int dm_test_first_child_probe(struct unit_test_state *uts)
  {
  	struct udevice *bus, *dev;
  	int count;
  
  	ut_assertok(uclass_first_device_err(UCLASS_TEST_BUS, &bus));
  	count = 0;
  	device_foreach_child_probe(dev, bus) {
  		ut_assert(dev->flags & DM_FLAG_PLATDATA_VALID);
  		ut_assert(dev->flags & DM_FLAG_ACTIVATED);
  		count++;
  	}
  	ut_asserteq(3, count);
  
  	return 0;
  }
  DM_TEST(dm_test_first_child_probe, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);