[Mesa-dev] [PATCH v3 6/7] mesa/st: glsl_to_tgsi: Add test set for evaluation of rename mapping
Gert Wollny
gw.fossdev at gmail.com
Sun Jun 18 17:42:58 UTC 2017
The patch adds tests for the register rename mapping evaluation.
---
.../tests/test_glsl_to_tgsi_lifetime.cpp | 71 ++++++++++++++++++++--
1 file changed, 66 insertions(+), 5 deletions(-)
diff --git a/src/mesa/state_tracker/tests/test_glsl_to_tgsi_lifetime.cpp b/src/mesa/state_tracker/tests/test_glsl_to_tgsi_lifetime.cpp
index 7e07f8868f..8fd62d1db3 100644
--- a/src/mesa/state_tracker/tests/test_glsl_to_tgsi_lifetime.cpp
+++ b/src/mesa/state_tracker/tests/test_glsl_to_tgsi_lifetime.cpp
@@ -74,15 +74,18 @@ private:
using expectation = vector<vector<int>>;
-class LifetimeEvaluatorTest : public testing::Test {
-
+class MesaTestWithMemCtx : public testing::Test {
void SetUp();
void TearDown();
protected:
+ void *mem_ctx;
+};
+
+class LifetimeEvaluatorTest : public MesaTestWithMemCtx {
+protected:
void run(const vector<MockCodeline>& code, const expectation& e);
private:
virtual void check(const vector<lifetime>& result, const expectation& e) = 0;
- void *mem_ctx;
};
/* This is a teat class to check the exact life times of
@@ -925,12 +928,12 @@ st_dst_reg MockShader::create_dst_register(int dst_idx)
return st_dst_reg(file, 0xF, GLSL_TYPE_INT, idx);
}
-void LifetimeEvaluatorTest::SetUp()
+void MesaTestWithMemCtx::SetUp()
{
mem_ctx = ralloc_context(nullptr);
}
-void LifetimeEvaluatorTest::TearDown()
+void MesaTestWithMemCtx::TearDown()
{
ralloc_free(mem_ctx);
mem_ctx = nullptr;
@@ -967,3 +970,61 @@ void LifetimeEvaluatorAtLeastTest::check( const vector<lifetime>& lifetimes,
EXPECT_GE(lifetimes[i].end, e[i][1]);
}
}
+
+class RegisterRemapping : public MesaTestWithMemCtx {
+protected:
+ void run(const vector<lifetime>& lt, const vector<int>& expect);
+};
+
+void RegisterRemapping::run(const vector<lifetime>& lt,
+ const vector<int>& expect)
+{
+ rename_reg_pair proto{false, 0};
+ vector<rename_reg_pair> result(lt.size(), proto);
+
+ evaluate_remapping(mem_ctx, lt.size(), <[0], &result[0]);
+
+ vector<int> remap(lt.size());
+ for (unsigned i = 0; i < lt.size(); ++i) {
+ remap[i] = result[i].valid ? result[i].new_reg : i;
+ }
+
+ std::transform(remap.begin(), remap.end(), result.begin(), remap.begin(),
+ [](int x, const rename_reg_pair& rn) {
+ return rn.valid ? rn.new_reg : x;
+ });
+
+ for(unsigned i = 1; i < remap.size(); ++i) {
+ EXPECT_EQ(remap[i], expect[i]);
+ }
+}
+
+TEST_F(RegisterRemapping, RegisterRemapping1)
+{
+ vector<lifetime> lt({{-1,-1},
+ {0, 1},
+ {0, 2},
+ {1, 2},
+ {2, 10},
+ {3, 5},
+ {5, 10}
+ });
+
+ vector<int> expect({0, 1, 2, 1, 1, 2, 2});
+ run(lt, expect);
+}
+
+
+TEST_F(RegisterRemapping, RegisterRemapping2)
+{
+ vector<lifetime> lt({{-1,-1},
+ {0, 1},
+ {0, 2},
+ {3, 3},
+ {4, 4},
+ });
+ vector<int> expect({0, 1, 2, 1, 1});
+ run(lt, expect);
+}
+
+
--
2.13.0
More information about the mesa-dev
mailing list