blob: 07776c5368d7b51463c839e9aca3302804335b99 [file] [log] [blame]
Simon Glassfb1451b2022-04-24 23:31:24 -06001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Test for bootdev functions. All start with 'bootdev'
4 *
5 * Copyright 2021 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
7 */
8
9#include <common.h>
10#include <bootstd.h>
11#include <test/suites.h>
12#include <test/ut.h>
13#include "bootstd_common.h"
14
15/* Check 'bootmeth list' command */
16static int bootmeth_cmd_list(struct unit_test_state *uts)
17{
18 console_record_reset_enable();
19 ut_assertok(run_command("bootmeth list", 0));
20 ut_assert_nextline("Order Seq Name Description");
21 ut_assert_nextlinen("---");
22 ut_assert_nextline(" 0 0 syslinux Syslinux boot from a block device");
23 ut_assert_nextline(" 1 1 efi EFI boot from an .efi file");
24 ut_assert_nextlinen("---");
25 ut_assert_nextline("(2 bootmeths)");
26 ut_assert_console_end();
27
28 return 0;
29}
30BOOTSTD_TEST(bootmeth_cmd_list, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
31
32/* Check 'bootmeth order' command */
33static int bootmeth_cmd_order(struct unit_test_state *uts)
34{
35 /* Select just one bootmethod */
36 console_record_reset_enable();
37 ut_assertok(run_command("bootmeth order syslinux", 0));
38 ut_assert_console_end();
39 ut_assertnonnull(env_get("bootmeths"));
40 ut_asserteq_str("syslinux", env_get("bootmeths"));
41
42 /* Only that one should be listed */
43 ut_assertok(run_command("bootmeth list", 0));
44 ut_assert_nextline("Order Seq Name Description");
45 ut_assert_nextlinen("---");
46 ut_assert_nextline(" 0 0 syslinux Syslinux boot from a block device");
47 ut_assert_nextlinen("---");
48 ut_assert_nextline("(1 bootmeth)");
49 ut_assert_console_end();
50
51 /* Check the -a flag, efi should show as not in the order ("-") */
52 ut_assertok(run_command("bootmeth list -a", 0));
53 ut_assert_nextline("Order Seq Name Description");
54 ut_assert_nextlinen("---");
55 ut_assert_nextline(" 0 0 syslinux Syslinux boot from a block device");
56 ut_assert_nextline(" - 1 efi EFI boot from an .efi file");
57 ut_assert_nextlinen("---");
58 ut_assert_nextline("(2 bootmeths)");
59 ut_assert_console_end();
60
61 /* Check the -a flag with the reverse order */
62 ut_assertok(run_command("bootmeth order \"efi syslinux\"", 0));
63 ut_assert_console_end();
64 ut_assertok(run_command("bootmeth list -a", 0));
65 ut_assert_nextline("Order Seq Name Description");
66 ut_assert_nextlinen("---");
67 ut_assert_nextline(" 1 0 syslinux Syslinux boot from a block device");
68 ut_assert_nextline(" 0 1 efi EFI boot from an .efi file");
69 ut_assert_nextlinen("---");
70 ut_assert_nextline("(2 bootmeths)");
71 ut_assert_console_end();
72
73 /* Now reset the order to empty, which should show all of them again */
74 ut_assertok(run_command("bootmeth order", 0));
75 ut_assert_console_end();
76 ut_assertnull(env_get("bootmeths"));
77 ut_assertok(run_command("bootmeth list", 0));
78 ut_assert_skip_to_line("(2 bootmeths)");
79
80 /* Try reverse order */
81 ut_assertok(run_command("bootmeth order \"efi syslinux\"", 0));
82 ut_assert_console_end();
83 ut_assertok(run_command("bootmeth list", 0));
84 ut_assert_nextline("Order Seq Name Description");
85 ut_assert_nextlinen("---");
86 ut_assert_nextline(" 0 1 efi EFI boot from an .efi file");
87 ut_assert_nextline(" 1 0 syslinux Syslinux boot from a block device");
88 ut_assert_nextlinen("---");
89 ut_assert_nextline("(2 bootmeths)");
90 ut_assertnonnull(env_get("bootmeths"));
91 ut_asserteq_str("efi syslinux", env_get("bootmeths"));
92 ut_assert_console_end();
93
94 return 0;
95}
96BOOTSTD_TEST(bootmeth_cmd_order, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
97
98/* Check 'bootmeths' env var */
99static int bootmeth_env(struct unit_test_state *uts)
100{
101 struct bootstd_priv *std;
102
103 ut_assertok(bootstd_get_priv(&std));
104
105 /* Select just one bootmethod */
106 console_record_reset_enable();
107 ut_assertok(env_set("bootmeths", "syslinux"));
108 ut_asserteq(1, std->bootmeth_count);
109
110 /* Select an invalid bootmethod */
111 ut_asserteq(1, run_command("setenv bootmeths fred", 0));
112 ut_assert_nextline("Unknown bootmeth 'fred'");
113 ut_assert_nextlinen("## Error inserting");
114 ut_assert_console_end();
115
116 ut_assertok(env_set("bootmeths", "efi syslinux"));
117 ut_asserteq(2, std->bootmeth_count);
118 ut_assert_console_end();
119
120 return 0;
121}
122BOOTSTD_TEST(bootmeth_env, UT_TESTF_DM | UT_TESTF_SCAN_FDT);