cmake: respect indentation
[piglit.git] / tests / asmparsertest / asmparsertest.c
blob4d9f301d9686b7de84bc4d49771e3d2222963683
1 /*
2 * Copyright © 2009 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
13 * Software.
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
21 * DEALINGS IN THE SOFTWARE.
24 #include <ctype.h>
26 #include "piglit-util-gl.h"
28 #ifndef TRUE
29 #define FALSE 0
30 #define TRUE (!FALSE)
31 #endif
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config.supports_gl_compat_version = 10;
37 config.window_width = 250;
38 config.window_height = 250;
39 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DEPTH;
41 PIGLIT_GL_TEST_CONFIG_END
43 char *
44 unix_line_endings(const char *input, size_t length)
46 char *output = malloc(length + 1);
47 unsigned i;
48 unsigned j = 0;
50 for (i = 0; i < length; i++) {
51 if ((input[i] == 0x0D) && (input[i + 1] == 0x0A)) {
52 i++;
53 output[j] = 0x0A;
54 } else {
55 output[j] = input[i];
58 j++;
61 output[j] = '\0';
62 return output;
66 char *
67 dos_line_endings(const char *input, size_t length)
69 char *output;
70 unsigned i;
71 unsigned j = 0;
72 size_t new_length = length;
75 for (i = 0; i < length; i++) {
76 if (input[i] == 0x0A) {
77 new_length++;
81 output = malloc(new_length + 1);
82 for (i = 0; i < length; i++) {
83 if ((input[i] == 0x0D) && (input[i + 1] == 0x0A)) {
84 i++;
85 output[j + 0] = 0x0D;
86 output[j + 1] = 0x0A;
87 j += 2;
88 } else if (input[i] == 0x0A) {
89 output[j + 0] = 0x0D;
90 output[j + 1] = 0x0A;
91 j += 2;
92 } else {
93 output[j] = input[i];
94 j++;
98 output[j] = '\0';
99 return output;
103 void
104 compile(const char *filename, GLenum target, int use_ARB)
106 GLenum err;
107 GLuint prognum[2];
108 char *buf;
109 char *ptr;
110 unsigned sz;
111 int expected_fail;
112 char *converted_buffers[2];
113 size_t buffer_sizes[2];
114 unsigned i;
117 if (!piglit_automatic) {
118 printf("%s:\n", filename);
121 buf = piglit_load_text_file(filename, &sz);
122 if (buf == NULL) {
123 fprintf(stderr, "Failed to open %s\n", filename);
124 piglit_report_result(PIGLIT_FAIL);
128 /* Scan the program source looking for two different things. First,
129 * look for comments of the form '# FAIL'. This signals that the
130 * program is expected to fail compilation. Second, look for comments
131 * of the form '# REQUIRE GL_XXX_xxxx_xxxx'. This signals that the
132 * program will only compile if some OpenGL extension is available.
134 expected_fail = (strstr(buf, "# FAIL") != NULL);
136 ptr = buf;
137 while (ptr != NULL) {
138 ptr = strstr(ptr, "# REQUIRE ");
139 if (ptr != NULL) {
140 char extension[128];
141 unsigned i;
143 ptr += strlen("# REQUIRE ");
145 for (i = 0; !isspace((int) ptr[i]) && (ptr[i] != '\0'); i++) {
146 extension[i] = ptr[i];
149 extension[i] = '\0';
150 piglit_require_extension(extension);
155 converted_buffers[0] = unix_line_endings(buf, sz);
156 buffer_sizes[0] = strlen(converted_buffers[0]);
157 converted_buffers[1] = dos_line_endings(buf, sz);
158 buffer_sizes[1] = strlen(converted_buffers[1]);
160 if (use_ARB) {
161 glEnable(target);
162 glGenProgramsARB(2, prognum);
163 } else {
164 glGenProgramsNV(2, prognum);
168 for (i = 0; i < 2; i++) {
169 /* The use_ARB flag is used instead of the target because
170 * GL_VERTEX_PROGRAM_ARB and GL_VERTEX_PROGRAM_NV have the same
171 * value.
173 if (use_ARB) {
174 glBindProgramARB(target, prognum[i]);
175 glProgramStringARB(target, GL_PROGRAM_FORMAT_ASCII_ARB,
176 buffer_sizes[i],
177 (const GLubyte *) converted_buffers[i]);
178 } else {
179 glBindProgramNV(target, prognum[i]);
180 glLoadProgramNV(target, prognum[i],
181 buffer_sizes[i],
182 (const GLubyte *) converted_buffers[i]);
186 err = glGetError();
187 if (err != GL_NO_ERROR) {
188 GLint errorpos;
190 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
191 if (!piglit_automatic) {
192 printf("glGetError = 0x%04x\n", err);
193 printf("errorpos: %d\n", errorpos);
194 printf("%s\n",
195 (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
199 if ((err == GL_NO_ERROR) != (expected_fail == FALSE)) {
200 piglit_report_result(PIGLIT_FAIL);
204 free(buf);
205 free(converted_buffers[0]);
206 free(converted_buffers[1]);
211 void
212 piglit_init(int argc, char **argv)
214 GLenum target;
215 unsigned i;
216 int use_ARB;
219 if (argc < 3) {
220 piglit_report_result(PIGLIT_FAIL);
224 use_ARB = 1;
225 if (strcmp(argv[1], "ARBvp1.0") == 0) {
226 target = GL_VERTEX_PROGRAM_ARB;
227 piglit_require_extension("GL_ARB_vertex_program");
228 } else if (strcmp(argv[1], "ARBfp1.0") == 0) {
229 target = GL_FRAGMENT_PROGRAM_ARB;
230 piglit_require_extension("GL_ARB_fragment_program");
231 } else if (strcmp(argv[1], "NVvp1.0") == 0) {
232 target = GL_VERTEX_PROGRAM_NV;
233 piglit_require_extension("GL_NV_vertex_program");
234 use_ARB = 0;
235 } else if (strcmp(argv[1], "NVfp1.0") == 0) {
236 target = GL_FRAGMENT_PROGRAM_NV;
237 piglit_require_extension("GL_NV_fragment_program");
238 use_ARB = 0;
239 } else {
240 target = GL_NONE;
241 piglit_report_result(PIGLIT_FAIL);
244 for (i = 2; i < argc; i++) {
245 compile(argv[i], target, use_ARB);
248 piglit_report_result(PIGLIT_PASS);
251 enum piglit_result
252 piglit_display(void)
254 /* Should never be reached */
255 return PIGLIT_FAIL;