print_ut.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #include <display_options.h>
  9. #include <version.h>
  10. #define FAKE_BUILD_TAG "jenkins-u-boot-denx_uboot_dm-master-build-aarch64" \
  11. "and a lot more text to come"
  12. static int do_ut_print(cmd_tbl_t *cmdtp, int flag, int argc,
  13. char *const argv[])
  14. {
  15. char big_str[400];
  16. int big_str_len;
  17. char str[10], *s;
  18. int len;
  19. printf("%s: Testing print\n", __func__);
  20. snprintf(str, sizeof(str), "testing");
  21. assert(!strcmp("testing", str));
  22. snprintf(str, sizeof(str), "testing but too long");
  23. assert(!strcmp("testing b", str));
  24. snprintf(str, 1, "testing none");
  25. assert(!strcmp("", str));
  26. *str = 'x';
  27. snprintf(str, 0, "testing none");
  28. assert(*str == 'x');
  29. /* Test the banner function */
  30. s = display_options_get_banner(true, str, sizeof(str));
  31. assert(s == str);
  32. assert(!strcmp("\n\nU-Boo\n\n", s));
  33. s = display_options_get_banner(true, str, 1);
  34. assert(s == str);
  35. assert(!strcmp("", s));
  36. s = display_options_get_banner(true, str, 2);
  37. assert(s == str);
  38. assert(!strcmp("\n", s));
  39. s = display_options_get_banner(false, str, sizeof(str));
  40. assert(s == str);
  41. assert(!strcmp("U-Boot \n\n", s));
  42. /* Give it enough space for some of the version */
  43. big_str_len = strlen(version_string) - 5;
  44. s = display_options_get_banner_priv(false, FAKE_BUILD_TAG, big_str,
  45. big_str_len);
  46. assert(s == big_str);
  47. assert(!strncmp(version_string, s, big_str_len - 3));
  48. assert(!strcmp("\n\n", s + big_str_len - 3));
  49. /* Give it enough space for the version and some of the build tag */
  50. big_str_len = strlen(version_string) + 9 + 20;
  51. s = display_options_get_banner_priv(false, FAKE_BUILD_TAG, big_str,
  52. big_str_len);
  53. assert(s == big_str);
  54. len = strlen(version_string);
  55. assert(!strncmp(version_string, s, len));
  56. assert(!strncmp(", Build: ", s + len, 9));
  57. assert(!strncmp(FAKE_BUILD_TAG, s + 9 + len, 12));
  58. assert(!strcmp("\n\n", s + big_str_len - 3));
  59. printf("%s: Everything went swimmingly\n", __func__);
  60. return 0;
  61. }
  62. U_BOOT_CMD(
  63. ut_print, 1, 1, do_ut_print,
  64. "Very basic test of printf(), etc.",
  65. ""
  66. );