kerneltest/e32test/mmu/t_shbuf.cpp
branchRCL_3
changeset 44 3e88ff8f41d5
parent 43 c1f20ce4abcf
equal deleted inserted replaced
43:c1f20ce4abcf 44:3e88ff8f41d5
    36 
    36 
    37 const TInt KTestPoolSizeInBytes = 1 << 20; // 1MB
    37 const TInt KTestPoolSizeInBytes = 1 << 20; // 1MB
    38 const TInt BufferSize[] = {128, 853, 4096, 5051, 131072, 1, 0}; // Last element must be 0
    38 const TInt BufferSize[] = {128, 853, 4096, 5051, 131072, 1, 0}; // Last element must be 0
    39 
    39 
    40 const TInt* PtrBufSize;
    40 const TInt* PtrBufSize;
    41 
       
    42 static TInt ThreadCounter = 0;
       
    43 
    41 
    44 RShBufTestChannel Ldd;
    42 RShBufTestChannel Ldd;
    45 
    43 
    46 _LIT(KTestSlave, "SLAVE");
    44 _LIT(KTestSlave, "SLAVE");
    47 _LIT(KTestLowSpaceSemaphore, "LowSpaceSemaphore");
    45 _LIT(KTestLowSpaceSemaphore, "LowSpaceSemaphore");
   622 	RArray<RShBuf> bufarray;
   620 	RArray<RShBuf> bufarray;
   623 	do
   621 	do
   624 		{
   622 		{
   625 		RShBuf buf;
   623 		RShBuf buf;
   626 		r = buf.Alloc(aPool);
   624 		r = buf.Alloc(aPool);
   627 		RDebug::Printf("alloc buf %d returned %d", bufarray.Count(), r);
       
   628 		if (r==KErrNoMemory && KTestPoolSizeInBufs>bufarray.Count())
   625 		if (r==KErrNoMemory && KTestPoolSizeInBufs>bufarray.Count())
   629 			{
   626 			{
   630 			// try again after a delay, to allow for background resource allocation
   627 			// try again after a delay, to allow for background resource allocation
   631 			
   628 			
   632 			User::After(1000000);
   629 			User::After(1000000);
   633 			r = buf.Alloc(aPool);
   630 			r = buf.Alloc(aPool);
   634 			RDebug::Printf("re-alloc buf %d returned %d", bufarray.Count(), r);
       
   635 			}
   631 			}
   636 		if (!r)
   632 		if (!r)
   637 			{
   633 			{
   638 			r = bufarray.Append(buf);
   634 			r = bufarray.Append(buf);
   639 			test_KErrNone(r);
   635 			test_KErrNone(r);
   647 	TInt n = bufarray.Count();
   643 	TInt n = bufarray.Count();
   648 	while (n)
   644 	while (n)
   649 		{
   645 		{
   650 		bufarray[--n].Close();
   646 		bufarray[--n].Close();
   651 		}
   647 		}
   652 	RDebug::Printf("closed bufs");
       
   653 
   648 
   654 	User::After(500000);
   649 	User::After(500000);
   655 
   650 
   656 	// Do it once more
   651 	// Do it once more
   657 	n = 0;
   652 	n = 0;
   658 	while (n<bufarray.Count())
   653 	while (n<bufarray.Count())
   659 		{
   654 		{
   660 		r = bufarray[n].Alloc(aPool);
   655 		r = bufarray[n].Alloc(aPool);
   661 		RDebug::Printf("alloc buf %d returned %d", n, r);
       
   662 		if (r==KErrNoMemory)
   656 		if (r==KErrNoMemory)
   663 			{
   657 			{
   664 			// try again after a delay, to allow for background resource allocation
   658 			// try again after a delay, to allow for background resource allocation
   665 			User::After(1000000);
   659 			User::After(1000000);
   666 			r = bufarray[n].Alloc(aPool);
   660 			r = bufarray[n].Alloc(aPool);
   667 			RDebug::Printf("re-alloc buf %d returned %d", n, r);
       
   668 			}
   661 			}
   669 		test_Assert(r == KErrNone, test.Printf(_L("n=%d r=%d\n"), n, r));
   662 		test_Assert(r == KErrNone, test.Printf(_L("n=%d r=%d\n"), n, r));
   670 		if(aligned)
   663 		if(aligned)
   671 			test(CheckNotFillShBuf(bufarray[n],0x99));
   664 			test(CheckNotFillShBuf(bufarray[n],0x99));
   672 		++n;
   665 		++n;
   673 		}
   666 		}
   674 
   667 
   675 	RShBuf extrabuf;
   668 	RShBuf extrabuf;
   676 	r = extrabuf.Alloc(aPool);
   669 	r = extrabuf.Alloc(aPool);
   677 	RDebug::Printf("alloc extra buf returned %d", r);
       
   678 	test_Equal(KErrNoMemory, r);
   670 	test_Equal(KErrNoMemory, r);
   679 
   671 
   680 	while (n)
   672 	while (n)
   681 		{
   673 		{
   682 		bufarray[--n].Close();
   674 		bufarray[--n].Close();
   683 		}
   675 		}
   684 	RDebug::Printf("closed bufs");
       
   685 
   676 
   686 	bufarray.Close();
   677 	bufarray.Close();
   687 	}
   678 	}
   688 
   679 
   689 void AllocateKernelMax()
   680 void AllocateKernelMax()
  1879  * CancelLowSpaceNotification() no longer panic()s if it can't find the
  1870  * CancelLowSpaceNotification() no longer panic()s if it can't find the
  1880  * notification, so this routine not currently called.
  1871  * notification, so this routine not currently called.
  1881  */
  1872  */
  1882 void RequestLowSpacePanic(RShPool& aPool, TUint aThreshold1, TUint aThreshold2, TTestLowSpaceType aType, TInt aLine)
  1873 void RequestLowSpacePanic(RShPool& aPool, TUint aThreshold1, TUint aThreshold2, TTestLowSpaceType aType, TInt aLine)
  1883 	{
  1874 	{
  1884 	TBuf<40> threadname;
  1875 	static TInt count = 0;
  1885 	threadname.Format(_L("ThreadLowSpacePanic%d"), ++ThreadCounter);
  1876 	count++;
  1886 	test.Printf(_L("RequestLowSpacePanic@%d(%S)\n"), aLine, &threadname);
  1877 	test.Printf(_L("RequestLowSpacePanic@%d(%d)\n"), aLine, count);
  1887 	TBool jit = User::JustInTime();
  1878 	TBool jit = User::JustInTime();
  1888 	User::SetJustInTime(EFalse);
  1879 	User::SetJustInTime(EFalse);
  1889 	TInt expectedpaniccode = KErrNone;	// Initialised to silence compiler warnings
  1880 	TInt expectedpaniccode = KErrNone;	// Initialised to silence compiler warnings
  1890 	switch (aType)
  1881 	switch (aType)
  1891 		{
  1882 		{
  1904 	targs.iType = aType;
  1895 	targs.iType = aType;
  1905 	//
  1896 	//
  1906 	RThread threadpanic;
  1897 	RThread threadpanic;
  1907 	TRequestStatus threadpanicrs;
  1898 	TRequestStatus threadpanicrs;
  1908 	TInt r;
  1899 	TInt r;
       
  1900 	TBuf<30> threadname;
       
  1901 	threadname.Format(_L("ThreadLowSpacePanic%d"), count);
  1909 	r = threadpanic.Create(threadname, ThreadLowSpacePanic, KDefaultStackSize, KMinHeapSize, 1 << 20, (TAny*) &targs);
  1902 	r = threadpanic.Create(threadname, ThreadLowSpacePanic, KDefaultStackSize, KMinHeapSize, 1 << 20, (TAny*) &targs);
  1910 	test_KErrNone(r);
  1903 	test_KErrNone(r);
  1911 	threadpanic.Logon(threadpanicrs);
  1904 	threadpanic.Logon(threadpanicrs);
  1912 	threadpanic.Resume();
  1905 	threadpanic.Resume();
  1913 	User::WaitForRequest(threadpanicrs);
  1906 	User::WaitForRequest(threadpanicrs);
  1930 	RTimer timer;
  1923 	RTimer timer;
  1931 	r = timer.CreateLocal();
  1924 	r = timer.CreateLocal();
  1932 	test_KErrNone(r);
  1925 	test_KErrNone(r);
  1933 	RThread thread;
  1926 	RThread thread;
  1934 	TRequestStatus threadrs;
  1927 	TRequestStatus threadrs;
  1935 	TBuf<40> threadname;
  1928 	r = thread.Create(_L("ThreadNotifications"), ThreadNotifications, KDefaultStackSize, KMinHeapSize, 1 << 20, (TAny*) &aPool);
  1936 	threadname.Format(_L("ThreadNotifications%d"), ++ThreadCounter);
       
  1937 	test.Printf(_L("Create %S\n"), &threadname);
       
  1938 	r = thread.Create(threadname, ThreadNotifications, KDefaultStackSize, KMinHeapSize, 1 << 20, (TAny*) &aPool);
       
  1939 	test_KErrNone(r);
  1929 	test_KErrNone(r);
  1940 	thread.SetPriority(EPriorityMore);
  1930 	thread.SetPriority(EPriorityMore);
  1941 	thread.Logon(threadrs);
  1931 	thread.Logon(threadrs);
  1942 
  1932 
  1943 	test.Printf(_L("Low space notification\n"));
  1933 	test.Printf(_L("Low space notification\n"));
  2085 	TInt r;
  2075 	TInt r;
  2086 
  2076 
  2087 	RSemaphore sem;
  2077 	RSemaphore sem;
  2088 	r = sem.CreateGlobal(KTestLowSpaceSemaphore, 0);
  2078 	r = sem.CreateGlobal(KTestLowSpaceSemaphore, 0);
  2089 	test_KErrNone(r);
  2079 	test_KErrNone(r);
  2090 
       
  2091 	TBuf<40> threadname;
       
  2092 	threadname.Format(_L("ThreadCancelNotifications%d"), ++ThreadCounter);
       
  2093 	test.Printf(_L("Create %S\n"), &threadname);
       
  2094 	RThread thread;
  2080 	RThread thread;
  2095 	TRequestStatus threadrs;
  2081 	TRequestStatus threadrs;
  2096 	r = thread.Create(threadname, ThreadNotifications, KDefaultStackSize, KMinHeapSize, 1 << 20, (TAny*) &aPool);
  2082 	r = thread.Create(_L("ThreadCancelNotifications"), ThreadNotifications, KDefaultStackSize, KMinHeapSize, 1 << 20, (TAny*) &aPool);
  2097 	test_KErrNone(r);
  2083 	test_KErrNone(r);
  2098 	thread.SetPriority(EPriorityLess);
  2084 	thread.SetPriority(EPriorityLess);
  2099 	thread.Logon(threadrs);
  2085 	thread.Logon(threadrs);
  2100 
  2086 
  2101 	test.Printf(_L("Cancel low space notifications\n"));
  2087 	test.Printf(_L("Cancel low space notifications\n"));