tests: Make monitor test case setup more declarative

In order to more easily create more test cases, make the test case
setup more declarative.

https://bugzilla.gnome.org/show_bug.cgi?id=777732
This commit is contained in:
Jonas Ådahl 2016-12-07 13:54:32 +08:00
parent c6d940d3b2
commit 376a76a082

View File

@ -26,7 +26,96 @@
#define ALL_TRANSFORMS ((1 << (META_MONITOR_TRANSFORM_FLIPPED_270 + 1)) - 1)
static MetaMonitorTestSetup *current_test_setup = NULL;
#define MAX_N_MODES 10
#define MAX_N_OUTPUTS 10
#define MAX_N_CRTCS 10
#define MAX_N_LOGICAL_MONITORS 10
typedef struct _MonitorTestCaseMode
{
int width;
int height;
float refresh_rate;
} 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;
} 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 _MonitorTestCase
{
MonitorTestCaseSetup setup;
} 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 = 222,
.height_mm = 125
}
},
.n_outputs = 2,
.crtcs = {
{
.current_mode = 0
},
{
.current_mode = 0
}
},
.n_crtcs = 2
}
};
static void
meta_test_monitor_linear_config (void)
@ -65,68 +154,129 @@ meta_test_monitor_linear_config (void)
}
}
static void
setup_initial_monitor_test_setup (void)
static MetaMonitorTestSetup *
create_monitor_test_setup (MonitorTestCase *test_case)
{
MetaMonitorTestSetup *test_setup;
int n_monitors = 2;
int i;
test_setup = g_new0 (MetaMonitorTestSetup, 1);
test_setup->n_modes = 1;
test_setup->modes = g_new0 (MetaMonitorMode, 1);
test_setup->modes[0].mode_id = 0;
test_setup->modes[0].width = 1024;
test_setup->modes[0].height = 768;
test_setup->modes[0].refresh_rate = 60.0;
test_setup->n_crtcs = n_monitors;
test_setup->crtcs = g_new0 (MetaCRTC, n_monitors);
test_setup->n_outputs = n_monitors;
test_setup->outputs = g_new0 (MetaOutput, n_monitors);
for (i = 0; i < n_monitors; i++)
test_setup->n_modes = test_case->setup.n_modes;
test_setup->modes = g_new0 (MetaMonitorMode, test_setup->n_modes);
for (i = 0; i < test_setup->n_modes; i++)
{
test_setup->crtcs[i].crtc_id = i + 1;
test_setup->crtcs[i].current_mode = &test_setup->modes[0];
test_setup->crtcs[i].transform = META_MONITOR_TRANSFORM_NORMAL;
test_setup->crtcs[i].all_transforms = ALL_TRANSFORMS;
test_setup->outputs[i].crtc = &test_setup->crtcs[i];
test_setup->outputs[i].winsys_id = i + 1;
test_setup->outputs[i].name = g_strdup_printf ("LVDS%d", i + 1);
test_setup->outputs[i].vendor = g_strdup ("MetaProducts Inc.");
test_setup->outputs[i].product = g_strdup ("unknown");
test_setup->outputs[i].serial = g_strdup ("0xC0FFEE");
test_setup->outputs[i].suggested_x = -1;
test_setup->outputs[i].suggested_y = -1;
test_setup->outputs[i].width_mm = 222;
test_setup->outputs[i].height_mm = 125;
test_setup->outputs[i].subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN;
test_setup->outputs[i].preferred_mode = &test_setup->modes[0];
test_setup->outputs[i].n_modes = 1;
test_setup->outputs[i].modes = g_new0 (MetaMonitorMode *, 1);
test_setup->outputs[i].modes[0] = &test_setup->modes[0];
test_setup->outputs[i].n_possible_crtcs = 1;
test_setup->outputs[i].possible_crtcs = g_new0 (MetaCRTC *, 1);
test_setup->outputs[i].possible_crtcs[0] = &test_setup->crtcs[i];
test_setup->outputs[i].n_possible_clones = 0;
test_setup->outputs[i].possible_clones = NULL;
test_setup->outputs[i].backlight = -1;
test_setup->outputs[i].connector_type = META_CONNECTOR_TYPE_LVDS;
test_setup->outputs[i].scale = 1;
test_setup->modes[i] = (MetaMonitorMode) {
.mode_id = i,
.width = test_case->setup.modes[i].width,
.height = test_case->setup.modes[i].height,
.refresh_rate = test_case->setup.modes[i].refresh_rate
};
}
meta_monitor_manager_test_init_test_setup (test_setup);
current_test_setup = test_setup;
test_setup->n_crtcs = test_case->setup.n_crtcs;
test_setup->crtcs = g_new0 (MetaCRTC, test_setup->n_crtcs);
for (i = 0; i < test_setup->n_crtcs; i++)
{
int current_mode_index;
MetaMonitorMode *current_mode;
current_mode_index = test_case->setup.crtcs[i].current_mode;
if (current_mode_index == -1)
current_mode = NULL;
else
current_mode = &test_setup->modes[current_mode_index];
test_setup->crtcs[i] = (MetaCRTC) {
.crtc_id = i + 1,
.current_mode = current_mode,
.transform = META_MONITOR_TRANSFORM_NORMAL,
.all_transforms = ALL_TRANSFORMS
};
}
test_setup->n_outputs = test_case->setup.n_outputs;
test_setup->outputs = g_new0 (MetaOutput, test_setup->n_outputs);
for (i = 0; i < test_setup->n_outputs; i++)
{
int crtc_index;
MetaCRTC *crtc;
int preferred_mode_index;
MetaMonitorMode *preferred_mode;
MetaMonitorMode **modes;
int n_modes;
int j;
MetaCRTC **possible_crtcs;
int n_possible_crtcs;
crtc_index = test_case->setup.outputs[i].crtc;
if (crtc_index == -1)
crtc = NULL;
else
crtc = &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 = &test_setup->modes[preferred_mode_index];
n_modes = test_case->setup.outputs[i].n_modes;
modes = g_new0 (MetaMonitorMode *, n_modes);
for (j = 0; j < n_modes; j++)
{
int mode_index;
mode_index = test_case->setup.outputs[i].modes[j];
modes[j] = &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] = &test_setup->crtcs[possible_crtc_index];
}
test_setup->outputs[i] = (MetaOutput) {
.crtc = crtc,
.winsys_id = i + 1,
.name = g_strdup_printf ("LVDS%d", i + 1),
.vendor = g_strdup ("MetaProducts Inc."),
.product = g_strdup ("unknown"),
.serial = g_strdup ("0xC0FFEE"),
.suggested_x = -1,
.suggested_y = -1,
.hotplug_mode_update = TRUE, /* Results in config being ignored */
.width_mm = test_case->setup.outputs[i].width_mm,
.height_mm = test_case->setup.outputs[i].height_mm,
.subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN,
.preferred_mode = preferred_mode,
.n_modes = n_modes,
.modes = modes,
.n_possible_crtcs = n_possible_crtcs,
.possible_crtcs = possible_crtcs,
.n_possible_clones = 0,
.possible_clones = NULL,
.backlight = -1,
.connector_type = META_CONNECTOR_TYPE_LVDS,
.scale = 1
};
}
return test_setup;
}
void
init_monitor_tests (void)
{
setup_initial_monitor_test_setup ();
MetaMonitorTestSetup *initial_test_setup;
initial_test_setup = create_monitor_test_setup (&initial_test_case);
meta_monitor_manager_test_init_test_setup (initial_test_setup);
g_test_add_func ("/backends/monitor/linear-config",
meta_test_monitor_linear_config);