]> Git Repo - J-u-boot.git/blob - test/boot/cedit.c
1dd78c64158dd4375905a996b0c70bd05fbb39d1
[J-u-boot.git] / test / boot / cedit.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2023 Google LLC
4  * Written by Simon Glass <[email protected]>
5  */
6
7 #include <common.h>
8 #include <cedit.h>
9 #include <expo.h>
10 #include <mapmem.h>
11 #include <dm/ofnode.h>
12 #include <test/ut.h>
13 #include "bootstd_common.h"
14 #include <test/cedit-test.h>
15 #include "../../boot/scene_internal.h"
16
17 /* Check the cedit command */
18 static int cedit_base(struct unit_test_state *uts)
19 {
20         extern struct expo *cur_exp;
21         struct scene_obj_menu *menu;
22         struct scene_obj_txt *txt;
23         struct expo *exp;
24         struct scene *scn;
25
26         ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0));
27
28         console_record_reset_enable();
29
30         /*
31          * ^N  Move down to second menu
32          * ^M  Open menu
33          * ^N  Move down to second item
34          * ^M  Select item
35          * \e  Quit
36          */
37         console_in_puts("\x0e\x0d\x0e\x0d\e");
38         ut_assertok(run_command("cedit run", 0));
39
40         exp = cur_exp;
41         scn = expo_lookup_scene_id(exp, exp->scene_id);
42         ut_assertnonnull(scn);
43
44         menu = scene_obj_find(scn, scn->highlight_id, SCENEOBJT_NONE);
45         ut_assertnonnull(menu);
46
47         txt = scene_obj_find(scn, menu->title_id, SCENEOBJT_NONE);
48         ut_assertnonnull(txt);
49         ut_asserteq_str("AC Power", expo_get_str(exp, txt->str_id));
50
51         ut_asserteq(ID_AC_ON, menu->cur_item_id);
52
53         return 0;
54 }
55 BOOTSTD_TEST(cedit_base, 0);
56
57 /* Check the cedit write_fdt commands */
58 static int cedit_fdt(struct unit_test_state *uts)
59 {
60         struct video_priv *vid_priv;
61         extern struct expo *cur_exp;
62         ulong addr = 0x1000;
63         struct ofprop prop;
64         struct scene *scn;
65         oftree tree;
66         ofnode node;
67         void *fdt;
68         int i;
69
70         console_record_reset_enable();
71         ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0));
72
73         ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, &vid_priv, &scn));
74
75         ut_assertok(run_command("cedit write_fdt hostfs - settings.dtb", 0));
76         ut_assertok(run_commandf("load hostfs - %lx settings.dtb", addr));
77         ut_assert_nextlinen("1024 bytes read");
78
79         fdt = map_sysmem(addr, 1024);
80         tree = oftree_from_fdt(fdt);
81         node = ofnode_find_subnode(oftree_root(tree), CEDIT_NODE_NAME);
82
83         ut_asserteq(ID_CPU_SPEED_1,
84                     ofnode_read_u32_default(node, "cpu-speed", 0));
85         ut_asserteq_str("2 GHz", ofnode_read_string(node, "cpu-speed-str"));
86         ut_assert(ofnode_valid(node));
87
88         /* There should only be 4 properties */
89         for (i = 0, ofnode_first_property(node, &prop); ofprop_valid(&prop);
90              i++, ofnode_next_property(&prop))
91                 ;
92         ut_asserteq(4, i);
93
94         ut_assert_console_end();
95
96         return 0;
97 }
98 BOOTSTD_TEST(cedit_fdt, 0);
This page took 0.020668 seconds and 2 git commands to generate.