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