perf/pixel-rate: new pixel throughput microbenchmark
[piglit.git] / tests / spec / glx_oml_sync_control / waitformsc.c
blobe8de8bad80d288b2e526905abe5322653d26aa76
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 waitformsc.c
30 * Test that glXWaitForMscOML() waits until both it and
31 * glXGetSyncValuesOML() return a an msc that meet the target.
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 wait_ust = 0xd0, wait_msc = 0xd0, wait_sbc = 0xd0;
48 int64_t current_ust = 0xd0, current_msc = 0xd0, current_sbc = 0xd0;
49 int64_t target_msc;
50 bool already_wrapped = false;
52 piglit_set_timeout(5, PIGLIT_FAIL);
54 wrap:
55 glXGetSyncValuesOML(dpy, win, &start_ust, &start_msc, &start_sbc);
57 /* Wait for the MSC to be at least equal to target,
58 * with no divisor trickery.
60 target_msc = start_msc + 5;
61 glXWaitForMscOML(dpy, win, target_msc, 0, 0,
62 &wait_ust, &wait_msc, &wait_sbc);
64 glXGetSyncValuesOML(dpy, win,
65 &current_ust, &current_msc, &current_sbc);
67 if (current_msc < target_msc) {
68 /* The clock may have actually wrapped, in which case
69 * we need to try again because we're not doing
70 * wrapping math here for simplicity.
72 if (!already_wrapped) {
73 already_wrapped = true;
74 goto wrap;
77 fprintf(stderr,
78 "glXGetSyncValuesOML() returned msc of %lld, "
79 "expected >= %lld\n",
80 (long long)current_msc,
81 (long long)target_msc);
84 if (wait_msc < target_msc) {
85 fprintf(stderr,
86 "glXWaitForMscOML() returned msc of %lld, "
87 "expected >= %lld\n",
88 (long long)wait_msc,
89 (long long)target_msc);
92 piglit_report_result(PIGLIT_PASS);
94 /* UNREACHED */
95 return PIGLIT_FAIL;
98 int
99 main(int argc, char **argv)
101 for (int i = 1; i < argc; i++) {
102 if (!strcmp(argv[i], "-auto"))
103 piglit_automatic = 1;
104 else
105 fprintf(stderr, "Unknown option: %s\n", argv[i]);
108 piglit_oml_sync_control_test_run(false, draw);
110 return 0;