Simon Glass | 44e4ec7 | 2023-08-14 16:40:26 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2023 Google LLC |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
| 5 | */ |
| 6 | |
Simon Glass | 44e4ec7 | 2023-08-14 16:40:26 -0600 | [diff] [blame] | 7 | #include <cedit.h> |
Simon Glass | ee44064 | 2025-05-02 08:46:19 -0600 | [diff] [blame^] | 8 | #include <dm.h> |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 9 | #include <env.h> |
Simon Glass | 44e4ec7 | 2023-08-14 16:40:26 -0600 | [diff] [blame] | 10 | #include <expo.h> |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 11 | #include <mapmem.h> |
| 12 | #include <dm/ofnode.h> |
Simon Glass | 44e4ec7 | 2023-08-14 16:40:26 -0600 | [diff] [blame] | 13 | #include <test/ut.h> |
Simon Glass | ee44064 | 2025-05-02 08:46:19 -0600 | [diff] [blame^] | 14 | #include <test/video.h> |
Simon Glass | 44e4ec7 | 2023-08-14 16:40:26 -0600 | [diff] [blame] | 15 | #include "bootstd_common.h" |
| 16 | #include <test/cedit-test.h> |
| 17 | #include "../../boot/scene_internal.h" |
| 18 | |
| 19 | /* Check the cedit command */ |
| 20 | static int cedit_base(struct unit_test_state *uts) |
| 21 | { |
| 22 | extern struct expo *cur_exp; |
| 23 | struct scene_obj_menu *menu; |
| 24 | struct scene_obj_txt *txt; |
| 25 | struct expo *exp; |
| 26 | struct scene *scn; |
| 27 | |
| 28 | ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0)); |
| 29 | |
Simon Glass | 44e4ec7 | 2023-08-14 16:40:26 -0600 | [diff] [blame] | 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 |
Simon Glass | 53a0a2f | 2024-10-14 16:31:57 -0600 | [diff] [blame] | 36 | * |
| 37 | * cedit_run() returns -EACCESS so this command returns CMD_RET_FAILURE |
Simon Glass | 44e4ec7 | 2023-08-14 16:40:26 -0600 | [diff] [blame] | 38 | */ |
| 39 | console_in_puts("\x0e\x0d\x0e\x0d\e"); |
Simon Glass | 53a0a2f | 2024-10-14 16:31:57 -0600 | [diff] [blame] | 40 | ut_asserteq(1, run_command("cedit run", 0)); |
Simon Glass | 44e4ec7 | 2023-08-14 16:40:26 -0600 | [diff] [blame] | 41 | |
| 42 | exp = cur_exp; |
| 43 | scn = expo_lookup_scene_id(exp, exp->scene_id); |
| 44 | ut_assertnonnull(scn); |
| 45 | |
| 46 | menu = scene_obj_find(scn, scn->highlight_id, SCENEOBJT_NONE); |
| 47 | ut_assertnonnull(menu); |
| 48 | |
| 49 | txt = scene_obj_find(scn, menu->title_id, SCENEOBJT_NONE); |
| 50 | ut_assertnonnull(txt); |
| 51 | ut_asserteq_str("AC Power", expo_get_str(exp, txt->str_id)); |
| 52 | |
| 53 | ut_asserteq(ID_AC_ON, menu->cur_item_id); |
| 54 | |
| 55 | return 0; |
| 56 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 57 | BOOTSTD_TEST(cedit_base, UTF_CONSOLE); |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 58 | |
Simon Glass | b1cd32b | 2023-08-14 16:40:34 -0600 | [diff] [blame] | 59 | /* Check the cedit write_fdt and read_fdt commands */ |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 60 | static int cedit_fdt(struct unit_test_state *uts) |
| 61 | { |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 62 | struct scene_obj_textline *tline; |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 63 | struct video_priv *vid_priv; |
| 64 | extern struct expo *cur_exp; |
Simon Glass | b1cd32b | 2023-08-14 16:40:34 -0600 | [diff] [blame] | 65 | struct scene_obj_menu *menu; |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 66 | ulong addr = 0x1000; |
| 67 | struct ofprop prop; |
| 68 | struct scene *scn; |
| 69 | oftree tree; |
| 70 | ofnode node; |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 71 | char *str; |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 72 | void *fdt; |
| 73 | int i; |
| 74 | |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 75 | ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0)); |
| 76 | |
| 77 | ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, &vid_priv, &scn)); |
| 78 | |
Simon Glass | b1cd32b | 2023-08-14 16:40:34 -0600 | [diff] [blame] | 79 | /* get a menu to fiddle with */ |
| 80 | menu = scene_obj_find(scn, ID_CPU_SPEED, SCENEOBJT_MENU); |
| 81 | ut_assertnonnull(menu); |
| 82 | menu->cur_item_id = ID_CPU_SPEED_2; |
| 83 | |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 84 | /* get a textline to fiddle with too */ |
| 85 | tline = scene_obj_find(scn, ID_MACHINE_NAME, SCENEOBJT_TEXTLINE); |
| 86 | ut_assertnonnull(tline); |
| 87 | str = abuf_data(&tline->buf); |
| 88 | strcpy(str, "my-machine"); |
| 89 | |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 90 | ut_assertok(run_command("cedit write_fdt hostfs - settings.dtb", 0)); |
| 91 | ut_assertok(run_commandf("load hostfs - %lx settings.dtb", addr)); |
| 92 | ut_assert_nextlinen("1024 bytes read"); |
| 93 | |
| 94 | fdt = map_sysmem(addr, 1024); |
| 95 | tree = oftree_from_fdt(fdt); |
| 96 | node = ofnode_find_subnode(oftree_root(tree), CEDIT_NODE_NAME); |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 97 | ut_assert(ofnode_valid(node)); |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 98 | |
Simon Glass | b1cd32b | 2023-08-14 16:40:34 -0600 | [diff] [blame] | 99 | ut_asserteq(ID_CPU_SPEED_2, |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 100 | ofnode_read_u32_default(node, "cpu-speed", 0)); |
Simon Glass | 6f3e87a | 2024-10-14 16:32:00 -0600 | [diff] [blame] | 101 | ut_asserteq(3, |
| 102 | ofnode_read_u32_default(node, "cpu-speed-value", 0)); |
Simon Glass | b1cd32b | 2023-08-14 16:40:34 -0600 | [diff] [blame] | 103 | ut_asserteq_str("2.5 GHz", ofnode_read_string(node, "cpu-speed-str")); |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 104 | ut_asserteq_str("my-machine", ofnode_read_string(node, "machine-name")); |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 105 | |
Simon Glass | 6f3e87a | 2024-10-14 16:32:00 -0600 | [diff] [blame] | 106 | /* There should only be 7 properties */ |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 107 | for (i = 0, ofnode_first_property(node, &prop); ofprop_valid(&prop); |
| 108 | i++, ofnode_next_property(&prop)) |
| 109 | ; |
Simon Glass | 6f3e87a | 2024-10-14 16:32:00 -0600 | [diff] [blame] | 110 | ut_asserteq(7, i); |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 111 | |
Simon Glass | b1cd32b | 2023-08-14 16:40:34 -0600 | [diff] [blame] | 112 | ut_assert_console_end(); |
| 113 | |
| 114 | /* reset the expo */ |
| 115 | menu->cur_item_id = ID_CPU_SPEED_1; |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 116 | *str = '\0'; |
Simon Glass | b1cd32b | 2023-08-14 16:40:34 -0600 | [diff] [blame] | 117 | |
| 118 | /* load in the settings and make sure they update */ |
| 119 | ut_assertok(run_command("cedit read_fdt hostfs - settings.dtb", 0)); |
| 120 | ut_asserteq(ID_CPU_SPEED_2, menu->cur_item_id); |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 121 | ut_asserteq_str("my-machine", ofnode_read_string(node, "machine-name")); |
Simon Glass | b1cd32b | 2023-08-14 16:40:34 -0600 | [diff] [blame] | 122 | |
| 123 | ut_assertnonnull(menu); |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 124 | ut_assert_console_end(); |
| 125 | |
| 126 | return 0; |
| 127 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 128 | BOOTSTD_TEST(cedit_fdt, UTF_CONSOLE); |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 129 | |
Simon Glass | 0f2e5a6 | 2023-08-14 16:40:36 -0600 | [diff] [blame] | 130 | /* Check the cedit write_env and read_env commands */ |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 131 | static int cedit_env(struct unit_test_state *uts) |
| 132 | { |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 133 | struct scene_obj_textline *tline; |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 134 | struct video_priv *vid_priv; |
| 135 | extern struct expo *cur_exp; |
| 136 | struct scene_obj_menu *menu; |
| 137 | struct scene *scn; |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 138 | char *str; |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 139 | |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 140 | ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0)); |
| 141 | |
| 142 | ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, &vid_priv, &scn)); |
| 143 | |
| 144 | /* get a menu to fiddle with */ |
| 145 | menu = scene_obj_find(scn, ID_CPU_SPEED, SCENEOBJT_MENU); |
| 146 | ut_assertnonnull(menu); |
| 147 | menu->cur_item_id = ID_CPU_SPEED_2; |
| 148 | |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 149 | /* get a textline to fiddle with too */ |
| 150 | tline = scene_obj_find(scn, ID_MACHINE_NAME, SCENEOBJT_TEXTLINE); |
| 151 | ut_assertnonnull(tline); |
| 152 | str = abuf_data(&tline->buf); |
| 153 | strcpy(str, "my-machine"); |
| 154 | |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 155 | ut_assertok(run_command("cedit write_env -v", 0)); |
Simon Glass | 53a0a2f | 2024-10-14 16:31:57 -0600 | [diff] [blame] | 156 | ut_assert_nextlinen("c.cpu-speed=11"); |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 157 | ut_assert_nextlinen("c.cpu-speed-str=2.5 GHz"); |
Simon Glass | 6f3e87a | 2024-10-14 16:32:00 -0600 | [diff] [blame] | 158 | ut_assert_nextlinen("c.cpu-speed-value=3"); |
Simon Glass | 53a0a2f | 2024-10-14 16:31:57 -0600 | [diff] [blame] | 159 | ut_assert_nextlinen("c.power-loss=14"); |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 160 | ut_assert_nextlinen("c.power-loss-str=Always Off"); |
Simon Glass | 6f3e87a | 2024-10-14 16:32:00 -0600 | [diff] [blame] | 161 | ut_assert_nextlinen("c.power-loss-value=0"); |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 162 | ut_assert_nextlinen("c.machine-name=my-machine"); |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 163 | ut_assert_console_end(); |
| 164 | |
Simon Glass | 53a0a2f | 2024-10-14 16:31:57 -0600 | [diff] [blame] | 165 | ut_asserteq(11, env_get_ulong("c.cpu-speed", 10, 0)); |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 166 | ut_asserteq_str("2.5 GHz", env_get("c.cpu-speed-str")); |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 167 | ut_asserteq_str("my-machine", env_get("c.machine-name")); |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 168 | |
Simon Glass | 0f2e5a6 | 2023-08-14 16:40:36 -0600 | [diff] [blame] | 169 | /* reset the expo */ |
| 170 | menu->cur_item_id = ID_CPU_SPEED_1; |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 171 | *str = '\0'; |
Simon Glass | 0f2e5a6 | 2023-08-14 16:40:36 -0600 | [diff] [blame] | 172 | |
| 173 | ut_assertok(run_command("cedit read_env -v", 0)); |
Simon Glass | 53a0a2f | 2024-10-14 16:31:57 -0600 | [diff] [blame] | 174 | ut_assert_nextlinen("c.cpu-speed=11"); |
| 175 | ut_assert_nextlinen("c.power-loss=14"); |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 176 | ut_assert_nextlinen("c.machine-name=my-machine"); |
Simon Glass | 0f2e5a6 | 2023-08-14 16:40:36 -0600 | [diff] [blame] | 177 | ut_assert_console_end(); |
| 178 | |
| 179 | ut_asserteq(ID_CPU_SPEED_2, menu->cur_item_id); |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 180 | ut_asserteq_str("my-machine", env_get("c.machine-name")); |
Simon Glass | 0f2e5a6 | 2023-08-14 16:40:36 -0600 | [diff] [blame] | 181 | |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 182 | return 0; |
| 183 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 184 | BOOTSTD_TEST(cedit_env, UTF_CONSOLE); |
Simon Glass | 2b91ca6 | 2023-08-14 16:40:37 -0600 | [diff] [blame] | 185 | |
| 186 | /* Check the cedit write_cmos and read_cmos commands */ |
| 187 | static int cedit_cmos(struct unit_test_state *uts) |
| 188 | { |
| 189 | struct scene_obj_menu *menu, *menu2; |
| 190 | struct video_priv *vid_priv; |
| 191 | extern struct expo *cur_exp; |
| 192 | struct scene *scn; |
| 193 | |
Simon Glass | 2b91ca6 | 2023-08-14 16:40:37 -0600 | [diff] [blame] | 194 | ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0)); |
| 195 | |
| 196 | ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, &vid_priv, &scn)); |
| 197 | |
| 198 | /* get the menus to fiddle with */ |
| 199 | menu = scene_obj_find(scn, ID_CPU_SPEED, SCENEOBJT_MENU); |
| 200 | ut_assertnonnull(menu); |
| 201 | menu->cur_item_id = ID_CPU_SPEED_2; |
| 202 | |
| 203 | menu2 = scene_obj_find(scn, ID_POWER_LOSS, SCENEOBJT_MENU); |
| 204 | ut_assertnonnull(menu2); |
| 205 | menu2->cur_item_id = ID_AC_MEMORY; |
| 206 | |
| 207 | ut_assertok(run_command("cedit write_cmos -v", 0)); |
| 208 | ut_assert_nextlinen("Write 2 bytes from offset 80 to 84"); |
| 209 | ut_assert_console_end(); |
| 210 | |
Simon Glass | 4462fa3 | 2023-08-14 16:40:38 -0600 | [diff] [blame] | 211 | /* reset the expo */ |
| 212 | menu->cur_item_id = ID_CPU_SPEED_1; |
| 213 | menu2->cur_item_id = ID_AC_OFF; |
| 214 | |
| 215 | ut_assertok(run_command("cedit read_cmos -v", 0)); |
| 216 | ut_assert_nextlinen("Read 2 bytes from offset 80 to 84"); |
| 217 | ut_assert_console_end(); |
| 218 | |
| 219 | ut_asserteq(ID_CPU_SPEED_2, menu->cur_item_id); |
| 220 | ut_asserteq(ID_AC_MEMORY, menu2->cur_item_id); |
| 221 | |
Simon Glass | 2b91ca6 | 2023-08-14 16:40:37 -0600 | [diff] [blame] | 222 | return 0; |
| 223 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 224 | BOOTSTD_TEST(cedit_cmos, UTF_CONSOLE); |
Simon Glass | ee44064 | 2025-05-02 08:46:19 -0600 | [diff] [blame^] | 225 | |
| 226 | /* Check the cedit displays correctely */ |
| 227 | static int cedit_render(struct unit_test_state *uts) |
| 228 | { |
| 229 | struct video_priv *vid_priv; |
| 230 | extern struct expo *cur_exp; |
| 231 | struct udevice *dev; |
| 232 | struct scene *scn; |
| 233 | struct expo *exp; |
| 234 | |
| 235 | ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0)); |
| 236 | |
| 237 | exp = cur_exp; |
| 238 | ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev)); |
| 239 | ut_asserteq(ID_SCENE1, cedit_prepare(exp, &vid_priv, &scn)); |
| 240 | ut_assertok(expo_render(exp)); |
| 241 | ut_asserteq(4929, video_compress_fb(uts, dev, false)); |
| 242 | ut_assertok(video_check_copy_fb(uts, dev)); |
| 243 | expo_destroy(exp); |
| 244 | cur_exp = NULL; |
| 245 | |
| 246 | return 0; |
| 247 | } |
| 248 | BOOTSTD_TEST(cedit_render, UTF_DM | UTF_SCAN_FDT); |