huangcm
2025-02-24 69ed55dec4b2116a19e4cca4393cbc014fce5fb2
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
/*-------------------------------------------------------------------------
 * 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 Extract sample lists from logs.
 *//*--------------------------------------------------------------------*/
 
#include "xeTestLogParser.hpp"
#include "xeTestResultParser.hpp"
#include "deFilePath.hpp"
#include "deString.h"
#include "deStringUtil.hpp"
 
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <stdexcept>
 
using std::vector;
using std::string;
using std::set;
using std::map;
 
void writeSampleList (const char* casePath, int listNdx, const xe::ri::SampleList& sampleList)
{
   const string    filename    = string(casePath) + "." + de::toString(listNdx) + ".csv";
   std::ofstream    out            (filename.c_str(), std::ios_base::binary);
 
   if (!out.good())
       throw std::runtime_error("Failed to open " + filename);
 
   // Header
   for (int ndx = 0; ndx < sampleList.sampleInfo.valueInfos.getNumItems(); ndx++)
   {
       if (ndx != 0)
           out << ",";
       out << static_cast<const xe::ri::ValueInfo&>(sampleList.sampleInfo.valueInfos.getItem(ndx)).name;
   }
   out << "\n";
 
   // Samples
   for (int sampleNdx = 0; sampleNdx < sampleList.samples.getNumItems(); sampleNdx++)
   {
       const xe::ri::Sample&    sample    = static_cast<const xe::ri::Sample&>(sampleList.samples.getItem(sampleNdx));
 
       for (int valNdx = 0; valNdx < sample.values.getNumItems(); valNdx++)
       {
           const xe::ri::SampleValue&    value    = static_cast<const xe::ri::SampleValue&>(sample.values.getItem(valNdx));
 
           if (valNdx != 0)
               out << ",";
 
           out << value.value;
       }
       out << "\n";
   }
}
 
void extractSampleLists (const char* casePath, int* listNdx, const xe::ri::List& items)
{
   for (int itemNdx = 0; itemNdx < items.getNumItems(); itemNdx++)
   {
       const xe::ri::Item& child = items.getItem(itemNdx);
 
       if (child.getType() == xe::ri::TYPE_SECTION)
           extractSampleLists(casePath, listNdx, static_cast<const xe::ri::Section&>(child).items);
       else if (child.getType() == xe::ri::TYPE_SAMPLELIST)
       {
           writeSampleList(casePath, *listNdx, static_cast<const xe::ri::SampleList&>(child));
           *listNdx += 1;
       }
   }
}
 
void extractSampleLists (const xe::TestCaseResult& result)
{
   int listNdx = 0;
   extractSampleLists(result.casePath.c_str(), &listNdx, result.resultItems);
}
 
class SampleListParser : public xe::TestLogHandler
{
public:
   SampleListParser (void)
   {
   }
 
   void setSessionInfo (const xe::SessionInfo&)
   {
       // Ignored.
   }
 
   xe::TestCaseResultPtr startTestCaseResult (const char* casePath)
   {
       return xe::TestCaseResultPtr(new xe::TestCaseResultData(casePath));
   }
 
   void testCaseResultUpdated (const xe::TestCaseResultPtr&)
   {
       // Ignored.
   }
 
   void testCaseResultComplete (const xe::TestCaseResultPtr& caseData)
   {
       xe::TestCaseResult result;
       xe::parseTestCaseResultFromData(&m_testResultParser, &result, *caseData.get());
       extractSampleLists(result);
   }
 
private:
   xe::TestResultParser    m_testResultParser;
};
 
static void processLogFile (const char* filename)
{
   std::ifstream        in                (filename, std::ifstream::binary|std::ifstream::in);
   SampleListParser    resultHandler;
   xe::TestLogParser    parser            (&resultHandler);
   deUint8                buf                [1024];
   int                    numRead            = 0;
 
   if (!in.good())
       throw std::runtime_error(string("Failed to open '") + filename + "'");
 
   for (;;)
   {
       in.read((char*)&buf[0], DE_LENGTH_OF_ARRAY(buf));
       numRead = (int)in.gcount();
 
       if (numRead <= 0)
           break;
 
       parser.parse(&buf[0], numRead);
   }
 
   in.close();
}
 
int main (int argc, const char* const* argv)
{
   if (argc != 2)
   {
       printf("%s: [filename]\n", de::FilePath(argv[0]).getBaseName().c_str());
       return -1;
   }
 
   try
   {
       processLogFile(argv[1]);
   }
   catch (const std::exception& e)
   {
       printf("FATAL ERROR: %s\n", e.what());
       return -1;
   }
 
   return 0;
}