os/kernelhwsrv/kerneltest/f32test/shostmassstorage/msman/test/t_msbot.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 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 //
    15 
    16 
    17 #include <e32def.h>
    18 #include <e32cmn.h>
    19 #include <e32base.h>
    20 #include <f32file.h>
    21 #include <e32cons.h>
    22 #include <e32debug.h>
    23 #define __E32TEST_EXTENSION__
    24 #include <e32test.h>
    25 #include <e32property.h>
    26 
    27 #include "cblockdevicetester.h"
    28 #include "cmsdrive.h"
    29 #include "tmsprintdrive.h"
    30 #include "ttestutils.h"
    31 #include "tmslog.h"
    32 
    33 extern CMsDrive* msDrive;
    34 
    35 RTest test(_L("T_MSBOT"));
    36 RFs fsSession;
    37 
    38 
    39 class RMassStoragePublisher
    40     {
    41 public:
    42     enum TPropertyKeys
    43         {
    44         KBotResetProperty = 1,
    45         KStallProperty = 2
    46         };
    47 
    48     RMassStoragePublisher(TPropertyKeys aKey);
    49     ~RMassStoragePublisher();
    50 
    51     TInt Count();
    52     TSecureId Sid() const;
    53 
    54 private:
    55     TPropertyKeys iKey;
    56     };
    57 
    58 TSecureId RMassStoragePublisher::Sid() const
    59     {
    60     RProcess process;
    61     return process.SecureId();
    62     }
    63 
    64 RMassStoragePublisher::RMassStoragePublisher(TPropertyKeys aKey)
    65 :   iKey(aKey)
    66     {
    67     _LIT_SECURITY_POLICY_PASS(KHostMassStoragePolicy);
    68     TInt res = RProperty::Define(iKey,
    69                                  RProperty::EInt,
    70                                  KHostMassStoragePolicy,
    71                                  KHostMassStoragePolicy);
    72 
    73     test(res == KErrNone);
    74     // reset the property flag
    75     res = RProperty::Set(Sid(), iKey, 0);
    76     }
    77 
    78 
    79 RMassStoragePublisher::~RMassStoragePublisher()
    80     {
    81     TInt res = RProperty::Delete(iKey);
    82     test(res == KErrNone || res == KErrNotFound);
    83     }
    84 
    85 
    86 TInt RMassStoragePublisher::Count()
    87     {
    88     TInt value;
    89     TInt res = RProperty::Get(Sid(), iKey, value);
    90     test_KErrNone(res);
    91     RDebug::Printf("RMassStoragePublisher[%d] res=%d value=%d", iKey, res, value);
    92     return value;
    93     }
    94 
    95 
    96 
    97 /*
    98 class TTestMsBlock
    99     {
   100 public:
   101     void tFileAccess();
   102     void tBlockAccess();
   103     void tRawAccess();
   104     void tLastLbaAccessL();
   105     };
   106 */
   107 
   108 class CTestBot: public CBase
   109     {
   110 public:
   111     static CTestBot* NewL();
   112     ~CTestBot();
   113 private:
   114     void ConstructL();
   115     CTestBot();
   116 
   117 public:
   118     void tTagMismatch();
   119     void tInvalidSignature();
   120     // No Data
   121     void tNoDataStallCsw();
   122     void tNoDataPhaseError();
   123     // Data OUT
   124     void tDoStallCsw();
   125     void tDoStallData();
   126     void tDoPhaseError();
   127     void tDoResidue();
   128     // Data In
   129     void tDiStallCsw();
   130     void tDiStallData();
   131     void tDiPhaseError();
   132     void tDiResidue();
   133 
   134 private:
   135     void CswResetRecovery(CBotTester::TTestCase aTestCase, const TDesC& aTestName);
   136     void NoDataResetRecovery(CBotTester::TTestCase aTestCase, const TDesC& aTestName);
   137     void NoDataClearStall(CBotTester::TTestCase aTestCase, const TDesC& aTestName);
   138 
   139     void DataOutClearStall(CBotTester::TTestCase aTestCase, const TDesC& aTestName);
   140     void DataInClearStall(CBotTester::TTestCase aTestCase, const TDesC& aTestName);
   141 
   142 private:
   143     CBotTester* iBotTester;
   144     };
   145 
   146 
   147 
   148 
   149 _LIT(KBotTest,          "Bulk Only Transfer Protocol Test");
   150 _LIT(KTagMismatch,      "TagMismatch");
   151 _LIT(KInvalidSignature, "InvalidSignature");
   152 _LIT(KNoDataStallCsw,   "NoDataStallCsw");
   153 _LIT(KNoDataPhaseError, "NoDataPhaseError");
   154 _LIT(KDoStallCsw,       "DoStallCsw");
   155 _LIT(KDoStallData,      "DoStallData");
   156 _LIT(KDoPhaseError,     "DoPhaseError");
   157 _LIT(KDoResidue,        "DoResidue");
   158 _LIT(KDiStallCsw,       "DiStallCsw");
   159 _LIT(KDiStallData,      "DiStallData");
   160 _LIT(KDiPhaseError,     "DiPhaseError");
   161 _LIT(KDiResidue,        "DiResidue");
   162 
   163 
   164 
   165 CTestBot* CTestBot::NewL()
   166     {
   167     __MSFNSLOG
   168 	CTestBot* r = new (ELeave) CTestBot();
   169 	CleanupStack::PushL(r);
   170 
   171 	r->ConstructL();
   172 	CleanupStack::Pop();
   173 	return r;
   174     }
   175 
   176 
   177 void CTestBot::ConstructL()
   178     {
   179     __MSFNLOG
   180     TInt driveNumber = msDrive->DriveNumber();
   181     iBotTester = CBotTester::NewL(driveNumber);
   182     }
   183 
   184 
   185 CTestBot::CTestBot()
   186     {
   187     __MSFNLOG
   188     }
   189 
   190 
   191 
   192 CTestBot::~CTestBot()
   193     {
   194     __MSFNLOG
   195     delete iBotTester;
   196     }
   197 
   198 /**
   199    USB Mass Storage Class Bulk-Only Transport
   200    6.5 Host Error Handling
   201    6.6.1 CBW Not Valid
   202    5.3.3.1 Phase Error
   203 
   204    @param aTestCase
   205    @param testName
   206  */
   207 void CTestBot::CswResetRecovery(CBotTester::TTestCase aTestCase, const TDesC& aTestName)
   208     {
   209     __MSFNLOG
   210     TInt res;
   211     test.Start(aTestName);
   212 
   213     RMassStoragePublisher msPublisher(RMassStoragePublisher::KBotResetProperty);
   214 
   215     // Set test case in client
   216     res = iBotTester->SetTest(aTestCase);
   217     test_KErrNone(res);
   218     // Enable test condition. File transfer is successful as the file server
   219     // retries in the event of a transfer error.
   220     test.Printf(_L("Writing file\n"));//
   221     res = iBotTester->WriteEnableFile();
   222     test_KErrNone(res);
   223 
   224     if (aTestCase == CBotTester::ETestCaseDiPhaseError)
   225         {
   226         test.Printf(_L("Reading file\n"));
   227         res = iBotTester->ReadEnableFile();
   228         }
   229 
   230     // Check that Host did a BOT Reset Recovery
   231     TInt botReset = msPublisher.Count();
   232     test(botReset==1);
   233     test.Printf(_L("Host performed Reset Recovery.\n"));
   234     test.End();
   235     }
   236 
   237 
   238 void CTestBot::NoDataResetRecovery(CBotTester::TTestCase aTestCase, const TDesC& aTestName)
   239     {
   240     __MSFNLOG
   241     TInt res;
   242     test.Start(aTestName);
   243 
   244     RMassStoragePublisher msPublisher(RMassStoragePublisher::KBotResetProperty);
   245 
   246     // Set test case in client
   247     res = iBotTester->SetTest(aTestCase);
   248     test_KErrNone(res);
   249 
   250     // Enable test condition.
   251     res = iBotTester->WriteEnableFile();
   252     test_KErrNone(res);
   253 
   254     // Wait for the host to send TEST UNIT READY. The client is configured to
   255     // respond with a Phase Error. Host should perform RESET RECOVERY
   256 
   257     // Check that Host did a BOT Reset Recovery
   258     User::After(1000*1000*30);
   259     TInt count = msPublisher.Count();
   260     test(count == 1);
   261     test.End();
   262     }
   263 
   264 
   265 void CTestBot::NoDataClearStall(CBotTester::TTestCase aTestCase, const TDesC& aTestName)
   266     {
   267     __MSFNLOG
   268     TInt res;
   269     test.Start(aTestName);
   270 
   271     RMassStoragePublisher msPublisher(RMassStoragePublisher::KStallProperty);
   272 
   273     // Set test case in client
   274     res = iBotTester->SetTest(aTestCase);
   275     test_KErrNone(res);
   276 
   277     // Enable test condition.
   278     res = iBotTester->WriteEnableFile();
   279     test_KErrNone(res);
   280 
   281     // Wait for the host to send TEST UNIT READY. The client is configured to
   282     // stall this request. Host should clear stall condition and attempt to
   283     // receive CSW again.
   284 
   285     /*
   286     // Cause host to send TEST UNIT READY with a client SENSE ERROR condition
   287     res = iBotTester->WriteSenseErrorFile();
   288     test_KErrNone(res);
   289 
   290     // read a file
   291     res = iBotTester->ReadTestFile();
   292     // KErrAbort returned due to Media Error
   293     test(KErrNotReady == res);
   294     */
   295 
   296     // Check that host cleared the Stall condition
   297     User::After(1000*1000*30);
   298     TInt i = msPublisher.Count();
   299     test(i == 1);
   300     test.End();
   301     }
   302 
   303 
   304 void CTestBot::DataOutClearStall(CBotTester::TTestCase aTestCase, const TDesC& aTestName)
   305     {
   306     __MSFNLOG
   307     TInt res;
   308     test.Start(aTestName);
   309 
   310     RMassStoragePublisher msPublisher(RMassStoragePublisher::KStallProperty);
   311 
   312     // Set test case in client
   313     res = iBotTester->SetTest(aTestCase);
   314     test_KErrNone(res);
   315     // Enable test condition. File transfer is successful as the file server
   316     // retries in the event of a transfer error.
   317     res = iBotTester->WriteEnableFile();
   318     test_KErrNone(res);
   319 
   320     if (aTestCase == CBotTester::ETestCaseDoStallData)
   321         {
   322         TLba lba = 0x5;
   323         TLba blocks = 0x4;
   324         test.Printf(_L("Writing data LBA=0x%x Blocks=0x%x\n"), lba, blocks);
   325         res = iBotTester->UpdateBlock(lba, blocks);
   326         res = iBotTester->UpdateBlock(lba, blocks);
   327         res = iBotTester->UpdateBlock(lba, blocks);
   328         res = iBotTester->UpdateBlock(lba, blocks);
   329         res = iBotTester->UpdateBlock(lba, blocks);
   330         res = iBotTester->UpdateBlock(lba, blocks);
   331         res = iBotTester->UpdateBlock(lba, blocks);
   332         res = iBotTester->UpdateBlock(lba, blocks);
   333         res = iBotTester->UpdateBlock(lba, blocks);
   334         }
   335 
   336     // Check that Host cleared the Stall condition
   337     TInt i = msPublisher.Count();
   338     test(i == 1);
   339     test.End();
   340     }
   341 
   342 
   343 void CTestBot::DataInClearStall(CBotTester::TTestCase aTestCase, const TDesC& aTestName)
   344     {
   345     __MSFNLOG
   346     TInt res;
   347     test.Start(aTestName);
   348 
   349     RMassStoragePublisher msPublisher(RMassStoragePublisher::KStallProperty);
   350 
   351     // Set test case in client
   352     res = iBotTester->SetTest(aTestCase);
   353     test_KErrNone(res);
   354     // Enable test condition. File transfer is successful as the file server
   355     // retries in the event of a transfer error.
   356     res = iBotTester->WriteEnableFile();
   357     test_KErrNone(res);
   358 
   359     test.Next(_L("Read file and check Data-In stall\n"));
   360     if (aTestCase == CBotTester::ETestCaseDiStallCsw)
   361         {
   362         res = iBotTester->ReadEnableFile();
   363         test.Printf(_L("File read returned %d.\n"), res);
   364         test_KErrNone(res);
   365         }
   366     else if (aTestCase == CBotTester::ETestCaseDiStallData)
   367         {
   368         res = iBotTester->ReadEnableFile();
   369         test.Printf(_L("File read returned %d.\n"), res);
   370         test_KErrNone(res);
   371         }
   372 
   373     // Check that Test client actually stalled. Note that the next CSW is
   374     // invalid and the host will also perform Reset Recovery
   375     TInt botStall = msPublisher.Count();
   376     test(botStall==1);
   377 
   378     test.Next(_L("Check next read is successful\n"));
   379     res = iBotTester->ReadEnableFile();
   380     test.Printf(_L("File read returned %d.\n"), res);
   381     test_KErrNone(res);
   382 
   383     test.Printf(_L("Host cleared stall on Bulk-In pipe.\n"));
   384     test.End();
   385     }
   386 
   387 
   388 /**
   389 Tag Mismatch:
   390     1. CSW tag does not match CBW tag
   391     2. CSW is not valid
   392     3. Host shall perform a Reset Recovery
   393 */
   394 void CTestBot::tTagMismatch()
   395     {
   396     __MSFNLOG
   397     CswResetRecovery(CBotTester::ETestCaseTagMismatch, KTagMismatch);
   398     }
   399 
   400 
   401 /**
   402 Invalid Signature:
   403     1. CSW Signature is not equal to 53425355h.
   404     2. CSW is not valid.
   405     3. Host shall perform a Reset Recovery.
   406 */
   407 void CTestBot::tInvalidSignature()
   408     {
   409     __MSFNLOG
   410     CswResetRecovery(CBotTester::ETestCaseInvalidSignature, KInvalidSignature);
   411     }
   412 
   413 
   414 /**
   415 Hn CSW stall condition
   416     1. Host expects no data transfer and CSW is stalled.
   417     2. Host shall clear the Bulk-In pipe.
   418     3. Host shall attempt to receive the CSW again.
   419 */
   420 void CTestBot::tNoDataStallCsw()
   421     {
   422     __MSFNLOG
   423     NoDataClearStall(CBotTester::ETestCaseNoDataStallCsw, KNoDataStallCsw);
   424     }
   425 
   426 /**
   427 Hn CSW Phase Error status
   428     1. Host expect no data transfer and CSW status = 02h (Phase Error.
   429     2. Host shall peroform a reset recovery.
   430 */
   431 void CTestBot::tNoDataPhaseError()
   432     {
   433     __MSFNLOG
   434     NoDataResetRecovery(CBotTester::ETestCaseNoDataPhaseError, KNoDataPhaseError);
   435     }
   436 
   437 
   438 void CTestBot::tDoStallCsw()
   439     {
   440     __MSFNLOG
   441     DataOutClearStall(CBotTester::ETestCaseDoStallCsw, KDoStallCsw);
   442     }
   443 
   444 
   445 void CTestBot::tDoStallData()
   446     {
   447     __MSFNLOG
   448     DataOutClearStall(CBotTester::ETestCaseDoStallData, KDoStallData);
   449     }
   450 
   451 
   452 void CTestBot::tDoPhaseError()
   453     {
   454     __MSFNLOG
   455     CswResetRecovery(CBotTester::ETestCaseDoPhaseError, KDoPhaseError);
   456     }
   457 
   458 
   459 void CTestBot::tDoResidue()
   460     {
   461     __MSFNLOG
   462     TInt res;
   463     test.Start(KDoResidue);
   464     res = iBotTester->SetTest(CBotTester::ETestCaseDoResidue);
   465     test_KErrNone(res);
   466     res = iBotTester->WriteEnableFile();
   467     test_KErrNone(res);
   468 
   469     res = iBotTester->WriteEnableFile();
   470     test_KErrNone(res);
   471 
   472     res = iBotTester->WriteEnableFile();
   473     test_KErrNone(res);
   474 
   475     res = iBotTester->WriteEnableFile();
   476     test_KErrNone(res);
   477 
   478     res = iBotTester->WriteEnableFile();
   479     test_KErrNone(res);
   480 
   481     test.End();
   482     }
   483 
   484 
   485 void CTestBot::tDiStallCsw()
   486     {
   487     __MSFNLOG
   488     DataInClearStall(CBotTester::ETestCaseDiStallCsw, KDiStallCsw);
   489     }
   490 
   491 
   492 void CTestBot::tDiStallData()
   493     {
   494     __MSFNLOG
   495     DataInClearStall(CBotTester::ETestCaseDiStallData, KDiStallData);
   496     }
   497 
   498 
   499 void CTestBot::tDiPhaseError()
   500     {
   501     __MSFNLOG
   502     CswResetRecovery(CBotTester::ETestCaseDiPhaseError, KDiPhaseError);
   503     }
   504 
   505 
   506 void CTestBot::tDiResidue()
   507     {
   508     __MSFNLOG
   509     TInt res;
   510     test.Start(KDiResidue);
   511 
   512     // First write test file to drive
   513     res = iBotTester->InitReadEnableFile();
   514     test_KErrNone(res);
   515 
   516     res = iBotTester->SetTest(CBotTester::ETestCaseDiResidue);
   517     test_KErrNone(res);
   518 
   519     res = iBotTester->WriteEnableFile();
   520     test_KErrNone(res);
   521 
   522     res = iBotTester->ReadEnableFile();
   523     test_KErrNone(res);
   524 
   525     res = iBotTester->ReadEnableFile();
   526     test_KErrNone(res);
   527 
   528     res = iBotTester->ReadEnableFile();
   529     test_KErrNone(res);
   530 
   531     res = iBotTester->ReadEnableFile();
   532     test_KErrNone(res);
   533 
   534     res = iBotTester->ReadEnableFile();
   535     test_KErrNone(res);
   536 
   537     res = iBotTester->ReadEnableFile();
   538     test_KErrNone(res);
   539 
   540     res = iBotTester->ReadEnableFile();
   541     test_KErrNone(res);
   542 
   543     res = iBotTester->ReadEnableFile();
   544     test_KErrNone(res);
   545 
   546     test.End();
   547     }
   548 
   549 
   550 void CallTestsL()
   551     {
   552     test.Start(KBotTest);
   553     CTestBot* tBot = CTestBot::NewL();
   554 
   555     test.Next(KTagMismatch);
   556     tBot->tTagMismatch();
   557 
   558     test.Next(KInvalidSignature);
   559     tBot->tInvalidSignature();
   560 
   561     test.Next(KNoDataStallCsw);
   562     tBot->tNoDataStallCsw();
   563 
   564     test.Next(KNoDataPhaseError);
   565     tBot->tNoDataPhaseError();
   566 
   567     test.Next(KDoStallCsw);
   568     tBot->tDoStallCsw();
   569 
   570 //    test.Next(KDoStallData);        // not working in test client
   571 //    tBot->tDoStallData();
   572 
   573     test.Next(KDoPhaseError);
   574     tBot->tDoPhaseError();
   575 
   576     test.Next(KDiStallCsw);
   577     tBot->tDiStallCsw();
   578 
   579     test.Next(KDiStallData);
   580     tBot->tDiStallData();
   581 
   582     test.Next(KDiPhaseError);
   583     tBot->tDiPhaseError();
   584 
   585     test.Next(KDoResidue);
   586     tBot->tDoResidue();
   587 
   588     test.Next(KDiResidue);
   589     tBot->tDiResidue();
   590 
   591     delete tBot;
   592     test.End();
   593     }