]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
3c97c4fb SG |
2 | /* |
3 | * Copyright (c) 2014 Google, Inc | |
4 | * Written by Simon Glass <[email protected]> | |
3c97c4fb SG |
5 | */ |
6 | ||
7 | #include <common.h> | |
8 | #include <bzlib.h> | |
9 | #include <dm.h> | |
c1cad06f | 10 | #include <gzip.h> |
f7ae49fc | 11 | #include <log.h> |
336d4615 | 12 | #include <malloc.h> |
3c97c4fb SG |
13 | #include <mapmem.h> |
14 | #include <os.h> | |
15 | #include <video.h> | |
16 | #include <video_console.h> | |
8657ad43 | 17 | #include <asm/test.h> |
3c97c4fb SG |
18 | #include <dm/test.h> |
19 | #include <dm/uclass-internal.h> | |
0e1fad43 | 20 | #include <test/test.h> |
3c97c4fb SG |
21 | #include <test/ut.h> |
22 | ||
23 | /* | |
24 | * These tests use the standard sandbox frame buffer, the resolution of which | |
25 | * is defined in the device tree. This only supports 16bpp so the tests only | |
26 | * test that code path. It would be possible to adjust this fairly easily, | |
27 | * by adjusting the bpix value in struct sandbox_sdl_plat. However the code | |
28 | * in sandbox_sdl_sync() would also need to change to handle the different | |
29 | * surface depth. | |
30 | */ | |
3c97c4fb SG |
31 | /* Basic test of the video uclass */ |
32 | static int dm_test_video_base(struct unit_test_state *uts) | |
33 | { | |
34 | struct video_priv *priv; | |
35 | struct udevice *dev; | |
36 | ||
37 | ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev)); | |
38 | ut_asserteq(1366, video_get_xsize(dev)); | |
39 | ut_asserteq(768, video_get_ysize(dev)); | |
40 | priv = dev_get_uclass_priv(dev); | |
41 | ut_asserteq(priv->fb_size, 1366 * 768 * 2); | |
42 | ||
43 | return 0; | |
44 | } | |
e180c2b1 | 45 | DM_TEST(dm_test_video_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
3c97c4fb SG |
46 | |
47 | /** | |
48 | * compress_frame_buffer() - Compress the frame buffer and return its size | |
49 | * | |
50 | * We want to write tests which perform operations on the video console and | |
51 | * check that the frame buffer ends up with the correct contents. But it is | |
52 | * painful to store 'known good' images for comparison with the frame | |
53 | * buffer. As an alternative, we can compress the frame buffer and check the | |
54 | * size of the compressed data. This provides a pretty good level of | |
55 | * certainty and the resulting tests need only check a single value. | |
56 | * | |
f578ca79 SG |
57 | * If the copy framebuffer is enabled, this compares it to the main framebuffer |
58 | * too. | |
59 | * | |
60 | * @uts: Test state | |
3c97c4fb SG |
61 | * @dev: Video device |
62 | * @return compressed size of the frame buffer, or -ve on error | |
63 | */ | |
f578ca79 SG |
64 | static int compress_frame_buffer(struct unit_test_state *uts, |
65 | struct udevice *dev) | |
3c97c4fb SG |
66 | { |
67 | struct video_priv *priv = dev_get_uclass_priv(dev); | |
f578ca79 | 68 | struct video_priv *uc_priv = dev_get_uclass_priv(dev); |
3c97c4fb SG |
69 | uint destlen; |
70 | void *dest; | |
71 | int ret; | |
72 | ||
73 | destlen = priv->fb_size; | |
74 | dest = malloc(priv->fb_size); | |
75 | if (!dest) | |
76 | return -ENOMEM; | |
77 | ret = BZ2_bzBuffToBuffCompress(dest, &destlen, | |
78 | priv->fb, priv->fb_size, | |
79 | 3, 0, 0); | |
80 | free(dest); | |
81 | if (ret) | |
82 | return ret; | |
83 | ||
f578ca79 SG |
84 | /* Check here that the copy frame buffer is working correctly */ |
85 | if (IS_ENABLED(CONFIG_VIDEO_COPY)) { | |
86 | ut_assertf(!memcmp(uc_priv->fb, uc_priv->copy_fb, | |
87 | uc_priv->fb_size), | |
88 | "Copy framebuffer does not match fb"); | |
89 | } | |
90 | ||
3c97c4fb SG |
91 | return destlen; |
92 | } | |
93 | ||
94 | /* | |
95 | * Call this function at any point to halt and show the current display. Be | |
96 | * sure to run the test with the -l flag. | |
97 | */ | |
98 | static void __maybe_unused see_output(void) | |
99 | { | |
100 | video_sync_all(); | |
101 | while (1); | |
102 | } | |
103 | ||
8df8dad5 SG |
104 | /* Select the video console driver to use for a video device */ |
105 | static int select_vidconsole(struct unit_test_state *uts, const char *drv_name) | |
106 | { | |
107 | struct sandbox_sdl_plat *plat; | |
108 | struct udevice *dev; | |
109 | ||
110 | ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev)); | |
111 | ut_assert(!device_active(dev)); | |
c69cda25 | 112 | plat = dev_get_plat(dev); |
8df8dad5 SG |
113 | plat->vidconsole_drv_name = "vidconsole0"; |
114 | ||
115 | return 0; | |
116 | } | |
117 | ||
3c97c4fb SG |
118 | /* Test text output works on the video console */ |
119 | static int dm_test_video_text(struct unit_test_state *uts) | |
120 | { | |
121 | struct udevice *dev, *con; | |
122 | int i; | |
123 | ||
124 | #define WHITE 0xffff | |
125 | #define SCROLL_LINES 100 | |
126 | ||
8df8dad5 | 127 | ut_assertok(select_vidconsole(uts, "vidconsole0")); |
3c97c4fb | 128 | ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev)); |
f578ca79 | 129 | ut_asserteq(46, compress_frame_buffer(uts, dev)); |
3c97c4fb SG |
130 | |
131 | ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); | |
132 | vidconsole_putc_xy(con, 0, 0, 'a'); | |
f578ca79 | 133 | ut_asserteq(79, compress_frame_buffer(uts, dev)); |
3c97c4fb SG |
134 | |
135 | vidconsole_putc_xy(con, 0, 0, ' '); | |
f578ca79 | 136 | ut_asserteq(46, compress_frame_buffer(uts, dev)); |
3c97c4fb SG |
137 | |
138 | for (i = 0; i < 20; i++) | |
f2661786 | 139 | vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i); |
f578ca79 | 140 | ut_asserteq(273, compress_frame_buffer(uts, dev)); |
3c97c4fb SG |
141 | |
142 | vidconsole_set_row(con, 0, WHITE); | |
f578ca79 | 143 | ut_asserteq(46, compress_frame_buffer(uts, dev)); |
3c97c4fb SG |
144 | |
145 | for (i = 0; i < 20; i++) | |
f2661786 | 146 | vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i); |
f578ca79 | 147 | ut_asserteq(273, compress_frame_buffer(uts, dev)); |
3c97c4fb SG |
148 | |
149 | return 0; | |
150 | } | |
e180c2b1 | 151 | DM_TEST(dm_test_video_text, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
3c97c4fb SG |
152 | |
153 | /* Test handling of special characters in the console */ | |
154 | static int dm_test_video_chars(struct unit_test_state *uts) | |
155 | { | |
156 | struct udevice *dev, *con; | |
5508f10a | 157 | 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."; |
3c97c4fb | 158 | |
8df8dad5 | 159 | ut_assertok(select_vidconsole(uts, "vidconsole0")); |
3c97c4fb SG |
160 | ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev)); |
161 | ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); | |
a7495ac8 | 162 | vidconsole_put_string(con, test_string); |
f578ca79 | 163 | ut_asserteq(466, compress_frame_buffer(uts, dev)); |
3c97c4fb SG |
164 | |
165 | return 0; | |
166 | } | |
e180c2b1 | 167 | DM_TEST(dm_test_video_chars, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
3c97c4fb | 168 | |
40186ee2 RC |
169 | #ifdef CONFIG_VIDEO_ANSI |
170 | #define ANSI_ESC "\x1b" | |
171 | /* Test handling of ANSI escape sequences */ | |
172 | static int dm_test_video_ansi(struct unit_test_state *uts) | |
173 | { | |
174 | struct udevice *dev, *con; | |
175 | ||
176 | ut_assertok(select_vidconsole(uts, "vidconsole0")); | |
177 | ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev)); | |
178 | ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); | |
179 | ||
180 | /* reference clear: */ | |
181 | video_clear(con->parent); | |
55d39911 | 182 | video_sync(con->parent, false); |
f578ca79 | 183 | ut_asserteq(46, compress_frame_buffer(uts, dev)); |
40186ee2 RC |
184 | |
185 | /* test clear escape sequence: [2J */ | |
186 | vidconsole_put_string(con, "A\tB\tC"ANSI_ESC"[2J"); | |
f578ca79 | 187 | ut_asserteq(46, compress_frame_buffer(uts, dev)); |
40186ee2 RC |
188 | |
189 | /* test set-cursor: [%d;%df */ | |
190 | vidconsole_put_string(con, "abc"ANSI_ESC"[2;2fab"ANSI_ESC"[4;4fcd"); | |
f578ca79 | 191 | ut_asserteq(143, compress_frame_buffer(uts, dev)); |
40186ee2 RC |
192 | |
193 | /* test colors (30-37 fg color, 40-47 bg color) */ | |
194 | vidconsole_put_string(con, ANSI_ESC"[30;41mfoo"); /* black on red */ | |
195 | vidconsole_put_string(con, ANSI_ESC"[33;44mbar"); /* yellow on blue */ | |
f578ca79 | 196 | ut_asserteq(272, compress_frame_buffer(uts, dev)); |
40186ee2 RC |
197 | |
198 | return 0; | |
199 | } | |
e180c2b1 | 200 | DM_TEST(dm_test_video_ansi, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
40186ee2 RC |
201 | #endif |
202 | ||
3c97c4fb SG |
203 | /** |
204 | * check_vidconsole_output() - Run a text console test | |
205 | * | |
206 | * @uts: Test state | |
ef453129 SG |
207 | * @rot: Console rotation (0=normal orientation, 1=90 degrees clockwise, |
208 | * 2=upside down, 3=90 degree counterclockwise) | |
3c97c4fb SG |
209 | * @wrap_size: Expected size of compressed frame buffer for the wrap test |
210 | * @scroll_size: Same for the scroll test | |
211 | * @return 0 on success | |
212 | */ | |
213 | static int check_vidconsole_output(struct unit_test_state *uts, int rot, | |
214 | int wrap_size, int scroll_size) | |
215 | { | |
216 | struct udevice *dev, *con; | |
217 | struct sandbox_sdl_plat *plat; | |
218 | int i; | |
219 | ||
220 | ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev)); | |
221 | ut_assert(!device_active(dev)); | |
c69cda25 | 222 | plat = dev_get_plat(dev); |
3c97c4fb SG |
223 | plat->rot = rot; |
224 | ||
225 | ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev)); | |
226 | ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); | |
f578ca79 | 227 | ut_asserteq(46, compress_frame_buffer(uts, dev)); |
3c97c4fb SG |
228 | |
229 | /* Check display wrap */ | |
230 | for (i = 0; i < 120; i++) | |
231 | vidconsole_put_char(con, 'A' + i % 50); | |
f578ca79 | 232 | ut_asserteq(wrap_size, compress_frame_buffer(uts, dev)); |
3c97c4fb SG |
233 | |
234 | /* Check display scrolling */ | |
235 | for (i = 0; i < SCROLL_LINES; i++) { | |
236 | vidconsole_put_char(con, 'A' + i % 50); | |
237 | vidconsole_put_char(con, '\n'); | |
238 | } | |
f578ca79 | 239 | ut_asserteq(scroll_size, compress_frame_buffer(uts, dev)); |
3c97c4fb SG |
240 | |
241 | /* If we scroll enough, the screen becomes blank again */ | |
242 | for (i = 0; i < SCROLL_LINES; i++) | |
243 | vidconsole_put_char(con, '\n'); | |
f578ca79 | 244 | ut_asserteq(46, compress_frame_buffer(uts, dev)); |
3c97c4fb SG |
245 | |
246 | return 0; | |
247 | } | |
248 | ||
249 | /* Test text output through the console uclass */ | |
250 | static int dm_test_video_context(struct unit_test_state *uts) | |
251 | { | |
8df8dad5 SG |
252 | ut_assertok(select_vidconsole(uts, "vidconsole0")); |
253 | ut_assertok(check_vidconsole_output(uts, 0, 788, 453)); | |
254 | ||
255 | return 0; | |
3c97c4fb | 256 | } |
e180c2b1 | 257 | DM_TEST(dm_test_video_context, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
85e08db8 SG |
258 | |
259 | /* Test rotated text output through the console uclass */ | |
260 | static int dm_test_video_rotation1(struct unit_test_state *uts) | |
261 | { | |
262 | ut_assertok(check_vidconsole_output(uts, 1, 1112, 680)); | |
263 | ||
264 | return 0; | |
265 | } | |
e180c2b1 | 266 | DM_TEST(dm_test_video_rotation1, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
85e08db8 SG |
267 | |
268 | /* Test rotated text output through the console uclass */ | |
269 | static int dm_test_video_rotation2(struct unit_test_state *uts) | |
270 | { | |
9beb364a | 271 | ut_assertok(check_vidconsole_output(uts, 2, 783, 445)); |
85e08db8 SG |
272 | |
273 | return 0; | |
274 | } | |
e180c2b1 | 275 | DM_TEST(dm_test_video_rotation2, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
85e08db8 SG |
276 | |
277 | /* Test rotated text output through the console uclass */ | |
278 | static int dm_test_video_rotation3(struct unit_test_state *uts) | |
279 | { | |
280 | ut_assertok(check_vidconsole_output(uts, 3, 1134, 681)); | |
281 | ||
282 | return 0; | |
283 | } | |
e180c2b1 | 284 | DM_TEST(dm_test_video_rotation3, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
747440d0 SG |
285 | |
286 | /* Read a file into memory and return a pointer to it */ | |
287 | static int read_file(struct unit_test_state *uts, const char *fname, | |
288 | ulong *addrp) | |
289 | { | |
290 | int buf_size = 100000; | |
291 | ulong addr = 0; | |
292 | int size, fd; | |
293 | char *buf; | |
294 | ||
295 | buf = map_sysmem(addr, 0); | |
296 | ut_assert(buf != NULL); | |
297 | fd = os_open(fname, OS_O_RDONLY); | |
298 | ut_assert(fd >= 0); | |
299 | size = os_read(fd, buf, buf_size); | |
a108082d | 300 | os_close(fd); |
747440d0 SG |
301 | ut_assert(size >= 0); |
302 | ut_assert(size < buf_size); | |
747440d0 SG |
303 | *addrp = addr; |
304 | ||
305 | return 0; | |
306 | } | |
307 | ||
308 | /* Test drawing a bitmap file */ | |
309 | static int dm_test_video_bmp(struct unit_test_state *uts) | |
310 | { | |
311 | struct udevice *dev; | |
312 | ulong addr; | |
313 | ||
314 | ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev)); | |
315 | ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr)); | |
316 | ||
317 | ut_assertok(video_bmp_display(dev, addr, 0, 0, false)); | |
f578ca79 | 318 | ut_asserteq(1368, compress_frame_buffer(uts, dev)); |
747440d0 SG |
319 | |
320 | return 0; | |
321 | } | |
e180c2b1 | 322 | DM_TEST(dm_test_video_bmp, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
747440d0 | 323 | |
8657ad43 SG |
324 | /* Test drawing a bitmap file on a 8bpp display */ |
325 | static int dm_test_video_bmp8(struct unit_test_state *uts) | |
326 | { | |
327 | struct udevice *dev; | |
328 | ulong addr; | |
329 | ||
330 | ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev)); | |
331 | ut_assertnonnull(dev); | |
332 | ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP8)); | |
333 | ||
334 | ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr)); | |
335 | ||
336 | ut_assertok(video_bmp_display(dev, addr, 0, 0, false)); | |
337 | ut_asserteq(1247, compress_frame_buffer(uts, dev)); | |
338 | ||
339 | return 0; | |
340 | } | |
341 | DM_TEST(dm_test_video_bmp8, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); | |
342 | ||
c1cad06f SG |
343 | /* Test drawing a bitmap file on a 16bpp display */ |
344 | static int dm_test_video_bmp16(struct unit_test_state *uts) | |
345 | { | |
346 | ulong src, src_len = ~0UL; | |
347 | uint dst_len = ~0U; | |
348 | struct udevice *dev; | |
349 | ulong dst = 0x10000; | |
350 | ||
351 | ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev)); | |
352 | ut_assertnonnull(dev); | |
353 | ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP16)); | |
354 | ||
355 | ut_assertok(read_file(uts, "tools/logos/denx-16bpp.bmp.gz", &src)); | |
356 | ut_assertok(gunzip(map_sysmem(dst, 0), dst_len, map_sysmem(src, 0), | |
357 | &src_len)); | |
358 | ||
359 | ut_assertok(video_bmp_display(dev, dst, 0, 0, false)); | |
360 | ut_asserteq(3700, compress_frame_buffer(uts, dev)); | |
361 | ||
362 | return 0; | |
363 | } | |
364 | DM_TEST(dm_test_video_bmp16, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); | |
365 | ||
4ea15482 SG |
366 | /* Test drawing a 24bpp bitmap file on a 16bpp display */ |
367 | static int dm_test_video_bmp24(struct unit_test_state *uts) | |
368 | { | |
369 | ulong src, src_len = ~0UL; | |
370 | uint dst_len = ~0U; | |
371 | struct udevice *dev; | |
372 | ulong dst = 0x10000; | |
373 | ||
374 | ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev)); | |
375 | ut_assertnonnull(dev); | |
376 | ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP16)); | |
377 | ||
378 | ut_assertok(read_file(uts, "tools/logos/denx-24bpp.bmp.gz", &src)); | |
379 | ut_assertok(gunzip(map_sysmem(dst, 0), dst_len, map_sysmem(src, 0), | |
380 | &src_len)); | |
381 | ||
382 | ut_assertok(video_bmp_display(dev, dst, 0, 0, false)); | |
383 | ut_asserteq(3656, compress_frame_buffer(uts, dev)); | |
384 | ||
385 | return 0; | |
386 | } | |
387 | DM_TEST(dm_test_video_bmp24, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); | |
388 | ||
389 | /* Test drawing a 24bpp bitmap file on a 32bpp display */ | |
390 | static int dm_test_video_bmp24_32(struct unit_test_state *uts) | |
391 | { | |
392 | ulong src, src_len = ~0UL; | |
393 | uint dst_len = ~0U; | |
394 | struct udevice *dev; | |
395 | ulong dst = 0x10000; | |
396 | ||
397 | ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev)); | |
398 | ut_assertnonnull(dev); | |
399 | ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32)); | |
400 | ||
401 | ut_assertok(read_file(uts, "tools/logos/denx-24bpp.bmp.gz", &src)); | |
402 | ut_assertok(gunzip(map_sysmem(dst, 0), dst_len, map_sysmem(src, 0), | |
403 | &src_len)); | |
404 | ||
405 | ut_assertok(video_bmp_display(dev, dst, 0, 0, false)); | |
406 | ut_asserteq(6827, compress_frame_buffer(uts, dev)); | |
407 | ||
408 | return 0; | |
409 | } | |
410 | DM_TEST(dm_test_video_bmp24_32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); | |
411 | ||
8657ad43 SG |
412 | /* Test drawing a bitmap file on a 32bpp display */ |
413 | static int dm_test_video_bmp32(struct unit_test_state *uts) | |
414 | { | |
415 | struct udevice *dev; | |
416 | ulong addr; | |
417 | ||
418 | ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev)); | |
419 | ut_assertnonnull(dev); | |
420 | ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32)); | |
421 | ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr)); | |
422 | ||
423 | ut_assertok(video_bmp_display(dev, addr, 0, 0, false)); | |
424 | ut_asserteq(2024, compress_frame_buffer(uts, dev)); | |
425 | ||
426 | return 0; | |
427 | } | |
428 | DM_TEST(dm_test_video_bmp32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); | |
429 | ||
747440d0 SG |
430 | /* Test drawing a compressed bitmap file */ |
431 | static int dm_test_video_bmp_comp(struct unit_test_state *uts) | |
432 | { | |
433 | struct udevice *dev; | |
434 | ulong addr; | |
435 | ||
436 | ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev)); | |
437 | ut_assertok(read_file(uts, "tools/logos/denx-comp.bmp", &addr)); | |
438 | ||
439 | ut_assertok(video_bmp_display(dev, addr, 0, 0, false)); | |
f578ca79 | 440 | ut_asserteq(1368, compress_frame_buffer(uts, dev)); |
747440d0 SG |
441 | |
442 | return 0; | |
443 | } | |
e180c2b1 | 444 | DM_TEST(dm_test_video_bmp_comp, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
5674ead7 | 445 | |
646e169a SG |
446 | /* Test drawing a bitmap file on a 32bpp display */ |
447 | static int dm_test_video_comp_bmp32(struct unit_test_state *uts) | |
448 | { | |
449 | struct udevice *dev; | |
450 | ulong addr; | |
451 | ||
452 | ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev)); | |
453 | ut_assertnonnull(dev); | |
454 | ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32)); | |
455 | ||
456 | ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr)); | |
457 | ||
458 | ut_assertok(video_bmp_display(dev, addr, 0, 0, false)); | |
459 | ut_asserteq(2024, compress_frame_buffer(uts, dev)); | |
460 | ||
461 | return 0; | |
462 | } | |
463 | DM_TEST(dm_test_video_comp_bmp32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); | |
464 | ||
465 | /* Test drawing a bitmap file on a 8bpp display */ | |
466 | static int dm_test_video_comp_bmp8(struct unit_test_state *uts) | |
467 | { | |
468 | struct udevice *dev; | |
469 | ulong addr; | |
470 | ||
471 | ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev)); | |
472 | ut_assertnonnull(dev); | |
473 | ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP8)); | |
474 | ||
475 | ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr)); | |
476 | ||
477 | ut_assertok(video_bmp_display(dev, addr, 0, 0, false)); | |
478 | ut_asserteq(1247, compress_frame_buffer(uts, dev)); | |
479 | ||
480 | return 0; | |
481 | } | |
482 | DM_TEST(dm_test_video_comp_bmp8, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); | |
483 | ||
5674ead7 SG |
484 | /* Test TrueType console */ |
485 | static int dm_test_video_truetype(struct unit_test_state *uts) | |
486 | { | |
487 | struct udevice *dev, *con; | |
488 | 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"; | |
5674ead7 SG |
489 | |
490 | ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev)); | |
491 | ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); | |
a7495ac8 | 492 | vidconsole_put_string(con, test_string); |
f578ca79 | 493 | ut_asserteq(12237, compress_frame_buffer(uts, dev)); |
5674ead7 SG |
494 | |
495 | return 0; | |
496 | } | |
e180c2b1 | 497 | DM_TEST(dm_test_video_truetype, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
5674ead7 SG |
498 | |
499 | /* Test scrolling TrueType console */ | |
500 | static int dm_test_video_truetype_scroll(struct unit_test_state *uts) | |
501 | { | |
502 | struct sandbox_sdl_plat *plat; | |
503 | struct udevice *dev, *con; | |
504 | 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"; | |
5674ead7 SG |
505 | |
506 | ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev)); | |
507 | ut_assert(!device_active(dev)); | |
c69cda25 | 508 | plat = dev_get_plat(dev); |
5674ead7 SG |
509 | plat->font_size = 100; |
510 | ||
511 | ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev)); | |
512 | ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); | |
a7495ac8 | 513 | vidconsole_put_string(con, test_string); |
f578ca79 | 514 | ut_asserteq(35030, compress_frame_buffer(uts, dev)); |
5674ead7 SG |
515 | |
516 | return 0; | |
517 | } | |
e180c2b1 | 518 | DM_TEST(dm_test_video_truetype_scroll, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
5674ead7 SG |
519 | |
520 | /* Test TrueType backspace, within and across lines */ | |
521 | static int dm_test_video_truetype_bs(struct unit_test_state *uts) | |
522 | { | |
523 | struct sandbox_sdl_plat *plat; | |
524 | struct udevice *dev, *con; | |
525 | 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."; | |
5674ead7 SG |
526 | |
527 | ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev)); | |
528 | ut_assert(!device_active(dev)); | |
c69cda25 | 529 | plat = dev_get_plat(dev); |
5674ead7 SG |
530 | plat->font_size = 100; |
531 | ||
532 | ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev)); | |
533 | ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); | |
a7495ac8 | 534 | vidconsole_put_string(con, test_string); |
f578ca79 | 535 | ut_asserteq(29018, compress_frame_buffer(uts, dev)); |
5674ead7 SG |
536 | |
537 | return 0; | |
538 | } | |
e180c2b1 | 539 | DM_TEST(dm_test_video_truetype_bs, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |