OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 buffer.Dispose(); | 96 buffer.Dispose(); |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 | 100 |
101 static const int kAreaSize = 512; | 101 static const int kAreaSize = 512; |
102 | 102 |
103 | 103 |
104 void TestMemMove(byte* area1, | 104 void TestMemMove(byte* area1, |
105 byte* area2, | 105 byte* area2, |
106 byte* area3, | |
107 int src_offset, | 106 int src_offset, |
108 int dest_offset, | 107 int dest_offset, |
109 int length) { | 108 int length) { |
110 for (int i = 0; i < kAreaSize; i++) { | 109 for (int i = 0; i < kAreaSize; i++) { |
111 area1[i] = i & 0xFF; | 110 area1[i] = i & 0xFF; |
112 area2[i] = i & 0xFF; | 111 area2[i] = i & 0xFF; |
113 area3[i] = i & 0xFF; | |
114 } | 112 } |
115 OS::MemMove(area1 + dest_offset, area1 + src_offset, length); | 113 OS::MemMove(area1 + dest_offset, area1 + src_offset, length); |
116 MoveBytes(area2 + dest_offset, area2 + src_offset, length); | 114 memmove(area2 + dest_offset, area2 + src_offset, length); |
117 memmove(area3 + dest_offset, area3 + src_offset, length); | 115 if (memcmp(area1, area2, kAreaSize) != 0) { |
118 if (memcmp(area1, area3, kAreaSize) != 0) { | |
119 printf("OS::MemMove(): src_offset: %d, dest_offset: %d, length: %d\n", | 116 printf("OS::MemMove(): src_offset: %d, dest_offset: %d, length: %d\n", |
120 src_offset, dest_offset, length); | 117 src_offset, dest_offset, length); |
121 for (int i = 0; i < kAreaSize; i++) { | 118 for (int i = 0; i < kAreaSize; i++) { |
122 if (area1[i] == area3[i]) continue; | 119 if (area1[i] == area2[i]) continue; |
123 printf("diff at offset %d (%p): is %d, should be %d\n", | 120 printf("diff at offset %d (%p): is %d, should be %d\n", |
124 i, reinterpret_cast<void*>(area1 + i), area1[i], area3[i]); | 121 i, reinterpret_cast<void*>(area1 + i), area1[i], area2[i]); |
125 } | 122 } |
126 CHECK(false); | 123 CHECK(false); |
127 } | 124 } |
128 if (memcmp(area2, area3, kAreaSize) != 0) { | |
129 printf("MoveBytes(): src_offset: %d, dest_offset: %d, length: %d\n", | |
130 src_offset, dest_offset, length); | |
131 for (int i = 0; i < kAreaSize; i++) { | |
132 if (area2[i] == area3[i]) continue; | |
133 printf("diff at offset %d (%p): is %d, should be %d\n", | |
134 i, reinterpret_cast<void*>(area2 + i), area2[i], area3[i]); | |
135 } | |
136 CHECK(false); | |
137 } | |
138 } | 125 } |
139 | 126 |
140 | 127 |
141 TEST(MemMove) { | 128 TEST(MemMove) { |
142 v8::V8::Initialize(); | 129 v8::V8::Initialize(); |
143 byte* area1 = new byte[kAreaSize]; | 130 byte* area1 = new byte[kAreaSize]; |
144 byte* area2 = new byte[kAreaSize]; | 131 byte* area2 = new byte[kAreaSize]; |
145 byte* area3 = new byte[kAreaSize]; | |
146 | 132 |
147 static const int kMinOffset = 32; | 133 static const int kMinOffset = 32; |
148 static const int kMaxOffset = 64; | 134 static const int kMaxOffset = 64; |
149 static const int kMaxLength = 128; | 135 static const int kMaxLength = 128; |
150 STATIC_ASSERT(kMaxOffset + kMaxLength < kAreaSize); | 136 STATIC_ASSERT(kMaxOffset + kMaxLength < kAreaSize); |
151 | 137 |
152 for (int src_offset = kMinOffset; src_offset <= kMaxOffset; src_offset++) { | 138 for (int src_offset = kMinOffset; src_offset <= kMaxOffset; src_offset++) { |
153 for (int dst_offset = kMinOffset; dst_offset <= kMaxOffset; dst_offset++) { | 139 for (int dst_offset = kMinOffset; dst_offset <= kMaxOffset; dst_offset++) { |
154 for (int length = 0; length <= kMaxLength; length++) { | 140 for (int length = 0; length <= kMaxLength; length++) { |
155 TestMemMove(area1, area2, area3, src_offset, dst_offset, length); | 141 TestMemMove(area1, area2, src_offset, dst_offset, length); |
156 } | 142 } |
157 } | 143 } |
158 } | 144 } |
159 delete[] area1; | 145 delete[] area1; |
160 delete[] area2; | 146 delete[] area2; |
161 delete[] area3; | |
162 } | 147 } |
163 | 148 |
164 | 149 |
165 TEST(Collector) { | 150 TEST(Collector) { |
166 Collector<int> collector(8); | 151 Collector<int> collector(8); |
167 const int kLoops = 5; | 152 const int kLoops = 5; |
168 const int kSequentialSize = 1000; | 153 const int kSequentialSize = 1000; |
169 const int kBlockSize = 7; | 154 const int kBlockSize = 7; |
170 for (int loop = 0; loop < kLoops; loop++) { | 155 for (int loop = 0; loop < kLoops; loop++) { |
171 Vector<int> block = collector.AddBlock(7, 0xbadcafe); | 156 Vector<int> block = collector.AddBlock(7, 0xbadcafe); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 TEST(SequenceCollectorRegression) { | 211 TEST(SequenceCollectorRegression) { |
227 SequenceCollector<char> collector(16); | 212 SequenceCollector<char> collector(16); |
228 collector.StartSequence(); | 213 collector.StartSequence(); |
229 collector.Add('0'); | 214 collector.Add('0'); |
230 collector.AddBlock( | 215 collector.AddBlock( |
231 i::Vector<const char>("12345678901234567890123456789012", 32)); | 216 i::Vector<const char>("12345678901234567890123456789012", 32)); |
232 i::Vector<char> seq = collector.EndSequence(); | 217 i::Vector<char> seq = collector.EndSequence(); |
233 CHECK_EQ(0, strncmp("0123456789012345678901234567890123", | 218 CHECK_EQ(0, strncmp("0123456789012345678901234567890123", |
234 seq.start(), seq.length())); | 219 seq.start(), seq.length())); |
235 } | 220 } |
OLD | NEW |