kms_rotation_crc: Remove useless comments
[platform/upstream/intel-gpu-tools.git] / tests / kms_setmode.c
index 47fab25..0b765a9 100644 (file)
@@ -24,7 +24,6 @@
 #include "config.h"
 #endif
 
-#include <assert.h>
 #include <cairo.h>
 #include <errno.h>
 #include <stdint.h>
 #include <getopt.h>
 #include <sys/time.h>
 
-#include "drm_fourcc.h"
 #include "drmtest.h"
 #include "intel_bufmgr.h"
 #include "intel_batchbuffer.h"
-#include "intel_gpu_tools.h"
+#include "intel_io.h"
+#include "igt_kms.h"
 
 #define MAX_CONNECTORS  10
 #define MAX_CRTCS       3
@@ -96,7 +95,7 @@ struct crtc_config {
        int pipe_id;
        int connector_count;
        struct connector_config *cconfs;
-       struct kmstest_fb fb_info;
+       struct igt_fb fb_info;
        drmModeModeInfo mode;
 };
 
@@ -142,24 +141,20 @@ static bool crtc_supports_mode(struct crtc_config *crtc, drmModeModeInfo *mode)
        return true;
 }
 
-static int paint_fb(struct kmstest_fb *fb, const char *test_name,
+static int paint_fb(struct igt_fb *fb, const char *test_name,
                    const char **crtc_str, int crtc_count, int current_crtc_idx)
 {
        double x, y;
        cairo_t *cr;
        int i;
 
-       cr = kmstest_get_cairo_ctx(drm_fd, fb);
-       if (!cr)
-               return -1;
+       cr = igt_get_cairo_ctx(drm_fd, fb);
 
-       kmstest_paint_test_pattern(cr, fb->width, fb->height);
+       igt_paint_test_pattern(cr, fb->width, fb->height);
 
-       cairo_select_font_face(cr, "Helvetica", CAIRO_FONT_SLANT_NORMAL,
-                              CAIRO_FONT_WEIGHT_NORMAL);
        cairo_move_to(cr, fb->width / 2, fb->height / 2);
        cairo_set_font_size(cr, 24);
-       kmstest_cairo_printf_line(cr, align_hcenter, 40, "%s", test_name);
+       igt_cairo_printf_line(cr, align_hcenter, 40, "%s", test_name);
 
        cairo_get_current_point(cr, &x, &y);
        cairo_move_to(cr, 60, y);
@@ -168,18 +163,20 @@ static int paint_fb(struct kmstest_fb *fb, const char *test_name,
                if (i == current_crtc_idx) {
                        cairo_get_current_point(cr, &x, &y);
                        cairo_move_to(cr, x - 20, y);
-                       kmstest_cairo_printf_line(cr, align_right, 20, "X");
+                       igt_cairo_printf_line(cr, align_right, 20, "X");
                        cairo_move_to(cr, x, y);
                }
-               kmstest_cairo_printf_line(cr, align_left, 20, "%s",
+               igt_cairo_printf_line(cr, align_left, 20, "%s",
                                          crtc_str[i]);
        }
 
+       cairo_destroy(cr);
+
        return 0;
 }
 
 static void create_fb_for_crtc(struct crtc_config *crtc,
-                              struct kmstest_fb *fb_info)
+                              struct igt_fb *fb_info)
 {
        int bpp;
        int depth;
@@ -189,10 +186,11 @@ static void create_fb_for_crtc(struct crtc_config *crtc,
        bpp = 32;
        depth = 24;
        enable_tiling = false;
-       fb_id = kmstest_create_fb(drm_fd, crtc->mode.hdisplay,
-                                 crtc->mode.vdisplay, bpp, depth,
+       fb_id = igt_create_fb(drm_fd, crtc->mode.hdisplay,
+                                 crtc->mode.vdisplay,
+                                 igt_bpp_depth_to_drm_format(bpp, depth),
                                  enable_tiling, fb_info);
-       assert(fb_id > 0);
+       igt_assert(fb_id > 0);
 }
 
 static void get_mode_for_crtc(struct crtc_config *crtc,
@@ -238,7 +236,7 @@ static int get_encoder_idx(drmModeRes *resources, drmModeEncoder *encoder)
        for (i = 0; i < resources->count_encoders; i++)
                if (resources->encoders[i] == encoder->encoder_id)
                        return i;
-       assert(0);
+       igt_assert(0);
 }
 
 static void get_crtc_config_str(struct crtc_config *crtc, char *buf,
@@ -274,6 +272,7 @@ static void setup_crtcs(drmModeRes *resources, struct connector_config *cconf,
        int crtc_count;
        bool config_valid;
        int i;
+       int encoder_usage_count[resources->count_encoders];
 
        i = 0;
        crtc_count = 0;
@@ -302,7 +301,7 @@ static void setup_crtcs(drmModeRes *resources, struct connector_config *cconf,
 
                crtc->cconfs = malloc(sizeof(*crtc->cconfs) *
                                      crtc->connector_count);
-               assert(crtc->cconfs);
+               igt_assert(crtc->cconfs);
 
                encoder_mask = 0;
                for (j = 0; j < crtc->connector_count; j++) {
@@ -316,7 +315,7 @@ static void setup_crtcs(drmModeRes *resources, struct connector_config *cconf,
                        igt_assert(connector->count_encoders == 1);
                        encoder = drmModeGetEncoder(drm_fd,
                                                    connector->encoders[0]);
-                       assert(encoder);
+                       igt_assert(encoder);
 
                        config_valid &= !!(encoder->possible_crtcs &
                                          (1 << crtc->crtc_idx));
@@ -336,6 +335,20 @@ static void setup_crtcs(drmModeRes *resources, struct connector_config *cconf,
                crtc++;
        }
 
+       memset(encoder_usage_count, 0, sizeof(encoder_usage_count));
+       for (i = 0; i < connector_count; i++) {
+               drmModeConnector *connector = cconf[i].connector;
+               drmModeEncoder *encoder;
+
+               igt_assert(connector->count_encoders == 1);
+               encoder = drmModeGetEncoder(drm_fd, connector->encoders[0]);
+               encoder_usage_count[get_encoder_idx(resources, encoder)]++;
+               drmModeFreeEncoder(encoder);
+       }
+       for (i = 0; i < resources->count_encoders; i++)
+               if (encoder_usage_count[i] > 1)
+                       config_valid = false;
+
        *crtc_count_ret = crtc_count;
        *config_valid_ret = config_valid;
 }
@@ -355,7 +368,7 @@ static uint32_t *get_connector_ids(struct crtc_config *crtc)
        int i;
 
        ids = malloc(sizeof(*ids) * crtc->connector_count);
-       assert(ids);
+       igt_assert(ids);
        for (i = 0; i < crtc->connector_count; i++)
                ids[i] = crtc->cconfs[i].connector->connector_id;
 
@@ -379,7 +392,7 @@ static void test_crtc_config(const struct test_config *tconf,
        if (filter_test_id && filter_test_id != test_id)
                return;
 
-       printf("  Test id#%d CRTC count %d\n", test_id, crtc_count);
+       igt_info("  Test id#%d CRTC count %d\n", test_id, crtc_count);
 
        for (i = 0; i < crtc_count; i++) {
                get_crtc_config_str(&crtcs[i], str_buf[i], sizeof(str_buf[i]));
@@ -388,7 +401,7 @@ static void test_crtc_config(const struct test_config *tconf,
 
        if (dry_run) {
                for (i = 0; i < crtc_count; i++)
-                       printf("    %s\n", crtc_strs[i]);
+                       igt_info("    %s\n", crtc_strs[i]);
                return;
        }
 
@@ -398,7 +411,7 @@ static void test_crtc_config(const struct test_config *tconf,
 
                crtc = &crtcs[i];
 
-               printf("    %s\n", crtc_strs[i]);
+               igt_info("    %s\n", crtc_strs[i]);
 
                create_fb_for_crtc(crtc, &crtc->fb_info);
                paint_fb(&crtc->fb_info, tconf->name, crtc_strs, crtc_count, i);
@@ -486,7 +499,7 @@ static int get_one_connector(drmModeRes *resources, int connector_id,
        drmModeModeInfo mode;
 
        connector = drmModeGetConnector(drm_fd, connector_id);
-       assert(connector);
+       igt_assert(connector);
        cconf->connector = connector;
 
        cconf->connected = connector->connection == DRM_MODE_CONNECTED;
@@ -527,7 +540,7 @@ static int get_connectors(drmModeRes *resources, int *connector_idxs,
                int connector_id;
 
                connector_idx = connector_idxs[i];
-               assert(connector_idx < resources->count_connectors);
+               igt_assert(connector_idx < resources->count_connectors);
                connector_id = resources->connectors[connector_idx];
 
                if (get_one_connector(resources, connector_id, &cconfs[i]) < 0)
@@ -573,7 +586,7 @@ static void iterate_combinations(int n, int k, bool allow_repetitions,
        int v;
 
        if (!k) {
-               assert(set->count < ARRAY_SIZE(set->items));
+               igt_assert(set->count < ARRAY_SIZE(set->items));
                set->items[set->count++] = *comb;
                return;
        }
@@ -592,7 +605,7 @@ static void get_combinations(int n, int k, bool allow_repetitions,
 {
        struct combination comb;
 
-       assert(k <= ARRAY_SIZE(set->items[0].elems));
+       igt_assert(k <= ARRAY_SIZE(set->items[0].elems));
        set->count = 0;
        iterate_combinations(n, k, allow_repetitions, 0, 0, &comb, set);
 }
@@ -610,15 +623,15 @@ static void test_combinations(const struct test_config *tconf,
        get_combinations(tconf->resources->count_crtcs, connector_count,
                         true, &crtc_combs);
 
-       printf("Testing: %s %d connector combinations\n", tconf->name,
-               connector_count);
+       igt_info("Testing: %s %d connector combinations\n", tconf->name,
+                connector_count);
        for (i = 0; i < connector_combs.count; i++) {
                int *connector_idxs;
                int ret;
                int j;
 
                cconfs = malloc(sizeof(*cconfs) * connector_count);
-               assert(cconfs);
+               igt_assert(cconfs);
 
                connector_idxs = &connector_combs.items[i].elems[0];
                ret = get_connectors(tconf->resources, connector_idxs,
@@ -662,7 +675,7 @@ static int opt_handler(int opt, int opt_index)
                filter_test_id = atoi(optarg);
                break;
        default:
-               assert(0);
+               igt_assert(0);
        }
 
        return 0;
@@ -674,6 +687,8 @@ int main(int argc, char **argv)
                enum test_flags flags;
                const char *name;
        } tests[] = {
+               { TEST_CLONE | TEST_SINGLE_CRTC_CLONE,
+                                       "clone-single-crtc" },
                { TEST_INVALID | TEST_CLONE | TEST_SINGLE_CRTC_CLONE,
                                        "invalid-clone-single-crtc" },
                { TEST_INVALID | TEST_CLONE | TEST_EXCLUSIVE_CRTC_CLONE,
@@ -694,17 +709,16 @@ int main(int argc, char **argv)
 
        igt_skip_on_simulation();
 
-       if (dry_run && filter_test_id) {
-               fprintf(stderr, "only one of -d and -t is accepted\n");
-               exit(1);
-       }
+       igt_assert_f(!(dry_run && filter_test_id),
+                    "only one of -d and -t is accepted\n");
 
        igt_fixture {
                drm_fd = drm_open_any();
-               do_or_die(igt_set_vt_graphics_mode());
+               if (!dry_run)
+                       igt_set_vt_graphics_mode();
 
                drm_resources = drmModeGetResources(drm_fd);
-               assert(drm_resources);
+               igt_assert(drm_resources);
        }
 
        for (i = 0; i < ARRAY_SIZE(tests); i++) {