blob: 659c47ed35fbd6eed45b5d22428048b6136b12af [file] [log] [blame]
Simon Glass44e4ec72023-08-14 16:40:26 -06001// 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>
9#include <expo.h>
Simon Glass28bf4352023-08-14 16:40:33 -060010#include <mapmem.h>
11#include <dm/ofnode.h>
Simon Glass44e4ec72023-08-14 16:40:26 -060012#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 */
18static 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
28 console_record_reset_enable();
29
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
36 */
37 console_in_puts("\x0e\x0d\x0e\x0d\e");
38 ut_assertok(run_command("cedit run", 0));
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}
55BOOTSTD_TEST(cedit_base, 0);
Simon Glass28bf4352023-08-14 16:40:33 -060056
Simon Glassb1cd32b2023-08-14 16:40:34 -060057/* Check the cedit write_fdt and read_fdt commands */
Simon Glass28bf4352023-08-14 16:40:33 -060058static int cedit_fdt(struct unit_test_state *uts)
59{
60 struct video_priv *vid_priv;
61 extern struct expo *cur_exp;
Simon Glassb1cd32b2023-08-14 16:40:34 -060062 struct scene_obj_menu *menu;
Simon Glass28bf4352023-08-14 16:40:33 -060063 ulong addr = 0x1000;
64 struct ofprop prop;
65 struct scene *scn;
66 oftree tree;
67 ofnode node;
68 void *fdt;
69 int i;
70
71 console_record_reset_enable();
72 ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0));
73
74 ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, &vid_priv, &scn));
75
Simon Glassb1cd32b2023-08-14 16:40:34 -060076 /* get a menu to fiddle with */
77 menu = scene_obj_find(scn, ID_CPU_SPEED, SCENEOBJT_MENU);
78 ut_assertnonnull(menu);
79 menu->cur_item_id = ID_CPU_SPEED_2;
80
Simon Glass28bf4352023-08-14 16:40:33 -060081 ut_assertok(run_command("cedit write_fdt hostfs - settings.dtb", 0));
82 ut_assertok(run_commandf("load hostfs - %lx settings.dtb", addr));
83 ut_assert_nextlinen("1024 bytes read");
84
85 fdt = map_sysmem(addr, 1024);
86 tree = oftree_from_fdt(fdt);
87 node = ofnode_find_subnode(oftree_root(tree), CEDIT_NODE_NAME);
88
Simon Glassb1cd32b2023-08-14 16:40:34 -060089 ut_asserteq(ID_CPU_SPEED_2,
Simon Glass28bf4352023-08-14 16:40:33 -060090 ofnode_read_u32_default(node, "cpu-speed", 0));
Simon Glassb1cd32b2023-08-14 16:40:34 -060091 ut_asserteq_str("2.5 GHz", ofnode_read_string(node, "cpu-speed-str"));
Simon Glass28bf4352023-08-14 16:40:33 -060092 ut_assert(ofnode_valid(node));
93
94 /* There should only be 4 properties */
95 for (i = 0, ofnode_first_property(node, &prop); ofprop_valid(&prop);
96 i++, ofnode_next_property(&prop))
97 ;
98 ut_asserteq(4, i);
99
Simon Glassb1cd32b2023-08-14 16:40:34 -0600100 ut_assert_console_end();
101
102 /* reset the expo */
103 menu->cur_item_id = ID_CPU_SPEED_1;
104
105 /* load in the settings and make sure they update */
106 ut_assertok(run_command("cedit read_fdt hostfs - settings.dtb", 0));
107 ut_asserteq(ID_CPU_SPEED_2, menu->cur_item_id);
108
109 ut_assertnonnull(menu);
Simon Glass28bf4352023-08-14 16:40:33 -0600110 ut_assert_console_end();
111
112 return 0;
113}
114BOOTSTD_TEST(cedit_fdt, 0);