print_ut.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2012, The Chromium Authors
  4. */
  5. #define DEBUG
  6. #include <common.h>
  7. #if defined(CONFIG_EFI_LOADER) && \
  8. !defined(CONFIG_SPL_BUILD) && !defined(API_BUILD)
  9. #include <efi_api.h>
  10. #endif
  11. #include <display_options.h>
  12. #include <version.h>
  13. #define FAKE_BUILD_TAG "jenkins-u-boot-denx_uboot_dm-master-build-aarch64" \
  14. "and a lot more text to come"
  15. /* Test efi_loader specific printing */
  16. static void efi_ut_print(void)
  17. {
  18. #if defined(CONFIG_EFI_LOADER) && \
  19. !defined(CONFIG_SPL_BUILD) && !defined(API_BUILD)
  20. char str[10];
  21. u8 buf[sizeof(struct efi_device_path_sd_mmc_path) +
  22. sizeof(struct efi_device_path)];
  23. u8 *pos = buf;
  24. struct efi_device_path *dp_end;
  25. struct efi_device_path_sd_mmc_path *dp_sd =
  26. (struct efi_device_path_sd_mmc_path *)pos;
  27. /* Create a device path for an SD card */
  28. dp_sd->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
  29. dp_sd->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_SD;
  30. dp_sd->dp.length = sizeof(struct efi_device_path_sd_mmc_path);
  31. dp_sd->slot_number = 3;
  32. pos += sizeof(struct efi_device_path_sd_mmc_path);
  33. /* Append end node */
  34. dp_end = (struct efi_device_path *)pos;
  35. dp_end->type = DEVICE_PATH_TYPE_END;
  36. dp_end->sub_type = DEVICE_PATH_SUB_TYPE_END;
  37. dp_end->length = sizeof(struct efi_device_path);
  38. snprintf(str, sizeof(str), "_%pD_", buf);
  39. assert(!strcmp("_/SD(3)_", str));
  40. /* NULL device path */
  41. snprintf(str, sizeof(str), "_%pD_", NULL);
  42. assert(!strcmp("_<NULL>_", str));
  43. #endif
  44. }
  45. static int do_ut_print(cmd_tbl_t *cmdtp, int flag, int argc,
  46. char *const argv[])
  47. {
  48. char big_str[400];
  49. int big_str_len;
  50. char str[10], *s;
  51. int len;
  52. printf("%s: Testing print\n", __func__);
  53. snprintf(str, sizeof(str), "testing");
  54. assert(!strcmp("testing", str));
  55. snprintf(str, sizeof(str), "testing but too long");
  56. assert(!strcmp("testing b", str));
  57. snprintf(str, 1, "testing none");
  58. assert(!strcmp("", str));
  59. *str = 'x';
  60. snprintf(str, 0, "testing none");
  61. assert(*str == 'x');
  62. sprintf(big_str, "_%ls_", L"foo");
  63. assert(!strcmp("_foo_", big_str));
  64. /* Test the banner function */
  65. s = display_options_get_banner(true, str, sizeof(str));
  66. assert(s == str);
  67. assert(!strcmp("\n\nU-Boo\n\n", s));
  68. s = display_options_get_banner(true, str, 1);
  69. assert(s == str);
  70. assert(!strcmp("", s));
  71. s = display_options_get_banner(true, str, 2);
  72. assert(s == str);
  73. assert(!strcmp("\n", s));
  74. s = display_options_get_banner(false, str, sizeof(str));
  75. assert(s == str);
  76. assert(!strcmp("U-Boot \n\n", s));
  77. /* Give it enough space for some of the version */
  78. big_str_len = strlen(version_string) - 5;
  79. s = display_options_get_banner_priv(false, FAKE_BUILD_TAG, big_str,
  80. big_str_len);
  81. assert(s == big_str);
  82. assert(!strncmp(version_string, s, big_str_len - 3));
  83. assert(!strcmp("\n\n", s + big_str_len - 3));
  84. /* Give it enough space for the version and some of the build tag */
  85. big_str_len = strlen(version_string) + 9 + 20;
  86. s = display_options_get_banner_priv(false, FAKE_BUILD_TAG, big_str,
  87. big_str_len);
  88. assert(s == big_str);
  89. len = strlen(version_string);
  90. assert(!strncmp(version_string, s, len));
  91. assert(!strncmp(", Build: ", s + len, 9));
  92. assert(!strncmp(FAKE_BUILD_TAG, s + 9 + len, 12));
  93. assert(!strcmp("\n\n", s + big_str_len - 3));
  94. /* Test efi_loader specific printing */
  95. efi_ut_print();
  96. printf("%s: Everything went swimmingly\n", __func__);
  97. return 0;
  98. }
  99. U_BOOT_CMD(
  100. ut_print, 1, 1, do_ut_print,
  101. "Very basic test of printf(), etc.",
  102. ""
  103. );