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
dm_test_sysinfo(struct unit_test_state * uts)17 static int dm_test_sysinfo(struct unit_test_state *uts)
18 {
19 struct udevice *sysinfo;
20 bool called_detect = false;
21 char str[64];
22 int i;
23
24 ut_assertok(sysinfo_get(&sysinfo));
25 ut_assert(sysinfo);
26
27 ut_asserteq(-EPERM, sysinfo_get_bool(sysinfo, BOOL_CALLED_DETECT,
28 &called_detect));
29 ut_assert(!called_detect);
30
31 sysinfo_detect(sysinfo);
32
33 ut_assertok(sysinfo_get_bool(sysinfo, BOOL_CALLED_DETECT,
34 &called_detect));
35 ut_assert(called_detect);
36
37 ut_assertok(sysinfo_get_str(sysinfo, STR_VACATIONSPOT, sizeof(str),
38 str));
39 ut_assertok(strcmp(str, "R'lyeh"));
40
41 ut_assertok(sysinfo_get_int(sysinfo, INT_TEST1, &i));
42 ut_asserteq(0, i);
43
44 ut_assertok(sysinfo_get_int(sysinfo, INT_TEST2, &i));
45 ut_asserteq(100, i);
46
47 ut_assertok(sysinfo_get_str(sysinfo, STR_VACATIONSPOT, sizeof(str),
48 str));
49 ut_assertok(strcmp(str, "Carcosa"));
50
51 ut_assertok(sysinfo_get_int(sysinfo, INT_TEST1, &i));
52 ut_asserteq(1, i);
53
54 ut_assertok(sysinfo_get_int(sysinfo, INT_TEST2, &i));
55 ut_asserteq(99, i);
56
57 ut_assertok(sysinfo_get_str(sysinfo, STR_VACATIONSPOT, sizeof(str),
58 str));
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);
65