summaryrefslogtreecommitdiff
path: root/tests/egl/spec/egl_khr_create_context/robustness.c
blob: 36f206756789c28dc733bcbe5b3146b5688a63bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* Copyright 2017 Simon Zeni <simon.zeni@collabora.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

#include <stdbool.h>

#include "piglit-util-egl.h"
#include "common.h"

#define BOOLSTR(x) ((x) ? "yes" : "no")

static void
check_extension(EGLint mask)
{
	if (!EGL_KHR_create_context_setup(mask))
		piglit_report_result(PIGLIT_SKIP);

	piglit_require_egl_extension(egl_dpy, "EGL_EXT_create_context_robustness");
	piglit_require_egl_extension(egl_dpy, "EGL_EXT_query_reset_notification_strategy");

	EGL_KHR_create_context_teardown();
}

static enum piglit_result
check_robustness(EGLenum api, bool robust, bool reset_notif)
{
	enum piglit_result result = PIGLIT_SKIP;
	EGLContext ctx;
	EGLint attribs[11];
	size_t ai = 0;
	EGLint mask = (api == EGL_OPENGL_API) ? EGL_OPENGL_BIT : EGL_OPENGL_ES2_BIT;

	if (!EGL_KHR_create_context_setup(mask))
		goto out;

	if (eglBindAPI(api) != EGL_TRUE)
		goto out;

	/* Always use OpenGL 2.0 or OpenGL ES 2.0 to keep this test reasonably
	 * simple; there are enough variants as-is.
	 */
	attribs[ai++] = EGL_CONTEXT_MAJOR_VERSION_KHR;
	attribs[ai++] = 2;
	attribs[ai++] = EGL_CONTEXT_MINOR_VERSION_KHR;
	attribs[ai++] = 0;

	if (api == EGL_OPENGL_ES_API) {
		attribs[ai++] = EGL_CONTEXT_CLIENT_VERSION;
		attribs[ai++] = 2;
	}

	if (robust) {
		attribs[ai++] = EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT;
		attribs[ai++] = EGL_TRUE;
	}

	if (reset_notif) {
		attribs[ai++] = EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT;
		attribs[ai++] = EGL_LOSE_CONTEXT_ON_RESET_EXT;
	}

	attribs[ai++] = EGL_NONE;

	ctx = eglCreateContext(egl_dpy, cfg, EGL_NO_CONTEXT, attribs);

	if (ctx == EGL_NO_CONTEXT) {
		/*
		 * [EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT] is only
		 * meaningful for OpenGL ES contexts, and specifying it for
		 * other types of contexts will generate an EGL_BAD_ATTRIBUTE
		 * error.
		 */
		if (api == EGL_OPENGL_API && reset_notif) {
			if (!piglit_check_egl_error(EGL_BAD_ATTRIBUTE)) {
				piglit_loge("expected EGL_BAD_ATTRIBUTE");
				result = PIGLIT_FAIL;
				goto out;
			}

			result = PIGLIT_PASS;
			goto out;
		} else {
			piglit_loge("failed to create EGL context");
			result = PIGLIT_FAIL;
			goto out;
		}
	}

	if (eglMakeCurrent(egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE,
			   ctx) != EGL_TRUE) {
		piglit_loge("error: failed to make context current");
		result = PIGLIT_FAIL;
		goto out;
	}

	EGLint strategy;
	EGLBoolean st = eglQueryContext(egl_dpy, ctx,
		EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, &strategy);
	if (st == EGL_FALSE || !piglit_check_egl_error(EGL_SUCCESS)) {
		piglit_loge("failed to query EGL context notification strategy");
		result = PIGLIT_FAIL;
		goto out;
	}

	if (reset_notif && strategy != EGL_LOSE_CONTEXT_ON_RESET_EXT) {
		piglit_loge("invalid reset strategy");
		result = PIGLIT_FAIL;
		goto out;
	} else if (!reset_notif && strategy != EGL_NO_RESET_NOTIFICATION_EXT) {
		piglit_loge("unexpected reset strategy");
		result = PIGLIT_FAIL;
		goto out;
	}

	/* Everything turned out to be fine */
	result = PIGLIT_PASS;
out:

	piglit_logi("%s robust=%s reset_notification=%s : %s",
		    (api == EGL_OPENGL_API) ? "OpenGL" : "OpenGL ES",
		    BOOLSTR(robust), BOOLSTR(reset_notif),
		    piglit_result_to_string(result));
	EGL_KHR_create_context_teardown();
	return result;
}

int main(int argc, char **argv)
{
	enum piglit_result result = PIGLIT_SKIP;

	check_extension(EGL_OPENGL_BIT);
	check_extension(EGL_OPENGL_ES2_BIT);

	piglit_merge_result(&result, check_robustness(EGL_OPENGL_API, true, true));
	piglit_merge_result(&result, check_robustness(EGL_OPENGL_API, true, false));
	piglit_merge_result(&result, check_robustness(EGL_OPENGL_API, false, true));
	piglit_merge_result(&result, check_robustness(EGL_OPENGL_API, false, false));
	piglit_merge_result(&result, check_robustness(EGL_OPENGL_ES_API, true, true));
	piglit_merge_result(&result, check_robustness(EGL_OPENGL_ES_API, true, false));
	piglit_merge_result(&result, check_robustness(EGL_OPENGL_ES_API, false, true));
	piglit_merge_result(&result, check_robustness(EGL_OPENGL_ES_API, false, false));

	piglit_report_result(result);
}