1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Test Executor
3 * ------------------------------------------
5 * Copyright 2014 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Extract sample lists from logs.
22 *//*--------------------------------------------------------------------*/
24 #include "xeTestLogParser.hpp"
25 #include "xeTestResultParser.hpp"
26 #include "deFilePath.hpp"
28 #include "deStringUtil.hpp"
43 void writeSampleList (const char* casePath, int listNdx, const xe::ri::SampleList& sampleList)
45 const string filename = string(casePath) + "." + de::toString(listNdx) + ".csv";
46 std::ofstream out (filename.c_str(), std::ios_base::binary);
49 throw std::runtime_error("Failed to open " + filename);
52 for (int ndx = 0; ndx < sampleList.sampleInfo.valueInfos.getNumItems(); ndx++)
56 out << static_cast<const xe::ri::ValueInfo&>(sampleList.sampleInfo.valueInfos.getItem(ndx)).name;
61 for (int sampleNdx = 0; sampleNdx < sampleList.samples.getNumItems(); sampleNdx++)
63 const xe::ri::Sample& sample = static_cast<const xe::ri::Sample&>(sampleList.samples.getItem(sampleNdx));
65 for (int valNdx = 0; valNdx < sample.values.getNumItems(); valNdx++)
67 const xe::ri::SampleValue& value = static_cast<const xe::ri::SampleValue&>(sample.values.getItem(valNdx));
78 void extractSampleLists (const char* casePath, int* listNdx, const xe::ri::List& items)
80 for (int itemNdx = 0; itemNdx < items.getNumItems(); itemNdx++)
82 const xe::ri::Item& child = items.getItem(itemNdx);
84 if (child.getType() == xe::ri::TYPE_SECTION)
85 extractSampleLists(casePath, listNdx, static_cast<const xe::ri::Section&>(child).items);
86 else if (child.getType() == xe::ri::TYPE_SAMPLELIST)
88 writeSampleList(casePath, *listNdx, static_cast<const xe::ri::SampleList&>(child));
94 void extractSampleLists (const xe::TestCaseResult& result)
97 extractSampleLists(result.casePath.c_str(), &listNdx, result.resultItems);
100 class SampleListParser : public xe::TestLogHandler
103 SampleListParser (void)
107 void setSessionInfo (const xe::SessionInfo&)
112 xe::TestCaseResultPtr startTestCaseResult (const char* casePath)
114 return xe::TestCaseResultPtr(new xe::TestCaseResultData(casePath));
117 void testCaseResultUpdated (const xe::TestCaseResultPtr&)
122 void testCaseResultComplete (const xe::TestCaseResultPtr& caseData)
124 xe::TestCaseResult result;
125 xe::parseTestCaseResultFromData(&m_testResultParser, &result, *caseData.get());
126 extractSampleLists(result);
130 xe::TestResultParser m_testResultParser;
133 static void processLogFile (const char* filename)
135 std::ifstream in (filename, std::ifstream::binary|std::ifstream::in);
136 SampleListParser resultHandler;
137 xe::TestLogParser parser (&resultHandler);
142 throw std::runtime_error(string("Failed to open '") + filename + "'");
146 in.read((char*)&buf[0], DE_LENGTH_OF_ARRAY(buf));
147 numRead = (int)in.gcount();
152 parser.parse(&buf[0], numRead);
158 int main (int argc, const char* const* argv)
162 printf("%s: [filename]\n", de::FilePath(argv[0]).getBaseName().c_str());
168 processLogFile(argv[1]);
170 catch (const std::exception& e)
172 printf("FATAL ERROR: %s\n", e.what());