fix the spelling in whole piglit
[piglit.git] / tests / general / sync_api.c
blob38511177682567036b5190008e65abe35f57ea56
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.
23 * Authors:
24 * Ian Romanick <ian.d.romanick@intel.com>
27 /**
28 * \file sync_api.c
29 * Simple test of the API for GL_ARB_sync.
32 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config.supports_gl_compat_version = 10;
38 config.window_width = 400;
39 config.window_height = 300;
40 config.window_visual = PIGLIT_GL_VISUAL_RGB;
42 PIGLIT_GL_TEST_CONFIG_END
44 #define FAIL_ON_ERROR(string) \
45 do { \
46 const GLenum err = glGetError(); \
47 if (err != GL_NO_ERROR) { \
48 fprintf(stderr, "%s generated error %s\n", \
49 string, piglit_get_gl_error_name(err)); \
50 pass = GL_FALSE; \
51 goto done; \
52 } \
53 } while (0)
55 void
56 piglit_init(int argc, char **argv)
58 piglit_require_extension("GL_ARB_sync");
60 glClearColor(0.1, 0.1, 0.3, 0.0);
61 piglit_gen_ortho_projection(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0, GL_FALSE);
64 GLboolean
65 test_GetSynciv(GLsync sync, GLenum pname, GLint expect)
67 GLboolean pass = GL_TRUE;
68 GLint val;
69 GLsizei len;
71 glGetSynciv(sync, pname, 1, & len, & val);
72 FAIL_ON_ERROR("glGetSynciv");
73 if (len != 1) {
74 fprintf(stderr, "glGetSynciv length of %s was %d\n",
75 piglit_get_gl_enum_name(pname), len);
76 pass = GL_FALSE;
77 } else if (val != expect) {
78 fprintf(stderr,
79 "glGetSynciv of %s expected 0x%08x got 0x%08x\n",
80 piglit_get_gl_enum_name(pname), expect, val);
81 pass = GL_FALSE;
84 done:
85 return pass;
88 enum piglit_result
89 piglit_display(void)
91 GLboolean pass = GL_TRUE;
92 GLenum wait_val;
93 GLsync sync;
95 glClear(GL_COLOR_BUFFER_BIT);
97 glBegin(GL_TRIANGLES);
98 glColor3f(.8,0,0);
99 glVertex3f(-0.9, -0.9, -30.0);
100 glColor3f(0,.9,0);
101 glVertex3f( 0.9, -0.9, -30.0);
102 glColor3f(0,0,.7);
103 glVertex3f( 0.0, 0.9, -30.0);
104 glEnd();
106 glGetError();
108 sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
109 FAIL_ON_ERROR("glFenceSync");
111 if (!glIsSync(sync)) {
112 fprintf(stderr, "IsSync(%p) failed\n", sync);
113 pass = GL_FALSE;
114 goto done;
116 FAIL_ON_ERROR("glIsSync");
118 if (! test_GetSynciv(sync, GL_SYNC_CONDITION,
119 GL_SYNC_GPU_COMMANDS_COMPLETE)) {
120 pass = GL_FALSE;
121 goto done;
124 if (! test_GetSynciv(sync, GL_SYNC_FLAGS, 0)) {
125 pass = GL_FALSE;
126 goto done;
129 glFinish();
131 /* After the glFinish, the sync *must* be signaled!
133 if (! test_GetSynciv(sync, GL_SYNC_STATUS, GL_SIGNALED)) {
134 pass = GL_FALSE;
135 goto done;
139 /* Since the sync has already been signaled, the wait should return
140 * GL_ALREADY_SIGNALED.
142 wait_val = glClientWaitSync(sync, 0, 1);
143 FAIL_ON_ERROR("glClientWaitSync");
145 if (wait_val != GL_ALREADY_SIGNALED) {
146 fprintf(stderr,
147 "glClientWaitSync expected GL_ALREADY_SIGNALED, "
148 "got %s\n", piglit_get_gl_enum_name(wait_val));
149 pass = GL_FALSE;
152 glDeleteSync(sync);
153 FAIL_ON_ERROR("glDeleteSync");
155 done:
156 return pass ? PIGLIT_PASS : PIGLIT_FAIL;