video.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2014 Google, Inc
  4. * Written by Simon Glass <sjg@chromium.org>
  5. */
  6. #include <common.h>
  7. #include <bzlib.h>
  8. #include <dm.h>
  9. #include <gzip.h>
  10. #include <log.h>
  11. #include <malloc.h>
  12. #include <mapmem.h>
  13. #include <os.h>
  14. #include <video.h>
  15. #include <video_console.h>
  16. #include <asm/test.h>
  17. #include <asm/sdl.h>
  18. #include <dm/test.h>
  19. #include <dm/uclass-internal.h>
  20. #include <test/test.h>
  21. #include <test/ut.h>
  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. */
  30. /* Basic test of the video uclass */
  31. static int dm_test_video_base(struct unit_test_state *uts)
  32. {
  33. struct video_priv *priv;
  34. struct udevice *dev;
  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);
  40. return 0;
  41. }
  42. DM_TEST(dm_test_video_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  43. /**
  44. * compress_frame_buffer() - Compress the frame buffer and return its size
  45. *
  46. * We want to write tests which perform operations on the video console and
  47. * check that the frame buffer ends up with the correct contents. But it is
  48. * painful to store 'known good' images for comparison with the frame
  49. * buffer. As an alternative, we can compress the frame buffer and check the
  50. * size of the compressed data. This provides a pretty good level of
  51. * certainty and the resulting tests need only check a single value.
  52. *
  53. * If the copy framebuffer is enabled, this compares it to the main framebuffer
  54. * too.
  55. *
  56. * @uts: Test state
  57. * @dev: Video device
  58. * Return: compressed size of the frame buffer, or -ve on error
  59. */
  60. static int compress_frame_buffer(struct unit_test_state *uts,
  61. struct udevice *dev)
  62. {
  63. struct video_priv *priv = dev_get_uclass_priv(dev);
  64. struct video_priv *uc_priv = dev_get_uclass_priv(dev);
  65. uint destlen;
  66. void *dest;
  67. int ret;
  68. destlen = priv->fb_size;
  69. dest = malloc(priv->fb_size);
  70. if (!dest)
  71. return -ENOMEM;
  72. ret = BZ2_bzBuffToBuffCompress(dest, &destlen,
  73. priv->fb, priv->fb_size,
  74. 3, 0, 0);
  75. free(dest);
  76. if (ret)
  77. return ret;
  78. /* Check here that the copy frame buffer is working correctly */
  79. if (IS_ENABLED(CONFIG_VIDEO_COPY)) {
  80. ut_assertf(!memcmp(uc_priv->fb, uc_priv->copy_fb,
  81. uc_priv->fb_size),
  82. "Copy framebuffer does not match fb");
  83. }
  84. return destlen;
  85. }
  86. /*
  87. * Call this function at any point to halt and show the current display. Be
  88. * sure to run the test with the -l flag.
  89. */
  90. static void __maybe_unused see_output(void)
  91. {
  92. video_sync_all();
  93. while (1);
  94. }
  95. /* Select the video console driver to use for a video device */
  96. static int select_vidconsole(struct unit_test_state *uts, const char *drv_name)
  97. {
  98. struct sandbox_sdl_plat *plat;
  99. struct udevice *dev;
  100. ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
  101. ut_assert(!device_active(dev));
  102. plat = dev_get_plat(dev);
  103. plat->vidconsole_drv_name = "vidconsole0";
  104. return 0;
  105. }
  106. /**
  107. * video_get_nologo() - Disable the logo on the video device and return it
  108. *
  109. * @uts: Test state
  110. * @devp: Returns video device
  111. * Return: 0 if OK, -ve on error
  112. */
  113. static int video_get_nologo(struct unit_test_state *uts, struct udevice **devp)
  114. {
  115. struct video_uc_plat *uc_plat;
  116. struct udevice *dev;
  117. ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
  118. ut_assertnonnull(dev);
  119. uc_plat = dev_get_uclass_plat(dev);
  120. uc_plat->hide_logo = true;
  121. /* now probe it */
  122. ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
  123. ut_assertnonnull(dev);
  124. *devp = dev;
  125. return 0;
  126. }
  127. /* Test text output works on the video console */
  128. static int dm_test_video_text(struct unit_test_state *uts)
  129. {
  130. struct udevice *dev, *con;
  131. int i;
  132. #define WHITE 0xffff
  133. #define SCROLL_LINES 100
  134. ut_assertok(select_vidconsole(uts, "vidconsole0"));
  135. ut_assertok(video_get_nologo(uts, &dev));
  136. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  137. ut_assertok(vidconsole_select_font(con, "8x16", 0));
  138. ut_asserteq(46, compress_frame_buffer(uts, dev));
  139. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  140. vidconsole_putc_xy(con, 0, 0, 'a');
  141. ut_asserteq(79, compress_frame_buffer(uts, dev));
  142. vidconsole_putc_xy(con, 0, 0, ' ');
  143. ut_asserteq(46, compress_frame_buffer(uts, dev));
  144. for (i = 0; i < 20; i++)
  145. vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
  146. ut_asserteq(273, compress_frame_buffer(uts, dev));
  147. vidconsole_set_row(con, 0, WHITE);
  148. ut_asserteq(46, compress_frame_buffer(uts, dev));
  149. for (i = 0; i < 20; i++)
  150. vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
  151. ut_asserteq(273, compress_frame_buffer(uts, dev));
  152. return 0;
  153. }
  154. DM_TEST(dm_test_video_text, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  155. static int dm_test_video_text_12x22(struct unit_test_state *uts)
  156. {
  157. struct udevice *dev, *con;
  158. int i;
  159. #define WHITE 0xffff
  160. #define SCROLL_LINES 100
  161. ut_assertok(select_vidconsole(uts, "vidconsole0"));
  162. ut_assertok(video_get_nologo(uts, &dev));
  163. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  164. ut_assertok(vidconsole_select_font(con, "12x22", 0));
  165. ut_asserteq(46, compress_frame_buffer(uts, dev));
  166. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  167. vidconsole_putc_xy(con, 0, 0, 'a');
  168. ut_asserteq(89, compress_frame_buffer(uts, dev));
  169. vidconsole_putc_xy(con, 0, 0, ' ');
  170. ut_asserteq(46, compress_frame_buffer(uts, dev));
  171. for (i = 0; i < 20; i++)
  172. vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
  173. ut_asserteq(363, compress_frame_buffer(uts, dev));
  174. vidconsole_set_row(con, 0, WHITE);
  175. ut_asserteq(46, compress_frame_buffer(uts, dev));
  176. for (i = 0; i < 20; i++)
  177. vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
  178. ut_asserteq(363, compress_frame_buffer(uts, dev));
  179. return 0;
  180. }
  181. DM_TEST(dm_test_video_text_12x22, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  182. /* Test handling of special characters in the console */
  183. static int dm_test_video_chars(struct unit_test_state *uts)
  184. {
  185. struct udevice *dev, *con;
  186. 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.";
  187. ut_assertok(select_vidconsole(uts, "vidconsole0"));
  188. ut_assertok(video_get_nologo(uts, &dev));
  189. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  190. ut_assertok(vidconsole_select_font(con, "8x16", 0));
  191. vidconsole_put_string(con, test_string);
  192. ut_asserteq(466, compress_frame_buffer(uts, dev));
  193. return 0;
  194. }
  195. DM_TEST(dm_test_video_chars, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  196. #ifdef CONFIG_VIDEO_ANSI
  197. #define ANSI_ESC "\x1b"
  198. /* Test handling of ANSI escape sequences */
  199. static int dm_test_video_ansi(struct unit_test_state *uts)
  200. {
  201. struct udevice *dev, *con;
  202. ut_assertok(select_vidconsole(uts, "vidconsole0"));
  203. ut_assertok(video_get_nologo(uts, &dev));
  204. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  205. ut_assertok(vidconsole_select_font(con, "8x16", 0));
  206. /* reference clear: */
  207. video_clear(con->parent);
  208. video_sync(con->parent, false);
  209. ut_asserteq(46, compress_frame_buffer(uts, dev));
  210. /* test clear escape sequence: [2J */
  211. vidconsole_put_string(con, "A\tB\tC"ANSI_ESC"[2J");
  212. ut_asserteq(46, compress_frame_buffer(uts, dev));
  213. /* test set-cursor: [%d;%df */
  214. vidconsole_put_string(con, "abc"ANSI_ESC"[2;2fab"ANSI_ESC"[4;4fcd");
  215. ut_asserteq(143, compress_frame_buffer(uts, dev));
  216. /* test colors (30-37 fg color, 40-47 bg color) */
  217. vidconsole_put_string(con, ANSI_ESC"[30;41mfoo"); /* black on red */
  218. vidconsole_put_string(con, ANSI_ESC"[33;44mbar"); /* yellow on blue */
  219. ut_asserteq(272, compress_frame_buffer(uts, dev));
  220. return 0;
  221. }
  222. DM_TEST(dm_test_video_ansi, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  223. #endif
  224. /**
  225. * check_vidconsole_output() - Run a text console test
  226. *
  227. * @uts: Test state
  228. * @rot: Console rotation (0=normal orientation, 1=90 degrees clockwise,
  229. * 2=upside down, 3=90 degree counterclockwise)
  230. * @wrap_size: Expected size of compressed frame buffer for the wrap test
  231. * @scroll_size: Same for the scroll test
  232. * Return: 0 on success
  233. */
  234. static int check_vidconsole_output(struct unit_test_state *uts, int rot,
  235. int wrap_size, int scroll_size)
  236. {
  237. struct udevice *dev, *con;
  238. struct sandbox_sdl_plat *plat;
  239. int i;
  240. ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
  241. ut_assert(!device_active(dev));
  242. plat = dev_get_plat(dev);
  243. plat->rot = rot;
  244. ut_assertok(video_get_nologo(uts, &dev));
  245. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  246. ut_assertok(vidconsole_select_font(con, "8x16", 0));
  247. ut_asserteq(46, compress_frame_buffer(uts, dev));
  248. /* Check display wrap */
  249. for (i = 0; i < 120; i++)
  250. vidconsole_put_char(con, 'A' + i % 50);
  251. ut_asserteq(wrap_size, compress_frame_buffer(uts, dev));
  252. /* Check display scrolling */
  253. for (i = 0; i < SCROLL_LINES; i++) {
  254. vidconsole_put_char(con, 'A' + i % 50);
  255. vidconsole_put_char(con, '\n');
  256. }
  257. ut_asserteq(scroll_size, compress_frame_buffer(uts, dev));
  258. /* If we scroll enough, the screen becomes blank again */
  259. for (i = 0; i < SCROLL_LINES; i++)
  260. vidconsole_put_char(con, '\n');
  261. ut_asserteq(46, compress_frame_buffer(uts, dev));
  262. return 0;
  263. }
  264. /* Test text output through the console uclass */
  265. static int dm_test_video_context(struct unit_test_state *uts)
  266. {
  267. ut_assertok(select_vidconsole(uts, "vidconsole0"));
  268. ut_assertok(check_vidconsole_output(uts, 0, 788, 453));
  269. return 0;
  270. }
  271. DM_TEST(dm_test_video_context, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  272. /* Test rotated text output through the console uclass */
  273. static int dm_test_video_rotation1(struct unit_test_state *uts)
  274. {
  275. ut_assertok(check_vidconsole_output(uts, 1, 1112, 680));
  276. return 0;
  277. }
  278. DM_TEST(dm_test_video_rotation1, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  279. /* Test rotated text output through the console uclass */
  280. static int dm_test_video_rotation2(struct unit_test_state *uts)
  281. {
  282. ut_assertok(check_vidconsole_output(uts, 2, 783, 445));
  283. return 0;
  284. }
  285. DM_TEST(dm_test_video_rotation2, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  286. /* Test rotated text output through the console uclass */
  287. static int dm_test_video_rotation3(struct unit_test_state *uts)
  288. {
  289. ut_assertok(check_vidconsole_output(uts, 3, 1134, 681));
  290. return 0;
  291. }
  292. DM_TEST(dm_test_video_rotation3, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  293. /* Read a file into memory and return a pointer to it */
  294. static int read_file(struct unit_test_state *uts, const char *fname,
  295. ulong *addrp)
  296. {
  297. int buf_size = 100000;
  298. ulong addr = 0;
  299. int size, fd;
  300. char *buf;
  301. buf = map_sysmem(addr, 0);
  302. ut_assert(buf != NULL);
  303. fd = os_open(fname, OS_O_RDONLY);
  304. ut_assert(fd >= 0);
  305. size = os_read(fd, buf, buf_size);
  306. os_close(fd);
  307. ut_assert(size >= 0);
  308. ut_assert(size < buf_size);
  309. *addrp = addr;
  310. return 0;
  311. }
  312. /* Test drawing a bitmap file */
  313. static int dm_test_video_bmp(struct unit_test_state *uts)
  314. {
  315. struct udevice *dev;
  316. ulong addr;
  317. ut_assertok(video_get_nologo(uts, &dev));
  318. ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
  319. ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
  320. ut_asserteq(1368, compress_frame_buffer(uts, dev));
  321. return 0;
  322. }
  323. DM_TEST(dm_test_video_bmp, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  324. /* Test drawing a bitmap file on a 8bpp display */
  325. static int dm_test_video_bmp8(struct unit_test_state *uts)
  326. {
  327. struct udevice *dev;
  328. ulong addr;
  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. ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
  333. ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
  334. ut_asserteq(1247, compress_frame_buffer(uts, dev));
  335. return 0;
  336. }
  337. DM_TEST(dm_test_video_bmp8, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  338. /* Test drawing a bitmap file on a 16bpp display */
  339. static int dm_test_video_bmp16(struct unit_test_state *uts)
  340. {
  341. ulong src, src_len = ~0UL;
  342. uint dst_len = ~0U;
  343. struct udevice *dev;
  344. ulong dst = 0x10000;
  345. ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
  346. ut_assertnonnull(dev);
  347. ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP16));
  348. ut_assertok(read_file(uts, "tools/logos/denx-16bpp.bmp.gz", &src));
  349. ut_assertok(gunzip(map_sysmem(dst, 0), dst_len, map_sysmem(src, 0),
  350. &src_len));
  351. ut_assertok(video_bmp_display(dev, dst, 0, 0, false));
  352. ut_asserteq(3700, compress_frame_buffer(uts, dev));
  353. return 0;
  354. }
  355. DM_TEST(dm_test_video_bmp16, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  356. /* Test drawing a 24bpp bitmap file on a 16bpp display */
  357. static int dm_test_video_bmp24(struct unit_test_state *uts)
  358. {
  359. ulong src, src_len = ~0UL;
  360. uint dst_len = ~0U;
  361. struct udevice *dev;
  362. ulong dst = 0x10000;
  363. ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
  364. ut_assertnonnull(dev);
  365. ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP16));
  366. ut_assertok(read_file(uts, "tools/logos/denx-24bpp.bmp.gz", &src));
  367. ut_assertok(gunzip(map_sysmem(dst, 0), dst_len, map_sysmem(src, 0),
  368. &src_len));
  369. ut_assertok(video_bmp_display(dev, dst, 0, 0, false));
  370. ut_asserteq(3656, compress_frame_buffer(uts, dev));
  371. return 0;
  372. }
  373. DM_TEST(dm_test_video_bmp24, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  374. /* Test drawing a 24bpp bitmap file on a 32bpp display */
  375. static int dm_test_video_bmp24_32(struct unit_test_state *uts)
  376. {
  377. ulong src, src_len = ~0UL;
  378. uint dst_len = ~0U;
  379. struct udevice *dev;
  380. ulong dst = 0x10000;
  381. ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
  382. ut_assertnonnull(dev);
  383. ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32));
  384. ut_assertok(read_file(uts, "tools/logos/denx-24bpp.bmp.gz", &src));
  385. ut_assertok(gunzip(map_sysmem(dst, 0), dst_len, map_sysmem(src, 0),
  386. &src_len));
  387. ut_assertok(video_bmp_display(dev, dst, 0, 0, false));
  388. ut_asserteq(6827, compress_frame_buffer(uts, dev));
  389. return 0;
  390. }
  391. DM_TEST(dm_test_video_bmp24_32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  392. /* Test drawing a bitmap file on a 32bpp display */
  393. static int dm_test_video_bmp32(struct unit_test_state *uts)
  394. {
  395. struct udevice *dev;
  396. ulong addr;
  397. ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
  398. ut_assertnonnull(dev);
  399. ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32));
  400. ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
  401. ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
  402. ut_asserteq(2024, compress_frame_buffer(uts, dev));
  403. return 0;
  404. }
  405. DM_TEST(dm_test_video_bmp32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  406. /* Test drawing a compressed bitmap file */
  407. static int dm_test_video_bmp_comp(struct unit_test_state *uts)
  408. {
  409. struct udevice *dev;
  410. ulong addr;
  411. ut_assertok(video_get_nologo(uts, &dev));
  412. ut_assertok(read_file(uts, "tools/logos/denx-comp.bmp", &addr));
  413. ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
  414. ut_asserteq(1368, compress_frame_buffer(uts, dev));
  415. return 0;
  416. }
  417. DM_TEST(dm_test_video_bmp_comp, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  418. /* Test drawing a bitmap file on a 32bpp display */
  419. static int dm_test_video_comp_bmp32(struct unit_test_state *uts)
  420. {
  421. struct udevice *dev;
  422. ulong addr;
  423. ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
  424. ut_assertnonnull(dev);
  425. ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32));
  426. ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
  427. ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
  428. ut_asserteq(2024, compress_frame_buffer(uts, dev));
  429. return 0;
  430. }
  431. DM_TEST(dm_test_video_comp_bmp32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  432. /* Test drawing a bitmap file on a 8bpp display */
  433. static int dm_test_video_comp_bmp8(struct unit_test_state *uts)
  434. {
  435. struct udevice *dev;
  436. ulong addr;
  437. ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
  438. ut_assertnonnull(dev);
  439. ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP8));
  440. ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
  441. ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
  442. ut_asserteq(1247, compress_frame_buffer(uts, dev));
  443. return 0;
  444. }
  445. DM_TEST(dm_test_video_comp_bmp8, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  446. /* Test TrueType console */
  447. static int dm_test_video_truetype(struct unit_test_state *uts)
  448. {
  449. struct udevice *dev, *con;
  450. 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";
  451. ut_assertok(video_get_nologo(uts, &dev));
  452. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  453. vidconsole_put_string(con, test_string);
  454. ut_asserteq(12174, compress_frame_buffer(uts, dev));
  455. return 0;
  456. }
  457. DM_TEST(dm_test_video_truetype, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  458. /* Test scrolling TrueType console */
  459. static int dm_test_video_truetype_scroll(struct unit_test_state *uts)
  460. {
  461. struct sandbox_sdl_plat *plat;
  462. struct udevice *dev, *con;
  463. 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";
  464. ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
  465. ut_assert(!device_active(dev));
  466. plat = dev_get_plat(dev);
  467. plat->font_size = 100;
  468. ut_assertok(video_get_nologo(uts, &dev));
  469. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  470. vidconsole_put_string(con, test_string);
  471. ut_asserteq(34287, compress_frame_buffer(uts, dev));
  472. return 0;
  473. }
  474. DM_TEST(dm_test_video_truetype_scroll, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  475. /* Test TrueType backspace, within and across lines */
  476. static int dm_test_video_truetype_bs(struct unit_test_state *uts)
  477. {
  478. struct sandbox_sdl_plat *plat;
  479. struct udevice *dev, *con;
  480. 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.";
  481. ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
  482. ut_assert(!device_active(dev));
  483. plat = dev_get_plat(dev);
  484. plat->font_size = 100;
  485. ut_assertok(video_get_nologo(uts, &dev));
  486. ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
  487. vidconsole_put_string(con, test_string);
  488. ut_asserteq(29471, compress_frame_buffer(uts, dev));
  489. return 0;
  490. }
  491. DM_TEST(dm_test_video_truetype_bs, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);