Changeset 8565a42 in mainline for kernel/test/cht/cht1.c
- Timestamp:
- 2018-03-02T20:34:50Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a1a81f69, d5e5fd1
- Parents:
- 3061bc1 (diff), 34e1206 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:34:50)
- git-committer:
- GitHub <noreply@…> (2018-03-02 20:34:50)
- File:
-
- 1 edited
-
kernel/test/cht/cht1.c (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
-
kernel/test/cht/cht1.c
r3061bc1 r8565a42 99 99 if (cht_find_lazy(h, (void*)0)) 100 100 return "Found lazy in empty table."; 101 101 102 102 if (cht_find(h, (void*)0)) 103 103 return "Found in empty table."; 104 104 105 105 if (cht_remove_key(h, (void*)0)) 106 106 return "Removed from empty table."; 107 107 108 108 const int val_cnt = 6; 109 109 val_t *v[6] = { NULL }; 110 110 111 111 for (int i = 0; i < val_cnt; ++i) 112 112 v[i] = malloc(sizeof(val_t), 0); 113 113 114 114 size_t key[] = { 1, 1, 1, 11, 12, 13 }; 115 115 116 116 /* First three are identical */ 117 117 for (int i = 0; i < 3; ++i) 118 118 set_val(v[i], 1, key[i]); 119 119 120 120 /* Same hash, different key.*/ 121 121 set_val(v[3], 1, key[3]); 122 122 123 123 /* Different hashes and keys. */ 124 124 set_val(v[4], 2, key[4]); 125 125 set_val(v[5], 3, key[5]); 126 126 127 127 cht_link_t *dup; 128 128 129 129 if (!cht_insert_unique(h, &v[0]->link, &dup)) 130 130 return "Duplicates in empty"; … … 132 132 if (cht_insert_unique(h, &v[1]->link, &dup)) 133 133 return "Inserted a duplicate"; 134 134 135 135 if (dup != &v[0]->link) 136 136 return "Returned wrong duplicate"; … … 138 138 if (!cht_insert_unique(h, &v[3]->link, &dup)) 139 139 return "Refused non-equal item but with a hash in table."; 140 140 141 141 cht_insert(h, &v[1]->link); 142 142 cht_insert(h, &v[2]->link); 143 143 144 144 bool ok = true; 145 145 ok = ok && cht_insert_unique(h, &v[4]->link, &dup); 146 146 ok = ok && cht_insert_unique(h, &v[5]->link, &dup); 147 147 148 148 if (!ok) 149 149 return "Refused unique ins 4, 5."; 150 150 151 151 if (cht_find(h, (void*)0)) 152 152 return "Phantom find."; 153 153 154 154 cht_link_t *item = cht_find(h, (void*)v[5]->unique_id); 155 155 if (!item || item != &v[5]->link) … … 159 159 if (item) 160 160 return "Found nonexisting duplicate 5"; 161 161 162 162 item = cht_find(h, (void*)v[3]->unique_id); 163 163 if (!item || item != &v[3]->link) … … 167 167 if (item) 168 168 return "Found nonexisting duplicate 3, same hash as others."; 169 169 170 170 item = cht_find(h, (void*)v[0]->unique_id); 171 171 ((val_t*)item)->mark = true; 172 172 173 173 for (int k = 1; k < 3; ++k) { 174 174 item = cht_find_next(h, item); 175 175 if (!item) 176 176 return "Did not find an inserted duplicate"; 177 177 178 178 val_t *val = ((val_t*)item); 179 179 180 180 if (val->unique_id != v[0]->unique_id) 181 181 return "Found item with a different key."; … … 184 184 val->mark = true; 185 185 } 186 186 187 187 for (int i = 0; i < 3; ++i) { 188 188 if (!v[i]->mark) 189 189 return "Did not find all duplicates"; 190 190 191 191 v[i]->mark = false; 192 192 } … … 196 196 197 197 item = cht_find_next(h, cht_find(h, (void*)key[0])); 198 198 199 199 ((val_t*)item)->mark = true; 200 200 if (!cht_remove_item(h, item)) 201 201 return "Failed to remove inserted item"; 202 202 203 203 item = cht_find(h, (void*)key[0]); 204 204 if (!item || ((val_t*)item)->mark) 205 205 return "Did not find proper item."; 206 206 207 207 item = cht_find_next(h, item); 208 208 if (!item || ((val_t*)item)->mark) … … 212 212 if (item) 213 213 return "Found removed duplicate"; 214 214 215 215 if (2 != cht_remove_key(h, (void*)key[0])) 216 216 return "Failed to remove all duplicates"; 217 217 218 218 if (cht_find(h, (void*)key[0])) 219 219 return "Found removed key"; 220 220 221 221 if (!cht_find(h, (void*)key[3])) 222 222 return "Removed incorrect key"; 223 223 224 224 for (size_t k = 0; k < sizeof(v) / sizeof(v[0]); ++k) { 225 225 cht_remove_key(h, (void*)key[k]); 226 226 } 227 227 228 228 for (size_t k = 0; k < sizeof(v) / sizeof(v[0]); ++k) { 229 229 if (cht_find(h, (void*)key[k])) … … 239 239 if (!cht_create_simple(&h, &val_ops)) 240 240 return "Could not create the table."; 241 241 242 242 rcu_read_lock(); 243 243 const char *err = do_sanity_test(&h); 244 244 rcu_read_unlock(); 245 245 246 246 cht_destroy(&h); 247 247 … … 321 321 goto out_of_mem; 322 322 } 323 323 324 324 s->free = true; 325 325 s->key = (i << 8) + work->id; 326 326 327 327 cht_insert(work->h, &s->link); 328 328 } 329 329 TPRINTF("}"); 330 330 331 331 thread_sleep(2); 332 332 … … 334 334 for (size_t i = 0; i < work->wave_elems; ++i) { 335 335 size_t key = (i << 8) + work->id; 336 336 337 337 if (1 != cht_remove_key(work->h, (void*)key)) { 338 338 TPRINTF("Err: Failed to remove inserted item\n"); … … 342 342 TPRINTF(">"); 343 343 } 344 344 345 345 /* Request that others stop. */ 346 346 *work->stop = 1; … … 365 365 stress_work_t *work = (stress_work_t *)arg; 366 366 assert(0 == *work->stop); 367 367 368 368 size_t loops = 0; 369 369 size_t seed = work->id; 370 370 371 371 while (0 == *work->stop && !work->failed) { 372 372 seed = next_rand(seed); … … 374 374 seed = next_rand(seed); 375 375 size_t elem_idx = seed % work->elem_cnt; 376 376 377 377 ++loops; 378 378 if (0 == loops % (1024 * 1024)) { … … 381 381 TPRINTF("*"); 382 382 } 383 383 384 384 if (upd) { 385 385 seed = next_rand(seed); 386 386 bool item_op = seed & 1; 387 387 388 388 if (work->elem[elem_idx].inserted) { 389 389 if (item_op) { … … 401 401 } else if (work->elem[elem_idx].deleted) { 402 402 work->elem[elem_idx].deleted = false; 403 403 404 404 if (item_op) { 405 405 rcu_read_lock(); … … 414 414 cht_insert(work->h, &work->elem[elem_idx].link); 415 415 } 416 416 417 417 work->elem[elem_idx].inserted = true; 418 418 } … … 452 452 { 453 453 cht_t h; 454 454 455 455 if (!cht_create_simple(&h, &stress_ops)) { 456 456 TPRINTF("Failed to create the table\n"); … … 464 464 size_t total_thr_cnt = op_thread_cnt + resize_thread_cnt; 465 465 size_t items_per_thread = 1024; 466 466 467 467 size_t work_cnt = op_thread_cnt + resize_thread_cnt; 468 468 size_t item_cnt = op_thread_cnt * items_per_thread; 469 469 470 470 /* Alloc hash table items. */ 471 471 size_t size = item_cnt * sizeof(stress_t) + work_cnt * sizeof(stress_work_t) 472 472 + sizeof(int); 473 473 474 474 TPRINTF("Alloc and init table items. \n"); 475 475 void *p = malloc(size, FRAME_ATOMIC); … … 479 479 return false; 480 480 } 481 481 482 482 stress_t *pitem = p + work_cnt * sizeof(stress_work_t); 483 483 stress_work_t *pwork = p; 484 484 int *pstop = (int*)(pitem + item_cnt); 485 485 486 486 *pstop = 0; 487 487 488 488 /* Init work items. */ 489 489 for (size_t i = 0; i < op_thread_cnt; ++i) { … … 496 496 pwork[i].failed = false; 497 497 } 498 498 499 499 for (size_t i = op_thread_cnt; i < op_thread_cnt + resize_thread_cnt; ++i) { 500 500 pwork[i].h = &h; … … 505 505 pwork[i].failed = false; 506 506 } 507 507 508 508 /* Init table elements. */ 509 509 for (size_t k = 0; k < op_thread_cnt; ++k) { … … 515 515 } 516 516 } 517 517 518 518 TPRINTF("Running %zu ins/del/find stress threads + %zu resizers.\n", 519 519 op_thread_cnt, resize_thread_cnt); 520 520 521 521 /* Create and run threads. */ 522 522 thread_t *thr[max_thread_cnt + resize_thread_cnt]; 523 523 524 524 for (size_t i = 0; i < total_thr_cnt; ++i) { 525 525 if (i < op_thread_cnt) … … 527 527 else 528 528 thr[i] = thread_create(resize_stresser, &pwork[i], TASK, 0, "cht-resize"); 529 529 530 530 assert(thr[i]); 531 531 thread_wire(thr[i], &cpus[i % config.cpu_active]); 532 532 thread_ready(thr[i]); 533 533 } 534 534 535 535 bool failed = false; 536 536 537 537 /* Wait for all threads to return. */ 538 538 TPRINTF("Joining resize stressers.\n"); … … 542 542 failed = pwork[i].failed || failed; 543 543 } 544 544 545 545 TPRINTF("Joining op stressers.\n"); 546 546 for (int i = (int)op_thread_cnt - 1; i >= 0; --i) { … … 550 550 failed = pwork[i].failed || failed; 551 551 } 552 552 553 553 cht_destroy(&h); 554 554 free(p); … … 566 566 return err; 567 567 printf("Basic sanity test: ok.\n"); 568 568 569 569 if (!do_stress()) 570 570 return "CHT stress test failed.";
Note:
See TracChangeset
for help on using the changeset viewer.
