Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [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 | |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 7 | #include <dm.h> |
| 8 | #include <log.h> |
| 9 | #include <dm/test.h> |
| 10 | #include <sysinfo.h> |
| 11 | #include <test/test.h> |
| 12 | #include <test/ut.h> |
| 13 | |
| 14 | #include "../../drivers/sysinfo/sandbox.h" |
| 15 | |
| 16 | static int dm_test_sysinfo(struct unit_test_state *uts) |
| 17 | { |
| 18 | struct udevice *sysinfo; |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 19 | bool called_detect = false; |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 20 | char str[64]; |
| 21 | int i; |
| 22 | |
| 23 | ut_assertok(sysinfo_get(&sysinfo)); |
| 24 | ut_assert(sysinfo); |
| 25 | |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 26 | ut_asserteq(-EPERM, sysinfo_get_bool(sysinfo, BOOL_CALLED_DETECT, |
| 27 | &called_detect)); |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 28 | ut_assert(!called_detect); |
| 29 | |
| 30 | sysinfo_detect(sysinfo); |
| 31 | |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 32 | ut_assertok(sysinfo_get_bool(sysinfo, BOOL_CALLED_DETECT, |
| 33 | &called_detect)); |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 34 | ut_assert(called_detect); |
| 35 | |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 36 | ut_assertok(sysinfo_get_str(sysinfo, STR_VACATIONSPOT, sizeof(str), |
| 37 | str)); |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 38 | ut_assertok(strcmp(str, "R'lyeh")); |
| 39 | |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 40 | ut_assertok(sysinfo_get_int(sysinfo, INT_TEST1, &i)); |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 41 | ut_asserteq(0, i); |
| 42 | |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 43 | ut_assertok(sysinfo_get_int(sysinfo, INT_TEST2, &i)); |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 44 | ut_asserteq(100, i); |
| 45 | |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 46 | ut_assertok(sysinfo_get_str(sysinfo, STR_VACATIONSPOT, sizeof(str), |
| 47 | str)); |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 48 | ut_assertok(strcmp(str, "Carcosa")); |
| 49 | |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 50 | ut_assertok(sysinfo_get_int(sysinfo, INT_TEST1, &i)); |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 51 | ut_asserteq(1, i); |
| 52 | |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 53 | ut_assertok(sysinfo_get_int(sysinfo, INT_TEST2, &i)); |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 54 | ut_asserteq(99, i); |
| 55 | |
Sean Anderson | 6ccf10a | 2021-04-20 10:50:56 -0400 | [diff] [blame] | 56 | ut_assertok(sysinfo_get_str(sysinfo, STR_VACATIONSPOT, sizeof(str), |
| 57 | str)); |
Simon Glass | 458b66a | 2020-11-05 06:32:05 -0700 | [diff] [blame] | 58 | ut_assertok(strcmp(str, "Yuggoth")); |
| 59 | |
| 60 | return 0; |
| 61 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 62 | DM_TEST(dm_test_sysinfo, UTF_SCAN_PDATA | UTF_SCAN_FDT); |