os/kernelhwsrv/kerneltest/f32test/smassstorage/src/t_ms_publish.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2004-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 // Component test of Publish and Subscribe
    15 // 
    16 //
    17 
    18 /**
    19  @file
    20  @internalTechnology
    21 */
    22 
    23 #include <f32file.h>
    24 #include <e32test.h>
    25 #include <e32std.h>
    26 #include <e32std_private.h>
    27 #include <e32svr.h>
    28 #include <hal.h>
    29 #include <massstorage.h>
    30 #include "t_ms_main.h"
    31 #include "testusbc.h"
    32 #include "scsicmdbuilder.h"
    33 #include "cstatemachine.h"
    34 #include "cpropertywatch.h"
    35 
    36 
    37 GLREF_D TBuf8<KScsiCmdMaxLen> scsiCmdBuf;
    38 GLREF_D RDevTestUsbcClient usbcClient;
    39 
    40 RFs fs;
    41 
    42 LOCAL_D TChar driveLetter;
    43 GLDEF_D TInt removalDrvNo;
    44 GLDEF_D TUint8 testLun(0);                // Use MMC card for testing
    45 
    46 _LIT(KMsFs, "MassStorageFileSystem");
    47 
    48 #define LOG_AND_TEST(a, e) {if (a!=e) {test.Printf(_L("lvalue %d, rvalue%d\n\r"), a,e); test(EFalse);}}
    49 
    50 
    51 LOCAL_C void ParseCommandArguments()
    52 //
    53 // Parses the command line arguments
    54 //
    55 	{
    56 	TBuf<0x100> cmd;
    57 	User::CommandLine(cmd);
    58 	TLex lex(cmd);
    59 	TPtrC token;
    60 	token.Set(lex.NextToken());
    61 	if (token.Length() != 0)
    62 		{
    63 		driveLetter = token[0];
    64 		driveLetter.UpperCase();
    65 		test.Printf(_L("CmdLine Param=%S"),&token);
    66 		}
    67 	else
    68 		{
    69 		test.Printf(_L("No or not enough command line arguments"));
    70 		// code drive letters based on platform
    71 		TInt uid;
    72 		TInt r=HAL::Get(HAL::EMachineUid,uid);
    73 		LOG_AND_TEST(r,KErrNone);
    74 	
    75 		switch(uid)
    76    			{
    77    			case HAL::EMachineUid_Lubbock:
    78    				driveLetter = 'F';
    79    				test.Printf(_L("Test is running on Lubbock\r\n"));
    80 				testLun = 2;
    81 				break;
    82    			case HAL::EMachineUid_Win32Emulator:
    83    				driveLetter = 'X';
    84    				test.Printf(_L("Test is running on Win32 Emulator\r\n"));
    85 				testLun = 0;
    86    				break;
    87    			default:
    88 				// Assume it's a H2 board for now as no relevant Enum is found
    89    				driveLetter = 'D';
    90    				test.Printf(_L("Test is running on H2 board\r\n"));	
    91    				testLun = 0;				
    92    				break;
    93    			}
    94    		}	
    95 	}
    96 
    97 LOCAL_C void doComponentTest()
    98     //
    99     // Do the component test
   100     //
   101 	{
   102 #ifndef __NO_HEAP_CHECK
   103 	__UHEAP_MARK;
   104 #endif	
   105 
   106     TInt ret;
   107     test.Printf(_L("Start MountStart test. Be sure MMC card is inserted.\n"));
   108     // Parse the CommandLine argument: removal drive
   109     ParseCommandArguments();
   110 
   111     // Connect to the server
   112     LOG_AND_TEST(KErrNone,  fs.Connect());
   113 	CleanupClosePushL(fs); 
   114 	   
   115     // Convert drive letter to its numerical equivalent
   116 	ret = fs.CharToDrive(driveLetter,removalDrvNo);
   117 	LOG_AND_TEST(ret,  KErrNone);	
   118 
   119 	// Load the logical device
   120 	_LIT(KDriverFileName,"TESTUSBC.LDD");
   121 	ret = User::LoadLogicalDevice(KDriverFileName);
   122 	LOG_AND_TEST(KErrNone, ret);
   123 
   124     // Add MS file system
   125 	_LIT(KMsFsFsy, "MSFS.FSY");
   126 	LOG_AND_TEST(KErrNone, fs.AddFileSystem(KMsFsFsy));
   127 	
   128     // Start Ms file system
   129     RUsbMassStorage usbMs;
   130     CleanupClosePushL(usbMs);
   131 
   132     TMassStorageConfig config;
   133     
   134     config.iVendorId.Copy(_L("vendorId"));
   135     config.iProductId.Copy(_L("productId"));
   136     config.iProductRev.Copy(_L("rev"));
   137 
   138 	ret = usbMs.Connect();
   139     LOG_AND_TEST(KErrNone, ret);
   140   
   141     // Start usb mass storage device
   142     LOG_AND_TEST(KErrNone , usbMs.Start(config));
   143 
   144     // Format removable drive using FAT FS
   145     RFormat format;
   146     TBuf<2> removalDrive;
   147     removalDrive.Append(driveLetter);
   148     removalDrive.Append(':');
   149     TInt tracksRemaining;
   150     test.Printf(_L("Start MMC card formatting\n"));
   151     LOG_AND_TEST(KErrNone, format.Open(fs, removalDrive, EHighDensity|EQuickFormat, tracksRemaining));
   152     while (tracksRemaining)
   153         {
   154         test.Printf(_L("."));
   155         LOG_AND_TEST(KErrNone,  format.Next(tracksRemaining));
   156         }
   157     format.Close();
   158   	test.Printf(_L("\nDone!\n"));
   159 
   160     // Open a session to LDD
   161     test.Printf(_L("Open LDD\n"));
   162     LOG_AND_TEST(KErrNone, usbcClient.Open(0));
   163 
   164 	test.Printf(_L("Creating CActiveScheduler\n"));
   165 	CActiveScheduler* sched = new(ELeave) CActiveScheduler;
   166 	CleanupStack::PushL(sched);
   167 	CActiveScheduler::Install(sched);
   168   	
   169 	// Create a state machine
   170 	CStateMachine* sm = CStateMachine::NewL();
   171 	CleanupStack::PushL(sm);
   172     sm->AddState(EUsbMsDriveState_Disconnected);
   173     sm->AddState(EUsbMsDriveState_Connecting);
   174     sm->AddState(EUsbMsDriveState_Connected);
   175     sm->AddState(EUsbMsDriveState_Disconnecting);
   176     sm->AddState(EUsbMsDriveState_Active);
   177     sm->AddState(EUsbMsDriveState_Locked);
   178     sm->AddState(EUsbMsState_Written);
   179     sm->AddState(EUsbMsState_Read);
   180     
   181     sm->SetInitState(EUsbMsDriveState_Disconnected);
   182 
   183   	CPropertyHandler* driveStatusHandler 	= CMsDriveStatusHandler::NewLC(removalDrvNo, *sm);
   184   	CPropertyHandler* readStatusHandler 	= CMsReadStatusHandler::NewLC(removalDrvNo, *sm);
   185   	CPropertyHandler* writtenStatusHandler 	= CMsWrittenStatusHandler::NewLC(removalDrvNo, *sm);
   186   	
   187  	CPropertyWatch::NewLC(EUsbMsDriveState_DriveStatus, *driveStatusHandler);
   188  	CPropertyWatch::NewLC(EUsbMsDriveState_KBytesRead, *readStatusHandler);
   189  	CPropertyWatch::NewLC(EUsbMsDriveState_KBytesWritten, *writtenStatusHandler);
   190  	
   191 	CActiveScheduler::Start();
   192 
   193 	ret = usbMs.Stop();
   194 	test.Printf(_L("usbMs.Stop returned %d\n"), ret);
   195 	test(ret == KErrNone);
   196 	usbMs.Close();
   197 	// 1 sec delay for MSFS to stop
   198 	User::After(1000000);
   199 	ret = fs.RemoveFileSystem(KMsFs);
   200 	test(ret == KErrNone || ret == KErrNotFound);
   201 	test.Printf(_L("RemoveFileSystem returned %d\n"), ret);
   202 
   203 	usbcClient.Close();
   204 	ret = User::FreeLogicalDevice(_L("USBC"));
   205 	test.Printf(_L("FreeLogicalDevice returned %d\n"), ret);
   206 	test(ret == KErrNone);			
   207 
   208 	CleanupStack::PopAndDestroy(3);	// 3 CPropertyWatches 
   209 	CleanupStack::PopAndDestroy(3);	// 3 property status change handlers
   210 	CleanupStack::PopAndDestroy(sm);
   211 	CleanupStack::PopAndDestroy(sched);
   212 	CleanupStack::PopAndDestroy(&usbMs);
   213 	CleanupStack::PopAndDestroy(&fs);
   214 
   215 #ifndef __NO_HEAP_CHECK
   216 	__UHEAP_MARKEND;
   217 #endif
   218 	}
   219 	
   220 GLDEF_C void CallTestsL()
   221 //
   222 // Do all tests
   223 //
   224 	{
   225 	test.Start( _L("Test Publish Subscriber") );
   226     doComponentTest();
   227     test.End();
   228     }
   229