| Index: test/mjsunit/tools/codemap.js
|
| diff --git a/test/mjsunit/tools/codemap.js b/test/mjsunit/tools/codemap.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7f344a65fabdb484a7133df084750963e2edcbac
|
| --- /dev/null
|
| +++ b/test/mjsunit/tools/codemap.js
|
| @@ -0,0 +1,116 @@
|
| +// Copyright 2009 the V8 project authors. All rights reserved.
|
| +// Redistribution and use in source and binary forms, with or without
|
| +// modification, are permitted provided that the following conditions are
|
| +// met:
|
| +//
|
| +// * Redistributions of source code must retain the above copyright
|
| +// notice, this list of conditions and the following disclaimer.
|
| +// * Redistributions in binary form must reproduce the above
|
| +// copyright notice, this list of conditions and the following
|
| +// disclaimer in the documentation and/or other materials provided
|
| +// with the distribution.
|
| +// * Neither the name of Google Inc. nor the names of its
|
| +// contributors may be used to endorse or promote products derived
|
| +// from this software without specific prior written permission.
|
| +//
|
| +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| +
|
| +// Load Splay tree and CodeMap implementations from <project root>/tools.
|
| +// Files: tools/splaytree.js tools/codemap.js
|
| +
|
| +
|
| +function newCodeEntry(size, name) {
|
| + return new devtools.profiler.CodeMap.CodeEntry(size, name);
|
| +};
|
| +
|
| +
|
| +function assertEntry(codeMap, expected_name, addr) {
|
| + var entry = codeMap.findEntry(addr);
|
| + assertNotNull(entry, 'no entry at ' + addr.toString(16));
|
| + assertEquals(expected_name, entry.name, 'at ' + addr.toString(16));
|
| +};
|
| +
|
| +
|
| +function assertNoEntry(codeMap, addr) {
|
| + assertNull(codeMap.findEntry(addr), 'at ' + addr.toString(16));
|
| +};
|
| +
|
| +
|
| +(function testStaticCode() {
|
| + var codeMap = new devtools.profiler.CodeMap();
|
| + codeMap.addStaticCode(0x1500, newCodeEntry(0x3000, 'lib1'));
|
| + codeMap.addStaticCode(0x15500, newCodeEntry(0x5000, 'lib2'));
|
| + codeMap.addStaticCode(0x155500, newCodeEntry(0x10000, 'lib3'));
|
| + assertNoEntry(codeMap, 0);
|
| + assertNoEntry(codeMap, 0x1500 - 1);
|
| + assertEntry(codeMap, 'lib1', 0x1500);
|
| + assertEntry(codeMap, 'lib1', 0x1500 + 0x100);
|
| + assertEntry(codeMap, 'lib1', 0x1500 + 0x1000);
|
| + assertEntry(codeMap, 'lib1', 0x1500 + 0x3000 - 1);
|
| + assertNoEntry(codeMap, 0x1500 + 0x3000);
|
| + assertNoEntry(codeMap, 0x15500 - 1);
|
| + assertEntry(codeMap, 'lib2', 0x15500);
|
| + assertEntry(codeMap, 'lib2', 0x15500 + 0x100);
|
| + assertEntry(codeMap, 'lib2', 0x15500 + 0x1000);
|
| + assertEntry(codeMap, 'lib2', 0x15500 + 0x5000 - 1);
|
| + assertNoEntry(codeMap, 0x15500 + 0x5000);
|
| + assertNoEntry(codeMap, 0x155500 - 1);
|
| + assertEntry(codeMap, 'lib3', 0x155500);
|
| + assertEntry(codeMap, 'lib3', 0x155500 + 0x100);
|
| + assertEntry(codeMap, 'lib3', 0x155500 + 0x1000);
|
| + assertEntry(codeMap, 'lib3', 0x155500 + 0x10000 - 1);
|
| + assertNoEntry(codeMap, 0x155500 + 0x10000);
|
| + assertNoEntry(codeMap, 0xFFFFFFFF);
|
| +})();
|
| +
|
| +
|
| +(function testDynamicCode() {
|
| + var codeMap = new devtools.profiler.CodeMap();
|
| + codeMap.addCode(0x1500, newCodeEntry(0x200, 'code1'));
|
| + codeMap.addCode(0x1700, newCodeEntry(0x100, 'code2'));
|
| + codeMap.addCode(0x1900, newCodeEntry(0x50, 'code3'));
|
| + codeMap.addCode(0x1950, newCodeEntry(0x10, 'code4'));
|
| + assertNoEntry(codeMap, 0);
|
| + assertNoEntry(codeMap, 0x1500 - 1);
|
| + assertEntry(codeMap, 'code1', 0x1500);
|
| + assertEntry(codeMap, 'code1', 0x1500 + 0x100);
|
| + assertEntry(codeMap, 'code1', 0x1500 + 0x200 - 1);
|
| + assertEntry(codeMap, 'code2', 0x1700);
|
| + assertEntry(codeMap, 'code2', 0x1700 + 0x50);
|
| + assertEntry(codeMap, 'code2', 0x1700 + 0x100 - 1);
|
| + assertNoEntry(codeMap, 0x1700 + 0x100);
|
| + assertNoEntry(codeMap, 0x1900 - 1);
|
| + assertEntry(codeMap, 'code3', 0x1900);
|
| + assertEntry(codeMap, 'code3', 0x1900 + 0x28);
|
| + assertEntry(codeMap, 'code4', 0x1950);
|
| + assertEntry(codeMap, 'code4', 0x1950 + 0x7);
|
| + assertEntry(codeMap, 'code4', 0x1950 + 0x10 - 1);
|
| + assertNoEntry(codeMap, 0x1950 + 0x10);
|
| + assertNoEntry(codeMap, 0xFFFFFFFF);
|
| +})();
|
| +
|
| +
|
| +(function testCodeMovesAndDeletions() {
|
| + var codeMap = new devtools.profiler.CodeMap();
|
| + codeMap.addCode(0x1500, newCodeEntry(0x200, 'code1'));
|
| + codeMap.addCode(0x1700, newCodeEntry(0x100, 'code2'));
|
| + assertEntry(codeMap, 'code1', 0x1500);
|
| + assertEntry(codeMap, 'code2', 0x1700);
|
| + codeMap.moveCode(0x1500, 0x1800);
|
| + assertNoEntry(codeMap, 0x1500);
|
| + assertEntry(codeMap, 'code2', 0x1700);
|
| + assertEntry(codeMap, 'code1', 0x1800);
|
| + codeMap.deleteCode(0x1700);
|
| + assertNoEntry(codeMap, 0x1700);
|
| + assertEntry(codeMap, 'code1', 0x1800);
|
| +})();
|
|
|