Changeset 3bacee1 in mainline for kernel/test/cht/cht1.c
- Timestamp:
- 2018-04-12T16:27:17Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3cf22f9
- Parents:
- 76d0981d
- git-author:
- Jiri Svoboda <jiri@…> (2018-04-11 19:25:33)
- git-committer:
- Jiri Svoboda <jiri@…> (2018-04-12 16:27:17)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/test/cht/cht1.c
r76d0981d r3bacee1 95 95 96 96 97 static const char * 98 { 99 if (cht_find_lazy(h, (void *)0))97 static const char *do_sanity_test(cht_t *h) 98 { 99 if (cht_find_lazy(h, (void *)0)) 100 100 return "Found lazy in empty table."; 101 101 102 if (cht_find(h, (void *)0))102 if (cht_find(h, (void *)0)) 103 103 return "Found in empty table."; 104 104 105 if (cht_remove_key(h, (void *)0))105 if (cht_remove_key(h, (void *)0)) 106 106 return "Removed from empty table."; 107 107 … … 149 149 return "Refused unique ins 4, 5."; 150 150 151 if (cht_find(h, (void *)0))151 if (cht_find(h, (void *)0)) 152 152 return "Phantom find."; 153 153 154 cht_link_t *item = cht_find(h, (void *)v[5]->unique_id);154 cht_link_t *item = cht_find(h, (void *)v[5]->unique_id); 155 155 if (!item || item != &v[5]->link) 156 156 return "Missing 5."; … … 160 160 return "Found nonexisting duplicate 5"; 161 161 162 item = cht_find(h, (void *)v[3]->unique_id);162 item = cht_find(h, (void *)v[3]->unique_id); 163 163 if (!item || item != &v[3]->link) 164 164 return "Missing 3."; … … 168 168 return "Found nonexisting duplicate 3, same hash as others."; 169 169 170 item = cht_find(h, (void *)v[0]->unique_id);171 ((val_t *)item)->mark = true;170 item = cht_find(h, (void *)v[0]->unique_id); 171 ((val_t *)item)->mark = true; 172 172 173 173 for (int k = 1; k < 3; ++k) { … … 176 176 return "Did not find an inserted duplicate"; 177 177 178 val_t *val = ((val_t *)item);178 val_t *val = ((val_t *)item); 179 179 180 180 if (val->unique_id != v[0]->unique_id) … … 195 195 return "Found non-existing duplicate."; 196 196 197 item = cht_find_next(h, cht_find(h, (void *)key[0]));198 199 ((val_t *)item)->mark = true;197 item = cht_find_next(h, cht_find(h, (void *)key[0])); 198 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 item = cht_find(h, (void *)key[0]);204 if (!item || ((val_t *)item)->mark)203 item = cht_find(h, (void *)key[0]); 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 if (!item || ((val_t *)item)->mark)208 if (!item || ((val_t *)item)->mark) 209 209 return "Did not find proper duplicate."; 210 210 … … 213 213 return "Found removed duplicate"; 214 214 215 if (2 != cht_remove_key(h, (void *)key[0]))215 if (2 != cht_remove_key(h, (void *)key[0])) 216 216 return "Failed to remove all duplicates"; 217 217 218 if (cht_find(h, (void *)key[0]))218 if (cht_find(h, (void *)key[0])) 219 219 return "Found removed key"; 220 220 221 if (!cht_find(h, (void *)key[3]))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 cht_remove_key(h, (void *)key[k]);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 if (cht_find(h, (void *)key[k]))229 if (cht_find(h, (void *)key[k])) 230 230 return "Found a key in a cleared table"; 231 231 } … … 234 234 } 235 235 236 static const char * 236 static const char *sanity_test(void) 237 237 { 238 238 cht_t h; … … 279 279 static size_t stress_hash(const cht_link_t *item) 280 280 { 281 return ((stress_t *)item)->key >> 8;281 return ((stress_t *)item)->key >> 8; 282 282 } 283 283 static size_t stress_key_hash(void *key) … … 287 287 static bool stress_equal(const cht_link_t *item1, const cht_link_t *item2) 288 288 { 289 return ((stress_t *)item1)->key == ((stress_t*)item2)->key;289 return ((stress_t *)item1)->key == ((stress_t *)item2)->key; 290 290 } 291 291 static bool stress_key_equal(void *key, const cht_link_t *item) 292 292 { 293 return ((size_t)key) == ((stress_t *)item)->key;293 return ((size_t)key) == ((stress_t *)item)->key; 294 294 } 295 295 static void stress_rm_callback(cht_link_t *item) 296 296 { 297 if (((stress_t *)item)->free)297 if (((stress_t *)item)->free) 298 298 free(item); 299 299 else 300 ((stress_t *)item)->deleted = true;300 ((stress_t *)item)->deleted = true; 301 301 } 302 302 … … 335 335 size_t key = (i << 8) + work->id; 336 336 337 if (1 != cht_remove_key(work->h, (void *)key)) {337 if (1 != cht_remove_key(work->h, (void *)key)) { 338 338 TPRINTF("Err: Failed to remove inserted item\n"); 339 339 goto failed; … … 357 357 for (size_t i = 0; i < work->wave_elems; ++i) { 358 358 size_t key = (i << 8) + work->id; 359 cht_remove_key(work->h, (void *)key);359 cht_remove_key(work->h, (void *)key); 360 360 } 361 361 } … … 392 392 rcu_read_unlock(); 393 393 } else { 394 void *key = (void *)work->elem[elem_idx].key;394 void *key = (void *)work->elem[elem_idx].key; 395 395 if (1 != cht_remove_key(work->h, key)) { 396 396 TPRINTF("Err: did not rm the key\n"); … … 406 406 cht_link_t *dup; 407 407 if (!cht_insert_unique(work->h, &work->elem[elem_idx].link, 408 408 &dup)) { 409 409 TPRINTF("Err: already inserted\n"); 410 410 work->failed = true; … … 420 420 rcu_read_lock(); 421 421 cht_link_t *item = 422 cht_find(work->h, (void*)work->elem[elem_idx].key);422 cht_find(work->h, (void *)work->elem[elem_idx].key); 423 423 rcu_read_unlock(); 424 424 … … 444 444 /* Remove anything we may have inserted. */ 445 445 for (size_t i = 0; i < work->elem_cnt; ++i) { 446 void *key = (void *) work->elem[i].key;446 void *key = (void *) work->elem[i].key; 447 447 cht_remove_key(work->h, key); 448 448 } … … 469 469 470 470 /* Alloc hash table items. */ 471 size_t size = item_cnt * sizeof(stress_t) + work_cnt * sizeof(stress_work_t) 472 +sizeof(int);471 size_t size = item_cnt * sizeof(stress_t) + work_cnt * sizeof(stress_work_t) + 472 sizeof(int); 473 473 474 474 TPRINTF("Alloc and init table items. \n"); … … 482 482 stress_t *pitem = p + work_cnt * sizeof(stress_work_t); 483 483 stress_work_t *pwork = p; 484 int *pstop = (int *)(pitem + item_cnt);484 int *pstop = (int *)(pitem + item_cnt); 485 485 486 486 *pstop = 0; … … 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. */
Note:
See TracChangeset
for help on using the changeset viewer.