Browse Source

GL: test for multithreaded behavior of GL::Context.

pull/362/head
Vladimír Vondruš 7 years ago
parent
commit
8e714280fa
  1. 7
      src/Magnum/GL/Test/CMakeLists.txt
  2. 58
      src/Magnum/GL/Test/ContextGLTest.cpp

7
src/Magnum/GL/Test/CMakeLists.txt

@ -106,7 +106,6 @@ endif()
if(BUILD_GL_TESTS)
corrade_add_test(GLAbstractTextureGLTest AbstractTextureGLTest.cpp LIBRARIES MagnumOpenGLTester)
corrade_add_test(GLBufferGLTest BufferGLTest.cpp LIBRARIES MagnumOpenGLTester)
corrade_add_test(GLContextGLTest ContextGLTest.cpp LIBRARIES MagnumOpenGLTester)
corrade_add_test(GLCubeMapTextureGLTest CubeMapTextureGLTest.cpp LIBRARIES MagnumOpenGLTester)
corrade_add_test(GLFramebufferGLTest FramebufferGLTest.cpp LIBRARIES MagnumOpenGLTester)
corrade_add_test(GLMeshGLTest MeshGLTest.cpp LIBRARIES MagnumOpenGLTesterTestLib)
@ -120,6 +119,12 @@ if(BUILD_GL_TESTS)
${GLAbstractShaderProgramGLTest_RES}
LIBRARIES MagnumOpenGLTester)
corrade_add_test(GLContextGLTest ContextGLTest.cpp LIBRARIES MagnumOpenGLTester)
if(NOT CORRADE_TARGET_EMSCRIPTEN)
find_package(Threads REQUIRED)
target_link_libraries(GLContextGLTest PRIVATE Threads::Threads)
endif()
if(CORRADE_TARGET_EMSCRIPTEN OR CORRADE_TARGET_ANDROID)
set(SHADERGLTEST_FILES_DIR "ShaderGLTestFiles")
else()

58
src/Magnum/GL/Test/ContextGLTest.cpp

@ -29,11 +29,19 @@
#include "Magnum/GL/Extensions.h"
#include "Magnum/GL/OpenGLTester.h"
#ifndef CORRADE_TARGET_EMSCRIPTEN
#include <thread>
#endif
namespace Magnum { namespace GL { namespace Test { namespace {
struct ContextGLTest: OpenGLTester {
explicit ContextGLTest();
#ifndef CORRADE_TARGET_EMSCRIPTEN
void multithreaded();
#endif
void isVersionSupported();
#ifndef MAGNUM_TARGET_GLES
void isVersionSupportedES();
@ -44,15 +52,51 @@ struct ContextGLTest: OpenGLTester {
};
ContextGLTest::ContextGLTest() {
addTests({&ContextGLTest::isVersionSupported,
#ifndef MAGNUM_TARGET_GLES
&ContextGLTest::isVersionSupportedES,
#endif
&ContextGLTest::supportedVersion,
&ContextGLTest::isExtensionSupported,
&ContextGLTest::isExtensionDisabled});
addTests({
#ifndef CORRADE_TARGET_EMSCRIPTEN
&ContextGLTest::multithreaded,
#endif
&ContextGLTest::isVersionSupported,
#ifndef MAGNUM_TARGET_GLES
&ContextGLTest::isVersionSupportedES,
#endif
&ContextGLTest::supportedVersion,
&ContextGLTest::isExtensionSupported,
&ContextGLTest::isExtensionDisabled});
}
#ifndef CORRADE_TARGET_EMSCRIPTEN
void ContextGLTest::multithreaded() {
CORRADE_VERIFY(Context::hasCurrent());
Containers::Optional<bool> otherThreadHasCurrent;
std::thread t{[](Containers::Optional<bool>& hasCurrent) {
hasCurrent = Context::hasCurrent();
}, std::ref(otherThreadHasCurrent)};
t.join();
CORRADE_VERIFY(otherThreadHasCurrent);
Debug{} << "MAGNUM_BUILD_MULTITHREADED defined:" <<
#ifdef MAGNUM_BUILD_MULTITHREADED
true
#else
false
#endif
;
Debug{} << "Current context visible in another thread:" << *otherThreadHasCurrent;
#ifdef MAGNUM_BUILD_MULTITHREADED
CORRADE_VERIFY(!*otherThreadHasCurrent);
#else
CORRADE_VERIFY(*otherThreadHasCurrent);
#endif
}
#endif
void ContextGLTest::isVersionSupported() {
const Version v = Context::current().version();
CORRADE_VERIFY(Context::current().isVersionSupported(v));

Loading…
Cancel
Save