818 |
819 |
819 void testNotifiers() |
820 void testNotifiers() |
820 { |
821 { |
821 RGobbler gobbler; |
822 RGobbler gobbler; |
822 TInt r = gobbler.Open(); |
823 TInt r = gobbler.Open(); |
823 test(r==KErrNone); |
824 test_KErrNone(r); |
824 TUint32 taken = gobbler.GobbleRAM(128*1024*1024); |
825 TUint32 taken = gobbler.GobbleRAM(128*1024*1024); |
825 test.Printf(_L("Gobbled: %dK\n"), taken/1024); |
826 test.Printf(_L("Gobbled: %dK\n"), taken/1024); |
826 test.Printf(_L("Free RAM 0x%08X bytes\n"),FreeRam()); |
827 test.Printf(_L("Free RAM 0x%08X bytes\n"),FreeRam()); |
827 |
828 |
828 test.Next(_L("Create thread")); |
829 test.Next(_L("Create thread")); |
829 r=NtfThrd.Create(KNotifierThreadName,NotifierThread,KDefaultStackSize,NULL,NULL); |
830 r=NtfThrd.Create(KNotifierThreadName,NotifierThread,KDefaultStackSize,NULL,NULL); |
830 test(r==KErrNone); |
831 test_KErrNone(r); |
831 NtfThrd.SetPriority(EPriorityMore); |
832 NtfThrd.SetPriority(EPriorityMore); |
832 NtfThrd.Resume(); |
833 NtfThrd.Resume(); |
833 test.Next(_L("Check for initial notifier")); |
834 test.Next(_L("Check for initial notifier")); |
834 CheckNotifierCount(1,1); |
835 CheckNotifierCount(1,1); |
835 TInt free=FreeRam(); |
836 TInt free=FreeRam(); |
836 test.Printf(_L("Free RAM: %dK\n"),free/1024); |
837 test.Printf(_L("Free RAM: %dK\n"),free/1024); |
837 test(free>=1048576); |
838 test_Value(free, free >= 1048576); |
838 test.Next(_L("Set thresholds")); |
839 test.Next(_L("Set thresholds")); |
839 r=UserSvr::SetMemoryThresholds(65536,524288); // low=64K good=512K |
840 r=UserSvr::SetMemoryThresholds(65536,524288); // low=64K good=512K |
840 test(r==KErrNone); |
841 test_KErrNone(r); |
841 test.Next(_L("Create chunk")); |
842 test.Next(_L("Create chunk")); |
842 // Chunk must not be paged otherwise it will not effect the amount |
843 // Chunk must not be paged otherwise it will not effect the amount |
843 // of free ram reported plus on h4 swap size is less than the total ram. |
844 // of free ram reported plus on h4 swap size is less than the total ram. |
|
845 TInt totalRam; |
|
846 test_KErrNone(HAL::Get(HAL::EMemoryRAM, totalRam)); |
844 TChunkCreateInfo createInfo; |
847 TChunkCreateInfo createInfo; |
845 createInfo.SetNormal(0, free+2097152); |
848 createInfo.SetNormal(0, totalRam); |
846 createInfo.SetPaging(TChunkCreateInfo::EUnpaged); |
849 createInfo.SetPaging(TChunkCreateInfo::EUnpaged); |
847 RChunk c; |
850 RChunk c; |
848 test_KErrNone(c.Create(createInfo)); |
851 test_KErrNone(c.Create(createInfo)); |
849 const TInt KBufferSpace = 768*1024; // 768K buffer |
852 const TInt KBufferSpace = 768*1024; // 768K buffer |
850 CheckNotifierCount(1,1); |
853 CheckNotifierCount(1,1); |
856 test.Printf(_L("Free RAM: %dK\n"),free2/1024); |
859 test.Printf(_L("Free RAM: %dK\n"),free2/1024); |
857 test(free2<=KBufferSpace); |
860 test(free2<=KBufferSpace); |
858 TInt free3=free-(KBufferSpace-free2); // this accounts for space used by page tables |
861 TInt free3=free-(KBufferSpace-free2); // this accounts for space used by page tables |
859 test.Next(_L("Leave 32K")); |
862 test.Next(_L("Leave 32K")); |
860 r=c.Adjust(free3-32768); // leave 32K |
863 r=c.Adjust(free3-32768); // leave 32K |
861 test(r==KErrNone); |
864 test_KErrNone(r); |
862 CheckNotifierCount(2,1); // should get notifier |
865 CheckNotifierCount(2,1); // should get notifier |
863 test.Next(_L("Leave 28K")); |
866 test.Next(_L("Leave 28K")); |
864 r=c.Adjust(free3-28672); // leave 28K |
867 r=c.Adjust(free3-28672); // leave 28K |
865 test(r==KErrNone); |
868 test_KErrNone(r); |
866 CheckNotifierCount(2,1); // shouldn't get another notifier |
869 CheckNotifierCount(2,1); // shouldn't get another notifier |
867 test.Next(_L("Ask for too much")); |
870 test.Next(_L("Ask for too much")); |
868 r=c.Adjust(free3+4096); // try to get more than available |
871 r=c.Adjust(totalRam); // try to get more than available |
869 test(r==KErrNoMemory); |
872 test_Equal(KErrNoMemory, r); |
870 CheckNotifierCount(2,2); // should get another notifier |
873 CheckNotifierCount(2,2); // should get another notifier |
871 test.Next(_L("Leave 128K")); |
874 test.Next(_L("Leave 128K")); |
872 r=c.Adjust(free3-131072); // leave 128K |
875 r=c.Adjust(free3-131072); // leave 128K |
873 test(r==KErrNone); |
876 test_KErrNone(r);; |
874 CheckNotifierCount(2,2); // shouldn't get another notifier |
877 CheckNotifierCount(2,2); // shouldn't get another notifier |
875 test.Next(_L("Leave 640K")); |
878 test.Next(_L("Leave 640K")); |
876 r=c.Adjust(free3-655360); // leave 640K |
879 r=c.Adjust(free3-655360); // leave 640K |
877 test(r==KErrNone); |
880 test_KErrNone(r); |
878 CheckNotifierCount(3,2); // should get another notifier |
881 CheckNotifierCount(3,2); // should get another notifier |
879 test.Next(_L("Leave 1M")); |
882 test.Next(_L("Leave 1M")); |
880 r=c.Adjust(free3-1048576); // leave 1M |
883 r=c.Adjust(free3-1048576); // leave 1M |
881 test(r==KErrNone); |
884 test_KErrNone(r); |
882 CheckNotifierCount(3,2); // shouldn't get another notifier |
885 CheckNotifierCount(3,2); // shouldn't get another notifier |
883 test.Next(_L("Ask for too much")); |
886 test.Next(_L("Ask for too much")); |
884 r=c.Adjust(free3+4096); // try to get more than available |
887 r=c.Adjust(totalRam); // try to get more than available |
885 test(r==KErrNoMemory); |
888 test_Equal(KErrNoMemory, r); |
886 |
889 |
887 TInt notifierCount = 3; |
890 TInt notifierCount = 3; |
888 if(MemModel==EMemModelTypeFlexible) |
891 if(MemModel==EMemModelTypeFlexible) |
889 { |
892 { |
890 // on flexible memory model, we get memory changed notifiers |
893 // on flexible memory model, we get memory changed notifiers |