-
Notifications
You must be signed in to change notification settings - Fork 303
/
Copy pathxeTestLogParser.cpp
187 lines (157 loc) · 6.04 KB
/
xeTestLogParser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*-------------------------------------------------------------------------
* drawElements Quality Program Test Executor
* ------------------------------------------
*
* Copyright 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*//*!
* \file
* \brief Test log parser.
*//*--------------------------------------------------------------------*/
#include "xeTestLogParser.hpp"
#include "deString.h"
using std::map;
using std::string;
using std::vector;
namespace xe
{
TestLogParser::TestLogParser(TestLogHandler *handler) : m_handler(handler), m_inSession(false)
{
}
TestLogParser::~TestLogParser(void)
{
}
void TestLogParser::reset(void)
{
m_containerParser.clear();
m_currentCaseData.clear();
m_sessionInfo = SessionInfo();
m_inSession = false;
}
void TestLogParser::parse(const uint8_t *bytes, size_t numBytes)
{
m_containerParser.feed(bytes, numBytes);
for (;;)
{
ContainerElement element = m_containerParser.getElement();
if (element == CONTAINERELEMENT_INCOMPLETE)
break;
switch (element)
{
case CONTAINERELEMENT_BEGIN_SESSION:
{
if (m_inSession)
throw Error("Unexpected #beginSession");
m_handler->setSessionInfo(m_sessionInfo);
m_inSession = true;
break;
}
case CONTAINERELEMENT_END_SESSION:
{
if (!m_inSession)
throw Error("Unexpected #endSession");
m_inSession = false;
break;
}
case CONTAINERELEMENT_SESSION_INFO:
{
if (m_inSession)
throw Error("Unexpected #sessionInfo");
const char *attribute = m_containerParser.getSessionInfoAttribute();
const char *value = m_containerParser.getSessionInfoValue();
if (strcmp(attribute, "releaseName") == 0)
m_sessionInfo.releaseName = value;
else if (strcmp(attribute, "releaseId") == 0)
m_sessionInfo.releaseId = value;
else if (strcmp(attribute, "targetName") == 0)
m_sessionInfo.targetName = value;
else if (strcmp(attribute, "candyTargetName") == 0)
m_sessionInfo.candyTargetName = value;
else if (strcmp(attribute, "configName") == 0)
m_sessionInfo.configName = value;
else if (strcmp(attribute, "resultName") == 0)
m_sessionInfo.resultName = value;
else if (strcmp(attribute, "timestamp") == 0)
m_sessionInfo.timestamp = value;
else if (strcmp(attribute, "commandLineParameters") == 0)
m_sessionInfo.qpaCommandLineParameters = value;
// \todo [2012-06-09 pyry] What to do with unknown/duplicate attributes? Currently just ignored.
break;
}
case CONTAINERELEMENT_BEGIN_TEST_CASE_RESULT:
{
if (!m_inSession)
throw Error("Unexpected #beginTestCaseResult");
const char *casePath = m_containerParser.getTestCasePath();
m_currentCaseData = m_handler->startTestCaseResult(casePath);
// Clear and set to running state.
m_currentCaseData->setDataSize(0);
m_currentCaseData->setTestResult(TESTSTATUSCODE_RUNNING, "Running");
m_handler->testCaseResultUpdated(m_currentCaseData);
break;
}
case CONTAINERELEMENT_END_TEST_CASE_RESULT:
if (m_currentCaseData)
{
// \todo [2012-06-16 pyry] Parse status code already here?
m_currentCaseData->setTestResult(TESTSTATUSCODE_LAST, "");
m_handler->testCaseResultComplete(m_currentCaseData);
}
m_currentCaseData.clear();
break;
case CONTAINERELEMENT_TERMINATE_TEST_CASE_RESULT:
if (m_currentCaseData)
{
TestStatusCode statusCode = TESTSTATUSCODE_CRASH;
const char *reason = m_containerParser.getTerminateReason();
try
{
statusCode = getTestStatusCode(reason);
}
catch (const xe::ParseError &)
{
// Could not map status code.
}
m_currentCaseData->setTestResult(statusCode, reason);
m_handler->testCaseResultComplete(m_currentCaseData);
}
m_currentCaseData.clear();
break;
case CONTAINERELEMENT_END_OF_STRING:
if (m_currentCaseData)
{
// Terminate current case.
m_currentCaseData->setTestResult(TESTSTATUSCODE_TERMINATED, "Unexpected end of string");
m_handler->testCaseResultComplete(m_currentCaseData);
}
m_currentCaseData.clear();
break;
case CONTAINERELEMENT_TEST_LOG_DATA:
if (m_currentCaseData)
{
int offset = m_currentCaseData->getDataSize();
int numDataBytes = m_containerParser.getDataSize();
m_currentCaseData->setDataSize(offset + numDataBytes);
m_containerParser.getData(m_currentCaseData->getData() + offset, numDataBytes, 0);
m_handler->testCaseResultUpdated(m_currentCaseData);
}
break;
default:
throw ContainerParseError("Unknown container element");
}
m_containerParser.advance();
}
}
} // namespace xe