]> git.tdb.fi Git - libs/gl.git/commitdiff
Support compile modes and specialization constants in the test harness
authorMikko Rasa <tdb@tdb.fi>
Wed, 10 Mar 2021 10:01:33 +0000 (12:01 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 10 Mar 2021 10:01:33 +0000 (12:01 +0200)
tests/glsl/glslcompiler.cpp

index acca61d36a217e7bec5dcc572576209a5bfb3244..30805db3ff80a2b8be88c2ad868c1bcbd33ea253 100644 (file)
@@ -16,6 +16,8 @@ private:
        {
                std::string name;
                std::string source;
+               Msp::GL::SL::Compiler::Mode compile_mode;
+               std::map<std::string, int> spec_values;
                std::map<Msp::GL::SL::Stage::Type, std::string> expected_output;
                std::string expected_error;
        };
@@ -56,6 +58,7 @@ const GlslCompilerTest::TestCase &GlslCompilerTest::load_test_case(const string
        IO::BufferedFile file(fn);
        TestCase test_case;
        test_case.name = FS::basename(fn);
+       test_case.compile_mode = GL::SL::Compiler::PROGRAM;
        string *target = &test_case.source;
        while(!file.eof())
        {
@@ -66,10 +69,10 @@ const GlslCompilerTest::TestCase &GlslCompilerTest::load_test_case(const string
                if(line=="*/")
                        continue;
 
-               string::size_type expected = line.find("Expected output:");
-               if(expected!=string::npos)
+               string::size_type pos = line.find("Expected output:");
+               if(pos!=string::npos)
                {
-                       string stage = strip(line.substr(expected+16));
+                       string stage = strip(line.substr(pos+16));
                        if(stage=="vertex")
                                target = &test_case.expected_output[GL::SL::Stage::VERTEX];
                        else if(stage=="geometry")
@@ -81,13 +84,41 @@ const GlslCompilerTest::TestCase &GlslCompilerTest::load_test_case(const string
                        continue;
                }
 
-               expected = line.find("Expected error:");
-               if(expected!=string::npos)
+               pos = line.find("Expected error:");
+               if(pos!=string::npos)
                {
                        target = &test_case.expected_error;
                        continue;
                }
 
+               pos = line.find("Compile mode:");
+               if(pos!=string::npos)
+               {
+                       string mode = strip(line.substr(pos+13));
+                       if(mode=="module")
+                               test_case.compile_mode = GL::SL::Compiler::MODULE;
+                       else if(mode=="program")
+                               test_case.compile_mode = GL::SL::Compiler::PROGRAM;
+                       else
+                               throw runtime_error("Unknown compile mode "+mode);
+                       continue;
+               }
+
+               pos = line.find("Specialize:");
+               if(pos!=string::npos)
+               {
+                       vector<string> parts = split(line.substr(pos+11));
+                       int value = 0;
+                       if(parts[1]=="true")
+                               value = 1;
+                       else if(parts[1]=="false")
+                               value = 0;
+                       else
+                               value = lexical_cast<int>(parts[1]);
+                       test_case.spec_values[parts[0]] = value;
+                       continue;
+               }
+
                *target += line;
                *target += '\n';
        }
@@ -102,7 +133,9 @@ void GlslCompilerTest::run_test_case(const TestCase *test_case)
        try
        {
                compiler.set_source(test_case->source, "<test>");
-               compiler.compile(GL::SL::Compiler::PROGRAM);
+               if(test_case->compile_mode==GL::SL::Compiler::PROGRAM)
+                       compiler.specialize(test_case->spec_values);
+               compiler.compile(test_case->compile_mode);
        }
        catch(const GL::SL::invalid_shader_source &exc)
        {