|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Main application class |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <stdio.h> |
|
20 #include <algorithm> |
|
21 #include <functional> |
|
22 #include <iostream.h> |
|
23 #include <fstream> |
|
24 #include <memory> |
|
25 |
|
26 #include "idxutil.h" |
|
27 #include "itk.h" |
|
28 #include "corpustester.h" |
|
29 |
|
30 #include "testvector.h" |
|
31 |
|
32 // This is a GCCE toolchain workaround needed when compiling with GCCE |
|
33 // and using main() entry point |
|
34 #ifdef __GCCE__ |
|
35 #include <staticlibinit_gcce.h> |
|
36 #endif |
|
37 |
|
38 /* OBS |
|
39 TestVector testVectors[] = { |
|
40 { "plain", 0, 60000, 5000, 100, 100, SOME_QUERY_TERMS, 5, 5}, |
|
41 // { "plain", 0, 120000, 15000, 100, 100, SOME_QUERY_TERMS, 1, 0}, |
|
42 // { "plain", 0, 30000, 5000, 100, 100, SOME_QUERY_TERMS, 5, 5}, |
|
43 // ORIGINAL { "plain", 0, 30, 5, 2, 2, SOME_QUERY_TERMS, 5, 5}, |
|
44 |
|
45 // penalty due to search - write state switch |
|
46 { "swA", 30000, 20, 20, 0, 0, SOME_QUERY_TERMS, 20, 0}, |
|
47 { "swB", 30000, 20, 1, 0, 0, SOME_QUERY_TERMS, 1, 0}, |
|
48 |
|
49 // penalty due to write - delete state switch |
|
50 { "wdA", 30000, 20, 20, 0, 20, EMPTY_QUERY_TERMS, 0, 0}, |
|
51 { "wdB", 30000, 20, 1, 0, 1, EMPTY_QUERY_TERMS, 0, 0}, |
|
52 |
|
53 // sys performance |
|
54 { "sys", 0, 2001, 100, 10, 10, SOME_QUERY_TERMS, 5, 5} |
|
55 }; |
|
56 */ |
|
57 |
|
58 |
|
59 #define BASEDIR "c:\\data\\perfmetrics\\" |
|
60 |
|
61 #define TESTVECTOR "c:\\data\\perfmetrics\\testvector.txt" |
|
62 |
|
63 |
|
64 extern const char BaseDir[] = BASEDIR; |
|
65 |
|
66 |
|
67 // |
|
68 // Install util/hugetestcorpus/....sis ! |
|
69 // |
|
70 // There is no install package for pois.txt: you have to use one POI |
|
71 // dump file and copy it manually to the right directory |
|
72 // |
|
73 |
|
74 #ifdef __WINS__ |
|
75 const char TEST_CORPUS_FILE[] = "c:\\data\\perfmetricscorpus\\hugetestcorpus.txt"; |
|
76 const char POI_CORPUS_FILE[] = "c:\\data\\perfmetricscorpus\\pois.txt"; |
|
77 const char STREET_CORPUS_FILE[] = "c:\\data\\perfmetricscorpus\\streets.csv"; |
|
78 #else |
|
79 const char TEST_CORPUS_FILE[] = "e:\\data\\perfmetricscorpus\\hugetestcorpus.txt"; |
|
80 const char POI_CORPUS_FILE[] = "e:\\data\\perfmetricscorpus\\pois.txt"; |
|
81 const char STREET_CORPUS_FILE[] = "e:\\data\\perfmetricscorpus\\streets.csv"; |
|
82 #endif |
|
83 |
|
84 class TestVectorContext : public Itk::ITestContext |
|
85 { |
|
86 TestVector tv_; |
|
87 CorpusTester * corpusTester_; |
|
88 IdxUtil * idxUtil_; |
|
89 |
|
90 public: |
|
91 |
|
92 TestVectorContext(const TestVector & testVector) |
|
93 : tv_(testVector), |
|
94 corpusTester_(NULL), |
|
95 idxUtil_(NULL) |
|
96 { |
|
97 ; |
|
98 } |
|
99 |
|
100 |
|
101 virtual void setup() throw (Itk::PanicExc) |
|
102 { |
|
103 using namespace std; |
|
104 |
|
105 /* OBS |
|
106 bool |
|
107 poi = (tv_.testName == "poi"); |
|
108 const char |
|
109 * corpusPath = poi ? POI_CORPUS_FILE : TEST_CORPUS_FILE; |
|
110 */ |
|
111 try |
|
112 { |
|
113 const char |
|
114 * corpusPath = NULL; |
|
115 auto_ptr<IdxUtil> |
|
116 iu; |
|
117 |
|
118 if (tv_.testName == "plain") |
|
119 { |
|
120 corpusPath = TEST_CORPUS_FILE; |
|
121 iu.reset(new IdxUtil()); |
|
122 } |
|
123 else if (tv_.testName == "poi") |
|
124 { |
|
125 corpusPath = POI_CORPUS_FILE; |
|
126 iu.reset(new PoiIdxUtil()); |
|
127 } |
|
128 else if (tv_.testName == "street") |
|
129 { |
|
130 corpusPath = STREET_CORPUS_FILE; |
|
131 iu.reset(new StreetIdxUtil()); |
|
132 } |
|
133 |
|
134 iu->init(static_cast<bool>(tv_.create)); |
|
135 cpix_IdxDb_setMaxInsertBufSize( iu->idxDb(), |
|
136 tv_.bufferSize ); |
|
137 |
|
138 auto_ptr<CorpusTester> |
|
139 ct(new CorpusTester(corpusPath, |
|
140 tv_.numPreindexedItems, |
|
141 tv_.testName, |
|
142 tv_.bufferSize, |
|
143 tv_.maxInputSize, |
|
144 tv_.lumpSize, |
|
145 tv_.first, |
|
146 tv_.last, |
|
147 tv_.queryTerms, |
|
148 tv_.search, |
|
149 tv_.incrementalSearch, |
|
150 tv_.minIncrementalLength, |
|
151 tv_.suggestionSearch, |
|
152 tv_.minSuggestionLength, |
|
153 tv_.takeIdxSnapshot, |
|
154 tv_.addLasts, |
|
155 tv_.delReAddLasts, |
|
156 tv_.updateLasts)); |
|
157 /* OBS |
|
158 auto_ptr<IdxUtil> |
|
159 iu(poi ? new PoiIdxUtil() : new IdxUtil()); |
|
160 iu->init(static_cast<bool>(tv_.create)); |
|
161 */ |
|
162 |
|
163 corpusTester_ = ct.get(); |
|
164 ct.release(); |
|
165 |
|
166 idxUtil_ = iu.get(); |
|
167 iu.release(); |
|
168 } |
|
169 catch (std::exception & exc) |
|
170 { |
|
171 ITK_PANIC("Cant' initialize corpus tester for %s: %s", |
|
172 tv_.testName.c_str(), |
|
173 exc.what()); |
|
174 } |
|
175 catch (...) |
|
176 { |
|
177 ITK_PANIC("Can't initialize corpus tester for %s: unknown reason.", |
|
178 tv_.testName.c_str()); |
|
179 } |
|
180 } |
|
181 |
|
182 |
|
183 virtual void tearDown() throw() |
|
184 { |
|
185 cleanup(); |
|
186 } |
|
187 |
|
188 |
|
189 virtual ~TestVectorContext() |
|
190 { |
|
191 cleanup(); |
|
192 } |
|
193 |
|
194 |
|
195 void measure(Itk::TestMgr * testMgr) |
|
196 { |
|
197 corpusTester_->run(testMgr, |
|
198 idxUtil_); |
|
199 } |
|
200 |
|
201 |
|
202 private: |
|
203 void cleanup() throw() |
|
204 { |
|
205 delete corpusTester_; |
|
206 corpusTester_ = NULL; |
|
207 |
|
208 delete idxUtil_; |
|
209 idxUtil_ = NULL; |
|
210 } |
|
211 }; |
|
212 |
|
213 |
|
214 Itk::TesterBase * CreateTestHierarchy() |
|
215 { |
|
216 using namespace Itk; |
|
217 |
|
218 // "all" |
|
219 SuiteTester |
|
220 * all = new SuiteTester("all"); |
|
221 |
|
222 std::ifstream |
|
223 ifs(TESTVECTOR); |
|
224 TestVector |
|
225 tv; |
|
226 ifs >> tv; |
|
227 |
|
228 TestVectorContext |
|
229 * tvc = new TestVectorContext(tv); |
|
230 ContextTester |
|
231 * contextTester = new ContextTester(tv.testName.c_str(), |
|
232 tvc); |
|
233 contextTester->add("measure", |
|
234 tvc, |
|
235 &TestVectorContext::measure); |
|
236 |
|
237 all->add(contextTester); |
|
238 |
|
239 return all; |
|
240 } |
|
241 |
|
242 |
|
243 |
|
244 void initBaseDir(const char * path) |
|
245 { |
|
246 if (!Cpt::directoryexists(path)) |
|
247 { |
|
248 if (Cpt::mkdirs(path, 0777) != 0) |
|
249 { |
|
250 printf("Could not create base directory: %s\n", |
|
251 path); |
|
252 exit(2); |
|
253 } |
|
254 } |
|
255 } |
|
256 |
|
257 |
|
258 |
|
259 void checkCorpus(const char * path) |
|
260 { |
|
261 if (!Cpt::isreadable(path)) |
|
262 { |
|
263 printf("Could not open test corpus for reading: %s\n", |
|
264 path); |
|
265 exit(2); |
|
266 } |
|
267 } |
|
268 |
|
269 |
|
270 |
|
271 int main(int , |
|
272 const char * ) |
|
273 { |
|
274 using namespace std; |
|
275 |
|
276 int |
|
277 rv = 0; |
|
278 |
|
279 cpix_Result |
|
280 result; |
|
281 cpix_init(&result, |
|
282 NULL); |
|
283 if (cpix_Failed(&result)) |
|
284 { |
|
285 wchar_t |
|
286 buffer[128]; |
|
287 cpix_Error_report(result.err_, |
|
288 buffer, |
|
289 sizeof(buffer)/sizeof(wchar_t)); |
|
290 printf("Failed to initialize CPix: %S\n", buffer); |
|
291 return -1; |
|
292 } |
|
293 |
|
294 std::auto_ptr<Itk::TesterBase> |
|
295 testCase(CreateTestHierarchy()); |
|
296 |
|
297 string |
|
298 cmd("all"); |
|
299 |
|
300 initBaseDir(BASEDIR); |
|
301 checkCorpus(TEST_CORPUS_FILE); |
|
302 |
|
303 bool |
|
304 help = false; |
|
305 const char |
|
306 * focus = NULL; |
|
307 string |
|
308 outPath(BASEDIR); |
|
309 |
|
310 if (cmd == "h") |
|
311 { |
|
312 help = true; |
|
313 outPath += "help.txt"; |
|
314 } |
|
315 else |
|
316 { |
|
317 focus = cmd.c_str(); |
|
318 outPath += focus; |
|
319 outPath += ".txt"; |
|
320 } |
|
321 |
|
322 ofstream |
|
323 ofs(outPath.c_str()); |
|
324 |
|
325 if (help) |
|
326 { |
|
327 std::cout << "Test hierarchy:" << endl; |
|
328 testCase->printHierarchy(std::cout); |
|
329 |
|
330 if (ofs) |
|
331 { |
|
332 ofs << "Test hierarchy:" << endl; |
|
333 testCase->printHierarchy(ofs); |
|
334 } |
|
335 } |
|
336 else |
|
337 { |
|
338 auto_ptr<Itk::CompositeTestRunObserver> |
|
339 observer(new Itk::CompositeTestRunObserver()); |
|
340 observer->add(new Itk::TestRunConsole(std::cout)); |
|
341 |
|
342 // do this only if you need a way to confirm that the |
|
343 // process is running on the phone without proper std IO |
|
344 // console |
|
345 // observer->add(new Itk::ProgressFsDisplayer()); |
|
346 |
|
347 // this observer will dump every event to a file, so it |
|
348 // slows down everything, but when things crash, at least |
|
349 // you get partial results on the file system |
|
350 observer->add(new Itk::ProgressDumper(BASEDIR "dump.txt")); |
|
351 |
|
352 Itk::TestMgr |
|
353 testMgr(observer.get(), |
|
354 BASEDIR); |
|
355 |
|
356 rv = testMgr.run(testCase.get(), focus); |
|
357 |
|
358 // TMP DISABLED testMgr.generateSummary(std::cout); |
|
359 |
|
360 if (ofs) |
|
361 { |
|
362 testMgr.generateSummary(ofs); |
|
363 } |
|
364 } |
|
365 |
|
366 // OBS int c = getchar(); |
|
367 return rv; |
|
368 } |
|
369 |