blob: 4aaa9e85bce0f731f1adece77a36f69941097e42 [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;
20 bool called_detect;
21 char str[64];
22 int i;
23
24 ut_assertok(sysinfo_get(&sysinfo));
25 ut_assert(sysinfo);
26
27 sysinfo_get_bool(sysinfo, BOOL_CALLED_DETECT, &called_detect);
28 ut_assert(!called_detect);
29
30 sysinfo_detect(sysinfo);
31
32 sysinfo_get_bool(sysinfo, BOOL_CALLED_DETECT, &called_detect);
33 ut_assert(called_detect);
34
35 sysinfo_get_str(sysinfo, STR_VACATIONSPOT, sizeof(str), str);
36 ut_assertok(strcmp(str, "R'lyeh"));
37
38 sysinfo_get_int(sysinfo, INT_TEST1, &i);
39 ut_asserteq(0, i);
40
41 sysinfo_get_int(sysinfo, INT_TEST2, &i);
42 ut_asserteq(100, i);
43
44 sysinfo_get_str(sysinfo, STR_VACATIONSPOT, sizeof(str), str);
45 ut_assertok(strcmp(str, "Carcosa"));
46
47 sysinfo_get_int(sysinfo, INT_TEST1, &i);
48 ut_asserteq(1, i);
49
50 sysinfo_get_int(sysinfo, INT_TEST2, &i);
51 ut_asserteq(99, i);
52
53 sysinfo_get_str(sysinfo, STR_VACATIONSPOT, sizeof(str), str);
54 ut_assertok(strcmp(str, "Yuggoth"));
55
56 return 0;
57}
58
59DM_TEST(dm_test_sysinfo, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);