1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2021 Steffen Jaeckel
5 * Unit tests for autoboot functionality
10 #include <test/common.h>
11 #include <test/test.h>
16 static int check_for_input(struct unit_test_state *uts, const char *in,
20 /* The bootdelay is set to 1 second in test_autoboot() */
21 const char *autoboot_prompt =
22 "Enter password \"a\" in 1 seconds to stop autoboot";
24 console_record_reset_enable();
27 /* turn on keyed autoboot for the test, if possible */
28 old_val = autoboot_set_keyed(true);
29 autoboot_command("echo Autoboot password unlock not successful");
30 old_val = autoboot_set_keyed(old_val);
32 ut_assert_nextline(autoboot_prompt);
34 ut_assert_nextline("Autoboot password unlock not successful");
35 ut_assert_console_end();
40 * test_autoboot() - unit test for autoboot
42 * @uts: unit test state
43 * Return: 0 = success, 1 = failure
45 static int test_autoboot(struct unit_test_state *uts)
47 /* make sure that the bootdelay is set to something,
48 * otherwise the called functions will time out
50 ut_assertok(env_set("bootdelay", "1"));
53 /* unset all relevant environment variables */
54 env_set("bootstopusesha256", NULL);
55 env_set("bootstopkeycrypt", NULL);
56 env_set("bootstopkeysha256", NULL);
58 if (IS_ENABLED(CONFIG_CRYPT_PW_SHA256)) {
59 /* test the default password from CONFIG_AUTOBOOT_STOP_STR_CRYPT */
60 ut_assertok(check_for_input(uts, "a\n", true));
61 /* test a password from the `bootstopkeycrypt` environment variable */
64 "$5$rounds=640000$ycgRgpnRq4lmu.eb$aZ6YJWdklvyLML13w7mEHMHJnJOux6aptnp6VlsR5a9"));
66 ut_assertok(check_for_input(uts, "test\n", true));
68 /* verify that the `bootstopusesha256` variable is treated correctly */
69 ut_assertok(env_set("bootstopusesha256", "false"));
70 ut_assertok(check_for_input(uts, "test\n", true));
73 if (IS_ENABLED(CONFIG_AUTOBOOT_ENCRYPTION)) {
74 /* test the `bootstopusesha256` and `bootstopkeysha256` features */
75 ut_assertok(env_set("bootstopusesha256", "true"));
78 "edeaaff3f1774ad2888673770c6d64097e391bc362d7d6fb34982ddf0efd18cb"));
80 ut_assertok(check_for_input(uts, "abc\n", true));
84 "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"));
86 ut_assertok(check_for_input(uts, "abc", true));
88 ut_assertok(check_for_input(uts, "abc\n", true));
90 ut_assertok(check_for_input(uts, "abd", false));
93 return CMD_RET_SUCCESS;
96 COMMON_TEST(test_autoboot, 0);