-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathmonitor-unit-tests.c
More file actions
6514 lines (6101 loc) · 166 KB
/
monitor-unit-tests.c
File metadata and controls
6514 lines (6101 loc) · 166 KB
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
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/*
* Copyright (C) 2016 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "tests/monitor-unit-tests.h"
#include "backends/meta-backend-private.h"
#include "backends/meta-crtc.h"
#include "backends/meta-logical-monitor.h"
#include "backends/meta-monitor.h"
#include "backends/meta-monitor-config-migration.h"
#include "backends/meta-monitor-config-store.h"
#include "backends/meta-output.h"
#include "core/window-private.h"
#include "meta-backend-test.h"
#include "tests/meta-monitor-manager-test.h"
#include "tests/monitor-test-utils.h"
#include "tests/test-utils.h"
#include "x11/meta-x11-display-private.h"
#define ALL_TRANSFORMS ((1 << (META_MONITOR_TRANSFORM_FLIPPED_270 + 1)) - 1)
#define MAX_N_MODES 10
#define MAX_N_OUTPUTS 10
#define MAX_N_CRTCS 10
#define MAX_N_MONITORS 10
#define MAX_N_LOGICAL_MONITORS 10
/*
* The following structures are used to define test cases.
*
* Each test case consists of a test case setup and a test case expectaction.
* and a expected result, consisting
* of an array of monitors, logical monitors and a screen size.
*
* TEST CASE SETUP:
*
* A test case setup consists of an array of modes, an array of outputs and an
* array of CRTCs.
*
* A mode has a width and height in pixels, and a refresh rate in updates per
* second.
*
* An output has an array of available modes, and a preferred mode. Modes are
* defined as indices into the modes array of the test case setup.
*
* It also has CRTc and an array of possible CRTCs. Crtcs are defined as indices
* into the CRTC array. The CRTC value -1 means no CRTC.
*
* It also has various meta data, such as physical dimension, tile info and
* scale.
*
* A CRTC only has a current mode. A mode is defined as an index into the modes
* array.
*
*
* TEST CASE EXPECTS:
*
* A test case expects consists of an array of monitors, an array of logical
* monitors, a output and crtc count, and a screen width.
*
* A monitor represents a physical monitor (such as an external monitor, or a
* laptop panel etc). A monitor consists of an array of outputs, defined by
* indices into the setup output array, an array of monitor modes, and the
* current mode, defined by an index into the monitor modes array, and the
* physical dimensions.
*
* A logical monitor represents a region of the total screen area. It contains
* the expected layout and a scale.
*/
typedef enum _MonitorTestFlag
{
MONITOR_TEST_FLAG_NONE,
MONITOR_TEST_FLAG_NO_STORED
} MonitorTestFlag;
typedef struct _MonitorTestCaseMode
{
int width;
int height;
float refresh_rate;
MetaCrtcModeFlag flags;
} MonitorTestCaseMode;
typedef struct _MonitorTestCaseOutput
{
int crtc;
int modes[MAX_N_MODES];
int n_modes;
int preferred_mode;
int possible_crtcs[MAX_N_CRTCS];
int n_possible_crtcs;
int width_mm;
int height_mm;
MetaTileInfo tile_info;
float scale;
gboolean is_laptop_panel;
gboolean is_underscanning;
const char *serial;
MetaMonitorTransform panel_orientation_transform;
} MonitorTestCaseOutput;
typedef struct _MonitorTestCaseCrtc
{
int current_mode;
} MonitorTestCaseCrtc;
typedef struct _MonitorTestCaseSetup
{
MonitorTestCaseMode modes[MAX_N_MODES];
int n_modes;
MonitorTestCaseOutput outputs[MAX_N_OUTPUTS];
int n_outputs;
MonitorTestCaseCrtc crtcs[MAX_N_CRTCS];
int n_crtcs;
} MonitorTestCaseSetup;
typedef struct _MonitorTestCaseMonitorCrtcMode
{
uint64_t output;
int crtc_mode;
} MetaTestCaseMonitorCrtcMode;
typedef struct _MonitorTestCaseMonitorMode
{
int width;
int height;
float refresh_rate;
MetaCrtcModeFlag flags;
MetaTestCaseMonitorCrtcMode crtc_modes[MAX_N_CRTCS];
} MetaMonitorTestCaseMonitorMode;
typedef struct _MonitorTestCaseMonitor
{
uint64_t outputs[MAX_N_OUTPUTS];
int n_outputs;
MetaMonitorTestCaseMonitorMode modes[MAX_N_MODES];
int n_modes;
int current_mode;
int width_mm;
int height_mm;
gboolean is_underscanning;
} MonitorTestCaseMonitor;
typedef struct _MonitorTestCaseLogicalMonitor
{
MetaRectangle layout;
float scale;
int monitors[MAX_N_MONITORS];
int n_monitors;
MetaMonitorTransform transform;
} MonitorTestCaseLogicalMonitor;
typedef struct _MonitorTestCaseCrtcExpect
{
MetaMonitorTransform transform;
int current_mode;
float x;
float y;
} MonitorTestCaseCrtcExpect;
typedef struct _MonitorTestCaseExpect
{
MonitorTestCaseMonitor monitors[MAX_N_MONITORS];
int n_monitors;
MonitorTestCaseLogicalMonitor logical_monitors[MAX_N_LOGICAL_MONITORS];
int n_logical_monitors;
int primary_logical_monitor;
int n_outputs;
MonitorTestCaseCrtcExpect crtcs[MAX_N_CRTCS];
int n_crtcs;
int n_tiled_monitors;
int screen_width;
int screen_height;
} MonitorTestCaseExpect;
typedef struct _MonitorTestCase
{
MonitorTestCaseSetup setup;
MonitorTestCaseExpect expect;
} MonitorTestCase;
static MonitorTestCase initial_test_case = {
.setup = {
.modes = {
{
.width = 1024,
.height = 768,
.refresh_rate = 60.0
}
},
.n_modes = 1,
.outputs = {
{
.crtc = 0,
.modes = { 0 },
.n_modes = 1,
.preferred_mode = 0,
.possible_crtcs = { 0 },
.n_possible_crtcs = 1,
.width_mm = 222,
.height_mm = 125
},
{
.crtc = 1,
.modes = { 0 },
.n_modes = 1,
.preferred_mode = 0,
.possible_crtcs = { 1 },
.n_possible_crtcs = 1,
.width_mm = 220,
.height_mm = 124
}
},
.n_outputs = 2,
.crtcs = {
{
.current_mode = 0
},
{
.current_mode = 0
}
},
.n_crtcs = 2
},
.expect = {
.monitors = {
{
.outputs = { 0 },
.n_outputs = 1,
.modes = {
{
.width = 1024,
.height = 768,
.refresh_rate = 60.0,
.crtc_modes = {
{
.output = 0,
.crtc_mode = 0
}
}
}
},
.n_modes = 1,
.current_mode = 0,
.width_mm = 222,
.height_mm = 125
},
{
.outputs = { 1 },
.n_outputs = 1,
.modes = {
{
.width = 1024,
.height = 768,
.refresh_rate = 60.0,
.crtc_modes = {
{
.output = 1,
.crtc_mode = 0
}
}
}
},
.n_modes = 1,
.current_mode = 0,
.width_mm = 220,
.height_mm = 124
}
},
.n_monitors = 2,
.logical_monitors = {
{
.monitors = { 0 },
.n_monitors = 1,
.layout = { .x = 0, .y = 0, .width = 1024, .height = 768 },
.scale = 1
},
{
.monitors = { 1 },
.n_monitors = 1,
.layout = { .x = 1024, .y = 0, .width = 1024, .height = 768 },
.scale = 1
}
},
.n_logical_monitors = 2,
.primary_logical_monitor = 0,
.n_outputs = 2,
.crtcs = {
{
.current_mode = 0,
},
{
.current_mode = 0,
.x = 1024,
}
},
.n_crtcs = 2,
.screen_width = 1024 * 2,
.screen_height = 768
}
};
static TestClient *wayland_monitor_test_client = NULL;
static TestClient *x11_monitor_test_client = NULL;
#define WAYLAND_TEST_CLIENT_NAME "wayland_monitor_test_client"
#define WAYLAND_TEST_CLIENT_WINDOW "window1"
#define X11_TEST_CLIENT_NAME "x11_monitor_test_client"
#define X11_TEST_CLIENT_WINDOW "window1"
static gboolean
monitor_tests_alarm_filter (MetaX11Display *x11_display,
XSyncAlarmNotifyEvent *event,
gpointer data)
{
return test_client_alarm_filter (x11_display, event, x11_monitor_test_client);
}
static void
create_monitor_test_clients (void)
{
GError *error = NULL;
test_wait_for_x11_display ();
meta_x11_display_set_alarm_filter (meta_get_display ()->x11_display,
monitor_tests_alarm_filter, NULL);
wayland_monitor_test_client = test_client_new (WAYLAND_TEST_CLIENT_NAME,
META_WINDOW_CLIENT_TYPE_WAYLAND,
&error);
if (!wayland_monitor_test_client)
g_error ("Failed to launch Wayland test client: %s", error->message);
x11_monitor_test_client = test_client_new (X11_TEST_CLIENT_NAME,
META_WINDOW_CLIENT_TYPE_X11,
&error);
if (!x11_monitor_test_client)
g_error ("Failed to launch X11 test client: %s", error->message);
if (!test_client_do (wayland_monitor_test_client, &error,
"create", WAYLAND_TEST_CLIENT_WINDOW,
NULL))
g_error ("Failed to create Wayland window: %s", error->message);
if (!test_client_do (x11_monitor_test_client, &error,
"create", X11_TEST_CLIENT_WINDOW,
NULL))
g_error ("Failed to create X11 window: %s", error->message);
if (!test_client_do (wayland_monitor_test_client, &error,
"show", WAYLAND_TEST_CLIENT_WINDOW,
NULL))
g_error ("Failed to show the window: %s", error->message);
if (!test_client_do (x11_monitor_test_client, &error,
"show", X11_TEST_CLIENT_WINDOW,
NULL))
g_error ("Failed to show the window: %s", error->message);
}
static void
check_test_client_state (TestClient *test_client)
{
GError *error = NULL;
if (!test_client_wait (test_client, &error))
{
g_error ("Failed to sync test client '%s': %s",
test_client_get_id (test_client), error->message);
}
}
static void
check_monitor_test_clients_state (void)
{
check_test_client_state (wayland_monitor_test_client);
check_test_client_state (x11_monitor_test_client);
}
static void
destroy_monitor_test_clients (void)
{
GError *error = NULL;
if (!test_client_quit (wayland_monitor_test_client, &error))
g_error ("Failed to quit Wayland test client: %s", error->message);
if (!test_client_quit (x11_monitor_test_client, &error))
g_error ("Failed to quit X11 test client: %s", error->message);
test_client_destroy (wayland_monitor_test_client);
test_client_destroy (x11_monitor_test_client);
meta_x11_display_set_alarm_filter (meta_get_display ()->x11_display,
NULL, NULL);
}
static MetaOutput *
output_from_winsys_id (MetaBackend *backend,
uint64_t winsys_id)
{
MetaGpu *gpu = meta_backend_test_get_gpu (META_BACKEND_TEST (backend));
GList *l;
for (l = meta_gpu_get_outputs (gpu); l; l = l->next)
{
MetaOutput *output = l->data;
if (output->winsys_id == winsys_id)
return output;
}
return NULL;
}
typedef struct _CheckMonitorModeData
{
MetaBackend *backend;
MetaTestCaseMonitorCrtcMode *expect_crtc_mode_iter;
} CheckMonitorModeData;
static gboolean
check_monitor_mode (MetaMonitor *monitor,
MetaMonitorMode *mode,
MetaMonitorCrtcMode *monitor_crtc_mode,
gpointer user_data,
GError **error)
{
CheckMonitorModeData *data = user_data;
MetaBackend *backend = data->backend;
MetaOutput *output;
MetaCrtcMode *crtc_mode;
int expect_crtc_mode_index;
output = output_from_winsys_id (backend,
data->expect_crtc_mode_iter->output);
g_assert (monitor_crtc_mode->output == output);
expect_crtc_mode_index = data->expect_crtc_mode_iter->crtc_mode;
if (expect_crtc_mode_index == -1)
{
crtc_mode = NULL;
}
else
{
MetaGpu *gpu = meta_output_get_gpu (output);
crtc_mode = g_list_nth_data (meta_gpu_get_modes (gpu),
expect_crtc_mode_index);
}
g_assert (monitor_crtc_mode->crtc_mode == crtc_mode);
if (crtc_mode)
{
float refresh_rate;
MetaCrtcModeFlag flags;
refresh_rate = meta_monitor_mode_get_refresh_rate (mode);
flags = meta_monitor_mode_get_flags (mode);
g_assert_cmpfloat (refresh_rate, ==, crtc_mode->refresh_rate);
g_assert_cmpint (flags, ==, (crtc_mode->flags & HANDLED_CRTC_MODE_FLAGS));
}
data->expect_crtc_mode_iter++;
return TRUE;
}
static gboolean
check_current_monitor_mode (MetaMonitor *monitor,
MetaMonitorMode *mode,
MetaMonitorCrtcMode *monitor_crtc_mode,
gpointer user_data,
GError **error)
{
CheckMonitorModeData *data = user_data;
MetaBackend *backend = data->backend;
MetaOutput *output;
MetaCrtc *crtc;
output = output_from_winsys_id (backend,
data->expect_crtc_mode_iter->output);
crtc = meta_output_get_assigned_crtc (output);
if (data->expect_crtc_mode_iter->crtc_mode == -1)
{
g_assert_null (crtc);
}
else
{
MetaCrtcConfig *crtc_config;
MetaLogicalMonitor *logical_monitor;
g_assert_nonnull (crtc);
crtc_config = crtc->config;
g_assert_nonnull (crtc_config);
g_assert (monitor_crtc_mode->crtc_mode == crtc_config->mode);
logical_monitor = meta_monitor_get_logical_monitor (monitor);
g_assert_nonnull (logical_monitor);
}
data->expect_crtc_mode_iter++;
return TRUE;
}
static MetaLogicalMonitor *
logical_monitor_from_layout (MetaMonitorManager *monitor_manager,
MetaRectangle *layout)
{
GList *l;
for (l = monitor_manager->logical_monitors; l; l = l->next)
{
MetaLogicalMonitor *logical_monitor = l->data;
if (meta_rectangle_equal (layout, &logical_monitor->rect))
return logical_monitor;
}
return NULL;
}
static void
check_logical_monitor (MonitorTestCase *test_case,
MetaMonitorManager *monitor_manager,
MonitorTestCaseLogicalMonitor *test_logical_monitor)
{
MetaLogicalMonitor *logical_monitor;
MetaOutput *primary_output;
GList *monitors;
GList *l;
int i;
logical_monitor = logical_monitor_from_layout (monitor_manager,
&test_logical_monitor->layout);
g_assert_nonnull (logical_monitor);
g_assert_cmpint (logical_monitor->rect.x,
==,
test_logical_monitor->layout.x);
g_assert_cmpint (logical_monitor->rect.y,
==,
test_logical_monitor->layout.y);
g_assert_cmpint (logical_monitor->rect.width,
==,
test_logical_monitor->layout.width);
g_assert_cmpint (logical_monitor->rect.height,
==,
test_logical_monitor->layout.height);
g_assert_cmpfloat (logical_monitor->scale,
==,
test_logical_monitor->scale);
g_assert_cmpuint (logical_monitor->transform,
==,
test_logical_monitor->transform);
if (logical_monitor == monitor_manager->primary_logical_monitor)
g_assert (meta_logical_monitor_is_primary (logical_monitor));
primary_output = NULL;
monitors = meta_logical_monitor_get_monitors (logical_monitor);
g_assert_cmpint ((int) g_list_length (monitors),
==,
test_logical_monitor->n_monitors);
for (i = 0; i < test_logical_monitor->n_monitors; i++)
{
MetaMonitor *monitor =
g_list_nth (monitor_manager->monitors,
test_logical_monitor->monitors[i])->data;
g_assert_nonnull (g_list_find (monitors, monitor));
}
for (l = monitors; l; l = l->next)
{
MetaMonitor *monitor = l->data;
GList *outputs;
GList *l_output;
outputs = meta_monitor_get_outputs (monitor);
for (l_output = outputs; l_output; l_output = l_output->next)
{
MetaOutput *output = l_output->data;
MetaCrtc *crtc;
if (output->is_primary)
{
g_assert_null (primary_output);
primary_output = output;
}
crtc = meta_output_get_assigned_crtc (output);
g_assert (!crtc ||
meta_monitor_get_logical_monitor (monitor) == logical_monitor);
g_assert_cmpint (logical_monitor->is_presentation,
==,
output->is_presentation);
}
}
if (logical_monitor == monitor_manager->primary_logical_monitor)
g_assert_nonnull (primary_output);
}
static void
check_monitor_configuration (MonitorTestCase *test_case)
{
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
MetaMonitorManagerTest *monitor_manager_test =
META_MONITOR_MANAGER_TEST (monitor_manager);
MetaGpu *gpu = meta_backend_test_get_gpu (META_BACKEND_TEST (backend));
int tiled_monitor_count;
GList *monitors;
GList *crtcs;
int n_logical_monitors;
GList *l;
int i;
g_assert_cmpint (monitor_manager->screen_width,
==,
test_case->expect.screen_width);
g_assert_cmpint (monitor_manager->screen_height,
==,
test_case->expect.screen_height);
g_assert_cmpint ((int) g_list_length (meta_gpu_get_outputs (gpu)),
==,
test_case->expect.n_outputs);
g_assert_cmpint ((int) g_list_length (meta_gpu_get_crtcs (gpu)),
==,
test_case->expect.n_crtcs);
tiled_monitor_count =
meta_monitor_manager_test_get_tiled_monitor_count (monitor_manager_test);
g_assert_cmpint (tiled_monitor_count,
==,
test_case->expect.n_tiled_monitors);
monitors = meta_monitor_manager_get_monitors (monitor_manager);
g_assert_cmpint ((int) g_list_length (monitors),
==,
test_case->expect.n_monitors);
for (l = monitors, i = 0; l; l = l->next, i++)
{
MetaMonitor *monitor = l->data;
GList *outputs;
GList *l_output;
int j;
int width_mm, height_mm;
GList *modes;
GList *l_mode;
MetaMonitorMode *current_mode;
int expected_current_mode_index;
MetaMonitorMode *expected_current_mode;
outputs = meta_monitor_get_outputs (monitor);
g_assert_cmpint ((int) g_list_length (outputs),
==,
test_case->expect.monitors[i].n_outputs);
for (l_output = outputs, j = 0; l_output; l_output = l_output->next, j++)
{
MetaOutput *output = l_output->data;
uint64_t winsys_id = test_case->expect.monitors[i].outputs[j];
g_assert (output == output_from_winsys_id (backend, winsys_id));
g_assert_cmpint (test_case->expect.monitors[i].is_underscanning,
==,
output->is_underscanning);
}
meta_monitor_get_physical_dimensions (monitor, &width_mm, &height_mm);
g_assert_cmpint (width_mm,
==,
test_case->expect.monitors[i].width_mm);
g_assert_cmpint (height_mm,
==,
test_case->expect.monitors[i].height_mm);
modes = meta_monitor_get_modes (monitor);
g_assert_cmpint (g_list_length (modes),
==,
test_case->expect.monitors[i].n_modes);
for (l_mode = modes, j = 0; l_mode; l_mode = l_mode->next, j++)
{
MetaMonitorMode *mode = l_mode->data;
int width;
int height;
float refresh_rate;
MetaCrtcModeFlag flags;
CheckMonitorModeData data;
meta_monitor_mode_get_resolution (mode, &width, &height);
refresh_rate = meta_monitor_mode_get_refresh_rate (mode);
flags = meta_monitor_mode_get_flags (mode);
g_assert_cmpint (width,
==,
test_case->expect.monitors[i].modes[j].width);
g_assert_cmpint (height,
==,
test_case->expect.monitors[i].modes[j].height);
g_assert_cmpfloat (refresh_rate,
==,
test_case->expect.monitors[i].modes[j].refresh_rate);
g_assert_cmpint (flags,
==,
test_case->expect.monitors[i].modes[j].flags);
data = (CheckMonitorModeData) {
.backend = backend,
.expect_crtc_mode_iter =
test_case->expect.monitors[i].modes[j].crtc_modes
};
meta_monitor_mode_foreach_output (monitor, mode,
check_monitor_mode,
&data,
NULL);
}
current_mode = meta_monitor_get_current_mode (monitor);
expected_current_mode_index = test_case->expect.monitors[i].current_mode;
if (expected_current_mode_index == -1)
expected_current_mode = NULL;
else
expected_current_mode = g_list_nth (modes,
expected_current_mode_index)->data;
g_assert (current_mode == expected_current_mode);
if (current_mode)
g_assert (meta_monitor_is_active (monitor));
else
g_assert (!meta_monitor_is_active (monitor));
if (current_mode)
{
CheckMonitorModeData data;
data = (CheckMonitorModeData) {
.backend = backend,
.expect_crtc_mode_iter =
test_case->expect.monitors[i].modes[expected_current_mode_index].crtc_modes
};
meta_monitor_mode_foreach_output (monitor, expected_current_mode,
check_current_monitor_mode,
&data,
NULL);
}
meta_monitor_derive_current_mode (monitor);
g_assert (current_mode == meta_monitor_get_current_mode (monitor));
}
n_logical_monitors =
meta_monitor_manager_get_num_logical_monitors (monitor_manager);
g_assert_cmpint (n_logical_monitors,
==,
test_case->expect.n_logical_monitors);
/*
* Check that we have a primary logical monitor (except for headless),
* and that the main output of the first monitor is the only output
* that is marked as primary (further below). Note: outputs being primary or
* not only matters on X11.
*/
if (test_case->expect.primary_logical_monitor == -1)
{
g_assert_null (monitor_manager->primary_logical_monitor);
g_assert_null (monitor_manager->logical_monitors);
}
else
{
MonitorTestCaseLogicalMonitor *test_logical_monitor =
&test_case->expect.logical_monitors[test_case->expect.primary_logical_monitor];
MetaLogicalMonitor *logical_monitor;
logical_monitor =
logical_monitor_from_layout (monitor_manager,
&test_logical_monitor->layout);
g_assert (logical_monitor == monitor_manager->primary_logical_monitor);
}
for (i = 0; i < test_case->expect.n_logical_monitors; i++)
{
MonitorTestCaseLogicalMonitor *test_logical_monitor =
&test_case->expect.logical_monitors[i];
check_logical_monitor (test_case, monitor_manager, test_logical_monitor);
}
g_assert_cmpint (n_logical_monitors, ==, i);
crtcs = meta_gpu_get_crtcs (gpu);
for (l = crtcs, i = 0; l; l = l->next, i++)
{
MetaCrtc *crtc = l->data;
MetaCrtcConfig *crtc_config = crtc->config;
if (test_case->expect.crtcs[i].current_mode == -1)
{
g_assert_null (crtc_config);
}
else
{
MetaCrtcMode *expected_current_mode;
g_assert_nonnull (crtc_config);
expected_current_mode =
g_list_nth_data (meta_gpu_get_modes (gpu),
test_case->expect.crtcs[i].current_mode);
g_assert (crtc_config->mode == expected_current_mode);
g_assert_cmpuint (crtc_config->transform,
==,
test_case->expect.crtcs[i].transform);
g_assert_cmpfloat_with_epsilon (crtc_config->layout.origin.x,
test_case->expect.crtcs[i].x,
FLT_EPSILON);
g_assert_cmpfloat_with_epsilon (crtc_config->layout.origin.y,
test_case->expect.crtcs[i].y,
FLT_EPSILON);
}
}
check_monitor_test_clients_state ();
}
static void
meta_output_test_destroy_notify (MetaOutput *output)
{
g_clear_pointer (&output->driver_private, g_free);
}
static MetaMonitorTestSetup *
create_monitor_test_setup (MonitorTestCase *test_case,
MonitorTestFlag flags)
{
MetaMonitorTestSetup *test_setup;
int i;
int n_laptop_panels = 0;
int n_normal_panels = 0;
gboolean hotplug_mode_update;
if (flags & MONITOR_TEST_FLAG_NO_STORED)
hotplug_mode_update = TRUE;
else
hotplug_mode_update = FALSE;
test_setup = g_new0 (MetaMonitorTestSetup, 1);
test_setup->modes = NULL;
for (i = 0; i < test_case->setup.n_modes; i++)
{
MetaCrtcMode *mode;
mode = g_object_new (META_TYPE_CRTC_MODE, NULL);
mode->mode_id = i;
mode->width = test_case->setup.modes[i].width;
mode->height = test_case->setup.modes[i].height;
mode->refresh_rate = test_case->setup.modes[i].refresh_rate;
mode->flags = test_case->setup.modes[i].flags;
test_setup->modes = g_list_append (test_setup->modes, mode);
}
test_setup->crtcs = NULL;
for (i = 0; i < test_case->setup.n_crtcs; i++)
{
MetaCrtc *crtc;
crtc = g_object_new (META_TYPE_CRTC, NULL);
crtc->crtc_id = i + 1;
crtc->all_transforms = ALL_TRANSFORMS;
test_setup->crtcs = g_list_append (test_setup->crtcs, crtc);
}
test_setup->outputs = NULL;
for (i = 0; i < test_case->setup.n_outputs; i++)
{
MetaOutput *output;
MetaOutputTest *output_test;
int crtc_index;
MetaCrtc *crtc;
int preferred_mode_index;
MetaCrtcMode *preferred_mode;
MetaCrtcMode **modes;
int n_modes;
int j;
MetaCrtc **possible_crtcs;
int n_possible_crtcs;
int scale;
gboolean is_laptop_panel;
const char *serial;
crtc_index = test_case->setup.outputs[i].crtc;
if (crtc_index == -1)
crtc = NULL;
else
crtc = g_list_nth_data (test_setup->crtcs, crtc_index);
preferred_mode_index = test_case->setup.outputs[i].preferred_mode;
if (preferred_mode_index == -1)
preferred_mode = NULL;
else
preferred_mode = g_list_nth_data (test_setup->modes,
preferred_mode_index);
n_modes = test_case->setup.outputs[i].n_modes;
modes = g_new0 (MetaCrtcMode *, n_modes);
for (j = 0; j < n_modes; j++)
{
int mode_index;
mode_index = test_case->setup.outputs[i].modes[j];
modes[j] = g_list_nth_data (test_setup->modes, mode_index);
}
n_possible_crtcs = test_case->setup.outputs[i].n_possible_crtcs;
possible_crtcs = g_new0 (MetaCrtc *, n_possible_crtcs);
for (j = 0; j < n_possible_crtcs; j++)
{
int possible_crtc_index;
possible_crtc_index = test_case->setup.outputs[i].possible_crtcs[j];
possible_crtcs[j] = g_list_nth_data (test_setup->crtcs,
possible_crtc_index);
}
output_test = g_new0 (MetaOutputTest, 1);
scale = test_case->setup.outputs[i].scale;
if (scale < 1)
scale = 1;
*output_test = (MetaOutputTest) {
.scale = scale
};
is_laptop_panel = test_case->setup.outputs[i].is_laptop_panel;
serial = test_case->setup.outputs[i].serial;
if (!serial)
serial = "0x123456";
output = g_object_new (META_TYPE_OUTPUT, NULL);
if (crtc)
meta_output_assign_crtc (output, crtc);
output->winsys_id = i;
output->name = (is_laptop_panel ? g_strdup_printf ("eDP-%d",
++n_laptop_panels)
: g_strdup_printf ("DP-%d",
++n_normal_panels));
output->vendor = g_strdup ("MetaProduct's Inc.");
output->product = g_strdup ("MetaMonitor");
output->serial = g_strdup (serial);
output->suggested_x = -1;
output->suggested_y = -1;
output->hotplug_mode_update = hotplug_mode_update;
output->width_mm = test_case->setup.outputs[i].width_mm;
output->height_mm = test_case->setup.outputs[i].height_mm;
output->subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN;
output->preferred_mode = preferred_mode;
output->n_modes = n_modes;
output->modes = modes;