1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2019 Google LLC
6 * Copyright (c) 2019 The Khronos Group Inc.
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
20 *//*--------------------------------------------------------------------*/
22 #include "vktAmberTestCase.hpp"
23 #include "vktTestGroupUtil.hpp"
30 class AmberIndexFileParser
35 static const int m_fieldLen = 256;
36 char m_scratch[m_fieldLen];
37 char m_filenameField[m_fieldLen];
38 char m_testnameField[m_fieldLen];
39 char m_descField[m_fieldLen];
41 bool isWhitespace (char c)
53 void skipWhitespace (void)
55 while (m_idx < m_len && isWhitespace(m_buf[m_idx]))
61 if (m_buf[m_idx] == c)
67 if (m_buf[m_idx] != c || m_idx >= m_len)
68 TCU_THROW(ResourceError, "Error parsing amber index file");
73 void captureString (char* field)
77 while (m_idx < m_len && i < m_fieldLen && m_buf[m_idx] != '"')
79 field[i] = m_buf[m_idx];
88 char* loadFile (const char* filename, size_t& len)
90 FILE* f = fopen(filename, "rb");
94 std::string error("Unable to open index file ");
95 error.append(filename);
96 TCU_THROW(ResourceError, error.c_str());
99 fseek(f, 0, SEEK_END);
101 fseek(f, 0, SEEK_SET);
102 char* buf = new char[len + 1];
104 if (fread(buf, 1, len, f) != len)
108 std::string error("File i/o error reading index file ");
109 error.append(filename);
110 TCU_THROW(ResourceError, error.c_str());
119 AmberIndexFileParser (const char* filename, const char* category)
121 std::string indexFilename("vulkan/amber/");
122 indexFilename.append(category);
123 indexFilename.append("/");
124 indexFilename.append(filename);
126 m_buf = loadFile(indexFilename.c_str(), m_len);
130 ~AmberIndexFileParser (void)
135 AmberTestCase* parse (const char* category, tcu::TestContext& testCtx)
138 // {"filename","test name","description"[,requirement[,requirement[,requirement..]]]}[,]
139 // Things inside [] are optional. Whitespace is allowed everywhere.
141 // For example, test without requirements might be:
142 // {"testname.amber","test name","test description"},
150 captureString(m_filenameField);
155 captureString(m_testnameField);
160 captureString(m_descField);
163 std::string testFilename("vulkan/amber/");
164 testFilename.append(category);
165 testFilename.append("/");
166 testFilename.append(m_filenameField);
167 AmberTestCase *testCase = new AmberTestCase(testCtx, m_testnameField, m_descField, testFilename);
169 while (m_idx < m_len && m_buf[m_idx] == ',')
174 captureString(m_scratch);
176 testCase->addRequirement(m_scratch);
189 void createAmberTestsFromIndexFile (tcu::TestContext& testCtx, tcu::TestCaseGroup* group, const std::string filename, const char* category)
191 AmberTestCase* testCase = 0;
192 AmberIndexFileParser parser(filename.c_str(), category);
196 testCase = parser.parse(category, testCtx);
199 group->addChild(testCase);
204 AmberTestCase* createAmberTestCase (tcu::TestContext& testCtx,
206 const char* description,
207 const char* category,
208 const std::string& filename,
209 const std::vector<std::string> requirements)
211 // shader_test files are saved in <path>/external/vulkancts/data/vulkan/amber/<categoryname>/
212 std::string readFilename("vulkan/amber/");
213 readFilename.append(category);
214 readFilename.append("/");
215 readFilename.append(filename);
217 AmberTestCase *testCase = new AmberTestCase(testCtx, name, description, readFilename);
219 for (auto req : requirements)
220 testCase->addRequirement(req);