1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/smassstorage/src/t_gml_tur.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,232 @@
1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <e32std.h>
1.20 +#include <e32std_private.h>
1.21 +#include <e32test.h>
1.22 +#include <testusbc.h>
1.23 +#include "t_gml_tur_protocol.h"
1.24 +#include "t_gml_tur_controller.h"
1.25 +#include "cbulkonlytransport.h"
1.26 +
1.27 +LOCAL_D RTest test(_L("t_gml_tur"));
1.28 +
1.29 +_LIT(KDriverFileName,"TESTUSBC.LDD");
1.30 +_LIT(KLddName,"usbc");
1.31 +_LIT(KTransportThreadName,"TransportThread");
1.32 +_LIT(KTransportSemName,"TransportThreadSem");
1.33 +
1.34 +LOCAL_D const TInt KFiveDrives = 5;
1.35 +LOCAL_D const TEndpointNumber KOutEp = EEndpoint1;
1.36 +
1.37 +GLDEF_D CUsbMassStorageController* gController = NULL;
1.38 +
1.39 +LOCAL_C void SetCBWHeader(TDes8& cbwData, TInt32 aDataTransferLength, TBool aDataIn, TUint8 aLun, TUint8 aCBLength)
1.40 + {
1.41 + //dCBWSignature
1.42 + cbwData[0] = 0x55;
1.43 + cbwData[1] = 0x53;
1.44 + cbwData[2] = 0x42;
1.45 + cbwData[3] = 0x43;
1.46 + //dCBWTag
1.47 + cbwData[4] = 0x01;
1.48 + cbwData[5] = 0x00;
1.49 + cbwData[6] = 0x00;
1.50 + cbwData[7] = 0x00;
1.51 + //dCBWDataTransferLength
1.52 + cbwData[8] = TUint8((aDataTransferLength & 0x000000FF));
1.53 + cbwData[9] = TUint8((aDataTransferLength & 0x0000FF00) >> 8);
1.54 + cbwData[10] = TUint8((aDataTransferLength & 0x00FF0000) >> 16);
1.55 + cbwData[11] = TUint8((aDataTransferLength & 0xFF000000) >> 24);
1.56 + //bmCBWFlags
1.57 + if (aDataIn)
1.58 + {
1.59 + cbwData[12] = 0x80;
1.60 + }
1.61 + else
1.62 + {
1.63 + cbwData[12] = 0x00;
1.64 + }
1.65 + //bCBWLUN
1.66 + cbwData[13] = aLun;
1.67 + //bCBWCBLength
1.68 + cbwData[14] = aCBLength;
1.69 + }
1.70 +
1.71 +LOCAL_C TInt TransportThreadEntry(TAny* aPtr)
1.72 + {
1.73 + TInt err = KErrNone;
1.74 + TInt numDrives = KFiveDrives;
1.75 +
1.76 + //Create and install cleanup trap and active scheduler
1.77 + CTrapCleanup* cleanup = CTrapCleanup::New();
1.78 + if (cleanup == NULL)
1.79 + {
1.80 + return KErrNoMemory;
1.81 + }
1.82 +
1.83 + CActiveScheduler* sched = new CActiveScheduler;
1.84 + if (sched == NULL)
1.85 + {
1.86 + return KErrNoMemory;
1.87 + }
1.88 + CActiveScheduler::Install(sched);
1.89 +
1.90 + //Start transport
1.91 + CScsiProtocol* protocol = NULL;
1.92 + TRAP(err, protocol = CScsiProtocol::NewL());
1.93 + if (err != KErrNone)
1.94 + {
1.95 + return err;
1.96 + }
1.97 +
1.98 + CUsbMassStorageController* controller = (CUsbMassStorageController*)aPtr;
1.99 + gController = controller;
1.100 + controller->CreateL(0);
1.101 +
1.102 + CBulkOnlyTransport* transport = NULL;
1.103 + TRAP(err, transport = CBulkOnlyTransport::NewL(numDrives, *controller));
1.104 + if (err != KErrNone)
1.105 + {
1.106 + return err;
1.107 + }
1.108 +
1.109 + controller->SetTransport(transport);
1.110 + TRAP(err, transport->InitialiseTransportL(1));
1.111 +
1.112 + transport->RegisterProtocol(*protocol);
1.113 + transport->Start();
1.114 +
1.115 + //Synchronize with test thread
1.116 + RSemaphore gSemThreadReady;
1.117 + gSemThreadReady.OpenGlobal(KTransportSemName);
1.118 + gSemThreadReady.Signal();
1.119 + gSemThreadReady.Close();
1.120 +
1.121 + CActiveScheduler::Start();
1.122 +
1.123 + delete transport;
1.124 + delete controller;
1.125 + delete protocol;
1.126 + delete sched;
1.127 + delete cleanup;
1.128 +
1.129 + return KErrNone;
1.130 + }
1.131 +
1.132 +GLDEF_C TInt E32Main()
1.133 + {
1.134 + test.Title();
1.135 +
1.136 + TInt err;
1.137 +
1.138 + test.Start(_L("Loading ldd"));
1.139 + err = User::LoadLogicalDevice(KDriverFileName);
1.140 + test(err == KErrNone || err == KErrAlreadyExists);
1.141 +
1.142 + RDevTestUsbcClient ldd;
1.143 + err = ldd.Open(0);
1.144 + test(err == KErrNone);
1.145 +
1.146 + //ldd.ResetEndpoints();
1.147 +
1.148 + RSemaphore gSemThreadReady;
1.149 + err = gSemThreadReady.CreateGlobal(KTransportSemName, 0);
1.150 +
1.151 + CUsbMassStorageController* controller = new CUsbMassStorageController();
1.152 + test(controller != NULL);
1.153 +
1.154 + //Start transport thread.
1.155 + RThread transportThread;
1.156 + test.Next(_L("Creating transport thread, Max Lun = 4"));
1.157 + err = transportThread.Create(KTransportThreadName, TransportThreadEntry, KDefaultStackSize, NULL, (void*)controller);
1.158 + test(err == KErrNone);
1.159 + transportThread.Resume();
1.160 +
1.161 + //Synchronize with transport thread.
1.162 + gSemThreadReady.Wait();
1.163 + gSemThreadReady.Close();
1.164 + test(gController != NULL);
1.165 +
1.166 + TRequestStatus status;
1.167 +
1.168 + test.Next(_L("Writing GetMaxLun request to endpoint 0"));
1.169 + //Write GetMaxLun request to endpoint 0
1.170 + TBuf8<KRequestHdrSize> controlData;
1.171 + controlData.SetLength(KRequestHdrSize);
1.172 + controlData.FillZ();
1.173 + controlData[0] = 0xA1;
1.174 + controlData[1] = 0xFE;
1.175 + controlData[6] = 0x01;
1.176 + ldd.HostWrite(status, EEndpoint0, controlData, KRequestHdrSize);
1.177 +
1.178 + User::WaitForRequest(status);
1.179 + test.Printf(_L("status = %d"), status.Int());
1.180 + test(status.Int() == KErrNone);
1.181 +
1.182 + //Read request response
1.183 + controlData.SetLength(1);
1.184 + ldd.HostRead(status, EEndpoint0, controlData, 1);
1.185 +
1.186 + User::WaitForRequest(status);
1.187 + test(status.Int() == KErrNone);
1.188 +
1.189 + test.Printf(_L("Max LUN: %d\n"), controlData[0]);
1.190 + test(controlData[0] == KFiveDrives - 1);
1.191 +
1.192 + //Send TEST UNIT READY command
1.193 + TBuf8<KCbwLength> cbwData;
1.194 + cbwData.SetLength(KCbwLength);
1.195 + cbwData.FillZ();
1.196 + SetCBWHeader(cbwData, 6, ETrue, 0, 6);
1.197 + ldd.HostWrite(status, KOutEp, cbwData, KCbwLength);
1.198 + User::WaitForRequest(status);
1.199 + test(status.Int() == KErrNone);
1.200 +
1.201 + test.Next(_L("Writing Reset request to endpoint 0"));
1.202 + //Write Reset request to endpoint 0
1.203 + controlData.SetLength(KRequestHdrSize);
1.204 + controlData.FillZ();
1.205 + controlData[0] = 0x21;
1.206 + controlData[1] = 0xFF;
1.207 + ldd.HostWrite(status, EEndpoint0, controlData, KRequestHdrSize);
1.208 +
1.209 + User::WaitForRequest(status);
1.210 + test(status.Int() == KErrNone);
1.211 +
1.212 + User::After(3000000); //3 seconds
1.213 + test(gController->IsReset());
1.214 + test.Printf(_L("Controller got reset request\n"));
1.215 +
1.216 + TRequestStatus logonStatus;
1.217 + transportThread.Logon(logonStatus);
1.218 + TRequestStatus* statusPtr = &(controller->iStatus);
1.219 + transportThread.RequestComplete(statusPtr, KErrNone);
1.220 + //Wait for thread to die
1.221 + test.Printf(_L("Waiting for controller thread to die\n"));
1.222 + User::WaitForRequest(logonStatus);
1.223 + transportThread.Close();
1.224 + test.Printf(_L("The thread is dead, long live the thread\n"));
1.225 +
1.226 + ldd.Close();
1.227 +
1.228 + test.Printf(_L("Unloading ldd"));
1.229 + err = User::FreeLogicalDevice(KLddName);
1.230 + test(err == KErrNone);
1.231 +
1.232 + test.End();
1.233 +
1.234 + return 0;
1.235 + }