Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <bzlib.h> |
| 9 | #include <dm.h> |
Simon Glass | c1cad06 | 2021-11-19 13:23:58 -0700 | [diff] [blame] | 10 | #include <gzip.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 12 | #include <malloc.h> |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 13 | #include <mapmem.h> |
| 14 | #include <os.h> |
| 15 | #include <video.h> |
| 16 | #include <video_console.h> |
Simon Glass | 8657ad4 | 2021-11-19 13:23:50 -0700 | [diff] [blame] | 17 | #include <asm/test.h> |
Sergei Antonov | 76e1607 | 2023-06-13 00:19:04 +0300 | [diff] [blame] | 18 | #include <asm/sdl.h> |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 19 | #include <dm/test.h> |
| 20 | #include <dm/uclass-internal.h> |
Simon Glass | 0e1fad4 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 21 | #include <test/test.h> |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 22 | #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 Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 32 | /* Basic test of the video uclass */ |
| 33 | static 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 Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 46 | DM_TEST(dm_test_video_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 47 | |
| 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 Glass | f578ca7 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 58 | * If the copy framebuffer is enabled, this compares it to the main framebuffer |
| 59 | * too. |
| 60 | * |
| 61 | * @uts: Test state |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 62 | * @dev: Video device |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 63 | * Return: compressed size of the frame buffer, or -ve on error |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 64 | */ |
Simon Glass | f578ca7 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 65 | static int compress_frame_buffer(struct unit_test_state *uts, |
| 66 | struct udevice *dev) |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 67 | { |
| 68 | struct video_priv *priv = dev_get_uclass_priv(dev); |
Simon Glass | f578ca7 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 69 | struct video_priv *uc_priv = dev_get_uclass_priv(dev); |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 70 | 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 Glass | f578ca7 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 85 | /* 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 Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 92 | 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 | */ |
| 99 | static void __maybe_unused see_output(void) |
| 100 | { |
| 101 | video_sync_all(); |
| 102 | while (1); |
| 103 | } |
| 104 | |
Simon Glass | 8df8dad | 2016-01-14 18:10:50 -0700 | [diff] [blame] | 105 | /* Select the video console driver to use for a video device */ |
| 106 | static 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 Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 113 | plat = dev_get_plat(dev); |
Simon Glass | 8df8dad | 2016-01-14 18:10:50 -0700 | [diff] [blame] | 114 | plat->vidconsole_drv_name = "vidconsole0"; |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
Simon Glass | 84e63ab | 2021-11-19 13:24:03 -0700 | [diff] [blame] | 119 | /** |
| 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 Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 124 | * Return: 0 if OK, -ve on error |
Simon Glass | 84e63ab | 2021-11-19 13:24:03 -0700 | [diff] [blame] | 125 | */ |
| 126 | static 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 Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 144 | /* Test text output works on the video console */ |
| 145 | static 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 Glass | 8df8dad | 2016-01-14 18:10:50 -0700 | [diff] [blame] | 153 | ut_assertok(select_vidconsole(uts, "vidconsole0")); |
Simon Glass | 84e63ab | 2021-11-19 13:24:03 -0700 | [diff] [blame] | 154 | ut_assertok(video_get_nologo(uts, &dev)); |
Dzmitry Sankouski | 7247162 | 2023-03-07 13:21:20 +0300 | [diff] [blame] | 155 | ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); |
| 156 | ut_assertok(vidconsole_select_font(con, "8x16", 0)); |
Simon Glass | f578ca7 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 157 | ut_asserteq(46, compress_frame_buffer(uts, dev)); |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 158 | |
| 159 | ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); |
| 160 | vidconsole_putc_xy(con, 0, 0, 'a'); |
Simon Glass | f578ca7 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 161 | ut_asserteq(79, compress_frame_buffer(uts, dev)); |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 162 | |
| 163 | vidconsole_putc_xy(con, 0, 0, ' '); |
Simon Glass | f578ca7 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 164 | ut_asserteq(46, compress_frame_buffer(uts, dev)); |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 165 | |
| 166 | for (i = 0; i < 20; i++) |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 167 | vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i); |
Simon Glass | f578ca7 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 168 | ut_asserteq(273, compress_frame_buffer(uts, dev)); |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 169 | |
| 170 | vidconsole_set_row(con, 0, WHITE); |
Simon Glass | f578ca7 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 171 | ut_asserteq(46, compress_frame_buffer(uts, dev)); |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 172 | |
| 173 | for (i = 0; i < 20; i++) |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 174 | vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i); |
Simon Glass | f578ca7 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 175 | ut_asserteq(273, compress_frame_buffer(uts, dev)); |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 176 | |
| 177 | return 0; |
| 178 | } |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 179 | DM_TEST(dm_test_video_text, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 180 | |
Dzmitry Sankouski | 7247162 | 2023-03-07 13:21:20 +0300 | [diff] [blame] | 181 | static 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 | } |
| 215 | DM_TEST(dm_test_video_text_12x22, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
| 216 | |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 217 | /* Test handling of special characters in the console */ |
| 218 | static int dm_test_video_chars(struct unit_test_state *uts) |
| 219 | { |
| 220 | struct udevice *dev, *con; |
Simon Glass | 5508f10 | 2016-01-14 18:10:38 -0700 | [diff] [blame] | 221 | 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 Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 222 | |
Simon Glass | 8df8dad | 2016-01-14 18:10:50 -0700 | [diff] [blame] | 223 | ut_assertok(select_vidconsole(uts, "vidconsole0")); |
Simon Glass | 84e63ab | 2021-11-19 13:24:03 -0700 | [diff] [blame] | 224 | ut_assertok(video_get_nologo(uts, &dev)); |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 225 | ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); |
Dzmitry Sankouski | 7247162 | 2023-03-07 13:21:20 +0300 | [diff] [blame] | 226 | ut_assertok(vidconsole_select_font(con, "8x16", 0)); |
Rob Clark | a7495ac | 2017-09-25 15:45:08 -0400 | [diff] [blame] | 227 | vidconsole_put_string(con, test_string); |
Simon Glass | f578ca7 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 228 | ut_asserteq(466, compress_frame_buffer(uts, dev)); |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 229 | |
| 230 | return 0; |
| 231 | } |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 232 | DM_TEST(dm_test_video_chars, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 233 | |
Rob Clark | 40186ee | 2017-09-25 15:45:09 -0400 | [diff] [blame] | 234 | #ifdef CONFIG_VIDEO_ANSI |
| 235 | #define ANSI_ESC "\x1b" |
| 236 | /* Test handling of ANSI escape sequences */ |
| 237 | static 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 Glass | 84e63ab | 2021-11-19 13:24:03 -0700 | [diff] [blame] | 242 | ut_assertok(video_get_nologo(uts, &dev)); |
Rob Clark | 40186ee | 2017-09-25 15:45:09 -0400 | [diff] [blame] | 243 | ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); |
Dzmitry Sankouski | 7247162 | 2023-03-07 13:21:20 +0300 | [diff] [blame] | 244 | ut_assertok(vidconsole_select_font(con, "8x16", 0)); |
Rob Clark | 40186ee | 2017-09-25 15:45:09 -0400 | [diff] [blame] | 245 | |
| 246 | /* reference clear: */ |
| 247 | video_clear(con->parent); |
Simon Glass | 55d3991 | 2018-10-01 11:55:14 -0600 | [diff] [blame] | 248 | video_sync(con->parent, false); |
Simon Glass | f578ca7 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 249 | ut_asserteq(46, compress_frame_buffer(uts, dev)); |
Rob Clark | 40186ee | 2017-09-25 15:45:09 -0400 | [diff] [blame] | 250 | |
| 251 | /* test clear escape sequence: [2J */ |
| 252 | vidconsole_put_string(con, "A\tB\tC"ANSI_ESC"[2J"); |
Simon Glass | f578ca7 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 253 | ut_asserteq(46, compress_frame_buffer(uts, dev)); |
Rob Clark | 40186ee | 2017-09-25 15:45:09 -0400 | [diff] [blame] | 254 | |
| 255 | /* test set-cursor: [%d;%df */ |
| 256 | vidconsole_put_string(con, "abc"ANSI_ESC"[2;2fab"ANSI_ESC"[4;4fcd"); |
Simon Glass | f578ca7 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 257 | ut_asserteq(143, compress_frame_buffer(uts, dev)); |
Rob Clark | 40186ee | 2017-09-25 15:45:09 -0400 | [diff] [blame] | 258 | |
| 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 Glass | f578ca7 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 262 | ut_asserteq(272, compress_frame_buffer(uts, dev)); |
Rob Clark | 40186ee | 2017-09-25 15:45:09 -0400 | [diff] [blame] | 263 | |
| 264 | return 0; |
| 265 | } |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 266 | DM_TEST(dm_test_video_ansi, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Rob Clark | 40186ee | 2017-09-25 15:45:09 -0400 | [diff] [blame] | 267 | #endif |
| 268 | |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 269 | /** |
| 270 | * check_vidconsole_output() - Run a text console test |
| 271 | * |
| 272 | * @uts: Test state |
Simon Glass | ef45312 | 2020-07-02 21:12:28 -0600 | [diff] [blame] | 273 | * @rot: Console rotation (0=normal orientation, 1=90 degrees clockwise, |
| 274 | * 2=upside down, 3=90 degree counterclockwise) |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 275 | * @wrap_size: Expected size of compressed frame buffer for the wrap test |
| 276 | * @scroll_size: Same for the scroll test |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 277 | * Return: 0 on success |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 278 | */ |
| 279 | static 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 Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 288 | plat = dev_get_plat(dev); |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 289 | plat->rot = rot; |
| 290 | |
Simon Glass | 84e63ab | 2021-11-19 13:24:03 -0700 | [diff] [blame] | 291 | ut_assertok(video_get_nologo(uts, &dev)); |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 292 | ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); |
Dzmitry Sankouski | 7247162 | 2023-03-07 13:21:20 +0300 | [diff] [blame] | 293 | ut_assertok(vidconsole_select_font(con, "8x16", 0)); |
Simon Glass | f578ca7 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 294 | ut_asserteq(46, compress_frame_buffer(uts, dev)); |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 295 | |
| 296 | /* Check display wrap */ |
| 297 | for (i = 0; i < 120; i++) |
| 298 | vidconsole_put_char(con, 'A' + i % 50); |
Simon Glass | f578ca7 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 299 | ut_asserteq(wrap_size, compress_frame_buffer(uts, dev)); |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 300 | |
| 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 Glass | f578ca7 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 306 | ut_asserteq(scroll_size, compress_frame_buffer(uts, dev)); |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 307 | |
| 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 Glass | f578ca7 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 311 | ut_asserteq(46, compress_frame_buffer(uts, dev)); |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 312 | |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | /* Test text output through the console uclass */ |
| 317 | static int dm_test_video_context(struct unit_test_state *uts) |
| 318 | { |
Simon Glass | 8df8dad | 2016-01-14 18:10:50 -0700 | [diff] [blame] | 319 | ut_assertok(select_vidconsole(uts, "vidconsole0")); |
| 320 | ut_assertok(check_vidconsole_output(uts, 0, 788, 453)); |
| 321 | |
| 322 | return 0; |
Simon Glass | 3c97c4f | 2016-01-18 19:52:26 -0700 | [diff] [blame] | 323 | } |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 324 | DM_TEST(dm_test_video_context, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Simon Glass | 85e08db | 2016-01-18 19:52:27 -0700 | [diff] [blame] | 325 | |
| 326 | /* Test rotated text output through the console uclass */ |
| 327 | static 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 Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 333 | DM_TEST(dm_test_video_rotation1, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Simon Glass | 85e08db | 2016-01-18 19:52:27 -0700 | [diff] [blame] | 334 | |
| 335 | /* Test rotated text output through the console uclass */ |
| 336 | static int dm_test_video_rotation2(struct unit_test_state *uts) |
| 337 | { |
Simon Glass | 9beb364 | 2020-07-02 21:12:17 -0600 | [diff] [blame] | 338 | ut_assertok(check_vidconsole_output(uts, 2, 783, 445)); |
Simon Glass | 85e08db | 2016-01-18 19:52:27 -0700 | [diff] [blame] | 339 | |
| 340 | return 0; |
| 341 | } |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 342 | DM_TEST(dm_test_video_rotation2, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Simon Glass | 85e08db | 2016-01-18 19:52:27 -0700 | [diff] [blame] | 343 | |
| 344 | /* Test rotated text output through the console uclass */ |
| 345 | static 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 Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 351 | DM_TEST(dm_test_video_rotation3, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Simon Glass | 747440d | 2016-01-18 19:52:28 -0700 | [diff] [blame] | 352 | |
| 353 | /* Read a file into memory and return a pointer to it */ |
| 354 | static 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 Glass | a108082 | 2016-01-30 15:45:17 -0700 | [diff] [blame] | 367 | os_close(fd); |
Simon Glass | 747440d | 2016-01-18 19:52:28 -0700 | [diff] [blame] | 368 | ut_assert(size >= 0); |
| 369 | ut_assert(size < buf_size); |
Simon Glass | 747440d | 2016-01-18 19:52:28 -0700 | [diff] [blame] | 370 | *addrp = addr; |
| 371 | |
| 372 | return 0; |
| 373 | } |
| 374 | |
| 375 | /* Test drawing a bitmap file */ |
| 376 | static int dm_test_video_bmp(struct unit_test_state *uts) |
| 377 | { |
| 378 | struct udevice *dev; |
| 379 | ulong addr; |
| 380 | |
Simon Glass | 84e63ab | 2021-11-19 13:24:03 -0700 | [diff] [blame] | 381 | ut_assertok(video_get_nologo(uts, &dev)); |
Simon Glass | 747440d | 2016-01-18 19:52:28 -0700 | [diff] [blame] | 382 | ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr)); |
| 383 | |
| 384 | ut_assertok(video_bmp_display(dev, addr, 0, 0, false)); |
Simon Glass | f578ca7 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 385 | ut_asserteq(1368, compress_frame_buffer(uts, dev)); |
Simon Glass | 747440d | 2016-01-18 19:52:28 -0700 | [diff] [blame] | 386 | |
| 387 | return 0; |
| 388 | } |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 389 | DM_TEST(dm_test_video_bmp, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Simon Glass | 747440d | 2016-01-18 19:52:28 -0700 | [diff] [blame] | 390 | |
Simon Glass | 8657ad4 | 2021-11-19 13:23:50 -0700 | [diff] [blame] | 391 | /* Test drawing a bitmap file on a 8bpp display */ |
| 392 | static 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 | } |
| 408 | DM_TEST(dm_test_video_bmp8, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
| 409 | |
Simon Glass | c1cad06 | 2021-11-19 13:23:58 -0700 | [diff] [blame] | 410 | /* Test drawing a bitmap file on a 16bpp display */ |
| 411 | static 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 | } |
| 431 | DM_TEST(dm_test_video_bmp16, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
| 432 | |
Simon Glass | 4ea1548 | 2021-11-19 13:23:59 -0700 | [diff] [blame] | 433 | /* Test drawing a 24bpp bitmap file on a 16bpp display */ |
| 434 | static 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 | } |
| 454 | DM_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 */ |
| 457 | static 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 | } |
| 477 | DM_TEST(dm_test_video_bmp24_32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
| 478 | |
Simon Glass | 8657ad4 | 2021-11-19 13:23:50 -0700 | [diff] [blame] | 479 | /* Test drawing a bitmap file on a 32bpp display */ |
| 480 | static 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 | } |
| 495 | DM_TEST(dm_test_video_bmp32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
| 496 | |
Simon Glass | 747440d | 2016-01-18 19:52:28 -0700 | [diff] [blame] | 497 | /* Test drawing a compressed bitmap file */ |
| 498 | static int dm_test_video_bmp_comp(struct unit_test_state *uts) |
| 499 | { |
| 500 | struct udevice *dev; |
| 501 | ulong addr; |
| 502 | |
Simon Glass | 84e63ab | 2021-11-19 13:24:03 -0700 | [diff] [blame] | 503 | ut_assertok(video_get_nologo(uts, &dev)); |
Simon Glass | 747440d | 2016-01-18 19:52:28 -0700 | [diff] [blame] | 504 | ut_assertok(read_file(uts, "tools/logos/denx-comp.bmp", &addr)); |
| 505 | |
| 506 | ut_assertok(video_bmp_display(dev, addr, 0, 0, false)); |
Simon Glass | f578ca7 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 507 | ut_asserteq(1368, compress_frame_buffer(uts, dev)); |
Simon Glass | 747440d | 2016-01-18 19:52:28 -0700 | [diff] [blame] | 508 | |
| 509 | return 0; |
| 510 | } |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 511 | DM_TEST(dm_test_video_bmp_comp, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Simon Glass | 5674ead | 2016-01-14 18:10:51 -0700 | [diff] [blame] | 512 | |
Simon Glass | 646e169 | 2021-11-19 13:23:55 -0700 | [diff] [blame] | 513 | /* Test drawing a bitmap file on a 32bpp display */ |
| 514 | static 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 | } |
| 530 | DM_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 */ |
| 533 | static 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 | } |
| 549 | DM_TEST(dm_test_video_comp_bmp8, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
| 550 | |
Simon Glass | 5674ead | 2016-01-14 18:10:51 -0700 | [diff] [blame] | 551 | /* Test TrueType console */ |
| 552 | static 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 Glass | 5674ead | 2016-01-14 18:10:51 -0700 | [diff] [blame] | 556 | |
Simon Glass | 84e63ab | 2021-11-19 13:24:03 -0700 | [diff] [blame] | 557 | ut_assertok(video_get_nologo(uts, &dev)); |
Simon Glass | 5674ead | 2016-01-14 18:10:51 -0700 | [diff] [blame] | 558 | ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); |
Rob Clark | a7495ac | 2017-09-25 15:45:08 -0400 | [diff] [blame] | 559 | vidconsole_put_string(con, test_string); |
Simon Glass | 04f3dcd | 2023-06-01 10:23:04 -0600 | [diff] [blame] | 560 | ut_asserteq(12174, compress_frame_buffer(uts, dev)); |
Simon Glass | 5674ead | 2016-01-14 18:10:51 -0700 | [diff] [blame] | 561 | |
| 562 | return 0; |
| 563 | } |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 564 | DM_TEST(dm_test_video_truetype, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Simon Glass | 5674ead | 2016-01-14 18:10:51 -0700 | [diff] [blame] | 565 | |
| 566 | /* Test scrolling TrueType console */ |
| 567 | static 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 Glass | 5674ead | 2016-01-14 18:10:51 -0700 | [diff] [blame] | 572 | |
| 573 | ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev)); |
| 574 | ut_assert(!device_active(dev)); |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 575 | plat = dev_get_plat(dev); |
Simon Glass | 5674ead | 2016-01-14 18:10:51 -0700 | [diff] [blame] | 576 | plat->font_size = 100; |
| 577 | |
Simon Glass | 84e63ab | 2021-11-19 13:24:03 -0700 | [diff] [blame] | 578 | ut_assertok(video_get_nologo(uts, &dev)); |
Simon Glass | 5674ead | 2016-01-14 18:10:51 -0700 | [diff] [blame] | 579 | ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); |
Rob Clark | a7495ac | 2017-09-25 15:45:08 -0400 | [diff] [blame] | 580 | vidconsole_put_string(con, test_string); |
Simon Glass | 04f3dcd | 2023-06-01 10:23:04 -0600 | [diff] [blame] | 581 | ut_asserteq(34287, compress_frame_buffer(uts, dev)); |
Simon Glass | 5674ead | 2016-01-14 18:10:51 -0700 | [diff] [blame] | 582 | |
| 583 | return 0; |
| 584 | } |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 585 | DM_TEST(dm_test_video_truetype_scroll, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Simon Glass | 5674ead | 2016-01-14 18:10:51 -0700 | [diff] [blame] | 586 | |
| 587 | /* Test TrueType backspace, within and across lines */ |
| 588 | static 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 Glass | 5674ead | 2016-01-14 18:10:51 -0700 | [diff] [blame] | 593 | |
| 594 | ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev)); |
| 595 | ut_assert(!device_active(dev)); |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 596 | plat = dev_get_plat(dev); |
Simon Glass | 5674ead | 2016-01-14 18:10:51 -0700 | [diff] [blame] | 597 | plat->font_size = 100; |
| 598 | |
Simon Glass | 84e63ab | 2021-11-19 13:24:03 -0700 | [diff] [blame] | 599 | ut_assertok(video_get_nologo(uts, &dev)); |
Simon Glass | 5674ead | 2016-01-14 18:10:51 -0700 | [diff] [blame] | 600 | ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); |
Rob Clark | a7495ac | 2017-09-25 15:45:08 -0400 | [diff] [blame] | 601 | vidconsole_put_string(con, test_string); |
Simon Glass | 04f3dcd | 2023-06-01 10:23:04 -0600 | [diff] [blame] | 602 | ut_asserteq(29471, compress_frame_buffer(uts, dev)); |
Simon Glass | 5674ead | 2016-01-14 18:10:51 -0700 | [diff] [blame] | 603 | |
| 604 | return 0; |
| 605 | } |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 606 | DM_TEST(dm_test_video_truetype_bs, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |