blob: 96b3a8ebabac9ec50551402884d66ce60da7d8a4 [file] [log] [blame]
Simon Glass3a8ee3d2020-11-05 06:32:05 -07001// 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
17static int dm_test_sysinfo(struct unit_test_state *uts)
18{
19 struct udevice *sysinfo;
Sean Anderson4d65c6b2021-04-20 10:50:56 -040020 bool called_detect = false;
Simon Glass3a8ee3d2020-11-05 06:32:05 -070021 char str[64];
22 int i;
23
24 ut_assertok(sysinfo_get(&sysinfo));
25 ut_assert(sysinfo);
26
Sean Anderson4d65c6b2021-04-20 10:50:56 -040027 ut_asserteq(-EPERM, sysinfo_get_bool(sysinfo, BOOL_CALLED_DETECT,
28 &called_detect));
Simon Glass3a8ee3d2020-11-05 06:32:05 -070029 ut_assert(!called_detect);
30
31 sysinfo_detect(sysinfo);
32
Sean Anderson4d65c6b2021-04-20 10:50:56 -040033 ut_assertok(sysinfo_get_bool(sysinfo, BOOL_CALLED_DETECT,
34 &called_detect));
Simon Glass3a8ee3d2020-11-05 06:32:05 -070035 ut_assert(called_detect);
36
Sean Anderson4d65c6b2021-04-20 10:50:56 -040037 ut_assertok(sysinfo_get_str(sysinfo, STR_VACATIONSPOT, sizeof(str),
38 str));
Simon Glass3a8ee3d2020-11-05 06:32:05 -070039 ut_assertok(strcmp(str, "R'lyeh"));
40
Sean Anderson4d65c6b2021-04-20 10:50:56 -040041 ut_assertok(sysinfo_get_int(sysinfo, INT_TEST1, &i));
Simon Glass3a8ee3d2020-11-05 06:32:05 -070042 ut_asserteq(0, i);
43
Sean Anderson4d65c6b2021-04-20 10:50:56 -040044 ut_assertok(sysinfo_get_int(sysinfo, INT_TEST2, &i));
Simon Glass3a8ee3d2020-11-05 06:32:05 -070045 ut_asserteq(100, i);
46
Sean Anderson4d65c6b2021-04-20 10:50:56 -040047 ut_assertok(sysinfo_get_str(sysinfo, STR_VACATIONSPOT, sizeof(str),
48 str));
Simon Glass3a8ee3d2020-11-05 06:32:05 -070049 ut_assertok(strcmp(str, "Carcosa"));
50
Sean Anderson4d65c6b2021-04-20 10:50:56 -040051 ut_assertok(sysinfo_get_int(sysinfo, INT_TEST1, &i));
Simon Glass3a8ee3d2020-11-05 06:32:05 -070052 ut_asserteq(1, i);
53
Sean Anderson4d65c6b2021-04-20 10:50:56 -040054 ut_assertok(sysinfo_get_int(sysinfo, INT_TEST2, &i));
Simon Glass3a8ee3d2020-11-05 06:32:05 -070055 ut_asserteq(99, i);
56
Sean Anderson4d65c6b2021-04-20 10:50:56 -040057 ut_assertok(sysinfo_get_str(sysinfo, STR_VACATIONSPOT, sizeof(str),
58 str));
Simon Glass3a8ee3d2020-11-05 06:32:05 -070059 ut_assertok(strcmp(str, "Yuggoth"));
60
61 return 0;
62}
63
64DM_TEST(dm_test_sysinfo, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);