1 // SPDX-License-Identifier: GPL-2.0+
3 * Test for bootdev functions. All start with 'bootmeth'
5 * Copyright 2021 Google LLC
13 #include <test/suites.h>
15 #include "bootstd_common.h"
17 /* Check 'bootmeth list' command */
18 static int bootmeth_cmd_list(struct unit_test_state *uts)
20 console_record_reset_enable();
21 ut_assertok(run_command("bootmeth list", 0));
22 ut_assert_nextline("Order Seq Name Description");
23 ut_assert_nextlinen("---");
24 ut_assert_nextline(" 0 0 syslinux Syslinux boot from a block device");
25 ut_assert_nextline(" 1 1 efi EFI boot from an .efi file");
26 ut_assert_nextline(" glob 2 firmware0 VBE simple");
27 ut_assert_nextlinen("---");
28 ut_assert_nextline("(3 bootmeths)");
29 ut_assert_console_end();
33 BOOTSTD_TEST(bootmeth_cmd_list, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
35 /* Check 'bootmeth order' command */
36 static int bootmeth_cmd_order(struct unit_test_state *uts)
38 /* Select just one bootmethod */
39 console_record_reset_enable();
40 ut_assertok(run_command("bootmeth order syslinux", 0));
41 ut_assert_console_end();
42 ut_assertnonnull(env_get("bootmeths"));
43 ut_asserteq_str("syslinux", env_get("bootmeths"));
45 /* Only that one should be listed */
46 ut_assertok(run_command("bootmeth list", 0));
47 ut_assert_nextline("Order Seq Name Description");
48 ut_assert_nextlinen("---");
49 ut_assert_nextline(" 0 0 syslinux Syslinux boot from a block device");
50 ut_assert_nextlinen("---");
51 ut_assert_nextline("(1 bootmeth)");
52 ut_assert_console_end();
54 /* Check the -a flag, efi should show as not in the order ("-") */
55 ut_assertok(run_command("bootmeth list -a", 0));
56 ut_assert_nextline("Order Seq Name Description");
57 ut_assert_nextlinen("---");
58 ut_assert_nextline(" 0 0 syslinux Syslinux boot from a block device");
59 ut_assert_nextline(" - 1 efi EFI boot from an .efi file");
60 ut_assert_nextline(" glob 2 firmware0 VBE simple");
61 ut_assert_nextlinen("---");
62 ut_assert_nextline("(3 bootmeths)");
63 ut_assert_console_end();
65 /* Check the -a flag with the reverse order */
66 ut_assertok(run_command("bootmeth order \"efi syslinux\"", 0));
67 ut_assert_console_end();
68 ut_assertok(run_command("bootmeth list -a", 0));
69 ut_assert_nextline("Order Seq Name Description");
70 ut_assert_nextlinen("---");
71 ut_assert_nextline(" 1 0 syslinux Syslinux boot from a block device");
72 ut_assert_nextline(" 0 1 efi EFI boot from an .efi file");
73 ut_assert_nextline(" glob 2 firmware0 VBE simple");
74 ut_assert_nextlinen("---");
75 ut_assert_nextline("(3 bootmeths)");
76 ut_assert_console_end();
78 /* Now reset the order to empty, which should show all of them again */
79 ut_assertok(run_command("bootmeth order", 0));
80 ut_assert_console_end();
81 ut_assertnull(env_get("bootmeths"));
82 ut_assertok(run_command("bootmeth list", 0));
83 ut_assert_skip_to_line("(3 bootmeths)");
85 /* Try reverse order */
86 ut_assertok(run_command("bootmeth order \"efi syslinux\"", 0));
87 ut_assert_console_end();
88 ut_assertok(run_command("bootmeth list", 0));
89 ut_assert_nextline("Order Seq Name Description");
90 ut_assert_nextlinen("---");
91 ut_assert_nextline(" 0 1 efi EFI boot from an .efi file");
92 ut_assert_nextline(" 1 0 syslinux Syslinux boot from a block device");
93 ut_assert_nextlinen("---");
94 ut_assert_nextline("(2 bootmeths)");
95 ut_assertnonnull(env_get("bootmeths"));
96 ut_asserteq_str("efi syslinux", env_get("bootmeths"));
97 ut_assert_console_end();
99 /* Try with global bootmeths */
100 ut_assertok(run_command("bootmeth order \"efi firmware0\"", 0));
101 ut_assert_console_end();
102 ut_assertok(run_command("bootmeth list", 0));
103 ut_assert_nextline("Order Seq Name Description");
104 ut_assert_nextlinen("---");
105 ut_assert_nextline(" 0 1 efi EFI boot from an .efi file");
106 ut_assert_nextline(" glob 2 firmware0 VBE simple");
107 ut_assert_nextlinen("---");
108 ut_assert_nextline("(2 bootmeths)");
109 ut_assertnonnull(env_get("bootmeths"));
110 ut_asserteq_str("efi firmware0", env_get("bootmeths"));
111 ut_assert_console_end();
115 BOOTSTD_TEST(bootmeth_cmd_order, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
117 /* Check 'bootmeths' env var */
118 static int bootmeth_env(struct unit_test_state *uts)
120 struct bootstd_priv *std;
122 ut_assertok(bootstd_get_priv(&std));
124 /* Select just one bootmethod */
125 console_record_reset_enable();
126 ut_assertok(env_set("bootmeths", "syslinux"));
127 ut_asserteq(1, std->bootmeth_count);
129 /* Select an invalid bootmethod */
130 ut_asserteq(1, run_command("setenv bootmeths fred", 0));
131 ut_assert_nextline("Unknown bootmeth 'fred'");
132 ut_assert_nextlinen("## Error inserting");
133 ut_assert_console_end();
135 ut_assertok(env_set("bootmeths", "efi syslinux"));
136 ut_asserteq(2, std->bootmeth_count);
137 ut_assert_console_end();
141 BOOTSTD_TEST(bootmeth_env, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
143 /* Check the get_state_desc() method */
144 static int bootmeth_state(struct unit_test_state *uts)
149 ut_assertok(uclass_first_device(UCLASS_BOOTMETH, &dev));
150 ut_assertnonnull(dev);
152 ut_assertok(bootmeth_get_state_desc(dev, buf, sizeof(buf)));
153 ut_asserteq_str("OK", buf);
157 BOOTSTD_TEST(bootmeth_state, UT_TESTF_DM | UT_TESTF_SCAN_FDT);