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