blob: 7444a580df6eb402f177866be6ad7629904b49ae [file] [log] [blame]
Simon Glass458b66a2020-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
Simon Glass458b66a2020-11-05 06:32:05 -07007#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
16static int dm_test_sysinfo(struct unit_test_state *uts)
17{
18 struct udevice *sysinfo;
Sean Anderson6ccf10a2021-04-20 10:50:56 -040019 bool called_detect = false;
Simon Glass458b66a2020-11-05 06:32:05 -070020 char str[64];
21 int i;
22
23 ut_assertok(sysinfo_get(&sysinfo));
24 ut_assert(sysinfo);
25
Sean Anderson6ccf10a2021-04-20 10:50:56 -040026 ut_asserteq(-EPERM, sysinfo_get_bool(sysinfo, BOOL_CALLED_DETECT,
27 &called_detect));
Simon Glass458b66a2020-11-05 06:32:05 -070028 ut_assert(!called_detect);
29
30 sysinfo_detect(sysinfo);
31
Sean Anderson6ccf10a2021-04-20 10:50:56 -040032 ut_assertok(sysinfo_get_bool(sysinfo, BOOL_CALLED_DETECT,
33 &called_detect));
Simon Glass458b66a2020-11-05 06:32:05 -070034 ut_assert(called_detect);
35
Sean Anderson6ccf10a2021-04-20 10:50:56 -040036 ut_assertok(sysinfo_get_str(sysinfo, STR_VACATIONSPOT, sizeof(str),
37 str));
Simon Glass458b66a2020-11-05 06:32:05 -070038 ut_assertok(strcmp(str, "R'lyeh"));
39
Sean Anderson6ccf10a2021-04-20 10:50:56 -040040 ut_assertok(sysinfo_get_int(sysinfo, INT_TEST1, &i));
Simon Glass458b66a2020-11-05 06:32:05 -070041 ut_asserteq(0, i);
42
Sean Anderson6ccf10a2021-04-20 10:50:56 -040043 ut_assertok(sysinfo_get_int(sysinfo, INT_TEST2, &i));
Simon Glass458b66a2020-11-05 06:32:05 -070044 ut_asserteq(100, i);
45
Sean Anderson6ccf10a2021-04-20 10:50:56 -040046 ut_assertok(sysinfo_get_str(sysinfo, STR_VACATIONSPOT, sizeof(str),
47 str));
Simon Glass458b66a2020-11-05 06:32:05 -070048 ut_assertok(strcmp(str, "Carcosa"));
49
Sean Anderson6ccf10a2021-04-20 10:50:56 -040050 ut_assertok(sysinfo_get_int(sysinfo, INT_TEST1, &i));
Simon Glass458b66a2020-11-05 06:32:05 -070051 ut_asserteq(1, i);
52
Sean Anderson6ccf10a2021-04-20 10:50:56 -040053 ut_assertok(sysinfo_get_int(sysinfo, INT_TEST2, &i));
Simon Glass458b66a2020-11-05 06:32:05 -070054 ut_asserteq(99, i);
55
Sean Anderson6ccf10a2021-04-20 10:50:56 -040056 ut_assertok(sysinfo_get_str(sysinfo, STR_VACATIONSPOT, sizeof(str),
57 str));
Simon Glass458b66a2020-11-05 06:32:05 -070058 ut_assertok(strcmp(str, "Yuggoth"));
59
60 return 0;
61}
62
63DM_TEST(dm_test_sysinfo, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);