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