Commit be3d2d98 by shrekshao Committed by Commit Bot

More HLSL tests with regex

Replace some more HLSL hardcoded unique id tests suffix with regex Bug: angleproject:3551 Change-Id: I4ed54092f9b2dda27702ba9412959ec3fb93a455 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1677408 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent b5a13bec
...@@ -44,7 +44,7 @@ class DebugShaderPrecisionTest : public MatchOutputCodeTest ...@@ -44,7 +44,7 @@ class DebugShaderPrecisionTest : public MatchOutputCodeTest
bool foundInHLSLCodeRegex(const char *regexToFind) const bool foundInHLSLCodeRegex(const char *regexToFind) const
{ {
#if defined(ANGLE_ENABLE_HLSL) #if defined(ANGLE_ENABLE_HLSL)
return foundInCodeRegex(SH_HLSL_4_1_OUTPUT, regexToFind); return foundInCodeRegex(SH_HLSL_4_1_OUTPUT, std::regex(regexToFind));
#else #else
return true; return true;
#endif #endif
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
// Tests for HLSL output. // Tests for HLSL output.
// //
#include <regex>
#include "GLSLANG/ShaderLang.h" #include "GLSLANG/ShaderLang.h"
#include "angle_gl.h" #include "angle_gl.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
...@@ -197,9 +198,7 @@ TEST_F(HLSLOutputTest, Array) ...@@ -197,9 +198,7 @@ TEST_F(HLSLOutputTest, Array)
} }
})"; })";
compile(shaderString); compile(shaderString);
// The unique id of arr is 1030, which is given to the symbol when parsed and inserted to the EXPECT_TRUE(foundInCodeRegex(std::regex("_arr(\\d)*\\[2\\]")));
// symbol table
EXPECT_TRUE(foundInCode("_arr1030[2]"));
} }
// Test that initializing array with previously declared array will not be overwritten // Test that initializing array with previously declared array will not be overwritten
...@@ -219,10 +218,14 @@ TEST_F(HLSLOutputTest, SameNameArray) ...@@ -219,10 +218,14 @@ TEST_F(HLSLOutputTest, SameNameArray)
} }
})"; })";
compile(shaderString); compile(shaderString);
// The unique id of the original array, arr, is 1029 // There should be two different arr defined, e.g. _arr1000 and _arr1001
EXPECT_TRUE(foundInCode("_arr1029[2]")); // Use Workaround for now.
// The unique id of the new array, arr, is 1030 // Once the build team fixes libc++ we could use the following one line solution instead.
EXPECT_TRUE(foundInCode("_arr1030[2]")); // EXPECT_TRUE(foundInCodeRegex(std::regex("_arr(\\d*)\\[2\\](.|\\r|\\n)*_arr(?!\\1)\\d*\\[2\\]")));
std::smatch m;
EXPECT_TRUE(foundInCodeRegex(std::regex("_arr(\\d)*\\[2\\]"), &m));
EXPECT_TRUE(m.size() == 2);
EXPECT_TRUE(m[0].str() != m[1].str());
} }
// Test that passing a non-struct member of a std140 structure to a function won't trigger the // Test that passing a non-struct member of a std140 structure to a function won't trigger the
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
// utilities for compiler unit tests. // utilities for compiler unit tests.
#include "tests/test_utils/compiler_test.h" #include "tests/test_utils/compiler_test.h"
#include <regex>
#include "angle_gl.h" #include "angle_gl.h"
#include "compiler/translator/Compiler.h" #include "compiler/translator/Compiler.h"
...@@ -157,7 +156,9 @@ bool MatchOutputCodeTest::compileWithSettings(ShShaderOutput output, ...@@ -157,7 +156,9 @@ bool MatchOutputCodeTest::compileWithSettings(ShShaderOutput output,
compileOptions, translatedCode, infoLog); compileOptions, translatedCode, infoLog);
} }
bool MatchOutputCodeTest::foundInCodeRegex(ShShaderOutput output, const char *regexToFind) const bool MatchOutputCodeTest::foundInCodeRegex(ShShaderOutput output,
const std::regex &regexToFind,
std::smatch *match) const
{ {
const auto code = mOutputCode.find(output); const auto code = mOutputCode.find(output);
EXPECT_NE(mOutputCode.end(), code); EXPECT_NE(mOutputCode.end(), code);
...@@ -166,9 +167,14 @@ bool MatchOutputCodeTest::foundInCodeRegex(ShShaderOutput output, const char *re ...@@ -166,9 +167,14 @@ bool MatchOutputCodeTest::foundInCodeRegex(ShShaderOutput output, const char *re
return std::string::npos; return std::string::npos;
} }
std::regex r(regexToFind); if (match)
{
return std::regex_search(code->second, r); return std::regex_search(code->second, *match, regexToFind);
}
else
{
return std::regex_search(code->second, regexToFind);
}
} }
bool MatchOutputCodeTest::foundInCode(ShShaderOutput output, const char *stringToFind) const bool MatchOutputCodeTest::foundInCode(ShShaderOutput output, const char *stringToFind) const
...@@ -247,6 +253,18 @@ bool MatchOutputCodeTest::foundInCode(const char *stringToFind) const ...@@ -247,6 +253,18 @@ bool MatchOutputCodeTest::foundInCode(const char *stringToFind) const
return true; return true;
} }
bool MatchOutputCodeTest::foundInCodeRegex(const std::regex &regexToFind, std::smatch *match) const
{
for (auto &code : mOutputCode)
{
if (!foundInCodeRegex(code.first, regexToFind, match))
{
return false;
}
}
return true;
}
bool MatchOutputCodeTest::foundInCode(const char *stringToFind, const int expectedOccurrences) const bool MatchOutputCodeTest::foundInCode(const char *stringToFind, const int expectedOccurrences) const
{ {
for (auto &code : mOutputCode) for (auto &code : mOutputCode)
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#define TESTS_TEST_UTILS_COMPILER_TEST_H_ #define TESTS_TEST_UTILS_COMPILER_TEST_H_
#include <map> #include <map>
#include <regex>
#include <vector> #include <vector>
#include "gtest/gtest.h" #include "gtest/gtest.h"
...@@ -64,9 +65,10 @@ class MatchOutputCodeTest : public testing::Test ...@@ -64,9 +65,10 @@ class MatchOutputCodeTest : public testing::Test
return foundInCode(SH_GLSL_COMPATIBILITY_OUTPUT, stringToFind); return foundInCode(SH_GLSL_COMPATIBILITY_OUTPUT, stringToFind);
} }
bool foundInCodeRegex(ShShaderOutput output, const char *regexToFind) const;
bool foundInCode(ShShaderOutput output, const char *stringToFind) const; bool foundInCode(ShShaderOutput output, const char *stringToFind) const;
bool foundInCodeRegex(ShShaderOutput output,
const std::regex &regexToFind,
std::smatch *match = nullptr) const;
// Test that the strings are found in the specified output in the specified order. // Test that the strings are found in the specified output in the specified order.
bool foundInCodeInOrder(ShShaderOutput output, std::vector<const char *> stringsToFind); bool foundInCodeInOrder(ShShaderOutput output, std::vector<const char *> stringsToFind);
...@@ -78,6 +80,7 @@ class MatchOutputCodeTest : public testing::Test ...@@ -78,6 +80,7 @@ class MatchOutputCodeTest : public testing::Test
// Test that the string is found in all outputs // Test that the string is found in all outputs
bool foundInCode(const char *stringToFind) const; bool foundInCode(const char *stringToFind) const;
bool foundInCodeRegex(const std::regex &regexToFind, std::smatch *match = nullptr) const;
// Test that the string occurs for exactly expectedOccurrences times in all outputs // Test that the string occurs for exactly expectedOccurrences times in all outputs
bool foundInCode(const char *stringToFind, const int expectedOccurrences) const; bool foundInCode(const char *stringToFind, const int expectedOccurrences) const;
......
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