blob: def9b64a282fd575f19d5805a7726b45de77ec2d [file] [log] [blame]
Mario Sixdea5df72018-08-06 10:23:44 +02001// 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
14static 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));
Peng Fan137432a2020-05-03 21:58:49 +080029 ut_asserteq_ptr(cpu_get_current_dev(), dev);
30 ut_asserteq(cpu_is_current(dev), 1);
Mario Sixdea5df72018-08-06 10:23:44 +020031
32 ut_assertok(cpu_get_desc(dev, text, sizeof(text)));
33 ut_assertok(strcmp(text, "LEG Inc. SuperMegaUltraTurbo CPU No. 1"));
34
35 ut_assertok(cpu_get_info(dev, &info));
36 ut_asserteq(info.cpu_freq, 42 * 42 * 42 * 42 * 42);
37 ut_asserteq(info.features, 0x42424242);
Simon Glassc35854a2020-04-08 16:57:20 -060038 ut_asserteq(info.address_width, 32);
Mario Sixdea5df72018-08-06 10:23:44 +020039
40 ut_asserteq(cpu_get_count(dev), 42);
41
42 ut_assertok(cpu_get_vendor(dev, text, sizeof(text)));
43 ut_assertok(strcmp(text, "Languid Example Garbage Inc."));
44
45 return 0;
46}
47
48DM_TEST(dm_test_cpu, DM_TESTF_SCAN_FDT);