1 package displayctl
2
3 import (
4 "context"
5 "testing"
6
7 "github.com/stretchr/testify/require"
8 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9
10 manager "edge-infra.dev/pkg/sds/display/displaymanager/manager/example"
11 v1 "edge-infra.dev/pkg/sds/display/k8s/apis/v1"
12 v2 "edge-infra.dev/pkg/sds/display/k8s/apis/v2"
13 )
14
15 var (
16 hostname = "upgrade"
17
18 card0HDMI1 = v2.DisplayPort("card0-HDMI1")
19 card0DP1 = v2.DisplayPort("card0-DP1")
20 disconnected = v2.NewDisplayPort(v2.UnknownCard, "disconnected-1")
21
22 elo4098 = v2.MPID("ELO-4098")
23 vsc9365 = v2.MPID("VSC-9365")
24 ncr1234 = v2.MPID("NCR-1234")
25
26 v1NotPrimary = v1.Primary(false)
27 v2NotPrimary = v2.Primary(false)
28
29 disabled = false
30
31 thirtySeconds = 30
32 sixtySeconds = 60
33 ninetySeconds = 90
34 oneTwentySeconds = 120
35 )
36
37 func TestUpgradeNodeDisplayConfig(t *testing.T) {
38 c := &NodeDisplayConfigController{
39 DisplayManager: manager.NewExampleDisplayManager(hostname, false),
40 }
41
42 tcs := []struct {
43 nodeDisplayConfig *v2.NodeDisplayConfig
44 expectedNodeDisplayConfig *v2.NodeDisplayConfig
45 expectedUpgraded bool
46 }{
47 {
48
49
50 nodeDisplayConfig: &v2.NodeDisplayConfig{
51 ObjectMeta: metav1.ObjectMeta{
52 Name: hostname,
53 },
54 Spec: &v2.DisplayConfig{},
55 },
56 expectedNodeDisplayConfig: &v2.NodeDisplayConfig{
57 ObjectMeta: metav1.ObjectMeta{
58 Name: hostname,
59 },
60 Spec: &v2.DisplayConfig{},
61 },
62 expectedUpgraded: false,
63 },
64 {
65
66
67 nodeDisplayConfig: &v2.NodeDisplayConfig{
68 ObjectMeta: metav1.ObjectMeta{
69 Name: hostname,
70 },
71 Spec: &v2.DisplayConfig{
72 Displays: v2.Displays{
73 {
74 DisplayPort: card0DP1,
75 MPID: &vsc9365,
76 Primary: &v2NotPrimary,
77 Orientation: &v2.InvertedOrientation,
78 Resolution: &v2.Resolution{
79 Width: 1280,
80 Height: 1084,
81 },
82 },
83 {
84 DisplayPort: card0HDMI1,
85 MPID: &elo4098,
86 Orientation: &v2.NormalOrientation,
87 Resolution: &v2.Resolution{
88 Width: 1260,
89 Height: 720,
90 },
91 },
92 },
93 DPMS: &v2.DPMS{
94 Enabled: &disabled,
95 BlankTime: &thirtySeconds,
96 StandbyTime: &sixtySeconds,
97 SuspendTime: &ninetySeconds,
98 OffTime: &oneTwentySeconds,
99 },
100 Layout: v2.Layout{card0HDMI1, card0DP1},
101 },
102 },
103 expectedNodeDisplayConfig: &v2.NodeDisplayConfig{
104 ObjectMeta: metav1.ObjectMeta{
105 Name: hostname,
106 },
107 Spec: &v2.DisplayConfig{
108 Displays: v2.Displays{
109 {
110 DisplayPort: card0DP1,
111 MPID: &vsc9365,
112 Primary: &v2NotPrimary,
113 Orientation: &v2.InvertedOrientation,
114 Resolution: &v2.Resolution{
115 Width: 1280,
116 Height: 1084,
117 },
118 },
119 {
120 DisplayPort: card0HDMI1,
121 MPID: &elo4098,
122 Orientation: &v2.NormalOrientation,
123 Resolution: &v2.Resolution{
124 Width: 1260,
125 Height: 720,
126 },
127 },
128 },
129 DPMS: &v2.DPMS{
130 Enabled: &disabled,
131 BlankTime: &thirtySeconds,
132 StandbyTime: &sixtySeconds,
133 SuspendTime: &ninetySeconds,
134 OffTime: &oneTwentySeconds,
135 },
136 Layout: v2.Layout{card0HDMI1, card0DP1},
137 },
138 },
139 expectedUpgraded: false,
140 },
141 {
142
143
144
145 nodeDisplayConfig: &v2.NodeDisplayConfig{
146 ObjectMeta: metav1.ObjectMeta{
147 Name: hostname,
148 },
149 Spec: &v2.DisplayConfig{
150 V1: &v1.DisplayConfig{
151 Displays: v1.Displays{
152 v1.MPID(vsc9365): v1.Display{
153 Primary: &v1NotPrimary,
154 Orientation: &v1.InvertedOrientation,
155 Resolution: &v1.Resolution{
156 Width: 1280,
157 Height: 1084,
158 },
159 },
160 v1.MPID(elo4098): {
161 Orientation: &v1.NormalOrientation,
162 Resolution: &v1.Resolution{
163 Width: 1260,
164 Height: 720,
165 },
166 },
167 v1.MPID(ncr1234): {
168 Resolution: &v1.Resolution{
169 Width: 1920,
170 Height: 1080,
171 },
172 },
173 },
174 DPMS: &v1.DPMS{
175 Enabled: &disabled,
176 BlankTime: &thirtySeconds,
177 StandbyTime: &sixtySeconds,
178 SuspendTime: &ninetySeconds,
179 OffTime: &oneTwentySeconds,
180 },
181 Layout: v1.Layout{v1.MPID(elo4098), v1.MPID(vsc9365), v1.MPID(ncr1234)},
182 },
183 },
184 },
185 expectedNodeDisplayConfig: &v2.NodeDisplayConfig{
186 ObjectMeta: metav1.ObjectMeta{
187 Name: hostname,
188 },
189 Spec: &v2.DisplayConfig{
190 Displays: v2.Displays{
191 {
192 DisplayPort: card0HDMI1,
193 Orientation: &v2.NormalOrientation,
194 Resolution: &v2.Resolution{
195 Width: 1260,
196 Height: 720,
197 },
198 },
199 {
200 DisplayPort: disconnected,
201 Resolution: &v2.Resolution{
202 Width: 1920,
203 Height: 1080,
204 },
205 },
206 {
207 DisplayPort: card0DP1,
208 Primary: &v2NotPrimary,
209 Orientation: &v2.InvertedOrientation,
210 Resolution: &v2.Resolution{
211 Width: 1280,
212 Height: 1084,
213 },
214 },
215 },
216 DPMS: &v2.DPMS{
217 Enabled: &disabled,
218 BlankTime: &thirtySeconds,
219 StandbyTime: &sixtySeconds,
220 SuspendTime: &ninetySeconds,
221 OffTime: &oneTwentySeconds,
222 },
223 Layout: v2.Layout{card0HDMI1, card0DP1, disconnected},
224 },
225 Status: v2.NodeDisplayConfigStatus{
226 Upgrade: v2.UpgradeStatus{
227 DisconnectedDisplays: map[v2.DisplayPort]v2.MPID{
228 disconnected: ncr1234,
229 },
230 },
231 },
232 },
233 expectedUpgraded: true,
234 },
235 {
236
237
238 nodeDisplayConfig: &v2.NodeDisplayConfig{
239 ObjectMeta: metav1.ObjectMeta{
240 Name: hostname,
241 },
242 Spec: &v2.DisplayConfig{
243 Displays: v2.Displays{
244 {
245 DisplayPort: card0HDMI1,
246 Orientation: &v2.NormalOrientation,
247 Resolution: &v2.Resolution{
248 Width: 1260,
249 Height: 720,
250 },
251 },
252 {
253 DisplayPort: disconnected,
254 Primary: &v2NotPrimary,
255 Orientation: &v2.InvertedOrientation,
256 Resolution: &v2.Resolution{
257 Width: 1280,
258 Height: 1084,
259 },
260 },
261 },
262 DPMS: &v2.DPMS{
263 Enabled: &disabled,
264 BlankTime: &thirtySeconds,
265 StandbyTime: &sixtySeconds,
266 SuspendTime: &ninetySeconds,
267 OffTime: &oneTwentySeconds,
268 },
269 Layout: v2.Layout{card0HDMI1, disconnected},
270 },
271 Status: v2.NodeDisplayConfigStatus{
272 Upgrade: v2.UpgradeStatus{
273 DisconnectedDisplays: map[v2.DisplayPort]v2.MPID{
274 disconnected: vsc9365,
275 },
276 },
277 },
278 },
279 expectedNodeDisplayConfig: &v2.NodeDisplayConfig{
280 ObjectMeta: metav1.ObjectMeta{
281 Name: hostname,
282 },
283 Spec: &v2.DisplayConfig{
284 Displays: v2.Displays{
285 {
286 DisplayPort: card0HDMI1,
287 Orientation: &v2.NormalOrientation,
288 Resolution: &v2.Resolution{
289 Width: 1260,
290 Height: 720,
291 },
292 },
293 {
294 DisplayPort: card0DP1,
295 Primary: &v2NotPrimary,
296 Orientation: &v2.InvertedOrientation,
297 Resolution: &v2.Resolution{
298 Width: 1280,
299 Height: 1084,
300 },
301 },
302 },
303 DPMS: &v2.DPMS{
304 Enabled: &disabled,
305 BlankTime: &thirtySeconds,
306 StandbyTime: &sixtySeconds,
307 SuspendTime: &ninetySeconds,
308 OffTime: &oneTwentySeconds,
309 },
310 Layout: v2.Layout{card0HDMI1, card0DP1},
311 },
312 Status: v2.NodeDisplayConfigStatus{},
313 },
314 expectedUpgraded: true,
315 },
316 }
317 for idx, tc := range tcs {
318 nodeDisplayConfig := tc.nodeDisplayConfig.DeepCopy()
319 upgraded, err := c.upgradeNodeDisplayConfig(context.Background(), nodeDisplayConfig)
320 require.NoError(t, err, "test case %d failed", idx+1)
321 require.Equal(t, tc.expectedUpgraded, upgraded, "test case %d failed", idx+1)
322 require.Equal(t, tc.expectedNodeDisplayConfig, nodeDisplayConfig, "test case %d failed", idx+1)
323 }
324 }
325
View as plain text