PIGLIT_GL_TEST_CONFIG_END

#define DRM_FORMAT_INVALID fourcc_code('F', 'O', 'O', '0')

static bool
test_excess_attributes(unsigned w, unsigned h, int fd, unsigned stride,
		unsigned offset, EGLint attr_id, EGLint attr_val)
{
	const EGLint excess_attr[2 * 7 + 1] = {
			EGL_HEIGHT, w,
		 	EGL_WIDTH, h,
			EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888,
			EGL_DMA_BUF_PLANE0_FD_EXT, fd,
			EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
			EGL_DMA_BUF_PLANE0_PITCH_EXT, stride,
			attr_id, attr_val,
			EGL_NONE };
	EGLImageKHR img = eglCreateImageKHR(eglGetCurrentDisplay(),
				EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT,
				(EGLClientBuffer)NULL, excess_attr);

	if (!piglit_check_egl_error(EGL_BAD_ATTRIBUTE)) {
		if (img)
			eglDestroyImageKHR(eglGetCurrentDisplay(), img);
		return false;
	}

	return true;
}
static bool
test_buffer_not_null(unsigned w, unsigned h, int fd, unsigned stride,
		unsigned offset)
{
	EGLImageKHR img;
	EGLint attr[] = {
		EGL_WIDTH, w,
		EGL_HEIGHT, h,
		EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888,
		EGL_DMA_BUF_PLANE0_FD_EXT, fd,
		EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
		EGL_DMA_BUF_PLANE0_PITCH_EXT, stride,
		EGL_NONE
	};

	/**
	 * The spec says:
	 *
	 *     "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid
	 *      display, <ctx> must be EGL_NO_CONTEXT, and <buffer> must be
	 *      NULL, cast into the type EGLClientBuffer."
	 */
	img = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT,
			EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)1, attr);

	if (!piglit_check_egl_error(EGL_BAD_PARAMETER)) {
		if (img)
			eglDestroyImageKHR(eglGetCurrentDisplay(), img);
		return false;
	}

	return true;
}
static bool
test_pitch_zero(unsigned w, unsigned h, int fd, unsigned stride,
		unsigned offset)
{
	EGLImageKHR img;
	EGLint attr[] = {
		EGL_WIDTH, w,
		EGL_HEIGHT, h,
		EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888,
		EGL_DMA_BUF_PLANE0_FD_EXT, fd,
		EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
		EGL_DMA_BUF_PLANE0_PITCH_EXT, 0,
		EGL_NONE
	};

	img = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT,
			EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)0, attr);

	if (!piglit_check_egl_error(EGL_BAD_ACCESS)) {
		if (img)
			eglDestroyImageKHR(eglGetCurrentDisplay(), img);
		return false;
	}

	return true;
}
Beispiel #4
0
/**
 * Verify that eglCreateSyncKHR emits correct error when no context is current.
 *
 * From the EGL_KHR_fence_sync spec:
 *
 *     If <type> is EGL_SYNC_FENCE_KHR and no context is current for
 *     the bound API (i.e., eglGetCurrentContext returns
 *     EGL_NO_CONTEXT), EGL_NO_SYNC_KHR is returned and an
 *     EGL_BAD_MATCH error is generated.
 */
static enum piglit_result
test_eglCreateSyncKHR_no_current_context(void *test_data)
{
	enum piglit_result result = PIGLIT_PASS;
	EGLSyncKHR sync = 0;

	result = test_setup();
	if (result != PIGLIT_PASS) {
		return result;
	}
	eglMakeCurrent(g_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);

	sync = peglCreateSyncKHR(g_dpy, EGL_SYNC_TYPE_KHR, NULL);
	if (sync) {
		piglit_loge("eglCreateSyncKHR() succeeded when no context was "
			  "current");
		peglDestroySyncKHR(g_dpy, sync);
		result = PIGLIT_FAIL;
	}
	if (!piglit_check_egl_error(EGL_BAD_MATCH)) {
		piglit_loge("eglCreateSyncKHR emitted wrong error");
		result = PIGLIT_FAIL;
	}

	test_cleanup(sync, &result);
	return result;
}
Beispiel #5
0
/**
 * Verify that eglDestroySyncKHR() emits the correct error when given an
 * invalid sync object.
 *
 * From the EGL_KHR_fence_sync spec:
 *
 *      * If <sync> is not a valid sync object for <dpy>, EGL_FALSE is
 *        returned and an EGL_BAD_PARAMETER error is generated.
 */
