blob: 29252ec1d6dc877aef783e9f9f226931ead75664 [file] [log] [blame]
Eric Anholt20f03e62013-12-04 16:00:34 -08001/*
2 * Copyright © 2013 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24#include <stdio.h>
25#include <stdlib.h>
26#include <assert.h>
27#include <err.h>
28#include "epoxy/gl.h"
29#include "epoxy/glx.h"
30#include <X11/Xlib.h>
31
32#include "glx_common.h"
33
34static Display *dpy;
35
36static bool
37test_has_extensions(void)
38{
39 int num_extensions;
40
41 glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions);
42
43 for (int i = 0; i < num_extensions; i++) {
44 char *ext = (char *)glGetStringi(GL_EXTENSIONS, i);
45
46 if (!epoxy_has_gl_extension(ext)) {
47 fprintf(stderr, "GL implementation reported support for %s, "
48 "but epoxy didn't\n", ext);
49 return false;
50 }
51 }
52
53 if (epoxy_has_gl_extension("GL_ARB_ham_sandwich")) {
54 fprintf(stderr, "epoxy implementation reported support for "
55 "GL_ARB_ham_sandwich, but it shouldn't\n");
56 return false;
57 }
58
59 return true;
60}
61
62static bool
63test_gl_version(void)
64{
65 int gl_version, epoxy_version;
66 int major, minor;
67
68 glGetIntegerv(GL_MAJOR_VERSION, &major);
69 glGetIntegerv(GL_MINOR_VERSION, &minor);
70 gl_version = major * 10 + minor;
71
72 if (gl_version < 32) {
73 fprintf(stderr,
74 "Implementation reported GL version %d, should be at least 32\n",
75 gl_version);
76 return false;
77 }
78
79 epoxy_version = epoxy_gl_version();
80 if (epoxy_version != gl_version) {
81 fprintf(stderr,
82 "Epoxy reported GL version %d, should be %d\n",
83 epoxy_version, gl_version);
84 return false;
85 }
86
87 return true;
88}
89
90static bool
91test_glx_version(void)
92{
93 int version = epoxy_glx_version(dpy, 0);
94 const char *version_string;
95 int ret;
96 int server_major, server_minor;
97 int client_major, client_minor;
98 int server, client, expected;
99
100 if (version < 13) {
101 fprintf(stderr,
102 "Reported GLX version %d, should be at least 13 "
103 "according to Linux GL ABI\n",
104 version);
105 return false;
106 }
107
108 version_string = glXQueryServerString(dpy, 0, GLX_VERSION);
109 ret = sscanf(version_string, "%d.%d", &server_major, &server_minor);
110 assert(ret == 2);
111 server = server_major * 10 + server_minor;
112
113 version_string = glXGetClientString(dpy, GLX_VERSION);
114 ret = sscanf(version_string, "%d.%d", &client_major, &client_minor);
115 assert(ret == 2);
116 client = client_major * 10 + client_minor;
117
118 if (client < server)
119 expected = client;
120 else
121 expected = server;
122
123 if (version != expected) {
124 fprintf(stderr,
125 "Reported GLX version %d, should be %d (%s)\n",
126 version, expected, version_string);
127 return false;
128 }
129
130 return true;
131}
132
133int
134main(int argc, char **argv)
135{
136 bool pass = true;
Eric Anholt36847f82014-01-31 15:19:09 -0800137 XVisualInfo *visinfo;
138 Window win;
139 GLXFBConfig config;
Eric Anholt20f03e62013-12-04 16:00:34 -0800140 static const int attribs[] = {
141 GLX_CONTEXT_PROFILE_MASK_ARB,
142 GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
143 GLX_CONTEXT_MAJOR_VERSION_ARB,
144 3,
145 GLX_CONTEXT_MINOR_VERSION_ARB,
146 2,
147 None
148 };
Eric Anholt36847f82014-01-31 15:19:09 -0800149 GLXContext ctx;
150
151 dpy = get_display_or_skip();
152
153 if (!epoxy_has_glx_extension(dpy, 0, "GLX_ARB_create_context_profile"))
154 errx(77, "Test requires GLX_ARB_create_context_profile");
155
156 visinfo = get_glx_visual(dpy);
157 win = get_glx_window(dpy, visinfo, false);
158 config = get_fbconfig_for_visinfo(dpy, visinfo);
159 ctx = glXCreateContextAttribsARB(dpy, config, NULL, True, attribs);
Eric Anholt20f03e62013-12-04 16:00:34 -0800160 if (ctx == None)
161 errx(77, "glXCreateContext failed");
162
163 glXMakeCurrent(dpy, win, ctx);
164
165 pass = test_gl_version() && pass;
166 pass = test_glx_version() && pass;
167 pass = test_has_extensions() && pass;
168
169 return pass != true;
170}