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 @@ ...@@ -96,6 +96,8 @@
'<(angle_path)/src/tests/test_utils/compiler_test.h', '<(angle_path)/src/tests/test_utils/compiler_test.h',
'<(angle_path)/src/tests/test_utils/ConstantFoldingTest.h', '<(angle_path)/src/tests/test_utils/ConstantFoldingTest.h',
'<(angle_path)/src/tests/test_utils/ConstantFoldingTest.cpp', '<(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 # TODO(jmadill): should probably call this windows sources
'angle_unittests_hlsl_sources': 'angle_unittests_hlsl_sources':
......
...@@ -11,142 +11,77 @@ ...@@ -11,142 +11,77 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "GLSLANG/ShaderLang.h" #include "GLSLANG/ShaderLang.h"
#include "compiler/translator/TranslatorESSL.h" #include "compiler/translator/TranslatorESSL.h"
#include "tests/test_utils/ShaderCompileTreeTest.h"
using namespace sh; using namespace sh;
class MalformedShaderTest : public testing::Test class MalformedShaderTest : public ShaderCompileTreeTest
{ {
public: public:
MalformedShaderTest() : mExtraCompileOptions(0) {} MalformedShaderTest() {}
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;
}
protected: protected:
std::string mInfoLog; ::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
TranslatorESSL *mTranslator; ShShaderSpec getShaderSpec() const override { return SH_GLES3_SPEC; }
ShCompileOptions mExtraCompileOptions;
}; };
class MalformedVertexShaderTest : public MalformedShaderTest class MalformedVertexShaderTest : public ShaderCompileTreeTest
{ {
public: public:
MalformedVertexShaderTest() {} MalformedVertexShaderTest() {}
protected: protected:
void SetUp() override ::GLenum getShaderType() const override { return GL_VERTEX_SHADER; }
{ ShShaderSpec getShaderSpec() const override { return SH_GLES3_SPEC; }
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_VERTEX_SHADER, SH_GLES3_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
}; };
class MalformedWebGL2ShaderTest : public MalformedShaderTest class MalformedWebGL2ShaderTest : public ShaderCompileTreeTest
{ {
public: public:
MalformedWebGL2ShaderTest() {} MalformedWebGL2ShaderTest() {}
protected: protected:
void SetUp() override ::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
{ ShShaderSpec getShaderSpec() const override { return SH_WEBGL2_SPEC; }
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_FRAGMENT_SHADER, SH_WEBGL2_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
}; };
class MalformedWebGL1ShaderTest : public MalformedShaderTest class MalformedWebGL1ShaderTest : public ShaderCompileTreeTest
{ {
public: public:
MalformedWebGL1ShaderTest() {} MalformedWebGL1ShaderTest() {}
protected: protected:
void SetUp() override ::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
{ ShShaderSpec getShaderSpec() const override { return SH_WEBGL_SPEC; }
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_FRAGMENT_SHADER, SH_WEBGL_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
}; };
class MalformedVertexShaderGLES31Test : public MalformedShaderTest class MalformedVertexShaderGLES31Test : public ShaderCompileTreeTest
{ {
public: public:
MalformedVertexShaderGLES31Test() {} MalformedVertexShaderGLES31Test() {}
private: private:
void SetUp() override ::GLenum getShaderType() const override { return GL_VERTEX_SHADER; }
{ ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_VERTEX_SHADER, SH_GLES3_1_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
}; };
class MalformedFragmentShaderGLES31Test : public MalformedShaderTest class MalformedFragmentShaderGLES31Test : public ShaderCompileTreeTest
{ {
public: public:
MalformedFragmentShaderGLES31Test() {} MalformedFragmentShaderGLES31Test() {}
private: private:
void SetUp() override ::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
{ ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_FRAGMENT_SHADER, SH_GLES3_1_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
}; };
class MalformedComputeShaderTest : public MalformedShaderTest class MalformedComputeShaderTest : public ShaderCompileTreeTest
{ {
public: public:
MalformedComputeShaderTest() {} MalformedComputeShaderTest() {}
private: private:
void SetUp() override ::GLenum getShaderType() const override { return GL_COMPUTE_SHADER; }
{ ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_COMPUTE_SHADER, SH_GLES3_1_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
}; };
// This is a test for a bug that used to exist in ANGLE: // This is a test for a bug that used to exist in ANGLE:
......
...@@ -13,45 +13,22 @@ ...@@ -13,45 +13,22 @@
#include "compiler/translator/TranslatorESSL.h" #include "compiler/translator/TranslatorESSL.h"
#include "GLSLANG/ShaderLang.h" #include "GLSLANG/ShaderLang.h"
#include "tests/test_utils/compiler_test.h" #include "tests/test_utils/compiler_test.h"
#include "tests/test_utils/ShaderCompileTreeTest.h"
using namespace sh; using namespace sh;
class QualificationVertexShaderTestESSL31 : public testing::Test class QualificationVertexShaderTestESSL31 : public ShaderCompileTreeTest
{ {
public: public:
QualificationVertexShaderTestESSL31() {} QualificationVertexShaderTestESSL31() {}
protected: protected:
virtual void SetUp() ::GLenum getShaderType() const override { return GL_VERTEX_SHADER; }
{ ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
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;
}
const TIntermSymbol *findSymbolInAST(const TString &symbolName, TBasicType basicType) const TIntermSymbol *findSymbolInAST(const TString &symbolName, TBasicType basicType)
{ {
return FindSymbolNode(mASTRoot, symbolName, 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. // GLSL ES 3.10 has relaxed checks on qualifier order. Any order is correct.
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#include "angle_gl.h" #include "angle_gl.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "GLSLANG/ShaderLang.h" #include "GLSLANG/ShaderLang.h"
#include "compiler/translator/TranslatorESSL.h"
#include "tests/test_utils/compiler_test.h" #include "tests/test_utils/compiler_test.h"
#include "tests/test_utils/ShaderCompileTreeTest.h"
using namespace sh; using namespace sh;
...@@ -111,39 +111,20 @@ void CheckImageDeclaration(TIntermNode *astRoot, ...@@ -111,39 +111,20 @@ void CheckImageDeclaration(TIntermNode *astRoot,
} // namespace } // namespace
class ShaderImageTest : public testing::Test class ShaderImageTest : public ShaderCompileTreeTest
{ {
public: public:
ShaderImageTest() {} ShaderImageTest() {}
protected: protected:
virtual void SetUp() void SetUp() override
{ {
ShBuiltInResources resources; ShaderCompileTreeTest::SetUp();
sh::InitBuiltInResources(&resources); mExtraCompileOptions |= SH_VARIABLES;
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;
} }
protected: ::GLenum getShaderType() const override { return GL_COMPUTE_SHADER; }
std::string mTranslatedCode; ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
std::string mInfoLog;
sh::TranslatorESSL *mTranslator;
TIntermNode *mASTRoot;
}; };
// Test that an image2D is properly parsed and exported as a uniform. // Test that an image2D is properly parsed and exported as a uniform.
...@@ -161,7 +142,7 @@ TEST_F(ShaderImageTest, Image2DDeclaration) ...@@ -161,7 +142,7 @@ TEST_F(ShaderImageTest, Image2DDeclaration)
FAIL() << "Shader compilation failed" << mInfoLog; 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, CheckImageDeclaration(mASTRoot, "myImage", EbtImage2D, EiifRGBA32F, true, false, false, false,
false); false);
} }
...@@ -181,7 +162,7 @@ TEST_F(ShaderImageTest, Image3DDeclaration) ...@@ -181,7 +162,7 @@ TEST_F(ShaderImageTest, Image3DDeclaration)
FAIL() << "Shader compilation failed" << mInfoLog; 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, CheckImageDeclaration(mASTRoot, "myImage", EbtUImage3D, EiifRGBA32UI, true, true, false, false,
false); false);
} }
......
...@@ -15,42 +15,6 @@ ...@@ -15,42 +15,6 @@
using namespace sh; 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) void ConstantFoldingExpressionTest::evaluateFloat(const std::string &floatExpression)
{ {
std::stringstream shaderStream; std::stringstream shaderStream;
...@@ -61,5 +25,5 @@ void ConstantFoldingExpressionTest::evaluateFloat(const std::string &floatExpres ...@@ -61,5 +25,5 @@ void ConstantFoldingExpressionTest::evaluateFloat(const std::string &floatExpres
"{\n" "{\n"
<< " my_FragColor = " << floatExpression << ";\n" << " my_FragColor = " << floatExpression << ";\n"
<< "}\n"; << "}\n";
compile(shaderStream.str()); compileAssumeSuccess(shaderStream.str());
} }
...@@ -14,8 +14,7 @@ ...@@ -14,8 +14,7 @@
#include "common/mathutil.h" #include "common/mathutil.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermNode.h"
#include "compiler/translator/PoolAlloc.h" #include "tests/test_utils/ShaderCompileTreeTest.h"
#include "gtest/gtest.h"
namespace sh namespace sh
{ {
...@@ -132,20 +131,14 @@ class ConstantFinder : public TIntermTraverser ...@@ -132,20 +131,14 @@ class ConstantFinder : public TIntermTraverser
bool mFound; bool mFound;
}; };
class ConstantFoldingTest : public testing::Test class ConstantFoldingTest : public ShaderCompileTreeTest
{ {
public: public:
ConstantFoldingTest() {} ConstantFoldingTest() {}
protected: protected:
void SetUp() override; ::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_GLES3_SPEC; }
void TearDown() override;
void compile(const std::string &shaderString);
// Must be called after compile()
bool hasWarning();
template <typename T> template <typename T>
bool constantFoundInAST(T constant) bool constantFoundInAST(T constant)
...@@ -176,12 +169,6 @@ class ConstantFoldingTest : public testing::Test ...@@ -176,12 +169,6 @@ class ConstantFoldingTest : public testing::Test
mASTRoot->traverse(&finder); mASTRoot->traverse(&finder);
return finder.found(); return finder.found();
} }
private:
TranslatorESSL *mTranslatorESSL;
TIntermNode *mASTRoot;
TPoolAllocator allocator;
}; };
class ConstantFoldingExpressionTest : public ConstantFoldingTest 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