2 * Copyright © 2011 Intel Corporation
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:
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
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
25 /** @file glx-string-sanity.c
26 * Sanity check the various GLX extension strings that application can query.
28 * This test reproduces Mesa bug #56057.
32 #include "piglit-util-gl.h"
33 #include "piglit-glx-util.h"
36 eat_whitespace(const char *s
)
38 /* Page 17 of the GLX 1.4 spec says:
40 * "The string is zero-terminated and contains a space-seperated
41 * list of extension names."
43 * It doesn't say whitespace. It just says space.
45 while (*s
== ' ' && *s
!= '\0')
52 eat_characters(const char *s
)
54 while (*s
!= ' ' && *s
!= '\0')
61 find_extension(const char *haystack
, const char *needle
, size_t needle_length
)
63 while ((haystack
= strstr(haystack
, needle
)) != NULL
) {
64 if (haystack
[needle_length
] == '\0'
65 || haystack
[needle_length
] == ' ')
73 validate_string(const char *string
, const char *name
)
77 while (*string
!= '\0') {
78 string
= eat_whitespace(string
);
82 if (strncmp("GLX_", string
, 4) != 0) {
85 /* Since the extension string may be very long, just
86 * log a few characters.
88 strncpy(junk
, string
, sizeof(junk
));
89 junk
[sizeof(junk
) - 1] = '\0';
90 fprintf(stderr
, "%s contains junk: %s\n", name
, junk
);
94 string
= eat_characters(string
);
101 main(int argc
, char **argv
)
104 const char *client_string
;
105 const char *server_string
;
106 const char *unified_string
;
109 Display
*dpy
= XOpenDisplay(NULL
);
111 fprintf(stderr
, "couldn't open display\n");
112 piglit_report_result(PIGLIT_FAIL
);
115 /* First, make sure that all the strings have the correct format.
117 server_string
= glXQueryServerString(dpy
, 0, GLX_EXTENSIONS
);
118 pass
= validate_string(server_string
, "server extensions string")
121 client_string
= glXGetClientString(dpy
, GLX_EXTENSIONS
);
122 pass
= validate_string(client_string
, "client extensions string")
125 unified_string
= glXQueryExtensionsString(dpy
, 0);
126 pass
= validate_string(unified_string
, "unified extensions string")
129 /* Now make sure that any string listed in both the server string and
130 * the client string is listed in the unified string.
132 * Also make sure that any string *not* listed in the client string is
133 * *not* listed in the unified string. Since there are several
134 * "client only" extensions (e.g., GLX_ARB_get_proc_address), it is
135 * valid for a string to not be in the server string when it is listed
136 * in the unified string.
138 buf
= malloc(strlen(server_string
) + 1);
139 while (*server_string
!= '\0') {
145 server_string
= eat_whitespace(server_string
);
146 if (*server_string
== '\0')
149 end
= eat_characters(server_string
);
151 bytes
= (size_t)(end
- server_string
);
152 memcpy(buf
, server_string
, bytes
);
155 /* Try to find the extension in the client extension list.
157 client
= find_extension(client_string
, buf
, bytes
);
158 if (client
== NULL
) {
159 if (find_extension(unified_string
, buf
, bytes
) != NULL
) {
161 "%s not found in client extension "
162 "string, but found in unified "
176 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);