blob: ab2b8a1f9ffaaf9229dc8331fb914e2daec47f5c [file] [log] [blame]
Simon Glassf80ebb22023-08-14 16:40:26 -06001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2023 Google LLC
4 * Written by Simon Glass <sjg@chromium.org>
5 */
6
7#include <common.h>
8#include <cedit.h>
Simon Glassfc9c0e02023-08-14 16:40:35 -06009#include <env.h>
Simon Glassf80ebb22023-08-14 16:40:26 -060010#include <expo.h>
Simon Glass2dee81f2023-08-14 16:40:33 -060011#include <mapmem.h>
12#include <dm/ofnode.h>
Simon Glassf80ebb22023-08-14 16:40:26 -060013#include <test/ut.h>
14#include "bootstd_common.h"
15#include <test/cedit-test.h>
16#include "../../boot/scene_internal.h"
17
18/* Check the cedit command */
19static int cedit_base(struct unit_test_state *uts)
20{
21 extern struct expo *cur_exp;
22 struct scene_obj_menu *menu;
23 struct scene_obj_txt *txt;
24 struct expo *exp;
25 struct scene *scn;
26
27 ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0));
28
29 console_record_reset_enable();
30
31 /*
32 * ^N Move down to second menu
33 * ^M Open menu
34 * ^N Move down to second item
35 * ^M Select item
36 * \e Quit
37 */
38 console_in_puts("\x0e\x0d\x0e\x0d\e");
39 ut_assertok(run_command("cedit run", 0));
40
41 exp = cur_exp;
42 scn = expo_lookup_scene_id(exp, exp->scene_id);
43 ut_assertnonnull(scn);
44
45 menu = scene_obj_find(scn, scn->highlight_id, SCENEOBJT_NONE);
46 ut_assertnonnull(menu);
47
48 txt = scene_obj_find(scn, menu->title_id, SCENEOBJT_NONE);
49 ut_assertnonnull(txt);
50 ut_asserteq_str("AC Power", expo_get_str(exp, txt->str_id));
51
52 ut_asserteq(ID_AC_ON, menu->cur_item_id);
53
54 return 0;
55}
56BOOTSTD_TEST(cedit_base, 0);
Simon Glass2dee81f2023-08-14 16:40:33 -060057
Simon Glass472317c2023-08-14 16:40:34 -060058/* Check the cedit write_fdt and read_fdt commands */
Simon Glass2dee81f2023-08-14 16:40:33 -060059static int cedit_fdt(struct unit_test_state *uts)
60{
61 struct video_priv *vid_priv;
62 extern struct expo *cur_exp;
Simon Glass472317c2023-08-14 16:40:34 -060063 struct scene_obj_menu *menu;
Simon Glass2dee81f2023-08-14 16:40:33 -060064 ulong addr = 0x1000;
65 struct ofprop prop;
66 struct scene *scn;
67 oftree tree;
68 ofnode node;
69 void *fdt;
70 int i;
71
72 console_record_reset_enable();
73 ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0));
74
75 ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, &vid_priv, &scn));
76
Simon Glass472317c2023-08-14 16:40:34 -060077 /* get a menu to fiddle with */
78 menu = scene_obj_find(scn, ID_CPU_SPEED, SCENEOBJT_MENU);
79 ut_assertnonnull(menu);
80 menu->cur_item_id = ID_CPU_SPEED_2;
81
Simon Glass2dee81f2023-08-14 16:40:33 -060082 ut_assertok(run_command("cedit write_fdt hostfs - settings.dtb", 0));
83 ut_assertok(run_commandf("load hostfs - %lx settings.dtb", addr));
84 ut_assert_nextlinen("1024 bytes read");
85
86 fdt = map_sysmem(addr, 1024);
87 tree = oftree_from_fdt(fdt);
88 node = ofnode_find_subnode(oftree_root(tree), CEDIT_NODE_NAME);
89
Simon Glass472317c2023-08-14 16:40:34 -060090 ut_asserteq(ID_CPU_SPEED_2,
Simon Glass2dee81f2023-08-14 16:40:33 -060091 ofnode_read_u32_default(node, "cpu-speed", 0));
Simon Glass472317c2023-08-14 16:40:34 -060092 ut_asserteq_str("2.5 GHz", ofnode_read_string(node, "cpu-speed-str"));
Simon Glass2dee81f2023-08-14 16:40:33 -060093 ut_assert(ofnode_valid(node));
94
95 /* There should only be 4 properties */
96 for (i = 0, ofnode_first_property(node, &prop); ofprop_valid(&prop);
97 i++, ofnode_next_property(&prop))
98 ;
99 ut_asserteq(4, i);
100
101 ut_assert_console_end();
102
Simon Glass472317c2023-08-14 16:40:34 -0600103 /* reset the expo */
104 menu->cur_item_id = ID_CPU_SPEED_1;
105
106 /* load in the settings and make sure they update */
107 ut_assertok(run_command("cedit read_fdt hostfs - settings.dtb", 0));
108 ut_asserteq(ID_CPU_SPEED_2, menu->cur_item_id);
109
110 ut_assertnonnull(menu);
111 ut_assert_console_end();
112
Simon Glass2dee81f2023-08-14 16:40:33 -0600113 return 0;
114}
115BOOTSTD_TEST(cedit_fdt, 0);
Simon Glassfc9c0e02023-08-14 16:40:35 -0600116
Simon Glassbcf2b722023-08-14 16:40:36 -0600117/* Check the cedit write_env and read_env commands */
Simon Glassfc9c0e02023-08-14 16:40:35 -0600118static int cedit_env(struct unit_test_state *uts)
119{
120 struct video_priv *vid_priv;
121 extern struct expo *cur_exp;
122 struct scene_obj_menu *menu;
123 struct scene *scn;
124
125 console_record_reset_enable();
126 ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0));
127
128 ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, &vid_priv, &scn));
129
130 /* get a menu to fiddle with */
131 menu = scene_obj_find(scn, ID_CPU_SPEED, SCENEOBJT_MENU);
132 ut_assertnonnull(menu);
133 menu->cur_item_id = ID_CPU_SPEED_2;
134
135 ut_assertok(run_command("cedit write_env -v", 0));
136 ut_assert_nextlinen("c.cpu-speed=7");
137 ut_assert_nextlinen("c.cpu-speed-str=2.5 GHz");
138 ut_assert_nextlinen("c.power-loss=10");
139 ut_assert_nextlinen("c.power-loss-str=Always Off");
140 ut_assert_console_end();
141
142 ut_asserteq(7, env_get_ulong("c.cpu-speed", 10, 0));
143 ut_asserteq_str("2.5 GHz", env_get("c.cpu-speed-str"));
144
Simon Glassbcf2b722023-08-14 16:40:36 -0600145 /* reset the expo */
146 menu->cur_item_id = ID_CPU_SPEED_1;
147
148 ut_assertok(run_command("cedit read_env -v", 0));
149 ut_assert_nextlinen("c.cpu-speed=7");
150 ut_assert_nextlinen("c.power-loss=10");
151 ut_assert_console_end();
152
153 ut_asserteq(ID_CPU_SPEED_2, menu->cur_item_id);
154
Simon Glassfc9c0e02023-08-14 16:40:35 -0600155 return 0;
156}
157BOOTSTD_TEST(cedit_env, 0);
Simon Glasseb6c71b2023-08-14 16:40:37 -0600158
159/* Check the cedit write_cmos and read_cmos commands */
160static int cedit_cmos(struct unit_test_state *uts)
161{
162 struct scene_obj_menu *menu, *menu2;
163 struct video_priv *vid_priv;
164 extern struct expo *cur_exp;
165 struct scene *scn;
166
167 console_record_reset_enable();
168 ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0));
169
170 ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, &vid_priv, &scn));
171
172 /* get the menus to fiddle with */
173 menu = scene_obj_find(scn, ID_CPU_SPEED, SCENEOBJT_MENU);
174 ut_assertnonnull(menu);
175 menu->cur_item_id = ID_CPU_SPEED_2;
176
177 menu2 = scene_obj_find(scn, ID_POWER_LOSS, SCENEOBJT_MENU);
178 ut_assertnonnull(menu2);
179 menu2->cur_item_id = ID_AC_MEMORY;
180
181 ut_assertok(run_command("cedit write_cmos -v", 0));
182 ut_assert_nextlinen("Write 2 bytes from offset 80 to 84");
183 ut_assert_console_end();
184
Simon Glasscfc402d2023-08-14 16:40:38 -0600185 /* reset the expo */
186 menu->cur_item_id = ID_CPU_SPEED_1;
187 menu2->cur_item_id = ID_AC_OFF;
188
189 ut_assertok(run_command("cedit read_cmos -v", 0));
190 ut_assert_nextlinen("Read 2 bytes from offset 80 to 84");
191 ut_assert_console_end();
192
193 ut_asserteq(ID_CPU_SPEED_2, menu->cur_item_id);
194 ut_asserteq(ID_AC_MEMORY, menu2->cur_item_id);
195
Simon Glasseb6c71b2023-08-14 16:40:37 -0600196 return 0;
197}
198BOOTSTD_TEST(cedit_cmos, 0);