Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: test/mjsunit/tools/tickprocessor.js

Issue 149195: Add automatic tests for Tick Processor. (Closed)
Patch Set: Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/mjsunit/tools/tickprocessor-test.default » ('j') | tools/tickprocessor.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 // Load implementations from <project root>/tools.
29 // Files: tools/splaytree.js tools/codemap.js tools/csvparser.js tools/consarray .js tools/profile.js tools/profile_view.js tools/logreader.js tools/tickprocesso r.js
Erik Corry 2009/07/07 11:15:32 Over-long line.
Mikhail Naganov 2009/07/07 12:08:10 This is an instruction to testcfg.py script to loa
30
31 (function testArgumentsProcessor() {
32 var p_default = new ArgumentsProcessor([]);
33 assertTrue(p_default.parse());
34 assertEquals(ArgumentsProcessor.DEFAULTS, p_default.result());
35
36 var p_logFile = new ArgumentsProcessor(['logfile.log']);
37 assertTrue(p_logFile.parse());
38 assertEquals('logfile.log', p_logFile.result().logFileName);
39
40 var p_platformAndLog = new ArgumentsProcessor(['--windows', 'winlog.log']);
41 assertTrue(p_platformAndLog.parse());
42 assertEquals('windows', p_platformAndLog.result().platform);
43 assertEquals('winlog.log', p_platformAndLog.result().logFileName);
44
45 var p_flags = new ArgumentsProcessor(['--gc', '--separate-ic']);
46 assertTrue(p_flags.parse());
47 assertEquals(TickProcessor.VmStates.GC, p_flags.result().stateFilter);
48 assertTrue(p_flags.result().separateIc);
49
50 var p_nmAndLog = new ArgumentsProcessor(['--nm=mn', 'nmlog.log']);
51 assertTrue(p_nmAndLog.parse());
52 assertEquals('mn', p_nmAndLog.result().nm);
53 assertEquals('nmlog.log', p_nmAndLog.result().logFileName);
54
55 var p_bad = new ArgumentsProcessor(['--unknown', 'badlog.log']);
56 assertFalse(p_bad.parse());
57 })();
58
59
60 (function testUnixCppEntriesProvider() {
61 var oldLoadSymbols = UnixCppEntriesProvider.prototype.loadSymbols;
62
63 // shell executable
64 UnixCppEntriesProvider.prototype.loadSymbols = function(libName) {
65 this.symbols = [[
66 ' U operator delete[](void*)@@GLIBCXX_3.4',
67 '08049790 T _init',
68 '08049f50 T _start',
69 '08139150 t v8::internal::Runtime_StringReplaceRegExpWithString(v8::intern al::Arguments)',
70 '08139ca0 T v8::internal::Runtime::GetElementOrCharAt(v8::internal::Handle <v8::internal::Object>, unsigned int)',
71 '0813a0b0 t v8::internal::Runtime_DebugGetPropertyDetails(v8::internal::Ar guments)',
72 '08181d30 W v8::internal::RegExpMacroAssemblerIrregexp::stack_limit_slack( )',
73 ' w __gmon_start__',
74 '081f08a0 B stdout'
75 ].join('\n'), ''];
76 };
77
78 var shell_prov = new UnixCppEntriesProvider();
79 var shell_syms = [];
80 shell_prov.parseVmSymbols('shell', 0x08048000, 0x081ee000,
81 function (name, start, end) {
82 shell_syms.push(Array.prototype.slice.apply(arguments, [0]));
83 });
84 assertEquals(
85 [['_init', 0x08049790, 0x08049f50],
86 ['_start', 0x08049f50, 0x08139150],
87 ['v8::internal::Runtime_StringReplaceRegExpWithString(v8::internal::Argum ents)', 0x08139150, 0x08139ca0],
88 ['v8::internal::Runtime::GetElementOrCharAt(v8::internal::Handle<v8::inte rnal::Object>, unsigned int)', 0x08139ca0, 0x0813a0b0],
89 ['v8::internal::Runtime_DebugGetPropertyDetails(v8::internal::Arguments)' , 0x0813a0b0, 0x08181d30],
90 ['v8::internal::RegExpMacroAssemblerIrregexp::stack_limit_slack()', 0x081 81d30, 0x081ee000]],
91 shell_syms);
92
93 // libc library
94 UnixCppEntriesProvider.prototype.loadSymbols = function(libName) {
95 this.symbols = [[
96 '000162a0 T __libc_init_first',
97 '0002a5f0 T __isnan',
98 '0002a5f0 W isnan',
99 '0002aaa0 W scalblnf',
100 '0002aaa0 W scalbnf',
101 '0011a340 T __libc_thread_freeres',
102 '00128860 R _itoa_lower_digits'].join('\n'), ''];
103 };
104 var libc_prov = new UnixCppEntriesProvider();
105 var libc_syms = [];
106 libc_prov.parseVmSymbols('libc', 0xf7c5c000, 0xf7da5000,
107 function (name, start, end) {
108 libc_syms.push(Array.prototype.slice.apply(arguments, [0]));
109 });
110 assertEquals(
111 [['__libc_init_first', 0xf7c5c000 + 0x000162a0, 0xf7c5c000 + 0x0002a5f0],
112 ['isnan', 0xf7c5c000 + 0x0002a5f0, 0xf7c5c000 + 0x0002aaa0],
113 ['scalbnf', 0xf7c5c000 + 0x0002aaa0, 0xf7c5c000 + 0x0011a340],
114 ['__libc_thread_freeres', 0xf7c5c000 + 0x0011a340, 0xf7da5000]],
115 libc_syms);
116
117 UnixCppEntriesProvider.prototype.loadSymbols = oldLoadSymbols;
118 })();
119
120
121 (function testWindowsCppEntriesProvider() {
122 var oldLoadSymbols = WindowsCppEntriesProvider.prototype.loadSymbols;
123
124 WindowsCppEntriesProvider.prototype.loadSymbols = function(libName) {
125 this.symbols = [
126 ' Start Length Name Class',
127 ' 0001:00000000 000ac902H .text CODE',
128 ' 0001:000ac910 000005e2H .text$yc CODE',
129 ' Address Publics by Value Rva+Base Lib:Object ',
130 ' 0000:00000000 __except_list 00000000 <absolute>',
131 ' 0001:00000000 ?ReadFile@@YA?AV?$Handle@VString@v8@@@v8@@PBD@Z 0040 1000 f shell.obj',
132 ' 0001:000000a0 ?Print@@YA?AV?$Handle@VValue@v8@@@v8@@ABVArguments@2 @@Z 004010a0 f shell.obj',
133 ' 0001:00001230 ??1UTF8Buffer@internal@v8@@QAE@XZ 00402230 f v8_sn apshot:scanner.obj',
134 ' 0001:00001230 ??1Utf8Value@String@v8@@QAE@XZ 00402230 f v8_snaps hot:api.obj',
135 ' 0001:000954ba __fclose_nolock 004964ba f LIBCMT:fclos e.obj',
136 ' 0002:00000000 __imp__SetThreadPriority@8 004af000 kernel32:KER NEL32.dll',
137 ' 0003:00000418 ?in_use_list_@PreallocatedStorage@internal@v8@@0V123 @A 00544418 v8_snapshot:allocation.obj',
138 ' Static symbols',
139 ' 0001:00000b70 ?DefaultFatalErrorHandler@v8@@YAXPBD0@Z 00401b70 f v8_snapshot:api.obj',
140 ' 0001:000010b0 ?EnsureInitialized@v8@@YAXPBD@Z 004020b0 f v8_snap shot:api.obj',
141 ' 0001:000ad17b ??__Fnomem@?5???2@YAPAXI@Z@YAXXZ 004ae17b f LIBCMT :new.obj'
142 ].join('\r\n');
143 };
144 var shell_prov = new WindowsCppEntriesProvider();
145 var shell_syms = [];
146 shell_prov.parseVmSymbols('shell.exe', 0x00400000, 0x0057c000,
147 function (name, start, end) {
148 shell_syms.push(Array.prototype.slice.apply(arguments, [0]));
149 });
150 assertEquals(
151 [['ReadFile', 0x00401000, 0x004010a0],
152 ['Print', 0x004010a0, 0x00402230],
153 ['v8::String::?1Utf8Value', 0x00402230, 0x004964ba],
154 ['v8::DefaultFatalErrorHandler', 0x00401b70, 0x004020b0],
155 ['v8::EnsureInitialized', 0x004020b0, 0x0057c000]],
156 shell_syms);
157
158 WindowsCppEntriesProvider.prototype.loadSymbols = oldLoadSymbols;
159 })();
160
161
162 function CppEntriesProviderMock() {
163 };
164
165
166 CppEntriesProviderMock.prototype.parseVmSymbols = function(
167 name, startAddr, endAddr, symbolAdder) {
168 var symbols = {
169 'shell':
170 [['v8::internal::JSObject::LocalLookupRealNamedProperty(v8::internal::St ring*, v8::internal::LookupResult*)', 0x080f8800, 0x080f8d90],
171 ['v8::internal::HashTable<v8::internal::StringDictionaryShape, v8::inte rnal::String*>::FindEntry(v8::internal::String*)', 0x080f8210, 0x080f8800],
172 ['v8::internal::Runtime_Math_exp(v8::internal::Arguments)', 0x08123b20, 0x08123b80]],
173 '/lib32/libm-2.7.so':
174 [['exp', startAddr + 0x00009e80, startAddr + 0x00009f30],
175 ['fegetexcept', startAddr + 0x000061e0, startAddr + 0x00008b10]],
176 'ffffe000-fffff000': []};
177 assertTrue(name in symbols);
178 var syms = symbols[name];
179 for (var i = 0; i < syms.length; ++i) {
180 symbolAdder.apply(null, syms[i]);
181 }
182 };
183
184
185 function PrintMonitor(outputOrFileName) {
186 var expectedOut = typeof outputOrFileName == 'string' ?
187 this.loadExpectedOutput(outputOrFileName) : outputOrFileName;
188 var outputPos = 0;
189 var diffs = this.diffs = [];
190 var realOut = this.realOut = [];
191
192 this.oldPrint = print;
193 print = function(str) {
194 var strSplit = str.split('\n');
195 for (var i = 0; i < strSplit.length; ++i) {
196 s = strSplit[i];
197 realOut.push(s);
198 assertTrue(outputPos < expectedOut.length,
199 'unexpected output: "' + s + '"');
200 if (expectedOut[outputPos] != s) {
201 diffs.push('line ' + outputPos + ': expected <' +
202 expectedOut[outputPos] + '> found <' + s + '>\n');
203 }
204 outputPos++;
205 }
206 };
207 };
208
209
210 PrintMonitor.prototype.loadExpectedOutput = function(fileName) {
211 var output = readFile(fileName);
212 return output.split('\n');
213 };
214
215
216 PrintMonitor.prototype.finish = function() {
217 print = this.oldPrint;
218 if (this.diffs.length > 0) {
219 print(this.realOut.join('\n'));
220 assertEquals([], this.diffs);
221 }
222 };
223
224
225 function driveTickProcessorTest(
226 separateIc, ignoreUnknown, stateFilter, logInput, refOutput) {
227 var TEST_PATH = 'test/mjsunit/tools/';
228 var tp = new TickProcessor(
229 new CppEntriesProviderMock(), separateIc, ignoreUnknown, stateFilter);
230 var pm = new PrintMonitor(TEST_PATH + refOutput);
231 tp.processLogFile(TEST_PATH + logInput);
232 // Hack file name to avoid dealing with platform specifics.
233 tp.lastLogFileName_ = 'v8.log';
234 tp.printStatistics();
235 pm.finish();
236 };
237
238
239 (function testProcessing() {
240 var testData = {
241 'Default': [
242 false, false, null,
243 'tickprocessor-test.log', 'tickprocessor-test.default'],
244 'SeparateIc': [
245 true, false, null,
246 'tickprocessor-test.log', 'tickprocessor-test.separate-ic'],
247 'IgnoreUnknown': [
248 false, true, null,
249 'tickprocessor-test.log', 'tickprocessor-test.ignore-unknown'],
250 'GcState': [
251 false, false, TickProcessor.VmStates.GC,
252 'tickprocessor-test.log', 'tickprocessor-test.gc-state']
253 };
254 for (var testName in testData) {
255 print('=== testProcessing-' + testName + ' ===');
256 driveTickProcessorTest.apply(null, testData[testName]);
257 }
258 })();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/tools/tickprocessor-test.default » ('j') | tools/tickprocessor.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698