Loading...
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (c) 2014 Google, Inc
 * Written by Simon Glass <sjg@chromium.org>
 */

#include <bzlib.h>
#include <dm.h>
#include <gzip.h>
#include <log.h>
#include <malloc.h>
#include <mapmem.h>
#include <os.h>
#include <video.h>
#include <video_console.h>
#include <asm/test.h>
#include <asm/sdl.h>
#include <dm/test.h>
#include <dm/uclass-internal.h>
#include <linux/delay.h>
#include <test/lib.h>
#include <test/test.h>
#include <test/ut.h>
#include <test/video.h>

/*
 * These tests use the standard sandbox frame buffer, the resolution of which
 * is defined in the device tree. This only supports 16bpp so the tests only
 * test that code path. It would be possible to adjust this fairly easily,
 * by adjusting the bpix value in struct sandbox_sdl_plat. However the code
 * in sandbox_sdl_sync() would also need to change to handle the different
 * surface depth.
 */
/* Basic test of the video uclass */
static int dm_test_video_base(struct unit_test_state *uts)
{
	struct video_priv *priv;
	struct udevice *dev;

	ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
	ut_asserteq(1366, video_get_xsize(dev));
	ut_asserteq(768, video_get_ysize(dev));
	priv = dev_get_uclass_priv(dev);
	ut_asserteq(priv->fb_size, 1366 * 768 * 2);

	return 0;
}
DM_TEST(dm_test_video_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);

int video_compress_fb(struct unit_test_state *uts, struct udevice *dev,
		      bool use_copy)
{
	struct video_priv *priv = dev_get_uclass_priv(dev);
	uint destlen;
	void *dest;
	int ret;

	if (!IS_ENABLED(CONFIG_VIDEO_COPY))
		use_copy = false;

	destlen = priv->fb_size;
	dest = malloc(priv->fb_size);
	if (!dest)
		return -ENOMEM;
	ret = BZ2_bzBuffToBuffCompress(dest, &destlen,
				       use_copy ? priv->copy_fb : priv->fb,
				       priv->fb_size,
				       3, 0, 0);
	free(dest);
	if (ret)
		return ret;

	/* provide a useful delay if #define LOG_DEBUG at the top of file */
	if (_DEBUG)
		mdelay(300);

	return destlen;
}

int video_check_copy_fb(struct unit_test_state *uts, struct udevice *dev)
{
	struct video_priv *priv = dev_get_uclass_priv(dev);

	if (!IS_ENABLED(CONFIG_VIDEO_COPY))
		return 0;

	video_sync(dev, false);
	ut_assertf(!memcmp(priv->fb, priv->copy_fb, priv->fb_size),
		   "Copy framebuffer does not match fb");

	return 0;
}

/*
 * Call this function at any point to halt and show the current display. Be
 * sure to run the test with the -l flag.
 */
static void __maybe_unused see_output(void)
{
	video_sync_all();
	while (1);
}

/* Select the video console driver to use for a video device */
static int select_vidconsole(struct unit_test_state *uts, const char *drv_name)
{
	struct sandbox_sdl_plat *plat;
	struct udevice *dev;

	ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
	ut_assert(!device_active(dev));
	plat = dev_get_plat(dev);
	plat->vidconsole_drv_name = "vidconsole0";

	return 0;
}

/**
 * video_get_nologo() - Disable the logo on the video device and return it
 *
 * @uts: Test state
 * @devp: Returns video device
 * Return: 0 if OK, -ve on error
 */
static int video_get_nologo(struct unit_test_state *uts, struct udevice **devp)
{
	struct video_uc_plat *uc_plat;
	struct udevice *dev;

	ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
	ut_assertnonnull(dev);
	uc_plat = dev_get_uclass_plat(dev);
	uc_plat->hide_logo = true;

	/* now probe it */
	ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
	ut_assertnonnull(dev);
	*devp = dev;

	return 0;
}