static enum piglit_result
test_eglDestroySyncKHR_invalid_sync(void *test_data)
{
	enum piglit_result result = PIGLIT_PASS;
	bool ok = false;
	EGLSyncKHR invalid_sync = (EGLSyncKHR) &canary;

	result = test_setup();
	if (result != PIGLIT_PASS) {
		return result;
	}

	ok = peglDestroySyncKHR(g_dpy, invalid_sync);
	if (ok) {
		piglit_loge("eglDestroySyncKHR() succeeded when given invalid "
			  "sync object");
		result = PIGLIT_FAIL;
	}
	if (!piglit_check_egl_error(EGL_BAD_PARAMETER)) {
		piglit_loge("eglGetSyncAttribKHR(EGL_SYNC_TYPE_KHR) emitted "
			  "an incorrect error");
		result = PIGLIT_FAIL;
	}

	test_cleanup(EGL_NO_SYNC_KHR, &result);
	return result;
}
enum piglit_result
piglit_display(void)
{
	const unsigned w = 2;
	const unsigned h = 2;
	const unsigned cpp = 4;
	const unsigned fourcc = DRM_FORMAT_ARGB8888;
	const unsigned char *pixels = alloca(w * h * cpp);
	struct piglit_dma_buf *buf;
	EGLImageKHR img;
	enum piglit_result res;
	bool pass = true;

	res = piglit_create_dma_buf(w, h, fourcc, pixels, &buf);
	if (res != PIGLIT_PASS)
		return res;

	img = create_image(w, h, buf->fd, buf->stride[0], buf->offset[0]);

	if (!img) {
		piglit_destroy_dma_buf(buf);

		/* unsupported format (BAD_MATCH) is not an error. */
		return piglit_check_egl_error(EGL_BAD_MATCH) ?
					PIGLIT_SKIP : PIGLIT_FAIL;
	}

	pass = try_as_texture_2d(img) && pass;
	pass = try_as_render_buffer(img) && pass;

	eglDestroyImageKHR(eglGetCurrentDisplay(), img);
	piglit_destroy_dma_buf(buf);

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Beispiel #7
0
/**
 * Verify that eglClientWaitSyncKHR() emits correct error when given an invalid
 * sync object.
 *
 * From the EGL_KHR_fence_sync:
 *
 *    * If <sync> is not a valid sync object for <dpy>, EGL_FALSE is
 *      returned and an EGL_BAD_PARAMETER error is generated.
 */
static enum piglit_result
test_eglClientWaitSyncKHR_invalid_sync(void *test_data)
{
	enum piglit_result result = PIGLIT_PASS;
	EGLint wait_status = 0;
	EGLSyncKHR invalid_sync = (EGLSyncKHR) &canary;

	result = test_setup();
	if (result != PIGLIT_PASS) {
		return result;
	}

	wait_status = peglClientWaitSyncKHR(g_dpy, invalid_sync, 0, 0);
	if (wait_status != EGL_FALSE) {
		piglit_loge("Given an invalid sync object, eglClientWaitSyncKHR() "
			  "should return EGL_FALSE, but returned 0x%x",
			  wait_status);
		result = PIGLIT_FAIL;
	}
	if (!piglit_check_egl_error(EGL_BAD_PARAMETER)) {
		piglit_loge("Given an invalid sync object, eglClientWaitSyncKHR() "
			  "did not emit EGL_BAD_PARAMETER");
		result = PIGLIT_FAIL;
	}

	test_cleanup(EGL_NO_SYNC_KHR, &result);
	return result;
}
static bool try_attribute(int attribute)
{
	const EGLint attribs[] = {
		attribute,
		EGL_NONE
	};
	bool pass = true;

	ctx = eglCreateContext(egl_dpy, cfg, EGL_NO_CONTEXT, attribs);
	if (ctx != NULL) {
		fprintf(stderr,
			"Created OpenGL context with invalid attribute "
			"0x%08x, but this should have failed.\n",
			attribute);
		eglDestroyContext(egl_dpy, ctx);
		pass = false;
	}

	/* The EGL_KHR_create_context spec says:
	 *
	 *     "* If an attribute name or attribute value in <attrib_list> is not
	 *        recognized (including unrecognized bits in bitmask attributes),
	 *        then an EGL_BAD_ATTRIBUTE error is generated."
	 */
	if (!piglit_check_egl_error(EGL_BAD_ATTRIBUTE))
		piglit_report_result(PIGLIT_FAIL);

	return pass;
}
Beispiel #9
0
/**
 * Verify that eglCreateSyncKHR emits correct error when given an invalid
 * attribute list.
 *
 * From the EGL_KHR_fence_sync spec:
 *
 *     If <attrib_list> is neither NULL nor empty (containing only
 *     EGL_NONE), EGL_NO_SYNC_KHR is returned and an EGL_BAD_ATTRIBUTE
 *     error is generated.
 */
static enum piglit_result
test_eglCreateSyncKHR_invalid_attrib_list(void *test_data)
{
	enum piglit_result result = PIGLIT_PASS;
	EGLSyncKHR sync = 0;
	const EGLint attrib_list[] = {
		EGL_CONTEXT_CLIENT_VERSION, 2,
		EGL_NONE,
	};

	result = test_setup();
	if (result != PIGLIT_PASS) {
		return result;
	}

	sync = peglCreateSyncKHR(g_dpy, EGL_SYNC_FENCE_KHR, attrib_list);
	if (sync) {
		piglit_loge("eglCreateSyncKHR() succeeded with invalid "
			  "attrib list");
		result = PIGLIT_FAIL;
	}
	if (!piglit_check_egl_error(EGL_BAD_ATTRIBUTE)) {
		piglit_loge("eglCreateSyncKHR emitted wrong error");
		result = PIGLIT_FAIL;
	}

	test_cleanup(sync, &result);
	return result;
}
Beispiel #10
0
/**
 * Verify that eglCreateSyncKHR emits correct error when given an invalid
 * sync type.
 *
 * From the EGL_KHR_fence_sync spec:
 *
 *     If <type> is not a supported type of sync object,
 *     EGL_NO_SYNC_KHR is returned and an EGL_BAD_ATTRIBUTE error is
 *     generated.
 *
 * TODO(chadv,joshtriplett): eglCreateSyncKHR should generate EGL_BAD_PARAMETER
 * TODO: on bad sync types, not EGL_BAD_ATTRIBUTE. Bug filed in Khronos private
 * TODO: Bugzilla; update the test when resolved.
 */
static enum piglit_result
test_eglCreateSyncKHR_invalid_sync_type(void *test_data)
{
	enum piglit_result result = PIGLIT_PASS;
	EGLSyncKHR sync = 0;
	EGLenum bad_sync_type = EGL_SYNC_TYPE_KHR;

	result = test_setup();
	if (result != PIGLIT_PASS) {
		return result;
	}

	sync = peglCreateSyncKHR(g_dpy, bad_sync_type, NULL);
	if (sync) {
		piglit_loge("eglCreateSyncKHR() succeeded with invalid "
			  "sync type");
		result = PIGLIT_FAIL;
	}
	if (!piglit_check_egl_error(EGL_BAD_ATTRIBUTE)) {
		piglit_loge("eglCreateSyncKHR emitted wrong error");
		result = PIGLIT_FAIL;
	}

	test_cleanup(sync, &result);
	return result;
}
Beispiel #11
0
/**
 * Verify that eglGetSyncAttribKHR emits the correct error when given an object
 * that is not a sync object.
 *
 * From the EGL_KHR_fence_sync:
 *
 *    * If <sync> is not a valid sync object for <dpy>, EGL_FALSE is
 *      returned and an EGL_BAD_PARAMETER error is generated.
 *
 *    [...]
 *
 *    If any error occurs, <*value> is not modified.
 */
static enum piglit_result
test_eglGetSyncAttribKHR_invalid_sync(void *test_data)
{
	enum piglit_result result = PIGLIT_PASS;
	bool ok = false;
	EGLint sync_type = canary;
	EGLSyncKHR invalid_sync = (EGLSyncKHR) &canary;

	result = test_setup();
	if (result != PIGLIT_PASS) {
		return result;
	}

	ok = peglGetSyncAttribKHR(g_dpy, invalid_sync, EGL_SYNC_TYPE_KHR, &sync_type);
	if (ok) {
		piglit_loge("eglGetSyncAttribKHR incorrectly succeeded when "
		          "given an invalid sync object");
		result = PIGLIT_FAIL;
	}
	if (!piglit_check_egl_error(EGL_BAD_PARAMETER)) {
		piglit_loge("eglGetSyncAttribKHR emitted wrong error");
		result = PIGLIT_FAIL;
	}
	if (sync_type != canary) {
		piglit_loge("eglGetSynAttribKHR modified out parameter <value>");
		result = PIGLIT_FAIL;
	}

	test_cleanup(EGL_NO_SYNC_KHR, &result);
	return result;
}
/**
 * Conformance test #2 in the EGL_EXT_client_extensions spec:
 *
 *    2. Obtain a display with eglGetDisplay but do not initialize it. Verify
 *       that passing the uninitialized display to `eglQueryString(dpy,
 *       EGL_EXTENSIONS)` returns NULL and generates EGL_NOT_INITIALIZED.
 */
static void
test_2(void)
{
	enum piglit_result result = PIGLIT_PASS;
	EGLDisplay dpy;
	const char *display_extensions;

	dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
	if (!dpy) {
		printf("Failed to get default display. Skipping.n");
		piglit_report_result(PIGLIT_SKIP);
	}

	printf("Calling eglQueryString(dpy, EGL_EXTENSIONS) with an "
	       "uninitialized display...\n");
	display_extensions = eglQueryString(dpy, EGL_EXTENSIONS);

	if (display_extensions == NULL) {
		printf("Correctly returned null extension string\n");
	} else {
		printf("Did not return null extension string\n");
		result = PIGLIT_FAIL;
	}

	if (!piglit_check_egl_error(EGL_NOT_INITIALIZED)) {
		result = PIGLIT_FAIL;
	}

	piglit_report_result(result);
}
Beispiel #13
0
static void*
thread2_create_sync_with_display_bound_in_other_thread(void *arg)
{
	enum piglit_result *result;
	EGLDisplay t2_dpy = 0;
	EGLContext t2_ctx = 0;
	EGLSyncKHR t2_sync = 0;

	result = malloc(sizeof(*result));
	*result = PIGLIT_FAIL;

	piglit_logi("create second EGLDisplay");
	*result = init_other_display(&t2_dpy, g_dpy);
	if (*result != PIGLIT_PASS) {
		piglit_loge("failed to initialize a second EGLDisplay");
		goto cleanup;
	}

	if (!piglit_is_egl_extension_supported(t2_dpy, "EGL_KHR_fence_sync")) {
		piglit_loge("EGL_KHR_fence_sync unsupported on second display");
		*result = PIGLIT_SKIP;
		goto cleanup;
	}

	piglit_logi("create and make context current on second display");
	*result = init_context(t2_dpy, &t2_ctx);
	if (*result != PIGLIT_PASS) {
		goto cleanup;
	}

	*result = check_sync_in_current_context();
	if (*result != PIGLIT_PASS) {
		goto cleanup;
	}

	piglit_logi("try to create sync on first display, which is "
		 "bound on thread1");
	t2_sync = peglCreateSyncKHR(t2_dpy, EGL_SYNC_FENCE_KHR, NULL);
	if (t2_sync) {
		piglit_loge("eglCreateSyncKHR incorrectly succeeded");
		*result = PIGLIT_FAIL;
		goto cleanup;
	}
	if (!piglit_check_egl_error(EGL_BAD_MATCH)) {
		piglit_loge("eglCreateSyncKHR emitted wrong error");
		*result = PIGLIT_FAIL;
		goto cleanup;
	}
	piglit_logi("eglCreateSyncKHR correctly failed with "
		 "EGL_BAD_MATCH");

cleanup:
	if (t2_dpy) {
		eglMakeCurrent(t2_dpy, 0, 0, 0);
		eglTerminate(t2_dpy);
	}
	return result;
}
/**
 * Conformance test #1 in the EGL_EXT_client_extensions spec:
 *
 *     1. Before any call to eglGetDisplay, call `eglQueryString(EGL_NO_DISPLAY,
 *        EGL_EXTENSIONS)`. Verify that either
 *
 *          a. The call returns NULL and generates EGL_BAD_DISPLAY.
 *          b. The call returns an extension string that contains, at a minimum,
 *             this extension and generates no error.
 */
static void
test_1(void)
{
	enum piglit_result result = PIGLIT_PASS;
	const char *client_extensions;

	printf("Making process's first EGL call, "
	       "eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS) ...\n");
	client_extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);

	if (client_extensions == NULL) {
		printf("Returned NULL\n");
		if (piglit_check_egl_error(EGL_BAD_DISPLAY)) {
			printf("And correctly emitted EGL_BAD_DISPLAY\n");
		} else {
			printf("But did not emit EGL_BAD_DISPLAY\n");
			result = PIGLIT_FAIL;
		}
	} else {
		printf("Returned a non-null extension string\n");

		if (!piglit_check_egl_error(EGL_SUCCESS)) {
			result = PIGLIT_FAIL;
		}

		if (!piglit_is_extension_in_string(client_extensions,
						   "EGL_EXT_client_extensions")) {
			printf("But it does not contain "
			       "EGL_EXT_client_extensions\n");
			result = PIGLIT_FAIL;
		} else {
			printf("And contains EGL_EXT_client_extensions "
			       "as expected\n");
		}
	}

	piglit_report_result(result);
}
PIGLIT_GL_TEST_CONFIG_END

