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