summaryrefslogtreecommitdiff
path: root/test/boot/cedit.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2023-10-12 08:15:31 -0400
committerTom Rini <trini@konsulko.com>2023-10-12 08:15:31 -0400
commitf9a47ac8d97da2b3aaf463f268a9a872a8d921df (patch)
tree0a67c8aa5bd018d376f8073147cea33c6772861b /test/boot/cedit.c
parent429d59c3e5e6a3d3d6cd9f3c59c075e9037459c0 (diff)
parent7e5b637483e03ce303ce84ec6b24156c6658ef46 (diff)
Merge branch '2023-10-12-expo-add-support-for-edting-lines-of-text'
To quote the author: So far expo only supports menus. These are quite flexible for various kinds of settings, but cannot deal with free-form input, such as a serial number or a machine name. This series adds support for a textline object, which is a single line of text. It has a maximum length and its value is stored within the expo structure. U-Boot already has a command-line editor which provides most of the features needed by expo. But the code runs in its own loop and only returns when the line is finished. This is not suitable for expo, which must handle a keypress at a time, returning to its caller after each one. In order to use the CLI code, some significant refactoring is included here. This mostly involves moving the internal loop of the CLI to a separate function and recording its state in a struct, just as was done for single keypresses some time back. A minor addition is support for Ctrl-W to delete a word, since strangely this is currently only present in the simple version. The video-console system provides most of the features needed by testline, but a few things are missing. This series provides: - primitive cursor support so the user can see where he is typing - saving and restoring of the text-entry context, so that expo can allow the user to continue where he left off, including deleting previously entered characters correctly (for Truetype) - obtaining the nominal width of a string of n characters, so that a suitable width can be chosen for the textline object Note that no support is provided for clearing the cursor. This was addressed in a previous series[1] which could perhaps be rebased. For this implementation, the cursor is therefore not enabled for the normal command line, only for expo. Reading and writing textline objects is supported for FDT and environment, but not for CMOS RAM, since it would likely use too much RAM to store a string. In terms of code size, the overall size increase is 180 bytes for Thumb02 boards, 160 of whcih is the addition of Ctrl-W to delete a word. [1] https://patchwork.ozlabs.org/project/uboot/list/?series=280178&state=*
Diffstat (limited to 'test/boot/cedit.c')
-rw-r--r--test/boot/cedit.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/test/boot/cedit.c b/test/boot/cedit.c
index ab2b8a1f9ff..aa417190486 100644
--- a/test/boot/cedit.c
+++ b/test/boot/cedit.c
@@ -58,6 +58,7 @@ BOOTSTD_TEST(cedit_base, 0);
/* Check the cedit write_fdt and read_fdt commands */
static int cedit_fdt(struct unit_test_state *uts)
{
+ struct scene_obj_textline *tline;
struct video_priv *vid_priv;
extern struct expo *cur_exp;
struct scene_obj_menu *menu;
@@ -66,6 +67,7 @@ static int cedit_fdt(struct unit_test_state *uts)
struct scene *scn;
oftree tree;
ofnode node;
+ char *str;
void *fdt;
int i;
@@ -79,6 +81,12 @@ static int cedit_fdt(struct unit_test_state *uts)
ut_assertnonnull(menu);
menu->cur_item_id = ID_CPU_SPEED_2;
+ /* get a textline to fiddle with too */
+ tline = scene_obj_find(scn, ID_MACHINE_NAME, SCENEOBJT_TEXTLINE);
+ ut_assertnonnull(tline);
+ str = abuf_data(&tline->buf);
+ strcpy(str, "my-machine");
+
ut_assertok(run_command("cedit write_fdt hostfs - settings.dtb", 0));
ut_assertok(run_commandf("load hostfs - %lx settings.dtb", addr));
ut_assert_nextlinen("1024 bytes read");
@@ -86,26 +94,29 @@ static int cedit_fdt(struct unit_test_state *uts)
fdt = map_sysmem(addr, 1024);
tree = oftree_from_fdt(fdt);
node = ofnode_find_subnode(oftree_root(tree), CEDIT_NODE_NAME);
+ ut_assert(ofnode_valid(node));
ut_asserteq(ID_CPU_SPEED_2,
ofnode_read_u32_default(node, "cpu-speed", 0));
ut_asserteq_str("2.5 GHz", ofnode_read_string(node, "cpu-speed-str"));
- ut_assert(ofnode_valid(node));
+ ut_asserteq_str("my-machine", ofnode_read_string(node, "machine-name"));
- /* There should only be 4 properties */
+ /* There should only be 5 properties */
for (i = 0, ofnode_first_property(node, &prop); ofprop_valid(&prop);
i++, ofnode_next_property(&prop))
;
- ut_asserteq(4, i);
+ ut_asserteq(5, i);
ut_assert_console_end();
/* reset the expo */
menu->cur_item_id = ID_CPU_SPEED_1;
+ *str = '\0';
/* load in the settings and make sure they update */
ut_assertok(run_command("cedit read_fdt hostfs - settings.dtb", 0));
ut_asserteq(ID_CPU_SPEED_2, menu->cur_item_id);
+ ut_asserteq_str("my-machine", ofnode_read_string(node, "machine-name"));
ut_assertnonnull(menu);
ut_assert_console_end();
@@ -117,10 +128,12 @@ BOOTSTD_TEST(cedit_fdt, 0);
/* Check the cedit write_env and read_env commands */
static int cedit_env(struct unit_test_state *uts)
{
+ struct scene_obj_textline *tline;
struct video_priv *vid_priv;
extern struct expo *cur_exp;
struct scene_obj_menu *menu;
struct scene *scn;
+ char *str;
console_record_reset_enable();
ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0));
@@ -132,25 +145,36 @@ static int cedit_env(struct unit_test_state *uts)
ut_assertnonnull(menu);
menu->cur_item_id = ID_CPU_SPEED_2;
+ /* get a textline to fiddle with too */
+ tline = scene_obj_find(scn, ID_MACHINE_NAME, SCENEOBJT_TEXTLINE);
+ ut_assertnonnull(tline);
+ str = abuf_data(&tline->buf);
+ strcpy(str, "my-machine");
+
ut_assertok(run_command("cedit write_env -v", 0));
ut_assert_nextlinen("c.cpu-speed=7");
ut_assert_nextlinen("c.cpu-speed-str=2.5 GHz");
ut_assert_nextlinen("c.power-loss=10");
ut_assert_nextlinen("c.power-loss-str=Always Off");
+ ut_assert_nextlinen("c.machine-name=my-machine");
ut_assert_console_end();
ut_asserteq(7, env_get_ulong("c.cpu-speed", 10, 0));
ut_asserteq_str("2.5 GHz", env_get("c.cpu-speed-str"));
+ ut_asserteq_str("my-machine", env_get("c.machine-name"));
/* reset the expo */
menu->cur_item_id = ID_CPU_SPEED_1;
+ *str = '\0';
ut_assertok(run_command("cedit read_env -v", 0));
ut_assert_nextlinen("c.cpu-speed=7");
ut_assert_nextlinen("c.power-loss=10");
+ ut_assert_nextlinen("c.machine-name=my-machine");
ut_assert_console_end();
ut_asserteq(ID_CPU_SPEED_2, menu->cur_item_id);
+ ut_asserteq_str("my-machine", env_get("c.machine-name"));
return 0;
}