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 | |
| 9 | #include <common.h> |
Simon Glass | f6d71a8 | 2022-07-30 15:52:19 -0600 | [diff] [blame^] | 10 | #include <bootmeth.h> |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 11 | #include <bootstd.h> |
Simon Glass | f6d71a8 | 2022-07-30 15:52:19 -0600 | [diff] [blame^] | 12 | #include <dm.h> |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 13 | #include <test/suites.h> |
| 14 | #include <test/ut.h> |
| 15 | #include "bootstd_common.h" |
| 16 | |
| 17 | /* Check 'bootmeth list' command */ |
| 18 | static int bootmeth_cmd_list(struct unit_test_state *uts) |
| 19 | { |
| 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_nextlinen("---"); |
| 27 | ut_assert_nextline("(2 bootmeths)"); |
| 28 | ut_assert_console_end(); |
| 29 | |
| 30 | return 0; |
| 31 | } |
| 32 | BOOTSTD_TEST(bootmeth_cmd_list, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 33 | |
| 34 | /* Check 'bootmeth order' command */ |
| 35 | static int bootmeth_cmd_order(struct unit_test_state *uts) |
| 36 | { |
| 37 | /* Select just one bootmethod */ |
| 38 | console_record_reset_enable(); |
| 39 | ut_assertok(run_command("bootmeth order syslinux", 0)); |
| 40 | ut_assert_console_end(); |
| 41 | ut_assertnonnull(env_get("bootmeths")); |
| 42 | ut_asserteq_str("syslinux", env_get("bootmeths")); |
| 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("---"); |
| 48 | ut_assert_nextline(" 0 0 syslinux Syslinux boot from a block device"); |
| 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("---"); |
| 57 | ut_assert_nextline(" 0 0 syslinux Syslinux boot from a block device"); |
| 58 | ut_assert_nextline(" - 1 efi EFI boot from an .efi file"); |
| 59 | ut_assert_nextlinen("---"); |
| 60 | ut_assert_nextline("(2 bootmeths)"); |
| 61 | ut_assert_console_end(); |
| 62 | |
| 63 | /* Check the -a flag with the reverse order */ |
| 64 | ut_assertok(run_command("bootmeth order \"efi syslinux\"", 0)); |
| 65 | ut_assert_console_end(); |
| 66 | ut_assertok(run_command("bootmeth list -a", 0)); |
| 67 | ut_assert_nextline("Order Seq Name Description"); |
| 68 | ut_assert_nextlinen("---"); |
| 69 | ut_assert_nextline(" 1 0 syslinux Syslinux boot from a block device"); |
| 70 | ut_assert_nextline(" 0 1 efi EFI boot from an .efi file"); |
| 71 | ut_assert_nextlinen("---"); |
| 72 | ut_assert_nextline("(2 bootmeths)"); |
| 73 | ut_assert_console_end(); |
| 74 | |
| 75 | /* Now reset the order to empty, which should show all of them again */ |
| 76 | ut_assertok(run_command("bootmeth order", 0)); |
| 77 | ut_assert_console_end(); |
| 78 | ut_assertnull(env_get("bootmeths")); |
| 79 | ut_assertok(run_command("bootmeth list", 0)); |
| 80 | ut_assert_skip_to_line("(2 bootmeths)"); |
| 81 | |
| 82 | /* Try reverse order */ |
| 83 | ut_assertok(run_command("bootmeth order \"efi syslinux\"", 0)); |
| 84 | ut_assert_console_end(); |
| 85 | ut_assertok(run_command("bootmeth list", 0)); |
| 86 | ut_assert_nextline("Order Seq Name Description"); |
| 87 | ut_assert_nextlinen("---"); |
| 88 | ut_assert_nextline(" 0 1 efi EFI boot from an .efi file"); |
| 89 | ut_assert_nextline(" 1 0 syslinux Syslinux boot from a block device"); |
| 90 | ut_assert_nextlinen("---"); |
| 91 | ut_assert_nextline("(2 bootmeths)"); |
| 92 | ut_assertnonnull(env_get("bootmeths")); |
| 93 | ut_asserteq_str("efi syslinux", env_get("bootmeths")); |
| 94 | ut_assert_console_end(); |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | BOOTSTD_TEST(bootmeth_cmd_order, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 99 | |
| 100 | /* Check 'bootmeths' env var */ |
| 101 | static int bootmeth_env(struct unit_test_state *uts) |
| 102 | { |
| 103 | struct bootstd_priv *std; |
| 104 | |
| 105 | ut_assertok(bootstd_get_priv(&std)); |
| 106 | |
| 107 | /* Select just one bootmethod */ |
| 108 | console_record_reset_enable(); |
| 109 | ut_assertok(env_set("bootmeths", "syslinux")); |
| 110 | ut_asserteq(1, std->bootmeth_count); |
| 111 | |
| 112 | /* Select an invalid bootmethod */ |
| 113 | ut_asserteq(1, run_command("setenv bootmeths fred", 0)); |
| 114 | ut_assert_nextline("Unknown bootmeth 'fred'"); |
| 115 | ut_assert_nextlinen("## Error inserting"); |
| 116 | ut_assert_console_end(); |
| 117 | |
| 118 | ut_assertok(env_set("bootmeths", "efi syslinux")); |
| 119 | ut_asserteq(2, std->bootmeth_count); |
| 120 | ut_assert_console_end(); |
| 121 | |
| 122 | return 0; |
| 123 | } |
| 124 | BOOTSTD_TEST(bootmeth_env, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
Simon Glass | f6d71a8 | 2022-07-30 15:52:19 -0600 | [diff] [blame^] | 125 | |
| 126 | /* Check the get_state_desc() method */ |
| 127 | static int bootmeth_state(struct unit_test_state *uts) |
| 128 | { |
| 129 | struct udevice *dev; |
| 130 | char buf[50]; |
| 131 | |
| 132 | ut_assertok(uclass_first_device(UCLASS_BOOTMETH, &dev)); |
| 133 | ut_assertnonnull(dev); |
| 134 | |
| 135 | ut_assertok(bootmeth_get_state_desc(dev, buf, sizeof(buf))); |
| 136 | ut_asserteq_str("OK", buf); |
| 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | BOOTSTD_TEST(bootmeth_state, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |