summaryrefslogtreecommitdiff
path: root/tests/gbm/gbm-device.c
blob: 8e1a82fde9fb8fd0c257cfc2142fbc5a57859f5c (plain)
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
/* Copyright (c) 2024 Collabora Ltd
 * SPDX-License-Identifier: MIT
 */

/**
 * \file
 * \brief Tests for libgbm.
 */

#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <gbm.h>
#include <sys/stat.h>
#include <sys/types.h>

#include "piglit-util.h"

int
main(int argc, char **argv)
{
	int drm_fd;
	char *nodename;
	struct gbm_device *gbm;

	/* Strip common piglit args. */
	piglit_strip_arg(&argc, argv, "-fbo");
	piglit_strip_arg(&argc, argv, "-auto");

	nodename = getenv("WAFFLE_GBM_DEVICE");
	if (!nodename)
		nodename = "/dev/dri/renderD128";
	drm_fd = open(nodename, O_RDWR);
	if (drm_fd == -1) {
		perror("Error opening render node");
		piglit_report_result(PIGLIT_SKIP);
	}

	gbm = gbm_create_device(drm_fd);
	if (!gbm)
		piglit_report_result(PIGLIT_FAIL);

	if (gbm_device_get_fd(gbm) != drm_fd)
		piglit_report_result(PIGLIT_FAIL);

	gbm_device_destroy(gbm);
	close(drm_fd);

	piglit_report_result(PIGLIT_PASS);
}