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