Mario Six | 4eea531 | 2018-09-27 09:19:31 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2018 |
| 4 | * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <display_options.h> |
| 9 | #include <dm.h> |
| 10 | #include <dm/test.h> |
| 11 | #include <test/ut.h> |
| 12 | #include <video_osd.h> |
| 13 | #include <asm/test.h> |
| 14 | |
| 15 | #include "../../drivers/video/sandbox_osd.h" |
| 16 | |
| 17 | const uint memsize = 2 * 10 * 10; |
| 18 | |
| 19 | static void split(u8 *mem, uint size, u8 *text, u8 *colors) |
| 20 | { |
| 21 | int i; |
| 22 | u16 *p = (u16 *)mem; |
| 23 | |
| 24 | for (i = 0; i < size; i++) { |
| 25 | colors[i] = p[i] % 0x100; |
| 26 | text[i] = p[i] / 0x100; |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | static void print_mem(u8 *mem, uint width, uint height) |
| 31 | { |
| 32 | const uint memsize = 2 * 10 * 10; |
| 33 | u8 colors[memsize / 2]; |
| 34 | u8 text[memsize / 2]; |
| 35 | int i; |
| 36 | |
| 37 | split(mem, memsize / 2, text, colors); |
| 38 | |
| 39 | for (i = 0; i < width * height; i++) { |
| 40 | printf("%c", text[i]); |
| 41 | if (i > 0 && ((i + 1) % width) == 0) |
| 42 | printf("\n"); |
| 43 | } |
| 44 | |
| 45 | printf("\n"); |
| 46 | |
| 47 | for (i = 0; i < width * height; i++) { |
| 48 | printf("%c", colors[i]); |
| 49 | if (i > 0 && ((i + 1) % width) == 0) |
| 50 | printf("\n"); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | static int dm_test_osd_basics(struct unit_test_state *uts) |
| 55 | { |
| 56 | struct udevice *dev; |
| 57 | u8 mem[memsize + 1]; |
| 58 | u8 colors[memsize / 2]; |
| 59 | u8 text[memsize / 2]; |
| 60 | struct video_osd_info info; |
| 61 | |
| 62 | ut_assertok(uclass_first_device_err(UCLASS_VIDEO_OSD, &dev)); |
| 63 | |
| 64 | video_osd_get_info(dev, &info); |
| 65 | |
| 66 | ut_asserteq(10, info.width); |
| 67 | ut_asserteq(10, info.height); |
| 68 | ut_asserteq(1, info.major_version); |
| 69 | ut_asserteq(0, info.minor_version); |
| 70 | |
| 71 | ut_assertok(sandbox_osd_get_mem(dev, mem, memsize)); |
| 72 | split(mem, memsize / 2, text, colors); |
| 73 | |
Simon Glass | f91f366 | 2020-05-10 12:52:45 -0600 | [diff] [blame^] | 74 | ut_asserteq_mem(text, |
| 75 | " " |
| 76 | " " |
| 77 | " " |
| 78 | " " |
| 79 | " " |
| 80 | " " |
| 81 | " " |
| 82 | " " |
| 83 | " " |
| 84 | " ", memsize / 2); |
Mario Six | 4eea531 | 2018-09-27 09:19:31 +0200 | [diff] [blame] | 85 | |
Simon Glass | f91f366 | 2020-05-10 12:52:45 -0600 | [diff] [blame^] | 86 | ut_asserteq_mem(colors, |
| 87 | "kkkkkkkkkk" |
| 88 | "kkkkkkkkkk" |
| 89 | "kkkkkkkkkk" |
| 90 | "kkkkkkkkkk" |
| 91 | "kkkkkkkkkk" |
| 92 | "kkkkkkkkkk" |
| 93 | "kkkkkkkkkk" |
| 94 | "kkkkkkkkkk" |
| 95 | "kkkkkkkkkk" |
| 96 | "kkkkkkkkkk", memsize / 2); |
Mario Six | 4eea531 | 2018-09-27 09:19:31 +0200 | [diff] [blame] | 97 | |
| 98 | print_mem(mem, 10, 10); |
| 99 | |
| 100 | ut_assertok(video_osd_print(dev, 1, 1, COLOR_RED, "Blah")); |
| 101 | |
| 102 | ut_assertok(sandbox_osd_get_mem(dev, mem, memsize)); |
| 103 | split(mem, memsize / 2, text, colors); |
| 104 | |
Simon Glass | f91f366 | 2020-05-10 12:52:45 -0600 | [diff] [blame^] | 105 | ut_asserteq_mem(text, |
| 106 | " " |
| 107 | " Blah " |
| 108 | " " |
| 109 | " " |
| 110 | " " |
| 111 | " " |
| 112 | " " |
| 113 | " " |
| 114 | " " |
| 115 | " ", memsize / 2); |
Mario Six | 4eea531 | 2018-09-27 09:19:31 +0200 | [diff] [blame] | 116 | |
Simon Glass | f91f366 | 2020-05-10 12:52:45 -0600 | [diff] [blame^] | 117 | ut_asserteq_mem(colors, |
| 118 | "kkkkkkkkkk" |
| 119 | "krrrrkkkkk" |
| 120 | "kkkkkkkkkk" |
| 121 | "kkkkkkkkkk" |
| 122 | "kkkkkkkkkk" |
| 123 | "kkkkkkkkkk" |
| 124 | "kkkkkkkkkk" |
| 125 | "kkkkkkkkkk" |
| 126 | "kkkkkkkkkk" |
| 127 | "kkkkkkkkkk", memsize / 2); |
Mario Six | 4eea531 | 2018-09-27 09:19:31 +0200 | [diff] [blame] | 128 | |
| 129 | print_mem(mem, 10, 10); |
| 130 | |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | DM_TEST(dm_test_osd_basics, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
| 135 | |
| 136 | static int dm_test_osd_extended(struct unit_test_state *uts) |
| 137 | { |
| 138 | struct udevice *dev; |
| 139 | u8 mem[memsize + 1]; |
| 140 | u8 colors[memsize / 2]; |
| 141 | u8 text[memsize / 2]; |
| 142 | struct video_osd_info info; |
| 143 | u16 val; |
| 144 | |
| 145 | ut_assertok(uclass_first_device_err(UCLASS_VIDEO_OSD, &dev)); |
| 146 | |
| 147 | ut_assertok(video_osd_set_size(dev, 20, 5)); |
| 148 | |
| 149 | video_osd_get_info(dev, &info); |
| 150 | |
| 151 | ut_asserteq(20, info.width); |
| 152 | ut_asserteq(5, info.height); |
| 153 | ut_asserteq(1, info.major_version); |
| 154 | ut_asserteq(0, info.minor_version); |
| 155 | |
| 156 | ut_assertok(sandbox_osd_get_mem(dev, mem, memsize)); |
| 157 | split(mem, memsize / 2, text, colors); |
| 158 | |
Simon Glass | f91f366 | 2020-05-10 12:52:45 -0600 | [diff] [blame^] | 159 | ut_asserteq_mem(text, |
| 160 | " " |
| 161 | " " |
| 162 | " " |
| 163 | " " |
| 164 | " ", memsize / 2); |
Mario Six | 4eea531 | 2018-09-27 09:19:31 +0200 | [diff] [blame] | 165 | |
Simon Glass | f91f366 | 2020-05-10 12:52:45 -0600 | [diff] [blame^] | 166 | ut_asserteq_mem(colors, |
| 167 | "kkkkkkkkkkkkkkkkkkkk" |
| 168 | "kkkkkkkkkkkkkkkkkkkk" |
| 169 | "kkkkkkkkkkkkkkkkkkkk" |
| 170 | "kkkkkkkkkkkkkkkkkkkk" |
| 171 | "kkkkkkkkkkkkkkkkkkkk", memsize / 2); |
Mario Six | 4eea531 | 2018-09-27 09:19:31 +0200 | [diff] [blame] | 172 | |
| 173 | print_mem(mem, 20, 5); |
| 174 | |
| 175 | /* Draw green border */ |
| 176 | val = '-' * 0x100 + 'g'; |
| 177 | ut_assertok(video_osd_set_mem(dev, 1, 0, (u8 *)&val, 2, 18)); |
| 178 | ut_assertok(video_osd_set_mem(dev, 1, 4, (u8 *)&val, 2, 18)); |
| 179 | ut_assertok(video_osd_print(dev, 0, 1, COLOR_GREEN, "|")); |
| 180 | ut_assertok(video_osd_print(dev, 0, 2, COLOR_GREEN, "|")); |
| 181 | ut_assertok(video_osd_print(dev, 0, 3, COLOR_GREEN, "|")); |
| 182 | ut_assertok(video_osd_print(dev, 19, 1, COLOR_GREEN, "|")); |
| 183 | ut_assertok(video_osd_print(dev, 19, 2, COLOR_GREEN, "|")); |
| 184 | ut_assertok(video_osd_print(dev, 19, 3, COLOR_GREEN, "|")); |
| 185 | ut_assertok(video_osd_print(dev, 0, 0, COLOR_GREEN, "+")); |
| 186 | ut_assertok(video_osd_print(dev, 19, 0, COLOR_GREEN, "+")); |
| 187 | ut_assertok(video_osd_print(dev, 19, 4, COLOR_GREEN, "+")); |
| 188 | ut_assertok(video_osd_print(dev, 0, 4, COLOR_GREEN, "+")); |
| 189 | |
| 190 | /* Add menu caption and entries */ |
| 191 | ut_assertok(video_osd_print(dev, 5, 0, COLOR_GREEN, " OSD menu ")); |
| 192 | ut_assertok(video_osd_print(dev, 2, 1, COLOR_BLUE, " * Entry 1")); |
| 193 | ut_assertok(video_osd_print(dev, 2, 2, COLOR_BLUE, "(*) Entry 2")); |
| 194 | ut_assertok(video_osd_print(dev, 2, 3, COLOR_BLUE, " * Entry 3")); |
| 195 | |
| 196 | ut_assertok(sandbox_osd_get_mem(dev, mem, memsize)); |
| 197 | split(mem, memsize / 2, text, colors); |
| 198 | |
| 199 | print_mem(mem, 20, 5); |
| 200 | |
Simon Glass | f91f366 | 2020-05-10 12:52:45 -0600 | [diff] [blame^] | 201 | ut_asserteq_mem(text, |
| 202 | "+---- OSD menu ----+" |
| 203 | "| * Entry 1 |" |
| 204 | "| (*) Entry 2 |" |
| 205 | "| * Entry 3 |" |
| 206 | "+------------------+", memsize / 2); |
Mario Six | 4eea531 | 2018-09-27 09:19:31 +0200 | [diff] [blame] | 207 | |
Simon Glass | f91f366 | 2020-05-10 12:52:45 -0600 | [diff] [blame^] | 208 | ut_asserteq_mem(colors, |
| 209 | "gggggggggggggggggggg" |
| 210 | "gkbbbbbbbbbbbkkkkkkg" |
| 211 | "gkbbbbbbbbbbbkkkkkkg" |
| 212 | "gkbbbbbbbbbbbkkkkkkg" |
| 213 | "gggggggggggggggggggg", memsize / 2); |
Mario Six | 4eea531 | 2018-09-27 09:19:31 +0200 | [diff] [blame] | 214 | |
| 215 | return 0; |
| 216 | } |
| 217 | |
| 218 | DM_TEST(dm_test_osd_extended, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |