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