]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - test/dm/video.c
dm: core: Test uclass_first/next_device() on probe failure
[people/ms/u-boot.git] / test / dm / video.c
index 4e3f9d558f403d8f1f7496aabd857bf542e32112..4d000fa1bea5b41681b763b0dd318dd52d6f4afd 100644 (file)
@@ -86,6 +86,20 @@ static void __maybe_unused see_output(void)
        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_platdata(dev);
+       plat->vidconsole_drv_name = "vidconsole0";
+
+       return 0;
+}
+
 /* Test text output works on the video console */
 static int dm_test_video_text(struct unit_test_state *uts)
 {
@@ -95,6 +109,7 @@ static int dm_test_video_text(struct unit_test_state *uts)
 #define WHITE          0xffff
 #define SCROLL_LINES   100
 
+       ut_assertok(select_vidconsole(uts, "vidconsole0"));
        ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
        ut_asserteq(46, compress_frame_buffer(dev));
 
@@ -127,6 +142,7 @@ static int dm_test_video_chars(struct unit_test_state *uts)
        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.";
        const char *s;
 
+       ut_assertok(select_vidconsole(uts, "vidconsole0"));
        ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
        ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
        for (s = test_string; *s; s++)
@@ -185,7 +201,10 @@ static int check_vidconsole_output(struct unit_test_state *uts, int rot,
 /* Test text output through the console uclass */
 static int dm_test_video_context(struct unit_test_state *uts)
 {
-       return check_vidconsole_output(uts, 0, 788, 453);
+       ut_assertok(select_vidconsole(uts, "vidconsole0"));
+       ut_assertok(check_vidconsole_output(uts, 0, 788, 453));
+
+       return 0;
 }
 DM_TEST(dm_test_video_context, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
@@ -230,9 +249,9 @@ static int read_file(struct unit_test_state *uts, const char *fname,
        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);
-       os_close(fd);
        *addrp = addr;
 
        return 0;
@@ -269,3 +288,66 @@ static int dm_test_video_bmp_comp(struct unit_test_state *uts)
        return 0;
 }
 DM_TEST(dm_test_video_bmp_comp, DM_TESTF_SCAN_PDATA | DM_TESTF_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";
+       const char *s;
+
+       ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
+       ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
+       for (s = test_string; *s; s++)
+               vidconsole_put_char(con, *s);
+       ut_asserteq(12619, compress_frame_buffer(dev));
+
+       return 0;
+}
+DM_TEST(dm_test_video_truetype, DM_TESTF_SCAN_PDATA | DM_TESTF_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";
+       const char *s;
+
+       ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
+       ut_assert(!device_active(dev));
+       plat = dev_get_platdata(dev);
+       plat->font_size = 100;
+
+       ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
+       ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
+       for (s = test_string; *s; s++)
+               vidconsole_put_char(con, *s);
+       ut_asserteq(33849, compress_frame_buffer(dev));
+
+       return 0;
+}
+DM_TEST(dm_test_video_truetype_scroll, DM_TESTF_SCAN_PDATA | DM_TESTF_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.";
+       const char *s;
+
+       ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
+       ut_assert(!device_active(dev));
+       plat = dev_get_platdata(dev);
+       plat->font_size = 100;
+
+       ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
+       ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
+       for (s = test_string; *s; s++)
+               vidconsole_put_char(con, *s);
+       ut_asserteq(34871, compress_frame_buffer(dev));
+
+       return 0;
+}
+DM_TEST(dm_test_video_truetype_bs, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);