u-boot/test/bootm.c
Simon Glass b3c01678fd bootm: Update bootm_process_cmdline_env() to use flags
At present only one transformation is supported: making the Linux console
silent. To prepare for adding more, convert the boolean parameter into a
flag value.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-12-04 16:09:26 -05:00

60 lines
1.7 KiB
C

// SPDX-License-Identifier: GPL-2.0+
/*
* Tests for bootm routines
*
* Copyright 2020 Google LLC
*/
#include <common.h>
#include <bootm.h>
#include <test/suites.h>
#include <test/test.h>
#include <test/ut.h>
DECLARE_GLOBAL_DATA_PTR;
#define BOOTM_TEST(_name, _flags) UNIT_TEST(_name, _flags, bootm_test)
#define CONSOLE_STR "console=/dev/ttyS0"
/* Test silent processing in the bootargs variable */
static int bootm_test_silent_var(struct unit_test_state *uts)
{
/* 'silent_linux' not set should do nothing */
env_set("silent_linux", NULL);
env_set("bootargs", CONSOLE_STR);
ut_assertok(bootm_process_cmdline_env(BOOTM_CL_SILENT));
ut_asserteq_str(CONSOLE_STR, env_get("bootargs"));
env_set("bootargs", NULL);
ut_assertok(bootm_process_cmdline_env(BOOTM_CL_SILENT));
ut_assertnull(env_get("bootargs"));
ut_assertok(env_set("silent_linux", "no"));
env_set("bootargs", CONSOLE_STR);
ut_assertok(bootm_process_cmdline_env(BOOTM_CL_SILENT));
ut_asserteq_str(CONSOLE_STR, env_get("bootargs"));
ut_assertok(env_set("silent_linux", "yes"));
env_set("bootargs", CONSOLE_STR);
ut_assertok(bootm_process_cmdline_env(BOOTM_CL_SILENT));
ut_asserteq_str("console=", env_get("bootargs"));
/* Empty buffer should still add the string */
env_set("bootargs", NULL);
ut_assertok(bootm_process_cmdline_env(BOOTM_CL_SILENT));
ut_asserteq_str("console=", env_get("bootargs"));
return 0;
}
BOOTM_TEST(bootm_test_silent_var, 0);
int do_ut_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
struct unit_test *tests = ll_entry_start(struct unit_test, bootm_test);
const int n_ents = ll_entry_count(struct unit_test, bootm_test);
return cmd_ut_category("bootm", "bootm_test_", tests, n_ents,
argc, argv);
}