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 Merge two test logs.
23 * \todo [2013-11-08 pyry] Write variant that can operate with less memory.
24 *//*--------------------------------------------------------------------*/
26 #include "xeTestLogParser.hpp"
27 #include "xeTestResultParser.hpp"
28 #include "xeTestLogWriter.hpp"
46 FLAG_USE_LAST_INFO = (1<<0)
56 vector<string> srcFilenames;
61 class LogHandler : public xe::TestLogHandler
64 LogHandler (xe::BatchResult* batchResult, deUint32 flags)
65 : m_batchResult (batchResult)
70 void setSessionInfo (const xe::SessionInfo& info)
72 xe::SessionInfo& combinedInfo = m_batchResult->getSessionInfo();
74 if (m_flags & FLAG_USE_LAST_INFO)
76 if (!info.targetName.empty()) combinedInfo.targetName = info.targetName;
77 if (!info.releaseId.empty()) combinedInfo.releaseId = info.releaseId;
78 if (!info.releaseName.empty()) combinedInfo.releaseName = info.releaseName;
79 if (!info.candyTargetName.empty()) combinedInfo.candyTargetName = info.candyTargetName;
80 if (!info.configName.empty()) combinedInfo.configName = info.configName;
81 if (!info.resultName.empty()) combinedInfo.resultName = info.resultName;
82 if (!info.timestamp.empty()) combinedInfo.timestamp = info.timestamp;
86 if (combinedInfo.targetName.empty()) combinedInfo.targetName = info.targetName;
87 if (combinedInfo.releaseId.empty()) combinedInfo.releaseId = info.releaseId;
88 if (combinedInfo.releaseName.empty()) combinedInfo.releaseName = info.releaseName;
89 if (combinedInfo.candyTargetName.empty()) combinedInfo.candyTargetName = info.candyTargetName;
90 if (combinedInfo.configName.empty()) combinedInfo.configName = info.configName;
91 if (combinedInfo.resultName.empty()) combinedInfo.resultName = info.resultName;
92 if (combinedInfo.timestamp.empty()) combinedInfo.timestamp = info.timestamp;
96 xe::TestCaseResultPtr startTestCaseResult (const char* casePath)
98 if (m_batchResult->hasTestCaseResult(casePath))
100 xe::TestCaseResultPtr existingResult = m_batchResult->getTestCaseResult(casePath);
101 existingResult->clear();
102 return existingResult;
105 return m_batchResult->createTestCaseResult(casePath);
108 void testCaseResultUpdated (const xe::TestCaseResultPtr&)
113 void testCaseResultComplete (const xe::TestCaseResultPtr&)
119 xe::BatchResult* const m_batchResult;
120 const deUint32 m_flags;
123 static void readLogFile (xe::BatchResult* dstResult, const char* filename, deUint32 flags)
125 std::ifstream in (filename, std::ifstream::binary|std::ifstream::in);
126 LogHandler resultHandler (dstResult, flags);
127 xe::TestLogParser parser (&resultHandler);
132 throw std::runtime_error(string("Failed to open '") + filename + "'");
136 in.read((char*)&buf[0], DE_LENGTH_OF_ARRAY(buf));
137 numRead = (int)in.gcount();
142 parser.parse(&buf[0], numRead);
148 static void mergeTestLogs (const CommandLine& cmdLine)
150 xe::BatchResult batchResult;
152 for (vector<string>::const_iterator filename = cmdLine.srcFilenames.begin(); filename != cmdLine.srcFilenames.end(); ++filename)
153 readLogFile(&batchResult, filename->c_str(), cmdLine.flags);
155 if (!cmdLine.dstFilename.empty())
156 xe::writeBatchResultToFile(batchResult, cmdLine.dstFilename.c_str());
158 xe::writeTestLog(batchResult, std::cout);
161 static void printHelp (const char* binName)
163 printf("%s: [filename] [[filename 2] ...]\n", binName);
164 printf(" --dst=[filename] Write final log to file, otherwise written to stdout.\n");
165 printf(" --info=[first|last] Select which session info to use (default: first).\n");
168 static bool parseCommandLine (CommandLine& cmdLine, int argc, const char* const* argv)
170 for (int argNdx = 1; argNdx < argc; argNdx++)
172 const char* arg = argv[argNdx];
174 if (!deStringBeginsWith(arg, "--"))
175 cmdLine.srcFilenames.push_back(arg);
176 else if (deStringBeginsWith(arg, "--dst="))
178 if (!cmdLine.dstFilename.empty())
180 cmdLine.dstFilename = arg+6;
182 else if (deStringEqual(arg, "--info=first"))
183 cmdLine.flags &= ~FLAG_USE_LAST_INFO;
184 else if (deStringEqual(arg, "--info=last"))
185 cmdLine.flags |= FLAG_USE_LAST_INFO;
190 if (cmdLine.srcFilenames.empty())
196 int main (int argc, const char* const* argv)
202 if (!parseCommandLine(cmdLine, argc, argv))
208 mergeTestLogs(cmdLine);
210 catch (const std::exception& e)
212 printf("FATAL ERROR: %s\n", e.what());