Commit fa44b53398d3a7f5ed28cb83493a70cde11f8188
Committed by
Simon Glass
1 parent
57370de377
Exists in
smarc_8mq_lf_v2020.04
and in
11 other branches
test: Add tests for CPU uclass
Add a sandbox CPU driver, and some tests for the CPU uclass. Signed-off-by: Mario Six <mario.six@gdsys.cc>
Showing 5 changed files with 120 additions and 0 deletions Side-by-side Diff
arch/sandbox/dts/test.dts
... | ... | @@ -297,6 +297,18 @@ |
297 | 297 | mbox-names = "other", "test"; |
298 | 298 | }; |
299 | 299 | |
300 | + cpu-test1 { | |
301 | + compatible = "sandbox,cpu_sandbox"; | |
302 | + }; | |
303 | + | |
304 | + cpu-test2 { | |
305 | + compatible = "sandbox,cpu_sandbox"; | |
306 | + }; | |
307 | + | |
308 | + cpu-test3 { | |
309 | + compatible = "sandbox,cpu_sandbox"; | |
310 | + }; | |
311 | + | |
300 | 312 | misc-test { |
301 | 313 | compatible = "sandbox,misc_sandbox"; |
302 | 314 | }; |
drivers/cpu/Makefile
drivers/cpu/cpu_sandbox.c
1 | +// SPDX-License-Identifier: GPL-2.0+ | |
2 | +/* | |
3 | + * (C) Copyright 2018 | |
4 | + * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc | |
5 | + */ | |
6 | + | |
7 | +#include <common.h> | |
8 | +#include <dm.h> | |
9 | +#include <cpu.h> | |
10 | + | |
11 | +int cpu_sandbox_get_desc(struct udevice *dev, char *buf, int size) | |
12 | +{ | |
13 | + snprintf(buf, size, "LEG Inc. SuperMegaUltraTurbo CPU No. 1"); | |
14 | + | |
15 | + return 0; | |
16 | +} | |
17 | + | |
18 | +int cpu_sandbox_get_info(struct udevice *dev, struct cpu_info *info) | |
19 | +{ | |
20 | + info->cpu_freq = 42 * 42 * 42 * 42 * 42; | |
21 | + info->features = 0x42424242; | |
22 | + | |
23 | + return 0; | |
24 | +} | |
25 | + | |
26 | +int cpu_sandbox_get_count(struct udevice *dev) | |
27 | +{ | |
28 | + return 42; | |
29 | +} | |
30 | + | |
31 | +int cpu_sandbox_get_vendor(struct udevice *dev, char *buf, int size) | |
32 | +{ | |
33 | + snprintf(buf, size, "Languid Example Garbage Inc."); | |
34 | + | |
35 | + return 0; | |
36 | +} | |
37 | + | |
38 | +static const struct cpu_ops cpu_sandbox_ops = { | |
39 | + .get_desc = cpu_sandbox_get_desc, | |
40 | + .get_info = cpu_sandbox_get_info, | |
41 | + .get_count = cpu_sandbox_get_count, | |
42 | + .get_vendor = cpu_sandbox_get_vendor, | |
43 | +}; | |
44 | + | |
45 | +int cpu_sandbox_probe(struct udevice *dev) | |
46 | +{ | |
47 | + return 0; | |
48 | +} | |
49 | + | |
50 | +static const struct udevice_id cpu_sandbox_ids[] = { | |
51 | + { .compatible = "sandbox,cpu_sandbox" }, | |
52 | + { } | |
53 | +}; | |
54 | + | |
55 | +U_BOOT_DRIVER(cpu_sandbox) = { | |
56 | + .name = "cpu_sandbox", | |
57 | + .id = UCLASS_CPU, | |
58 | + .ops = &cpu_sandbox_ops, | |
59 | + .of_match = cpu_sandbox_ids, | |
60 | + .probe = cpu_sandbox_probe, | |
61 | +}; |
test/dm/Makefile
test/dm/cpu.c
1 | +// SPDX-License-Identifier: GPL-2.0+ | |
2 | +/* | |
3 | + * (C) Copyright 2018 | |
4 | + * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc | |
5 | + */ | |
6 | + | |
7 | +#include <common.h> | |
8 | +#include <dm.h> | |
9 | +#include <dm/test.h> | |
10 | +#include <dm/uclass-internal.h> | |
11 | +#include <cpu.h> | |
12 | +#include <test/ut.h> | |
13 | + | |
14 | +static int dm_test_cpu(struct unit_test_state *uts) | |
15 | +{ | |
16 | + struct udevice *dev; | |
17 | + char text[128]; | |
18 | + struct cpu_info info; | |
19 | + | |
20 | + ut_assertok(cpu_probe_all()); | |
21 | + | |
22 | + /* Check that cpu_probe_all really activated all CPUs */ | |
23 | + for (uclass_find_first_device(UCLASS_CPU, &dev); | |
24 | + dev; | |
25 | + uclass_find_next_device(&dev)) | |
26 | + ut_assert(dev->flags & DM_FLAG_ACTIVATED); | |
27 | + | |
28 | + ut_assertok(uclass_get_device_by_name(UCLASS_CPU, "cpu-test1", &dev)); | |
29 | + | |
30 | + ut_assertok(cpu_get_desc(dev, text, sizeof(text))); | |
31 | + ut_assertok(strcmp(text, "LEG Inc. SuperMegaUltraTurbo CPU No. 1")); | |
32 | + | |
33 | + ut_assertok(cpu_get_info(dev, &info)); | |
34 | + ut_asserteq(info.cpu_freq, 42 * 42 * 42 * 42 * 42); | |
35 | + ut_asserteq(info.features, 0x42424242); | |
36 | + | |
37 | + ut_asserteq(cpu_get_count(dev), 42); | |
38 | + | |
39 | + ut_assertok(cpu_get_vendor(dev, text, sizeof(text))); | |
40 | + ut_assertok(strcmp(text, "Languid Example Garbage Inc.")); | |
41 | + | |
42 | + return 0; | |
43 | +} | |
44 | + | |
45 | +DM_TEST(dm_test_cpu, DM_TESTF_SCAN_FDT); |