blob: cf4a3a545ed0c827c9f713ac3a8278bbc239c24b [file] [log] [blame]
Mario Six02ad6fb2018-09-27 09:19:31 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2018
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
5 */
6
Mario Six02ad6fb2018-09-27 09:19:31 +02007#include <display_options.h>
8#include <dm.h>
Mario Six02ad6fb2018-09-27 09:19:31 +02009#include <video_osd.h>
10#include <asm/test.h>
Simon Glass75c4d412020-07-19 10:15:37 -060011#include <dm/test.h>
12#include <test/test.h>
13#include <test/ut.h>
Mario Six02ad6fb2018-09-27 09:19:31 +020014
15#include "../../drivers/video/sandbox_osd.h"
16
17const uint memsize = 2 * 10 * 10;
18
19static 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
30static 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
54static 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 Glassa3186e62020-05-10 12:52:45 -060074 ut_asserteq_mem(text,
75 " "
76 " "
77 " "
78 " "
79 " "
80 " "
81 " "
82 " "
83 " "
84 " ", memsize / 2);
Mario Six02ad6fb2018-09-27 09:19:31 +020085
Simon Glassa3186e62020-05-10 12:52:45 -060086 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 Six02ad6fb2018-09-27 09:19:31 +020097
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 Glassa3186e62020-05-10 12:52:45 -0600105 ut_asserteq_mem(text,
106 " "
107 " Blah "
108 " "
109 " "
110 " "
111 " "
112 " "
113 " "
114 " "
115 " ", memsize / 2);
Mario Six02ad6fb2018-09-27 09:19:31 +0200116
Simon Glassa3186e62020-05-10 12:52:45 -0600117 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 Six02ad6fb2018-09-27 09:19:31 +0200128
129 print_mem(mem, 10, 10);
130
131 return 0;
132}
133
Simon Glass974dccd2020-07-28 19:41:12 -0600134DM_TEST(dm_test_osd_basics, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Mario Six02ad6fb2018-09-27 09:19:31 +0200135
136static 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 Glassa3186e62020-05-10 12:52:45 -0600159 ut_asserteq_mem(text,
160 " "
161 " "
162 " "
163 " "
164 " ", memsize / 2);
Mario Six02ad6fb2018-09-27 09:19:31 +0200165
Simon Glassa3186e62020-05-10 12:52:45 -0600166 ut_asserteq_mem(colors,
167 "kkkkkkkkkkkkkkkkkkkk"
168 "kkkkkkkkkkkkkkkkkkkk"
169 "kkkkkkkkkkkkkkkkkkkk"
170 "kkkkkkkkkkkkkkkkkkkk"
171 "kkkkkkkkkkkkkkkkkkkk", memsize / 2);
Mario Six02ad6fb2018-09-27 09:19:31 +0200172
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 Glassa3186e62020-05-10 12:52:45 -0600201 ut_asserteq_mem(text,
202 "+---- OSD menu ----+"
203 "| * Entry 1 |"
204 "| (*) Entry 2 |"
205 "| * Entry 3 |"
206 "+------------------+", memsize / 2);
Mario Six02ad6fb2018-09-27 09:19:31 +0200207
Simon Glassa3186e62020-05-10 12:52:45 -0600208 ut_asserteq_mem(colors,
209 "gggggggggggggggggggg"
210 "gkbbbbbbbbbbbkkkkkkg"
211 "gkbbbbbbbbbbbkkkkkkg"
212 "gkbbbbbbbbbbbkkkkkkg"
213 "gggggggggggggggggggg", memsize / 2);
Mario Six02ad6fb2018-09-27 09:19:31 +0200214
215 return 0;
216}
217
Simon Glass974dccd2020-07-28 19:41:12 -0600218DM_TEST(dm_test_osd_extended, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);