Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012, The Chromium Authors |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #define DEBUG |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <display_options.h> |
| 11 | #include <version.h> |
| 12 | |
| 13 | #define FAKE_BUILD_TAG "jenkins-u-boot-denx_uboot_dm-master-build-aarch64" \ |
| 14 | "and a lot more text to come" |
| 15 | |
| 16 | static int do_ut_print(cmd_tbl_t *cmdtp, int flag, int argc, |
| 17 | char *const argv[]) |
| 18 | { |
| 19 | char big_str[400]; |
| 20 | int big_str_len; |
| 21 | char str[10], *s; |
| 22 | int len; |
| 23 | |
| 24 | printf("%s: Testing print\n", __func__); |
| 25 | |
| 26 | snprintf(str, sizeof(str), "testing"); |
| 27 | assert(!strcmp("testing", str)); |
| 28 | |
| 29 | snprintf(str, sizeof(str), "testing but too long"); |
| 30 | assert(!strcmp("testing b", str)); |
| 31 | |
| 32 | snprintf(str, 1, "testing none"); |
| 33 | assert(!strcmp("", str)); |
| 34 | |
| 35 | *str = 'x'; |
| 36 | snprintf(str, 0, "testing none"); |
| 37 | assert(*str == 'x'); |
| 38 | |
Rob Clark | 22ae0a7 | 2017-09-13 18:46:54 -0400 | [diff] [blame] | 39 | sprintf(big_str, "_%ls_", L"foo"); |
| 40 | assert(!strcmp("_foo_", big_str)); |
| 41 | |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 42 | /* Test the banner function */ |
| 43 | s = display_options_get_banner(true, str, sizeof(str)); |
| 44 | assert(s == str); |
| 45 | assert(!strcmp("\n\nU-Boo\n\n", s)); |
| 46 | |
| 47 | s = display_options_get_banner(true, str, 1); |
| 48 | assert(s == str); |
| 49 | assert(!strcmp("", s)); |
| 50 | |
| 51 | s = display_options_get_banner(true, str, 2); |
| 52 | assert(s == str); |
| 53 | assert(!strcmp("\n", s)); |
| 54 | |
| 55 | s = display_options_get_banner(false, str, sizeof(str)); |
| 56 | assert(s == str); |
| 57 | assert(!strcmp("U-Boot \n\n", s)); |
| 58 | |
| 59 | /* Give it enough space for some of the version */ |
| 60 | big_str_len = strlen(version_string) - 5; |
| 61 | s = display_options_get_banner_priv(false, FAKE_BUILD_TAG, big_str, |
| 62 | big_str_len); |
| 63 | assert(s == big_str); |
| 64 | assert(!strncmp(version_string, s, big_str_len - 3)); |
| 65 | assert(!strcmp("\n\n", s + big_str_len - 3)); |
| 66 | |
| 67 | /* Give it enough space for the version and some of the build tag */ |
| 68 | big_str_len = strlen(version_string) + 9 + 20; |
| 69 | s = display_options_get_banner_priv(false, FAKE_BUILD_TAG, big_str, |
| 70 | big_str_len); |
| 71 | assert(s == big_str); |
| 72 | len = strlen(version_string); |
| 73 | assert(!strncmp(version_string, s, len)); |
| 74 | assert(!strncmp(", Build: ", s + len, 9)); |
| 75 | assert(!strncmp(FAKE_BUILD_TAG, s + 9 + len, 12)); |
| 76 | assert(!strcmp("\n\n", s + big_str_len - 3)); |
| 77 | |
| 78 | printf("%s: Everything went swimmingly\n", __func__); |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | U_BOOT_CMD( |
| 83 | ut_print, 1, 1, do_ut_print, |
| 84 | "Very basic test of printf(), etc.", |
| 85 | "" |
| 86 | ); |