glx-oml-sync-control-timing: Refactor helper functions for swap / wait
[piglit.git] / tests / spec / glx_oml_sync_control / swapbuffersmsc-divisor-zero.c
blob9a9f9ef443582ba825327e255b7d8b2f8b4e3c92
1 /*
2 * Copyright © 2012 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 DEALINGS
21 * IN THE SOFTWARE.
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
28 /** @file swapbuffersmsc-divisor-zero.c
30 * Test that when the divsior is zero in glXSwapBuffersMscOML, the
31 * target MSC is reached.
34 #include "piglit-util-gl.h"
35 #include "piglit-glx-util.h"
36 #include "common.h"
38 int piglit_width = 50, piglit_height = 50;
40 enum piglit_result
41 draw(Display *dpy)
43 /* Fill the variables that will be returned as out values with
44 * junk to better detect failure there.
46 int64_t start_ust = 0xd0, start_msc = 0xd0, start_sbc = 0xd0;
47 int64_t swapped_ust = 0xd0, swapped_msc = 0xd0, swapped_sbc = 0xd0;
48 int64_t current_ust = 0xd0, current_msc = 0xd0, current_sbc = 0xd0;
49 int64_t target_msc, outstanding_sbc;
50 bool already_wrapped = false;
52 piglit_set_timeout(5, PIGLIT_FAIL);
54 glXGetSyncValuesOML(dpy, win, &start_ust, &start_msc, &start_sbc);
55 if (start_sbc != 0) {
56 fprintf(stderr,
57 "Initial SBC for the window should be 0, was %lld\n",
58 (long long)start_sbc);
59 piglit_report_result(PIGLIT_FAIL);
61 outstanding_sbc = start_sbc;
63 wrap:
64 glClearColor(0.0, 1.0, 0.0, 0.0);
65 glClear(GL_COLOR_BUFFER_BIT);
67 /* Queue a swap for 5 frames from when we started. */
68 target_msc = start_msc + 5;
69 glXSwapBuffersMscOML(dpy, win, target_msc, 0, 0);
70 outstanding_sbc++;
72 /* Wait for that swap. */
73 glXWaitForSbcOML(dpy, win, outstanding_sbc,
74 &swapped_ust, &swapped_msc, &swapped_sbc);
75 if (swapped_sbc != outstanding_sbc) {
76 fprintf(stderr,
77 "glXWaitForSbcOML() returned SBC %lld, "
78 "should be %lld\n",
79 (long long)swapped_sbc, (long long)outstanding_sbc);
80 piglit_report_result(PIGLIT_FAIL);
83 glXGetSyncValuesOML(dpy, win,
84 &current_ust, &current_msc, &current_sbc);
85 if (current_sbc != outstanding_sbc) {
86 fprintf(stderr,
87 "glXGetSyncValuesOML() returned SBC %lld, "
88 "should be %lld\n",
89 (long long)current_sbc, (long long)outstanding_sbc);
90 piglit_report_result(PIGLIT_FAIL);
93 if (current_msc < start_msc) {
94 /* The MSC counter wrapped. Try the test again. But
95 * it definitely won't wrap this time.
97 if (already_wrapped) {
98 fprintf(stderr,
99 "Wrapped MSC twice!\n"
100 "Second time: %lld -> %lld\n",
101 (long long)start_msc,
102 (long long)current_msc);
103 piglit_report_result(PIGLIT_FAIL);
106 glXGetSyncValuesOML(dpy, win,
107 &start_ust, &start_msc, &start_sbc);
108 already_wrapped = true;
109 goto wrap;
112 if (swapped_msc < target_msc) {
113 fprintf(stderr,
114 "glXWaitForSbcOML() returned MSC %lld, "
115 "should be at least %lld\n",
116 (long long)swapped_msc,
117 (long long)target_msc);
118 piglit_report_result(PIGLIT_FAIL);
121 if (current_msc < target_msc ||
122 current_msc < swapped_msc) {
123 fprintf(stderr,
124 "glXGetSyncValuesMsc() returned MSC %lld, "
125 "should be at least swap target msc (%lld) "
126 "and last swap MSC (%lld)\n",
127 (long long)current_msc,
128 (long long)target_msc,
129 (long long)swapped_msc);
130 piglit_report_result(PIGLIT_FAIL);
133 piglit_report_result(PIGLIT_PASS);
135 /* UNREACHED */
136 return PIGLIT_FAIL;
140 main(int argc, char **argv)
142 piglit_oml_sync_control_test_run(false, draw);
144 return 0;