kerneltest/f32test/ext/t_testext.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2005-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 the License "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 // f32test\ext\t_testext.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32math.h>
       
    19 #include "t_testext.h"
       
    20 
       
    21 CTestProxyDrive::CTestProxyDrive(CProxyDrive* aProxyDrive, CMountCB* aMount)
       
    22     : CBaseExtProxyDrive(aProxyDrive,aMount), iMount(aMount)
       
    23     {
       
    24     __PRINT(_L("CTestProxyDrive::CTestProxyDrive"));
       
    25     }
       
    26 
       
    27 CTestProxyDrive::~CTestProxyDrive()
       
    28     {
       
    29     __PRINT(_L("CTestProxyDrive::~CTestProxyDrive"));
       
    30     delete[] iMap;
       
    31     }
       
    32 
       
    33 void CTestProxyDrive::InitL()
       
    34     {
       
    35     __PRINT(_L("CTestProxyDrive::Init"));
       
    36 
       
    37     DoInitL();
       
    38 
       
    39     // Allocate bad sector bit map
       
    40     TInt size = (iTotalSectors+7) >> 3; // round up by byte
       
    41     iMap = new(ELeave) TUint8[size];
       
    42     Mem::FillZ(iMap, size);
       
    43 
       
    44     iMountInitialised = ETrue;
       
    45     }
       
    46 
       
    47 TInt CTestProxyDrive::ControlIO(const RMessagePtr2& aMessage,TInt aCommand,TAny* aParam1,TAny* aParam2)
       
    48     {
       
    49     __PRINT(_L("CTestProxyDrive::ControlIO"));
       
    50 
       
    51     TInt r = KErrNone;
       
    52 
       
    53     if (!iMountInitialised)
       
    54         return KErrNotReady;
       
    55 
       
    56     switch(aCommand+EExtCustom)
       
    57         {
       
    58         case ESetEvent:
       
    59             r = SetEvent((TInt)aParam1, (TInt)aParam2);
       
    60             break;
       
    61         
       
    62         case EMark:
       
    63             //-- mark given sector as bad
       
    64             __PRINT1(_L("CTestProxyDrive: marking sector:%d as bad"), (TInt)aParam1);
       
    65             r = Mark((TInt)aParam1);
       
    66             break;
       
    67         
       
    68         case EUnmark:
       
    69             //-- mark given sector as good
       
    70             __PRINT1(_L("CTestProxyDrive: Unmarking sector:%d"), (TInt)aParam1);
       
    71             r = Unmark((TInt)aParam1);
       
    72             break;
       
    73         
       
    74         case EUnmarkAll:
       
    75             r = UnmarkAll();
       
    76             break;
       
    77         
       
    78         case EIsMarked:
       
    79             if (IsMarked((TInt)aParam1))
       
    80                 r = aMessage.Write(3, TPckgBuf<TBool>(ETrue));
       
    81             else
       
    82                 r = aMessage.Write(3, TPckgBuf<TBool>(EFalse));
       
    83             break;
       
    84         case EDiskSize:
       
    85             r = aMessage.Write(2, TPckgBuf<TInt64>(iMount->Size()));
       
    86             break;
       
    87         default:
       
    88             r = DoControlIO(aMessage,aCommand,aParam1,aParam2);
       
    89             __PRINT2(_L("Get unknown command %d error %d"), aCommand, r);
       
    90         }
       
    91     return r;
       
    92     }
       
    93 
       
    94 TInt CTestProxyDrive::GetLastErrorInfo(TDes8 &aErrorInfo)
       
    95     {
       
    96     __PRINT(_L("CTestProxyDrive::GetLastErrorInfo"));
       
    97     TPckgBuf<TErrorInfo> errInfoBuf;
       
    98     errInfoBuf().iReasonCode = iLastErrorReason;
       
    99     errInfoBuf().iErrorPos = iSuccessBytes;
       
   100     aErrorInfo = errInfoBuf;
       
   101 
       
   102     return KErrNone;
       
   103     }
       
   104 
       
   105 TInt CTestProxyDrive::SetEvent(TInt aType, TInt aValue)
       
   106     {
       
   107     __PRINT(_L("CTestProxyDrive::SetEvent"));
       
   108 
       
   109     switch (aType)
       
   110         {
       
   111         case ENone:
       
   112             break;
       
   113         case ENext:
       
   114             iEventType = aType;
       
   115             break;
       
   116         case ERandom:
       
   117             Mark((TInt)(Math::Random() / (TReal64)KMaxTUint) * iTotalSectors);
       
   118             break;
       
   119         case EDeterministic:
       
   120             iEventType = aType;
       
   121             if (aValue <= 0)
       
   122                 return KErrArgument;
       
   123             iCount = aValue;
       
   124             break;
       
   125         default:
       
   126             return KErrArgument;
       
   127         }
       
   128     return KErrNone;
       
   129     }
       
   130 
       
   131 
       
   132 /**
       
   133     mark aSector as a bad sector by adding it to the bad sectors map
       
   134     @param  aSector sector number to mark as bad
       
   135 */
       
   136 TInt CTestProxyDrive::Mark(TInt aSector)
       
   137     {
       
   138     __PRINT1(_L("CTestProxyDrive::Mark %d"), aSector);
       
   139 
       
   140     if (aSector >= iTotalSectors)
       
   141         return KErrNone;
       
   142     if (aSector < 0)
       
   143         return KErrArgument;
       
   144     iMap[aSector>>3] = (TUint8)(iMap[aSector>>3] | (1<<(aSector & 7)));
       
   145     return KErrNone;
       
   146     }
       
   147 
       
   148 TInt CTestProxyDrive::Unmark(TInt aSector)
       
   149 //
       
   150 // Remove bad cluster aValue from list.
       
   151 //
       
   152     {
       
   153     __PRINT1(_L("CTestProxyDrive::Unmark %d"), aSector);
       
   154 
       
   155     if (aSector>=iTotalSectors || aSector<0)
       
   156         return KErrArgument;
       
   157     iMap[aSector>>3] = (TUint8)(iMap[aSector>>3] & ~(1<<(aSector & 7)));
       
   158     return KErrNone;
       
   159     }
       
   160 
       
   161 TInt CTestProxyDrive::UnmarkAll()
       
   162 //
       
   163 // Clear all bad cluster marks.
       
   164 //
       
   165     {
       
   166     __PRINT(_L("CTestProxyDrive::UnmarkAll"));
       
   167 
       
   168     Mem::FillZ(iMap, (iTotalSectors+7)>>3);
       
   169     return KErrNone;
       
   170     }
       
   171 
       
   172 TBool CTestProxyDrive::IsMarked(TInt aSector) const
       
   173 //
       
   174 // Check if cluster number is in bad cluster list.
       
   175 //
       
   176     {
       
   177     
       
   178 
       
   179     if (aSector>=iTotalSectors || aSector<0)
       
   180         return EFalse;
       
   181     
       
   182     const TBool bMarked = iMap[aSector>>3] & (1<<(aSector & 7));
       
   183     if(bMarked)
       
   184         {
       
   185         __PRINT1(_L("CTestProxyDrive::IsMarked %d"), aSector);
       
   186         }
       
   187 
       
   188     return bMarked ;
       
   189     }
       
   190 
       
   191 TBool CTestProxyDrive::CheckEvent(TInt64 aPos, TInt aLength)
       
   192     {
       
   193     //__PRINT(_L("CTestProxyDrive::CheckEvent"));
       
   194 
       
   195     if (!iMountInitialised)
       
   196         return EFalse;
       
   197 
       
   198     return DoCheckEvent(aPos, aLength);
       
   199     }