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 | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 8 | #include <env.h> |
Simon Glass | 44e4ec7 | 2023-08-14 16:40:26 -0600 | [diff] [blame] | 9 | #include <expo.h> |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 10 | #include <mapmem.h> |
| 11 | #include <dm/ofnode.h> |
Simon Glass | 44e4ec7 | 2023-08-14 16:40:26 -0600 | [diff] [blame] | 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 | |
Simon Glass | 44e4ec7 | 2023-08-14 16:40:26 -0600 | [diff] [blame] | 28 | /* |
| 29 | * ^N Move down to second menu |
| 30 | * ^M Open menu |
| 31 | * ^N Move down to second item |
| 32 | * ^M Select item |
| 33 | * \e Quit |
Simon Glass | 53a0a2f | 2024-10-14 16:31:57 -0600 | [diff] [blame] | 34 | * |
| 35 | * cedit_run() returns -EACCESS so this command returns CMD_RET_FAILURE |
Simon Glass | 44e4ec7 | 2023-08-14 16:40:26 -0600 | [diff] [blame] | 36 | */ |
| 37 | console_in_puts("\x0e\x0d\x0e\x0d\e"); |
Simon Glass | 53a0a2f | 2024-10-14 16:31:57 -0600 | [diff] [blame] | 38 | ut_asserteq(1, run_command("cedit run", 0)); |
Simon Glass | 44e4ec7 | 2023-08-14 16:40:26 -0600 | [diff] [blame] | 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 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 55 | BOOTSTD_TEST(cedit_base, UTF_CONSOLE); |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 56 | |
Simon Glass | b1cd32b | 2023-08-14 16:40:34 -0600 | [diff] [blame] | 57 | /* Check the cedit write_fdt and read_fdt commands */ |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 58 | static int cedit_fdt(struct unit_test_state *uts) |
| 59 | { |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 60 | struct scene_obj_textline *tline; |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 61 | struct video_priv *vid_priv; |
| 62 | extern struct expo *cur_exp; |
Simon Glass | b1cd32b | 2023-08-14 16:40:34 -0600 | [diff] [blame] | 63 | struct scene_obj_menu *menu; |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 64 | ulong addr = 0x1000; |
| 65 | struct ofprop prop; |
| 66 | struct scene *scn; |
| 67 | oftree tree; |
| 68 | ofnode node; |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 69 | char *str; |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 70 | void *fdt; |
| 71 | int i; |
| 72 | |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 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 Glass | b1cd32b | 2023-08-14 16:40:34 -0600 | [diff] [blame] | 77 | /* 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 Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 82 | /* get a textline to fiddle with too */ |
| 83 | tline = scene_obj_find(scn, ID_MACHINE_NAME, SCENEOBJT_TEXTLINE); |
| 84 | ut_assertnonnull(tline); |
| 85 | str = abuf_data(&tline->buf); |
| 86 | strcpy(str, "my-machine"); |
| 87 | |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 88 | ut_assertok(run_command("cedit write_fdt hostfs - settings.dtb", 0)); |
| 89 | ut_assertok(run_commandf("load hostfs - %lx settings.dtb", addr)); |
| 90 | ut_assert_nextlinen("1024 bytes read"); |
| 91 | |
| 92 | fdt = map_sysmem(addr, 1024); |
| 93 | tree = oftree_from_fdt(fdt); |
| 94 | node = ofnode_find_subnode(oftree_root(tree), CEDIT_NODE_NAME); |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 95 | ut_assert(ofnode_valid(node)); |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 96 | |
Simon Glass | b1cd32b | 2023-08-14 16:40:34 -0600 | [diff] [blame] | 97 | ut_asserteq(ID_CPU_SPEED_2, |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 98 | ofnode_read_u32_default(node, "cpu-speed", 0)); |
Simon Glass | 6f3e87a | 2024-10-14 16:32:00 -0600 | [diff] [blame] | 99 | ut_asserteq(3, |
| 100 | ofnode_read_u32_default(node, "cpu-speed-value", 0)); |
Simon Glass | b1cd32b | 2023-08-14 16:40:34 -0600 | [diff] [blame] | 101 | 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] | 102 | ut_asserteq_str("my-machine", ofnode_read_string(node, "machine-name")); |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 103 | |
Simon Glass | 6f3e87a | 2024-10-14 16:32:00 -0600 | [diff] [blame] | 104 | /* There should only be 7 properties */ |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 105 | for (i = 0, ofnode_first_property(node, &prop); ofprop_valid(&prop); |
| 106 | i++, ofnode_next_property(&prop)) |
| 107 | ; |
Simon Glass | 6f3e87a | 2024-10-14 16:32:00 -0600 | [diff] [blame] | 108 | ut_asserteq(7, i); |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 109 | |
Simon Glass | b1cd32b | 2023-08-14 16:40:34 -0600 | [diff] [blame] | 110 | ut_assert_console_end(); |
| 111 | |
| 112 | /* reset the expo */ |
| 113 | menu->cur_item_id = ID_CPU_SPEED_1; |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 114 | *str = '\0'; |
Simon Glass | b1cd32b | 2023-08-14 16:40:34 -0600 | [diff] [blame] | 115 | |
| 116 | /* load in the settings and make sure they update */ |
| 117 | ut_assertok(run_command("cedit read_fdt hostfs - settings.dtb", 0)); |
| 118 | ut_asserteq(ID_CPU_SPEED_2, menu->cur_item_id); |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 119 | ut_asserteq_str("my-machine", ofnode_read_string(node, "machine-name")); |
Simon Glass | b1cd32b | 2023-08-14 16:40:34 -0600 | [diff] [blame] | 120 | |
| 121 | ut_assertnonnull(menu); |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 122 | ut_assert_console_end(); |
| 123 | |
| 124 | return 0; |
| 125 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 126 | BOOTSTD_TEST(cedit_fdt, UTF_CONSOLE); |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 127 | |
Simon Glass | 0f2e5a6 | 2023-08-14 16:40:36 -0600 | [diff] [blame] | 128 | /* Check the cedit write_env and read_env commands */ |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 129 | static int cedit_env(struct unit_test_state *uts) |
| 130 | { |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 131 | struct scene_obj_textline *tline; |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 132 | struct video_priv *vid_priv; |
| 133 | extern struct expo *cur_exp; |
| 134 | struct scene_obj_menu *menu; |
| 135 | struct scene *scn; |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 136 | char *str; |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 137 | |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 138 | ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0)); |
| 139 | |
| 140 | ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, &vid_priv, &scn)); |
| 141 | |
| 142 | /* get a menu to fiddle with */ |
| 143 | menu = scene_obj_find(scn, ID_CPU_SPEED, SCENEOBJT_MENU); |
| 144 | ut_assertnonnull(menu); |
| 145 | menu->cur_item_id = ID_CPU_SPEED_2; |
| 146 | |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 147 | /* get a textline to fiddle with too */ |
| 148 | tline = scene_obj_find(scn, ID_MACHINE_NAME, SCENEOBJT_TEXTLINE); |
| 149 | ut_assertnonnull(tline); |
| 150 | str = abuf_data(&tline->buf); |
| 151 | strcpy(str, "my-machine"); |
| 152 | |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 153 | ut_assertok(run_command("cedit write_env -v", 0)); |
Simon Glass | 53a0a2f | 2024-10-14 16:31:57 -0600 | [diff] [blame] | 154 | ut_assert_nextlinen("c.cpu-speed=11"); |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 155 | ut_assert_nextlinen("c.cpu-speed-str=2.5 GHz"); |
Simon Glass | 6f3e87a | 2024-10-14 16:32:00 -0600 | [diff] [blame] | 156 | ut_assert_nextlinen("c.cpu-speed-value=3"); |
Simon Glass | 53a0a2f | 2024-10-14 16:31:57 -0600 | [diff] [blame] | 157 | ut_assert_nextlinen("c.power-loss=14"); |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 158 | ut_assert_nextlinen("c.power-loss-str=Always Off"); |
Simon Glass | 6f3e87a | 2024-10-14 16:32:00 -0600 | [diff] [blame] | 159 | ut_assert_nextlinen("c.power-loss-value=0"); |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 160 | ut_assert_nextlinen("c.machine-name=my-machine"); |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 161 | ut_assert_console_end(); |
| 162 | |
Simon Glass | 53a0a2f | 2024-10-14 16:31:57 -0600 | [diff] [blame] | 163 | ut_asserteq(11, env_get_ulong("c.cpu-speed", 10, 0)); |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 164 | ut_asserteq_str("2.5 GHz", env_get("c.cpu-speed-str")); |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 165 | ut_asserteq_str("my-machine", env_get("c.machine-name")); |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 166 | |
Simon Glass | 0f2e5a6 | 2023-08-14 16:40:36 -0600 | [diff] [blame] | 167 | /* reset the expo */ |
| 168 | menu->cur_item_id = ID_CPU_SPEED_1; |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 169 | *str = '\0'; |
Simon Glass | 0f2e5a6 | 2023-08-14 16:40:36 -0600 | [diff] [blame] | 170 | |
| 171 | ut_assertok(run_command("cedit read_env -v", 0)); |
Simon Glass | 53a0a2f | 2024-10-14 16:31:57 -0600 | [diff] [blame] | 172 | ut_assert_nextlinen("c.cpu-speed=11"); |
| 173 | ut_assert_nextlinen("c.power-loss=14"); |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 174 | ut_assert_nextlinen("c.machine-name=my-machine"); |
Simon Glass | 0f2e5a6 | 2023-08-14 16:40:36 -0600 | [diff] [blame] | 175 | ut_assert_console_end(); |
| 176 | |
| 177 | ut_asserteq(ID_CPU_SPEED_2, menu->cur_item_id); |
Simon Glass | 70c579b | 2023-10-01 19:13:39 -0600 | [diff] [blame] | 178 | ut_asserteq_str("my-machine", env_get("c.machine-name")); |
Simon Glass | 0f2e5a6 | 2023-08-14 16:40:36 -0600 | [diff] [blame] | 179 | |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 180 | return 0; |
| 181 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 182 | BOOTSTD_TEST(cedit_env, UTF_CONSOLE); |
Simon Glass | 2b91ca6 | 2023-08-14 16:40:37 -0600 | [diff] [blame] | 183 | |
| 184 | /* Check the cedit write_cmos and read_cmos commands */ |
| 185 | static int cedit_cmos(struct unit_test_state *uts) |
| 186 | { |
| 187 | struct scene_obj_menu *menu, *menu2; |
| 188 | struct video_priv *vid_priv; |
| 189 | extern struct expo *cur_exp; |
| 190 | struct scene *scn; |
| 191 | |
Simon Glass | 2b91ca6 | 2023-08-14 16:40:37 -0600 | [diff] [blame] | 192 | ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0)); |
| 193 | |
| 194 | ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, &vid_priv, &scn)); |
| 195 | |
| 196 | /* get the menus to fiddle with */ |
| 197 | menu = scene_obj_find(scn, ID_CPU_SPEED, SCENEOBJT_MENU); |
| 198 | ut_assertnonnull(menu); |
| 199 | menu->cur_item_id = ID_CPU_SPEED_2; |
| 200 | |
| 201 | menu2 = scene_obj_find(scn, ID_POWER_LOSS, SCENEOBJT_MENU); |
| 202 | ut_assertnonnull(menu2); |
| 203 | menu2->cur_item_id = ID_AC_MEMORY; |
| 204 | |
| 205 | ut_assertok(run_command("cedit write_cmos -v", 0)); |
| 206 | ut_assert_nextlinen("Write 2 bytes from offset 80 to 84"); |
| 207 | ut_assert_console_end(); |
| 208 | |
Simon Glass | 4462fa3 | 2023-08-14 16:40:38 -0600 | [diff] [blame] | 209 | /* reset the expo */ |
| 210 | menu->cur_item_id = ID_CPU_SPEED_1; |
| 211 | menu2->cur_item_id = ID_AC_OFF; |
| 212 | |
| 213 | ut_assertok(run_command("cedit read_cmos -v", 0)); |
| 214 | ut_assert_nextlinen("Read 2 bytes from offset 80 to 84"); |
| 215 | ut_assert_console_end(); |
| 216 | |
| 217 | ut_asserteq(ID_CPU_SPEED_2, menu->cur_item_id); |
| 218 | ut_asserteq(ID_AC_MEMORY, menu2->cur_item_id); |
| 219 | |
Simon Glass | 2b91ca6 | 2023-08-14 16:40:37 -0600 | [diff] [blame] | 220 | return 0; |
| 221 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 222 | BOOTSTD_TEST(cedit_cmos, UTF_CONSOLE); |