X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=tests%2Fglsl%2Fglslcompiler.cpp;h=8d3fe532c2eb818a6e0123c8505e0a0545064c8f;hb=1401e69c17d06034af53f6e55e735be065b75c7b;hp=0fd0855489d63ca4f6a5de05c30c0615a9307c89;hpb=1e3605edd174bce94bb21b662c7a83f79f1df37f;p=libs%2Fgl.git diff --git a/tests/glsl/glslcompiler.cpp b/tests/glsl/glslcompiler.cpp index 0fd08554..8d3fe532 100644 --- a/tests/glsl/glslcompiler.cpp +++ b/tests/glsl/glslcompiler.cpp @@ -43,6 +43,18 @@ private: virtual void fail(const std::string &m) { Test::fail(m); } }; +class GlslCompilerIdempotence: public Msp::Test::RegisteredTest, private GlslCompilerHelper +{ +public: + GlslCompilerIdempotence(); + + static const char *get_name() { return "GLSL compiler idempotence"; } + +private: + void run_test_case(const TestCase *); + virtual void fail(const std::string &m) { Test::fail(m); } +}; + using namespace std; using namespace Msp; @@ -216,7 +228,7 @@ GlslCompilerTest::GlslCompilerTest() void GlslCompilerTest::run_test_case(const TestCase *test_case) { - GL::SL::Compiler compiler(GL::SL::Features::all()); + GL::SL::Compiler compiler(GL::SL::Features::latest()); try { compiler.set_source(test_case->source, ""); @@ -259,3 +271,42 @@ void GlslCompilerTest::run_test_case(const TestCase *test_case) if(find(stages, s.first)==stages.end()) fail(format("Compiler didn't produce stage %s", GL::SL::Stage::get_stage_name(s.first))); } + + +GlslCompilerIdempotence::GlslCompilerIdempotence() +{ + load_all_test_cases("glsl"); + for(const auto &tc: test_cases) + if(tc.expected_error.empty()) + add(&GlslCompilerIdempotence::run_test_case, &tc, tc.name); +} + +void GlslCompilerIdempotence::run_test_case(const TestCase *test_case) +{ + GL::SL::Compiler compiler(GL::SL::Features::latest()); + compiler.set_source(test_case->source, ""); + if(test_case->compile_mode==GL::SL::Compiler::PROGRAM) + compiler.specialize(test_case->spec_values); + compiler.compile(test_case->compile_mode); + + GL::SL::Compiler compiler2(GL::SL::Features::latest()); + compiler2.set_source(compiler.get_combined_glsl(), ""); + compiler2.compile(test_case->compile_mode); + + auto stages = compiler.get_stages(); + auto stages2 = compiler2.get_stages(); + auto i = stages.begin(); + auto j = stages2.begin(); + for(; (i!=stages.end() && j!=stages2.end() && *i==*j); ++i, ++j) + { + string output = compiler.get_stage_glsl(*i); + string output2 = compiler2.get_stage_glsl(*j); + + verify_output(output2, output); + } + + if(i!=stages.end()) + fail(format("Second pass didn't produce stage %s", GL::SL::Stage::get_stage_name(*i))); + if(j!=stages2.end()) + fail(format("Second pass produced extra stage %s", GL::SL::Stage::get_stage_name(*j))); +}