#define NUM_MANDATORY_ATTRS 6

static bool
test_missing(int fd, const EGLint *attr)
{
	EGLImageKHR img;

	img = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT,
			EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)NULL, attr);

	if (!piglit_check_egl_error(EGL_BAD_PARAMETER)) {
		if (img)
			eglDestroyImageKHR(eglGetCurrentDisplay(), img);
		return false;
	}

	return true;
}
Beispiel #16
0
/**
 * Verify that eglCreateSyncKHR() emits correct error when given a display that
 * does not match the display of the bound context.
 *
 * From the EGL_KHR_fence_sync spec:
 *
 *      * If <type> is EGL_SYNC_FENCE_KHR and <dpy> does not match the
 *        EGLDisplay of the currently bound context for the currently
 *        bound client API (the EGLDisplay returned by
 *        eglGetCurrentDisplay()) then EGL_NO_SYNC_KHR is returned and an
 *        EGL_BAD_MATCH error is generated.
 *
 * This test verifies a simple case for the above error. It binds a context and
 * display to the main thread, creates a second display on the same threads but
 * does not bind it, then gives the second display to eglCreateSyncKHR().
 */
static enum piglit_result
test_eglCreateSyncKHR_wrong_display_same_thread(void *test_data)
{
	enum piglit_result result = PIGLIT_PASS;
	EGLDisplay wrong_dpy = 0;
	EGLSyncKHR sync = 0;

	result = test_setup();
	if (result != PIGLIT_PASS) {
		return result;
	}

	piglit_logi("create second EGLDisplay");
	result = init_other_display(&wrong_dpy, g_dpy);
	if (result != PIGLIT_PASS) {
		goto cleanup;
	}

	piglit_require_egl_extension(wrong_dpy, "EGL_KHR_fence_sync");

	piglit_logi("try to create sync with second display");
	sync = peglCreateSyncKHR(wrong_dpy, EGL_SYNC_FENCE_KHR, NULL);
	if (sync) {
		piglit_loge("eglCreateSyncKHR() incorrectly succeeded");
		result = PIGLIT_FAIL;
		goto cleanup;
	}
	if (!piglit_check_egl_error(EGL_BAD_MATCH)) {
		piglit_loge("eglCreateSyncKHR emitted wrong error");
		result = PIGLIT_FAIL;
		goto cleanup;
	}

cleanup:
	if (wrong_dpy) {
		eglTerminate(wrong_dpy);
	}
	test_cleanup(EGL_NO_SYNC_KHR, &result);
	return result;
}
Beispiel #17
0
/**
 * Teardown state after each subtest completes.
 */
