263 EXPECT_TRUE(cht->remove(thr, stl)) << "Removing a pre-existing value failed."; |
263 EXPECT_TRUE(cht->remove(thr, stl)) << "Removing a pre-existing value failed."; |
264 EXPECT_FALSE(cht->get_copy(thr, stl) == val) << "Got a removed value."; |
264 EXPECT_FALSE(cht->get_copy(thr, stl) == val) << "Got a removed value."; |
265 delete cht; |
265 delete cht; |
266 } |
266 } |
267 |
267 |
|
268 struct ChtCountScan { |
|
269 size_t _count; |
|
270 ChtCountScan() : _count(0) {} |
|
271 bool operator()(uintptr_t* val) { |
|
272 _count++; |
|
273 return true; /* continue scan */ |
|
274 } |
|
275 }; |
|
276 |
|
277 static void cht_move_to(Thread* thr) { |
|
278 uintptr_t val1 = 0x2; |
|
279 uintptr_t val2 = 0xe0000002; |
|
280 uintptr_t val3 = 0x3; |
|
281 SimpleTestLookup stl1(val1), stl2(val2), stl3(val3); |
|
282 SimpleTestTable* from_cht = new SimpleTestTable(); |
|
283 EXPECT_TRUE(from_cht->insert(thr, stl1, val1)) << "Insert unique value failed."; |
|
284 EXPECT_TRUE(from_cht->insert(thr, stl2, val2)) << "Insert unique value failed."; |
|
285 EXPECT_TRUE(from_cht->insert(thr, stl3, val3)) << "Insert unique value failed."; |
|
286 |
|
287 SimpleTestTable* to_cht = new SimpleTestTable(); |
|
288 EXPECT_TRUE(from_cht->try_move_nodes_to(thr, to_cht)) << "Moving nodes to new table failed"; |
|
289 |
|
290 ChtCountScan scan_old; |
|
291 EXPECT_TRUE(from_cht->try_scan(thr, scan_old)) << "Scanning table should work."; |
|
292 EXPECT_EQ(scan_old._count, (size_t)0) << "All items should be moved"; |
|
293 |
|
294 ChtCountScan scan_new; |
|
295 EXPECT_TRUE(to_cht->try_scan(thr, scan_new)) << "Scanning table should work."; |
|
296 EXPECT_EQ(scan_new._count, (size_t)3) << "All items should be moved"; |
|
297 EXPECT_TRUE(to_cht->get_copy(thr, stl1) == val1) << "Getting an inserted value should work."; |
|
298 EXPECT_TRUE(to_cht->get_copy(thr, stl2) == val2) << "Getting an inserted value should work."; |
|
299 EXPECT_TRUE(to_cht->get_copy(thr, stl3) == val3) << "Getting an inserted value should work."; |
|
300 } |
|
301 |
268 static void cht_grow(Thread* thr) { |
302 static void cht_grow(Thread* thr) { |
269 uintptr_t val = 0x2; |
303 uintptr_t val = 0x2; |
270 uintptr_t val2 = 0x22; |
304 uintptr_t val2 = 0x22; |
271 uintptr_t val3 = 0x222; |
305 uintptr_t val3 = 0x222; |
272 SimpleTestLookup stl(val), stl2(val2), stl3(val3); |
306 SimpleTestLookup stl(val), stl2(val2), stl3(val3); |
367 nomt_test_doer(cht_getinsert_bulkdelete_task); |
401 nomt_test_doer(cht_getinsert_bulkdelete_task); |
368 } |
402 } |
369 |
403 |
370 TEST_VM(ConcurrentHashTable, basic_scan) { |
404 TEST_VM(ConcurrentHashTable, basic_scan) { |
371 nomt_test_doer(cht_scan); |
405 nomt_test_doer(cht_scan); |
|
406 } |
|
407 |
|
408 TEST_VM(ConcurrentHashTable, basic_move_to) { |
|
409 nomt_test_doer(cht_move_to); |
372 } |
410 } |
373 |
411 |
374 TEST_VM(ConcurrentHashTable, basic_grow) { |
412 TEST_VM(ConcurrentHashTable, basic_grow) { |
375 nomt_test_doer(cht_grow); |
413 nomt_test_doer(cht_grow); |
376 } |
414 } |