lib/igt_fb: switch to igt_ prefix from kmstest_
[platform/upstream/intel-gpu-tools.git] / tests / kms_setmode.c
1 /*
2  * Permission is hereby granted, free of charge, to any person obtaining a
3  * copy of this software and associated documentation files (the "Software"),
4  * to deal in the Software without restriction, including without limitation
5  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
6  * and/or sell copies of the Software, and to permit persons to whom the
7  * Software is furnished to do so, subject to the following conditions:
8  *
9  * The above copyright notice and this permission notice shall be included in
10  * all copies or substantial portions of the Software.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
18  * IN THE SOFTWARE.
19  *
20  * Authors:
21  *    Imre Deak <imre.deak@intel.com>
22  */
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <cairo.h>
28 #include <errno.h>
29 #include <stdint.h>
30 #include <unistd.h>
31 #include <string.h>
32 #include <getopt.h>
33 #include <sys/time.h>
34
35 #include "drmtest.h"
36 #include "intel_bufmgr.h"
37 #include "intel_batchbuffer.h"
38 #include "intel_io.h"
39 #include "igt_kms.h"
40
41 #define MAX_CONNECTORS  10
42 #define MAX_CRTCS       3
43
44 /* max combinations with repetitions */
45 #define MAX_COMBINATION_COUNT   \
46         (MAX_CONNECTORS * MAX_CONNECTORS * MAX_CONNECTORS)
47 #define MAX_COMBINATION_ELEMS   MAX_CRTCS
48
49 static int drm_fd;
50 static drmModeRes *drm_resources;
51 static int filter_test_id;
52 static bool dry_run;
53
54 const drmModeModeInfo mode_640_480 = {
55         .name           = "640x480",
56         .vrefresh       = 60,
57         .clock          = 25200,
58
59         .hdisplay       = 640,
60         .hsync_start    = 656,
61         .hsync_end      = 752,
62         .htotal         = 800,
63
64         .vdisplay       = 480,
65         .vsync_start    = 490,
66         .vsync_end      = 492,
67         .vtotal         = 525,
68
69         .flags          = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
70 };
71
72 enum test_flags {
73         TEST_INVALID                    = 0x01,
74         TEST_CLONE                      = 0x02,
75         TEST_SINGLE_CRTC_CLONE          = 0x04,
76         TEST_EXCLUSIVE_CRTC_CLONE       = 0x08,
77 };
78
79 struct test_config {
80         const char *name;
81         enum test_flags flags;
82         drmModeRes *resources;
83 };
84
85 struct connector_config {
86         drmModeConnector *connector;
87         int crtc_idx;
88         bool connected;
89         drmModeModeInfo default_mode;
90 };
91
92 struct crtc_config {
93         int crtc_idx;
94         int crtc_id;
95         int pipe_id;
96         int connector_count;
97         struct connector_config *cconfs;
98         struct igt_fb fb_info;
99         drmModeModeInfo mode;
100 };
101
102 static bool drm_mode_equal(drmModeModeInfo *m1, drmModeModeInfo *m2)
103 {
104 #define COMP(x) do { if (m1->x != m2->x) return false; } while (0)
105         COMP(vrefresh);
106         COMP(clock);
107         COMP(hdisplay);
108         COMP(hsync_start);
109         COMP(hsync_end);
110         COMP(htotal);
111         COMP(vdisplay);
112         COMP(vsync_start);
113         COMP(vsync_end);
114         COMP(vtotal);
115         COMP(flags);
116
117         return true;
118 }
119
120 static bool connector_supports_mode(drmModeConnector *connector,
121                                     drmModeModeInfo *mode)
122 {
123         int i;
124
125         for (i = 0; i < connector->count_modes; i++)
126                 if (drm_mode_equal(&connector->modes[i], mode))
127                         return true;
128
129         return false;
130 }
131
132 static bool crtc_supports_mode(struct crtc_config *crtc, drmModeModeInfo *mode)
133 {
134         int i;
135
136         for (i = 0; i < crtc->connector_count; i++) {
137                 if (!connector_supports_mode(crtc->cconfs[i].connector, mode))
138                         return false;
139         }
140
141         return true;
142 }
143
144 static int paint_fb(struct igt_fb *fb, const char *test_name,
145                     const char **crtc_str, int crtc_count, int current_crtc_idx)
146 {
147         double x, y;
148         cairo_t *cr;
149         int i;
150
151         cr = igt_get_cairo_ctx(drm_fd, fb);
152
153         igt_paint_test_pattern(cr, fb->width, fb->height);
154
155         cairo_select_font_face(cr, "Helvetica", CAIRO_FONT_SLANT_NORMAL,
156                                CAIRO_FONT_WEIGHT_NORMAL);
157         cairo_move_to(cr, fb->width / 2, fb->height / 2);
158         cairo_set_font_size(cr, 24);
159         igt_cairo_printf_line(cr, align_hcenter, 40, "%s", test_name);
160
161         cairo_get_current_point(cr, &x, &y);
162         cairo_move_to(cr, 60, y);
163
164         for (i = 0; i < crtc_count; i++) {
165                 if (i == current_crtc_idx) {
166                         cairo_get_current_point(cr, &x, &y);
167                         cairo_move_to(cr, x - 20, y);
168                         igt_cairo_printf_line(cr, align_right, 20, "X");
169                         cairo_move_to(cr, x, y);
170                 }
171                 igt_cairo_printf_line(cr, align_left, 20, "%s",
172                                           crtc_str[i]);
173         }
174
175         cairo_destroy(cr);
176
177         return 0;
178 }
179
180 static void create_fb_for_crtc(struct crtc_config *crtc,
181                                struct igt_fb *fb_info)
182 {
183         int bpp;
184         int depth;
185         bool enable_tiling;
186         int fb_id;
187
188         bpp = 32;
189         depth = 24;
190         enable_tiling = false;
191         fb_id = igt_create_fb(drm_fd, crtc->mode.hdisplay,
192                                   crtc->mode.vdisplay,
193                                   igt_bpp_depth_to_drm_format(bpp, depth),
194                                   enable_tiling, fb_info);
195         igt_assert(fb_id > 0);
196 }
197
198 static void get_mode_for_crtc(struct crtc_config *crtc,
199                               drmModeModeInfo *mode_ret)
200 {
201         drmModeModeInfo mode;
202         int i;
203
204         /*
205          * First try to select a default mode that is supported by all
206          * connectors.
207          */
208         for (i = 0; i < crtc->connector_count; i++) {
209                 mode = crtc->cconfs[i].default_mode;
210                 if (crtc_supports_mode(crtc, &mode))
211                         goto found;
212         }
213
214         /*
215          * Then just fall back to find any that is supported by all
216          * connectors.
217          */
218         for (i = 0; i < crtc->cconfs[0].connector->count_modes; i++) {
219                 mode = crtc->cconfs[0].connector->modes[i];
220                 if (crtc_supports_mode(crtc, &mode))
221                         goto found;
222         }
223
224         /*
225          * If none is found then just pick the default mode of the first
226          * connector and hope the other connectors can support it by scaling
227          * etc.
228          */
229         mode = crtc->cconfs[0].default_mode;
230 found:
231         *mode_ret = mode;
232 }
233
234 static int get_encoder_idx(drmModeRes *resources, drmModeEncoder *encoder)
235 {
236         int i;
237
238         for (i = 0; i < resources->count_encoders; i++)
239                 if (resources->encoders[i] == encoder->encoder_id)
240                         return i;
241         igt_assert(0);
242 }
243
244 static void get_crtc_config_str(struct crtc_config *crtc, char *buf,
245                                 size_t buf_size)
246 {
247         int pos;
248         int i;
249
250         pos = snprintf(buf, buf_size,
251                        "CRTC[%d] [Pipe %s] Mode: %s@%dHz Connectors: ",
252                        crtc->crtc_id, kmstest_pipe_str(crtc->pipe_id),
253                        crtc->mode.name, crtc->mode.vrefresh);
254         if (pos > buf_size)
255                 return;
256         for (i = 0; i < crtc->connector_count; i++) {
257                 drmModeConnector *connector = crtc->cconfs[i].connector;
258
259                 pos += snprintf(&buf[pos], buf_size - pos,
260                         "%s%s-%d[%d]%s", i ? ", " : "",
261                         kmstest_connector_type_str(connector->connector_type),
262                         connector->connector_type_id, connector->connector_id,
263                         crtc->cconfs[i].connected ? "" : " (NC)");
264                 if (pos > buf_size)
265                         return;
266         }
267 }
268
269 static void setup_crtcs(drmModeRes *resources, struct connector_config *cconf,
270                         int connector_count, struct crtc_config *crtcs,
271                         int *crtc_count_ret, bool *config_valid_ret)
272 {
273         struct crtc_config *crtc;
274         int crtc_count;
275         bool config_valid;
276         int i;
277         int encoder_usage_count[resources->count_encoders];
278
279         i = 0;
280         crtc_count = 0;
281         crtc = crtcs;
282         config_valid = true;
283
284         while (i < connector_count) {
285                 drmModeCrtc *drm_crtc;
286                 unsigned long encoder_mask;
287                 int j;
288
289                 igt_assert(crtc_count < MAX_CRTCS);
290
291                 crtc->crtc_idx = cconf[i].crtc_idx;
292                 drm_crtc = drmModeGetCrtc(drm_fd,
293                                           resources->crtcs[crtc->crtc_idx]);
294                 crtc->crtc_id = drm_crtc->crtc_id;
295                 drmModeFreeCrtc(drm_crtc);
296                 crtc->pipe_id = kmstest_get_pipe_from_crtc_id(drm_fd,
297                                                               crtc->crtc_id);
298
299                 crtc->connector_count = 1;
300                 for (j = i + 1; j < connector_count; j++)
301                         if (cconf[j].crtc_idx == crtc->crtc_idx)
302                                 crtc->connector_count++;
303
304                 crtc->cconfs = malloc(sizeof(*crtc->cconfs) *
305                                       crtc->connector_count);
306                 igt_assert(crtc->cconfs);
307
308                 encoder_mask = 0;
309                 for (j = 0; j < crtc->connector_count; j++) {
310                         drmModeConnector *connector;
311                         drmModeEncoder *encoder;
312
313                         crtc->cconfs[j] = cconf[i + j];
314                         connector = cconf[i + j].connector;
315
316                         /* Intel connectors have only a single encoder */
317                         igt_assert(connector->count_encoders == 1);
318                         encoder = drmModeGetEncoder(drm_fd,
319                                                     connector->encoders[0]);
320                         igt_assert(encoder);
321
322                         config_valid &= !!(encoder->possible_crtcs &
323                                           (1 << crtc->crtc_idx));
324
325                         encoder_mask |= 1 << get_encoder_idx(resources,
326                                                              encoder);
327                         config_valid &= !(encoder_mask &
328                                           ~encoder->possible_clones);
329
330                         drmModeFreeEncoder(encoder);
331                 }
332                 get_mode_for_crtc(crtc, &crtc->mode);
333                 create_fb_for_crtc(crtc, &crtc->fb_info);
334
335                 i += crtc->connector_count;
336                 crtc_count++;
337                 crtc++;
338         }
339
340         memset(encoder_usage_count, 0, sizeof(encoder_usage_count));
341         for (i = 0; i < connector_count; i++) {
342                 drmModeConnector *connector = cconf[i].connector;
343                 drmModeEncoder *encoder;
344
345                 igt_assert(connector->count_encoders == 1);
346                 encoder = drmModeGetEncoder(drm_fd, connector->encoders[0]);
347                 encoder_usage_count[get_encoder_idx(resources, encoder)]++;
348                 drmModeFreeEncoder(encoder);
349         }
350         for (i = 0; i < resources->count_encoders; i++)
351                 if (encoder_usage_count[i] > 1)
352                         config_valid = false;
353
354         *crtc_count_ret = crtc_count;
355         *config_valid_ret = config_valid;
356 }
357
358 static void cleanup_crtcs(struct crtc_config *crtcs, int crtc_count)
359 {
360         int i;
361
362         for (i = 0; i < crtc_count; i++) {
363                 free(crtcs[i].cconfs);
364         }
365 }
366
367 static uint32_t *get_connector_ids(struct crtc_config *crtc)
368 {
369         uint32_t *ids;
370         int i;
371
372         ids = malloc(sizeof(*ids) * crtc->connector_count);
373         igt_assert(ids);
374         for (i = 0; i < crtc->connector_count; i++)
375                 ids[i] = crtc->cconfs[i].connector->connector_id;
376
377         return ids;
378 }
379
380 static void test_crtc_config(const struct test_config *tconf,
381                              struct crtc_config *crtcs, int crtc_count)
382 {
383         char str_buf[MAX_CRTCS][1024];
384         const char *crtc_strs[MAX_CRTCS];
385         struct crtc_config *crtc;
386         static int test_id;
387         bool config_failed = false;
388         bool connector_connected = false;
389         int ret = 0;
390         int i;
391
392         test_id++;
393
394         if (filter_test_id && filter_test_id != test_id)
395                 return;
396
397         printf("  Test id#%d CRTC count %d\n", test_id, crtc_count);
398
399         for (i = 0; i < crtc_count; i++) {
400                 get_crtc_config_str(&crtcs[i], str_buf[i], sizeof(str_buf[i]));
401                 crtc_strs[i] = &str_buf[i][0];
402         }
403
404         if (dry_run) {
405                 for (i = 0; i < crtc_count; i++)
406                         printf("    %s\n", crtc_strs[i]);
407                 return;
408         }
409
410         for (i = 0; i < crtc_count; i++) {
411                 uint32_t *ids;
412                 int j;
413
414                 crtc = &crtcs[i];
415
416                 printf("    %s\n", crtc_strs[i]);
417
418                 create_fb_for_crtc(crtc, &crtc->fb_info);
419                 paint_fb(&crtc->fb_info, tconf->name, crtc_strs, crtc_count, i);
420
421                 ids = get_connector_ids(crtc);
422                 ret = drmModeSetCrtc(drm_fd, crtc->crtc_id,
423                                      crtc->fb_info.fb_id, 0, 0, ids,
424                                      crtc->connector_count, &crtc->mode);
425                 free(ids);
426
427                 if (ret < 0) {
428                         igt_assert(errno == EINVAL);
429                         config_failed = true;
430                 }
431
432                 for (j = 0; j < crtc->connector_count; j++)
433                         connector_connected |= crtc->cconfs[j].connected;
434         }
435
436         igt_assert(config_failed == !!(tconf->flags & TEST_INVALID));
437
438         if (ret == 0 && connector_connected && !(tconf->flags & TEST_INVALID))
439                 sleep(5);
440
441         for (i = 0; i < crtc_count; i++) {
442                 if (crtcs[i].fb_info.fb_id) {
443                         drmModeSetCrtc(drm_fd, crtcs[i].crtc_id, 0, 0, 0, NULL,
444                                         0, NULL);
445                         drmModeRmFB(drm_fd, crtcs[i].fb_info.fb_id);
446                         crtcs[i].fb_info.fb_id = 0;
447                 }
448         }
449
450         return;
451 }
452
453 static void test_one_combination(const struct test_config *tconf,
454                                  struct connector_config *cconfs,
455                                  int connector_count)
456 {
457         struct crtc_config crtcs[MAX_CRTCS];
458         int crtc_count;
459         bool config_valid;
460
461         setup_crtcs(tconf->resources, cconfs, connector_count, crtcs,
462                     &crtc_count, &config_valid);
463
464         if (config_valid == !(tconf->flags & TEST_INVALID))
465                 test_crtc_config(tconf, crtcs, crtc_count);
466
467         cleanup_crtcs(crtcs, crtc_count);
468 }
469
470 static int assign_crtc_to_connectors(const struct test_config *tconf,
471                                      int *crtc_idxs, int connector_count,
472                                      struct connector_config *cconfs)
473 {
474         unsigned long crtc_idx_mask;
475         int i;
476
477         crtc_idx_mask = 0;
478         for (i = 0; i < connector_count; i++) {
479                 int crtc_idx = crtc_idxs[i];
480
481                 if ((tconf->flags & TEST_SINGLE_CRTC_CLONE) &&
482                     crtc_idx_mask & ~(1 << crtc_idx))
483                         return -1;
484
485                 if ((tconf->flags & TEST_EXCLUSIVE_CRTC_CLONE) &&
486                     crtc_idx_mask & (1 << crtc_idx))
487                         return -1;
488
489                 crtc_idx_mask |= 1 << crtc_idx;
490
491                 cconfs[i].crtc_idx = crtc_idx;
492         }
493
494         return 0;
495 }
496
497 static int get_one_connector(drmModeRes *resources, int connector_id,
498                              struct connector_config *cconf)
499 {
500         drmModeConnector *connector;
501         drmModeModeInfo mode;
502
503         connector = drmModeGetConnector(drm_fd, connector_id);
504         igt_assert(connector);
505         cconf->connector = connector;
506
507         cconf->connected = connector->connection == DRM_MODE_CONNECTED;
508
509         /*
510          * For DP/eDP we need a connected sink, since mode setting depends
511          * on successful link training and retrieved DPCD parameters.
512          */
513         switch (connector->connector_type) {
514         case DRM_MODE_CONNECTOR_DisplayPort:
515         case DRM_MODE_CONNECTOR_eDP:
516                 if (!cconf->connected) {
517                         drmModeFreeConnector(connector);
518                         return -1;
519                 }
520         }
521
522         if (cconf->connected) {
523                 if (kmstest_get_connector_default_mode(drm_fd, connector,
524                                                         &mode) < 0)
525                         mode = mode_640_480;
526         } else {
527                 mode = mode_640_480;
528         }
529
530         cconf->default_mode = mode;
531
532         return 0;
533 }
534
535 static int get_connectors(drmModeRes *resources, int *connector_idxs,
536                           int connector_count, struct connector_config *cconfs)
537 {
538         int i;
539
540         for (i = 0; i < connector_count; i++) {
541                 int connector_idx;
542                 int connector_id;
543
544                 connector_idx = connector_idxs[i];
545                 igt_assert(connector_idx < resources->count_connectors);
546                 connector_id = resources->connectors[connector_idx];
547
548                 if (get_one_connector(resources, connector_id, &cconfs[i]) < 0)
549                         goto err;
550
551         }
552
553         return 0;
554
555 err:
556         while (i--)
557                 drmModeFreeConnector(cconfs[i].connector);
558
559         return -1;
560 }
561
562 static void free_connectors(struct connector_config *cconfs,
563                             int connector_count)
564 {
565         int i;
566
567         for (i = 0; i < connector_count; i++)
568                 drmModeFreeConnector(cconfs[i].connector);
569 }
570
571 struct combination {
572         int elems[MAX_COMBINATION_ELEMS];
573 };
574
575 struct combination_set {
576         int count;
577         struct combination items[MAX_COMBINATION_COUNT];
578 };
579
580 /*
581  * Get all possible selection of k elements from n elements with or without
582  * repetitions.
583  */
584 static void iterate_combinations(int n, int k, bool allow_repetitions,
585                                  int depth, int base, struct combination *comb,
586                                  struct combination_set *set)
587 {
588         int v;
589
590         if (!k) {
591                 igt_assert(set->count < ARRAY_SIZE(set->items));
592                 set->items[set->count++] = *comb;
593                 return;
594         }
595
596         for (v = base; v < n; v++) {
597                 comb->elems[depth] = v;
598                 iterate_combinations(n, k - 1, allow_repetitions,
599                                      depth + 1, allow_repetitions ? 0 : v + 1,
600                                      comb, set);
601         }
602
603 }
604
605 static void get_combinations(int n, int k, bool allow_repetitions,
606                              struct combination_set *set)
607 {
608         struct combination comb;
609
610         igt_assert(k <= ARRAY_SIZE(set->items[0].elems));
611         set->count = 0;
612         iterate_combinations(n, k, allow_repetitions, 0, 0, &comb, set);
613 }
614
615 static void test_combinations(const struct test_config *tconf,
616                               int connector_count)
617 {
618         struct combination_set connector_combs;
619         struct combination_set crtc_combs;
620         struct connector_config *cconfs;
621         int i;
622
623         get_combinations(tconf->resources->count_connectors, connector_count,
624                          false, &connector_combs);
625         get_combinations(tconf->resources->count_crtcs, connector_count,
626                          true, &crtc_combs);
627
628         printf("Testing: %s %d connector combinations\n", tconf->name,
629                 connector_count);
630         for (i = 0; i < connector_combs.count; i++) {
631                 int *connector_idxs;
632                 int ret;
633                 int j;
634
635                 cconfs = malloc(sizeof(*cconfs) * connector_count);
636                 igt_assert(cconfs);
637
638                 connector_idxs = &connector_combs.items[i].elems[0];
639                 ret = get_connectors(tconf->resources, connector_idxs,
640                                      connector_count, cconfs);
641                 if (ret < 0)
642                         goto free_cconfs;
643
644                 for (j = 0; j < crtc_combs.count; j++) {
645                         int *crtc_idxs = &crtc_combs.items[j].elems[0];
646                         ret = assign_crtc_to_connectors(tconf, crtc_idxs,
647                                                         connector_count,
648                                                         cconfs);
649                         if (ret < 0)
650                                 continue;
651
652                         test_one_combination(tconf, cconfs, connector_count);
653                 }
654
655                 free_connectors(cconfs, connector_count);
656 free_cconfs:
657                 free(cconfs);
658         }
659 }
660
661 static void run_test(const struct test_config *tconf)
662 {
663         int connector_num;
664
665         connector_num = tconf->flags & TEST_CLONE ? 2 : 1;
666         for (; connector_num <= tconf->resources->count_crtcs; connector_num++)
667                 test_combinations(tconf, connector_num);
668 }
669
670 static int opt_handler(int opt, int opt_index)
671 {
672         switch (opt) {
673         case 'd':
674                 dry_run = true;
675                 break;
676         case 't':
677                 filter_test_id = atoi(optarg);
678                 break;
679         default:
680                 igt_assert(0);
681         }
682
683         return 0;
684 }
685
686 int main(int argc, char **argv)
687 {
688         const struct {
689                 enum test_flags flags;
690                 const char *name;
691         } tests[] = {
692                 { TEST_CLONE | TEST_SINGLE_CRTC_CLONE,
693                                         "clone-single-crtc" },
694                 { TEST_INVALID | TEST_CLONE | TEST_SINGLE_CRTC_CLONE,
695                                         "invalid-clone-single-crtc" },
696                 { TEST_INVALID | TEST_CLONE | TEST_EXCLUSIVE_CRTC_CLONE,
697                                         "invalid-clone-exclusive-crtc" },
698                 { TEST_CLONE | TEST_EXCLUSIVE_CRTC_CLONE,
699                                         "clone-exclusive-crtc" },
700         };
701         const char *help_str =
702                "  -d\t\tDon't run any test, only print what would be done. (still needs DRM access)\n"
703                "  -t <test id>\tRun only the test with this id.";
704         int i;
705         int ret;
706
707         ret = igt_subtest_init_parse_opts(argc, argv, "dt:", NULL, help_str,
708                                           opt_handler);
709         if (ret < 0)
710                 return ret == -1 ? 0 : ret;
711
712         igt_skip_on_simulation();
713
714         if (dry_run && filter_test_id) {
715                 fprintf(stderr, "only one of -d and -t is accepted\n");
716                 exit(1);
717         }
718
719         igt_fixture {
720                 drm_fd = drm_open_any();
721                 if (!dry_run)
722                         igt_set_vt_graphics_mode();
723
724                 drm_resources = drmModeGetResources(drm_fd);
725                 igt_assert(drm_resources);
726         }
727
728         for (i = 0; i < ARRAY_SIZE(tests); i++) {
729                 igt_subtest(tests[i].name) {
730                         struct test_config tconf = {
731                                 .flags          = tests[i].flags,
732                                 .name           = tests[i].name,
733                                 .resources      = drm_resources,
734                         };
735                         run_test(&tconf);
736                 }
737         }
738
739         igt_fixture {
740                 drmModeFreeResources(drm_resources);
741
742                 close(drm_fd);
743         }
744
745         igt_exit();
746 }