]> Git Repo - J-u-boot.git/blob - test/boot/bootflow.c
bootstd: Switch bootdev scanning to use labels
[J-u-boot.git] / test / boot / bootflow.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Test for bootdev functions. All start with 'bootdev'
4  *
5  * Copyright 2021 Google LLC
6  * Written by Simon Glass <[email protected]>
7  */
8
9 #include <common.h>
10 #include <bootdev.h>
11 #include <bootflow.h>
12 #include <bootmeth.h>
13 #include <bootstd.h>
14 #include <cli.h>
15 #include <dm.h>
16 #include <expo.h>
17 #ifdef CONFIG_SANDBOX
18 #include <asm/test.h>
19 #endif
20 #include <dm/device-internal.h>
21 #include <dm/lists.h>
22 #include <test/suites.h>
23 #include <test/ut.h>
24 #include "bootstd_common.h"
25 #include "../../boot/bootflow_internal.h"
26 #include "../../boot/scene_internal.h"
27
28 DECLARE_GLOBAL_DATA_PTR;
29
30 extern U_BOOT_DRIVER(bootmeth_script);
31
32 static int inject_response(struct unit_test_state *uts)
33 {
34         /*
35          * The image being booted presents a menu of options:
36          *
37          * Fedora-Workstation-armhfp-31-1.9 Boot Options.
38          * 1:   Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)
39          * Enter choice:
40          *
41          * Provide input for this, to avoid waiting two seconds for a timeout.
42          */
43         ut_asserteq(2, console_in_puts("1\n"));
44
45         return 0;
46 }
47
48 /* Check 'bootflow scan/list' commands */
49 static int bootflow_cmd(struct unit_test_state *uts)
50 {
51         console_record_reset_enable();
52         ut_assertok(run_command("bootdev select 1", 0));
53         ut_assert_console_end();
54         ut_assertok(run_command("bootflow scan -lH", 0));
55         ut_assert_nextline("Scanning for bootflows in bootdev 'mmc1.bootdev'");
56         ut_assert_nextline("Seq  Method       State   Uclass    Part  Name                      Filename");
57         ut_assert_nextlinen("---");
58         ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':");
59         ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':");
60         ut_assert_nextline("  0  syslinux     ready   mmc          1  mmc1.bootdev.part_1       /extlinux/extlinux.conf");
61         ut_assert_nextline("No more bootdevs");
62         ut_assert_nextlinen("---");
63         ut_assert_nextline("(1 bootflow, 1 valid)");
64         ut_assert_console_end();
65
66         ut_assertok(run_command("bootflow list", 0));
67         ut_assert_nextline("Showing bootflows for bootdev 'mmc1.bootdev'");
68         ut_assert_nextline("Seq  Method       State   Uclass    Part  Name                      Filename");
69         ut_assert_nextlinen("---");
70         ut_assert_nextline("  0  syslinux     ready   mmc          1  mmc1.bootdev.part_1       /extlinux/extlinux.conf");
71         ut_assert_nextlinen("---");
72         ut_assert_nextline("(1 bootflow, 1 valid)");
73         ut_assert_console_end();
74
75         return 0;
76 }
77 BOOTSTD_TEST(bootflow_cmd, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
78
79 #if 0 /* disable for now */
80 /* Check 'bootflow scan' with a label / seq */
81 static int bootflow_cmd_label(struct unit_test_state *uts)
82 {
83         test_set_eth_enable(false);
84
85         console_record_reset_enable();
86         ut_assertok(run_command("bootflow scan -lH mmc1", 0));
87         ut_assert_nextline("Scanning for bootflows with label 'mmc1'");
88         ut_assert_skip_to_line("(1 bootflow, 1 valid)");
89         ut_assert_console_end();
90
91         ut_assertok(run_command("bootflow scan -lH 0", 0));
92         ut_assert_nextline("Scanning for bootflows with label '0'");
93         ut_assert_skip_to_line("(0 bootflows, 0 valid)");
94         ut_assert_console_end();
95
96         /*
97          * with ethernet enabled we have 8 devices ahead of the mmc ones:
98          *
99          * ut_assertok(run_command("bootdev list", 0));
100          * Seq  Probed  Status  Uclass    Name
101          * ---  ------  ------  --------  ------------------
102          * 0   [ + ]      OK  ethernet  [email protected]
103          * 1   [   ]      OK  ethernet  [email protected]
104          * 2   [   ]      OK  ethernet  sbe5.bootdev
105          * 3   [   ]      OK  ethernet  [email protected]
106          * 4   [   ]      OK  ethernet  phy-test-eth.bootdev
107          * 5   [   ]      OK  ethernet  dsa-test-eth.bootdev
108          * 6   [   ]      OK  ethernet  [email protected]
109          * 7   [   ]      OK  ethernet  [email protected]
110          * 8   [   ]      OK  mmc       mmc2.bootdev
111          * 9   [ + ]      OK  mmc       mmc1.bootdev
112          * a   [   ]      OK  mmc       mmc0.bootdev
113          */
114         ut_assertok(run_command("bootflow scan -lH 9", 0));
115         ut_assert_nextline("Scanning for bootflows with label '9'");
116         ut_assert_skip_to_line("(1 bootflow, 1 valid)");
117
118         ut_assertok(run_command("bootflow scan -lH 0", 0));
119         ut_assert_nextline("Scanning for bootflows with label '0'");
120         ut_assert_skip_to_line("(0 bootflows, 0 valid)");
121         ut_assert_console_end();
122
123         return 0;
124 }
125 BOOTSTD_TEST(bootflow_cmd_label, UT_TESTF_DM | UT_TESTF_SCAN_FDT |
126              UT_TESTF_ETH_BOOTDEV);
127 #endif
128
129 /* Check 'bootflow scan/list' commands using all bootdevs */
130 static int bootflow_cmd_glob(struct unit_test_state *uts)
131 {
132         ut_assertok(bootstd_test_drop_bootdev_order(uts));
133
134         console_record_reset_enable();
135         ut_assertok(run_command("bootflow scan -lGH", 0));
136         ut_assert_nextline("Scanning for bootflows in all bootdevs");
137         ut_assert_nextline("Seq  Method       State   Uclass    Part  Name                      Filename");
138         ut_assert_nextlinen("---");
139         ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':");
140         ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':");
141         ut_assert_nextline("  0  syslinux     ready   mmc          1  mmc1.bootdev.part_1       /extlinux/extlinux.conf");
142         ut_assert_nextline("Scanning bootdev 'mmc0.bootdev':");
143         ut_assert_nextline("No more bootdevs");
144         ut_assert_nextlinen("---");
145         ut_assert_nextline("(1 bootflow, 1 valid)");
146         ut_assert_console_end();
147
148         ut_assertok(run_command("bootflow list", 0));
149         ut_assert_nextline("Showing all bootflows");
150         ut_assert_nextline("Seq  Method       State   Uclass    Part  Name                      Filename");
151         ut_assert_nextlinen("---");
152         ut_assert_nextline("  0  syslinux     ready   mmc          1  mmc1.bootdev.part_1       /extlinux/extlinux.conf");
153         ut_assert_nextlinen("---");
154         ut_assert_nextline("(1 bootflow, 1 valid)");
155         ut_assert_console_end();
156
157         return 0;
158 }
159 BOOTSTD_TEST(bootflow_cmd_glob, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
160
161 /* Check 'bootflow scan -e' */
162 static int bootflow_cmd_scan_e(struct unit_test_state *uts)
163 {
164         ut_assertok(bootstd_test_drop_bootdev_order(uts));
165
166         console_record_reset_enable();
167         ut_assertok(run_command("bootflow scan -aleGH", 0));
168         ut_assert_nextline("Scanning for bootflows in all bootdevs");
169         ut_assert_nextline("Seq  Method       State   Uclass    Part  Name                      Filename");
170         ut_assert_nextlinen("---");
171         ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':");
172         ut_assert_nextline("  0  syslinux     media   mmc          0  mmc2.bootdev.whole        <NULL>");
173         ut_assert_nextline("     ** No partition found, err=-93");
174         ut_assert_nextline("  1  efi          media   mmc          0  mmc2.bootdev.whole        <NULL>");
175         ut_assert_nextline("     ** No partition found, err=-93");
176
177         ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':");
178         ut_assert_nextline("  2  syslinux     media   mmc          0  mmc1.bootdev.whole        <NULL>");
179         ut_assert_nextline("     ** No partition found, err=-2");
180         ut_assert_nextline("  3  efi          media   mmc          0  mmc1.bootdev.whole        <NULL>");
181         ut_assert_nextline("     ** No partition found, err=-2");
182         ut_assert_nextline("  4  syslinux     ready   mmc          1  mmc1.bootdev.part_1       /extlinux/extlinux.conf");
183         ut_assert_nextline("  5  efi          fs      mmc          1  mmc1.bootdev.part_1       efi/boot/bootsbox.efi");
184
185         ut_assert_skip_to_line("Scanning bootdev 'mmc0.bootdev':");
186         ut_assert_skip_to_line(" 3f  efi          media   mmc          0  mmc0.bootdev.whole        <NULL>");
187         ut_assert_nextline("     ** No partition found, err=-93");
188         ut_assert_nextline("No more bootdevs");
189         ut_assert_nextlinen("---");
190         ut_assert_nextline("(64 bootflows, 1 valid)");
191         ut_assert_console_end();
192
193         ut_assertok(run_command("bootflow list", 0));
194         ut_assert_nextline("Showing all bootflows");
195         ut_assert_nextline("Seq  Method       State   Uclass    Part  Name                      Filename");
196         ut_assert_nextlinen("---");
197         ut_assert_nextline("  0  syslinux     media   mmc          0  mmc2.bootdev.whole        <NULL>");
198         ut_assert_nextline("  1  efi          media   mmc          0  mmc2.bootdev.whole        <NULL>");
199         ut_assert_skip_to_line("  4  syslinux     ready   mmc          1  mmc1.bootdev.part_1       /extlinux/extlinux.conf");
200         ut_assert_skip_to_line(" 3f  efi          media   mmc          0  mmc0.bootdev.whole        <NULL>");
201         ut_assert_nextlinen("---");
202         ut_assert_nextline("(64 bootflows, 1 valid)");
203         ut_assert_console_end();
204
205         return 0;
206 }
207 BOOTSTD_TEST(bootflow_cmd_scan_e, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
208
209 /* Check 'bootflow info' */
210 static int bootflow_cmd_info(struct unit_test_state *uts)
211 {
212         console_record_reset_enable();
213         ut_assertok(run_command("bootdev select 1", 0));
214         ut_assert_console_end();
215         ut_assertok(run_command("bootflow scan", 0));
216         ut_assert_console_end();
217         ut_assertok(run_command("bootflow select 0", 0));
218         ut_assert_console_end();
219         ut_assertok(run_command("bootflow info", 0));
220         ut_assert_nextline("Name:      mmc1.bootdev.part_1");
221         ut_assert_nextline("Device:    mmc1.bootdev");
222         ut_assert_nextline("Block dev: mmc1.blk");
223         ut_assert_nextline("Method:    syslinux");
224         ut_assert_nextline("State:     ready");
225         ut_assert_nextline("Partition: 1");
226         ut_assert_nextline("Subdir:    (none)");
227         ut_assert_nextline("Filename:  /extlinux/extlinux.conf");
228         ut_assert_nextlinen("Buffer:    ");
229         ut_assert_nextline("Size:      253 (595 bytes)");
230         ut_assert_nextline("OS:        Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)");
231         ut_assert_nextline("Logo:      (none)");
232         ut_assert_nextline("FDT:       <NULL>");
233         ut_assert_nextline("Error:     0");
234         ut_assert_console_end();
235
236         ut_assertok(run_command("bootflow info -d", 0));
237         ut_assert_nextline("Name:      mmc1.bootdev.part_1");
238         ut_assert_skip_to_line("Error:     0");
239         ut_assert_nextline("Contents:");
240         ut_assert_nextline("%s", "");
241         ut_assert_nextline("# extlinux.conf generated by appliance-creator");
242         ut_assert_skip_to_line("        initrd /initramfs-5.3.7-301.fc31.armv7hl.img");
243         ut_assert_console_end();
244
245         return 0;
246 }
247 BOOTSTD_TEST(bootflow_cmd_info, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
248
249 /* Check 'bootflow scan -b' to boot the first available bootdev */
250 static int bootflow_scan_boot(struct unit_test_state *uts)
251 {
252         console_record_reset_enable();
253         ut_assertok(inject_response(uts));
254         ut_assertok(run_command("bootflow scan -b", 0));
255         ut_assert_nextline(
256                 "** Booting bootflow 'mmc1.bootdev.part_1' with syslinux");
257         ut_assert_nextline("Ignoring unknown command: ui");
258
259         /*
260          * We expect it to get through to boot although sandbox always returns
261          * -EFAULT as it cannot actually boot the kernel
262          */
263         ut_assert_skip_to_line("sandbox: continuing, as we cannot run Linux");
264         ut_assert_nextline("Boot failed (err=-14)");
265         ut_assert_console_end();
266
267         return 0;
268 }
269 BOOTSTD_TEST(bootflow_scan_boot, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
270
271 /* Check iterating through available bootflows */
272 static int bootflow_iter(struct unit_test_state *uts)
273 {
274         struct bootflow_iter iter;
275         struct bootflow bflow;
276
277         bootstd_clear_glob();
278
279         /* The first device is mmc2.bootdev which has no media */
280         ut_asserteq(-EPROTONOSUPPORT,
281                     bootflow_scan_first(&iter, BOOTFLOWF_ALL | BOOTFLOWF_SKIP_GLOBAL, &bflow));
282         ut_asserteq(2, iter.num_methods);
283         ut_asserteq(0, iter.cur_method);
284         ut_asserteq(0, iter.part);
285         ut_asserteq(0, iter.max_part);
286         ut_asserteq_str("syslinux", iter.method->name);
287         ut_asserteq(0, bflow.err);
288
289         /*
290          * This shows MEDIA even though there is none, since in
291          * bootdev_find_in_blk() we call part_get_info() which returns
292          * -EPROTONOSUPPORT. Ideally it would return -EEOPNOTSUPP and we would
293          * know.
294          */
295         ut_asserteq(BOOTFLOWST_MEDIA, bflow.state);
296
297         ut_asserteq(-EPROTONOSUPPORT, bootflow_scan_next(&iter, &bflow));
298         ut_asserteq(2, iter.num_methods);
299         ut_asserteq(1, iter.cur_method);
300         ut_asserteq(0, iter.part);
301         ut_asserteq(0, iter.max_part);
302         ut_asserteq_str("efi", iter.method->name);
303         ut_asserteq(0, bflow.err);
304         ut_asserteq(BOOTFLOWST_MEDIA, bflow.state);
305         bootflow_free(&bflow);
306
307         /* The next device is mmc1.bootdev - at first we use the whole device */
308         ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow));
309         ut_asserteq(2, iter.num_methods);
310         ut_asserteq(0, iter.cur_method);
311         ut_asserteq(0, iter.part);
312         ut_asserteq(0x1e, iter.max_part);
313         ut_asserteq_str("syslinux", iter.method->name);
314         ut_asserteq(0, bflow.err);
315         ut_asserteq(BOOTFLOWST_MEDIA, bflow.state);
316         bootflow_free(&bflow);
317
318         ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow));
319         ut_asserteq(2, iter.num_methods);
320         ut_asserteq(1, iter.cur_method);
321         ut_asserteq(0, iter.part);
322         ut_asserteq(0x1e, iter.max_part);
323         ut_asserteq_str("efi", iter.method->name);
324         ut_asserteq(0, bflow.err);
325         ut_asserteq(BOOTFLOWST_MEDIA, bflow.state);
326         bootflow_free(&bflow);
327
328         /* Then more to partition 1 where we find something */
329         ut_assertok(bootflow_scan_next(&iter, &bflow));
330         ut_asserteq(2, iter.num_methods);
331         ut_asserteq(0, iter.cur_method);
332         ut_asserteq(1, iter.part);
333         ut_asserteq(0x1e, iter.max_part);
334         ut_asserteq_str("syslinux", iter.method->name);
335         ut_asserteq(0, bflow.err);
336         ut_asserteq(BOOTFLOWST_READY, bflow.state);
337         bootflow_free(&bflow);
338
339         ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow));
340         ut_asserteq(2, iter.num_methods);
341         ut_asserteq(1, iter.cur_method);
342         ut_asserteq(1, iter.part);
343         ut_asserteq(0x1e, iter.max_part);
344         ut_asserteq_str("efi", iter.method->name);
345         ut_asserteq(0, bflow.err);
346         ut_asserteq(BOOTFLOWST_FS, bflow.state);
347         bootflow_free(&bflow);
348
349         /* Then more to partition 2 which exists but is not bootable */
350         ut_asserteq(-EINVAL, bootflow_scan_next(&iter, &bflow));
351         ut_asserteq(2, iter.num_methods);
352         ut_asserteq(0, iter.cur_method);
353         ut_asserteq(2, iter.part);
354         ut_asserteq(0x1e, iter.max_part);
355         ut_asserteq_str("syslinux", iter.method->name);
356         ut_asserteq(0, bflow.err);
357         ut_asserteq(BOOTFLOWST_MEDIA, bflow.state);
358         bootflow_free(&bflow);
359
360         bootflow_iter_uninit(&iter);
361
362         ut_assert_console_end();
363
364         return 0;
365 }
366 BOOTSTD_TEST(bootflow_iter, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
367
368 #if defined(CONFIG_SANDBOX) && defined(CONFIG_BOOTMETH_GLOBAL)
369 /* Check using the system bootdev */
370 static int bootflow_system(struct unit_test_state *uts)
371 {
372         struct udevice *bootstd, *dev;
373
374         if (!IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR))
375                 return -EAGAIN;
376         ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
377         ut_assertok(device_bind(bootstd, DM_DRIVER_GET(bootmeth_efi_mgr),
378                                 "efi_mgr", 0, ofnode_null(), &dev));
379         ut_assertok(device_probe(dev));
380         sandbox_set_fake_efi_mgr_dev(dev, true);
381
382         /* We should get a single 'bootmgr' method right at the end */
383         bootstd_clear_glob();
384         console_record_reset_enable();
385         ut_assertok(run_command("bootflow scan -lH", 0));
386         ut_assert_skip_to_line(
387                 "  0  efi_mgr      ready   (none)       0  <NULL>                    <NULL>");
388         ut_assert_skip_to_line("No more bootdevs");
389         ut_assert_skip_to_line("(2 bootflows, 2 valid)");
390         ut_assert_console_end();
391
392         return 0;
393 }
394 BOOTSTD_TEST(bootflow_system, UT_TESTF_DM | UT_TESTF_SCAN_PDATA |
395              UT_TESTF_SCAN_FDT);
396 #endif
397
398 /* Check disabling a bootmethod if it requests it */
399 static int bootflow_iter_disable(struct unit_test_state *uts)
400 {
401         struct udevice *bootstd, *dev;
402         struct bootflow_iter iter;
403         struct bootflow bflow;
404         int i;
405
406         /* Add the EFI bootmgr driver */
407         ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
408         ut_assertok(device_bind_driver(bootstd, "bootmeth_sandbox", "sandbox",
409                                        &dev));
410
411         ut_assertok(bootstd_test_drop_bootdev_order(uts));
412
413         bootstd_clear_glob();
414         console_record_reset_enable();
415         ut_assertok(inject_response(uts));
416         ut_assertok(run_command("bootflow scan -lbH", 0));
417
418         /* Try to boot the bootmgr flow, which will fail */
419         console_record_reset_enable();
420         ut_assertok(bootflow_scan_first(&iter, 0, &bflow));
421         ut_asserteq(3, iter.num_methods);
422         ut_asserteq_str("sandbox", iter.method->name);
423         ut_assertok(inject_response(uts));
424         ut_asserteq(-ENOTSUPP, bootflow_run_boot(&iter, &bflow));
425
426         ut_assert_skip_to_line("Boot method 'sandbox' failed and will not be retried");
427         ut_assert_console_end();
428
429         /* Check that the sandbox bootmeth has been removed */
430         ut_asserteq(2, iter.num_methods);
431         for (i = 0; i < iter.num_methods; i++)
432                 ut_assert(strcmp("sandbox", iter.method_order[i]->name));
433
434         return 0;
435 }
436 BOOTSTD_TEST(bootflow_iter_disable, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
437
438 /* Check 'bootflow scan' with a bootmeth ordering including a global bootmeth */
439 static int bootflow_scan_glob_bootmeth(struct unit_test_state *uts)
440 {
441         if (!IS_ENABLED(CONFIG_BOOTMETH_GLOBAL))
442                 return -EAGAIN;
443
444         ut_assertok(bootstd_test_drop_bootdev_order(uts));
445
446         /*
447          * Make sure that the -G flag makes the scan fail, since this is not
448          * supported when an ordering is provided
449          */
450         console_record_reset_enable();
451         ut_assertok(bootmeth_set_order("efi firmware0"));
452         ut_assertok(run_command("bootflow scan -lGH", 0));
453         ut_assert_nextline("Scanning for bootflows in all bootdevs");
454         ut_assert_nextline(
455                 "Seq  Method       State   Uclass    Part  Name                      Filename");
456         ut_assert_nextlinen("---");
457         ut_assert_nextlinen("---");
458         ut_assert_nextline("(0 bootflows, 0 valid)");
459         ut_assert_console_end();
460
461         ut_assertok(run_command("bootflow scan -lH", 0));
462         ut_assert_nextline("Scanning for bootflows in all bootdevs");
463         ut_assert_nextline(
464                 "Seq  Method       State   Uclass    Part  Name                      Filename");
465         ut_assert_nextlinen("---");
466         ut_assert_nextline("Scanning global bootmeth 'firmware0':");
467         ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':");
468         ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':");
469         ut_assert_nextline("Scanning bootdev 'mmc0.bootdev':");
470         ut_assert_nextline("No more bootdevs");
471         ut_assert_nextlinen("---");
472         ut_assert_nextline("(0 bootflows, 0 valid)");
473         ut_assert_console_end();
474
475         return 0;
476 }
477 BOOTSTD_TEST(bootflow_scan_glob_bootmeth, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
478
479 /* Check 'bootflow boot' to boot a selected bootflow */
480 static int bootflow_cmd_boot(struct unit_test_state *uts)
481 {
482         console_record_reset_enable();
483         ut_assertok(run_command("bootdev select 1", 0));
484         ut_assert_console_end();
485         ut_assertok(run_command("bootflow scan", 0));
486         ut_assert_console_end();
487         ut_assertok(run_command("bootflow select 0", 0));
488         ut_assert_console_end();
489
490         ut_assertok(inject_response(uts));
491         ut_asserteq(1, run_command("bootflow boot", 0));
492         ut_assert_nextline(
493                 "** Booting bootflow 'mmc1.bootdev.part_1' with syslinux");
494         ut_assert_nextline("Ignoring unknown command: ui");
495
496         /*
497          * We expect it to get through to boot although sandbox always returns
498          * -EFAULT as it cannot actually boot the kernel
499          */
500         ut_assert_skip_to_line("sandbox: continuing, as we cannot run Linux");
501         ut_assert_nextline("Boot failed (err=-14)");
502         ut_assert_console_end();
503
504         return 0;
505 }
506 BOOTSTD_TEST(bootflow_cmd_boot, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
507
508 /**
509  * prep_mmc4_bootdev() - Set up the mmc4 bootdev so we can access a fake Armbian
510  *
511  * @uts: Unit test state
512  * Returns 0 on success, -ve on failure
513  */
514 static int prep_mmc4_bootdev(struct unit_test_state *uts)
515 {
516         static const char *order[] = {"mmc2", "mmc1", "mmc4", NULL};
517         struct udevice *dev, *bootstd;
518         struct bootstd_priv *std;
519         const char **old_order;
520         ofnode node;
521
522         /* Enable the mmc4 node since we need a second bootflow */
523         node = ofnode_path("/mmc4");
524         ut_assertok(lists_bind_fdt(gd->dm_root, node, &dev, NULL, false));
525
526         /* Enable the script bootmeth too */
527         ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
528         ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_script),
529                                 "bootmeth_script", 0, ofnode_null(), &dev));
530
531         /* Change the order to include mmc4 */
532         std = dev_get_priv(bootstd);
533         old_order = std->bootdev_order;
534         std->bootdev_order = order;
535
536         console_record_reset_enable();
537         ut_assertok(run_command("bootflow scan", 0));
538         ut_assert_console_end();
539
540         /* Restore the order used by the device tree */
541         std->bootdev_order = old_order;
542
543         return 0;
544 }
545
546 /* Check 'bootflow menu' to select a bootflow */
547 static int bootflow_cmd_menu(struct unit_test_state *uts)
548 {
549         char prev[3];
550
551         ut_assertok(prep_mmc4_bootdev(uts));
552
553         /* Add keypresses to move to and select the second one in the list */
554         prev[0] = CTL_CH('n');
555         prev[1] = '\r';
556         prev[2] = '\0';
557         ut_asserteq(2, console_in_puts(prev));
558
559         ut_assertok(run_command("bootflow menu", 0));
560         ut_assert_nextline("Selected: Armbian");
561         ut_assert_console_end();
562
563         return 0;
564 }
565 BOOTSTD_TEST(bootflow_cmd_menu, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
566
567 /**
568  * check_font() - Check that the font size for an item matches expectations
569  *
570  * @uts: Unit test state
571  * @scn: Scene containing the text object
572  * @id: ID of the text object
573  * Returns 0 on success, -ve on failure
574  */
575 static int check_font(struct unit_test_state *uts, struct scene *scn, uint id,
576                       int font_size)
577 {
578         struct scene_obj_txt *txt;
579
580         txt = scene_obj_find(scn, id, SCENEOBJT_TEXT);
581         ut_assertnonnull(txt);
582
583         ut_asserteq(font_size, txt->font_size);
584
585         return 0;
586 }
587
588 /* Check themes work with a bootflow menu */
589 static int bootflow_menu_theme(struct unit_test_state *uts)
590 {
591         const int font_size = 30;
592         struct scene *scn;
593         struct expo *exp;
594         ofnode node;
595         int i;
596
597         ut_assertok(prep_mmc4_bootdev(uts));
598
599         ut_assertok(bootflow_menu_new(&exp));
600         node = ofnode_path("/bootstd/theme");
601         ut_assert(ofnode_valid(node));
602         ut_assertok(bootflow_menu_apply_theme(exp, node));
603
604         scn = expo_lookup_scene_id(exp, MAIN);
605         ut_assertnonnull(scn);
606
607         /*
608          * Check that the txt objects have the correct font size from the
609          * device tree node: bootstd/theme
610          *
611          * Check both menu items, since there are two bootflows
612          */
613         ut_assertok(check_font(uts, scn, OBJ_PROMPT, font_size));
614         ut_assertok(check_font(uts, scn, OBJ_POINTER, font_size));
615         for (i = 0; i < 2; i++) {
616                 ut_assertok(check_font(uts, scn, ITEM_DESC + i, font_size));
617                 ut_assertok(check_font(uts, scn, ITEM_KEY + i, font_size));
618                 ut_assertok(check_font(uts, scn, ITEM_LABEL + i, font_size));
619         }
620
621         expo_destroy(exp);
622
623         return 0;
624 }
625 BOOTSTD_TEST(bootflow_menu_theme, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
This page took 0.062959 seconds and 4 git commands to generate.