blob: d907f681600bace36d83b3335ae706cbc4e38b52 [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>
Sergei Antonov76e16072023-06-13 00:19:04 +030018#include <asm/sdl.h>
Simon Glass3c97c4f2016-01-18 19:52:26 -070019#include <dm/test.h>
20#include <dm/uclass-internal.h>
Simon Glass0e1fad42020-07-19 10:15:37 -060021#include <test/test.h>
Simon Glass3c97c4f2016-01-18 19:52:26 -070022#include <test/ut.h>
23
24/*
25 * These tests use the standard sandbox frame buffer, the resolution of which
26 * is defined in the device tree. This only supports 16bpp so the tests only
27 * test that code path. It would be possible to adjust this fairly easily,
28 * by adjusting the bpix value in struct sandbox_sdl_plat. However the code
29 * in sandbox_sdl_sync() would also need to change to handle the different
30 * surface depth.
31 */
Simon Glass3c97c4f2016-01-18 19:52:26 -070032/* Basic test of the video uclass */
33static int dm_test_video_base(struct unit_test_state *uts)
34{
35 struct video_priv *priv;
36 struct udevice *dev;
37
38 ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
39 ut_asserteq(1366, video_get_xsize(dev));
40 ut_asserteq(768, video_get_ysize(dev));
41 priv = dev_get_uclass_priv(dev);
42 ut_asserteq(priv->fb_size, 1366 * 768 * 2);
43
44 return 0;
45}
Simon Glasse180c2b2020-07-28 19:41:12 -060046DM_TEST(dm_test_video_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass3c97c4f2016-01-18 19:52:26 -070047
48/**
49 * compress_frame_buffer() - Compress the frame buffer and return its size
50 *
51 * We want to write tests which perform operations on the video console and
52 * check that the frame buffer ends up with the correct contents. But it is
53 * painful to store 'known good' images for comparison with the frame
54 * buffer. As an alternative, we can compress the frame buffer and check the
55 * size of the compressed data. This provides a pretty good level of
56 * certainty and the resulting tests need only check a single value.
57 *
Simon Glassf578ca72020-07-02 21:12:29 -060058 * If the copy framebuffer is enabled, this compares it to the main framebuffer
59 * too.
60 *
61 * @uts: Test state
Simon Glass3c97c4f2016-01-18 19:52:26 -070062 * @dev: Video device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010063 * Return: compressed size of the frame buffer, or -ve on error
Simon Glass3c97c4f2016-01-18 19:52:26 -070064 */
Simon Glassf578ca72020-07-02 21:12:29 -060065static int compress_frame_buffer(struct unit_test_state *uts,
66 struct udevice *dev)
Simon Glass3c97c4f2016-01-18 19:52:26 -070067{
68 struct video_priv *priv = dev_get_uclass_priv(dev);
Simon Glassf578ca72020-07-02 21:12:29 -060069 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
Simon Glass3c97c4f2016-01-18 19:52:26 -070070 uint destlen;
71 void *dest;
72 int ret;
73
74 destlen = priv->fb_size;
75 dest = malloc(priv->fb_size);
76 if (!dest)
77 return -ENOMEM;
78 ret = BZ2_bzBuffToBuffCompress(dest, &destlen,
79 priv->fb, priv->fb_size,
80 3, 0, 0);
81 free(dest);
82 if (ret)
83 return ret;
84
Simon Glassf578ca72020-07-02 21:12:29 -060085 /* Check here that the copy frame buffer is working correctly */
86 if (IS_ENABLED(CONFIG_VIDEO_COPY)) {
87 ut_assertf(!memcmp(uc_priv->fb, uc_priv->copy_fb,
88 uc_priv->fb_size),
89 "Copy framebuffer does not match fb");
90 }
91
Simon Glass3c97c4f2016-01-18 19:52:26 -070092 return destlen;
93}
94
95/*
96 * Call this function at any point to halt and show the current display. Be
97 * sure to run the test with the -l flag.
98 */
99static void __maybe_unused see_output(void)
100{
101 video_sync_all();
102 while (1);
103}
104
Simon Glass8df8dad2016-01-14 18:10:50 -0700105/* Select the video console driver to use for a video device */
106static int select_vidconsole(struct unit_test_state *uts, const char *drv_name)
107{
108 struct sandbox_sdl_plat *plat;
109 struct udevice *dev;
110
111 ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
112 ut_assert(!device_active(dev));
Simon Glassc69cda22020-12-03 16:55:20 -0700113 plat = dev_get_plat(dev);
Simon Glass8df8dad2016-01-14 18:10:50 -0700114 plat->vidconsole_drv_name = "vidconsole0";
115
116 return 0;
117}
118
Simon Glass84e63ab2021-11-19 13:24:03 -0700119/**
120 * video_get_nologo() - Disable the logo on the video device and return it
121 *
122 * @uts: Test state
123 * @devp: Returns video device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100124 * Return: 0 if OK, -ve on error
Simon Glass84e63ab2021-11-19 13:24:03 -0700125 */
126static int video_get_nologo(struct unit_test_state *uts, struct udevice **devp)
127{
128 struct video_uc_plat *uc_plat;
129 struct udevice *dev;
130
131 ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
132 ut_assertnonnull(dev);
133 uc_plat = dev_get_uclass_plat(dev);
134 uc_plat->hide_logo = true;
135
136 /* now probe it */
137 ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
138 ut_assertnonnull(dev);
139 *devp = dev;
140
141 return 0;
142}
143
Simon Glass3c97c4f2016-01-18 19:52:26 -0700144/* Test text output works on the video console */
145static int dm_test_video_text(struct unit_test_state *uts)
146{
147 struct udevice *dev, *con;
148 int i;
149
150#define WHITE 0xffff
151#define SCROLL_LINES 100
152
Simon Glass8df8dad2016-01-14 18:10:50 -0700153 ut_assertok(select_vidconsole(uts, "vidconsole0"));
Simon Glass84e63ab2021-11-19 13:24:03 -0700154 ut_assertok(video_get_nologo(uts, &dev));
Dzmitry Sankouski72471622023-03-07 13:21:20 +0300155 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
156 ut_assertok(vidconsole_select_font(con, "8x16", 0));
Simon Glassf578ca72020-07-02 21:12:29 -0600157 ut_asserteq(46, compress_frame_buffer(uts, dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700158
159 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
160 vidconsole_putc_xy(con, 0, 0, 'a');
Simon Glassf578ca72020-07-02 21:12:29 -0600161 ut_asserteq(79, compress_frame_buffer(uts, dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700162
163 vidconsole_putc_xy(con, 0, 0, ' ');
Simon Glassf578ca72020-07-02 21:12:29 -0600164 ut_asserteq(46, compress_frame_buffer(uts, dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700165
166 for (i = 0; i < 20; i++)
Simon Glassf2661782016-01-14 18:10:37 -0700167 vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
Simon Glassf578ca72020-07-02 21:12:29 -0600168 ut_asserteq(273, compress_frame_buffer(uts, dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700169
170 vidconsole_set_row(con, 0, WHITE);
Simon Glassf578ca72020-07-02 21:12:29 -0600171 ut_asserteq(46, compress_frame_buffer(uts, dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700172
173 for (i = 0; i < 20; i++)
Simon Glassf2661782016-01-14 18:10:37 -0700174 vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
Simon Glassf578ca72020-07-02 21:12:29 -0600175 ut_asserteq(273, compress_frame_buffer(uts, dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700176
177 return 0;
178}
Simon Glasse180c2b2020-07-28 19:41:12 -0600179DM_TEST(dm_test_video_text, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass3c97c4f2016-01-18 19:52:26 -0700180
Dzmitry Sankouski72471622023-03-07 13:21:20 +0300181static int dm_test_video_text_12x22(struct unit_test_state *uts)
182{
183 struct udevice *dev, *con;
184 int i;
185
186#define WHITE 0xffff
187#define SCROLL_LINES 100
188
189 ut_assertok(select_vidconsole(uts, "vidconsole0"));
190 ut_assertok(video_get_nologo(uts, &dev));
191 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
192 ut_assertok(vidconsole_select_font(con, "12x22", 0));
193 ut_asserteq(46, compress_frame_buffer(uts, dev));
194
195 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
196 vidconsole_putc_xy(con, 0, 0, 'a');
197 ut_asserteq(89, compress_frame_buffer(uts, dev));
198
199 vidconsole_putc_xy(con, 0, 0, ' ');
200 ut_asserteq(46, compress_frame_buffer(uts, dev));
201
202 for (i = 0; i < 20; i++)
203 vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
204 ut_asserteq(363, compress_frame_buffer(uts, dev));
205
206 vidconsole_set_row(con, 0, WHITE);
207 ut_asserteq(46, compress_frame_buffer(uts, dev));
208
209 for (i = 0; i < 20; i++)
210 vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
211 ut_asserteq(363, compress_frame_buffer(uts, dev));
212
213 return 0;
214}
215DM_TEST(dm_test_video_text_12x22, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
216
Simon Glass3c97c4f2016-01-18 19:52:26 -0700217/* Test handling of special characters in the console */
218static int dm_test_video_chars(struct unit_test_state *uts)
219{
220 struct udevice *dev, *con;
Simon Glass5508f102016-01-14 18:10:38 -0700221 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 -0700222
Simon Glass8df8dad2016-01-14 18:10:50 -0700223 ut_assertok(select_vidconsole(uts, "vidconsole0"));
Simon Glass84e63ab2021-11-19 13:24:03 -0700224 ut_assertok(video_get_nologo(uts, &dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700225 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
Dzmitry Sankouski72471622023-03-07 13:21:20 +0300226 ut_assertok(vidconsole_select_font(con, "8x16", 0));
Rob Clarka7495ac2017-09-25 15:45:08 -0400227 vidconsole_put_string(con, test_string);
Simon Glassf578ca72020-07-02 21:12:29 -0600228 ut_asserteq(466, compress_frame_buffer(uts, dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700229
230 return 0;
231}
Simon Glasse180c2b2020-07-28 19:41:12 -0600232DM_TEST(dm_test_video_chars, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass3c97c4f2016-01-18 19:52:26 -0700233
Rob Clark40186ee2017-09-25 15:45:09 -0400234#ifdef CONFIG_VIDEO_ANSI
235#define ANSI_ESC "\x1b"
236/* Test handling of ANSI escape sequences */
237static int dm_test_video_ansi(struct unit_test_state *uts)
238{
239 struct udevice *dev, *con;
240
241 ut_assertok(select_vidconsole(uts, "vidconsole0"));
Simon Glass84e63ab2021-11-19 13:24:03 -0700242 ut_assertok(video_get_nologo(uts, &dev));
Rob Clark40186ee2017-09-25 15:45:09 -0400243 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
Dzmitry Sankouski72471622023-03-07 13:21:20 +0300244 ut_assertok(vidconsole_select_font(con, "8x16", 0));
Rob Clark40186ee2017-09-25 15:45:09 -0400245
246 /* reference clear: */
247 video_clear(con->parent);
Simon Glass55d39912018-10-01 11:55:14 -0600248 video_sync(con->parent, false);
Simon Glassf578ca72020-07-02 21:12:29 -0600249 ut_asserteq(46, compress_frame_buffer(uts, dev));
Rob Clark40186ee2017-09-25 15:45:09 -0400250
251 /* test clear escape sequence: [2J */
252 vidconsole_put_string(con, "A\tB\tC"ANSI_ESC"[2J");
Simon Glassf578ca72020-07-02 21:12:29 -0600253 ut_asserteq(46, compress_frame_buffer(uts, dev));
Rob Clark40186ee2017-09-25 15:45:09 -0400254
255 /* test set-cursor: [%d;%df */
256 vidconsole_put_string(con, "abc"ANSI_ESC"[2;2fab"ANSI_ESC"[4;4fcd");
Simon Glassf578ca72020-07-02 21:12:29 -0600257 ut_asserteq(143, compress_frame_buffer(uts, dev));
Rob Clark40186ee2017-09-25 15:45:09 -0400258
259 /* test colors (30-37 fg color, 40-47 bg color) */
260 vidconsole_put_string(con, ANSI_ESC"[30;41mfoo"); /* black on red */
261 vidconsole_put_string(con, ANSI_ESC"[33;44mbar"); /* yellow on blue */
Simon Glassf578ca72020-07-02 21:12:29 -0600262 ut_asserteq(272, compress_frame_buffer(uts, dev));
Rob Clark40186ee2017-09-25 15:45:09 -0400263
264 return 0;
265}
Simon Glasse180c2b2020-07-28 19:41:12 -0600266DM_TEST(dm_test_video_ansi, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Rob Clark40186ee2017-09-25 15:45:09 -0400267#endif
268
Simon Glass3c97c4f2016-01-18 19:52:26 -0700269/**
270 * check_vidconsole_output() - Run a text console test
271 *
272 * @uts: Test state
Simon Glassef453122020-07-02 21:12:28 -0600273 * @rot: Console rotation (0=normal orientation, 1=90 degrees clockwise,
274 * 2=upside down, 3=90 degree counterclockwise)
Simon Glass3c97c4f2016-01-18 19:52:26 -0700275 * @wrap_size: Expected size of compressed frame buffer for the wrap test
276 * @scroll_size: Same for the scroll test
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100277 * Return: 0 on success
Simon Glass3c97c4f2016-01-18 19:52:26 -0700278 */
279static int check_vidconsole_output(struct unit_test_state *uts, int rot,
280 int wrap_size, int scroll_size)
281{
282 struct udevice *dev, *con;
283 struct sandbox_sdl_plat *plat;
284 int i;
285
286 ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
287 ut_assert(!device_active(dev));
Simon Glassc69cda22020-12-03 16:55:20 -0700288 plat = dev_get_plat(dev);
Simon Glass3c97c4f2016-01-18 19:52:26 -0700289 plat->rot = rot;
290
Simon Glass84e63ab2021-11-19 13:24:03 -0700291 ut_assertok(video_get_nologo(uts, &dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700292 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
Dzmitry Sankouski72471622023-03-07 13:21:20 +0300293 ut_assertok(vidconsole_select_font(con, "8x16", 0));
Simon Glassf578ca72020-07-02 21:12:29 -0600294 ut_asserteq(46, compress_frame_buffer(uts, dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700295
296 /* Check display wrap */
297 for (i = 0; i < 120; i++)
298 vidconsole_put_char(con, 'A' + i % 50);
Simon Glassf578ca72020-07-02 21:12:29 -0600299 ut_asserteq(wrap_size, compress_frame_buffer(uts, dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700300
301 /* Check display scrolling */
302 for (i = 0; i < SCROLL_LINES; i++) {
303 vidconsole_put_char(con, 'A' + i % 50);
304 vidconsole_put_char(con, '\n');
305 }
Simon Glassf578ca72020-07-02 21:12:29 -0600306 ut_asserteq(scroll_size, compress_frame_buffer(uts, dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700307
308 /* If we scroll enough, the screen becomes blank again */
309 for (i = 0; i < SCROLL_LINES; i++)
310 vidconsole_put_char(con, '\n');
Simon Glassf578ca72020-07-02 21:12:29 -0600311 ut_asserteq(46, compress_frame_buffer(uts, dev));
Simon Glass3c97c4f2016-01-18 19:52:26 -0700312
313 return 0;
314}
315
316/* Test text output through the console uclass */
317static int dm_test_video_context(struct unit_test_state *uts)
318{
Simon Glass8df8dad2016-01-14 18:10:50 -0700319 ut_assertok(select_vidconsole(uts, "vidconsole0"));
320 ut_assertok(check_vidconsole_output(uts, 0, 788, 453));
321
322 return 0;
Simon Glass3c97c4f2016-01-18 19:52:26 -0700323}
Simon Glasse180c2b2020-07-28 19:41:12 -0600324DM_TEST(dm_test_video_context, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass85e08db2016-01-18 19:52:27 -0700325
326/* Test rotated text output through the console uclass */
327static int dm_test_video_rotation1(struct unit_test_state *uts)
328{
329 ut_assertok(check_vidconsole_output(uts, 1, 1112, 680));
330
331 return 0;
332}
Simon Glasse180c2b2020-07-28 19:41:12 -0600333DM_TEST(dm_test_video_rotation1, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass85e08db2016-01-18 19:52:27 -0700334
335/* Test rotated text output through the console uclass */
336static int dm_test_video_rotation2(struct unit_test_state *uts)
337{
Simon Glass9beb3642020-07-02 21:12:17 -0600338 ut_assertok(check_vidconsole_output(uts, 2, 783, 445));
Simon Glass85e08db2016-01-18 19:52:27 -0700339
340 return 0;
341}
Simon Glasse180c2b2020-07-28 19:41:12 -0600342DM_TEST(dm_test_video_rotation2, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass85e08db2016-01-18 19:52:27 -0700343
344/* Test rotated text output through the console uclass */
345static int dm_test_video_rotation3(struct unit_test_state *uts)
346{
347 ut_assertok(check_vidconsole_output(uts, 3, 1134, 681));
348
349 return 0;
350}
Simon Glasse180c2b2020-07-28 19:41:12 -0600351DM_TEST(dm_test_video_rotation3, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass747440d2016-01-18 19:52:28 -0700352
353/* Read a file into memory and return a pointer to it */
354static int read_file(struct unit_test_state *uts, const char *fname,
355 ulong *addrp)
356{
357 int buf_size = 100000;
358 ulong addr = 0;
359 int size, fd;
360 char *buf;
361
362 buf = map_sysmem(addr, 0);
363 ut_assert(buf != NULL);
364 fd = os_open(fname, OS_O_RDONLY);
365 ut_assert(fd >= 0);
366 size = os_read(fd, buf, buf_size);
Simon Glassa1080822016-01-30 15:45:17 -0700367 os_close(fd);
Simon Glass747440d2016-01-18 19:52:28 -0700368 ut_assert(size >= 0);
369 ut_assert(size < buf_size);
Simon Glass747440d2016-01-18 19:52:28 -0700370 *addrp = addr;
371
372 return 0;
373}
374
375/* Test drawing a bitmap file */
376static int dm_test_video_bmp(struct unit_test_state *uts)
377{
378 struct udevice *dev;
379 ulong addr;
380
Simon Glass84e63ab2021-11-19 13:24:03 -0700381 ut_assertok(video_get_nologo(uts, &dev));
Simon Glass747440d2016-01-18 19:52:28 -0700382 ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
383
384 ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
Simon Glassf578ca72020-07-02 21:12:29 -0600385 ut_asserteq(1368, compress_frame_buffer(uts, dev));
Simon Glass747440d2016-01-18 19:52:28 -0700386
387 return 0;
388}
Simon Glasse180c2b2020-07-28 19:41:12 -0600389DM_TEST(dm_test_video_bmp, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass747440d2016-01-18 19:52:28 -0700390
Simon Glass8657ad42021-11-19 13:23:50 -0700391/* Test drawing a bitmap file on a 8bpp display */
392static int dm_test_video_bmp8(struct unit_test_state *uts)
393{
394 struct udevice *dev;
395 ulong addr;
396
397 ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
398 ut_assertnonnull(dev);
399 ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP8));
400
401 ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
402
403 ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
404 ut_asserteq(1247, compress_frame_buffer(uts, dev));
405
406 return 0;
407}
408DM_TEST(dm_test_video_bmp8, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
409
Simon Glassc1cad062021-11-19 13:23:58 -0700410/* Test drawing a bitmap file on a 16bpp display */
411static int dm_test_video_bmp16(struct unit_test_state *uts)
412{
413 ulong src, src_len = ~0UL;
414 uint dst_len = ~0U;
415 struct udevice *dev;
416 ulong dst = 0x10000;
417
418 ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
419 ut_assertnonnull(dev);
420 ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP16));
421
422 ut_assertok(read_file(uts, "tools/logos/denx-16bpp.bmp.gz", &src));
423 ut_assertok(gunzip(map_sysmem(dst, 0), dst_len, map_sysmem(src, 0),
424 &src_len));
425
426 ut_assertok(video_bmp_display(dev, dst, 0, 0, false));
427 ut_asserteq(3700, compress_frame_buffer(uts, dev));
428
429 return 0;
430}
431DM_TEST(dm_test_video_bmp16, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
432
Simon Glass4ea15482021-11-19 13:23:59 -0700433/* Test drawing a 24bpp bitmap file on a 16bpp display */
434static int dm_test_video_bmp24(struct unit_test_state *uts)
435{
436 ulong src, src_len = ~0UL;
437 uint dst_len = ~0U;
438 struct udevice *dev;
439 ulong dst = 0x10000;
440
441 ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
442 ut_assertnonnull(dev);
443 ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP16));
444
445 ut_assertok(read_file(uts, "tools/logos/denx-24bpp.bmp.gz", &src));
446 ut_assertok(gunzip(map_sysmem(dst, 0), dst_len, map_sysmem(src, 0),
447 &src_len));
448
449 ut_assertok(video_bmp_display(dev, dst, 0, 0, false));
450 ut_asserteq(3656, compress_frame_buffer(uts, dev));
451
452 return 0;
453}
454DM_TEST(dm_test_video_bmp24, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
455
456/* Test drawing a 24bpp bitmap file on a 32bpp display */
457static int dm_test_video_bmp24_32(struct unit_test_state *uts)
458{
459 ulong src, src_len = ~0UL;
460 uint dst_len = ~0U;
461 struct udevice *dev;
462 ulong dst = 0x10000;
463
464 ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
465 ut_assertnonnull(dev);
466 ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32));
467
468 ut_assertok(read_file(uts, "tools/logos/denx-24bpp.bmp.gz", &src));
469 ut_assertok(gunzip(map_sysmem(dst, 0), dst_len, map_sysmem(src, 0),
470 &src_len));
471
472 ut_assertok(video_bmp_display(dev, dst, 0, 0, false));
473 ut_asserteq(6827, compress_frame_buffer(uts, dev));
474
475 return 0;
476}
477DM_TEST(dm_test_video_bmp24_32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
478
Simon Glass8657ad42021-11-19 13:23:50 -0700479/* Test drawing a bitmap file on a 32bpp display */
480static int dm_test_video_bmp32(struct unit_test_state *uts)
481{
482 struct udevice *dev;
483 ulong addr;
484
485 ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
486 ut_assertnonnull(dev);
487 ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32));
488 ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
489
490 ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
491 ut_asserteq(2024, compress_frame_buffer(uts, dev));
492
493 return 0;
494}
495DM_TEST(dm_test_video_bmp32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
496
Simon Glass747440d2016-01-18 19:52:28 -0700497/* Test drawing a compressed bitmap file */
498static int dm_test_video_bmp_comp(struct unit_test_state *uts)
499{
500 struct udevice *dev;
501 ulong addr;
502
Simon Glass84e63ab2021-11-19 13:24:03 -0700503 ut_assertok(video_get_nologo(uts, &dev));
Simon Glass747440d2016-01-18 19:52:28 -0700504 ut_assertok(read_file(uts, "tools/logos/denx-comp.bmp", &addr));
505
506 ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
Simon Glassf578ca72020-07-02 21:12:29 -0600507 ut_asserteq(1368, compress_frame_buffer(uts, dev));
Simon Glass747440d2016-01-18 19:52:28 -0700508
509 return 0;
510}
Simon Glasse180c2b2020-07-28 19:41:12 -0600511DM_TEST(dm_test_video_bmp_comp, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass5674ead2016-01-14 18:10:51 -0700512
Simon Glass646e1692021-11-19 13:23:55 -0700513/* Test drawing a bitmap file on a 32bpp display */
514static int dm_test_video_comp_bmp32(struct unit_test_state *uts)
515{
516 struct udevice *dev;
517 ulong addr;
518
519 ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
520 ut_assertnonnull(dev);
521 ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32));
522
523 ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
524
525 ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
526 ut_asserteq(2024, compress_frame_buffer(uts, dev));
527
528 return 0;
529}
530DM_TEST(dm_test_video_comp_bmp32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
531
532/* Test drawing a bitmap file on a 8bpp display */
533static int dm_test_video_comp_bmp8(struct unit_test_state *uts)
534{
535 struct udevice *dev;
536 ulong addr;
537
538 ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
539 ut_assertnonnull(dev);
540 ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP8));
541
542 ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
543
544 ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
545 ut_asserteq(1247, compress_frame_buffer(uts, dev));
546
547 return 0;
548}
549DM_TEST(dm_test_video_comp_bmp8, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
550
Simon Glass5674ead2016-01-14 18:10:51 -0700551/* Test TrueType console */
552static int dm_test_video_truetype(struct unit_test_state *uts)
553{
554 struct udevice *dev, *con;
555 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 -0700556
Simon Glass84e63ab2021-11-19 13:24:03 -0700557 ut_assertok(video_get_nologo(uts, &dev));
Simon Glass5674ead2016-01-14 18:10:51 -0700558 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
Rob Clarka7495ac2017-09-25 15:45:08 -0400559 vidconsole_put_string(con, test_string);
Simon Glass04f3dcd2023-06-01 10:23:04 -0600560 ut_asserteq(12174, compress_frame_buffer(uts, dev));
Simon Glass5674ead2016-01-14 18:10:51 -0700561
562 return 0;
563}
Simon Glasse180c2b2020-07-28 19:41:12 -0600564DM_TEST(dm_test_video_truetype, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass5674ead2016-01-14 18:10:51 -0700565
566/* Test scrolling TrueType console */
567static int dm_test_video_truetype_scroll(struct unit_test_state *uts)
568{
569 struct sandbox_sdl_plat *plat;
570 struct udevice *dev, *con;
571 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 -0700572
573 ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
574 ut_assert(!device_active(dev));
Simon Glassc69cda22020-12-03 16:55:20 -0700575 plat = dev_get_plat(dev);
Simon Glass5674ead2016-01-14 18:10:51 -0700576 plat->font_size = 100;
577
Simon Glass84e63ab2021-11-19 13:24:03 -0700578 ut_assertok(video_get_nologo(uts, &dev));
Simon Glass5674ead2016-01-14 18:10:51 -0700579 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
Rob Clarka7495ac2017-09-25 15:45:08 -0400580 vidconsole_put_string(con, test_string);
Simon Glass04f3dcd2023-06-01 10:23:04 -0600581 ut_asserteq(34287, compress_frame_buffer(uts, dev));
Simon Glass5674ead2016-01-14 18:10:51 -0700582
583 return 0;
584}
Simon Glasse180c2b2020-07-28 19:41:12 -0600585DM_TEST(dm_test_video_truetype_scroll, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass5674ead2016-01-14 18:10:51 -0700586
587/* Test TrueType backspace, within and across lines */
588static int dm_test_video_truetype_bs(struct unit_test_state *uts)
589{
590 struct sandbox_sdl_plat *plat;
591 struct udevice *dev, *con;
592 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 -0700593
594 ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
595 ut_assert(!device_active(dev));
Simon Glassc69cda22020-12-03 16:55:20 -0700596 plat = dev_get_plat(dev);
Simon Glass5674ead2016-01-14 18:10:51 -0700597 plat->font_size = 100;
598
Simon Glass84e63ab2021-11-19 13:24:03 -0700599 ut_assertok(video_get_nologo(uts, &dev));
Simon Glass5674ead2016-01-14 18:10:51 -0700600 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
Rob Clarka7495ac2017-09-25 15:45:08 -0400601 vidconsole_put_string(con, test_string);
Simon Glass04f3dcd2023-06-01 10:23:04 -0600602 ut_asserteq(29471, compress_frame_buffer(uts, dev));
Simon Glass5674ead2016-01-14 18:10:51 -0700603
604 return 0;
605}
Simon Glasse180c2b2020-07-28 19:41:12 -0600606DM_TEST(dm_test_video_truetype_bs, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);