os/kernelhwsrv/kerneltest/f32test/smassstorage/src/t_ms_clisvr.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
// f32test\msfs\src\t_ms_clisvr.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#define __T_MS_CLISVR__
sl@0
    19
sl@0
    20
#include <f32file.h>
sl@0
    21
#include <e32test.h>
sl@0
    22
#include <e32std.h>
sl@0
    23
#include <e32std_private.h>
sl@0
    24
#include <e32svr.h>
sl@0
    25
#include <hal.h>
sl@0
    26
#include <massstorage.h>
sl@0
    27
#include "rusbmassstorage.h"
sl@0
    28
#include "t_ms_main.h"
sl@0
    29
sl@0
    30
#ifdef __USBMS_NO_PROCESSES__
sl@0
    31
#include <e32math.h>
sl@0
    32
#endif
sl@0
    33
sl@0
    34
GLDEF_D RUsbMassStorage gUsbMs;
sl@0
    35
sl@0
    36
// Unit test for MS client API and server API
sl@0
    37
GLREF_C void t_ms_clisvr();
sl@0
    38
sl@0
    39
// Unit test for MS file server
sl@0
    40
GLREF_C void t_ms_fsunit();
sl@0
    41
sl@0
    42
sl@0
    43
LOCAL_C TInt StartServer()
sl@0
    44
//
sl@0
    45
// Start the server process or thread
sl@0
    46
//
sl@0
    47
	{
sl@0
    48
	const TUidType serverUid(KNullUid, KNullUid, KUsbMsSvrUid);
sl@0
    49
sl@0
    50
#ifdef __USBMS_NO_PROCESSES__
sl@0
    51
	//
sl@0
    52
	// In EKA1 WINS the server is a DLL, the exported entrypoint returns a TInt
sl@0
    53
	// which represents the real entry-point for the server thread
sl@0
    54
	//
sl@0
    55
	RLibrary lib;
sl@0
    56
	TInt err = lib.Load(KUsbMsImg, serverUid);
sl@0
    57
sl@0
    58
	if (err != KErrNone )
sl@0
    59
		{
sl@0
    60
		return err;
sl@0
    61
		}
sl@0
    62
	TLibraryFunction ordinal1 = lib.Lookup(1);
sl@0
    63
	TThreadFunction serverFunc = reinterpret_cast<TThreadFunction>(ordinal1());
sl@0
    64
sl@0
    65
	//
sl@0
    66
	// To deal with the unique thread (+semaphore!) naming in EPOC, and that we may
sl@0
    67
	// be trying to restart a server that has just exited we attempt to create a
sl@0
    68
	// unique thread name for the server.
sl@0
    69
	// This uses Math::Random() to generate a 32-bit random number for the name
sl@0
    70
	//
sl@0
    71
	TName name(KUsbMsServerName);
sl@0
    72
	name.AppendNum(Math::Random(),EHex);
sl@0
    73
	
sl@0
    74
	RThread server;
sl@0
    75
	err = server.Create (
sl@0
    76
		name,
sl@0
    77
		serverFunc,
sl@0
    78
		KUsbMsStackSize,
sl@0
    79
		NULL,
sl@0
    80
		&lib,
sl@0
    81
		NULL,
sl@0
    82
		KUsbMsMinHeapSize,
sl@0
    83
		KUsbMsMaxHeapSize,
sl@0
    84
		EOwnerProcess
sl@0
    85
	);
sl@0
    86
sl@0
    87
	lib.Close();	// if successful, server thread has handle to library now
sl@0
    88
#else
sl@0
    89
	//
sl@0
    90
	// EPOC and EKA2 is easy, we just create a new server process. Simultaneous
sl@0
    91
	// launching of two such processes should be detected when the second one
sl@0
    92
	// attempts to create the server object, failing with KErrAlreadyExists.
sl@0
    93
	//
sl@0
    94
	RProcess server;
sl@0
    95
	TInt err = server.Create(KUsbMsImg1, KNullDesC, serverUid);
sl@0
    96
	if (err == KErrNotFound)
sl@0
    97
		{
sl@0
    98
		err = server.Create(KUsbMsImg, KNullDesC, serverUid);
sl@0
    99
		}
sl@0
   100
#endif 
sl@0
   101
	
sl@0
   102
	if (err != KErrNone)
sl@0
   103
		{
sl@0
   104
		return err;
sl@0
   105
		}
sl@0
   106
sl@0
   107
	TRequestStatus stat;
sl@0
   108
	server.Rendezvous(stat);
sl@0
   109
	
sl@0
   110
	if (stat!=KRequestPending)
sl@0
   111
		server.Kill(0);		// abort startup
sl@0
   112
	else
sl@0
   113
		server.Resume();	// logon OK - start the server
sl@0
   114
sl@0
   115
	User::WaitForRequest(stat);		// wait for start or death
sl@0
   116
sl@0
   117
	// we can't use the 'exit reason' if the server panicked as this
sl@0
   118
	// is the panic 'reason' and may be '0' which cannot be distinguished
sl@0
   119
	// from KErrNone
sl@0
   120
	err = (server.ExitType() == EExitPanic) ? KErrServerTerminated : stat.Int();
sl@0
   121
sl@0
   122
	server.Close();
sl@0
   123
sl@0
   124
	return err;
sl@0
   125
	}
