kerneltest/e32test/system/t_ctrap.cpp
changeset 247 d8d70de2bd36
parent 109 b3a1d9898418
child 293 0659d0e1a03c
equal deleted inserted replaced
201:43365a9b78a3 247:d8d70de2bd36
    37 // closed when it goes out of scope, push it on the cleanup stack,
    37 // closed when it goes out of scope, push it on the cleanup stack,
    38 // verify cleanup results are as expected.
    38 // verify cleanup results are as expected.
    39 // - Test that the Cleanup stack can go re-entrant.
    39 // - Test that the Cleanup stack can go re-entrant.
    40 // - Ensure that the stack is properly balanced with and without
    40 // - Ensure that the stack is properly balanced with and without
    41 // leaving.
    41 // leaving.
       
    42 // - Test creating cleanup with CCleanup::NewL in normal
       
    43 // memory conditions and condition where heap is full (panic)
    42 // Platforms/Drives/Compatibility:
    44 // Platforms/Drives/Compatibility:
    43 // All.
    45 // All.
    44 // Assumptions/Requirement/Pre-requisites:
    46 // Assumptions/Requirement/Pre-requisites:
    45 // Failures and causes:
    47 // Failures and causes:
    46 // Base Port information:
    48 // Base Port information:
    60 	const TInt KInitialCountAll=3;
    62 	const TInt KInitialCountAll=3;
    61 #endif
    63 #endif
    62 
    64 
    63 const TInt KLeaveValue=0x12345678;
    65 const TInt KLeaveValue=0x12345678;
    64 const TInt KMaxAlloc=6;	
    66 const TInt KMaxAlloc=6;	
       
    67 const TInt KTableSize = 1000;
    65 
    68 
    66 static const TInt KHeapSize = 0x2000;
    69 static const TInt KHeapSize = 0x2000;
       
    70 
    67 
    71 
    68 enum TWhat {EPop,EPopAndDestroy,EMulti,ENull};
    72 enum TWhat {EPop,EPopAndDestroy,EMulti,ENull};
    69 
    73 
    70 class CTest : public CBase
    74 class CTest : public CBase
    71 	{
    75 	{
  1536 
  1540 
  1537 	delete pC;
  1541 	delete pC;
  1538 	test.End();
  1542 	test.End();
  1539 	}
  1543 	}
  1540 
  1544 
       
  1545 void testCCleanupNewL()
       
  1546 	{
       
  1547 	// don't want just in time debugging as we trap panics
       
  1548 	TBool justInTime=User::JustInTime(); 
       
  1549 	User::SetJustInTime(EFalse); 
       
  1550 
       
  1551 	// no need to test otherwise, since this calls only
       
  1552 	// CCleanup::New and that has been tested.
       
  1553 	test.Start(_L("Create cleanup NewL"));
       
  1554 	CCleanup* pC=CCleanup::NewL();
       
  1555 	test(pC!=NULL);
       
  1556 	delete pC;
       
  1557 
       
  1558 	TAny* ptrTable[KTableSize];
       
  1559 	TInt allocSize=sizeof(CCleanup);
       
  1560 	TAny* ptr=0;
       
  1561 
       
  1562 	__UHEAP_MARK;
       
  1563 
       
  1564 	TInt i=0;
       
  1565 	// first alloc 4Kb bits
       
  1566 	do
       
  1567 		{
       
  1568 		ptr=User::Alloc(0x1000);
       
  1569 		if(ptr!=NULL)
       
  1570 			{
       
  1571 			ptrTable[i]=ptr;
       
  1572 			i++;
       
  1573 			}
       
  1574 		}
       
  1575 		while (ptr!=NULL && i<KTableSize);
       
  1576 
       
  1577 	// then eat memory with size of CCleanup object granurality
       
  1578 	do
       
  1579 		{
       
  1580 		ptr=User::Alloc(allocSize);
       
  1581 		if(ptr!=NULL)
       
  1582 			{
       
  1583 			ptrTable[i]=ptr;
       
  1584 			i++;
       
  1585 			}
       
  1586 		}
       
  1587 		while (ptr!=NULL && i<KTableSize);
       
  1588 	
       
  1589 	i--; // last one failed, so lets adjust this to last successfull entry
       
  1590 
       
  1591 	TInt r=KErrNone;
       
  1592 	test.Next(_L("Create cleanup NewL while no room in heap"));
       
  1593 	TRAP(r,pC=CCleanup::NewL());
       
  1594 	test_Equal(KErrNoMemory,r);
       
  1595 
       
  1596 	for (;i>=0;i--)
       
  1597 		{
       
  1598 		User::Free(ptrTable[i]);
       
  1599 		}
       
  1600 	
       
  1601 	__UHEAP_MARKEND;
       
  1602 
       
  1603 	//restore settings
       
  1604 	User::SetJustInTime(justInTime); 
       
  1605 
       
  1606 	test.End();
       
  1607 	}
       
  1608 
  1541 GLDEF_C TInt E32Main()
  1609 GLDEF_C TInt E32Main()
  1542     {
  1610     {
  1543 	test.Title();
  1611 	test.Title();
  1544 	
  1612 	
  1545 	test.Start(_L("Test destructor causing stack reallocation"));
  1613 	test.Start(_L("Test destructor causing stack reallocation"));
  1595 	testStackBalance();
  1663 	testStackBalance();
  1596 
  1664 
  1597 	test.Next(_L("Test TRAP_IGNORE"));
  1665 	test.Next(_L("Test TRAP_IGNORE"));
  1598 	testTrapIgnore();
  1666 	testTrapIgnore();
  1599 
  1667 
       
  1668 	test.Next(_L("Test CCleanup::NewL"));
       
  1669 	testCCleanupNewL();
       
  1670 
       
  1671 	delete pT;
       
  1672 
  1600 	test.End();
  1673 	test.End();
  1601 	return(0);
  1674 	return(0);
  1602     }
  1675     }
  1603 
  1676