featuremgmt/featuremgr/test/rtest/src/t_fmgrstartup.cpp
branchRCL_3
changeset 8 fa9941cf3867
child 10 31a8f755b7fe
equal deleted inserted replaced
6:5ffdb8f2067f 8:fa9941cf3867
       
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32test.h>
       
    17 #include <bautils.h>
       
    18 #include "featmgrserver.h"
       
    19 #include "featmgrconfiguration.h"
       
    20 
       
    21 static TInt TheProcessHandleCount = 0;
       
    22 static TInt TheThreadHandleCount = 0;
       
    23 static TInt TheAllocatedCellsCount = 0;
       
    24 
       
    25 #ifdef EXTENDED_FEATURE_MANAGER_TEST
       
    26 static const TInt KBurstRate = 20;
       
    27 #endif
       
    28 
       
    29 ///////////////////////////////////////////////////////////////////////////////////////
       
    30 
       
    31 static RTest TheTest(_L("t_fmgrstartup"));
       
    32 _LIT( KZOrgFeaturesFile, "Z:\\Private\\10205054\\features.dat" );
       
    33 #ifdef EXTENDED_FEATURE_MANAGER_TEST
       
    34 _LIT( KZFeaturesFile, "C:\\Private\\102836E5\\features.dat" );
       
    35 _LIT( KZFeaturesDir, "C:\\Private\\102836E5\\" );
       
    36 #else
       
    37 _LIT( KZFeaturesFile, "Z:\\Private\\10205054\\features.dat" );
       
    38 _LIT( KZFeaturesDir, "Z:\\Private\\10205054\\" );
       
    39 #endif // EXTENDED_FEATURE_MANAGER_TEST
       
    40 
       
    41 ///////////////////////////////////////////////////////////////////////////////////////
       
    42 
       
    43 //Deletes all created test files.
       
    44 void DestroyTestEnv()
       
    45     {
       
    46     }
       
    47 
       
    48 ///////////////////////////////////////////////////////////////////////////////////////
       
    49 ///////////////////////////////////////////////////////////////////////////////////////
       
    50 //Test macros and functions
       
    51 void Check1(TInt aValue, TInt aLine)
       
    52     {
       
    53     if(!aValue)
       
    54         {
       
    55         DestroyTestEnv();
       
    56         RDebug::Print(_L("*** Expression evaluated to false. Line %d\r\n"), aLine);
       
    57         TheTest(EFalse, aLine);
       
    58         }
       
    59     }
       
    60 void Check2(TInt aValue, TInt aExpected, TInt aLine)
       
    61     {
       
    62     if(aValue != aExpected)
       
    63         {
       
    64         DestroyTestEnv();
       
    65         RDebug::Print(_L("*** Expected: %d, got: %d. Line %d\r\n"), aExpected, aValue, aLine);
       
    66         TheTest(EFalse, aLine);
       
    67         }
       
    68     }
       
    69 #define TEST(arg) ::Check1((arg), __LINE__)
       
    70 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__)
       
    71 
       
    72 ///////////////////////////////////////////////////////////////////////////////////////
       
    73 
       
    74 static void MarkHandles()
       
    75     {
       
    76     RThread().HandleCount(TheProcessHandleCount, TheThreadHandleCount);
       
    77     }
       
    78 
       
    79 static void MarkAllocatedCells()
       
    80     {
       
    81     TheAllocatedCellsCount = User::CountAllocCells();
       
    82     }
       
    83 
       
    84 static void CheckAllocatedCells()
       
    85     {
       
    86     TInt allocatedCellsCount = User::CountAllocCells();
       
    87     TEST2(allocatedCellsCount, TheAllocatedCellsCount);
       
    88     }
       
    89 
       
    90 static void CheckHandles()
       
    91     {
       
    92     TInt endProcessHandleCount;
       
    93     TInt endThreadHandleCount;
       
    94     
       
    95     RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
       
    96 
       
    97     TEST2(TheProcessHandleCount, endProcessHandleCount);
       
    98     TEST2(TheThreadHandleCount, endThreadHandleCount);
       
    99     }
       
   100 
       
   101 static void OomPreStep(TInt aFailingAllocationNo)
       
   102     {
       
   103     aFailingAllocationNo = aFailingAllocationNo; //to silent the warning in urel build
       
   104     MarkHandles();
       
   105     MarkAllocatedCells();
       
   106     __UHEAP_MARK;
       
   107     __UHEAP_SETBURSTFAIL(RAllocator::EBurstFailNext, aFailingAllocationNo, KBurstRate);
       
   108     }
       
   109 
       
   110 static void OomPostStep()
       
   111     {
       
   112     __UHEAP_RESET;
       
   113     __UHEAP_MARKEND;
       
   114     CheckAllocatedCells();
       
   115     CheckHandles();
       
   116     }
       
   117 
       
   118 ///////////////////////////////////////////////////////////////////////////////////////
       
   119 
       
   120 static void CreateAndDestroyFeatMgrServerL()
       
   121     {
       
   122     CFeatMgrServer* server = CFeatMgrServer::NewLC(KServerCActivePriority);
       
   123     CleanupStack::PopAndDestroy(server);
       
   124     }
       
   125 
       
   126 /**
       
   127 @SYMTestCaseID          PDS-EFM-CT-4109
       
   128 @SYMTestCaseDesc        
       
   129 @SYMTestPriority        High
       
   130 @SYMTestActions         
       
   131 @SYMTestExpectedResults Test must not fail
       
   132 @SYMDEF                 DEF144262
       
   133 */
       
   134 void FeatMgrServerStartupOomTest()
       
   135 //TODO - panics in CFeatMgrServer::LoadPluginsL() because the error is KErrNoMemory
       
   136     {
       
   137     TInt err = KErrNoMemory;
       
   138     TInt failingAllocationNo = 0;
       
   139     TheTest.Printf(_L("Iteration:\r\n"));
       
   140     while(err == KErrNoMemory)
       
   141         {
       
   142         TheTest.Printf(_L(" %d"), ++failingAllocationNo);
       
   143         OomPreStep(failingAllocationNo);
       
   144         TRAP(err, CreateAndDestroyFeatMgrServerL());
       
   145         OomPostStep();
       
   146         }
       
   147     if(err != KErrNoMemory)
       
   148         {
       
   149         TEST2(err, KErrNone);   
       
   150         }
       
   151     TheTest.Printf(_L("\r\n===OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
       
   152     }
       
   153 
       
   154 /**
       
   155 @SYMTestCaseID          PDS-EFM-CT-4110
       
   156 @SYMTestCaseDesc        
       
   157 @SYMTestPriority        High
       
   158 @SYMTestActions         
       
   159 @SYMTestExpectedResults Test must not fail
       
   160 @SYMDEF                 DEF144262
       
   161 */
       
   162 void FeatMgrServerStartupFileIoTest()
       
   163     {
       
   164     RFs fs;
       
   165     TInt err = fs.Connect();
       
   166     TEST2(err, KErrNone);
       
   167     err = KErrNotFound;
       
   168     TInt cnt=1;
       
   169     for(;err<KErrNone;++cnt)
       
   170         {
       
   171         TheTest.Printf(_L("===Iteration %d. Simulated error:\r\n"), cnt);       
       
   172         for (TInt fsError=KErrNotFound;fsError>=KErrBadName;--fsError)
       
   173             {
       
   174             if(fsError == KErrNotFound || fsError == KErrCorrupt || fsError == KErrPathNotFound || fsError == KErrEof)
       
   175                 {
       
   176                 continue;//TODO: the server code panics
       
   177                 }
       
   178             TheTest.Printf(_L("%d "), fsError);
       
   179             (void)fs.SetErrorCondition(fsError, cnt);
       
   180             TRAP(err, CreateAndDestroyFeatMgrServerL());
       
   181             (void)fs.SetErrorCondition(KErrNone);
       
   182             }
       
   183         TheTest.Printf(_L("\r\n"));
       
   184         }
       
   185     fs.Close();
       
   186     TheTest.Printf(_L("\r\n===File I/O error simulation test succeeded on iteration %d===\r\n"), cnt);
       
   187     }
       
   188 
       
   189 void PreTest()
       
   190     {
       
   191     // Connect session
       
   192     RFs fsSession;
       
   193     User::LeaveIfError(fsSession.Connect()); 
       
   194     
       
   195     TEntry entry;
       
   196     TInt err = fsSession.Entry(KZFeaturesDir, entry);
       
   197     if (err == KErrNotFound)
       
   198         {
       
   199         err = fsSession.MkDir(KZFeaturesDir);
       
   200         }
       
   201     TEST2 (err, KErrNone);
       
   202     err = BaflUtils::CopyFile(fsSession, KZOrgFeaturesFile, KZFeaturesDir);
       
   203     TEST2 (err, KErrNone);
       
   204     
       
   205     // close file server session
       
   206     fsSession.Close();
       
   207 
       
   208     }
       
   209 
       
   210 void PostTest()
       
   211     {
       
   212     // Connect session
       
   213     RFs fsSession;
       
   214     User::LeaveIfError(fsSession.Connect()); 
       
   215     
       
   216     TEntry entry;
       
   217     TInt err = fsSession.Entry(KZFeaturesDir, entry);
       
   218     if (err == KErrNone)
       
   219         {
       
   220         err = BaflUtils::DeleteFile(fsSession,KZFeaturesFile);
       
   221         TEST2 (err, KErrNone);
       
   222         
       
   223         }
       
   224     TEST2 (err, KErrNone);
       
   225     
       
   226     // close file server session
       
   227     fsSession.Close();
       
   228     }
       
   229 
       
   230 void DoTestsL()
       
   231     {
       
   232     CActiveScheduler* scheduler = new CActiveScheduler;
       
   233     TEST(scheduler != NULL);
       
   234     CActiveScheduler::Install(scheduler);
       
   235     
       
   236     TheTest.Start(_L("@SYMTestCaseID:PDS-EFM-CT-4109 CFeatMgrServer::NewLC() OOM test"));
       
   237     PreTest();
       
   238     FeatMgrServerStartupOomTest();
       
   239 
       
   240     TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4110 CFeatMgrServer::NewLC() file I/O error simulation test"));
       
   241     FeatMgrServerStartupFileIoTest();
       
   242     PostTest();
       
   243     
       
   244     delete scheduler;
       
   245     }
       
   246 
       
   247 TInt E32Main()
       
   248     {
       
   249     TheTest.Title();
       
   250     
       
   251     CTrapCleanup* tc = CTrapCleanup::New();
       
   252     TheTest(tc != NULL);
       
   253     
       
   254     __UHEAP_MARK;
       
   255     
       
   256     TRAPD(err, DoTestsL());
       
   257     DestroyTestEnv();
       
   258     TEST2(err, KErrNone);
       
   259 
       
   260     __UHEAP_MARKEND;
       
   261     
       
   262     TheTest.End();
       
   263     TheTest.Close();
       
   264     
       
   265     delete tc;
       
   266 
       
   267     User::Heap().Check();
       
   268     return KErrNone;
       
   269     }