blob: c496b05df76f3e7eb80f5ff0da1894deeb9370ba [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass3c97c4f2016-01-18 19:52:26 -07002/*
3 * Copyright (c) 2014 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glass3c97c4f2016-01-18 19:52:26 -07005 */
6
7#include <common.h>
8#include <bzlib.h>
9#include <dm.h>
Simon Glassc1cad062021-11-19 13:23:58 -070010#include <gzip.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060011#include <log.h>
Simon Glass336d4612020-02-03 07:36:16 -070012#include <malloc.h>
Simon Glass3c97c4f2016-01-18 19:52:26 -070013#include <mapmem.h>
14#include <os.h>
15#include <video.h>
16#include <video_console.h>
Simon Glass8657ad42021-11-19 13:23:50 -070017#include <asm/test.h>
Simon Glass3c97c4f2016-01-18 19:52:26 -070018#include <dm/test.h>
19#include <dm/uclass-internal.h>
Simon Glass0e1fad42020-07-19 10:15:37 -060020#include <test/test.h>
Simon Glass3c97c4f2016-01-18 19:52:26 -070021#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 */
Simon Glass3c97c4f2016-01-18 19:52:26 -070031/* Basic test of the video uclass */
32static 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}
Simon Glasse180c2b2020-07-28 19:41:12 -060045DM_TEST(dm_test_video_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass3c97c4f2016-01-18 19:52:26 -070046
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 *
Simon Glassf578ca72020-07-02 21:12:29 -060057 * If the copy framebuffer is enabled, this compares it to the main framebuffer
58 * too.
59 *
60 * @uts: Test state
Simon Glass3c97c4f2016-01-18 19:52:26 -070061 * @dev: Video device
62 * @return compressed size of the frame buffer, or -ve on error
63 */
Simon Glassf578ca72020-07-02 21:12:29 -060064static int compress_frame_buffer(struct unit_test_state *uts,
65 struct udevice *dev)
Simon Glass3c97c4f2016-01-18 19:52:26 -070066{
67 struct video_priv *priv = dev_get_uclass_priv(dev);
Simon Glassf578ca72020-07-02 21:12:29 -060068 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
Simon Glass3c97c4f2016-01-18 19:52:26 -070069 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
Simon Glassf578ca72020-07-02 21:12:29 -060084 /* 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
Simon Glass3c97c4f2016-01-18 19:52:26 -070091 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 */
98static void __maybe_unused see_output(void)
99{
100 video_sync_all();
101 while (1);
102}
103
Simon Glass8df8dad2016-01-14 18:10:50 -0700104/* Select the video console driver to use for a video device */
105static 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));
Simon Glassc69cda22020-12-03 16:55:20 -0700112 plat = dev_get_plat(dev);
Simon Glass8df8dad2016-01-14 18:10:50 -0700113 plat->vidconsole_drv_name = "vidconsole0";
114
115 return 0;
116}
117
Simon Glass3c97c4f2016-01-18 19:52:26 -0700118/* Test text output works on the video console */
119static 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
Simon Glass8df8dad2016-01-14 18:10:50 -0700127 ut_assertok(select_vidconsole(uts, "vidconsole0"));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700128 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
Simon Glassf578ca72020-07-02 21:12:29 -0600129 ut_asserteq(46, compress_frame_buffer(uts, dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700130
131 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
132 vidconsole_putc_xy(con, 0, 0, 'a');
Simon Glassf578ca72020-07-02 21:12:29 -0600133 ut_asserteq(79, compress_frame_buffer(uts, dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700134
135 vidconsole_putc_xy(con, 0, 0, ' ');
Simon Glassf578ca72020-07-02 21:12:29 -0600136 ut_asserteq(46, compress_frame_buffer(uts, dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700137
138 for (i = 0; i < 20; i++)
Simon Glassf2661782016-01-14 18:10:37 -0700139 vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
Simon Glassf578ca72020-07-02 21:12:29 -0600140 ut_asserteq(273, compress_frame_buffer(uts, dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700141
142 vidconsole_set_row(con, 0, WHITE);
Simon Glassf578ca72020-07-02 21:12:29 -0600143 ut_asserteq(46, compress_frame_buffer(uts, dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700144
145 for (i = 0; i < 20; i++)
Simon Glassf2661782016-01-14 18:10:37 -0700146 vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
Simon Glassf578ca72020-07-02 21:12:29 -0600147 ut_asserteq(273, compress_frame_buffer(uts, dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700148
149 return 0;
150}
Simon Glasse180c2b2020-07-28 19:41:12 -0600151DM_TEST(dm_test_video_text, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass3c97c4f2016-01-18 19:52:26 -0700152
153/* Test handling of special characters in the console */
154static int dm_test_video_chars(struct unit_test_state *uts)
155{
156 struct udevice *dev, *con;
Simon Glass5508f102016-01-14 18:10:38 -0700157 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.";
Simon Glass3c97c4f2016-01-18 19:52:26 -0700158
Simon Glass8df8dad2016-01-14 18:10:50 -0700159 ut_assertok(select_vidconsole(uts, "vidconsole0"));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700160 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
161 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
Rob Clarka7495ac2017-09-25 15:45:08 -0400162 vidconsole_put_string(con, test_string);
Simon Glassf578ca72020-07-02 21:12:29 -0600163 ut_asserteq(466, compress_frame_buffer(uts, dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700164
165 return 0;
166}
Simon Glasse180c2b2020-07-28 19:41:12 -0600167DM_TEST(dm_test_video_chars, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass3c97c4f2016-01-18 19:52:26 -0700168
Rob Clark40186ee2017-09-25 15:45:09 -0400169#ifdef CONFIG_VIDEO_ANSI
170#define ANSI_ESC "\x1b"
171/* Test handling of ANSI escape sequences */
172static 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);
Simon Glass55d39912018-10-01 11:55:14 -0600182 video_sync(con->parent, false);
Simon Glassf578ca72020-07-02 21:12:29 -0600183 ut_asserteq(46, compress_frame_buffer(uts, dev));
Rob Clark40186ee2017-09-25 15:45:09 -0400184
185 /* test clear escape sequence: [2J */
186 vidconsole_put_string(con, "A\tB\tC"ANSI_ESC"[2J");
Simon Glassf578ca72020-07-02 21:12:29 -0600187 ut_asserteq(46, compress_frame_buffer(uts, dev));
Rob Clark40186ee2017-09-25 15:45:09 -0400188
189 /* test set-cursor: [%d;%df */
190 vidconsole_put_string(con, "abc"ANSI_ESC"[2;2fab"ANSI_ESC"[4;4fcd");
Simon Glassf578ca72020-07-02 21:12:29 -0600191 ut_asserteq(143, compress_frame_buffer(uts, dev));
Rob Clark40186ee2017-09-25 15:45:09 -0400192
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 */
Simon Glassf578ca72020-07-02 21:12:29 -0600196 ut_asserteq(272, compress_frame_buffer(uts, dev));
Rob Clark40186ee2017-09-25 15:45:09 -0400197
198 return 0;
199}
Simon Glasse180c2b2020-07-28 19:41:12 -0600200DM_TEST(dm_test_video_ansi, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Rob Clark40186ee2017-09-25 15:45:09 -0400201#endif
202
Simon Glass3c97c4f2016-01-18 19:52:26 -0700203/**
204 * check_vidconsole_output() - Run a text console test
205 *
206 * @uts: Test state
Simon Glassef453122020-07-02 21:12:28 -0600207 * @rot: Console rotation (0=normal orientation, 1=90 degrees clockwise,
208 * 2=upside down, 3=90 degree counterclockwise)
Simon Glass3c97c4f2016-01-18 19:52:26 -0700209 * @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 */
213static 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));
Simon Glassc69cda22020-12-03 16:55:20 -0700222 plat = dev_get_plat(dev);
Simon Glass3c97c4f2016-01-18 19:52:26 -0700223 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));
Simon Glassf578ca72020-07-02 21:12:29 -0600227 ut_asserteq(46, compress_frame_buffer(uts, dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700228
229 /* Check display wrap */
230 for (i = 0; i < 120; i++)
231 vidconsole_put_char(con, 'A' + i % 50);
Simon Glassf578ca72020-07-02 21:12:29 -0600232 ut_asserteq(wrap_size, compress_frame_buffer(uts, dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700233
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 }
Simon Glassf578ca72020-07-02 21:12:29 -0600239 ut_asserteq(scroll_size, compress_frame_buffer(uts, dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700240
241 /* If we scroll enough, the screen becomes blank again */
242 for (i = 0; i < SCROLL_LINES; i++)
243 vidconsole_put_char(con, '\n');
Simon Glassf578ca72020-07-02 21:12:29 -0600244 ut_asserteq(46, compress_frame_buffer(uts, dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700245
246 return 0;
247}
248
249/* Test text output through the console uclass */
250static int dm_test_video_context(struct unit_test_state *uts)
251{
Simon Glass8df8dad2016-01-14 18:10:50 -0700252 ut_assertok(select_vidconsole(uts, "vidconsole0"));
253 ut_assertok(check_vidconsole_output(uts, 0, 788, 453));
254
255 return 0;
Simon Glass3c97c4f2016-01-18 19:52:26 -0700256}
Simon Glasse180c2b2020-07-28 19:41:12 -0600257DM_TEST(dm_test_video_context, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass85e08db2016-01-18 19:52:27 -0700258
259/* Test rotated text output through the console uclass */
260static 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}
Simon Glasse180c2b2020-07-28 19:41:12 -0600266DM_TEST(dm_test_video_rotation1, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass85e08db2016-01-18 19:52:27 -0700267
268/* Test rotated text output through the console uclass */
269static int dm_test_video_rotation2(struct unit_test_state *uts)
270{
Simon Glass9beb3642020-07-02 21:12:17 -0600271 ut_assertok(check_vidconsole_output(uts, 2, 783, 445));
Simon Glass85e08db2016-01-18 19:52:27 -0700272
273 return 0;
274}
Simon Glasse180c2b2020-07-28 19:41:12 -0600275DM_TEST(dm_test_video_rotation2, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass85e08db2016-01-18 19:52:27 -0700276
277/* Test rotated text output through the console uclass */
278static 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}
Simon Glasse180c2b2020-07-28 19:41:12 -0600284DM_TEST(dm_test_video_rotation3, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass747440d2016-01-18 19:52:28 -0700285
286/* Read a file into memory and return a pointer to it */
287static 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);
Simon Glassa1080822016-01-30 15:45:17 -0700300 os_close(fd);
Simon Glass747440d2016-01-18 19:52:28 -0700301 ut_assert(size >= 0);
302 ut_assert(size < buf_size);
Simon Glass747440d2016-01-18 19:52:28 -0700303 *addrp = addr;
304
305 return 0;
306}
307
308/* Test drawing a bitmap file */
309static 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));
Simon Glassf578ca72020-07-02 21:12:29 -0600318 ut_asserteq(1368, compress_frame_buffer(uts, dev));
Simon Glass747440d2016-01-18 19:52:28 -0700319
320 return 0;
321}
Simon Glasse180c2b2020-07-28 19:41:12 -0600322DM_TEST(dm_test_video_bmp, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass747440d2016-01-18 19:52:28 -0700323
Simon Glass8657ad42021-11-19 13:23:50 -0700324/* Test drawing a bitmap file on a 8bpp display */
325static 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}
341DM_TEST(dm_test_video_bmp8, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
342
Simon Glassc1cad062021-11-19 13:23:58 -0700343/* Test drawing a bitmap file on a 16bpp display */
344static 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}
364DM_TEST(dm_test_video_bmp16, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
365
Simon Glass8657ad42021-11-19 13:23:50 -0700366/* Test drawing a bitmap file on a 32bpp display */
367static int dm_test_video_bmp32(struct unit_test_state *uts)
368{
369 struct udevice *dev;
370 ulong addr;
371
372 ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
373 ut_assertnonnull(dev);
374 ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32));
375 ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
376
377 ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
378 ut_asserteq(2024, compress_frame_buffer(uts, dev));
379
380 return 0;
381}
382DM_TEST(dm_test_video_bmp32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
383
Simon Glass747440d2016-01-18 19:52:28 -0700384/* Test drawing a compressed bitmap file */
385static int dm_test_video_bmp_comp(struct unit_test_state *uts)
386{
387 struct udevice *dev;
388 ulong addr;
389
390 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
391 ut_assertok(read_file(uts, "tools/logos/denx-comp.bmp", &addr));
392
393 ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
Simon Glassf578ca72020-07-02 21:12:29 -0600394 ut_asserteq(1368, compress_frame_buffer(uts, dev));
Simon Glass747440d2016-01-18 19:52:28 -0700395
396 return 0;
397}
Simon Glasse180c2b2020-07-28 19:41:12 -0600398DM_TEST(dm_test_video_bmp_comp, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass5674ead2016-01-14 18:10:51 -0700399
Simon Glass646e1692021-11-19 13:23:55 -0700400/* Test drawing a bitmap file on a 32bpp display */
401static int dm_test_video_comp_bmp32(struct unit_test_state *uts)
402{
403 struct udevice *dev;
404 ulong addr;
405
406 ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
407 ut_assertnonnull(dev);
408 ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32));
409
410 ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
411
412 ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
413 ut_asserteq(2024, compress_frame_buffer(uts, dev));
414
415 return 0;
416}
417DM_TEST(dm_test_video_comp_bmp32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
418
419/* Test drawing a bitmap file on a 8bpp display */
420static int dm_test_video_comp_bmp8(struct unit_test_state *uts)
421{
422 struct udevice *dev;
423 ulong addr;
424
425 ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
426 ut_assertnonnull(dev);
427 ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP8));
428
429 ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
430
431 ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
432 ut_asserteq(1247, compress_frame_buffer(uts, dev));
433
434 return 0;
435}
436DM_TEST(dm_test_video_comp_bmp8, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
437
Simon Glass5674ead2016-01-14 18:10:51 -0700438/* Test TrueType console */
439static int dm_test_video_truetype(struct unit_test_state *uts)
440{
441 struct udevice *dev, *con;
442 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";
Simon Glass5674ead2016-01-14 18:10:51 -0700443
444 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
445 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
Rob Clarka7495ac2017-09-25 15:45:08 -0400446 vidconsole_put_string(con, test_string);
Simon Glassf578ca72020-07-02 21:12:29 -0600447 ut_asserteq(12237, compress_frame_buffer(uts, dev));
Simon Glass5674ead2016-01-14 18:10:51 -0700448
449 return 0;
450}
Simon Glasse180c2b2020-07-28 19:41:12 -0600451DM_TEST(dm_test_video_truetype, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass5674ead2016-01-14 18:10:51 -0700452
453/* Test scrolling TrueType console */
454static int dm_test_video_truetype_scroll(struct unit_test_state *uts)
455{
456 struct sandbox_sdl_plat *plat;
457 struct udevice *dev, *con;
458 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";
Simon Glass5674ead2016-01-14 18:10:51 -0700459
460 ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
461 ut_assert(!device_active(dev));
Simon Glassc69cda22020-12-03 16:55:20 -0700462 plat = dev_get_plat(dev);
Simon Glass5674ead2016-01-14 18:10:51 -0700463 plat->font_size = 100;
464
465 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
466 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
Rob Clarka7495ac2017-09-25 15:45:08 -0400467 vidconsole_put_string(con, test_string);
Simon Glassf578ca72020-07-02 21:12:29 -0600468 ut_asserteq(35030, compress_frame_buffer(uts, dev));
Simon Glass5674ead2016-01-14 18:10:51 -0700469
470 return 0;
471}
Simon Glasse180c2b2020-07-28 19:41:12 -0600472DM_TEST(dm_test_video_truetype_scroll, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass5674ead2016-01-14 18:10:51 -0700473
474/* Test TrueType backspace, within and across lines */
475static int dm_test_video_truetype_bs(struct unit_test_state *uts)
476{
477 struct sandbox_sdl_plat *plat;
478 struct udevice *dev, *con;
479 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.";
Simon Glass5674ead2016-01-14 18:10:51 -0700480
481 ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
482 ut_assert(!device_active(dev));
Simon Glassc69cda22020-12-03 16:55:20 -0700483 plat = dev_get_plat(dev);
Simon Glass5674ead2016-01-14 18:10:51 -0700484 plat->font_size = 100;
485
486 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
487 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
Rob Clarka7495ac2017-09-25 15:45:08 -0400488 vidconsole_put_string(con, test_string);
Simon Glassf578ca72020-07-02 21:12:29 -0600489 ut_asserteq(29018, compress_frame_buffer(uts, dev));
Simon Glass5674ead2016-01-14 18:10:51 -0700490
491 return 0;
492}
Simon Glasse180c2b2020-07-28 19:41:12 -0600493DM_TEST(dm_test_video_truetype_bs, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);