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 | |
| 7 | #include <common.h> |
| 8 | #include <cedit.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> |
| 14 | #include "bootstd_common.h" |
| 15 | #include <test/cedit-test.h> |
| 16 | #include "../../boot/scene_internal.h" |
| 17 | |
| 18 | /* Check the cedit command */ |
| 19 | static 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 | } |
| 56 | BOOTSTD_TEST(cedit_base, 0); |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 57 | |
Simon Glass | b1cd32b | 2023-08-14 16:40:34 -0600 | [diff] [blame] | 58 | /* Check the cedit write_fdt and read_fdt commands */ |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 59 | static int cedit_fdt(struct unit_test_state *uts) |
| 60 | { |
| 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; |
| 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 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 | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 82 | 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 Glass | b1cd32b | 2023-08-14 16:40:34 -0600 | [diff] [blame] | 90 | ut_asserteq(ID_CPU_SPEED_2, |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 91 | ofnode_read_u32_default(node, "cpu-speed", 0)); |
Simon Glass | b1cd32b | 2023-08-14 16:40:34 -0600 | [diff] [blame] | 92 | ut_asserteq_str("2.5 GHz", ofnode_read_string(node, "cpu-speed-str")); |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 93 | 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 | |
Simon Glass | b1cd32b | 2023-08-14 16:40:34 -0600 | [diff] [blame] | 101 | ut_assert_console_end(); |
| 102 | |
| 103 | /* 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); |
Simon Glass | 28bf435 | 2023-08-14 16:40:33 -0600 | [diff] [blame] | 111 | ut_assert_console_end(); |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | BOOTSTD_TEST(cedit_fdt, 0); |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 116 | |
Simon Glass | 0f2e5a6 | 2023-08-14 16:40:36 -0600 | [diff] [blame] | 117 | /* Check the cedit write_env and read_env commands */ |
Simon Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 118 | static 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 Glass | 0f2e5a6 | 2023-08-14 16:40:36 -0600 | [diff] [blame] | 145 | /* 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 Glass | 237f375 | 2023-08-14 16:40:35 -0600 | [diff] [blame] | 155 | return 0; |
| 156 | } |
| 157 | BOOTSTD_TEST(cedit_env, 0); |
Simon Glass | 2b91ca6 | 2023-08-14 16:40:37 -0600 | [diff] [blame^] | 158 | |
| 159 | /* Check the cedit write_cmos and read_cmos commands */ |
| 160 | static 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 | |
| 185 | return 0; |
| 186 | } |
| 187 | BOOTSTD_TEST(cedit_cmos, 0); |