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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
23 #define __E32TEST_EXTENSION__
25 #include <e32property.h>
27 #include "cblockdevicetester.h"
29 #include "tmsprintdrive.h"
30 #include "ttestutils.h"
33 extern CMsDrive* msDrive;
35 RTest test(_L("T_MSBOT"));
39 class RMassStoragePublisher
44 KBotResetProperty = 1,
48 RMassStoragePublisher(TPropertyKeys aKey);
49 ~RMassStoragePublisher();
52 TSecureId Sid() const;
58 TSecureId RMassStoragePublisher::Sid() const
61 return process.SecureId();
64 RMassStoragePublisher::RMassStoragePublisher(TPropertyKeys aKey)
67 _LIT_SECURITY_POLICY_PASS(KHostMassStoragePolicy);
68 TInt res = RProperty::Define(iKey,
70 KHostMassStoragePolicy,
71 KHostMassStoragePolicy);
73 test(res == KErrNone);
74 // reset the property flag
75 res = RProperty::Set(Sid(), iKey, 0);
79 RMassStoragePublisher::~RMassStoragePublisher()
81 TInt res = RProperty::Delete(iKey);
82 test(res == KErrNone || res == KErrNotFound);
86 TInt RMassStoragePublisher::Count()
89 TInt res = RProperty::Get(Sid(), iKey, value);
91 RDebug::Printf("RMassStoragePublisher[%d] res=%d value=%d", iKey, res, value);
104 void tLastLbaAccessL();
108 class CTestBot: public CBase
111 static CTestBot* NewL();
119 void tInvalidSignature();
121 void tNoDataStallCsw();
122 void tNoDataPhaseError();
126 void tDoPhaseError();
131 void tDiPhaseError();
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);
139 void DataOutClearStall(CBotTester::TTestCase aTestCase, const TDesC& aTestName);
140 void DataInClearStall(CBotTester::TTestCase aTestCase, const TDesC& aTestName);
143 CBotTester* iBotTester;
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");
165 CTestBot* CTestBot::NewL()
168 CTestBot* r = new (ELeave) CTestBot();
169 CleanupStack::PushL(r);
177 void CTestBot::ConstructL()
180 TInt driveNumber = msDrive->DriveNumber();
181 iBotTester = CBotTester::NewL(driveNumber);
192 CTestBot::~CTestBot()
199 USB Mass Storage Class Bulk-Only Transport
200 6.5 Host Error Handling
207 void CTestBot::CswResetRecovery(CBotTester::TTestCase aTestCase, const TDesC& aTestName)
211 test.Start(aTestName);
213 RMassStoragePublisher msPublisher(RMassStoragePublisher::KBotResetProperty);
215 // Set test case in client
216 res = iBotTester->SetTest(aTestCase);
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();
224 if (aTestCase == CBotTester::ETestCaseDiPhaseError)
226 test.Printf(_L("Reading file\n"));
227 res = iBotTester->ReadEnableFile();
230 // Check that Host did a BOT Reset Recovery
231 TInt botReset = msPublisher.Count();
233 test.Printf(_L("Host performed Reset Recovery.\n"));
238 void CTestBot::NoDataResetRecovery(CBotTester::TTestCase aTestCase, const TDesC& aTestName)
242 test.Start(aTestName);
244 RMassStoragePublisher msPublisher(RMassStoragePublisher::KBotResetProperty);
246 // Set test case in client
247 res = iBotTester->SetTest(aTestCase);
250 // Enable test condition.
251 res = iBotTester->WriteEnableFile();
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
257 // Check that Host did a BOT Reset Recovery
258 User::After(1000*1000*30);
259 TInt count = msPublisher.Count();
265 void CTestBot::NoDataClearStall(CBotTester::TTestCase aTestCase, const TDesC& aTestName)
269 test.Start(aTestName);
271 RMassStoragePublisher msPublisher(RMassStoragePublisher::KStallProperty);
273 // Set test case in client
274 res = iBotTester->SetTest(aTestCase);
277 // Enable test condition.
278 res = iBotTester->WriteEnableFile();
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.
286 // Cause host to send TEST UNIT READY with a client SENSE ERROR condition
287 res = iBotTester->WriteSenseErrorFile();
291 res = iBotTester->ReadTestFile();
292 // KErrAbort returned due to Media Error
293 test(KErrNotReady == res);
296 // Check that host cleared the Stall condition
297 User::After(1000*1000*30);
298 TInt i = msPublisher.Count();
304 void CTestBot::DataOutClearStall(CBotTester::TTestCase aTestCase, const TDesC& aTestName)
308 test.Start(aTestName);
310 RMassStoragePublisher msPublisher(RMassStoragePublisher::KStallProperty);
312 // Set test case in client
313 res = iBotTester->SetTest(aTestCase);
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();
320 if (aTestCase == CBotTester::ETestCaseDoStallData)
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);
336 // Check that Host cleared the Stall condition
337 TInt i = msPublisher.Count();
343 void CTestBot::DataInClearStall(CBotTester::TTestCase aTestCase, const TDesC& aTestName)
347 test.Start(aTestName);
349 RMassStoragePublisher msPublisher(RMassStoragePublisher::KStallProperty);
351 // Set test case in client
352 res = iBotTester->SetTest(aTestCase);
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();
359 test.Next(_L("Read file and check Data-In stall\n"));
360 if (aTestCase == CBotTester::ETestCaseDiStallCsw)
362 res = iBotTester->ReadEnableFile();
363 test.Printf(_L("File read returned %d.\n"), res);
366 else if (aTestCase == CBotTester::ETestCaseDiStallData)
368 res = iBotTester->ReadEnableFile();
369 test.Printf(_L("File read returned %d.\n"), res);
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();
378 test.Next(_L("Check next read is successful\n"));
379 res = iBotTester->ReadEnableFile();
380 test.Printf(_L("File read returned %d.\n"), res);
383 test.Printf(_L("Host cleared stall on Bulk-In pipe.\n"));
390 1. CSW tag does not match CBW tag
392 3. Host shall perform a Reset Recovery
394 void CTestBot::tTagMismatch()
397 CswResetRecovery(CBotTester::ETestCaseTagMismatch, KTagMismatch);
403 1. CSW Signature is not equal to 53425355h.
405 3. Host shall perform a Reset Recovery.
407 void CTestBot::tInvalidSignature()
410 CswResetRecovery(CBotTester::ETestCaseInvalidSignature, KInvalidSignature);
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.
420 void CTestBot::tNoDataStallCsw()
423 NoDataClearStall(CBotTester::ETestCaseNoDataStallCsw, KNoDataStallCsw);
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.
431 void CTestBot::tNoDataPhaseError()
434 NoDataResetRecovery(CBotTester::ETestCaseNoDataPhaseError, KNoDataPhaseError);
438 void CTestBot::tDoStallCsw()
441 DataOutClearStall(CBotTester::ETestCaseDoStallCsw, KDoStallCsw);
445 void CTestBot::tDoStallData()
448 DataOutClearStall(CBotTester::ETestCaseDoStallData, KDoStallData);
452 void CTestBot::tDoPhaseError()
455 CswResetRecovery(CBotTester::ETestCaseDoPhaseError, KDoPhaseError);
459 void CTestBot::tDoResidue()
463 test.Start(KDoResidue);
464 res = iBotTester->SetTest(CBotTester::ETestCaseDoResidue);
466 res = iBotTester->WriteEnableFile();
469 res = iBotTester->WriteEnableFile();
472 res = iBotTester->WriteEnableFile();
475 res = iBotTester->WriteEnableFile();
478 res = iBotTester->WriteEnableFile();
485 void CTestBot::tDiStallCsw()
488 DataInClearStall(CBotTester::ETestCaseDiStallCsw, KDiStallCsw);
492 void CTestBot::tDiStallData()
495 DataInClearStall(CBotTester::ETestCaseDiStallData, KDiStallData);
499 void CTestBot::tDiPhaseError()
502 CswResetRecovery(CBotTester::ETestCaseDiPhaseError, KDiPhaseError);
506 void CTestBot::tDiResidue()
510 test.Start(KDiResidue);
512 // First write test file to drive
513 res = iBotTester->InitReadEnableFile();
516 res = iBotTester->SetTest(CBotTester::ETestCaseDiResidue);
519 res = iBotTester->WriteEnableFile();
522 res = iBotTester->ReadEnableFile();
525 res = iBotTester->ReadEnableFile();
528 res = iBotTester->ReadEnableFile();
531 res = iBotTester->ReadEnableFile();
534 res = iBotTester->ReadEnableFile();
537 res = iBotTester->ReadEnableFile();
540 res = iBotTester->ReadEnableFile();
543 res = iBotTester->ReadEnableFile();
552 test.Start(KBotTest);
553 CTestBot* tBot = CTestBot::NewL();
555 test.Next(KTagMismatch);
556 tBot->tTagMismatch();
558 test.Next(KInvalidSignature);
559 tBot->tInvalidSignature();
561 test.Next(KNoDataStallCsw);
562 tBot->tNoDataStallCsw();
564 test.Next(KNoDataPhaseError);
565 tBot->tNoDataPhaseError();
567 test.Next(KDoStallCsw);
570 // test.Next(KDoStallData); // not working in test client
571 // tBot->tDoStallData();
573 test.Next(KDoPhaseError);
574 tBot->tDoPhaseError();
576 test.Next(KDiStallCsw);
579 test.Next(KDiStallData);
580 tBot->tDiStallData();
582 test.Next(KDiPhaseError);
583 tBot->tDiPhaseError();
585 test.Next(KDoResidue);
588 test.Next(KDiResidue);