1e52adb7bSmrg/*
2e52adb7bSmrg * Copyright © 2013 Intel Corporation
3e52adb7bSmrg *
4e52adb7bSmrg * Permission is hereby granted, free of charge, to any person obtaining a
5e52adb7bSmrg * copy of this software and associated documentation files (the "Software"),
6e52adb7bSmrg * to deal in the Software without restriction, including without limitation
7e52adb7bSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8e52adb7bSmrg * and/or sell copies of the Software, and to permit persons to whom the
9e52adb7bSmrg * Software is furnished to do so, subject to the following conditions:
10e52adb7bSmrg *
11e52adb7bSmrg * The above copyright notice and this permission notice (including the next
12e52adb7bSmrg * paragraph) shall be included in all copies or substantial portions of the
13e52adb7bSmrg * Software.
14e52adb7bSmrg *
15e52adb7bSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16e52adb7bSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17e52adb7bSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18e52adb7bSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19e52adb7bSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20e52adb7bSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21e52adb7bSmrg * IN THE SOFTWARE.
22e52adb7bSmrg */
23e52adb7bSmrg
24e52adb7bSmrg#include <stdio.h>
25e52adb7bSmrg#include <assert.h>
26e52adb7bSmrg#include "epoxy/gl.h"
27e52adb7bSmrg#include "epoxy/glx.h"
28e52adb7bSmrg#include <X11/Xlib.h>
29e52adb7bSmrg
30e52adb7bSmrg#include "glx_common.h"
31e52adb7bSmrg
32e52adb7bSmrgstatic Display *dpy;
33e52adb7bSmrg
34e52adb7bSmrgstatic bool
35e52adb7bSmrgtest_gl_version(void)
36e52adb7bSmrg{
37e52adb7bSmrg    int version = epoxy_gl_version();
38e52adb7bSmrg    if (version < 12) {
39e52adb7bSmrg        fprintf(stderr,
40e52adb7bSmrg                "Reported GL version %d, should be at least 12\n",
41e52adb7bSmrg                version);
42e52adb7bSmrg        return false;
43e52adb7bSmrg    }
44e52adb7bSmrg
45e52adb7bSmrg    return true;
46e52adb7bSmrg}
47e52adb7bSmrg
48e52adb7bSmrgstatic bool
49e52adb7bSmrgtest_glx_version(void)
50e52adb7bSmrg{
51e52adb7bSmrg    int version = epoxy_glx_version(dpy, 0);
52e52adb7bSmrg    const char *version_string;
53e52adb7bSmrg    int ret;
54e52adb7bSmrg    int server_major, server_minor;
55e52adb7bSmrg    int client_major, client_minor;
56e52adb7bSmrg    int server, client, expected;
57e52adb7bSmrg
58e52adb7bSmrg    if (version < 13) {
59e52adb7bSmrg        fprintf(stderr,
60e52adb7bSmrg                "Reported GLX version %d, should be at least 13 "
61e52adb7bSmrg                "according to Linux GL ABI\n",
62e52adb7bSmrg                version);
63e52adb7bSmrg        return false;
64e52adb7bSmrg    }
65e52adb7bSmrg
66e52adb7bSmrg    version_string = glXQueryServerString(dpy, 0, GLX_VERSION);
67e52adb7bSmrg    ret = sscanf(version_string, "%d.%d", &server_major, &server_minor);
68e52adb7bSmrg    assert(ret == 2);
69e52adb7bSmrg    server = server_major * 10 + server_minor;
70e52adb7bSmrg
71e52adb7bSmrg    version_string = glXGetClientString(dpy, GLX_VERSION);
72e52adb7bSmrg    ret = sscanf(version_string, "%d.%d", &client_major, &client_minor);
73e52adb7bSmrg    assert(ret == 2);
74e52adb7bSmrg    client = client_major * 10 + client_minor;
75e52adb7bSmrg
76e52adb7bSmrg    if (client < server)
77e52adb7bSmrg        expected = client;
78e52adb7bSmrg    else
79e52adb7bSmrg        expected = server;
80e52adb7bSmrg
81e52adb7bSmrg    if (version != expected) {
82e52adb7bSmrg        fprintf(stderr,
83e52adb7bSmrg                "Reported GLX version %d, should be %d (%s)\n",
84e52adb7bSmrg                version, expected, version_string);
85e52adb7bSmrg        return false;
86e52adb7bSmrg    }
87e52adb7bSmrg
88e52adb7bSmrg    return true;
89e52adb7bSmrg}
90e52adb7bSmrg
91e52adb7bSmrgstatic bool
92e52adb7bSmrgtest_glx_extension_supported(void)
93e52adb7bSmrg{
94e52adb7bSmrg    if (!epoxy_has_glx_extension(dpy, 0, "GLX_ARB_get_proc_address")) {
95ca86eba8Smrg        fputs("Incorrectly reported no support for GLX_ARB_get_proc_address "
96ca86eba8Smrg              "(should always be present in Linux ABI)\n",
97ca86eba8Smrg              stderr);
98e52adb7bSmrg        return false;
99e52adb7bSmrg    }
100e52adb7bSmrg
101e52adb7bSmrg    if (epoxy_has_glx_extension(dpy, 0, "GLX_EXT_ham_sandwich")) {
102ca86eba8Smrg        fputs("Incorrectly reported support for GLX_EXT_ham_sandwich\n",
103ca86eba8Smrg              stderr);
104e52adb7bSmrg        return false;
105e52adb7bSmrg    }
106e52adb7bSmrg
107e52adb7bSmrg    return true;
108e52adb7bSmrg}
109e52adb7bSmrg
110e52adb7bSmrgint
111e52adb7bSmrgmain(int argc, char **argv)
112e52adb7bSmrg{
113e52adb7bSmrg    bool pass = true;
114e52adb7bSmrg
115e52adb7bSmrg    dpy = get_display_or_skip();
116e52adb7bSmrg    make_glx_context_current_or_skip(dpy);
117e52adb7bSmrg
118e52adb7bSmrg    pass = test_gl_version() && pass;
119e52adb7bSmrg    pass = test_glx_version() && pass;
120e52adb7bSmrg    pass = test_glx_extension_supported() && pass;
121e52adb7bSmrg
122e52adb7bSmrg    return pass != true;
123e52adb7bSmrg}
124