Mario Six | dea5df7 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 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> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Mario Six | dea5df7 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 10 | #include <dm/test.h> |
| 11 | #include <dm/uclass-internal.h> |
| 12 | #include <cpu.h> |
Simon Glass | 75c4d41 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 13 | #include <test/test.h> |
Mario Six | dea5df7 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 14 | #include <test/ut.h> |
| 15 | |
| 16 | static int dm_test_cpu(struct unit_test_state *uts) |
| 17 | { |
| 18 | struct udevice *dev; |
| 19 | char text[128]; |
| 20 | struct cpu_info info; |
| 21 | |
| 22 | ut_assertok(cpu_probe_all()); |
| 23 | |
| 24 | /* Check that cpu_probe_all really activated all CPUs */ |
| 25 | for (uclass_find_first_device(UCLASS_CPU, &dev); |
| 26 | dev; |
| 27 | uclass_find_next_device(&dev)) |
Simon Glass | 6211d76 | 2020-12-19 10:40:10 -0700 | [diff] [blame] | 28 | ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED); |
Mario Six | dea5df7 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 29 | |
| 30 | ut_assertok(uclass_get_device_by_name(UCLASS_CPU, "cpu-test1", &dev)); |
Peng Fan | 137432a | 2020-05-03 21:58:49 +0800 | [diff] [blame] | 31 | ut_asserteq_ptr(cpu_get_current_dev(), dev); |
| 32 | ut_asserteq(cpu_is_current(dev), 1); |
Mario Six | dea5df7 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 33 | |
| 34 | ut_assertok(cpu_get_desc(dev, text, sizeof(text))); |
| 35 | ut_assertok(strcmp(text, "LEG Inc. SuperMegaUltraTurbo CPU No. 1")); |
| 36 | |
| 37 | ut_assertok(cpu_get_info(dev, &info)); |
| 38 | ut_asserteq(info.cpu_freq, 42 * 42 * 42 * 42 * 42); |
| 39 | ut_asserteq(info.features, 0x42424242); |
Simon Glass | c35854a | 2020-04-08 16:57:20 -0600 | [diff] [blame] | 40 | ut_asserteq(info.address_width, 32); |
Mario Six | dea5df7 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 41 | |
| 42 | ut_asserteq(cpu_get_count(dev), 42); |
| 43 | |
| 44 | ut_assertok(cpu_get_vendor(dev, text, sizeof(text))); |
| 45 | ut_assertok(strcmp(text, "Languid Example Garbage Inc.")); |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 50 | DM_TEST(dm_test_cpu, UT_TESTF_SCAN_FDT); |