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

Side by Side Diff: test/unittests/source-position-table-unittest.cc

Issue 2451853002: Uniform and precise source positions for inlining (Closed)
Patch Set: addressed comments Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/objects.h" 7 #include "src/objects.h"
8 #include "src/source-position-table.h" 8 #include "src/source-position-table.h"
9 #include "test/unittests/test-utils.h" 9 #include "test/unittests/test-utils.h"
10 10
11 namespace v8 { 11 namespace v8 {
12 namespace internal { 12 namespace internal {
13 namespace interpreter { 13 namespace interpreter {
14 14
15 class SourcePositionTableTest : public TestWithIsolateAndZone { 15 class SourcePositionTableTest : public TestWithIsolateAndZone {
16 public: 16 public:
17 SourcePositionTableTest() {} 17 SourcePositionTableTest() {}
18 ~SourcePositionTableTest() override {} 18 ~SourcePositionTableTest() override {}
19 }; 19 };
20 20
21 // Some random offsets, mostly at 'suspicious' bit boundaries. 21 // Some random offsets, mostly at 'suspicious' bit boundaries.
22 static int offsets[] = {0, 1, 2, 3, 4, 30, 31, 32, 22 static int offsets[] = {0, 1, 2, 3, 4, 30, 31, 32,
23 33, 62, 63, 64, 65, 126, 127, 128, 23 33, 62, 63, 64, 65, 126, 127, 128,
24 129, 250, 1000, 9999, 12000, 31415926}; 24 129, 250, 1000, 9999, 12000, 31415926};
25 25
26 SourcePosition toPos(int offset) { return SourcePosition(offset); }
27
26 TEST_F(SourcePositionTableTest, EncodeStatement) { 28 TEST_F(SourcePositionTableTest, EncodeStatement) {
27 SourcePositionTableBuilder builder(zone()); 29 SourcePositionTableBuilder builder(zone());
28 for (int i = 0; i < arraysize(offsets); i++) { 30 for (int i = 0; i < arraysize(offsets); i++) {
29 builder.AddPosition(offsets[i], offsets[i], true); 31 builder.AddPosition(offsets[i], toPos(offsets[i]), true);
30 } 32 }
31 33
32 // To test correctness, we rely on the assertions in ToSourcePositionTable(). 34 // To test correctness, we rely on the assertions in ToSourcePositionTable().
33 // (Also below.) 35 // (Also below.)
34 CHECK(!builder.ToSourcePositionTable(isolate(), Handle<AbstractCode>()) 36 CHECK(!builder.ToSourcePositionTable(isolate(), Handle<AbstractCode>())
35 .is_null()); 37 .is_null());
36 } 38 }
37 39
38 TEST_F(SourcePositionTableTest, EncodeStatementDuplicates) { 40 TEST_F(SourcePositionTableTest, EncodeStatementDuplicates) {
39 SourcePositionTableBuilder builder(zone()); 41 SourcePositionTableBuilder builder(zone());
40 for (int i = 0; i < arraysize(offsets); i++) { 42 for (int i = 0; i < arraysize(offsets); i++) {
41 builder.AddPosition(offsets[i], offsets[i], true); 43 builder.AddPosition(offsets[i], toPos(offsets[i]), true);
42 builder.AddPosition(offsets[i], offsets[i] + 1, true); 44 builder.AddPosition(offsets[i], toPos(offsets[i] + 1), true);
43 } 45 }
44 46
45 // To test correctness, we rely on the assertions in ToSourcePositionTable(). 47 // To test correctness, we rely on the assertions in ToSourcePositionTable().
46 // (Also below.) 48 // (Also below.)
47 CHECK(!builder.ToSourcePositionTable(isolate(), Handle<AbstractCode>()) 49 CHECK(!builder.ToSourcePositionTable(isolate(), Handle<AbstractCode>())
48 .is_null()); 50 .is_null());
49 } 51 }
50 52
51 TEST_F(SourcePositionTableTest, EncodeExpression) { 53 TEST_F(SourcePositionTableTest, EncodeExpression) {
52 SourcePositionTableBuilder builder(zone()); 54 SourcePositionTableBuilder builder(zone());
53 for (int i = 0; i < arraysize(offsets); i++) { 55 for (int i = 0; i < arraysize(offsets); i++) {
54 builder.AddPosition(offsets[i], offsets[i], false); 56 builder.AddPosition(offsets[i], toPos(offsets[i]), false);
55 } 57 }
56 CHECK(!builder.ToSourcePositionTable(isolate(), Handle<AbstractCode>()) 58 CHECK(!builder.ToSourcePositionTable(isolate(), Handle<AbstractCode>())
57 .is_null()); 59 .is_null());
58 } 60 }
59 61
60 TEST_F(SourcePositionTableTest, EncodeAscending) { 62 TEST_F(SourcePositionTableTest, EncodeAscending) {
61 SourcePositionTableBuilder builder(zone()); 63 SourcePositionTableBuilder builder(zone());
62 64
63 int code_offset = 0; 65 int code_offset = 0;
64 int source_position = 0; 66 int source_position = 0;
65 for (int i = 0; i < arraysize(offsets); i++) { 67 for (int i = 0; i < arraysize(offsets); i++) {
66 code_offset += offsets[i]; 68 code_offset += offsets[i];
67 source_position += offsets[i]; 69 source_position += offsets[i];
68 if (i % 2) { 70 if (i % 2) {
69 builder.AddPosition(code_offset, source_position, true); 71 builder.AddPosition(code_offset, toPos(source_position), true);
70 } else { 72 } else {
71 builder.AddPosition(code_offset, source_position, false); 73 builder.AddPosition(code_offset, toPos(source_position), false);
72 } 74 }
73 } 75 }
74 76
75 // Also test negative offsets for source positions: 77 // Also test negative offsets for source positions:
76 for (int i = 0; i < arraysize(offsets); i++) { 78 for (int i = 0; i < arraysize(offsets); i++) {
77 code_offset += offsets[i]; 79 code_offset += offsets[i];
78 source_position -= offsets[i]; 80 source_position -= offsets[i];
79 if (i % 2) { 81 if (i % 2) {
80 builder.AddPosition(code_offset, source_position, true); 82 builder.AddPosition(code_offset, toPos(source_position), true);
81 } else { 83 } else {
82 builder.AddPosition(code_offset, source_position, false); 84 builder.AddPosition(code_offset, toPos(source_position), false);
83 } 85 }
84 } 86 }
85 87
86 CHECK(!builder.ToSourcePositionTable(isolate(), Handle<AbstractCode>()) 88 CHECK(!builder.ToSourcePositionTable(isolate(), Handle<AbstractCode>())
87 .is_null()); 89 .is_null());
88 } 90 }
89 91
90 } // namespace interpreter 92 } // namespace interpreter
91 } // namespace internal 93 } // namespace internal
92 } // namespace v8 94 } // namespace v8
OLDNEW
« test/cctest/cctest.status ('K') | « test/unittests/interpreter/bytecode-array-writer-unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698