1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2012, The Chromium Authors
9 #if CONFIG_IS_ENABLED(EFI_LOADER) && !defined(API_BUILD)
12 #include <display_options.h>
15 #define FAKE_BUILD_TAG "jenkins-u-boot-denx_uboot_dm-master-build-aarch64" \
16 "and a lot more text to come"
18 /* Test efi_loader specific printing */
19 static void efi_ut_print(void)
21 #if CONFIG_IS_ENABLED(EFI_LOADER) && !defined(API_BUILD)
23 u8 buf
[sizeof(struct efi_device_path_sd_mmc_path
) +
24 sizeof(struct efi_device_path
)];
26 struct efi_device_path
*dp_end
;
27 struct efi_device_path_sd_mmc_path
*dp_sd
=
28 (struct efi_device_path_sd_mmc_path
*)pos
;
30 /* Create a device path for an SD card */
31 dp_sd
->dp
.type
= DEVICE_PATH_TYPE_MESSAGING_DEVICE
;
32 dp_sd
->dp
.sub_type
= DEVICE_PATH_SUB_TYPE_MSG_SD
;
33 dp_sd
->dp
.length
= sizeof(struct efi_device_path_sd_mmc_path
);
34 dp_sd
->slot_number
= 3;
35 pos
+= sizeof(struct efi_device_path_sd_mmc_path
);
37 dp_end
= (struct efi_device_path
*)pos
;
38 dp_end
->type
= DEVICE_PATH_TYPE_END
;
39 dp_end
->sub_type
= DEVICE_PATH_SUB_TYPE_END
;
40 dp_end
->length
= sizeof(struct efi_device_path
);
42 snprintf(str
, sizeof(str
), "_%pD_", buf
);
43 assert(!strcmp("_/SD(3)_", str
));
45 /* NULL device path */
46 snprintf(str
, sizeof(str
), "_%pD_", NULL
);
47 assert(!strcmp("_<NULL>_", str
));
51 static int do_ut_print(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
59 printf("%s: Testing print\n", __func__
);
61 snprintf(str
, sizeof(str
), "testing");
62 assert(!strcmp("testing", str
));
64 snprintf(str
, sizeof(str
), "testing but too long");
65 assert(!strcmp("testing b", str
));
67 snprintf(str
, 1, "testing none");
68 assert(!strcmp("", str
));
71 snprintf(str
, 0, "testing none");
74 sprintf(big_str
, "_%ls_", L
"foo");
75 assert(!strcmp("_foo_", big_str
));
77 /* Test the banner function */
78 s
= display_options_get_banner(true, str
, sizeof(str
));
80 assert(!strcmp("\n\nU-Boo\n\n", s
));
82 s
= display_options_get_banner(true, str
, 1);
84 assert(!strcmp("", s
));
86 s
= display_options_get_banner(true, str
, 2);
88 assert(!strcmp("\n", s
));
90 s
= display_options_get_banner(false, str
, sizeof(str
));
92 assert(!strcmp("U-Boot \n\n", s
));
94 /* Give it enough space for some of the version */
95 big_str_len
= strlen(version_string
) - 5;
96 s
= display_options_get_banner_priv(false, FAKE_BUILD_TAG
, big_str
,
99 assert(!strncmp(version_string
, s
, big_str_len
- 3));
100 assert(!strcmp("\n\n", s
+ big_str_len
- 3));
102 /* Give it enough space for the version and some of the build tag */
103 big_str_len
= strlen(version_string
) + 9 + 20;
104 s
= display_options_get_banner_priv(false, FAKE_BUILD_TAG
, big_str
,
106 assert(s
== big_str
);
107 len
= strlen(version_string
);
108 assert(!strncmp(version_string
, s
, len
));
109 assert(!strncmp(", Build: ", s
+ len
, 9));
110 assert(!strncmp(FAKE_BUILD_TAG
, s
+ 9 + len
, 12));
111 assert(!strcmp("\n\n", s
+ big_str_len
- 3));
113 /* Test efi_loader specific printing */
116 printf("%s: Everything went swimmingly\n", __func__
);
121 ut_print
, 1, 1, do_ut_print
,
122 "Very basic test of printf(), etc.",