diff --git a/src/tests/angle_end2end_tests.gypi b/src/tests/angle_end2end_tests.gypi index b8ca183ba..e11c6e824 100644 --- a/src/tests/angle_end2end_tests.gypi +++ b/src/tests/angle_end2end_tests.gypi @@ -35,6 +35,7 @@ '<(angle_path)/src/tests/gl_tests/media/pixel.inl', '<(angle_path)/src/tests/gl_tests/PBOExtensionTest.cpp', '<(angle_path)/src/tests/gl_tests/PointSpritesTest.cpp', + '<(angle_path)/src/tests/gl_tests/OcclusionQueriesTest.cpp', '<(angle_path)/src/tests/gl_tests/ProgramBinaryTest.cpp', '<(angle_path)/src/tests/gl_tests/ReadPixelsTest.cpp', '<(angle_path)/src/tests/gl_tests/RendererTest.cpp', @@ -59,8 +60,6 @@ ], 'angle_end2end_tests_win_sources': [ - # TODO(cwallez) for Linux, requires a portable implementation of sleep - '<(angle_path)/src/tests/gl_tests/OcclusionQueriesTest.cpp', # TODO(cwallez) for Linux, requires implementation of eglBindTexImage for pbuffers '<(angle_path)/src/tests/gl_tests/PbufferTest.cpp', '<(angle_path)/src/tests/gl_tests/QueryDisplayAttribTest.cpp', diff --git a/src/tests/gl_tests/OcclusionQueriesTest.cpp b/src/tests/gl_tests/OcclusionQueriesTest.cpp index 69301b79c..6d7171cd7 100644 --- a/src/tests/gl_tests/OcclusionQueriesTest.cpp +++ b/src/tests/gl_tests/OcclusionQueriesTest.cpp @@ -4,11 +4,9 @@ // found in the LICENSE file. // +#include "system_utils.h" #include "test_utils/ANGLETest.h" -// Needed for Sleep() -#include - using namespace angle; class OcclusionQueriesTest : public ANGLETest @@ -92,7 +90,7 @@ TEST_P(OcclusionQueriesTest, IsOccluded) GLuint ready = GL_FALSE; while (ready == GL_FALSE) { - Sleep(0); + angle::Sleep(0); glGetQueryObjectuivEXT(query, GL_QUERY_RESULT_AVAILABLE_EXT, &ready); } diff --git a/util/posix/Posix_system_utils.cpp b/util/posix/Posix_system_utils.cpp new file mode 100644 index 000000000..ae4f79d22 --- /dev/null +++ b/util/posix/Posix_system_utils.cpp @@ -0,0 +1,37 @@ +// +// Copyright (c) 2015 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. +// + +// Posix_system_utils.cpp: Implementation of OS-specific functions for Posix systems + +#include "system_utils.h" + +#include +#include + +namespace angle +{ + +void Sleep(unsigned int milliseconds) +{ + // On Windows Sleep(0) yields while it isn't guaranteed by Posix's sleep + // so we replicate Windows' behavior with an explicit yield. + if (milliseconds == 0) + { + sched_yield(); + } + else + { + timespec sleepTime = + { + .tv_sec = milliseconds / 1000, + .tv_nsec = (milliseconds % 1000) * 1000000, + }; + + nanosleep(&sleepTime, nullptr); + } +} + +} // namespace angle diff --git a/util/system_utils.h b/util/system_utils.h index 89ef615a2..6ae431457 100644 --- a/util/system_utils.h +++ b/util/system_utils.h @@ -17,6 +17,9 @@ namespace angle std::string GetExecutablePath(); std::string GetExecutableDirectory(); +// Cross platform equivalent of the Windows Sleep function +void Sleep(unsigned int milliseconds); + } // namespace angle #endif // SAMPLE_UTIL_PATH_UTILS_H diff --git a/util/util.gyp b/util/util.gyp index 6c1df012f..0e364a17f 100644 --- a/util/util.gyp +++ b/util/util.gyp @@ -35,6 +35,7 @@ 'linux/Linux_system_utils.cpp', 'linux/LinuxTimer.cpp', 'linux/LinuxTimer.h', + 'posix/Posix_system_utils.cpp', 'x11/X11Window.cpp', 'x11/X11Window.h', ] diff --git a/util/win32/Win32_system_utils.cpp b/util/win32/Win32_system_utils.cpp index 9f6f9266c..99d1a26b5 100644 --- a/util/win32/Win32_system_utils.cpp +++ b/util/win32/Win32_system_utils.cpp @@ -28,4 +28,9 @@ std::string GetExecutableDirectory() return (lastPathSepLoc != std::string::npos) ? executablePath.substr(0, lastPathSepLoc) : ""; } +void Sleep(unsigned int milliseconds) +{ + ::Sleep(static_cast(milliseconds)); +} + } // namespace angle