]>
git.ipfire.org Git - people/ms/u-boot.git/blob - test/dm/video.c
2 * Copyright (c) 2014 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
5 * SPDX-License-Identifier: GPL-2.0+
14 #include <video_console.h>
16 #include <dm/uclass-internal.h>
20 * These tests use the standard sandbox frame buffer, the resolution of which
21 * is defined in the device tree. This only supports 16bpp so the tests only
22 * test that code path. It would be possible to adjust this fairly easily,
23 * by adjusting the bpix value in struct sandbox_sdl_plat. However the code
24 * in sandbox_sdl_sync() would also need to change to handle the different
27 DECLARE_GLOBAL_DATA_PTR
;
29 /* Basic test of the video uclass */
30 static int dm_test_video_base(struct unit_test_state
*uts
)
32 struct video_priv
*priv
;
35 ut_assertok(uclass_get_device(UCLASS_VIDEO
, 0, &dev
));
36 ut_asserteq(1366, video_get_xsize(dev
));
37 ut_asserteq(768, video_get_ysize(dev
));
38 priv
= dev_get_uclass_priv(dev
);
39 ut_asserteq(priv
->fb_size
, 1366 * 768 * 2);
43 DM_TEST(dm_test_video_base
, DM_TESTF_SCAN_PDATA
| DM_TESTF_SCAN_FDT
);
46 * compress_frame_buffer() - Compress the frame buffer and return its size
48 * We want to write tests which perform operations on the video console and
49 * check that the frame buffer ends up with the correct contents. But it is
50 * painful to store 'known good' images for comparison with the frame
51 * buffer. As an alternative, we can compress the frame buffer and check the
52 * size of the compressed data. This provides a pretty good level of
53 * certainty and the resulting tests need only check a single value.
56 * @return compressed size of the frame buffer, or -ve on error
58 static int compress_frame_buffer(struct udevice
*dev
)
60 struct video_priv
*priv
= dev_get_uclass_priv(dev
);
65 destlen
= priv
->fb_size
;
66 dest
= malloc(priv
->fb_size
);
69 ret
= BZ2_bzBuffToBuffCompress(dest
, &destlen
,
70 priv
->fb
, priv
->fb_size
,
80 * Call this function at any point to halt and show the current display. Be
81 * sure to run the test with the -l flag.
83 static void __maybe_unused
see_output(void)
89 /* Test text output works on the video console */
90 static int dm_test_video_text(struct unit_test_state
*uts
)
92 struct udevice
*dev
, *con
;
96 #define SCROLL_LINES 100
98 ut_assertok(uclass_get_device(UCLASS_VIDEO
, 0, &dev
));
99 ut_asserteq(46, compress_frame_buffer(dev
));
101 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE
, 0, &con
));
102 vidconsole_putc_xy(con
, 0, 0, 'a');
103 ut_asserteq(79, compress_frame_buffer(dev
));
105 vidconsole_putc_xy(con
, 0, 0, ' ');
106 ut_asserteq(46, compress_frame_buffer(dev
));
108 for (i
= 0; i
< 20; i
++)
109 vidconsole_putc_xy(con
, i
* 8, 0, ' ' + i
);
110 ut_asserteq(273, compress_frame_buffer(dev
));
112 vidconsole_set_row(con
, 0, WHITE
);
113 ut_asserteq(46, compress_frame_buffer(dev
));
115 for (i
= 0; i
< 20; i
++)
116 vidconsole_putc_xy(con
, i
* 8, 0, ' ' + i
);
117 ut_asserteq(273, compress_frame_buffer(dev
));
121 DM_TEST(dm_test_video_text
, DM_TESTF_SCAN_PDATA
| DM_TESTF_SCAN_FDT
);
123 /* Test handling of special characters in the console */
124 static int dm_test_video_chars(struct unit_test_state
*uts
)
126 struct udevice
*dev
, *con
;
127 const char *test_string
= "Well\b\b\b\bxhe is\r \n\ta very modest \bman\n\t\tand Has much to\b\bto be modest about.";
130 ut_assertok(uclass_get_device(UCLASS_VIDEO
, 0, &dev
));
131 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE
, 0, &con
));
132 for (s
= test_string
; *s
; s
++)
133 vidconsole_put_char(con
, *s
);
134 ut_asserteq(466, compress_frame_buffer(dev
));
138 DM_TEST(dm_test_video_chars
, DM_TESTF_SCAN_PDATA
| DM_TESTF_SCAN_FDT
);
141 * check_vidconsole_output() - Run a text console test
144 * @rot: Console rotation (0, 90, 180, 270)
145 * @wrap_size: Expected size of compressed frame buffer for the wrap test
146 * @scroll_size: Same for the scroll test
147 * @return 0 on success
149 static int check_vidconsole_output(struct unit_test_state
*uts
, int rot
,
150 int wrap_size
, int scroll_size
)
152 struct udevice
*dev
, *con
;
153 struct sandbox_sdl_plat
*plat
;
156 ut_assertok(uclass_find_device(UCLASS_VIDEO
, 0, &dev
));
157 ut_assert(!device_active(dev
));
158 plat
= dev_get_platdata(dev
);
161 ut_assertok(uclass_get_device(UCLASS_VIDEO
, 0, &dev
));
162 ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE
, 0, &con
));
163 ut_asserteq(46, compress_frame_buffer(dev
));
165 /* Check display wrap */
166 for (i
= 0; i
< 120; i
++)
167 vidconsole_put_char(con
, 'A' + i
% 50);
168 ut_asserteq(wrap_size
, compress_frame_buffer(dev
));
170 /* Check display scrolling */
171 for (i
= 0; i
< SCROLL_LINES
; i
++) {
172 vidconsole_put_char(con
, 'A' + i
% 50);
173 vidconsole_put_char(con
, '\n');
175 ut_asserteq(scroll_size
, compress_frame_buffer(dev
));
177 /* If we scroll enough, the screen becomes blank again */
178 for (i
= 0; i
< SCROLL_LINES
; i
++)
179 vidconsole_put_char(con
, '\n');
180 ut_asserteq(46, compress_frame_buffer(dev
));
185 /* Test text output through the console uclass */
186 static int dm_test_video_context(struct unit_test_state
*uts
)
188 return check_vidconsole_output(uts
, 0, 788, 453);
190 DM_TEST(dm_test_video_context
, DM_TESTF_SCAN_PDATA
| DM_TESTF_SCAN_FDT
);
192 /* Test rotated text output through the console uclass */
193 static int dm_test_video_rotation1(struct unit_test_state
*uts
)
195 ut_assertok(check_vidconsole_output(uts
, 1, 1112, 680));
199 DM_TEST(dm_test_video_rotation1
, DM_TESTF_SCAN_PDATA
| DM_TESTF_SCAN_FDT
);
201 /* Test rotated text output through the console uclass */
202 static int dm_test_video_rotation2(struct unit_test_state
*uts
)
204 ut_assertok(check_vidconsole_output(uts
, 2, 785, 446));
208 DM_TEST(dm_test_video_rotation2
, DM_TESTF_SCAN_PDATA
| DM_TESTF_SCAN_FDT
);
210 /* Test rotated text output through the console uclass */
211 static int dm_test_video_rotation3(struct unit_test_state
*uts
)
213 ut_assertok(check_vidconsole_output(uts
, 3, 1134, 681));
217 DM_TEST(dm_test_video_rotation3
, DM_TESTF_SCAN_PDATA
| DM_TESTF_SCAN_FDT
);