Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | // SPDX-License-Identifier: GPL-2.0+ /* * Test for bootdev functions. All start with 'bootmeth' * * Copyright 2021 Google LLC * Written by Simon Glass <sjg@chromium.org> */ #include <bootmeth.h> #include <bootstd.h> #include <dm.h> #include <env.h> #include <test/ut.h> #include "bootstd_common.h" /* Check 'bootmeth list' command */ static int bootmeth_cmd_list(struct unit_test_state *uts) { ut_assertok(run_command("bootmeth list", 0)); ut_assert_nextline("Order Seq Name Description"); ut_assert_nextlinen("---"); ut_assert_nextline(" 0 0 extlinux Extlinux boot from a block device"); ut_assert_nextline(" 1 1 efi EFI boot from an .efi file"); ut_assert_nextline(" 2 2 vbe VBE A/B/recovery for OS"); if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL)) ut_assert_nextline(" glob 3 firmware0 VBE simple"); ut_assert_nextlinen("---"); ut_assert_nextline(IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) ? "(4 bootmeths)" : "(3 bootmeths)"); ut_assert_console_end(); return 0; } BOOTSTD_TEST(bootmeth_cmd_list, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); /* Check 'bootmeth order' command */ static int bootmeth_cmd_order(struct unit_test_state *uts) { /* Select just one bootmethod */ ut_assertok(run_command("bootmeth order extlinux", 0)); ut_assert_console_end(); ut_assertnonnull(env_get("bootmeths")); ut_asserteq_str("extlinux", env_get("bootmeths")); /* Only that one should be listed */ ut_assertok(run_command("bootmeth list", 0)); ut_assert_nextline("Order Seq Name Description"); ut_assert_nextlinen("---"); ut_assert_nextline(" 0 0 extlinux Extlinux boot from a block device"); ut_assert_nextlinen("---"); ut_assert_nextline("(1 bootmeth)"); ut_assert_console_end(); /* Check the -a flag, efi should show as not in the order ("-") */ ut_assertok(run_command("bootmeth list -a", 0)); ut_assert_nextline("Order Seq Name Description"); ut_assert_nextlinen("---"); ut_assert_nextline(" 0 0 extlinux Extlinux boot from a block device"); ut_assert_nextline(" - 1 efi EFI boot from an .efi file"); ut_assert_nextline(" - 2 vbe VBE A/B/recovery for OS"); if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL)) ut_assert_nextline(" glob 3 firmware0 VBE simple"); ut_assert_nextlinen("---"); ut_assert_nextline(IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) ? "(4 bootmeths)" : "(3 bootmeths)"); ut_assert_console_end(); /* Check the -a flag with the reverse order */ ut_assertok(run_command("bootmeth order \"efi extlinux\"", 0)); ut_assert_console_end(); ut_assertok(run_command("bootmeth list -a", 0)); ut_assert_nextline("Order Seq Name Description"); ut_assert_nextlinen("---"); ut_assert_nextline(" 1 0 extlinux Extlinux boot from a block device"); ut_assert_nextline(" 0 1 efi EFI boot from an .efi file"); ut_assert_nextline(" - 2 vbe VBE A/B/recovery for OS"); if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL)) ut_assert_nextline(" glob 3 firmware0 VBE simple"); ut_assert_nextlinen("---"); ut_assert_nextline(IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) ? "(4 bootmeths)" : "(3 bootmeths)"); ut_assert_console_end(); /* Now reset the order to empty, which should show all of them again */ ut_assertok(run_command("bootmeth order", 0)); ut_assert_console_end(); ut_assertnull(env_get("bootmeths")); ut_assertok(run_command("bootmeth list", 0)); ut_assert_skip_to_line(IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) ? "(4 bootmeths)" : "(3 bootmeths)"); /* Try reverse order */ ut_assertok(run_command("bootmeth order \"efi extlinux\"", 0)); ut_assert_console_end(); ut_assertok(run_command("bootmeth list", 0)); ut_assert_nextline("Order Seq Name Description"); ut_assert_nextlinen("---"); ut_assert_nextline(" 0 1 efi EFI boot from an .efi file"); ut_assert_nextline(" 1 0 extlinux Extlinux boot from a block device"); ut_assert_nextlinen("---"); ut_assert_nextline("(2 bootmeths)"); ut_assertnonnull(env_get("bootmeths")); ut_asserteq_str("efi extlinux", env_get("bootmeths")); ut_assert_console_end(); return 0; } BOOTSTD_TEST(bootmeth_cmd_order, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); /* Check 'bootmeth order' command with global bootmeths */ static int bootmeth_cmd_order_glob(struct unit_test_state *uts) { if (!IS_ENABLED(CONFIG_BOOTMETH_GLOBAL)) return -EAGAIN; ut_assertok(run_command("bootmeth order \"efi firmware0\"", 0)); ut_assert_console_end(); ut_assertok(run_command("bootmeth list", 0)); ut_assert_nextline("Order Seq Name Description"); ut_assert_nextlinen("---"); ut_assert_nextline(" 0 1 efi EFI boot from an .efi file"); ut_assert_nextline(" glob 3 firmware0 VBE simple"); ut_assert_nextlinen("---"); ut_assert_nextline("(2 bootmeths)"); ut_assertnonnull(env_get("bootmeths")); ut_asserteq_str("efi firmware0", env_get("bootmeths")); ut_assert_console_end(); return 0; } BOOTSTD_TEST(bootmeth_cmd_order_glob, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); /* Check 'bootmeth set' command */ static int bootmeth_cmd_set(struct unit_test_state *uts) { /* Check we can enable extlinux fallback */ console_record_reset_enable(); ut_assertok(run_command("bootmeth set extlinux fallback 1", 0)); ut_assert_console_end(); /* Check we can disable extlinux fallback */ console_record_reset_enable(); ut_assertok(run_command("bootmeth set extlinux fallback 0", 0)); ut_assert_console_end(); /* Check extlinux fallback unexpected value */ console_record_reset_enable(); ut_asserteq(1, run_command("bootmeth set extlinux fallback fred", 0)); ut_assert_nextline("Unexpected value 'fred'"); ut_assert_nextline("Failed (err=-22)"); ut_assert_console_end(); /* Check that we need to provide right number of parameters */ ut_asserteq(1, run_command("bootmeth set extlinux fallback", 0)); ut_assert_nextline("Required parameters not provided"); ut_assert_console_end(); /* Check that we need to provide a valid bootmethod */ ut_asserteq(1, run_command("bootmeth set fred fallback 0", 0)); ut_assert_nextline("Unknown bootmeth 'fred'"); ut_assert_nextline("Failed (err=-19)"); ut_assert_console_end(); /* Check that we need to provide a valid property */ ut_asserteq(1, run_command("bootmeth set extlinux fred 0", 0)); ut_assert_nextline("Invalid option"); ut_assert_nextline("Failed (err=-22)"); ut_assert_console_end(); /* Check that we need to provide a bootmeth that supports properties */ ut_asserteq(1, run_command("bootmeth set efi fallback 0", 0)); ut_assert_nextline("set_property not found"); ut_assert_nextline("Failed (err=-19)"); ut_assert_console_end(); return 0; } BOOTSTD_TEST(bootmeth_cmd_set, UTF_DM | UTF_SCAN_FDT); /* Check 'bootmeths' env var */ static int bootmeth_env(struct unit_test_state *uts) { struct bootstd_priv *std; ut_assertok(bootstd_get_priv(&std)); /* Select just one bootmethod */ ut_assertok(env_set("bootmeths", "extlinux")); ut_asserteq(1, std->bootmeth_count); /* Select an invalid bootmethod */ ut_asserteq(1, run_command("setenv bootmeths fred", 0)); ut_assert_nextline("Unknown bootmeth 'fred'"); ut_assert_nextlinen("## Error inserting"); ut_assert_console_end(); ut_assertok(env_set("bootmeths", "efi extlinux")); ut_asserteq(2, std->bootmeth_count); ut_assert_console_end(); return 0; } BOOTSTD_TEST(bootmeth_env, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); /* Check the get_state_desc() method */ static int bootmeth_state(struct unit_test_state *uts) { struct udevice *dev; char buf[50]; ut_assertok(uclass_first_device_err(UCLASS_BOOTMETH, &dev)); ut_assertnonnull(dev); ut_assertok(bootmeth_get_state_desc(dev, buf, sizeof(buf))); ut_asserteq_str("OK", buf); return 0; } BOOTSTD_TEST(bootmeth_state, UTF_DM | UTF_SCAN_FDT); |