Commit 72fc5547 by Olli Etuaho Committed by Commit Bot

Add a ShaderCompileTreeTest base class to use in compiler tests

The test class provides facilities for parsing test shader source into an AST and determining compile status. Compilation flags change for some of the tests, but this should only have a minor effect on code coverage - mostly affecting non-core parts such as intermediate output. BUG=angleproject:1673 TEST=angle_unittests Change-Id: I7d0900ef490e021272a27c4b0c938bfee02abf39 Reviewed-on: https://chromium-review.googlesource.com/422367Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent fc5aef40
......@@ -96,6 +96,8 @@
'<(angle_path)/src/tests/test_utils/compiler_test.h',
'<(angle_path)/src/tests/test_utils/ConstantFoldingTest.h',
'<(angle_path)/src/tests/test_utils/ConstantFoldingTest.cpp',
'<(angle_path)/src/tests/test_utils/ShaderCompileTreeTest.h',
'<(angle_path)/src/tests/test_utils/ShaderCompileTreeTest.cpp',
],
# TODO(jmadill): should probably call this windows sources
'angle_unittests_hlsl_sources':
......
......@@ -11,142 +11,77 @@
#include "gtest/gtest.h"
#include "GLSLANG/ShaderLang.h"
#include "compiler/translator/TranslatorESSL.h"
#include "tests/test_utils/ShaderCompileTreeTest.h"
using namespace sh;
class MalformedShaderTest : public testing::Test
class MalformedShaderTest : public ShaderCompileTreeTest
{
public:
MalformedShaderTest() : mExtraCompileOptions(0) {}
protected:
virtual void SetUp()
{
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_FRAGMENT_SHADER, SH_GLES3_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
virtual void TearDown()
{
delete mTranslator;
}
// Return true when compilation succeeds
bool compile(const std::string& shaderString)
{
const char *shaderStrings[] = { shaderString.c_str() };
bool compilationSuccess =
mTranslator->compile(shaderStrings, 1, SH_INTERMEDIATE_TREE | mExtraCompileOptions);
TInfoSink &infoSink = mTranslator->getInfoSink();
mInfoLog = infoSink.info.c_str();
return compilationSuccess;
}
bool hasWarning() const
{
return mInfoLog.find("WARNING: ") != std::string::npos;
}
MalformedShaderTest() {}
protected:
std::string mInfoLog;
TranslatorESSL *mTranslator;
ShCompileOptions mExtraCompileOptions;
::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_GLES3_SPEC; }
};
class MalformedVertexShaderTest : public MalformedShaderTest
class MalformedVertexShaderTest : public ShaderCompileTreeTest
{
public:
MalformedVertexShaderTest() {}
protected:
void SetUp() override
{
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_VERTEX_SHADER, SH_GLES3_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
::GLenum getShaderType() const override { return GL_VERTEX_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_GLES3_SPEC; }
};
class MalformedWebGL2ShaderTest : public MalformedShaderTest
class MalformedWebGL2ShaderTest : public ShaderCompileTreeTest
{
public:
MalformedWebGL2ShaderTest() {}
protected:
void SetUp() override
{
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_FRAGMENT_SHADER, SH_WEBGL2_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_WEBGL2_SPEC; }
};
class MalformedWebGL1ShaderTest : public MalformedShaderTest
class MalformedWebGL1ShaderTest : public ShaderCompileTreeTest
{
public:
MalformedWebGL1ShaderTest() {}
protected:
void SetUp() override
{
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_FRAGMENT_SHADER, SH_WEBGL_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_WEBGL_SPEC; }
};
class MalformedVertexShaderGLES31Test : public MalformedShaderTest
class MalformedVertexShaderGLES31Test : public ShaderCompileTreeTest
{
public:
MalformedVertexShaderGLES31Test() {}
private:
void SetUp() override
{
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_VERTEX_SHADER, SH_GLES3_1_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
::GLenum getShaderType() const override { return GL_VERTEX_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
};
class MalformedFragmentShaderGLES31Test : public MalformedShaderTest
class MalformedFragmentShaderGLES31Test : public ShaderCompileTreeTest
{
public:
MalformedFragmentShaderGLES31Test() {}
private:
void SetUp() override
{
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_FRAGMENT_SHADER, SH_GLES3_1_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
};
class MalformedComputeShaderTest : public MalformedShaderTest
class MalformedComputeShaderTest : public ShaderCompileTreeTest
{
public:
MalformedComputeShaderTest() {}
private:
void SetUp() override
{
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_COMPUTE_SHADER, SH_GLES3_1_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
::GLenum getShaderType() const override { return GL_COMPUTE_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
};
// This is a test for a bug that used to exist in ANGLE:
......
......@@ -13,45 +13,22 @@
#include "compiler/translator/TranslatorESSL.h"
#include "GLSLANG/ShaderLang.h"
#include "tests/test_utils/compiler_test.h"
#include "tests/test_utils/ShaderCompileTreeTest.h"
using namespace sh;
class QualificationVertexShaderTestESSL31 : public testing::Test
class QualificationVertexShaderTestESSL31 : public ShaderCompileTreeTest
{
public:
QualificationVertexShaderTestESSL31() {}
protected:
virtual void SetUp()
{
ShBuiltInResources resources;
InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_VERTEX_SHADER, SH_GLES3_1_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
virtual void TearDown() { delete mTranslator; }
// Return true when compilation succeeds
bool compile(const std::string &shaderString)
{
const char *shaderStrings[] = {shaderString.c_str()};
mASTRoot = mTranslator->compileTreeForTesting(shaderStrings, 1,
SH_INTERMEDIATE_TREE | SH_VARIABLES);
TInfoSink &infoSink = mTranslator->getInfoSink();
mInfoLog = infoSink.info.c_str();
return mASTRoot != nullptr;
}
::GLenum getShaderType() const override { return GL_VERTEX_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
const TIntermSymbol *findSymbolInAST(const TString &symbolName, TBasicType basicType)
{
return FindSymbolNode(mASTRoot, symbolName, basicType);
}
protected:
TranslatorESSL *mTranslator;
TIntermNode *mASTRoot;
std::string mInfoLog;
};
// GLSL ES 3.10 has relaxed checks on qualifier order. Any order is correct.
......
......@@ -10,8 +10,8 @@
#include "angle_gl.h"
#include "gtest/gtest.h"
#include "GLSLANG/ShaderLang.h"
#include "compiler/translator/TranslatorESSL.h"
#include "tests/test_utils/compiler_test.h"
#include "tests/test_utils/ShaderCompileTreeTest.h"
using namespace sh;
......@@ -111,39 +111,20 @@ void CheckImageDeclaration(TIntermNode *astRoot,
} // namespace
class ShaderImageTest : public testing::Test
class ShaderImageTest : public ShaderCompileTreeTest
{
public:
ShaderImageTest() {}
protected:
virtual void SetUp()
void SetUp() override
{
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
mTranslator = new sh::TranslatorESSL(GL_COMPUTE_SHADER, SH_GLES3_1_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
virtual void TearDown() { delete mTranslator; }
// Return true when compilation succeeds
bool compile(const std::string &shaderString)
{
const char *shaderStrings[] = {shaderString.c_str()};
mASTRoot = mTranslator->compileTreeForTesting(shaderStrings, 1,
SH_INTERMEDIATE_TREE | SH_VARIABLES);
TInfoSink &infoSink = mTranslator->getInfoSink();
mInfoLog = infoSink.info.c_str();
return mASTRoot != nullptr;
ShaderCompileTreeTest::SetUp();
mExtraCompileOptions |= SH_VARIABLES;
}
protected:
std::string mTranslatedCode;
std::string mInfoLog;
sh::TranslatorESSL *mTranslator;
TIntermNode *mASTRoot;
::GLenum getShaderType() const override { return GL_COMPUTE_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
};
// Test that an image2D is properly parsed and exported as a uniform.
......@@ -161,7 +142,7 @@ TEST_F(ShaderImageTest, Image2DDeclaration)
FAIL() << "Shader compilation failed" << mInfoLog;
}
CheckExportedImageUniform(mTranslator->getUniforms(), 0, GL_IMAGE_2D, "myImage");
CheckExportedImageUniform(getUniforms(), 0, GL_IMAGE_2D, "myImage");
CheckImageDeclaration(mASTRoot, "myImage", EbtImage2D, EiifRGBA32F, true, false, false, false,
false);
}
......@@ -181,7 +162,7 @@ TEST_F(ShaderImageTest, Image3DDeclaration)
FAIL() << "Shader compilation failed" << mInfoLog;
}
CheckExportedImageUniform(mTranslator->getUniforms(), 0, GL_UNSIGNED_INT_IMAGE_3D, "myImage");
CheckExportedImageUniform(getUniforms(), 0, GL_UNSIGNED_INT_IMAGE_3D, "myImage");
CheckImageDeclaration(mASTRoot, "myImage", EbtUImage3D, EiifRGBA32UI, true, true, false, false,
false);
}
......
......@@ -15,42 +15,6 @@
using namespace sh;
void ConstantFoldingTest::SetUp()
{
allocator.push();
SetGlobalPoolAllocator(&allocator);
ShBuiltInResources resources;
InitBuiltInResources(&resources);
mTranslatorESSL = new TranslatorESSL(GL_FRAGMENT_SHADER, SH_GLES3_SPEC);
ASSERT_TRUE(mTranslatorESSL->Init(resources));
}
void ConstantFoldingTest::TearDown()
{
delete mTranslatorESSL;
SetGlobalPoolAllocator(NULL);
allocator.pop();
}
void ConstantFoldingTest::compile(const std::string &shaderString)
{
const char *shaderStrings[] = {shaderString.c_str()};
mASTRoot = mTranslatorESSL->compileTreeForTesting(shaderStrings, 1, SH_OBJECT_CODE);
if (!mASTRoot)
{
TInfoSink &infoSink = mTranslatorESSL->getInfoSink();
FAIL() << "Shader compilation into ESSL failed " << infoSink.info.c_str();
}
}
bool ConstantFoldingTest::hasWarning()
{
TInfoSink &infoSink = mTranslatorESSL->getInfoSink();
return infoSink.info.str().find("WARNING:") != std::string::npos;
}
void ConstantFoldingExpressionTest::evaluateFloat(const std::string &floatExpression)
{
std::stringstream shaderStream;
......@@ -61,5 +25,5 @@ void ConstantFoldingExpressionTest::evaluateFloat(const std::string &floatExpres
"{\n"
<< " my_FragColor = " << floatExpression << ";\n"
<< "}\n";
compile(shaderStream.str());
compileAssumeSuccess(shaderStream.str());
}
......@@ -14,8 +14,7 @@
#include "common/mathutil.h"
#include "compiler/translator/IntermNode.h"
#include "compiler/translator/PoolAlloc.h"
#include "gtest/gtest.h"
#include "tests/test_utils/ShaderCompileTreeTest.h"
namespace sh
{
......@@ -132,20 +131,14 @@ class ConstantFinder : public TIntermTraverser
bool mFound;
};
class ConstantFoldingTest : public testing::Test
class ConstantFoldingTest : public ShaderCompileTreeTest
{
public:
ConstantFoldingTest() {}
protected:
void SetUp() override;
void TearDown() override;
void compile(const std::string &shaderString);
// Must be called after compile()
bool hasWarning();
::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_GLES3_SPEC; }
template <typename T>
bool constantFoundInAST(T constant)
......@@ -176,12 +169,6 @@ class ConstantFoldingTest : public testing::Test
mASTRoot->traverse(&finder);
return finder.found();
}
private:
TranslatorESSL *mTranslatorESSL;
TIntermNode *mASTRoot;
TPoolAllocator allocator;
};
class ConstantFoldingExpressionTest : public ConstantFoldingTest
......
//
// Copyright (c) 2016 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.
//
// ShaderCompileTreeTest.cpp:
// Test that shader validation results in the correct compile status.
//
#include "tests/test_utils/ShaderCompileTreeTest.h"
#include "compiler/translator/TranslatorESSL.h"
using namespace sh;
void ShaderCompileTreeTest::SetUp()
{
mAllocator.push();
SetGlobalPoolAllocator(&mAllocator);
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
initResources(&resources);
mTranslator = new TranslatorESSL(getShaderType(), getShaderSpec());
ASSERT_TRUE(mTranslator->Init(resources));
}
void ShaderCompileTreeTest::TearDown()
{
delete mTranslator;
SetGlobalPoolAllocator(nullptr);
mAllocator.pop();
}
bool ShaderCompileTreeTest::compile(const std::string &shaderString)
{
const char *shaderStrings[] = {shaderString.c_str()};
mASTRoot = mTranslator->compileTreeForTesting(shaderStrings, 1, mExtraCompileOptions);
TInfoSink &infoSink = mTranslator->getInfoSink();
mInfoLog = infoSink.info.c_str();
return mASTRoot != nullptr;
}
void ShaderCompileTreeTest::compileAssumeSuccess(const std::string &shaderString)
{
if (!compile(shaderString))
{
FAIL() << "Shader compilation into ESSL failed, log:\n" << mInfoLog;
}
}
bool ShaderCompileTreeTest::hasWarning() const
{
return mInfoLog.find("WARNING: ") != std::string::npos;
}
const std::vector<sh::Uniform> ShaderCompileTreeTest::getUniforms()
{
ASSERT(mExtraCompileOptions & SH_VARIABLES);
return mTranslator->getUniforms();
}
\ No newline at end of file
//
// Copyright (c) 2016 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.
//
// ShaderCompileTreeTest.h:
// Test that shader validation results in the correct compile status.
//
#ifndef TESTS_TEST_UTILS_SHADER_COMPILE_TREE_TEST_H_
#define TESTS_TEST_UTILS_SHADER_COMPILE_TREE_TEST_H_
#include "angle_gl.h"
#include "compiler/translator/PoolAlloc.h"
#include "gtest/gtest.h"
#include "GLSLANG/ShaderLang.h"
namespace sh
{
class TIntermBlock;
class TranslatorESSL;
class ShaderCompileTreeTest : public testing::Test
{
public:
ShaderCompileTreeTest() : mExtraCompileOptions(0) {}
protected:
void SetUp() override;
void TearDown() override;
// Return true when compilation succeeds
bool compile(const std::string &shaderString);
void compileAssumeSuccess(const std::string &shaderString);
bool hasWarning() const;
const std::vector<sh::Uniform> getUniforms();
virtual void initResources(ShBuiltInResources *resources) {}
virtual ::GLenum getShaderType() const = 0;
virtual ShShaderSpec getShaderSpec() const = 0;
std::string mInfoLog;
ShCompileOptions mExtraCompileOptions;
TIntermBlock *mASTRoot;
private:
TranslatorESSL *mTranslator;
TPoolAllocator mAllocator;
};
} // namespace sh
#endif // TESTS_TEST_UTILS_SHADER_COMPILE_TREE_TEST_H_
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