2 * Copyright (c) 2012, The Chromium Authors
4 * SPDX-License-Identifier: GPL-2.0+
10 #if defined(CONFIG_EFI_LOADER) && \
11 !defined(CONFIG_SPL_BUILD) && !defined(API_BUILD)
14 #include <display_options.h>
17 #define FAKE_BUILD_TAG "jenkins-u-boot-denx_uboot_dm-master-build-aarch64" \
18 "and a lot more text to come"
20 /* Test efi_loader specific printing */
21 static void efi_ut_print(void)
23 #if defined(CONFIG_EFI_LOADER) && \
24 !defined(CONFIG_SPL_BUILD) && !defined(API_BUILD)
26 u8 buf
[sizeof(struct efi_device_path_sd_mmc_path
) +
27 sizeof(struct efi_device_path
)];
29 struct efi_device_path
*dp_end
;
30 struct efi_device_path_sd_mmc_path
*dp_sd
=
31 (struct efi_device_path_sd_mmc_path
*)pos
;
33 /* Create a device path for an SD card */
34 dp_sd
->dp
.type
= DEVICE_PATH_TYPE_MESSAGING_DEVICE
;
35 dp_sd
->dp
.sub_type
= DEVICE_PATH_SUB_TYPE_MSG_SD
;
36 dp_sd
->dp
.length
= sizeof(struct efi_device_path_sd_mmc_path
);
37 dp_sd
->slot_number
= 3;
38 pos
+= sizeof(struct efi_device_path_sd_mmc_path
);
40 dp_end
= (struct efi_device_path
*)pos
;
41 dp_end
->type
= DEVICE_PATH_TYPE_END
;
42 dp_end
->sub_type
= DEVICE_PATH_SUB_TYPE_END
;
43 dp_end
->length
= sizeof(struct efi_device_path
);
45 snprintf(str
, sizeof(str
), "_%pD_", buf
);
46 assert(!strcmp("_/SD(3)_", str
));
50 static int do_ut_print(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
58 printf("%s: Testing print\n", __func__
);
60 snprintf(str
, sizeof(str
), "testing");
61 assert(!strcmp("testing", str
));
63 snprintf(str
, sizeof(str
), "testing but too long");
64 assert(!strcmp("testing b", str
));
66 snprintf(str
, 1, "testing none");
67 assert(!strcmp("", str
));
70 snprintf(str
, 0, "testing none");
73 sprintf(big_str
, "_%ls_", L
"foo");
74 assert(!strcmp("_foo_", big_str
));
76 /* Test the banner function */
77 s
= display_options_get_banner(true, str
, sizeof(str
));
79 assert(!strcmp("\n\nU-Boo\n\n", s
));
81 s
= display_options_get_banner(true, str
, 1);
83 assert(!strcmp("", s
));
85 s
= display_options_get_banner(true, str
, 2);
87 assert(!strcmp("\n", s
));
89 s
= display_options_get_banner(false, str
, sizeof(str
));
91 assert(!strcmp("U-Boot \n\n", s
));
93 /* Give it enough space for some of the version */
94 big_str_len
= strlen(version_string
) - 5;
95 s
= display_options_get_banner_priv(false, FAKE_BUILD_TAG
, big_str
,
98 assert(!strncmp(version_string
, s
, big_str_len
- 3));
99 assert(!strcmp("\n\n", s
+ big_str_len
- 3));
101 /* Give it enough space for the version and some of the build tag */
102 big_str_len
= strlen(version_string
) + 9 + 20;
103 s
= display_options_get_banner_priv(false, FAKE_BUILD_TAG
, big_str
,
105 assert(s
== big_str
);
106 len
= strlen(version_string
);
107 assert(!strncmp(version_string
, s
, len
));
108 assert(!strncmp(", Build: ", s
+ len
, 9));
109 assert(!strncmp(FAKE_BUILD_TAG
, s
+ 9 + len
, 12));
110 assert(!strcmp("\n\n", s
+ big_str_len
- 3));
112 /* Test efi_loader specific printing */
115 printf("%s: Everything went swimmingly\n", __func__
);
120 ut_print
, 1, 1, do_ut_print
,
121 "Very basic test of printf(), etc.",