blob: d5648f0c59bcc5544394a7f77e69136b730da900 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass90b6fef2016-01-18 19:52:26 -07002/*
3 * Copyright (c) 2014 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glass90b6fef2016-01-18 19:52:26 -07005 */
6
7#include <common.h>
8#include <bzlib.h>
9#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -070011#include <malloc.h>
Simon Glass90b6fef2016-01-18 19:52:26 -070012#include <mapmem.h>
13#include <os.h>
14#include <video.h>
15#include <video_console.h>
Simon Glassc3b5adf2021-11-19 13:23:50 -070016#include <asm/test.h>
Simon Glass90b6fef2016-01-18 19:52:26 -070017#include <dm/test.h>
18#include <dm/uclass-internal.h>
Simon Glass75c4d412020-07-19 10:15:37 -060019#include <test/test.h>
Simon Glass90b6fef2016-01-18 19:52:26 -070020#include <test/ut.h>
21
22/*
23 * These tests use the standard sandbox frame buffer, the resolution of which
24 * is defined in the device tree. This only supports 16bpp so the tests only
25 * test that code path. It would be possible to adjust this fairly easily,
26 * by adjusting the bpix value in struct sandbox_sdl_plat. However the code
27 * in sandbox_sdl_sync() would also need to change to handle the different
28 * surface depth.
29 */
Simon Glass90b6fef2016-01-18 19:52:26 -070030/* Basic test of the video uclass */
31static int dm_test_video_base(struct unit_test_state *uts)
32{
33 struct video_priv *priv;
34 struct udevice *dev;
35
36 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
37 ut_asserteq(1366, video_get_xsize(dev));
38 ut_asserteq(768, video_get_ysize(dev));
39 priv = dev_get_uclass_priv(dev);
40 ut_asserteq(priv->fb_size, 1366 * 768 * 2);
41
42 return 0;
43}
Simon Glass974dccd2020-07-28 19:41:12 -060044DM_TEST(dm_test_video_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass90b6fef2016-01-18 19:52:26 -070045
46/**
47 * compress_frame_buffer() - Compress the frame buffer and return its size
48 *
49 * We want to write tests which perform operations on the video console and
50 * check that the frame buffer ends up with the correct contents. But it is
51 * painful to store 'known good' images for comparison with the frame
52 * buffer. As an alternative, we can compress the frame buffer and check the
53 * size of the compressed data. This provides a pretty good level of
54 * certainty and the resulting tests need only check a single value.
55 *
Simon Glass2a0f8e32020-07-02 21:12:29 -060056 * If the copy framebuffer is enabled, this compares it to the main framebuffer
57 * too.
58 *
59 * @uts: Test state
Simon Glass90b6fef2016-01-18 19:52:26 -070060 * @dev: Video device
61 * @return compressed size of the frame buffer, or -ve on error
62 */
Simon Glass2a0f8e32020-07-02 21:12:29 -060063static int compress_frame_buffer(struct unit_test_state *uts,
64 struct udevice *dev)
Simon Glass90b6fef2016-01-18 19:52:26 -070065{
66 struct video_priv *priv = dev_get_uclass_priv(dev);
Simon Glass2a0f8e32020-07-02 21:12:29 -060067 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
Simon Glass90b6fef2016-01-18 19:52:26 -070068 uint destlen;
69 void *dest;
70 int ret;
71
72 destlen = priv->fb_size;
73 dest = malloc(priv->fb_size);
74 if (!dest)
75 return -ENOMEM;
76 ret = BZ2_bzBuffToBuffCompress(dest, &destlen,
77 priv->fb, priv->fb_size,
78 3, 0, 0);
79 free(dest);
80 if (ret)
81 return ret;
82
Simon Glass2a0f8e32020-07-02 21:12:29 -060083 /* Check here that the copy frame buffer is working correctly */
84 if (IS_ENABLED(CONFIG_VIDEO_COPY)) {
85 ut_assertf(!memcmp(uc_priv->fb, uc_priv->copy_fb,
86 uc_priv->fb_size),
87 "Copy framebuffer does not match fb");
88 }
89
Simon Glass90b6fef2016-01-18 19:52:26 -070090 return destlen;
91}
92
93/*
94 * Call this function at any point to halt and show the current display. Be
95 * sure to run the test with the -l flag.
96 */
97static void __maybe_unused see_output(void)
98{
99 video_sync_all();
100 while (1);
101}
102
Simon Glassdaac9c72016-01-14 18:10:50 -0700103/* Select the video console driver to use for a video device */
104static int select_vidconsole(struct unit_test_state *uts, const char *drv_name)
105{
106 struct sandbox_sdl_plat *plat;
107 struct udevice *dev;
108
109 ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
110 ut_assert(!device_active(dev));
Simon Glassfa20e932020-12-03 16:55:20 -0700111 plat = dev_get_plat(dev);
Simon Glassdaac9c72016-01-14 18:10:50 -0700112 plat->vidconsole_drv_name = "vidconsole0";
113
114 return 0;
115}
116
Simon Glass90b6fef2016-01-18 19:52:26 -0700117/* Test text output works on the video console */
118static int dm_test_video_text(struct unit_test_state *uts)
119{
120 struct udevice *dev, *con;
121 int i;
122
123#define WHITE 0xffff
124#define SCROLL_LINES 100
125
Simon Glassdaac9c72016-01-14 18:10:50 -0700126 ut_assertok(select_vidconsole(uts, "vidconsole0"));
Simon Glass90b6fef2016-01-18 19:52:26 -0700127 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
Simon Glass2a0f8e32020-07-02 21:12:29 -0600128 ut_asserteq(46, compress_frame_buffer(uts, dev));
Simon Glass90b6fef2016-01-18 19:52:26 -0700129
130 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
131 vidconsole_putc_xy(con, 0, 0, 'a');
Simon Glass2a0f8e32020-07-02 21:12:29 -0600132 ut_asserteq(79, compress_frame_buffer(uts, dev));
Simon Glass90b6fef2016-01-18 19:52:26 -0700133
134 vidconsole_putc_xy(con, 0, 0, ' ');
Simon Glass2a0f8e32020-07-02 21:12:29 -0600135 ut_asserteq(46, compress_frame_buffer(uts, dev));
Simon Glass90b6fef2016-01-18 19:52:26 -0700136
137 for (i = 0; i < 20; i++)
Simon Glass52c10c52016-01-14 18:10:37 -0700138 vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
Simon Glass2a0f8e32020-07-02 21:12:29 -0600139 ut_asserteq(273, compress_frame_buffer(uts, dev));
Simon Glass90b6fef2016-01-18 19:52:26 -0700140
141 vidconsole_set_row(con, 0, WHITE);
Simon Glass2a0f8e32020-07-02 21:12:29 -0600142 ut_asserteq(46, compress_frame_buffer(uts, dev));
Simon Glass90b6fef2016-01-18 19:52:26 -0700143
144 for (i = 0; i < 20; i++)
Simon Glass52c10c52016-01-14 18:10:37 -0700145 vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
Simon Glass2a0f8e32020-07-02 21:12:29 -0600146 ut_asserteq(273, compress_frame_buffer(uts, dev));
Simon Glass90b6fef2016-01-18 19:52:26 -0700147
148 return 0;
149}
Simon Glass974dccd2020-07-28 19:41:12 -0600150DM_TEST(dm_test_video_text, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass90b6fef2016-01-18 19:52:26 -0700151
152/* Test handling of special characters in the console */
153static int dm_test_video_chars(struct unit_test_state *uts)
154{
155 struct udevice *dev, *con;
Simon Glass37b80202016-01-14 18:10:38 -0700156 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 Glass90b6fef2016-01-18 19:52:26 -0700157
Simon Glassdaac9c72016-01-14 18:10:50 -0700158 ut_assertok(select_vidconsole(uts, "vidconsole0"));
Simon Glass90b6fef2016-01-18 19:52:26 -0700159 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
160 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
Rob Clark985935b2017-09-25 15:45:08 -0400161 vidconsole_put_string(con, test_string);
Simon Glass2a0f8e32020-07-02 21:12:29 -0600162 ut_asserteq(466, compress_frame_buffer(uts, dev));
Simon Glass90b6fef2016-01-18 19:52:26 -0700163
164 return 0;
165}
Simon Glass974dccd2020-07-28 19:41:12 -0600166DM_TEST(dm_test_video_chars, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass90b6fef2016-01-18 19:52:26 -0700167
Rob Clark09d64b32017-09-25 15:45:09 -0400168#ifdef CONFIG_VIDEO_ANSI
169#define ANSI_ESC "\x1b"
170/* Test handling of ANSI escape sequences */
171static int dm_test_video_ansi(struct unit_test_state *uts)
172{
173 struct udevice *dev, *con;
174
175 ut_assertok(select_vidconsole(uts, "vidconsole0"));
176 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
177 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
178
179 /* reference clear: */
180 video_clear(con->parent);
Simon Glass0806dcc2018-10-01 11:55:14 -0600181 video_sync(con->parent, false);
Simon Glass2a0f8e32020-07-02 21:12:29 -0600182 ut_asserteq(46, compress_frame_buffer(uts, dev));
Rob Clark09d64b32017-09-25 15:45:09 -0400183
184 /* test clear escape sequence: [2J */
185 vidconsole_put_string(con, "A\tB\tC"ANSI_ESC"[2J");
Simon Glass2a0f8e32020-07-02 21:12:29 -0600186 ut_asserteq(46, compress_frame_buffer(uts, dev));
Rob Clark09d64b32017-09-25 15:45:09 -0400187
188 /* test set-cursor: [%d;%df */
189 vidconsole_put_string(con, "abc"ANSI_ESC"[2;2fab"ANSI_ESC"[4;4fcd");
Simon Glass2a0f8e32020-07-02 21:12:29 -0600190 ut_asserteq(143, compress_frame_buffer(uts, dev));
Rob Clark09d64b32017-09-25 15:45:09 -0400191
192 /* test colors (30-37 fg color, 40-47 bg color) */
193 vidconsole_put_string(con, ANSI_ESC"[30;41mfoo"); /* black on red */
194 vidconsole_put_string(con, ANSI_ESC"[33;44mbar"); /* yellow on blue */
Simon Glass2a0f8e32020-07-02 21:12:29 -0600195 ut_asserteq(272, compress_frame_buffer(uts, dev));
Rob Clark09d64b32017-09-25 15:45:09 -0400196
197 return 0;
198}
Simon Glass974dccd2020-07-28 19:41:12 -0600199DM_TEST(dm_test_video_ansi, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Rob Clark09d64b32017-09-25 15:45:09 -0400200#endif
201
Simon Glass90b6fef2016-01-18 19:52:26 -0700202/**
203 * check_vidconsole_output() - Run a text console test
204 *
205 * @uts: Test state
Simon Glass4425bf42020-07-02 21:12:28 -0600206 * @rot: Console rotation (0=normal orientation, 1=90 degrees clockwise,
207 * 2=upside down, 3=90 degree counterclockwise)
Simon Glass90b6fef2016-01-18 19:52:26 -0700208 * @wrap_size: Expected size of compressed frame buffer for the wrap test
209 * @scroll_size: Same for the scroll test
210 * @return 0 on success
211 */
212static int check_vidconsole_output(struct unit_test_state *uts, int rot,
213 int wrap_size, int scroll_size)
214{
215 struct udevice *dev, *con;
216 struct sandbox_sdl_plat *plat;
217 int i;
218
219 ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
220 ut_assert(!device_active(dev));
Simon Glassfa20e932020-12-03 16:55:20 -0700221 plat = dev_get_plat(dev);
Simon Glass90b6fef2016-01-18 19:52:26 -0700222 plat->rot = rot;
223
224 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
225 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
Simon Glass2a0f8e32020-07-02 21:12:29 -0600226 ut_asserteq(46, compress_frame_buffer(uts, dev));
Simon Glass90b6fef2016-01-18 19:52:26 -0700227
228 /* Check display wrap */
229 for (i = 0; i < 120; i++)
230 vidconsole_put_char(con, 'A' + i % 50);
Simon Glass2a0f8e32020-07-02 21:12:29 -0600231 ut_asserteq(wrap_size, compress_frame_buffer(uts, dev));
Simon Glass90b6fef2016-01-18 19:52:26 -0700232
233 /* Check display scrolling */
234 for (i = 0; i < SCROLL_LINES; i++) {
235 vidconsole_put_char(con, 'A' + i % 50);
236 vidconsole_put_char(con, '\n');
237 }
Simon Glass2a0f8e32020-07-02 21:12:29 -0600238 ut_asserteq(scroll_size, compress_frame_buffer(uts, dev));
Simon Glass90b6fef2016-01-18 19:52:26 -0700239
240 /* If we scroll enough, the screen becomes blank again */
241 for (i = 0; i < SCROLL_LINES; i++)
242 vidconsole_put_char(con, '\n');
Simon Glass2a0f8e32020-07-02 21:12:29 -0600243 ut_asserteq(46, compress_frame_buffer(uts, dev));
Simon Glass90b6fef2016-01-18 19:52:26 -0700244
245 return 0;
246}
247
248/* Test text output through the console uclass */
249static int dm_test_video_context(struct unit_test_state *uts)
250{
Simon Glassdaac9c72016-01-14 18:10:50 -0700251 ut_assertok(select_vidconsole(uts, "vidconsole0"));
252 ut_assertok(check_vidconsole_output(uts, 0, 788, 453));
253
254 return 0;
Simon Glass90b6fef2016-01-18 19:52:26 -0700255}
Simon Glass974dccd2020-07-28 19:41:12 -0600256DM_TEST(dm_test_video_context, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glassa0f1efe2016-01-18 19:52:27 -0700257
258/* Test rotated text output through the console uclass */
259static int dm_test_video_rotation1(struct unit_test_state *uts)
260{
261 ut_assertok(check_vidconsole_output(uts, 1, 1112, 680));
262
263 return 0;
264}
Simon Glass974dccd2020-07-28 19:41:12 -0600265DM_TEST(dm_test_video_rotation1, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glassa0f1efe2016-01-18 19:52:27 -0700266
267/* Test rotated text output through the console uclass */
268static int dm_test_video_rotation2(struct unit_test_state *uts)
269{
Simon Glassf50a6b92020-07-02 21:12:17 -0600270 ut_assertok(check_vidconsole_output(uts, 2, 783, 445));
Simon Glassa0f1efe2016-01-18 19:52:27 -0700271
272 return 0;
273}
Simon Glass974dccd2020-07-28 19:41:12 -0600274DM_TEST(dm_test_video_rotation2, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glassa0f1efe2016-01-18 19:52:27 -0700275
276/* Test rotated text output through the console uclass */
277static int dm_test_video_rotation3(struct unit_test_state *uts)
278{
279 ut_assertok(check_vidconsole_output(uts, 3, 1134, 681));
280
281 return 0;
282}
Simon Glass974dccd2020-07-28 19:41:12 -0600283DM_TEST(dm_test_video_rotation3, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass7a1cb292016-01-18 19:52:28 -0700284
285/* Read a file into memory and return a pointer to it */
286static int read_file(struct unit_test_state *uts, const char *fname,
287 ulong *addrp)
288{
289 int buf_size = 100000;
290 ulong addr = 0;
291 int size, fd;
292 char *buf;
293
294 buf = map_sysmem(addr, 0);
295 ut_assert(buf != NULL);
296 fd = os_open(fname, OS_O_RDONLY);
297 ut_assert(fd >= 0);
298 size = os_read(fd, buf, buf_size);
Simon Glass9050c5f2016-01-30 15:45:17 -0700299 os_close(fd);
Simon Glass7a1cb292016-01-18 19:52:28 -0700300 ut_assert(size >= 0);
301 ut_assert(size < buf_size);
Simon Glass7a1cb292016-01-18 19:52:28 -0700302 *addrp = addr;
303
304 return 0;
305}
306
307/* Test drawing a bitmap file */
308static int dm_test_video_bmp(struct unit_test_state *uts)
309{
310 struct udevice *dev;
311 ulong addr;
312
313 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
314 ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
315
316 ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
Simon Glass2a0f8e32020-07-02 21:12:29 -0600317 ut_asserteq(1368, compress_frame_buffer(uts, dev));
Simon Glass7a1cb292016-01-18 19:52:28 -0700318
319 return 0;
320}
Simon Glass974dccd2020-07-28 19:41:12 -0600321DM_TEST(dm_test_video_bmp, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass7a1cb292016-01-18 19:52:28 -0700322
Simon Glassc3b5adf2021-11-19 13:23:50 -0700323/* Test drawing a bitmap file on a 8bpp display */
324static int dm_test_video_bmp8(struct unit_test_state *uts)
325{
326 struct udevice *dev;
327 ulong addr;
328
329 ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
330 ut_assertnonnull(dev);
331 ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP8));
332
333 ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
334
335 ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
336 ut_asserteq(1247, compress_frame_buffer(uts, dev));
337
338 return 0;
339}
340DM_TEST(dm_test_video_bmp8, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
341
342/* Test drawing a bitmap file on a 32bpp display */
343static int dm_test_video_bmp32(struct unit_test_state *uts)
344{
345 struct udevice *dev;
346 ulong addr;
347
348 ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
349 ut_assertnonnull(dev);
350 ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32));
351 ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
352
353 ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
354 ut_asserteq(2024, compress_frame_buffer(uts, dev));
355
356 return 0;
357}
358DM_TEST(dm_test_video_bmp32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
359
Simon Glass7a1cb292016-01-18 19:52:28 -0700360/* Test drawing a compressed bitmap file */
361static int dm_test_video_bmp_comp(struct unit_test_state *uts)
362{
363 struct udevice *dev;
364 ulong addr;
365
366 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
367 ut_assertok(read_file(uts, "tools/logos/denx-comp.bmp", &addr));
368
369 ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
Simon Glass2a0f8e32020-07-02 21:12:29 -0600370 ut_asserteq(1368, compress_frame_buffer(uts, dev));
Simon Glass7a1cb292016-01-18 19:52:28 -0700371
372 return 0;
373}
Simon Glass974dccd2020-07-28 19:41:12 -0600374DM_TEST(dm_test_video_bmp_comp, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass32337982016-01-14 18:10:51 -0700375
Simon Glass490bb992021-11-19 13:23:55 -0700376/* Test drawing a bitmap file on a 32bpp display */
377static int dm_test_video_comp_bmp32(struct unit_test_state *uts)
378{
379 struct udevice *dev;
380 ulong addr;
381
382 ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
383 ut_assertnonnull(dev);
384 ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32));
385
386 ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
387
388 ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
389 ut_asserteq(2024, compress_frame_buffer(uts, dev));
390
391 return 0;
392}
393DM_TEST(dm_test_video_comp_bmp32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
394
395/* Test drawing a bitmap file on a 8bpp display */
396static int dm_test_video_comp_bmp8(struct unit_test_state *uts)
397{
398 struct udevice *dev;
399 ulong addr;
400
401 ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
402 ut_assertnonnull(dev);
403 ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP8));
404
405 ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
406
407 ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
408 ut_asserteq(1247, compress_frame_buffer(uts, dev));
409
410 return 0;
411}
412DM_TEST(dm_test_video_comp_bmp8, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
413
Simon Glass32337982016-01-14 18:10:51 -0700414/* Test TrueType console */
415static int dm_test_video_truetype(struct unit_test_state *uts)
416{
417 struct udevice *dev, *con;
418 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 Glass32337982016-01-14 18:10:51 -0700419
420 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
421 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
Rob Clark985935b2017-09-25 15:45:08 -0400422 vidconsole_put_string(con, test_string);
Simon Glass2a0f8e32020-07-02 21:12:29 -0600423 ut_asserteq(12237, compress_frame_buffer(uts, dev));
Simon Glass32337982016-01-14 18:10:51 -0700424
425 return 0;
426}
Simon Glass974dccd2020-07-28 19:41:12 -0600427DM_TEST(dm_test_video_truetype, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass32337982016-01-14 18:10:51 -0700428
429/* Test scrolling TrueType console */
430static int dm_test_video_truetype_scroll(struct unit_test_state *uts)
431{
432 struct sandbox_sdl_plat *plat;
433 struct udevice *dev, *con;
434 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 Glass32337982016-01-14 18:10:51 -0700435
436 ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
437 ut_assert(!device_active(dev));
Simon Glassfa20e932020-12-03 16:55:20 -0700438 plat = dev_get_plat(dev);
Simon Glass32337982016-01-14 18:10:51 -0700439 plat->font_size = 100;
440
441 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
442 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
Rob Clark985935b2017-09-25 15:45:08 -0400443 vidconsole_put_string(con, test_string);
Simon Glass2a0f8e32020-07-02 21:12:29 -0600444 ut_asserteq(35030, compress_frame_buffer(uts, dev));
Simon Glass32337982016-01-14 18:10:51 -0700445
446 return 0;
447}
Simon Glass974dccd2020-07-28 19:41:12 -0600448DM_TEST(dm_test_video_truetype_scroll, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass32337982016-01-14 18:10:51 -0700449
450/* Test TrueType backspace, within and across lines */
451static int dm_test_video_truetype_bs(struct unit_test_state *uts)
452{
453 struct sandbox_sdl_plat *plat;
454 struct udevice *dev, *con;
455 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 Glass32337982016-01-14 18:10:51 -0700456
457 ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
458 ut_assert(!device_active(dev));
Simon Glassfa20e932020-12-03 16:55:20 -0700459 plat = dev_get_plat(dev);
Simon Glass32337982016-01-14 18:10:51 -0700460 plat->font_size = 100;
461
462 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
463 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
Rob Clark985935b2017-09-25 15:45:08 -0400464 vidconsole_put_string(con, test_string);
Simon Glass2a0f8e32020-07-02 21:12:29 -0600465 ut_asserteq(29018, compress_frame_buffer(uts, dev));
Simon Glass32337982016-01-14 18:10:51 -0700466
467 return 0;
468}
Simon Glass974dccd2020-07-28 19:41:12 -0600469DM_TEST(dm_test_video_truetype_bs, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);