blob: 885cddb8690f203e6f9bf9f9bcf1a0727ef7efe6 [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
Mario Sixdea5df72018-08-06 10:23:44 +02007#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
Mario Sixdea5df72018-08-06 10:23:44 +02009#include <dm/test.h>
10#include <dm/uclass-internal.h>
11#include <cpu.h>
Simon Glass75c4d412020-07-19 10:15:37 -060012#include <test/test.h>
Mario Sixdea5df72018-08-06 10:23:44 +020013#include <test/ut.h>
14
15static int dm_test_cpu(struct unit_test_state *uts)
16{
17 struct udevice *dev;
18 char text[128];
19 struct cpu_info info;
20
21 ut_assertok(cpu_probe_all());
22
23 /* Check that cpu_probe_all really activated all CPUs */
24 for (uclass_find_first_device(UCLASS_CPU, &dev);
25 dev;
26 uclass_find_next_device(&dev))
Simon Glass6211d762020-12-19 10:40:10 -070027 ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
Mario Sixdea5df72018-08-06 10:23:44 +020028
Heinrich Schuchardt20f9d3d2021-08-28 11:42:08 +020029 ut_assertok(uclass_get_device_by_name(UCLASS_CPU, "cpu@1", &dev));
Peng Fan137432a2020-05-03 21:58:49 +080030 ut_asserteq_ptr(cpu_get_current_dev(), dev);
31 ut_asserteq(cpu_is_current(dev), 1);
Mario Sixdea5df72018-08-06 10:23:44 +020032
33 ut_assertok(cpu_get_desc(dev, text, sizeof(text)));
34 ut_assertok(strcmp(text, "LEG Inc. SuperMegaUltraTurbo CPU No. 1"));
35
36 ut_assertok(cpu_get_info(dev, &info));
37 ut_asserteq(info.cpu_freq, 42 * 42 * 42 * 42 * 42);
38 ut_asserteq(info.features, 0x42424242);
Marek Vasut5d5dd812023-08-13 21:52:19 +020039 ut_asserteq(info.address_width, IS_ENABLED(CONFIG_PHYS_64BIT) ? 64 : 32);
Mario Sixdea5df72018-08-06 10:23:44 +020040
41 ut_asserteq(cpu_get_count(dev), 42);
42
43 ut_assertok(cpu_get_vendor(dev, text, sizeof(text)));
44 ut_assertok(strcmp(text, "Languid Example Garbage Inc."));
45
Hou Zhiqiang42d78362024-08-01 11:59:49 +080046 ut_assertok(cpu_release_core(dev, 0));
47
Mario Sixdea5df72018-08-06 10:23:44 +020048 return 0;
49}
50
Simon Glass1a92f832024-08-22 07:57:48 -060051DM_TEST(dm_test_cpu, UTF_SCAN_FDT);