static void
test_cleanup(EGLSyncKHR sync, enum piglit_result *inout_result)
{
	bool ok = false;

	if (sync) {
		/* From the EGL_KHR_fence_sync spec:
		 *
		 *     If no errors are generated, EGL_TRUE is returned, and
		 *     <sync> will no longer be the handle of a valid sync
		 *     object.
		 */
		ok = peglDestroySyncKHR(g_dpy, sync);
		if (!ok) {
			piglit_loge("eglDestroySyncKHR failed");
			*inout_result = PIGLIT_FAIL;
		}
		if (!piglit_check_egl_error(EGL_SUCCESS)) {
			piglit_loge("eglDestroySyncKHR emitted an error");
			*inout_result = PIGLIT_FAIL;
		}
	}

	/* Ensure that no leftover GL commands impact the next test. */
	if (eglGetCurrentContext()) {
		glFinish();
	}

	if (g_dpy) {
		eglMakeCurrent(g_dpy, 0, 0, 0);
		ok = eglTerminate(g_dpy);
		if (!ok) {
			piglit_loge("failed to terminate EGLDisplay");
			*inout_result = PIGLIT_FAIL;
		}
	}

	g_dpy = EGL_NO_DISPLAY;
	g_ctx = EGL_NO_CONTEXT;
}
Beispiel #18
0
/**
 * Verify that eglGetSyncAttribKHR emits the correct error when querying an
 * unrecognized attribute of a fence sync.
 *
 * From the EGL_KHR_fence_sync:
 *
 *    [eglGetSyncAttribKHR] is used to query attributes of the sync object
 *    <sync>. Legal values for <attribute> depend on the type of sync object,
 *    as shown in table
 *    3.cc. [...]
 *
 *    Attribute              Description                Supported Sync Objects
 *    -----------------      -----------------------    ----------------------
 *    EGL_SYNC_TYPE_KHR      Type of the sync object    All
 *    EGL_SYNC_STATUS_KHR    Status of the sync object  All
 *    EGL_SYNC_CONDITION_KHR Signaling condition        EGL_SYNC_FENCE_KHR only
 *
 *    Table 3.cc  Attributes Accepted by eglGetSyncAttribKHR Command
 *
 *    [...]
 *
 *    * If <attribute> is not one of the attributes in table 3.cc,
 *      EGL_FALSE is returned and an EGL_BAD_ATTRIBUTE error is
 *      generated.
 *
 *    [...]
 *
 *    If any error occurs, <*value> is not modified.
 */
static enum piglit_result
test_eglGetSyncAttribKHR_invalid_attrib(void *test_data)
{
	enum piglit_result result = PIGLIT_PASS;
	bool ok = false;
	EGLSyncKHR sync = 0;
	EGLint attrib_value = canary;

	result = test_setup();
	if (result != PIGLIT_PASS) {
		return result;
	}

	sync = peglCreateSyncKHR(g_dpy, EGL_SYNC_FENCE_KHR, NULL);
	if (!sync) {
		piglit_loge("eglCreateSyncKHR(EGL_SYNC_FENCE_KHR) failed");
		result = PIGLIT_FAIL;
		goto cleanup;
	}

	ok = peglGetSyncAttribKHR(g_dpy, sync, EGL_BUFFER_PRESERVED,
				 &attrib_value);
	if (ok) {
		piglit_loge("eglGetSyncAttribKHR(attrib=EGL_BUFFER_PRESERVED) "
		          "incorrectly succeeded");
		result = PIGLIT_FAIL;
	}
	if (!piglit_check_egl_error(EGL_BAD_ATTRIBUTE)) {
		piglit_loge("eglGetSyncAttribKHR emitted wrong error");
		result = PIGLIT_FAIL;
	}
	if (attrib_value != canary) {
		piglit_loge("eglGetSynAttribKHR modified out parameter <value>");
		result = PIGLIT_FAIL;
	}

cleanup:
	test_cleanup(sync, &result);
	return result;
}
/* Test that eglCreatePlatformWindowSurface fails with EGL_BAD_NATIVE_WINDOW.
 *
 * From the EGL_MESA_platform_surfaceless spec (v1):
 *
 *    eglCreatePlatformWindowSurface fails when called with a <display>
 *    that belongs to the surfaceless platform. It returns
 *    EGL_NO_SURFACE and generates EGL_BAD_NATIVE_WINDOW. The
 *    justification for this unconditional failure is that the
 *    surfaceless platform has no native windows, and therefore the
 *    <native_window> parameter is always invalid.
 */
static enum piglit_result
test_create_window(void *test_data)
{
	EGLDisplay dpy;
	EGLSurface surf;

	test_setup(&dpy);

	surf = peglCreatePlatformWindowSurfaceEXT(dpy, EGL_NO_CONFIG_KHR,
					      /*native_window*/ NULL,
					      /*attrib_list*/ NULL);
	if (surf) {
		printf("eglCreatePlatformWindowSurface incorrectly succeeded\n");
		return PIGLIT_FAIL;
	}

	if (!piglit_check_egl_error(EGL_BAD_NATIVE_WINDOW))
		return PIGLIT_FAIL;

	eglTerminate(dpy);
	return PIGLIT_PASS;
}
enum piglit_result
piglit_display(void)
{
	const unsigned w = 2;
	const unsigned h = 2;
	const unsigned cpp = 4;
	const unsigned char pixels[w * h * cpp];
	struct piglit_dma_buf *buf;
	unsigned stride;
	unsigned offset;
	int fd;
	EGLImageKHR img;
	enum piglit_result res;

	res = piglit_create_dma_buf(w, h, cpp, pixels, w * cpp,
				&buf, &fd, &stride, &offset);
	if (res != PIGLIT_PASS)
		return res;

	img = create_image(w, h, fd, stride, offset);

	if (!piglit_check_egl_error(EGL_BAD_MATCH)) {
		if (img)
			eglDestroyImageKHR(eglGetCurrentDisplay(), img);
		return PIGLIT_FAIL;
	}

	piglit_destroy_dma_buf(buf);

	/**
	 * EGL stack can claim the ownership of the file descriptor only when it
	 * succeeds. Close the descriptor and check that it really wasn't closed
	 * by EGL.
	 */
	return close(fd) == 0 ? PIGLIT_PASS : PIGLIT_FAIL;
}
Beispiel #21
0
/**
 * Verify that glClientWaitSyncKHR emits correct error when given invalid flag.
 *
 * From the EGL_KHR_fence_sync spec:
 *
 *    Accepted in the <flags> parameter of eglClientWaitSyncKHR:
 *
 *    EGL_SYNC_FLUSH_COMMANDS_BIT_KHR         0x0001
 */
