Commit e95a7f07 by Jamie Madill Committed by Commit Bot

Make EGLThreadTest cross-platform.

BUG=angleproject:2464 Change-Id: Ib2a43bc8e2da467f49e8938c386a5e867c80d5bc Reviewed-on: https://chromium-review.googlesource.com/361921Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent c0a403e2
...@@ -125,6 +125,7 @@ ...@@ -125,6 +125,7 @@
'<(angle_path)/src/tests/egl_tests/EGLSanityCheckTest.cpp', '<(angle_path)/src/tests/egl_tests/EGLSanityCheckTest.cpp',
'<(angle_path)/src/tests/egl_tests/EGLSurfacelessContextTest.cpp', '<(angle_path)/src/tests/egl_tests/EGLSurfacelessContextTest.cpp',
'<(angle_path)/src/tests/egl_tests/EGLSurfaceTest.cpp', '<(angle_path)/src/tests/egl_tests/EGLSurfaceTest.cpp',
'<(angle_path)/src/tests/egl_tests/EGLThreadTest.cpp',
'<(angle_path)/src/tests/test_utils/ANGLETest.cpp', '<(angle_path)/src/tests/test_utils/ANGLETest.cpp',
'<(angle_path)/src/tests/test_utils/ANGLETest.h', '<(angle_path)/src/tests/test_utils/ANGLETest.h',
'<(angle_path)/src/tests/test_utils/angle_test_configs.cpp', '<(angle_path)/src/tests/test_utils/angle_test_configs.cpp',
...@@ -144,8 +145,6 @@ ...@@ -144,8 +145,6 @@
'<(angle_path)/src/tests/egl_tests/EGLPresentPathD3D11Test.cpp', '<(angle_path)/src/tests/egl_tests/EGLPresentPathD3D11Test.cpp',
'<(angle_path)/src/tests/egl_tests/EGLStreamTest.cpp', '<(angle_path)/src/tests/egl_tests/EGLStreamTest.cpp',
'<(angle_path)/src/tests/egl_tests/EGLSyncControlTest.cpp', '<(angle_path)/src/tests/egl_tests/EGLSyncControlTest.cpp',
# TODO(cwallez) for Linux, requires a portable implementation of threads
'<(angle_path)/src/tests/egl_tests/EGLThreadTest.cpp',
'<(angle_path)/src/tests/egl_tests/media/yuvtest.inl', '<(angle_path)/src/tests/egl_tests/media/yuvtest.inl',
], ],
'angle_end2end_tests_x11_sources': 'angle_end2end_tests_x11_sources':
......
//
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// EGLThreadTest.h: Tests multi-threaded uses of EGL.
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "system_utils.h"
#include <thread>
#include <EGL/egl.h> #include <EGL/egl.h>
#include <EGL/eglext.h> #include <EGL/eglext.h>
typedef EGLDisplay EGLAPIENTRY EGLGetDisplay(EGLNativeDisplayType display_id);
typedef EGLBoolean EGLAPIENTRY EGLInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor);
typedef EGLContext EGLAPIENTRY EGLGetCurrentContext(void);
typedef EGLSurface EGLAPIENTRY EGLGetCurrentSurface(EGLint readdraw);
typedef EGLBoolean EGLAPIENTRY EGLTerminate(EGLDisplay dpy);
class EGLThreadTest : public testing::Test class EGLThreadTest : public testing::Test
{ {
public: public:
virtual void SetUp() {} void threadingTest();
virtual void TearDown() {}
EGLGetDisplay *mGetDisplay;
EGLInitialize *mInitialize;
EGLGetCurrentContext *mGetCurrentContext;
EGLGetCurrentSurface *mGetCurrentSurface;
EGLDisplay mDisplay;
HMODULE mEGL;
HMODULE mGLESv2;
static DWORD WINAPI ThreadingTestEntryPoint(LPVOID thisPointer);
private: protected:
void ThreadingTest(); EGLDisplay mDisplay = EGL_NO_DISPLAY;
}; };
DWORD WINAPI EGLThreadTest::ThreadingTestEntryPoint(LPVOID lpParameter) void EGLThreadTest::threadingTest()
{ {
EGLThreadTest *test = (EGLThreadTest *)lpParameter; mDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
test->ThreadingTest();
return 0;
}
void EGLThreadTest::ThreadingTest()
{
mEGL = LoadLibrary(TEXT(ANGLE_EGL_LIBRARY_NAME ".dll"));
mGLESv2 = LoadLibrary(TEXT(ANGLE_GLESV2_LIBRARY_NAME ".dll"));
EXPECT_TRUE(mEGL != nullptr);
EXPECT_TRUE(mGLESv2 != nullptr);
mGetDisplay = (EGLGetDisplay *)GetProcAddress(mEGL, "eglGetDisplay");
mInitialize = (EGLInitialize *)GetProcAddress(mEGL, "eglInitialize");
mGetCurrentContext = (EGLGetCurrentContext *)GetProcAddress(mEGL, "eglGetCurrentContext");
mGetCurrentSurface = (EGLGetCurrentSurface *)GetProcAddress(mEGL, "eglGetCurrentSurface");
EXPECT_TRUE(mGetDisplay != nullptr);
EXPECT_TRUE(mInitialize != nullptr);
EXPECT_TRUE(mGetCurrentContext != nullptr);
EXPECT_TRUE(mGetCurrentSurface != nullptr);
mDisplay = mGetDisplay(EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE);
EXPECT_TRUE(mDisplay!= EGL_NO_DISPLAY); EXPECT_TRUE(mDisplay != EGL_NO_DISPLAY);
mInitialize(mDisplay, nullptr, nullptr); eglInitialize(mDisplay, nullptr, nullptr);
mGetCurrentContext(); eglGetCurrentContext();
} }
TEST_F(EGLThreadTest, thread_init_crash) // Test a bug in our EGL TLS implementation.
TEST_F(EGLThreadTest, ThreadInitCrash)
{ {
DWORD threadId; std::thread runner(&EGLThreadTest::threadingTest, this);
HANDLE threadHandle =
CreateThread(nullptr, 0, EGLThreadTest::ThreadingTestEntryPoint, this, 0, &threadId);
EXPECT_TRUE(threadHandle != nullptr);
// wait for signal from thread // wait for signal from thread
DWORD waitResult = WaitForSingleObject(threadHandle, 1000); runner.join();
EXPECT_EQ(waitResult, WAIT_OBJECT_0);
// crash, because the TLS value is NULL on main thread // crash, because the TLS value is NULL on main thread
mGetCurrentSurface(EGL_DRAW); eglGetCurrentSurface(EGL_DRAW);
mGetCurrentContext(); eglGetCurrentContext();
auto terminate = (EGLTerminate *)GetProcAddress(mEGL, "eglTerminate"); eglTerminate(mDisplay);
terminate(mDisplay);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment