Changeset 19945 in vbox
- Timestamp:
- May 23, 2009 9:48:25 PM (16 years ago)
- Location:
- trunk/src/VBox/Runtime/testcase
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/Makefile.kmk
r19933 r19945 49 49 # 50 50 PROGRAMS += \ 51 tst Avl \51 tstRTAvl \ 52 52 tstBase64 \ 53 53 tstBitOperations \ … … 136 136 # 137 137 138 tst Avl_SOURCES = tstAvl.cpp138 tstRTAvl_SOURCES = tstRTAvl.cpp 139 139 140 140 tstBase64_TEMPLATE = VBOXR3TSTEXE -
trunk/src/VBox/Runtime/testcase/tstRTAvl.cpp
r19943 r19945 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT Testcase - A vltrees.3 * IPRT Testcase - AVL trees. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2006-200 7Sun Microsystems, Inc.7 * Copyright (C) 2006-2009 Sun Microsystems, Inc. 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 29 29 */ 30 30 31 32 31 /******************************************************************************* 33 32 * Header Files * 34 33 *******************************************************************************/ 35 34 #include <iprt/avl.h> 35 36 36 #include <iprt/asm.h> 37 #include <iprt/initterm.h> 38 #include <iprt/mem.h> 39 #include <iprt/rand.h> 37 40 #include <iprt/stdarg.h> 38 41 #include <iprt/string.h> 39 40 #include <stdio.h> 41 #include <stdlib.h> /* rand */ 42 #include <iprt/test.h> 42 43 43 44 … … 60 61 61 62 62 /** 63 * Gets a random number between 0 and Max. 64 * 65 * @return random number. 66 * @param Max The max number. (exclusive) 67 */ 68 uint32_t Random(uint32_t Max) 69 { 70 unsigned rc = rand(); 71 if (Max < RAND_MAX) 72 { 73 while (rc >= Max) 74 rc /= 3; 75 } 76 else 77 { 78 /// @todo... 79 } 80 return rc; 81 } 63 /******************************************************************************* 64 * Global Variables * 65 *******************************************************************************/ 66 static RTTEST g_hTest; 67 static RTRAND g_hRand; 82 68 83 69 … … 88 74 * @param MaxKey The max key value for the tracker. (exclusive) 89 75 */ 90 PTRACKER TrackerCreate(uint32_t MaxKey)76 static PTRACKER TrackerCreate(uint32_t MaxKey) 91 77 { 92 78 uint32_t cbBitmap = (MaxKey + sizeof(uint32_t) * sizeof(uint8_t) - 1) / sizeof(uint8_t); 93 PTRACKER pTracker = (PTRACKER) calloc(1,RT_OFFSETOF(TRACKER, abBitmap[cbBitmap]));79 PTRACKER pTracker = (PTRACKER)RTMemAllocZ(RT_OFFSETOF(TRACKER, abBitmap[cbBitmap])); 94 80 if (pTracker) 95 81 { … … 97 83 pTracker->LastAllocatedKey = MaxKey; 98 84 pTracker->cbBitmap = cbBitmap; 85 Assert(pTracker->cSetBits == 0); 99 86 } 100 87 return pTracker; … … 107 94 * @param pTracker The tracker. 108 95 */ 109 void TrackerDestroy(PTRACKER pTracker) 110 { 111 if (pTracker) 112 free(pTracker); 96 static void TrackerDestroy(PTRACKER pTracker) 97 { 98 RTMemFree(pTracker); 113 99 } 114 100 … … 122 108 * @param KeyLast The last key in the range. (inclusive) 123 109 */ 124 bool TrackerInsert(PTRACKER pTracker, uint32_t Key, uint32_t KeyLast)110 static bool TrackerInsert(PTRACKER pTracker, uint32_t Key, uint32_t KeyLast) 125 111 { 126 112 bool fRc = !ASMBitTestAndSet(pTracker->abBitmap, Key); … … 147 133 * @param KeyLast The last key in the range. (inclusive) 148 134 */ 149 bool TrackerRemove(PTRACKER pTracker, uint32_t Key, uint32_t KeyLast)135 static bool TrackerRemove(PTRACKER pTracker, uint32_t Key, uint32_t KeyLast) 150 136 { 151 137 bool fRc = ASMBitTestAndClear(pTracker->abBitmap, Key); … … 174 160 * @remark The caller has to call TrackerInsert. 175 161 */ 176 bool TrackerNewRandomEx(PTRACKER pTracker, uint32_t *pKey, uint32_t *pKeyLast, uint32_t cMaxKeys)162 static bool TrackerNewRandomEx(PTRACKER pTracker, uint32_t *pKey, uint32_t *pKeyLast, uint32_t cMaxKeys) 177 163 { 178 164 /* 179 165 * Find a key. 180 166 */ 181 uint32_t Key = R andom(pTracker->MaxKey);167 uint32_t Key = RTRandAdvU32Ex(g_hRand, 0, pTracker->MaxKey - 1); 182 168 if (ASMBitTest(pTracker->abBitmap, Key)) 183 169 { … … 194 180 { 195 181 const uint32_t KeyPrev = Key; 196 Key = R andom(KeyPrev);182 Key = RTRandAdvU32Ex(g_hRand, 0, KeyPrev - 1); 197 183 if (!ASMBitTest(pTracker->abBitmap, Key)) 198 184 break; … … 215 201 else 216 202 { 217 uint32_t cKeys = R andom(RT_MIN(pTracker->MaxKey - Key, cMaxKeys));203 uint32_t cKeys = RTRandAdvU32Ex(g_hRand, 0, RT_MIN(pTracker->MaxKey - Key, cMaxKeys - 1)); 218 204 KeyLast = Key + cKeys; 219 205 int Key2 = ASMBitNextSet(pTracker->abBitmap, RT_ALIGN_32(KeyLast, 32), Key); … … 241 227 * @remark The caller has to call TrackerInsert. 242 228 */ 243 bool TrackerNewRandom(PTRACKER pTracker, uint32_t *pKey)229 static bool TrackerNewRandom(PTRACKER pTracker, uint32_t *pKey) 244 230 { 245 231 return TrackerNewRandomEx(pTracker, pKey, NULL, 1); … … 255 241 * @remark The caller has to call TrackerRemove. 256 242 */ 257 bool TrackerFindRandom(PTRACKER pTracker, uint32_t *pKey)258 { 259 uint32_t Key = R andom(pTracker->MaxKey);243 static bool TrackerFindRandom(PTRACKER pTracker, uint32_t *pKey) 244 { 245 uint32_t Key = RTRandAdvU32Ex(g_hRand, 0, pTracker->MaxKey - 1); 260 246 if (!ASMBitTest(pTracker->abBitmap, Key)) 261 247 { … … 268 254 else 269 255 { 270 /* we're missing a ASMBitPrevSet function, so just try another, lower, value.*/ 271 for (;;) 272 { 273 const uint32_t KeyPrev = Key; 274 Key = Random(KeyPrev); 275 if (ASMBitTest(pTracker->abBitmap, Key)) 276 break; 277 Key2 = ASMBitNextSet(pTracker->abBitmap, RT_ALIGN_32(KeyPrev, 32), Key); 278 if (Key2 > 0) 256 /* we're missing a ASMBitPrevSet function, so here's a quick replacement hack. */ 257 uint32_t *pu32Start = (uint32_t *)&pTracker->abBitmap[0]; 258 uint32_t *pu32Cur = (uint32_t *)&pTracker->abBitmap[Key >> 8]; 259 while (pu32Cur >= pu32Start) 260 { 261 if (*pu32Cur) 279 262 { 280 Key = Key2;281 break;263 *pKey = ASMBitLastSetU32(*pu32Cur) - 1 + (uint32_t)((pu32Cur - pu32Start) * 32); 264 return true; 282 265 } 283 } 266 pu32Cur--; 267 } 268 Key2 = ASMBitFirstSet(pTracker->abBitmap, pTracker->MaxKey); 269 if (Key2 == -1) 270 { 271 RTTestIFailed("cSetBits=%u - but ASMBitFirstSet failed to find any", pTracker->cSetBits); 272 return false; 273 } 274 Key = Key2; 284 275 } 285 276 } … … 301 292 * @param ch The char. 302 293 */ 303 void ProgressChar(char ch)304 { 305 fputc(ch, stdout);306 fflush(stdout);294 static void ProgressChar(char ch) 295 { 296 //RTTestIPrintf(RTTESTLVL_INFO, "%c", ch); 297 RTTestIPrintf(RTTESTLVL_SUB_TEST, "%c", ch); 307 298 } 308 299 … … 317 308 if (cMax < 10000) 318 309 return; 310 319 311 va_list va; 320 312 va_start(va, pszFormat); 321 vfprintf(stdout, pszFormat, va); 313 //RTTestIPrintfV(RTTESTLVL_INFO, pszFormat, va); 314 RTTestIPrintfV(RTTESTLVL_SUB_TEST, pszFormat, va); 322 315 va_end(va); 323 316 } … … 338 331 339 332 340 int avlogcphys(unsigned cMax)333 static int avlogcphys(unsigned cMax) 341 334 { 342 335 /* 343 336 * Simple linear insert and remove. 344 337 */ 345 ProgressPrintf(cMax, "tstAVL oGCPhys(%d): linear left", cMax); 346 PAVLOGCPHYSTREE pTree = (PAVLOGCPHYSTREE)calloc(sizeof(*pTree),1); 338 if (cMax >= 10000) 339 RTTestISubF("oGCPhys(%d): linear left", cMax); 340 PAVLOGCPHYSTREE pTree = (PAVLOGCPHYSTREE)RTMemAllocZ(sizeof(*pTree)); 347 341 unsigned i; 348 342 for (i = 0; i < cMax; i++) 349 343 { 350 344 Progress(i, cMax); 351 PAVLOGCPHYSNODECORE pNode = (PAVLOGCPHYSNODECORE) malloc(sizeof(*pNode));345 PAVLOGCPHYSNODECORE pNode = (PAVLOGCPHYSNODECORE)RTMemAlloc(sizeof(*pNode)); 352 346 pNode->Key = i; 353 347 if (!RTAvloGCPhysInsert(pTree, pNode)) 354 348 { 355 printf("\ntstAvl: FAILURE - oGCPhys -linear left insert i=%d\n", i);349 RTTestIFailed("linear left insert i=%d\n", i); 356 350 return 1; 357 351 } … … 360 354 if (RTAvloGCPhysInsert(pTree, &Node)) 361 355 { 362 printf("\ntstAvl: FAILURE - oGCPhys -linear left negative insert i=%d\n", i);356 RTTestIFailed("linear left negative insert i=%d\n", i); 363 357 return 1; 364 358 } … … 372 366 if (!pNode) 373 367 { 374 printf("\ntstAvl: FAILURE - oGCPhys -linear left remove i=%d\n", i);368 RTTestIFailed("linear left remove i=%d\n", i); 375 369 return 1; 376 370 } 377 371 memset(pNode, 0xcc, sizeof(*pNode)); 378 free(pNode);372 RTMemFree(pNode); 379 373 380 374 /* negative */ … … 382 376 if (pNode) 383 377 { 384 printf("\ntstAvl: FAILURE - oGCPhys -linear left negative remove i=%d\n", i);378 RTTestIFailed("linear left negative remove i=%d\n", i); 385 379 return 1; 386 380 } … … 390 384 * Simple linear insert and remove from the right. 391 385 */ 392 ProgressPrintf(cMax, "\ntstAVL oGCPhys(%d): linear right", cMax); 386 if (cMax >= 10000) 387 RTTestISubF("oGCPhys(%d): linear right", cMax); 393 388 for (i = 0; i < cMax; i++) 394 389 { 395 390 Progress(i, cMax); 396 PAVLOGCPHYSNODECORE pNode = (PAVLOGCPHYSNODECORE) malloc(sizeof(*pNode));391 PAVLOGCPHYSNODECORE pNode = (PAVLOGCPHYSNODECORE)RTMemAlloc(sizeof(*pNode)); 397 392 pNode->Key = i; 398 393 if (!RTAvloGCPhysInsert(pTree, pNode)) 399 394 { 400 printf("\ntstAvl: FAILURE - oGCPhys -linear right insert i=%d\n", i);395 RTTestIFailed("linear right insert i=%d\n", i); 401 396 return 1; 402 397 } … … 405 400 if (RTAvloGCPhysInsert(pTree, &Node)) 406 401 { 407 printf("\ntstAvl: FAILURE - oGCPhys -linear right negative insert i=%d\n", i);402 RTTestIFailed("linear right negative insert i=%d\n", i); 408 403 return 1; 409 404 } … … 417 412 if (!pNode) 418 413 { 419 printf("\ntstAvl: FAILURE - oGCPhys -linear right remove i=%d\n", i);414 RTTestIFailed("linear right remove i=%d\n", i); 420 415 return 1; 421 416 } 422 417 memset(pNode, 0xcc, sizeof(*pNode)); 423 free(pNode);418 RTMemFree(pNode); 424 419 425 420 /* negative */ … … 427 422 if (pNode) 428 423 { 429 printf("\ntstAvl: FAILURE - oGCPhys -linear right negative remove i=%d\n", i);424 RTTestIFailed("linear right negative remove i=%d\n", i); 430 425 return 1; 431 426 } … … 435 430 * Linear insert but root based removal. 436 431 */ 437 ProgressPrintf(cMax, "\ntstAVL oGCPhys(%d): linear root", cMax); 432 if (cMax >= 10000) 433 RTTestISubF("oGCPhys(%d): linear root", cMax); 438 434 for (i = 0; i < cMax; i++) 439 435 { 440 436 Progress(i, cMax); 441 PAVLOGCPHYSNODECORE pNode = (PAVLOGCPHYSNODECORE) malloc(sizeof(*pNode));437 PAVLOGCPHYSNODECORE pNode = (PAVLOGCPHYSNODECORE)RTMemAlloc(sizeof(*pNode)); 442 438 pNode->Key = i; 443 439 if (!RTAvloGCPhysInsert(pTree, pNode)) 444 440 { 445 printf("\ntstAvl: FAILURE - oGCPhys -linear root insert i=%d\n", i);441 RTTestIFailed("linear root insert i=%d\n", i); 446 442 return 1; 447 443 } … … 450 446 if (RTAvloGCPhysInsert(pTree, &Node)) 451 447 { 452 printf("\ntstAvl: FAILURE - oGCPhys -linear root negative insert i=%d\n", i);448 RTTestIFailed("linear root negative insert i=%d\n", i); 453 449 return 1; 454 450 } … … 464 460 if (!pNode) 465 461 { 466 printf("\ntstAvl: FAILURE - oGCPhys -linear root remove i=%d Key=%d\n", i, (unsigned)Key);462 RTTestIFailed("linear root remove i=%d Key=%d\n", i, (unsigned)Key); 467 463 return 1; 468 464 } 469 465 memset(pNode, 0xcc, sizeof(*pNode)); 470 free(pNode);466 RTMemFree(pNode); 471 467 472 468 /* negative */ … … 474 470 if (pNode) 475 471 { 476 printf("\ntstAvl: FAILURE - oGCPhys -linear root negative remove i=%d Key=%d\n", i, (unsigned)Key);472 RTTestIFailed("linear root negative remove i=%d Key=%d\n", i, (unsigned)Key); 477 473 return 1; 478 474 } … … 480 476 if (*pTree) 481 477 { 482 printf("\ntstAvl: FAILURE - oGCPhys -sparse remove didn't remove it all!\n");478 RTTestIFailed("sparse remove didn't remove it all!\n"); 483 479 return 1; 484 480 } … … 488 484 */ 489 485 const unsigned cMaxSparse = RT_ALIGN(cMax, 32); 490 ProgressPrintf(cMaxSparse, "\ntstAVL oGCPhys(%d): sparse", cMax); 486 if (cMaxSparse >= 10000) 487 RTTestISubF("oGCPhys(%d): sparse", cMax); 491 488 for (i = 0; i < cMaxSparse; i += 8) 492 489 { 493 490 Progress(i, cMaxSparse); 494 PAVLOGCPHYSNODECORE pNode = (PAVLOGCPHYSNODECORE) malloc(sizeof(*pNode));491 PAVLOGCPHYSNODECORE pNode = (PAVLOGCPHYSNODECORE)RTMemAlloc(sizeof(*pNode)); 495 492 pNode->Key = i; 496 493 if (!RTAvloGCPhysInsert(pTree, pNode)) 497 494 { 498 printf("\ntstAvl: FAILURE - oGCPhys -sparse insert i=%d\n", i);495 RTTestIFailed("sparse insert i=%d\n", i); 499 496 return 1; 500 497 } … … 503 500 if (RTAvloGCPhysInsert(pTree, &Node)) 504 501 { 505 printf("\ntstAvl: FAILURE - oGCPhys -sparse negative insert i=%d\n", i);502 RTTestIFailed("sparse negative insert i=%d\n", i); 506 503 return 1; 507 504 } … … 519 516 if (!pNode) 520 517 { 521 printf("\ntstAvl: FAILURE - oGCPhys -sparse remove i=%d j=%d\n", i, j);518 RTTestIFailed("sparse remove i=%d j=%d\n", i, j); 522 519 return 1; 523 520 } 524 521 if (pNode->Key - (unsigned long)i >= 8 * 4) 525 522 { 526 printf("\ntstAvl: FAILURE - oGCPhys -sparse remove i=%d j=%d Key=%d\n", i, j, (unsigned)pNode->Key);523 RTTestIFailed("sparse remove i=%d j=%d Key=%d\n", i, j, (unsigned)pNode->Key); 527 524 return 1; 528 525 } 529 526 memset(pNode, 0xdd, sizeof(*pNode)); 530 free(pNode);527 RTMemFree(pNode); 531 528 } 532 529 } 533 530 if (*pTree) 534 531 { 535 printf("\ntstAvl: FAILURE - oGCPhys -sparse remove didn't remove it all!\n");532 RTTestIFailed("sparse remove didn't remove it all!\n"); 536 533 return 1; 537 534 } 538 free(pTree);535 RTMemFree(pTree); 539 536 ProgressPrintf(cMaxSparse, "\n"); 540 537 return 0; … … 544 541 int avlogcphysRand(unsigned cMax, unsigned cMax2) 545 542 { 546 PAVLOGCPHYSTREE pTree = (PAVLOGCPHYSTREE) calloc(sizeof(*pTree),1);543 PAVLOGCPHYSTREE pTree = (PAVLOGCPHYSTREE)RTMemAllocZ(sizeof(*pTree)); 547 544 unsigned i; 548 545 … … 550 547 * Random tree. 551 548 */ 552 ProgressPrintf(cMax, "tstAVL oGCPhys(%d, %d): random", cMax, cMax2); 549 if (cMax >= 10000) 550 RTTestISubF("oGCPhys(%d, %d): random", cMax, cMax2); 553 551 PTRACKER pTracker = TrackerCreate(cMax2); 554 552 if (!pTracker) 555 553 { 556 printf("tstAVL: Failure - oGCPhys -failed to create %d tracker!\n", cMax2);554 RTTestIFailed("failed to create %d tracker!\n", cMax2); 557 555 return 1; 558 556 } … … 565 563 if (!TrackerNewRandom(pTracker, &Key)) 566 564 { 567 printf("\ntstAVL: Failure - oGCPhys -failed to allocate node no. %d\n", i);565 RTTestIFailed("failed to allocate node no. %d\n", i); 568 566 TrackerDestroy(pTracker); 569 567 return 1; 570 568 } 571 PAVLOGCPHYSNODECORE pNode = (PAVLOGCPHYSNODECORE) malloc(sizeof(*pNode));569 PAVLOGCPHYSNODECORE pNode = (PAVLOGCPHYSNODECORE)RTMemAlloc(sizeof(*pNode)); 572 570 pNode->Key = Key; 573 571 if (!RTAvloGCPhysInsert(pTree, pNode)) 574 572 { 575 printf("\ntstAvl: FAILURE - oGCPhys -random insert i=%d Key=%#x\n", i, Key);573 RTTestIFailed("random insert i=%d Key=%#x\n", i, Key); 576 574 return 1; 577 575 } … … 580 578 if (RTAvloGCPhysInsert(pTree, &Node)) 581 579 { 582 printf("\ntstAvl: FAILURE - oGCPhys -linear negative insert i=%d Key=%#x\n", i, Key);580 RTTestIFailed("linear negative insert i=%d Key=%#x\n", i, Key); 583 581 return 1; 584 582 } … … 595 593 if (!TrackerFindRandom(pTracker, &Key)) 596 594 { 597 printf("\ntstAVL: Failure - oGCPhys -failed to find free node no. %d\n", i);595 RTTestIFailed("failed to find free node no. %d\n", i); 598 596 TrackerDestroy(pTracker); 599 597 return 1; … … 603 601 if (!pNode) 604 602 { 605 printf("\ntstAvl: FAILURE - oGCPhys -random remove i=%d Key=%#x\n", i, Key);603 RTTestIFailed("random remove i=%d Key=%#x\n", i, Key); 606 604 return 1; 607 605 } 608 606 if (pNode->Key != Key) 609 607 { 610 printf("\ntstAvl: FAILURE - oGCPhys -random remove i=%d Key=%#x pNode->Key=%#x\n", i, Key, (unsigned)pNode->Key);608 RTTestIFailed("random remove i=%d Key=%#x pNode->Key=%#x\n", i, Key, (unsigned)pNode->Key); 611 609 return 1; 612 610 } 613 611 TrackerRemove(pTracker, Key, Key); 614 612 memset(pNode, 0xdd, sizeof(*pNode)); 615 free(pNode);613 RTMemFree(pNode); 616 614 } 617 615 if (*pTree) 618 616 { 619 printf("\ntstAvl: FAILURE - oGCPhys -random remove didn't remove it all!\n");617 RTTestIFailed("random remove didn't remove it all!\n"); 620 618 return 1; 621 619 } 622 620 ProgressPrintf(cMax, "\n"); 623 621 TrackerDestroy(pTracker); 624 free(pTree);622 RTMemFree(pTree); 625 623 return 0; 626 624 } … … 633 631 unsigned j; 634 632 unsigned k; 635 PAVLROGCPHYSTREE pTree = (PAVLROGCPHYSTREE) calloc(sizeof(*pTree), 1);633 PAVLROGCPHYSTREE pTree = (PAVLROGCPHYSTREE)RTMemAllocZ(sizeof(*pTree)); 636 634 637 635 AssertCompileSize(AVLOGCPHYSNODECORE, 24); 638 636 AssertCompileSize(AVLROGCPHYSNODECORE, 32); 639 637 638 RTTestISubF("RTAvlroGCPhys"); 639 640 640 /* 641 641 * Simple linear insert, get and remove. … … 644 644 for (i = 0; i < 65536; i += 4) 645 645 { 646 PAVLROGCPHYSNODECORE pNode = (PAVLROGCPHYSNODECORE) malloc(sizeof(*pNode));646 PAVLROGCPHYSNODECORE pNode = (PAVLROGCPHYSNODECORE)RTMemAlloc(sizeof(*pNode)); 647 647 pNode->Key = i; 648 648 pNode->KeyLast = i + 3; 649 649 if (!RTAvlroGCPhysInsert(pTree, pNode)) 650 650 { 651 printf("tstAvl: FAILURE - roGCPhys -linear insert i=%d\n", (unsigned)i);651 RTTestIFailed("linear insert i=%d\n", (unsigned)i); 652 652 return 1; 653 653 } … … 663 663 if (RTAvlroGCPhysInsert(pTree, &Node)) 664 664 { 665 printf("tstAvl: FAILURE - roGCPhys -linear negative insert i=%d j=%d k=%d\n", i, j, k);665 RTTestIFailed("linear negative insert i=%d j=%d k=%d\n", i, j, k); 666 666 return 1; 667 667 } … … 676 676 if (!pNode) 677 677 { 678 printf("tstAvl: FAILURE - roGCPhys -linear get i=%d\n", i);678 RTTestIFailed("linear get i=%d\n", i); 679 679 return 1; 680 680 } 681 681 if (pNode->Key > i || pNode->KeyLast < i) 682 682 { 683 printf("tstAvl: FAILURE - roGCPhys -linear get i=%d Key=%d KeyLast=%d\n", i, (unsigned)pNode->Key, (unsigned)pNode->KeyLast);683 RTTestIFailed("linear get i=%d Key=%d KeyLast=%d\n", i, (unsigned)pNode->Key, (unsigned)pNode->KeyLast); 684 684 return 1; 685 685 } … … 689 689 if (RTAvlroGCPhysRangeGet(pTree, i + j) != pNode) 690 690 { 691 printf("tstAvl: FAILURE - roGCPhys -linear range get i=%d j=%d\n", i, j);691 RTTestIFailed("linear range get i=%d j=%d\n", i, j); 692 692 return 1; 693 693 } … … 699 699 || RTAvlroGCPhysGet(pTree, i + 3)) 700 700 { 701 printf("tstAvl: FAILURE - roGCPhys -linear negative get i=%d + n\n", i);701 RTTestIFailed("linear negative get i=%d + n\n", i); 702 702 return 1; 703 703 } … … 711 711 if (!pNode) 712 712 { 713 printf("tstAvl: FAILURE - roGCPhys -linear remove i=%d\n", i);713 RTTestIFailed("linear remove i=%d\n", i); 714 714 return 1; 715 715 } 716 716 memset(pNode, 0xcc, sizeof(*pNode)); 717 free(pNode);717 RTMemFree(pNode); 718 718 719 719 /* negative */ … … 723 723 || RTAvlroGCPhysRemove(pTree, i + 3)) 724 724 { 725 printf("tstAvl: FAILURE - roGCPhys -linear negative remove i=%d + n\n", i);725 RTTestIFailed("linear negative remove i=%d + n\n", i); 726 726 return 1; 727 727 } … … 733 733 for (i = 0; i < 65536; i += 8) 734 734 { 735 PAVLROGCPHYSNODECORE pNode = (PAVLROGCPHYSNODECORE) malloc(sizeof(*pNode));735 PAVLROGCPHYSNODECORE pNode = (PAVLROGCPHYSNODECORE)RTMemAlloc(sizeof(*pNode)); 736 736 pNode->Key = i; 737 737 pNode->KeyLast = i + 3; 738 738 if (!RTAvlroGCPhysInsert(pTree, pNode)) 739 739 { 740 printf("tstAvl: FAILURE - roGCPhys -sparse insert i=%d\n", i);740 RTTestIFailed("sparse insert i=%d\n", i); 741 741 return 1; 742 742 } … … 753 753 if (RTAvlroGCPhysInsert(pTree, &Node)) 754 754 { 755 printf("tstAvl: FAILURE - roGCPhys -sparse negative insert i=%d j=%d k=%d\n", i, j, k);755 RTTestIFailed("sparse negative insert i=%d j=%d k=%d\n", i, j, k); 756 756 return 1; 757 757 } … … 772 772 if (!pNode) 773 773 { 774 printf("tstAvl: FAILURE - roGCPhys -sparse get i=%d j=%d KeyBase=%d\n", i, j, (unsigned)KeyBase);774 RTTestIFailed("sparse get i=%d j=%d KeyBase=%d\n", i, j, (unsigned)KeyBase); 775 775 return 1; 776 776 } 777 777 if (pNode->Key > KeyBase || pNode->KeyLast < KeyBase) 778 778 { 779 printf("tstAvl: FAILURE - roGCPhys -sparse get i=%d j=%d KeyBase=%d pNode->Key=%d\n", i, j, (unsigned)KeyBase, (unsigned)pNode->Key);779 RTTestIFailed("sparse get i=%d j=%d KeyBase=%d pNode->Key=%d\n", i, j, (unsigned)KeyBase, (unsigned)pNode->Key); 780 780 return 1; 781 781 } … … 784 784 if (RTAvlroGCPhysRangeGet(pTree, k) != pNode) 785 785 { 786 printf("tstAvl: FAILURE - roGCPhys -sparse range get i=%d j=%d k=%d\n", i, j, k);786 RTTestIFailed("sparse range get i=%d j=%d k=%d\n", i, j, k); 787 787 return 1; 788 788 } … … 795 795 && RTAvlroGCPhysGet(pTree, k)) 796 796 { 797 printf("tstAvl: FAILURE - roGCPhys -sparse negative get i=%d j=%d k=%d\n", i, j, k);797 RTTestIFailed("sparse negative get i=%d j=%d k=%d\n", i, j, k); 798 798 return 1; 799 799 } … … 803 803 if (RTAvlroGCPhysRangeGet(pTree, k)) 804 804 { 805 printf("tstAvl: FAILURE - roGCPhys -sparse negative range get i=%d j=%d k=%d\n", i, j, k);805 RTTestIFailed("sparse negative range get i=%d j=%d k=%d\n", i, j, k); 806 806 return 1; 807 807 } … … 811 811 if (RTAvlroGCPhysRangeGet(pTree, k)) 812 812 { 813 printf("tstAvl: FAILURE - roGCPhys -sparse negative range get i=%d j=%d k=%d\n", i, j, k);813 RTTestIFailed("sparse negative range get i=%d j=%d k=%d\n", i, j, k); 814 814 return 1; 815 815 } … … 820 820 if (RTAvlroGCPhysRangeRemove(pTree, Key) != pNode) 821 821 { 822 printf("tstAvl: FAILURE - roGCPhys -sparse remove i=%d j=%d Key=%d\n", i, j, (unsigned)Key);822 RTTestIFailed("sparse remove i=%d j=%d Key=%d\n", i, j, (unsigned)Key); 823 823 return 1; 824 824 } 825 825 memset(pNode, 0xdd, sizeof(*pNode)); 826 free(pNode);826 RTMemFree(pNode); 827 827 } 828 828 } 829 829 if (*pTree) 830 830 { 831 printf("tstAvl: FAILURE - roGCPhys -sparse remove didn't remove it all!\n");831 RTTestIFailed("sparse remove didn't remove it all!\n"); 832 832 return 1; 833 833 } … … 856 856 if (!RTAvlroGCPhysInsert(&s1.Tree, pNode)) 857 857 { 858 printf("tstAvl: FAILURE - roGCPhys -real insert i=%d\n", i);858 RTTestIFailed("real insert i=%d\n", i); 859 859 return 1; 860 860 } 861 861 if (RTAvlroGCPhysInsert(&s1.Tree, pNode)) 862 862 { 863 printf("tstAvl: FAILURE - roGCPhys -real negative insert i=%d\n", i);863 RTTestIFailed("real negative insert i=%d\n", i); 864 864 return 1; 865 865 } 866 866 if (RTAvlroGCPhysGet(&s1.Tree, pNode->Key) != pNode) 867 867 { 868 printf("tstAvl: FAILURE - roGCPhys -real get (1) i=%d\n", i);868 RTTestIFailed("real get (1) i=%d\n", i); 869 869 return 1; 870 870 } 871 871 if (RTAvlroGCPhysGet(&s1.Tree, pNode->KeyLast) != NULL) 872 872 { 873 printf("tstAvl: FAILURE - roGCPhys -real negative get (2) i=%d\n", i);873 RTTestIFailed("real negative get (2) i=%d\n", i); 874 874 return 1; 875 875 } 876 876 if (RTAvlroGCPhysRangeGet(&s1.Tree, pNode->Key) != pNode) 877 877 { 878 printf("tstAvl: FAILURE - roGCPhys -real range get (1) i=%d\n", i);878 RTTestIFailed("real range get (1) i=%d\n", i); 879 879 return 1; 880 880 } 881 881 if (RTAvlroGCPhysRangeGet(&s1.Tree, pNode->Key + 1) != pNode) 882 882 { 883 printf("tstAvl: FAILURE - roGCPhys -real range get (2) i=%d\n", i);883 RTTestIFailed("real range get (2) i=%d\n", i); 884 884 return 1; 885 885 } 886 886 if (RTAvlroGCPhysRangeGet(&s1.Tree, pNode->KeyLast) != pNode) 887 887 { 888 printf("tstAvl: FAILURE - roGCPhys -real range get (3) i=%d\n", i);888 RTTestIFailed("real range get (3) i=%d\n", i); 889 889 return 1; 890 890 } … … 898 898 if (RTAvlroGCPhysGet(&s3.Tree, pNode->Key) != pNode) 899 899 { 900 printf("tstAvl: FAILURE - roGCPhys -real get (10) i=%d\n", i);900 RTTestIFailed("real get (10) i=%d\n", i); 901 901 return 1; 902 902 } 903 903 if (RTAvlroGCPhysRangeGet(&s3.Tree, pNode->Key) != pNode) 904 904 { 905 printf("tstAvl: FAILURE - roGCPhys -real range get (10) i=%d\n", i);905 RTTestIFailed("real range get (10) i=%d\n", i); 906 906 return 1; 907 907 } … … 912 912 if (RTAvlroGCPhysGet(&s3.Tree, j) != NULL) 913 913 { 914 printf("tstAvl: FAILURE - roGCPhys -real negative get (11) i=%d j=%#x\n", i, j);914 RTTestIFailed("real negative get (11) i=%d j=%#x\n", i, j); 915 915 return 1; 916 916 } 917 917 if (RTAvlroGCPhysRangeGet(&s3.Tree, j) != pNode) 918 918 { 919 printf("tstAvl: FAILURE - roGCPhys -real range get (11) i=%d j=%#x\n", i, j);919 RTTestIFailed("real range get (11) i=%d j=%#x\n", i, j); 920 920 return 1; 921 921 } … … 929 929 int avlul(void) 930 930 { 931 RTTestISubF("RTAvlUL"); 932 931 933 /* 932 934 * Simple linear insert and remove. … … 937 939 for (i = 0; i < 65536; i++) 938 940 { 939 PAVLULNODECORE pNode = (PAVLULNODECORE) malloc(sizeof(*pNode));941 PAVLULNODECORE pNode = (PAVLULNODECORE)RTMemAlloc(sizeof(*pNode)); 940 942 pNode->Key = i; 941 943 if (!RTAvlULInsert(&pTree, pNode)) 942 944 { 943 printf("tstAvl: FAILURE - UL -linear insert i=%d\n", i);945 RTTestIFailed("linear insert i=%d\n", i); 944 946 return 1; 945 947 } … … 948 950 if (RTAvlULInsert(&pTree, &Node)) 949 951 { 950 printf("tstAvl: FAILURE - UL -linear negative insert i=%d\n", i);952 RTTestIFailed("linear negative insert i=%d\n", i); 951 953 return 1; 952 954 } … … 958 960 if (!pNode) 959 961 { 960 printf("tstAvl: FAILURE - UL -linear remove i=%d\n", i);962 RTTestIFailed("linear remove i=%d\n", i); 961 963 return 1; 962 964 } … … 964 966 pNode->pRight = (PAVLULNODECORE)0xbbbbbbbb; 965 967 pNode->uchHeight = 'e'; 966 free(pNode);968 RTMemFree(pNode); 967 969 968 970 /* negative */ … … 970 972 if (pNode) 971 973 { 972 printf("tstAvl: FAILURE - UL -linear negative remove i=%d\n", i);974 RTTestIFailed("linear negative remove i=%d\n", i); 973 975 return 1; 974 976 } … … 980 982 for (i = 0; i < 65536; i += 8) 981 983 { 982 PAVLULNODECORE pNode = (PAVLULNODECORE) malloc(sizeof(*pNode));984 PAVLULNODECORE pNode = (PAVLULNODECORE)RTMemAlloc(sizeof(*pNode)); 983 985 pNode->Key = i; 984 986 if (!RTAvlULInsert(&pTree, pNode)) 985 987 { 986 printf("tstAvl: FAILURE - UL -linear insert i=%d\n", i);988 RTTestIFailed("linear insert i=%d\n", i); 987 989 return 1; 988 990 } … … 991 993 if (RTAvlULInsert(&pTree, &Node)) 992 994 { 993 printf("tstAvl: FAILURE - UL -linear negative insert i=%d\n", i);995 RTTestIFailed("linear negative insert i=%d\n", i); 994 996 return 1; 995 997 } … … 1008 1010 if (!pNode) 1009 1011 { 1010 printf("tstAvl: FAILURE - UL -sparse remove i=%d j=%d\n", i, j);1012 RTTestIFailed("sparse remove i=%d j=%d\n", i, j); 1011 1013 return 1; 1012 1014 } … … 1014 1016 pNode->pRight = (PAVLULNODECORE)0xcccccccc; 1015 1017 pNode->uchHeight = 'E'; 1016 free(pNode);1018 RTMemFree(pNode); 1017 1019 } 1018 1020 } … … 1024 1026 int main() 1025 1027 { 1026 int cErrors = 0; 1028 /* 1029 * Init. 1030 */ 1031 int rc = RTR3Init(); 1032 if (RT_FAILURE(rc)) 1033 return 1; 1034 1035 RTTEST hTest; 1036 rc = RTTestCreate("tstRTAvl", &hTest); 1037 if (RT_FAILURE(rc)) 1038 return 1; 1039 g_hTest = hTest; 1040 RTTestBanner(hTest); 1041 1042 rc = RTRandAdvCreateParkMiller(&g_hRand); 1043 if (RT_FAILURE(rc)) 1044 { 1045 RTTestIFailed("RTRandAdvCreateParkMiller -> %Rrc", rc); 1046 return RTTestSummaryAndDestroy(hTest); 1047 } 1048 1049 /* 1050 * Testing. 1051 */ 1027 1052 unsigned i; 1028 1029 ProgressPrintf(~0, "tstAvl oGCPhys(32..2048)\n"); 1030 for (i = 32; i < 2048 && !cErrors; i++) 1031 cErrors += avlogcphys(i); 1032 cErrors += avlogcphys(_64K); 1033 cErrors += avlogcphys(_512K); 1034 cErrors += avlogcphys(_4M); 1035 for (unsigned j = 0; j < /*256*/ 1 && !cErrors; j++) 1036 { 1037 ProgressPrintf(~0, "tstAvl oGCPhys(32..2048, *1K)\n"); 1038 for (i = 32; i < 4096 && !cErrors; i++) 1039 cErrors += avlogcphysRand(i, i + _1K); 1040 for (; i <= _4M && !cErrors; i *= 2) 1041 cErrors += avlogcphysRand(i, i * 8); 1042 } 1043 1044 cErrors += avlrogcphys(); 1045 cErrors += avlul(); 1046 1047 if (!cErrors) 1048 printf("tstAvl: SUCCESS\n"); 1049 else 1050 printf("tstAvl: FAILURE - %d errors\n", cErrors); 1051 return !!cErrors; 1052 } 1053 RTTestSub(hTest, "oGCPhys(32..2048)"); 1054 for (i = 32; i < 2048; i++) 1055 if (avlogcphys(i)) 1056 break; 1057 1058 avlogcphys(_64K); 1059 avlogcphys(_512K); 1060 avlogcphys(_4M); 1061 1062 RTTestISubF("oGCPhys(32..2048, *1K)"); 1063 for (i = 32; i < 4096; i++) 1064 if (avlogcphysRand(i, i + _1K)) 1065 break; 1066 for (; i <= _4M; i *= 2) 1067 if (avlogcphysRand(i, i * 8)) 1068 break; 1069 1070 avlrogcphys(); 1071 avlul(); 1072 1073 /* 1074 * Done. 1075 */ 1076 return RTTestSummaryAndDestroy(hTest); 1077 } 1078
Note:
See TracChangeset
for help on using the changeset viewer.