static enum piglit_result
test_eglClientWaitSyncKHR_invalid_flag(void *test_data)
{
	enum piglit_result result = PIGLIT_PASS;
	EGLSyncKHR sync = 0;
	EGLint wait_status = 0;
	EGLint invalid_flag = 0x8000;

	result = test_setup();
	if (result != PIGLIT_PASS) {
		return result;
	}

	sync = peglCreateSyncKHR(g_dpy, EGL_SYNC_FENCE_KHR, NULL);
	if (!sync) {
		piglit_loge("eglCreateSyncKHR(EGL_SYNC_FENCE_KHR) failed");
		result = PIGLIT_FAIL;
		goto cleanup;
	}

	/* Use timeout=0 so that eglClientWaitSyncKHR immediately returns. */
	wait_status = peglClientWaitSyncKHR(g_dpy, sync, invalid_flag, 0);
	if (wait_status != EGL_FALSE) {
		piglit_loge("eglClientWaitSyncKHR succeeded when given invalid "
			  "flag 0x%x", invalid_flag);
		result = PIGLIT_FAIL;
	}
	if (!piglit_check_egl_error(EGL_BAD_PARAMETER)) {
		piglit_loge("eglClientWaitSyncKHR emitted wrong error");
		result = PIGLIT_FAIL;
	}

cleanup:
	test_cleanup(sync, &result);
	return result;
}
Beispiel #22
0
/**
 * Verify that eglCreateSyncKHR emits correct error when given an invalid
 * display.
 *
 * From the EGL_KHR_fence_sync spec:
 *
 *     If <dpy> is not the name of a valid, initialized EGLDisplay,
 *     EGL_NO_SYNC_KHR is returned and an EGL_BAD_DISPLAY error is
 *     generated.
 */
static enum piglit_result
test_eglCreateSyncKHR_invalid_display(void *test_data)
{
	enum piglit_result result = PIGLIT_PASS;
	EGLSyncKHR sync = 0;

	result = test_setup();
	if (result != PIGLIT_PASS) {
		return result;
	}

	sync = peglCreateSyncKHR(EGL_NO_DISPLAY, EGL_SYNC_FENCE_KHR, NULL);
	if (sync) {
		piglit_loge("eglCreateSyncKHR(EGL_NO_DISPLAY) succeeded");
		result = PIGLIT_FAIL;
	}
	if (!piglit_check_egl_error(EGL_BAD_DISPLAY)) {
		piglit_loge("eglCreateSyncKHR emitted wrong error");
		result = PIGLIT_FAIL;
	}

	test_cleanup(sync, &result);
	return result;
}
Beispiel #23
0
/**
 * Verify that eglGetSyncAttribKHR() reports correct sync status before and
 * after glFinish().
 */
static enum piglit_result
test_eglGetSyncAttribKHR_sync_status(void *test_data)
{
	enum piglit_result result = PIGLIT_PASS;
	EGLSyncKHR sync = 0;
	EGLint sync_status = 0;
	bool ok = false;

	result = test_setup();
	if (result != PIGLIT_PASS) {
		return result;
	}
	glClear(GL_COLOR_BUFFER_BIT);

	sync = peglCreateSyncKHR(g_dpy, EGL_SYNC_FENCE_KHR, NULL);
	if (!sync) {
		piglit_loge("eglCreateSyncKHR(EGL_SYNC_FENCE_KHR) failed");
		result = PIGLIT_FAIL;
		goto cleanup;
	}

	ok = peglGetSyncAttribKHR(g_dpy, sync, EGL_SYNC_STATUS_KHR, &sync_status);
	if (!ok) {
		piglit_loge("before glFinish, eglGetSyncAttribKHR(EGL_SYNC_STATUS_KHR) "
			  "failed");
		result = PIGLIT_FAIL;
	}
	if (!piglit_check_egl_error(EGL_SUCCESS)) {
		piglit_loge("before glFinish, eglGetSyncAttribKHR(EGL_SYNC_STATUS_KHR) "
			  "emitted an error");
		result = PIGLIT_FAIL;
	}
	if (sync_status != EGL_SIGNALED_KHR &&
	    sync_status != EGL_UNSIGNALED_KHR) {
		piglit_loge("before glFinish, eglGetSyncAttribKHR(EGL_SYNC_STATUS_KHR):\n"
			  "  Expected status: EGL_SIGNALED_KHR or EGL_UNSIGNALED_KHR\n",
			  "  Actual status: 0x%x",
			  sync_status);
		result = PIGLIT_FAIL;
	}

	glFinish();

	ok = peglGetSyncAttribKHR(g_dpy, sync, EGL_SYNC_STATUS_KHR, &sync_status);
	if (!ok) {
		piglit_loge("after glFinish, eglGetSyncAttribKHR(EGL_SYNC_STATUS_KHR) "
			  "failed");
		result = PIGLIT_FAIL;
	}
	if (!piglit_check_egl_error(EGL_SUCCESS)) {
		piglit_loge("after glFinish, eglGetSyncAttribKHR(EGL_SYNC_STATUS_KHR) "
			  "emitted an error");
		result = PIGLIT_FAIL;
	}
	if (sync_status != EGL_SIGNALED_KHR) {
		piglit_loge("after glFinish, eglGetSyncAttribKHR(EGL_SYNC_STATUS_KHR):\n"
			  "  Expected status: EGL_SIGNALED_KHR\n",
			  "  Actual status: 0x%x",
			  sync_status);
		result = PIGLIT_FAIL;
	}

cleanup:
	test_cleanup(sync, &result);
	return result;
}
/**
 * Conformance test #3 in the EGL_EXT_client_extensions spec:
 *
 *  3. Obtain a list of display extensions by calling `eglQueryString(dpy,
 *     EGL_EXTENSIONS)` on an initialized display. Obtain the list of client
 *     extensions by calling `eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS)`.
 *     If both calls succeed, verify the two lists are disjoint.
 *
 */