/* Test text output works on the video console */
static int dm_test_video_text(struct unit_test_state *uts)
{
	struct udevice *dev, *con;
	int i;

#define WHITE		0xffff
#define SCROLL_LINES	100

	ut_assertok(select_vidconsole(uts, "vidconsole0"));
	ut_assertok(video_get_nologo(uts, &dev));
	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
	ut_assertok(vidconsole_select_font(con, "8x16", 0));
	ut_asserteq(46, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
	vidconsole_putc_xy(con, 0, 0, 'a');
	ut_asserteq(79, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	vidconsole_putc_xy(con, 0, 0, ' ');
	ut_asserteq(46, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	for (i = 0; i < 20; i++)
		vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
	ut_asserteq(273, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	vidconsole_set_row(con, 0, WHITE);
	ut_asserteq(46, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	for (i = 0; i < 20; i++)
		vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
	ut_asserteq(273, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	return 0;
}
DM_TEST(dm_test_video_text, UTF_SCAN_PDATA | UTF_SCAN_FDT);

static int dm_test_video_text_12x22(struct unit_test_state *uts)
{
	struct udevice *dev, *con;
	int i;

#define WHITE		0xffff
#define SCROLL_LINES	100

	ut_assertok(select_vidconsole(uts, "vidconsole0"));
	ut_assertok(video_get_nologo(uts, &dev));
	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
	ut_assertok(vidconsole_select_font(con, "12x22", 0));
	ut_asserteq(46, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
	vidconsole_putc_xy(con, 0, 0, 'a');
	ut_asserteq(89, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	vidconsole_putc_xy(con, 0, 0, ' ');
	ut_asserteq(46, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	for (i = 0; i < 20; i++)
		vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
	ut_asserteq(363, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	vidconsole_set_row(con, 0, WHITE);
	ut_asserteq(46, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	for (i = 0; i < 20; i++)
		vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
	ut_asserteq(363, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	return 0;
}
DM_TEST(dm_test_video_text_12x22, UTF_SCAN_PDATA | UTF_SCAN_FDT);

/* Test handling of special characters in the console */
static int dm_test_video_chars(struct unit_test_state *uts)
{
	struct udevice *dev, *con;
	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.";

	ut_assertok(select_vidconsole(uts, "vidconsole0"));
	ut_assertok(video_get_nologo(uts, &dev));
	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
	ut_assertok(vidconsole_select_font(con, "8x16", 0));
	vidconsole_put_string(con, test_string);
	ut_asserteq(466, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	return 0;
}
DM_TEST(dm_test_video_chars, UTF_SCAN_PDATA | UTF_SCAN_FDT);

#ifdef CONFIG_VIDEO_ANSI
#define ANSI_ESC "\x1b"
/* Test handling of ANSI escape sequences */
static int dm_test_video_ansi(struct unit_test_state *uts)
{
	struct udevice *dev, *con;

	ut_assertok(select_vidconsole(uts, "vidconsole0"));
	ut_assertok(video_get_nologo(uts, &dev));
	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
	ut_assertok(vidconsole_select_font(con, "8x16", 0));

	/* reference clear: */
	video_clear(con->parent);
	video_sync(con->parent, false);
	ut_asserteq(46, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	/* test clear escape sequence: [2J */
	vidconsole_put_string(con, "A\tB\tC"ANSI_ESC"[2J");
	ut_asserteq(46, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	/* test set-cursor: [%d;%df */
	vidconsole_put_string(con, "abc"ANSI_ESC"[2;2fab"ANSI_ESC"[4;4fcd");
	ut_asserteq(143, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	/* test colors (30-37 fg color, 40-47 bg color) */
	vidconsole_put_string(con, ANSI_ESC"[30;41mfoo"); /* black on red */
	vidconsole_put_string(con, ANSI_ESC"[33;44mbar"); /* yellow on blue */
	ut_asserteq(272, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	return 0;
}
DM_TEST(dm_test_video_ansi, UTF_SCAN_PDATA | UTF_SCAN_FDT);
#endif

/**
 * check_vidconsole_output() - Run a text console test
 *
 * @uts:	Test state
 * @rot:	Console rotation (0=normal orientation, 1=90 degrees clockwise,
 *		2=upside down, 3=90 degree counterclockwise)
 * @wrap_size:	Expected size of compressed frame buffer for the wrap test
 * @scroll_size: Same for the scroll test
 * Return: 0 on success
 */
static int check_vidconsole_output(struct unit_test_state *uts, int rot,
				   int wrap_size, int scroll_size)
{
	struct udevice *dev, *con;
	struct sandbox_sdl_plat *plat;
	int i;

	ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
	ut_assert(!device_active(dev));
	plat = dev_get_plat(dev);
	plat->rot = rot;

	ut_assertok(video_get_nologo(uts, &dev));
	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
	ut_assertok(vidconsole_select_font(con, "8x16", 0));
	ut_asserteq(46, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	/* Check display wrap */
	for (i = 0; i < 120; i++)
		vidconsole_put_char(con, 'A' + i % 50);
	ut_asserteq(wrap_size, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	/* Check display scrolling */
	for (i = 0; i < SCROLL_LINES; i++) {
		vidconsole_put_char(con, 'A' + i % 50);
		vidconsole_put_char(con, '\n');
	}
	ut_asserteq(scroll_size, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	/* If we scroll enough, the screen becomes blank again */
	for (i = 0; i < SCROLL_LINES; i++)
		vidconsole_put_char(con, '\n');
	ut_asserteq(46, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	return 0;
}

/* Test text output through the console uclass */
static int dm_test_video_context(struct unit_test_state *uts)
{
	ut_assertok(select_vidconsole(uts, "vidconsole0"));
	ut_assertok(check_vidconsole_output(uts, 0, 788, 453));

	return 0;
}
DM_TEST(dm_test_video_context, UTF_SCAN_PDATA | UTF_SCAN_FDT);

/* Test rotated text output through the console uclass */
static int dm_test_video_rotation1(struct unit_test_state *uts)
{
	ut_assertok(check_vidconsole_output(uts, 1, 1112, 680));

	return 0;
}
DM_TEST(dm_test_video_rotation1, UTF_SCAN_PDATA | UTF_SCAN_FDT);

/* Test rotated text output through the console uclass */
static int dm_test_video_rotation2(struct unit_test_state *uts)
{
	ut_assertok(check_vidconsole_output(uts, 2, 783, 445));

	return 0;
}
DM_TEST(dm_test_video_rotation2, UTF_SCAN_PDATA | UTF_SCAN_FDT);

/* Test rotated text output through the console uclass */
static int dm_test_video_rotation3(struct unit_test_state *uts)
{
	ut_assertok(check_vidconsole_output(uts, 3, 1134, 681));

	return 0;
}
DM_TEST(dm_test_video_rotation3, UTF_SCAN_PDATA | UTF_SCAN_FDT);

/* Read a file into memory and return a pointer to it */
static int read_file(struct unit_test_state *uts, const char *fname,
		     ulong *addrp)
{
	int buf_size = 100000;
	ulong addr = 0;
	int size, fd;
	char *buf;

	buf = map_sysmem(addr, 0);
	ut_assert(buf != NULL);
	fd = os_open(fname, OS_O_RDONLY);
	ut_assert(fd >= 0);
	size = os_read(fd, buf, buf_size);
	os_close(fd);
	ut_assert(size >= 0);
	ut_assert(size < buf_size);
	*addrp = addr;

	return 0;
}

/* Test drawing a bitmap file */
static int dm_test_video_bmp(struct unit_test_state *uts)
{
	struct udevice *dev;
	ulong addr;

	ut_assertok(video_get_nologo(uts, &dev));
	ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));

	ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
	ut_asserteq(1368, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	return 0;
}
DM_TEST(dm_test_video_bmp, UTF_SCAN_PDATA | UTF_SCAN_FDT);

/* Test drawing a bitmap file on a 8bpp display */
static int dm_test_video_bmp8(struct unit_test_state *uts)
{
	struct udevice *dev;
	ulong addr;

	ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
	ut_assertnonnull(dev);
	ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP8));

	ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));

	ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
	ut_asserteq(1247, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	return 0;
}
DM_TEST(dm_test_video_bmp8, UTF_SCAN_PDATA | UTF_SCAN_FDT);

/* Test drawing a bitmap file on a 16bpp display */
static int dm_test_video_bmp16(struct unit_test_state *uts)
{
	ulong src, src_len = ~0UL;
	uint dst_len = ~0U;
	struct udevice *dev;
	ulong dst = 0x10000;

	ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
	ut_assertnonnull(dev);
	ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP16));

	ut_assertok(read_file(uts, "tools/logos/denx-16bpp.bmp.gz", &src));
	ut_assertok(gunzip(map_sysmem(dst, 0), dst_len, map_sysmem(src, 0),
			   &src_len));

	ut_assertok(video_bmp_display(dev, dst, 0, 0, false));
	ut_asserteq(3700, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	return 0;
}
DM_TEST(dm_test_video_bmp16, UTF_SCAN_PDATA | UTF_SCAN_FDT);

/* Test drawing a 24bpp bitmap file on a 16bpp display */
static int dm_test_video_bmp24(struct unit_test_state *uts)
{
	ulong src, src_len = ~0UL;
	uint dst_len = ~0U;
	struct udevice *dev;
	ulong dst = 0x10000;

	ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
	ut_assertnonnull(dev);
	ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP16));

	ut_assertok(read_file(uts, "tools/logos/denx-24bpp.bmp.gz", &src));
	ut_assertok(gunzip(map_sysmem(dst, 0), dst_len, map_sysmem(src, 0),
			   &src_len));

	ut_assertok(video_bmp_display(dev, dst, 0, 0, false));
	ut_asserteq(3656, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	return 0;
}
DM_TEST(dm_test_video_bmp24, UTF_SCAN_PDATA | UTF_SCAN_FDT);

/* Test drawing a 24bpp bitmap file on a 32bpp display */
static int dm_test_video_bmp24_32(struct unit_test_state *uts)
{
	ulong src, src_len = ~0UL;
	uint dst_len = ~0U;
	struct udevice *dev;
	ulong dst = 0x10000;

	ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
	ut_assertnonnull(dev);
	ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32));

	ut_assertok(read_file(uts, "tools/logos/denx-24bpp.bmp.gz", &src));
	ut_assertok(gunzip(map_sysmem(dst, 0), dst_len, map_sysmem(src, 0),
			   &src_len));

	ut_assertok(video_bmp_display(dev, dst, 0, 0, false));
	ut_asserteq(6827, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	return 0;
}
DM_TEST(dm_test_video_bmp24_32, UTF_SCAN_PDATA | UTF_SCAN_FDT);

/* Test drawing a bitmap file on a 32bpp display */
static int dm_test_video_bmp32(struct unit_test_state *uts)
{
	struct udevice *dev;
	ulong addr;

	ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
	ut_assertnonnull(dev);
	ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32));
	ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));

	ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
	ut_asserteq(2024, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	return 0;
}
DM_TEST(dm_test_video_bmp32, UTF_SCAN_PDATA | UTF_SCAN_FDT);

/* Test drawing a compressed bitmap file */
static int dm_test_video_bmp_comp(struct unit_test_state *uts)
{
	struct udevice *dev;
	ulong addr;

	ut_assertok(video_get_nologo(uts, &dev));
	ut_assertok(read_file(uts, "tools/logos/denx-comp.bmp", &addr));

	ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
	ut_asserteq(1368, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	return 0;
}
DM_TEST(dm_test_video_bmp_comp, UTF_SCAN_PDATA | UTF_SCAN_FDT);

/* Test drawing a bitmap file on a 32bpp display */
static int dm_test_video_comp_bmp32(struct unit_test_state *uts)
{
	struct udevice *dev;
	ulong addr;

	ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
	ut_assertnonnull(dev);
	ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32));

	ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));

	ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
	ut_asserteq(2024, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	return 0;
}
DM_TEST(dm_test_video_comp_bmp32, UTF_SCAN_PDATA | UTF_SCAN_FDT);

/* Test drawing a bitmap file on a 8bpp display */
static int dm_test_video_comp_bmp8(struct unit_test_state *uts)
{
	struct udevice *dev;
	ulong addr;

	ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
	ut_assertnonnull(dev);
	ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP8));

	ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));

	ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
	ut_asserteq(1247, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	return 0;
}
DM_TEST(dm_test_video_comp_bmp8, UTF_SCAN_PDATA | UTF_SCAN_FDT);

/* Test TrueType console */
static int dm_test_video_truetype(struct unit_test_state *uts)
{
	struct udevice *dev, *con;
	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";

	ut_assertok(video_get_nologo(uts, &dev));
	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
	vidconsole_put_string(con, test_string);
	vidconsole_put_stringn(con, test_string, 30);
	ut_asserteq(13073, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	return 0;
}
DM_TEST(dm_test_video_truetype, UTF_SCAN_PDATA | UTF_SCAN_FDT);

/* Test scrolling TrueType console */
static int dm_test_video_truetype_scroll(struct unit_test_state *uts)
{
	struct sandbox_sdl_plat *plat;
	struct udevice *dev, *con;
	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";

	ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
	ut_assert(!device_active(dev));
	plat = dev_get_plat(dev);
	plat->font_size = 100;

	ut_assertok(video_get_nologo(uts, &dev));
	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
	vidconsole_put_string(con, test_string);
	ut_asserteq(34248, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	return 0;
}
DM_TEST(dm_test_video_truetype_scroll, UTF_SCAN_PDATA | UTF_SCAN_FDT);

/* Test TrueType backspace, within and across lines */
static int dm_test_video_truetype_bs(struct unit_test_state *uts)
{
	struct sandbox_sdl_plat *plat;
	struct udevice *dev, *con;
	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.";

	ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
	ut_assert(!device_active(dev));
	plat = dev_get_plat(dev);
	plat->font_size = 100;

	ut_assertok(video_get_nologo(uts, &dev));
	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
	vidconsole_put_string(con, test_string);
	ut_asserteq(29310, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	return 0;
}
DM_TEST(dm_test_video_truetype_bs, UTF_SCAN_PDATA | UTF_SCAN_FDT);

/* Test partial rendering onto hardware frame buffer */
static int dm_test_video_copy(struct unit_test_state *uts)
{
	struct sandbox_sdl_plat *plat;
	struct video_uc_plat *uc_plat;
	struct udevice *dev, *con;
	struct video_priv *priv;
	const char *test_string = "\n\tCriticism may not be agreeable, but it "
		"is necessary.\t";
	ulong addr;

	if (!IS_ENABLED(CONFIG_VIDEO_COPY))
		return -EAGAIN;

	ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
	ut_assertnonnull(dev);
	uc_plat = dev_get_uclass_plat(dev);
	uc_plat->hide_logo = true;
	plat = dev_get_plat(dev);
	plat->font_size = 32;
	ut_assert(!device_active(dev));
	ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
	ut_assertnonnull(dev);
	priv = dev_get_uclass_priv(dev);

	ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
	ut_assertok(video_bmp_display(dev, addr, 0, 0, false));

	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
	vidconsole_put_string(con, "\n\n\n\n\n");
	vidconsole_put_string(con, test_string);
	vidconsole_put_string(con, test_string);

	ut_asserteq(6884, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	/*
	 * Secretly clear the hardware frame buffer, but in a different
	 * color (black) to see which parts will be overwritten.
	 */
	memset(priv->copy_fb, 0, priv->fb_size);

	/*
	 * We should have the full content on the main buffer, but only
	 * 'damage' should have been copied to the copy buffer. This consists
	 * of a while rectangle with the Denx logo and four lines of text. The
	 * rest of the display is black.
	 *
	 * An easy way to try this is by changing video_sync() to call
	 * sandbox_sdl_sync(priv->copy_fb) instead of priv->fb then running the
	 * unit test:
	 *
	 *   ./u-boot -Tl
	 *   ut dm dm_test_video_copy
	 */
	vidconsole_put_string(con, test_string);
	vidconsole_put_string(con, test_string);
	video_sync(dev, true);
	ut_asserteq(7621, video_compress_fb(uts, dev, false));
	ut_asserteq(7741, video_compress_fb(uts, dev, true));

	return 0;
}
DM_TEST(dm_test_video_copy, UTF_SCAN_PDATA | UTF_SCAN_FDT);

/* Test video damage tracking */
static int dm_test_video_damage(struct unit_test_state *uts)
{
	struct sandbox_sdl_plat *plat;
	struct udevice *dev, *con;
	struct video_priv *priv;
	const char *test_string_1 = "Criticism may not be agreeable, ";
	const char *test_string_2 = "but it is necessary.";
	const char *test_string_3 = "It fulfils the same function as pain in "
		"the human body.";

	if (!IS_ENABLED(CONFIG_VIDEO_DAMAGE))
		return -EAGAIN;

	ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
	ut_assert(!device_active(dev));
	plat = dev_get_plat(dev);
	plat->font_size = 32;

	ut_assertok(video_get_nologo(uts, &dev));
	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
	priv = dev_get_uclass_priv(dev);

	vidconsole_position_cursor(con, 14, 10);
	vidconsole_put_string(con, test_string_2);
	ut_asserteq(449, priv->damage.xstart);
	ut_asserteq(325, priv->damage.ystart);
	ut_asserteq(661, priv->damage.xend);
	ut_asserteq(350, priv->damage.yend);

	vidconsole_position_cursor(con, 7, 5);
	vidconsole_put_string(con, test_string_1);
	ut_asserteq(225, priv->damage.xstart);
	ut_asserteq(164, priv->damage.ystart);
	ut_asserteq(661, priv->damage.xend);
	ut_asserteq(350, priv->damage.yend);

	vidconsole_position_cursor(con, 21, 15);
	vidconsole_put_string(con, test_string_3);
	ut_asserteq(225, priv->damage.xstart);
	ut_asserteq(164, priv->damage.ystart);
	ut_asserteq(1280, priv->damage.xend);
	ut_asserteq(510, priv->damage.yend);

	video_sync(dev, true);
	ut_asserteq(priv->xsize, priv->damage.xstart);
	ut_asserteq(priv->ysize, priv->damage.ystart);
	ut_asserteq(0, priv->damage.xend);
	ut_asserteq(0, priv->damage.yend);

	ut_asserteq(7335, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	return 0;
}
DM_TEST(dm_test_video_damage, UTF_SCAN_PDATA | UTF_SCAN_FDT);

/* Test font measurement */
static int dm_test_font_measure(struct unit_test_state *uts)
{
	const char *test_string = "There is always much\nto be said for not "
		"attempting more than you can do and for making a certainty of "
		"what you try. But this principle, like others in life and "
		"war, has its exceptions.";
	const struct vidconsole_mline *line;
	struct vidconsole_bbox bbox;
	struct video_priv *priv;
	struct udevice *dev, *con;
	const int limit = 0x320;
	struct alist lines;
	int nl;

	ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
	priv = dev_get_uclass_priv(dev);
	ut_asserteq(1366, priv->xsize);
	ut_asserteq(768, priv->ysize);

	/* this is using the Nimbus font with size of 18 pixels */
	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
	vidconsole_position_cursor(con, 0, 0);
	alist_init_struct(&lines, struct vidconsole_mline);
	ut_assertok(vidconsole_measure(con, NULL, 0, test_string, -1, &bbox,
				       &lines));
	ut_asserteq(0, bbox.x0);
	ut_asserteq(0, bbox.y0);
	ut_asserteq(0x3ea, bbox.x1);
	ut_asserteq(0x24, bbox.y1);
	ut_asserteq(2, lines.count);

	nl = strchr(test_string, '\n') - test_string;

	line = alist_get(&lines, 0, struct vidconsole_mline);
	ut_assertnonnull(line);
	ut_asserteq(0, line->bbox.x0);
	ut_asserteq(0, line->bbox.y0);
	ut_asserteq(0x8c, line->bbox.x1);
	ut_asserteq(0x12, line->bbox.y1);
	ut_asserteq(0, line->start);
	ut_asserteq(20, line->len);
	ut_asserteq(nl, line->len);

	line++;
	ut_asserteq(0x0, line->bbox.x0);
	ut_asserteq(0x12, line->bbox.y0);
	ut_asserteq(0x3ea, line->bbox.x1);
	ut_asserteq(0x24, line->bbox.y1);
	ut_asserteq(21, line->start);
	ut_asserteq(nl + 1, line->start);
	ut_asserteq(163, line->len);
	ut_asserteq(strlen(test_string + nl + 1), line->len);

	/* now use a limit on the width */
	ut_assertok(vidconsole_measure(con, NULL, 0, test_string, limit, &bbox,
				       &lines));
	ut_asserteq(0, bbox.x0);
	ut_asserteq(0, bbox.y0);
	ut_asserteq(0x31e, bbox.x1);
	ut_asserteq(0x36, bbox.y1);
	ut_asserteq(3, lines.count);

	nl = strchr(test_string, '\n') - test_string;

	line = alist_get(&lines, 0, struct vidconsole_mline);
	ut_assertnonnull(line);
	ut_asserteq(0, line->bbox.x0);
	ut_asserteq(0, line->bbox.y0);
	ut_asserteq(0x8c, line->bbox.x1);
	ut_asserteq(0x12, line->bbox.y1);
	ut_asserteq(0, line->start);
	ut_asserteq(20, line->len);
	ut_asserteq(nl, line->len);
	printf("line0 '%.*s'\n", line->len, test_string + line->start);
	ut_asserteq_strn("There is always much",
			 test_string + line->start);

	line++;
	ut_asserteq(0x0, line->bbox.x0);
	ut_asserteq(0x12, line->bbox.y0);
	ut_asserteq(0x31e, line->bbox.x1);
	ut_asserteq(0x24, line->bbox.y1);
	ut_asserteq(21, line->start);
	ut_asserteq(nl + 1, line->start);
	ut_asserteq(129, line->len);
	printf("line1 '%.*s'\n", line->len, test_string + line->start);
	ut_asserteq_strn("to be said for not attempting more than you can do "
			 "and for making a certainty of what you try. But this "
			 "principle, like others in",
			 test_string + line->start);

	line++;
	ut_asserteq(0x0, line->bbox.x0);
	ut_asserteq(0x24, line->bbox.y0);
	ut_asserteq(0xc8, line->bbox.x1);
	ut_asserteq(0x36, line->bbox.y1);
	ut_asserteq(21 + 130, line->start);
	ut_asserteq(33, line->len);
	printf("line2 '%.*s'\n", line->len, test_string + line->start);
	ut_asserteq_strn("life and war, has its exceptions.",
			 test_string + line->start);

	/*
	 * all characters should be accounted for, except the newline and the
	 * space which is consumed in the wordwrap
	 */
	ut_asserteq(strlen(test_string) - 2,
		    line[-2].len + line[-1].len + line->len);

	return 0;
}
DM_TEST(dm_test_font_measure, UTF_SCAN_FDT);

/* Test silencing the video console */
static int dm_test_video_silence(struct unit_test_state *uts)
{
	struct udevice *dev, *con;
	struct stdio_dev *sdev;

	ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));

	/*
	 * use the old console device from before when dm_test_pre_run() was
	 * called, since that is what is in stdio / console
	 */
	sdev = stdio_get_by_name("vidconsole");
	ut_assertnonnull(sdev);
	con = sdev->priv;
	ut_assertok(vidconsole_clear_and_reset(con));
	ut_unsilence_console(uts);

	printf("message 1: console\n");
	vidconsole_put_string(con, "message 1: video\n");

	vidconsole_set_quiet(con, true);
	printf("second message: console\n");
	vidconsole_put_string(con, "second message: video\n");

	vidconsole_set_quiet(con, false);
	printf("final message: console\n");
	vidconsole_put_string(con, "final message: video\n");

	ut_asserteq(3944, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	return 0;
}
DM_TEST(dm_test_video_silence, UTF_SCAN_FDT);

/* test drawing a box */
static int dm_test_video_box(struct unit_test_state *uts)
{
	struct video_priv *priv;
	struct udevice *dev;

	ut_assertok(video_get_nologo(uts, &dev));
	priv = dev_get_uclass_priv(dev);

	/* test outline boxes */
	video_draw_box(dev, 100, 100, 200, 200, 3,
		       video_index_to_colour(priv, VID_LIGHT_BLUE), false);
	video_draw_box(dev, 300, 100, 400, 200, 1,
		       video_index_to_colour(priv, VID_MAGENTA), false);
	video_draw_box(dev, 500, 100, 600, 200, 20,
		       video_index_to_colour(priv, VID_LIGHT_RED), false);
	ut_asserteq(133, video_compress_fb(uts, dev, false));

	/* test filled boxes */
	video_draw_box(dev, 150, 250, 200, 300, 0,
		       video_index_to_colour(priv, VID_GREEN), true);
	video_draw_box(dev, 350, 250, 400, 300, 0,
		       video_index_to_colour(priv, VID_YELLOW), true);
	ut_asserteq(175, video_compress_fb(uts, dev, false));

	return 0;
}
DM_TEST(dm_test_video_box, UTF_SCAN_FDT);

/* font switching between TrueType and bitmap fonts */
static int dm_test_video_font_switch(struct unit_test_state *uts)
{
	struct udevice *dev, *con;
	const char *truetype_text =
		"This is a long line of text written with TrueType font that "
		"should wrap to multiple lines to test the multi-line "
		"functionality properly. This is the second part of TrueType "
		"text that should also be long enough to wrap and test the "
		"line handling.";
	const char *bitmap_text =
		"Now this is bitmap font text that spans multiple lines and "
		"should be rendered with the standard 8x16 bitmap font instead "
		"of TrueType. More of the line of-bitmap text for testing "
		"purposes.";
	const char *final_truetype_text =
		"Finally back to TrueType font for this concluding multi-line "
		"text that demonstrates the font switching functionality "
		"working correctly.\nFinal line of TrueType text to complete "
		"the test.\n";

	ut_assertok(video_get_nologo(uts, &dev));
	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));

	/* Start with TrueType font and write multi-line text */
	vidconsole_put_string(con, truetype_text);

	/* Switch to bitmap font */
	ut_assertok(vidconsole_select_font(con, "8x16", 0));
	vidconsole_put_string(con, bitmap_text);

	/* Switch back to TrueType font */
	ut_assertok(vidconsole_select_font(con, NULL, 0));
	vidconsole_put_string(con, final_truetype_text);

	ut_asserteq(14892, video_compress_fb(uts, dev, false));

	return 0;
}
DM_TEST(dm_test_video_font_switch, UTF_SCAN_PDATA | UTF_SCAN_FDT);

/* cursor backspace without artifacts */
static int check_cursor_backspace(struct unit_test_state *uts,
				  struct udevice *dev, struct udevice *con,
				  int exp_height)
{
	int with_a, with_cursor, after_backspace, after_idle, after_hide;
	struct vidconsole_priv *vc_priv = dev_get_uclass_priv(con);
	struct vidconsole_cursor *curs = &vc_priv->curs;

	/* Output chars without cursor */
	ut_assert(!curs->visible);
	ut_assert(!curs->enabled);
	ut_assert(!curs->saved);
	ut_assert(!curs->height);
	ut_assertok(vidconsole_put_char(con, ' '));
	ut_assertok(vidconsole_put_char(con, 'a'));
	with_a = video_compress_fb(uts, dev, false);

	/* Show cursor at current position (after 'a') */
	ut_assertok(vidconsole_show_cursor(con));
	ut_assert(curs->visible);
	ut_assert(curs->saved);
	ut_asserteq(exp_height, curs->height);
	with_cursor = video_compress_fb(uts, dev, false);

	/* Enable the cursor so that backspace will move it */
	curs->enabled = true;

	/* Do backspace - the cursor will be hidden */
	ut_assertok(vidconsole_put_char(con, '\b'));
	ut_assert(!curs->visible);
	ut_assert(!curs->saved);
	after_backspace = video_compress_fb(uts, dev, false);
	ut_asserteq(with_a, after_backspace);
	ut_assert(curs->enabled);

	/* Run idle function - this should show the cursor */
	vidconsole_idle(con);
	ut_assert(curs->visible);
	ut_assert(curs->saved);
	after_idle = video_compress_fb(uts, dev, false);
	ut_assert(after_idle != with_a);

	/* Hide the cursor */
	ut_assertok(vidconsole_hide_cursor(con));
	ut_assert(curs->enabled);
	ut_assert(!curs->visible);
	ut_assert(!curs->saved);
	after_hide = video_compress_fb(uts, dev, false);

	ut_asserteq(with_a, after_hide);

	return 0;
}

/* cursor backspace without artifacts */
static int dm_test_video_backspace_normal(struct unit_test_state *uts)
{
	struct udevice *dev, *con;

	ut_assertok(select_vidconsole(uts, "vidconsole0"));
	ut_assertok(video_get_nologo(uts, &dev));
	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
	ut_assertok(vidconsole_select_font(con, "8x16", 0));
	ut_assertok(check_cursor_backspace(uts, dev, con, 16));

	return 0;
}
DM_TEST(dm_test_video_backspace_normal, UTF_SCAN_PDATA | UTF_SCAN_FDT);

/* cursor backspace without artifacts on truetype */
static int dm_test_video_backspace_truetype(struct unit_test_state *uts)
{
	struct udevice *dev, *con;

	ut_assertok(video_get_nologo(uts, &dev));
	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
	ut_assertok(vidconsole_select_font(con, NULL, 30));
	ut_assertok(check_cursor_backspace(uts, dev, con, 30));

	return 0;
}
DM_TEST(dm_test_video_backspace_truetype, UTF_SCAN_PDATA | UTF_SCAN_FDT);

/* video commands */
static int dm_test_video_cmd(struct unit_test_state *uts)
{
	struct udevice *dev, *con;

	ut_assertok(select_vidconsole(uts, "vidconsole0"));
	ut_assertok(video_get_nologo(uts, &dev));
	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
	ut_assertok(vidconsole_select_font(con, "8x16", 0));

	ut_assertok(run_command("setcurs 10 5", 0));

	ut_assertok(run_command("lcdputs \"Test string\"", 0));
	ut_asserteq(187, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	ut_assertok(run_command("video setcursor 0 0", 0));
	ut_assertok(run_command("video puts \"Top left\"", 0));
	ut_asserteq(272, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	ut_assertok(run_command(
		"video write 14:6 \"Multi\" 19:7 \"Write\"", 0));
	ut_asserteq(381, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	ut_assertok(run_command("video write -p a3:34 \"Pixels\"", 0));
	ut_asserteq(440, video_compress_fb(uts, dev, false));
	ut_assertok(video_check_copy_fb(uts, dev));

	return 0;
}
DM_TEST(dm_test_video_cmd, UTF_SCAN_PDATA | UTF_SCAN_FDT);

/* video images command */
static int dm_test_video_images(struct unit_test_state *uts)
{
	ut_assertok(run_command("video images", 0));
	ut_assert_nextline("Name                       Size");
	ut_assert_nextline("-------------------- ----------");
	ut_assert_nextline("bgrt                      43926");
	ut_assert_nextline("u_boot                     6932");
	ut_assert_skip_to_line("");
	ut_assert_nextline("Total images: 2");
	ut_assert_console_end();

	return 0;
}
DM_TEST(dm_test_video_images, UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE);