print_ut.c 3.4 KB

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