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
bool foundInHLSLCodeRegex(const char *regexToFind) const
{
#if defined(ANGLE_ENABLE_HLSL)
return foundInCodeRegex(SH_HLSL_4_1_OUTPUT, regexToFind);
return foundInCodeRegex(SH_HLSL_4_1_OUTPUT, std::regex(regexToFind));
#else
return true;
#endif
......
......@@ -7,6 +7,7 @@
// Tests for HLSL output.
//
#include <regex>
#include "GLSLANG/ShaderLang.h"
#include "angle_gl.h"
#include "gtest/gtest.h"
......@@ -197,9 +198,7 @@ TEST_F(HLSLOutputTest, Array)
}
})";
compile(shaderString);
// The unique id of arr is 1030, which is given to the symbol when parsed and inserted to the
// symbol table
EXPECT_TRUE(foundInCode("_arr1030[2]"));
EXPECT_TRUE(foundInCodeRegex(std::regex("_arr(\\d)*\\[2\\]")));
}
// Test that initializing array with previously declared array will not be overwritten
......@@ -219,10 +218,14 @@ TEST_F(HLSLOutputTest, SameNameArray)
}
})";
compile(shaderString);
// The unique id of the original array, arr, is 1029
EXPECT_TRUE(foundInCode("_arr1029[2]"));
// The unique id of the new array, arr, is 1030
EXPECT_TRUE(foundInCode("_arr1030[2]"));
// There should be two different arr defined, e.g. _arr1000 and _arr1001
// Use Workaround for now.
// Once the build team fixes libc++ we could use the following one line solution instead.
// 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
......
......@@ -7,7 +7,6 @@
// utilities for compiler unit tests.
#include "tests/test_utils/compiler_test.h"
#include <regex>
#include "angle_gl.h"
#include "compiler/translator/Compiler.h"
......@@ -157,7 +156,9 @@ bool MatchOutputCodeTest::compileWithSettings(ShShaderOutput output,
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);
EXPECT_NE(mOutputCode.end(), code);
......@@ -166,9 +167,14 @@ bool MatchOutputCodeTest::foundInCodeRegex(ShShaderOutput output, const char *re
return std::string::npos;
}
std::regex r(regexToFind);
return std::regex_search(code->second, r);
if (match)
{
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
......@@ -247,6 +253,18 @@ bool MatchOutputCodeTest::foundInCode(const char *stringToFind) const
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
{
for (auto &code : mOutputCode)
......
......@@ -10,6 +10,7 @@
#define TESTS_TEST_UTILS_COMPILER_TEST_H_
#include <map>
#include <regex>
#include <vector>
#include "gtest/gtest.h"
......@@ -64,9 +65,10 @@ class MatchOutputCodeTest : public testing::Test
return foundInCode(SH_GLSL_COMPATIBILITY_OUTPUT, stringToFind);
}
bool foundInCodeRegex(ShShaderOutput output, const char *regexToFind) 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.
bool foundInCodeInOrder(ShShaderOutput output, std::vector<const char *> stringsToFind);
......@@ -78,6 +80,7 @@ class MatchOutputCodeTest : public testing::Test
// Test that the string is found in all outputs
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
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