static void
test_3(void)
{
	enum piglit_result result = PIGLIT_PASS;
	EGLDisplay dpy;
	EGLint major_version, minor_version;
	const char *display_ext_string;
	const char *client_ext_string;
	const char **display_ext_array;
	const char **client_ext_array;
	int i, j;

	dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
	if (!dpy) {
		printf("Failed to get default display. Skipping.\n");
		piglit_report_result(PIGLIT_SKIP);
	}
	if (!eglInitialize(dpy, &major_version, &minor_version)) {
		printf("Failed to initialize default display\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	display_ext_string = eglQueryString(dpy, EGL_EXTENSIONS);
	if (!piglit_check_egl_error(EGL_SUCCESS)) {
		printf("eglQueryString(EGL_EXTENSIONS) failed on default "
		       "display\n");
		piglit_report_result(PIGLIT_FAIL);
	}
	if (!display_ext_string) {
		printf("eglQueryString(EGL_EXTENSIONS) returned null for "
		       "default display\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	client_ext_string = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
	if (!client_ext_string) {
		if (piglit_check_egl_error(EGL_BAD_DISPLAY)) {
			printf("eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS) "
			       "returned null. Skipping.\n");
			piglit_report_result(PIGLIT_SKIP);
		} else {
			printf("eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS) "
			       "returned null but did not emit "
			       "EGL_BAD_DISPLAY\n");
			piglit_report_result(PIGLIT_FAIL);
		}

		abort();
	}

	display_ext_array = piglit_split_string_to_array(display_ext_string, " ");
	client_ext_array = piglit_split_string_to_array(client_ext_string, " ");

	/* Check that the two sets of extensions are disjoint. */
	for (i = 0; display_ext_array[i] != NULL; ++i) {
		const char *display_ext = display_ext_array[i];
		for (j = 0; client_ext_array[j] != NULL; ++j) {
			const char *client_ext = client_ext_array[j];
			if (strcmp(display_ext, client_ext) == 0) {
				printf("%s is listed both as a client and "
				       "display extension\n", display_ext);
				result = PIGLIT_FAIL;
			}
		}
	}

	piglit_report_result(result);
}
Beispiel #25
0
static void
try_debug_flag(EGLenum context_api, EGLenum context_bit)
{
	GLint actual_flags = 0;
	piglit_dispatch_api dispatch_api;

	EGLint attribs[64];
	int i = 0;

	if (!EGL_KHR_create_context_setup(context_bit))
		piglit_report_result(PIGLIT_SKIP);

	if (!piglit_egl_bind_api(context_api))
		piglit_report_result(PIGLIT_SKIP);

        attribs[i++] = EGL_CONTEXT_FLAGS_KHR;
        attribs[i++] = EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;

        switch (context_bit) {
        case EGL_OPENGL_BIT:
           break;
        case EGL_OPENGL_ES_BIT:
              attribs[i++] = EGL_CONTEXT_MAJOR_VERSION_KHR;
              attribs[i++] = 1;
              break;
        case EGL_OPENGL_ES2_BIT:
              attribs[i++] = EGL_CONTEXT_MAJOR_VERSION_KHR;
              attribs[i++] = 2;
              break;
        case EGL_OPENGL_ES3_BIT_KHR:
           attribs[i++] = EGL_CONTEXT_MAJOR_VERSION_KHR;
           attribs[i++] = 3;
           break;
        default:
           assert(0);
           break;
        }

        attribs[i++] = EGL_NONE;

	ctx = eglCreateContext(egl_dpy, cfg, EGL_NO_CONTEXT, attribs);
	if (!ctx) {
		if (piglit_check_egl_error(EGL_BAD_MATCH)) {
			piglit_report_result(PIGLIT_SKIP);
		} else {
			piglit_report_result(PIGLIT_FAIL);
		}
	}

	if (!eglMakeCurrent(egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx)) {
		fprintf(stderr, "eglMakeCurrent() failed\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	switch (context_bit) {
	case EGL_OPENGL_BIT:
		dispatch_api = PIGLIT_DISPATCH_GL;
		break;
	case EGL_OPENGL_ES_BIT:
		/* Piglit doesn't yet have ES1 dispatch, so just initialize
		 * with ES2 dispatch. This should be safe because the only
		 * GL functions called by this test are glGetString() and
		 * glGetIntegerv().
		 */
		dispatch_api = PIGLIT_DISPATCH_ES2;
		break;
	case EGL_OPENGL_ES2_BIT:
	case EGL_OPENGL_ES3_BIT_KHR:
		dispatch_api = PIGLIT_DISPATCH_ES2;
		break;
	default:
		dispatch_api = 0;
		assert(0);
		break;
	}

	piglit_dispatch_default_init(dispatch_api);

	switch (context_bit) {
	case EGL_OPENGL_BIT:
		if (piglit_get_gl_version() < 31 &&
		    !piglit_is_extension_supported("GL_KHR_debug")) {
			fprintf(stderr, "In OpenGL, either OpenGL 3.1 or "
				"GL_KHR_debug is required to query "
				"GL_CONTEXT_FLAGS\n");
			piglit_report_result(PIGLIT_SKIP);
		}
		break;
	case EGL_OPENGL_ES_BIT:
	case EGL_OPENGL_ES2_BIT:
	case EGL_OPENGL_ES3_BIT_KHR:
		if (!piglit_is_extension_supported("GL_KHR_debug")) {
			fprintf(stderr, "In OpenGL ES, GL_KHR_debug is "
				"required to query GL_CONTEXT_FLAGS\n");
			piglit_report_result(PIGLIT_SKIP);
		}
		break;
	default:
		assert(0);
		break;
	}

	glGetIntegerv(GL_CONTEXT_FLAGS, &actual_flags);

	if (!piglit_check_gl_error(GL_NO_ERROR)) {
		fprintf(stderr, "glGetIntegerv(GL_CONTEXT_FLAGS) failed\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	/* Verify that this is actually a debug context. */
	if (!(actual_flags & GL_CONTEXT_FLAG_DEBUG_BIT)) {
		fprintf(stderr,
			"GL_CONTEXT_FLAGS=0x%x does not contain "
			"GL_CONTEXT_FLAG_DEBUG_BIT=0x%x\n",
			actual_flags, GL_CONTEXT_FLAG_DEBUG_BIT);
		piglit_report_result(PIGLIT_FAIL);
	}

	eglDestroyContext(egl_dpy, ctx);
	EGL_KHR_create_context_teardown();

	piglit_report_result(PIGLIT_PASS);
}
static enum piglit_result
check_flavor(int requested_version, enum gl_api requested_api)
{
	static bool is_dispatch_init = false;

	enum piglit_result result = PIGLIT_PASS;
	int i;

	const char *api_name = NULL;
	const char *profile_name = "";

	EGLint context_attribs[64];
	EGLContext ctx = 0;

	EGLenum requested_client_type = 0;
	EGLint actual_client_type = 0;
	int actual_version = 0;
	GLint actual_profile = 0;

	switch (requested_api) {
	case API_GL_COMPAT:
		requested_client_type = EGL_OPENGL_API;
		api_name = "OpenGL";
		if (requested_version >= 32)
			profile_name = "compatibility ";
		break;
	case API_GL_CORE:
		requested_client_type = EGL_OPENGL_API;
		api_name = "OpenGL";
		if (requested_version >= 32)
			profile_name = "core ";
		break;
	case API_GLES1:
	case API_GLES2:
	case API_GLES3:
		requested_client_type = EGL_OPENGL_ES_API;
		api_name = "OpenGL ES";
		break;
	default:
		assert(0);
		break;
	}

	printf("info: request an %s %d.%d %scontext\n",
	       api_name,
	       requested_version / 10,
	       requested_version % 10,
	       profile_name);

	if (!eglBindAPI(requested_client_type)) {
		/* Assume the driver doesn't support the requested API. */
		result = PIGLIT_SKIP;
		goto cleanup;
	}

	i = 0;
	context_attribs[i++] = EGL_CONTEXT_MAJOR_VERSION_KHR;
	context_attribs[i++] = requested_version / 10;
	context_attribs[i++] = EGL_CONTEXT_MINOR_VERSION_KHR;
	context_attribs[i++] = requested_version % 10;
	if (requested_api == API_GL_CORE) {
		context_attribs[i++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
		context_attribs[i++] = EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR;
	} else if (requested_api == API_GL_COMPAT) {
		context_attribs[i++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
		context_attribs[i++] = EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR;
	}
	context_attribs[i++] = EGL_NONE;

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

	if (ctx == NULL) {
		printf("%s", "info: context creation failed\n");
		if (eglGetError() != EGL_SUCCESS) {
			result = PIGLIT_SKIP;
		} else {
			printf("%s", "error: eglCreateContext failed but "
			       "the EGL error is EGL_SUCCESS\n");
			result = PIGLIT_FAIL;
		}

		goto cleanup;
	}

	if (!piglit_check_egl_error(EGL_SUCCESS)) {
		result = PIGLIT_FAIL;
		goto cleanup;
	}

	if (!eglMakeCurrent(egl_dpy, EGL_NO_SURFACE,
			    EGL_NO_SURFACE, ctx)) {
		printf("%s", "error: failed to make context current\n");
		goto fail;
	}

	if (!is_dispatch_init) {
		/* We must postpone initialization of piglit-dispatch until
		 * a context is current.
		 */
		piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
		is_dispatch_init = true;
	}

	if (!eglQueryContext(egl_dpy, ctx,
			     EGL_CONTEXT_CLIENT_TYPE, &actual_client_type)) {
		printf("%s", "error: eglQueryContext(EGL_CONTEXT_CLIENT_TYPE) "
		       "failed\n");
		goto fail;
	}

	if (actual_client_type != requested_client_type) {
		printf("error: requested a context with EGL_CONTEXT_CLIENT_TYPE=0x%x "
		       "but received one with EGL_CONTEXT_CLIENT_TYPE=0x%x.\n",
		       requested_client_type,
		       actual_client_type);
		goto fail;
	}

	actual_version = get_gl_version();

	if (actual_version < requested_version) {
		printf("error: requested context version %d.%d but received "
		       "version %d.%d\n",
		       requested_version / 10, requested_version % 10,
		       actual_version / 10, actual_version % 10);
		goto fail;
	}

	if (requested_api == API_GL_CORE ||
	    (requested_api == API_GL_COMPAT && requested_version >= 32)) {
		my_glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &actual_profile);
		if (!piglit_check_gl_error(GL_NO_ERROR)) {
			printf("%s", "error: glGetIntegerv(GL_CONTEXT_PROFILE_MASK)"
			       "failed\n");
			goto fail;
		}
	}

	if (requested_api == API_GL_CORE) {
		assert(requested_version >= 32);
		if (actual_profile != EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR) {
			printf("error: requested an OpenGL %d.%d core context, "
			       "but received a context whose profile "
			       "mask is 0x%x.\n",
			       requested_version / 10, requested_version % 10,
			       actual_profile);
			goto fail;
		}
	} else if (requested_api == API_GL_COMPAT && requested_version >= 32) {
		if (actual_profile != EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR) {
			printf("error: requested an OpenGL %d.%d compatibility context, "
			       "but received a context whose profile "
			       "mask is 0x%x.\n",
			       requested_version / 10, requested_version % 10,
			       actual_profile);
			goto fail;
		}
	} else if (requested_api == API_GLES1) {
		if (actual_version > 11) {
			printf("error: requested an OpenGL ES %d.%d context, "
			       "but received %d.%d context.\n",
			       requested_version / 10, requested_version % 10,
			       actual_version / 10, actual_version % 10);
			goto fail;
		}
	} else if (requested_api == API_GLES2) {
		/* Nothing special to check. */
	}

	result = PIGLIT_PASS;
	goto cleanup;

fail:
	result = PIGLIT_FAIL;
	goto cleanup;

cleanup:
	/* We must unbind the context here due to a subtle requirement in the
	 * EGL 1.4 spec published on 2011-04-06. The call to eglMakeCurrent at
	 * the top of this function may attempt to bind a context whose api
	 * differs from the api of the current context. Yet, according to the
	 * EGL spec, it is illegal to bind a GL context to a surface if an ES
	 * context is currently bound to it, and vice versa.
	 *
	 * A future revision of the EGL 1.4 spec will fix this non-intuitive
	 * requirement.
	 */
	if (!eglMakeCurrent(egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE,
			    EGL_NO_CONTEXT)) {
		printf("%s", "error: failed to unbind any current context\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	switch (result) {
	case PIGLIT_PASS:
		printf("%s", "info: pass\n");
		break;
	case PIGLIT_FAIL:
		printf("%s", "info: fail\n");
		break;
	case PIGLIT_SKIP:
		printf("%s", "info: skip\n");
		break;
	case PIGLIT_WARN:
	default:
		assert(0);
		break;
	}

	return result;
}
int
main(void)
{
	enum piglit_result result = PIGLIT_PASS;
	EGLint i, numdevs;
	EGLDeviceEXT devs[NDEVS];
	PFNEGLQUERYDEVICESEXTPROC queryDevices;

	const char *client_exts = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
	bool has_client_ext =
		client_exts &&
		((piglit_is_extension_in_string(client_exts,
			"EGL_EXT_device_query") &&
		  piglit_is_extension_in_string(client_exts,
			"EGL_EXT_device_enumeration")) ||
		 piglit_is_extension_in_string(client_exts,
			"EGL_EXT_device_base"));

	if (!has_client_ext) {
		printf("EGL_EXT_device_enumeration not supported\n");
		piglit_report_result(PIGLIT_SKIP);
	}

	queryDevices = (void *)eglGetProcAddress("eglQueryDevicesEXT");

	if (!queryDevices) {
		printf("No device query entrypoint\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	if (!queryDevices(0, NULL, &numdevs)) {
		printf("Failed to get device count\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	if (numdevs < 1) {
		printf("No devices supported\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	if (numdevs > NDEVS) {
		printf("More than %d devices, please fix this test\n", NDEVS);
		result = PIGLIT_WARN;
		numdevs = NDEVS;
	}

	memset(devs, 0, sizeof devs);
	if (!queryDevices(numdevs, devs, &numdevs)) {
		printf("Failed to enumerate devices\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	for (i = 0; i < numdevs; i++)
	    if (devs[i] == NULL) {
		printf("Enumerated device slot not initialized\n");
		piglit_report_result(PIGLIT_FAIL);
	    }

	for (i = numdevs; i < ARRAY_SIZE(devs); i++)
	    if (devs[i] != NULL) {
		printf("Non-enumerated device slot initialized\n");
		piglit_report_result(PIGLIT_FAIL);
	    }

	queryDevices(0, devs, &numdevs);
	if (!piglit_check_egl_error(EGL_BAD_PARAMETER))
		piglit_report_result(PIGLIT_FAIL);

	queryDevices(-1, devs, &numdevs);
	if (!piglit_check_egl_error(EGL_BAD_PARAMETER))
		piglit_report_result(PIGLIT_FAIL);

	queryDevices(ARRAY_SIZE(devs), devs, NULL);
	if (!piglit_check_egl_error(EGL_BAD_PARAMETER))
		piglit_report_result(PIGLIT_FAIL);

	piglit_report_result(result);
}
Beispiel #28
0
PIGLIT_GL_TEST_CONFIG_END

static enum piglit_result
test_create_and_destroy(unsigned w, unsigned h, void *buf, int fd,
		unsigned stride, unsigned offset)
{
	EGLint error;
	EGLImageKHR img;
	EGLint attr[] = {
		EGL_WIDTH, w,
		EGL_HEIGHT, h,
		EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888,
		EGL_DMA_BUF_PLANE0_FD_EXT, fd,
		EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
		EGL_DMA_BUF_PLANE0_PITCH_EXT, stride,
		EGL_NONE
	};

	img = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT,
			EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)0, attr);

	/* Release the creator side of the buffer. */
	piglit_destroy_dma_buf(buf);

	error = eglGetError();

	/* EGL may not support the format, this is not an error. */
	if (!img && error == EGL_BAD_MATCH)
		return PIGLIT_SKIP;

	if (error != EGL_SUCCESS) {
		fprintf(stderr, "eglCreateImageKHR() failed: %s 0x%x\n",
			piglit_get_egl_error_name(error), error);
		return PIGLIT_FAIL;
	}

	if (!img) {
		fprintf(stderr, "image creation succeed but returned NULL\n");
		return PIGLIT_FAIL;
	}

	eglDestroyImageKHR(eglGetCurrentDisplay(), img);

	if (!piglit_check_egl_error(EGL_SUCCESS))
		return PIGLIT_FAIL;

	/**
	 * EGL stack is allowed to keep the importing file descriptor open until
	 * all resources are released. Therefore close the display first.
	 */
	if (!eglTerminate(eglGetCurrentDisplay())) {
		fprintf(stderr, "eglTerminate() failed\n");
		return PIGLIT_FAIL;
	}

	/*
	 * Our own file descriptor must still be valid, and therefore
	 * closing it must succeed.
	 */
	return close(fd) == 0 ? PIGLIT_PASS : PIGLIT_FAIL;
}
Beispiel #29
0
/**
 * Verify that eglCreateSyncKHR(), when given an empty attribute list,
 * intializes the sync object's attributes to the correct values.
 *
 * From the EGL_KHR_fence_sync spec:
 *
 *     Attributes not specified in the list will be assigned their default
 *     values.
 *
 *     Attributes of the fence sync object are
 *     set as follows:
 *
 *       Attribute Name         Initial Attribute Value(s)
 *       ---------------        --------------------------
 *       EGL_SYNC_TYPE_KHR      EGL_SYNC_FENCE_KHR
 *       EGL_SYNC_STATUS_KHR    EGL_UNSIGNALED_KHR
 *       EGL_SYNC_CONDITION_KHR EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR
 */
static enum piglit_result
test_eglCreateSyncKHR_default_attributes(void *test_data)
{
	enum piglit_result result = PIGLIT_PASS;
	EGLSyncKHR sync = 0;
	EGLint sync_type = canary,
	       sync_status = canary,
	       sync_condition = canary;
	bool ok = false;

	result = test_setup();
	if (result != PIGLIT_PASS) {
		return result;
	}

	sync = peglCreateSyncKHR(g_dpy, EGL_SYNC_FENCE_KHR, NULL);
	if (!sync) {
		piglit_loge("eglCreateSyncKHR(EGL_SYNC_FENCE_KHR) failed");
		result = PIGLIT_FAIL;
		goto cleanup;
	}

	ok = peglGetSyncAttribKHR(g_dpy, sync, EGL_SYNC_TYPE_KHR, &sync_type);
	if (ok) {
		piglit_loge("eglGetSyncAttribKHR(EGL_SYNC_TYPE_KHR) failed");
		result = PIGLIT_FAIL;
	}
	if (!piglit_check_egl_error(EGL_SUCCESS)) {
		piglit_loge("eglGetSyncAttribKHR(EGL_SYNC_TYPE_KHR) emitted "
			  "an error");
		result = PIGLIT_FAIL;
	}
	if (sync_type != EGL_SYNC_FENCE_KHR) {
		piglit_loge("eglGetSyncAttribKHR(EGL_SYNC_TYPE_KHR) returned "
			  "0x%x but expected EGL_SYNC_FENCE_KHR(0x%x)",
			  sync_type, EGL_SYNC_FENCE_KHR);
		result = PIGLIT_FAIL;
	}

	ok = peglGetSyncAttribKHR(g_dpy, sync, EGL_SYNC_STATUS_KHR, &sync_status);
	if (!ok) {
		piglit_loge("eglGetSyncAttribKHR(EGL_SYNC_STATUS_KHR) failed");
		result = PIGLIT_FAIL;
	}
	if (!piglit_check_egl_error(EGL_SUCCESS)) {
		piglit_loge("eglGetSyncAttribKHR(EGL_SYNC_STATUS_KHR) emitted "
			  "an error");
		result = PIGLIT_FAIL;
	}
	if (sync_status != EGL_UNSIGNALED_KHR) {
		piglit_loge("eglGetSyncAttribKHR(EGL_SYNC_STATUS_KHR) returned "
			  "0x%x but expected EGL_UNSIGNALED_KHR(0x%x)",
			  sync_status, EGL_UNSIGNALED_KHR);
		result = PIGLIT_FAIL;
	}

	ok = peglGetSyncAttribKHR(g_dpy, sync, EGL_SYNC_CONDITION_KHR, &sync_condition);
	if (!ok) {
		piglit_loge("eglGetSyncAttribKHR(EGL_SYNC_CONDITION_KHR) failed");
		result = PIGLIT_FAIL;
	}
	if (!piglit_check_egl_error(EGL_SUCCESS)) {
		piglit_loge("eglGetSyncAttribKHR(EGL_SYNC_CONDITION_KHR) "
			  "emitted an error");
		result = PIGLIT_FAIL;
	}
	if (sync_condition != EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR) {
		piglit_loge("eglGetSyncAttribKHR(EGL_SYNC_CONDITION_KHR) "
			  "returned 0x%x but expected "
			  "EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR(0x%x)",
			  sync_condition, EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR);
		result = PIGLIT_FAIL;
	}

cleanup:
	test_cleanup(sync, &result);
	return result;
}