Commit 18afd77e by Jamie Madill

Make the HugeSetDataTest more robust.

By starting from a near-maximum size, and trying until we reach a a valid allocatable size, we can guarantee the test can run. Previously the allocation could fail under some systems and succeded in others, leading to flakiness. BUG=angle:716 Change-Id: If1690349f7028c4e6a88f20649fb255ea2dd2587 Reviewed-on: https://chromium-review.googlesource.com/210992Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 91fa9ce4
#include "ANGLETest.h" #include "ANGLETest.h"
#include <cstdint>
class BufferDataTest : public ANGLETest class BufferDataTest : public ANGLETest
{ {
protected: protected:
...@@ -117,24 +119,21 @@ TEST_F(BufferDataTest, HugeSetDataShouldNotCrash) ...@@ -117,24 +119,21 @@ TEST_F(BufferDataTest, HugeSetDataShouldNotCrash)
glBindBuffer(GL_ARRAY_BUFFER, mBuffer); glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
EXPECT_GL_NO_ERROR(); EXPECT_GL_NO_ERROR();
// use as large a size as possible without causing an exception GLsizei allocSize = std::numeric_limits<GLsizei>::max() >> 2;
GLsizei hugeSize = (1 << 29);
// on x64, use as large a GLsizei value as possible uint8_t *data = NULL;
if (sizeof(size_t) > 4) while (data == NULL && allocSize >= 4)
{ {
hugeSize = std::numeric_limits<GLsizei>::max(); data = new (std::nothrow) uint8_t[allocSize];
}
char *data = new (std::nothrow) char[hugeSize];
ASSERT_NE((char * const)NULL, data);
if (data == NULL) if (data == NULL)
{ {
return; allocSize <<= 1;
}
} }
memset(data, 0, hugeSize); ASSERT_NE(static_cast<uint8_t*>(NULL), data);
memset(data, 0, allocSize);
float * fValue = reinterpret_cast<float*>(data); float * fValue = reinterpret_cast<float*>(data);
for (unsigned int f = 0; f < 6; f++) for (unsigned int f = 0; f < 6; f++)
...@@ -142,7 +141,7 @@ TEST_F(BufferDataTest, HugeSetDataShouldNotCrash) ...@@ -142,7 +141,7 @@ TEST_F(BufferDataTest, HugeSetDataShouldNotCrash)
fValue[f] = 1.0f; fValue[f] = 1.0f;
} }
glBufferData(GL_ARRAY_BUFFER, hugeSize, data, GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, allocSize, data, GL_STATIC_DRAW);
GLenum error = glGetError(); GLenum error = glGetError();
if (error == GL_NO_ERROR) if (error == GL_NO_ERROR)
......
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