1
2
3
4
5
6
7
8#include <common.h>
9#include <bzlib.h>
10#include <dm.h>
11#include <mapmem.h>
12#include <os.h>
13#include <video.h>
14#include <video_console.h>
15#include <dm/test.h>
16#include <dm/uclass-internal.h>
17#include <test/ut.h>
18
19
20
21
22
23
24
25
26
27DECLARE_GLOBAL_DATA_PTR;
28
29
30static int dm_test_video_base(struct unit_test_state *uts)
31{
32 struct video_priv *priv;
33 struct udevice *dev;
34
35 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
36 ut_asserteq(1366, video_get_xsize(dev));
37 ut_asserteq(768, video_get_ysize(dev));
38 priv = dev_get_uclass_priv(dev);
39 ut_asserteq(priv->fb_size, 1366 * 768 * 2);
40
41 return 0;
42}
43DM_TEST(dm_test_video_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58static int compress_frame_buffer(struct udevice *dev)
59{
60 struct video_priv *priv = dev_get_uclass_priv(dev);
61 uint destlen;
62 void *dest;
63 int ret;
64
65 destlen = priv->fb_size;
66 dest = malloc(priv->fb_size);
67 if (!dest)
68 return -ENOMEM;
69 ret = BZ2_bzBuffToBuffCompress(dest, &destlen,
70 priv->fb, priv->fb_size,
71 3, 0, 0);
72 free(dest);
73 if (ret)
74 return ret;
75
76 return destlen;
77}
78
79
80
81
82
83static void __maybe_unused see_output(void)
84{
85 video_sync_all();
86 while (1);
87}
88
89
90static int select_vidconsole(struct unit_test_state *uts, const char *drv_name)
91{
92 struct sandbox_sdl_plat *plat;
93 struct udevice *dev;
94
95 ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
96 ut_assert(!device_active(dev));
97 plat = dev_get_platdata(dev);
98 plat->vidconsole_drv_name = "vidconsole0";
99
100 return 0;
101}
102
103
104static int dm_test_video_text(struct unit_test_state *uts)
105{
106 struct udevice *dev, *con;
107 int i;
108
109#define WHITE 0xffff
110#define SCROLL_LINES 100
111
112 ut_assertok(select_vidconsole(uts, "vidconsole0"));
113 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
114 ut_asserteq(46, compress_frame_buffer(dev));
115
116 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
117 vidconsole_putc_xy(con, 0, 0, 'a');
118 ut_asserteq(79, compress_frame_buffer(dev));
119
120 vidconsole_putc_xy(con, 0, 0, ' ');
121 ut_asserteq(46, compress_frame_buffer(dev));
122
123 for (i = 0; i < 20; i++)
124 vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
125 ut_asserteq(273, compress_frame_buffer(dev));
126
127 vidconsole_set_row(con, 0, WHITE);
128 ut_asserteq(46, compress_frame_buffer(dev));
129
130 for (i = 0; i < 20; i++)
131 vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
132 ut_asserteq(273, compress_frame_buffer(dev));
133
134 return 0;
135}
136DM_TEST(dm_test_video_text, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
137
138
139static int dm_test_video_chars(struct unit_test_state *uts)
140{
141 struct udevice *dev, *con;
142 const char *test_string = "Well\b\b\b\bxhe is\r \n\ta very \amodest \bman\n\t\tand Has much to\b\bto be modest about.";
143 const char *s;
144
145 ut_assertok(select_vidconsole(uts, "vidconsole0"));
146 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
147 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
148 for (s = test_string; *s; s++)
149 vidconsole_put_char(con, *s);
150 ut_asserteq(466, compress_frame_buffer(dev));
151
152 return 0;
153}
154DM_TEST(dm_test_video_chars, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
155
156
157
158
159
160
161
162
163
164
165static int check_vidconsole_output(struct unit_test_state *uts, int rot,
166 int wrap_size, int scroll_size)
167{
168 struct udevice *dev, *con;
169 struct sandbox_sdl_plat *plat;
170 int i;
171
172 ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
173 ut_assert(!device_active(dev));
174 plat = dev_get_platdata(dev);
175 plat->rot = rot;
176
177 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
178 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
179 ut_asserteq(46, compress_frame_buffer(dev));
180
181
182 for (i = 0; i < 120; i++)
183 vidconsole_put_char(con, 'A' + i % 50);
184 ut_asserteq(wrap_size, compress_frame_buffer(dev));
185
186
187 for (i = 0; i < SCROLL_LINES; i++) {
188 vidconsole_put_char(con, 'A' + i % 50);
189 vidconsole_put_char(con, '\n');
190 }
191 ut_asserteq(scroll_size, compress_frame_buffer(dev));
192
193
194 for (i = 0; i < SCROLL_LINES; i++)
195 vidconsole_put_char(con, '\n');
196 ut_asserteq(46, compress_frame_buffer(dev));
197
198 return 0;
199}
200
201
202static int dm_test_video_context(struct unit_test_state *uts)
203{
204 ut_assertok(select_vidconsole(uts, "vidconsole0"));
205 ut_assertok(check_vidconsole_output(uts, 0, 788, 453));
206
207 return 0;
208}
209DM_TEST(dm_test_video_context, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
210
211
212static int dm_test_video_rotation1(struct unit_test_state *uts)
213{
214 ut_assertok(check_vidconsole_output(uts, 1, 1112, 680));
215
216 return 0;
217}
218DM_TEST(dm_test_video_rotation1, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
219
220
221static int dm_test_video_rotation2(struct unit_test_state *uts)
222{
223 ut_assertok(check_vidconsole_output(uts, 2, 785, 446));
224
225 return 0;
226}
227DM_TEST(dm_test_video_rotation2, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
228
229
230static int dm_test_video_rotation3(struct unit_test_state *uts)
231{
232 ut_assertok(check_vidconsole_output(uts, 3, 1134, 681));
233
234 return 0;
235}
236DM_TEST(dm_test_video_rotation3, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
237
238
239static int read_file(struct unit_test_state *uts, const char *fname,
240 ulong *addrp)
241{
242 int buf_size = 100000;
243 ulong addr = 0;
244 int size, fd;
245 char *buf;
246
247 buf = map_sysmem(addr, 0);
248 ut_assert(buf != NULL);
249 fd = os_open(fname, OS_O_RDONLY);
250 ut_assert(fd >= 0);
251 size = os_read(fd, buf, buf_size);
252 os_close(fd);
253 ut_assert(size >= 0);
254 ut_assert(size < buf_size);
255 *addrp = addr;
256
257 return 0;
258}
259
260
261static int dm_test_video_bmp(struct unit_test_state *uts)
262{
263 struct udevice *dev;
264 ulong addr;
265
266 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
267 ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
268
269 ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
270 ut_asserteq(1368, compress_frame_buffer(dev));
271
272 return 0;
273}
274DM_TEST(dm_test_video_bmp, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
275
276
277static int dm_test_video_bmp_comp(struct unit_test_state *uts)
278{
279 struct udevice *dev;
280 ulong addr;
281
282 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
283 ut_assertok(read_file(uts, "tools/logos/denx-comp.bmp", &addr));
284
285 ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
286 ut_asserteq(1368, compress_frame_buffer(dev));
287
288 return 0;
289}
290DM_TEST(dm_test_video_bmp_comp, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
291
292
293static int dm_test_video_truetype(struct unit_test_state *uts)
294{
295 struct udevice *dev, *con;
296 const char *test_string = "Criticism may not be agreeable, but it is necessary. It fulfils the same function as pain in the human body. It calls attention to an unhealthy state of things. Some see private enterprise as a predatory target to be shot, others as a cow to be milked, but few are those who see it as a sturdy horse pulling the wagon. The \aprice OF\b\bof greatness\n\tis responsibility.\n\nBye";
297 const char *s;
298
299 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
300 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
301 for (s = test_string; *s; s++)
302 vidconsole_put_char(con, *s);
303 ut_asserteq(12619, compress_frame_buffer(dev));
304
305 return 0;
306}
307DM_TEST(dm_test_video_truetype, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
308
309
310static int dm_test_video_truetype_scroll(struct unit_test_state *uts)
311{
312 struct sandbox_sdl_plat *plat;
313 struct udevice *dev, *con;
314 const char *test_string = "Criticism may not be agreeable, but it is necessary. It fulfils the same function as pain in the human body. It calls attention to an unhealthy state of things. Some see private enterprise as a predatory target to be shot, others as a cow to be milked, but few are those who see it as a sturdy horse pulling the wagon. The \aprice OF\b\bof greatness\n\tis responsibility.\n\nBye";
315 const char *s;
316
317 ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
318 ut_assert(!device_active(dev));
319 plat = dev_get_platdata(dev);
320 plat->font_size = 100;
321
322 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
323 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
324 for (s = test_string; *s; s++)
325 vidconsole_put_char(con, *s);
326 ut_asserteq(33849, compress_frame_buffer(dev));
327
328 return 0;
329}
330DM_TEST(dm_test_video_truetype_scroll, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
331
332
333static int dm_test_video_truetype_bs(struct unit_test_state *uts)
334{
335 struct sandbox_sdl_plat *plat;
336 struct udevice *dev, *con;
337 const char *test_string = "...Criticism may or may\b\b\b\b\b\bnot be agreeable, but seldom it is necessary\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bit is necessary. It fulfils the same function as pain in the human body. It calls attention to an unhealthy state of things.";
338 const char *s;
339
340 ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
341 ut_assert(!device_active(dev));
342 plat = dev_get_platdata(dev);
343 plat->font_size = 100;
344
345 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
346 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
347 for (s = test_string; *s; s++)
348 vidconsole_put_char(con, *s);
349 ut_asserteq(34871, compress_frame_buffer(dev));
350
351 return 0;
352}
353DM_TEST(dm_test_video_truetype_bs, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
354