sl@0
   126
sl@0
   127
LOCAL_C void DoTestConnect()
sl@0
   128
    // 
sl@0
   129
    // Connect to the file server
sl@0
   130
    // 
sl@0
   131
    {
sl@0
   132
    test.Printf(_L("DoTestConnect\n"));
sl@0
   133
    // Load MS file server
sl@0
   134
    TInt r = StartServer();
sl@0
   135
    test(KErrNone == r);
sl@0
   136
    // Connect to MS file server
sl@0
   137
    r = gUsbMs.Connect();
sl@0
   138
    test(KErrNone == r);
sl@0
   139
    
sl@0
   140
    test.Printf(_L("DoTestConnect ====> PASS\n"));
sl@0
   141
    }
sl@0
   142
    
sl@0
   143
LOCAL_C void DoTestStart()
sl@0
   144
    //
sl@0
   145
    // Start mass storage device
sl@0
   146
    //
sl@0
   147
    {
sl@0
   148
sl@0
   149
    TMassStorageConfig msConfig;
sl@0
   150
    msConfig.iVendorId.Copy(t_vendorId);
sl@0
   151
    msConfig.iProductId.Copy(t_productId);
sl@0
   152
    msConfig.iProductRev.Copy(t_productRev);
sl@0
   153
sl@0
   154
    TInt r = gUsbMs.Start(msConfig);
sl@0
   155
    test(KErrNone == r);
sl@0
   156
    
sl@0
   157
    test.Printf(_L("DoTestStart ====> PASS\n"));
sl@0
   158
    }
sl@0
   159
sl@0
   160
LOCAL_C void DoTestStop()
sl@0
   161
    //
sl@0
   162
    // Stop USB device
sl@0
   163
    //
sl@0
   164
    {
sl@0
   165
    test.Printf(_L("TestStop\n"));
sl@0
   166
    TInt r = gUsbMs.Stop();
sl@0
   167
    test(KErrNone == r); 
sl@0
   168
    
sl@0
   169
    test.Printf(_L("DoTestStop ====> PASS\n"));;
sl@0
   170
    }
sl@0
   171
sl@0
   172
GLDEF_C void t_ms_clisvr()
sl@0
   173
//
sl@0
   174
// Do all tests
sl@0
   175
//
sl@0
   176
	{
sl@0
   177
	test.Next( _L("TestConnect") );
sl@0
   178
    DoTestConnect();
sl@0
   179
   	test.Next(_L("TestStart"));
sl@0
   180
    DoTestStart();
sl@0
   181
    test.Next(_L("TestStop"));
sl@0
   182
    DoTestStop();
sl@0
   183
 	gUsbMs.Shutdown();
sl@0
   184
	gUsbMs.Close();
sl@0
   185
    
sl@0
   186
    }
sl@0
   187
sl@0
   188
GLDEF_C void CallTestsL()
sl@0
   189
	{
sl@0
   190
	test.Start(_L("ClientServer Tests"));
sl@0
   191
	t_ms_clisvr();
sl@0
   192
	test.End();
sl@0
   193
	test.Start(_L("File System Unit Tests"));
sl@0
   194
	t_ms_fsunit();
sl@0
   195
	test.End();
sl@0
   196
	}