blob: dedb4f7683e677215eb22b237a94ae1ed138ee7e [file] [log] [blame]
Rui Miguel Silva433f15a2022-05-11 10:55:40 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Test for loadm command
4 *
5 * Copyright 2022 ARM Limited
6 * Copyright 2022 Linaro
7 *
8 * Authors:
9 * Rui Miguel Silva <rui.silva@linaro.org>
10 */
11
Rui Miguel Silva433f15a2022-05-11 10:55:40 +010012#include <console.h>
13#include <mapmem.h>
14#include <asm/global_data.h>
15#include <dm/test.h>
16#include <test/suites.h>
17#include <test/test.h>
18#include <test/ut.h>
19
20#define BUF_SIZE 0x100
21
22#define LOADM_TEST(_name, _flags) UNIT_TEST(_name, _flags, loadm_test)
23
24static int loadm_test_params(struct unit_test_state *uts)
25{
Rui Miguel Silva433f15a2022-05-11 10:55:40 +010026 run_command("loadm", 0);
27 ut_assert_nextline("loadm - load binary blob from source address to destination address");
28
29 ut_assertok(console_record_reset_enable());
30 run_command("loadm 0x12345678", 0);
31 ut_assert_nextline("loadm - load binary blob from source address to destination address");
32
33 ut_assertok(console_record_reset_enable());
34 run_command("loadm 0x12345678 0x12345678", 0);
35 ut_assert_nextline("loadm - load binary blob from source address to destination address");
36
37 ut_assertok(console_record_reset_enable());
38 run_command("loadm 0x12345678 0x12345678 0", 0);
39 ut_assert_nextline("loadm: can not load zero bytes");
40
41 return 0;
42}
Simon Glass11fcfa32024-08-22 07:57:50 -060043LOADM_TEST(loadm_test_params, UTF_CONSOLE);
Rui Miguel Silva433f15a2022-05-11 10:55:40 +010044
45static int loadm_test_load (struct unit_test_state *uts)
46{
47 char *buf;
48
49 buf = map_sysmem(0, BUF_SIZE);
50 memset(buf, '\0', BUF_SIZE);
51 memset(buf, 0xaa, BUF_SIZE / 2);
52
Rui Miguel Silva433f15a2022-05-11 10:55:40 +010053 run_command("loadm 0x0 0x80 0x80", 0);
54 ut_assert_nextline("loaded bin to memory: size: 128");
55
56 unmap_sysmem(buf);
57
58 return 0;
59}
Simon Glass11fcfa32024-08-22 07:57:50 -060060LOADM_TEST(loadm_test_load, UTF_CONSOLE);
Rui Miguel Silva433f15a2022-05-11 10:55:40 +010061
62int do_ut_loadm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
63{
64 struct unit_test *tests = UNIT_TEST_SUITE_START(loadm_test);
65 const int n_ents = UNIT_TEST_SUITE_COUNT(loadm_test);
66
67 return cmd_ut_category("loadm", "loadm_test_", tests, n_ents, argc,
68 argv);
69}