kerneltest/f32test/shostmassstorage/msman/test/t_msmain.cpp
changeset 0 a41df078684a
child 297 b2826f67641f
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2008-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 // f32test\server\t_msmain.cpp
       
    15 //
       
    16 //
       
    17 
       
    18 #include <e32def.h>
       
    19 #include <e32cmn.h>
       
    20 #include <e32base.h>
       
    21 #include <f32file.h>
       
    22 #include <e32debug.h>
       
    23 #include <e32test.h>
       
    24 
       
    25 #include "rfsydebug.h"
       
    26 #include "rusbhostsession.h"
       
    27 #include "rusbotgsession.h"
       
    28 #include "cmsdrive.h"
       
    29 #include "tmslog.h"
       
    30 
       
    31 /*
       
    32 OTG Platform configuration 
       
    33 Define for H4 and undefine for Navi Engine 
       
    34 */
       
    35 #define _OTG_CONFIG 
       
    36 
       
    37 extern RTest test;
       
    38 extern RFs fsSession;
       
    39 
       
    40 CMsDrive* msDrive;
       
    41 
       
    42 extern void CallTestsL();
       
    43 
       
    44 
       
    45 GLDEF_C void MainL()
       
    46     {
       
    47     __MSFNSLOG
       
    48 
       
    49     TInt err;
       
    50     CleanupClosePushL(fsSession);
       
    51     User::LeaveIfError(fsSession.Connect());
       
    52 
       
    53     msDrive = CMsDrive::NewL();
       
    54     CleanupStack::PushL(msDrive);
       
    55 
       
    56     RUsbOtgSession usbOtgSession;
       
    57     err = usbOtgSession.Connect();
       
    58     User::LeaveIfError(err);
       
    59     CleanupClosePushL(usbOtgSession);
       
    60     test.Printf(_L("USB OTG Server Connected\n"));
       
    61 
       
    62 
       
    63 #ifdef _OTG_CONFIG
       
    64     TBool deviceInserted = usbOtgSession.DeviceInserted();
       
    65     test.Printf(_L("hub inserted = %d\n"), deviceInserted);
       
    66 
       
    67     while (!deviceInserted)
       
    68         {
       
    69         TBool change;
       
    70         TRequestStatus status;
       
    71         test.Printf(_L("Waiting for hub inserted event...\n"));
       
    72         usbOtgSession.NotifyChange(change, status);
       
    73     
       
    74         User::WaitForRequest(status);
       
    75         User::LeaveIfError(status.Int());
       
    76 
       
    77         TBool deviceInserted = usbOtgSession.DeviceInserted();
       
    78         test.Printf(_L("hub inserted = %d\n"), deviceInserted);
       
    79         }
       
    80 #else
       
    81     TBool deviceInserted = ETrue;
       
    82 #endif
       
    83 
       
    84 
       
    85 
       
    86 
       
    87     RUsbHostSession usbHostSession;
       
    88     err = usbHostSession.Connect();
       
    89     User::LeaveIfError(err);
       
    90     CleanupClosePushL(usbHostSession);
       
    91     test.Printf(_L("USB Host Server Connected\n"));
       
    92 
       
    93     err = usbHostSession.Start();
       
    94     User::LeaveIfError(err);
       
    95     test.Printf(_L("USB Host Server Started\n"));
       
    96 
       
    97 
       
    98     if (deviceInserted)
       
    99         {
       
   100         TBool driveFound = EFalse;
       
   101 
       
   102         do
       
   103             {
       
   104             TRequestStatus status;
       
   105             fsSession.NotifyChange(ENotifyAll, status);
       
   106 
       
   107             // trigger fileserver to update drive lists
       
   108             TDriveList driveList;
       
   109             User::LeaveIfError(fsSession.DriveList(driveList));
       
   110 
       
   111             test.Printf(_L("Waiting for File System change notifcation...\r\n"));
       
   112             User::WaitForRequest(status);
       
   113             test.Printf(_L("NotifyChange status=%d\r\n"), status.Int());
       
   114 
       
   115             driveFound = msDrive->GetUsbDeviceL();
       
   116             } while (!driveFound);
       
   117 
       
   118         msDrive->SetSessionPathL();
       
   119 
       
   120         if (!msDrive->DrivePresent())
       
   121             {
       
   122             test.Printf(_L("Media Not present !\n"));
       
   123             User::Leave(KErrNotReady);
       
   124             }
       
   125 
       
   126         test.Printf(_L("#--> ==== All mount enhancements are disabled ====\n"));
       
   127         RFsyDebug fsyDebug(msDrive->DriveNumber());
       
   128         fsyDebug.DisableAll();
       
   129 
       
   130         CallTestsL();
       
   131         }
       
   132     else
       
   133         {
       
   134         test.Printf(_L("Hub not inserted!\n"));
       
   135         test(EFalse);
       
   136         }
       
   137 
       
   138     
       
   139     test.Printf(_L("Destroying sessions...\n"));
       
   140     test.Printf(_L("Destroying USB Host session...\n"));
       
   141     CleanupStack::PopAndDestroy(&usbHostSession);
       
   142     // Wait for thread to die
       
   143     User::After(1000 * 1000 * 4);
       
   144 
       
   145     test.Printf(_L("Destroying USB OTG session...\n"));
       
   146     CleanupStack::PopAndDestroy(&usbOtgSession);
       
   147     test.Printf(_L("Sessions Destroyed.\n"));
       
   148     // Wait for thread to die
       
   149     User::After(1000 * 1000 * 4);
       
   150 
       
   151     CleanupStack::PopAndDestroy(msDrive);
       
   152     CleanupStack::PopAndDestroy();  // fsSession
       
   153     }
       
   154 
       
   155 
       
   156 GLDEF_C TInt E32Main()
       
   157 	{
       
   158     CTrapCleanup* cleanup = CTrapCleanup::New();
       
   159 	__UHEAP_MARK;
       
   160     test.Title();
       
   161     test.Start(_L("Starting tests..."));
       
   162 
       
   163 	TTime timerC;
       
   164 	timerC.HomeTime();
       
   165 
       
   166 	TRAPD(err, MainL());
       
   167     test(err == KErrNone);
       
   168 
       
   169     TTime endTimeC;
       
   170     endTimeC.HomeTime();
       
   171     TTimeIntervalSeconds timeTakenC;
       
   172     err = endTimeC.SecondsFrom(timerC,timeTakenC);
       
   173     test(err == KErrNone);
       
   174     test.Printf(_L("Time taken for test = %d seconds\n"),timeTakenC.Int());
       
   175 
       
   176 	test.End();
       
   177 	test.Close();
       
   178 	__UHEAP_MARKEND;
       
   179 	delete cleanup;
       
   180 	return KErrNone;
       
   181 	}
       
   182