loadm.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // 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. #include <common.h>
  12. #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. #define BUF_SIZE 0x100
  20. #define LOADM_TEST(_name, _flags) UNIT_TEST(_name, _flags, loadm_test)
  21. static int loadm_test_params(struct unit_test_state *uts)
  22. {
  23. ut_assertok(console_record_reset_enable());
  24. run_command("loadm", 0);
  25. ut_assert_nextline("loadm - load binary blob from source address to destination address");
  26. ut_assertok(console_record_reset_enable());
  27. run_command("loadm 0x12345678", 0);
  28. ut_assert_nextline("loadm - load binary blob from source address to destination address");
  29. ut_assertok(console_record_reset_enable());
  30. run_command("loadm 0x12345678 0x12345678", 0);
  31. ut_assert_nextline("loadm - load binary blob from source address to destination address");
  32. ut_assertok(console_record_reset_enable());
  33. run_command("loadm 0x12345678 0x12345678 0", 0);
  34. ut_assert_nextline("loadm: can not load zero bytes");
  35. return 0;
  36. }
  37. LOADM_TEST(loadm_test_params, UT_TESTF_CONSOLE_REC);
  38. static int loadm_test_load (struct unit_test_state *uts)
  39. {
  40. char *buf;
  41. buf = map_sysmem(0, BUF_SIZE);
  42. memset(buf, '\0', BUF_SIZE);
  43. memset(buf, 0xaa, BUF_SIZE / 2);
  44. ut_assertok(console_record_reset_enable());
  45. run_command("loadm 0x0 0x80 0x80", 0);
  46. ut_assert_nextline("loaded bin to memory: size: 128");
  47. unmap_sysmem(buf);
  48. return 0;
  49. }
  50. LOADM_TEST(loadm_test_load, UT_TESTF_CONSOLE_REC);
  51. int do_ut_loadm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
  52. {
  53. struct unit_test *tests = UNIT_TEST_SUITE_START(loadm_test);
  54. const int n_ents = UNIT_TEST_SUITE_COUNT(loadm_test);
  55. return cmd_ut_category("loadm", "loadm_test_", tests, n_ents, argc,
  56. argv);
  57. }