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

Side by Side Diff: src/processor/range_map_unittest.cc

Issue 2029953003: Adding support for overlapping ranges to RangeMap. (Closed) Base URL: https://chromium.googlesource.com/breakpad/breakpad.git@master
Patch Set: Created 4 years, 6 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
OLDNEW
1 // Copyright (c) 2010 Google Inc. 1 // Copyright (c) 2010 Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // The number of tests in the set 97 // The number of tests in the set
98 unsigned int range_test_count; 98 unsigned int range_test_count;
99 }; 99 };
100 100
101 101
102 // StoreTest uses the data in a RangeTest and calls StoreRange on the 102 // StoreTest uses the data in a RangeTest and calls StoreRange on the
103 // test RangeMap. It returns true if the expected result occurred, and 103 // test RangeMap. It returns true if the expected result occurred, and
104 // false if something else happened. 104 // false if something else happened.
105 static bool StoreTest(TestMap *range_map, const RangeTest *range_test) { 105 static bool StoreTest(TestMap *range_map, const RangeTest *range_test) {
106 linked_ptr<CountedObject> object(new CountedObject(range_test->id)); 106 linked_ptr<CountedObject> object(new CountedObject(range_test->id));
107 bool stored = range_map->StoreRange(range_test->address, 107 bool stored = range_map->StoreRange(range_test->address, 0 /* delta */,
108 range_test->size, 108 range_test->size, object);
109 object);
110 109
111 if (stored != range_test->expect_storable) { 110 if (stored != range_test->expect_storable) {
112 fprintf(stderr, "FAILED: " 111 fprintf(stderr, "FAILED: "
113 "StoreRange id %d, expected %s, observed %s\n", 112 "StoreRange id %d, expected %s, observed %s\n",
114 range_test->id, 113 range_test->id,
115 range_test->expect_storable ? "storable" : "not storable", 114 range_test->expect_storable ? "storable" : "not storable",
116 stored ? "stored" : "not stored"); 115 stored ? "stored" : "not stored");
117 return false; 116 return false;
118 } 117 }
119 118
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 expected_result = true; // test should always succeed. 158 expected_result = true; // test should always succeed.
160 else if (offset == -1) // When checking one below the target, 159 else if (offset == -1) // When checking one below the target,
161 expected_result = side; // should fail low and succeed high. 160 expected_result = side; // should fail low and succeed high.
162 else // When checking one above the target, 161 else // When checking one above the target,
163 expected_result = !side; // should succeed low and fail high. 162 expected_result = !side; // should succeed low and fail high.
164 } 163 }
165 164
166 linked_ptr<CountedObject> object; 165 linked_ptr<CountedObject> object;
167 AddressType retrieved_base = AddressType(); 166 AddressType retrieved_base = AddressType();
168 AddressType retrieved_size = AddressType(); 167 AddressType retrieved_size = AddressType();
168 AddressType retrieved_delta = AddressType();
169 bool retrieved = range_map->RetrieveRange(address, &object, 169 bool retrieved = range_map->RetrieveRange(address, &object,
170 &retrieved_base, 170 &retrieved_base,
171 &retrieved_delta,
171 &retrieved_size); 172 &retrieved_size);
172 173
173 bool observed_result = retrieved && object->id() == range_test->id; 174 bool observed_result = retrieved && object->id() == range_test->id;
174 175
175 if (observed_result != expected_result) { 176 if (observed_result != expected_result) {
176 fprintf(stderr, "FAILED: " 177 fprintf(stderr, "FAILED: "
177 "RetrieveRange id %d, side %d, offset %d, " 178 "RetrieveRange id %d, side %d, offset %d, "
178 "expected %s, observed %s\n", 179 "expected %s, observed %s\n",
179 range_test->id, 180 range_test->id,
180 side, 181 side,
(...skipping 21 matching lines...) Expand all
202 203
203 // Now, check RetrieveNearestRange. The nearest range is always 204 // Now, check RetrieveNearestRange. The nearest range is always
204 // expected to be different from the test range when checking one 205 // expected to be different from the test range when checking one
205 // less than the low side. 206 // less than the low side.
206 bool expected_nearest = range_test->expect_storable; 207 bool expected_nearest = range_test->expect_storable;
207 if (!side && offset < 0) 208 if (!side && offset < 0)
208 expected_nearest = false; 209 expected_nearest = false;
209 210
210 linked_ptr<CountedObject> nearest_object; 211 linked_ptr<CountedObject> nearest_object;
211 AddressType nearest_base = AddressType(); 212 AddressType nearest_base = AddressType();
213 AddressType nearest_delta = AddressType();
212 AddressType nearest_size = AddressType(); 214 AddressType nearest_size = AddressType();
213 bool retrieved_nearest = range_map->RetrieveNearestRange(address, 215 bool retrieved_nearest = range_map->RetrieveNearestRange(address,
214 &nearest_object, 216 &nearest_object,
215 &nearest_base, 217 &nearest_base,
218 &nearest_delta,
216 &nearest_size); 219 &nearest_size);
217 220
218 // When checking one greater than the high side, RetrieveNearestRange 221 // When checking one greater than the high side, RetrieveNearestRange
219 // should usually return the test range. When a different range begins 222 // should usually return the test range. When a different range begins
220 // at that address, though, then RetrieveNearestRange should return the 223 // at that address, though, then RetrieveNearestRange should return the
221 // range at the address instead of the test range. 224 // range at the address instead of the test range.
222 if (side && offset > 0 && nearest_base == address) { 225 if (side && offset > 0 && nearest_base == address) {
223 expected_nearest = false; 226 expected_nearest = false;
224 } 227 }
225 228
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 // call, and that ranges are returned with increasing base addresses. Returns 270 // call, and that ranges are returned with increasing base addresses. Returns
268 // false if the test fails. 271 // false if the test fails.
269 static bool RetrieveIndexTest(TestMap *range_map, int set) { 272 static bool RetrieveIndexTest(TestMap *range_map, int set) {
270 linked_ptr<CountedObject> object; 273 linked_ptr<CountedObject> object;
271 CountedObject *last_object = NULL; 274 CountedObject *last_object = NULL;
272 AddressType last_base = 0; 275 AddressType last_base = 0;
273 276
274 int object_count = range_map->GetCount(); 277 int object_count = range_map->GetCount();
275 for (int object_index = 0; object_index < object_count; ++object_index) { 278 for (int object_index = 0; object_index < object_count; ++object_index) {
276 AddressType base; 279 AddressType base;
277 if (!range_map->RetrieveRangeAtIndex(object_index, &object, &base, NULL)) { 280 if (!range_map->RetrieveRangeAtIndex(object_index, &object, &base,
281 NULL, NULL)) {
278 fprintf(stderr, "FAILED: RetrieveRangeAtIndex set %d index %d, " 282 fprintf(stderr, "FAILED: RetrieveRangeAtIndex set %d index %d, "
279 "expected success, observed failure\n", 283 "expected success, observed failure\n",
280 set, object_index); 284 set, object_index);
281 return false; 285 return false;
282 } 286 }
283 287
284 if (!object.get()) { 288 if (!object.get()) {
285 fprintf(stderr, "FAILED: RetrieveRangeAtIndex set %d index %d, " 289 fprintf(stderr, "FAILED: RetrieveRangeAtIndex set %d index %d, "
286 "expected object, observed NULL\n", 290 "expected object, observed NULL\n",
287 set, object_index); 291 set, object_index);
(...skipping 19 matching lines...) Expand all
307 return false; 311 return false;
308 } 312 }
309 } 313 }
310 314
311 last_object = object.get(); 315 last_object = object.get();
312 last_base = base; 316 last_base = base;
313 } 317 }
314 318
315 // Make sure that RetrieveRangeAtIndex doesn't allow lookups at indices that 319 // Make sure that RetrieveRangeAtIndex doesn't allow lookups at indices that
316 // are too high. 320 // are too high.
317 if (range_map->RetrieveRangeAtIndex(object_count, &object, NULL, NULL)) { 321 if (range_map->RetrieveRangeAtIndex(object_count, &object, NULL, NULL,
322 NULL)) {
318 fprintf(stderr, "FAILED: RetrieveRangeAtIndex set %d index %d (too large), " 323 fprintf(stderr, "FAILED: RetrieveRangeAtIndex set %d index %d (too large), "
319 "expected failure, observed success\n", 324 "expected failure, observed success\n",
320 set, object_count); 325 set, object_count);
321 return false; 326 return false;
322 } 327 }
323 328
324 return true; 329 return true;
325 } 330 }
326 331
327 // Additional RetriveAtIndex test to expose the bug in RetrieveRangeAtIndex(). 332 // Additional RetriveAtIndex test to expose the bug in RetrieveRangeAtIndex().
328 // Bug info: RetrieveRangeAtIndex() previously retrieves the high address of 333 // Bug info: RetrieveRangeAtIndex() previously retrieves the high address of
329 // entry, however, it is supposed to retrieve the base address of entry as 334 // entry, however, it is supposed to retrieve the base address of entry as
330 // stated in the comment in range_map.h. 335 // stated in the comment in range_map.h.
331 static bool RetriveAtIndexTest2() { 336 static bool RetriveAtIndexTest2() {
332 scoped_ptr<TestMap> range_map(new TestMap()); 337 scoped_ptr<TestMap> range_map(new TestMap());
333 338
334 // Store ranges with base address = 2 * object_id: 339 // Store ranges with base address = 2 * object_id:
335 const int range_size = 2; 340 const int range_size = 2;
336 for (int object_id = 0; object_id < 100; ++object_id) { 341 for (int object_id = 0; object_id < 100; ++object_id) {
337 linked_ptr<CountedObject> object(new CountedObject(object_id)); 342 linked_ptr<CountedObject> object(new CountedObject(object_id));
338 int base_address = 2 * object_id; 343 int base_address = 2 * object_id;
339 range_map->StoreRange(base_address, range_size, object); 344 range_map->StoreRange(base_address, 0 /* delta */, range_size, object);
340 } 345 }
341 346
342 linked_ptr<CountedObject> object; 347 linked_ptr<CountedObject> object;
343 int object_count = range_map->GetCount(); 348 int object_count = range_map->GetCount();
344 for (int object_index = 0; object_index < object_count; ++object_index) { 349 for (int object_index = 0; object_index < object_count; ++object_index) {
345 AddressType base; 350 AddressType base;
346 if (!range_map->RetrieveRangeAtIndex(object_index, &object, &base, NULL)) { 351 if (!range_map->RetrieveRangeAtIndex(object_index, &object, &base, NULL,
352 NULL)) {
347 fprintf(stderr, "FAILED: RetrieveAtIndexTest2 index %d, " 353 fprintf(stderr, "FAILED: RetrieveAtIndexTest2 index %d, "
348 "expected success, observed failure\n", object_index); 354 "expected success, observed failure\n", object_index);
349 return false; 355 return false;
350 } 356 }
351 357
352 int expected_base = 2 * object->id(); 358 int expected_base = 2 * object->id();
353 if (base != expected_base) { 359 if (base != expected_base) {
354 fprintf(stderr, "FAILED: RetriveAtIndexTest2 index %d, " 360 fprintf(stderr, "FAILED: RetriveAtIndexTest2 index %d, "
355 "expected base %d, observed base %d", 361 "expected base %d, observed base %d",
356 object_index, expected_base, base); 362 object_index, expected_base, base);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 549
544 550
545 } // namespace 551 } // namespace
546 552
547 553
548 int main(int argc, char **argv) { 554 int main(int argc, char **argv) {
549 BPLOG_INIT(&argc, &argv); 555 BPLOG_INIT(&argc, &argv);
550 556
551 return RunTests() ? 0 : 1; 557 return RunTests() ? 0 : 1;
552 } 558 }
559
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698