Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Simon Glass | da19202 | 2022-07-30 15:52:17 -0600 | [diff] [blame] | 3 | * Test for bootdev functions. All start with 'bootmeth' |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 4 | * |
| 5 | * Copyright 2021 Google LLC |
| 6 | * Written by Simon Glass <sjg@chromium.org> |
| 7 | */ |
| 8 | |
Simon Glass | f6d71a8 | 2022-07-30 15:52:19 -0600 | [diff] [blame] | 9 | #include <bootmeth.h> |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 10 | #include <bootstd.h> |
Simon Glass | f6d71a8 | 2022-07-30 15:52:19 -0600 | [diff] [blame] | 11 | #include <dm.h> |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 12 | #include <test/suites.h> |
| 13 | #include <test/ut.h> |
| 14 | #include "bootstd_common.h" |
| 15 | |
| 16 | /* Check 'bootmeth list' command */ |
| 17 | static int bootmeth_cmd_list(struct unit_test_state *uts) |
| 18 | { |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 19 | ut_assertok(run_command("bootmeth list", 0)); |
| 20 | ut_assert_nextline("Order Seq Name Description"); |
| 21 | ut_assert_nextlinen("---"); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 22 | ut_assert_nextline(" 0 0 extlinux Extlinux boot from a block device"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 23 | ut_assert_nextline(" 1 1 efi EFI boot from an .efi file"); |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 24 | if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL)) |
| 25 | ut_assert_nextline(" glob 2 firmware0 VBE simple"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 26 | ut_assert_nextlinen("---"); |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 27 | ut_assert_nextline(IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) ? |
| 28 | "(3 bootmeths)" : "(2 bootmeths)"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 29 | ut_assert_console_end(); |
| 30 | |
| 31 | return 0; |
| 32 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 33 | BOOTSTD_TEST(bootmeth_cmd_list, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 34 | |
| 35 | /* Check 'bootmeth order' command */ |
| 36 | static int bootmeth_cmd_order(struct unit_test_state *uts) |
| 37 | { |
| 38 | /* Select just one bootmethod */ |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 39 | ut_assertok(run_command("bootmeth order extlinux", 0)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 40 | ut_assert_console_end(); |
| 41 | ut_assertnonnull(env_get("bootmeths")); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 42 | ut_asserteq_str("extlinux", env_get("bootmeths")); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 43 | |
| 44 | /* Only that one should be listed */ |
| 45 | ut_assertok(run_command("bootmeth list", 0)); |
| 46 | ut_assert_nextline("Order Seq Name Description"); |
| 47 | ut_assert_nextlinen("---"); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 48 | ut_assert_nextline(" 0 0 extlinux Extlinux boot from a block device"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 49 | ut_assert_nextlinen("---"); |
| 50 | ut_assert_nextline("(1 bootmeth)"); |
| 51 | ut_assert_console_end(); |
| 52 | |
| 53 | /* Check the -a flag, efi should show as not in the order ("-") */ |
| 54 | ut_assertok(run_command("bootmeth list -a", 0)); |
| 55 | ut_assert_nextline("Order Seq Name Description"); |
| 56 | ut_assert_nextlinen("---"); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 57 | ut_assert_nextline(" 0 0 extlinux Extlinux boot from a block device"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 58 | ut_assert_nextline(" - 1 efi EFI boot from an .efi file"); |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 59 | if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL)) |
| 60 | ut_assert_nextline(" glob 2 firmware0 VBE simple"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 61 | ut_assert_nextlinen("---"); |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 62 | ut_assert_nextline(IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) ? |
| 63 | "(3 bootmeths)" : "(2 bootmeths)"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 64 | ut_assert_console_end(); |
| 65 | |
| 66 | /* Check the -a flag with the reverse order */ |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 67 | ut_assertok(run_command("bootmeth order \"efi extlinux\"", 0)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 68 | ut_assert_console_end(); |
| 69 | ut_assertok(run_command("bootmeth list -a", 0)); |
| 70 | ut_assert_nextline("Order Seq Name Description"); |
| 71 | ut_assert_nextlinen("---"); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 72 | ut_assert_nextline(" 1 0 extlinux Extlinux boot from a block device"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 73 | ut_assert_nextline(" 0 1 efi EFI boot from an .efi file"); |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 74 | if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL)) |
| 75 | ut_assert_nextline(" glob 2 firmware0 VBE simple"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 76 | ut_assert_nextlinen("---"); |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 77 | ut_assert_nextline(IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) ? |
| 78 | "(3 bootmeths)" : "(2 bootmeths)"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 79 | ut_assert_console_end(); |
| 80 | |
| 81 | /* Now reset the order to empty, which should show all of them again */ |
| 82 | ut_assertok(run_command("bootmeth order", 0)); |
| 83 | ut_assert_console_end(); |
| 84 | ut_assertnull(env_get("bootmeths")); |
| 85 | ut_assertok(run_command("bootmeth list", 0)); |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 86 | ut_assert_skip_to_line(IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) ? |
| 87 | "(3 bootmeths)" : "(2 bootmeths)"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 88 | |
| 89 | /* Try reverse order */ |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 90 | ut_assertok(run_command("bootmeth order \"efi extlinux\"", 0)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 91 | ut_assert_console_end(); |
| 92 | ut_assertok(run_command("bootmeth list", 0)); |
| 93 | ut_assert_nextline("Order Seq Name Description"); |
| 94 | ut_assert_nextlinen("---"); |
| 95 | ut_assert_nextline(" 0 1 efi EFI boot from an .efi file"); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 96 | ut_assert_nextline(" 1 0 extlinux Extlinux boot from a block device"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 97 | ut_assert_nextlinen("---"); |
| 98 | ut_assert_nextline("(2 bootmeths)"); |
| 99 | ut_assertnonnull(env_get("bootmeths")); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 100 | ut_asserteq_str("efi extlinux", env_get("bootmeths")); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 101 | ut_assert_console_end(); |
| 102 | |
Simon Glass | c759944 | 2022-10-20 18:22:49 -0600 | [diff] [blame] | 103 | return 0; |
| 104 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 105 | BOOTSTD_TEST(bootmeth_cmd_order, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | c759944 | 2022-10-20 18:22:49 -0600 | [diff] [blame] | 106 | |
| 107 | /* Check 'bootmeth order' command with global bootmeths */ |
| 108 | static int bootmeth_cmd_order_glob(struct unit_test_state *uts) |
| 109 | { |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 110 | if (!IS_ENABLED(CONFIG_BOOTMETH_GLOBAL)) |
Simon Glass | c759944 | 2022-10-20 18:22:49 -0600 | [diff] [blame] | 111 | return -EAGAIN; |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 112 | |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 113 | ut_assertok(run_command("bootmeth order \"efi firmware0\"", 0)); |
| 114 | ut_assert_console_end(); |
| 115 | ut_assertok(run_command("bootmeth list", 0)); |
| 116 | ut_assert_nextline("Order Seq Name Description"); |
| 117 | ut_assert_nextlinen("---"); |
| 118 | ut_assert_nextline(" 0 1 efi EFI boot from an .efi file"); |
| 119 | ut_assert_nextline(" glob 2 firmware0 VBE simple"); |
| 120 | ut_assert_nextlinen("---"); |
| 121 | ut_assert_nextline("(2 bootmeths)"); |
| 122 | ut_assertnonnull(env_get("bootmeths")); |
| 123 | ut_asserteq_str("efi firmware0", env_get("bootmeths")); |
| 124 | ut_assert_console_end(); |
| 125 | |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 126 | return 0; |
| 127 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 128 | BOOTSTD_TEST(bootmeth_cmd_order_glob, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 129 | |
| 130 | /* Check 'bootmeths' env var */ |
| 131 | static int bootmeth_env(struct unit_test_state *uts) |
| 132 | { |
| 133 | struct bootstd_priv *std; |
| 134 | |
| 135 | ut_assertok(bootstd_get_priv(&std)); |
| 136 | |
| 137 | /* Select just one bootmethod */ |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 138 | ut_assertok(env_set("bootmeths", "extlinux")); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 139 | ut_asserteq(1, std->bootmeth_count); |
| 140 | |
| 141 | /* Select an invalid bootmethod */ |
| 142 | ut_asserteq(1, run_command("setenv bootmeths fred", 0)); |
| 143 | ut_assert_nextline("Unknown bootmeth 'fred'"); |
| 144 | ut_assert_nextlinen("## Error inserting"); |
| 145 | ut_assert_console_end(); |
| 146 | |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 147 | ut_assertok(env_set("bootmeths", "efi extlinux")); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 148 | ut_asserteq(2, std->bootmeth_count); |
| 149 | ut_assert_console_end(); |
| 150 | |
| 151 | return 0; |
| 152 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 153 | BOOTSTD_TEST(bootmeth_env, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | f6d71a8 | 2022-07-30 15:52:19 -0600 | [diff] [blame] | 154 | |
| 155 | /* Check the get_state_desc() method */ |
| 156 | static int bootmeth_state(struct unit_test_state *uts) |
| 157 | { |
| 158 | struct udevice *dev; |
| 159 | char buf[50]; |
| 160 | |
Michal Suchanek | ac12a2f | 2022-10-12 21:57:59 +0200 | [diff] [blame] | 161 | ut_assertok(uclass_first_device_err(UCLASS_BOOTMETH, &dev)); |
Simon Glass | f6d71a8 | 2022-07-30 15:52:19 -0600 | [diff] [blame] | 162 | ut_assertnonnull(dev); |
| 163 | |
| 164 | ut_assertok(bootmeth_get_state_desc(dev, buf, sizeof(buf))); |
| 165 | ut_asserteq_str("OK", buf); |
| 166 | |
| 167 | return 0; |
| 168 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 169 | BOOTSTD_TEST(bootmeth_state, UTF_DM | UTF_SCAN_FDT); |