kerneltest/f32test/fsstress/t_rmain.cpp
changeset 0 a41df078684a
child 109 b3a1d9898418
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1998-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\fsstress\t_rmain.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #if !defined(__F32FILE_H__)
       
    19 #include <f32file.h>
       
    20 #endif
       
    21 #if !defined(__E32TEST_H__)
       
    22 #include <e32test.h>
       
    23 #endif
       
    24 #if !defined(__E32HAL_H__)
       
    25 #include <e32hal.h>
       
    26 #endif
       
    27 #if !defined(__E32MATH_H__)
       
    28 #include <e32math.h>
       
    29 #endif
       
    30 #if !defined(__F32DBG_H__)
       
    31 #include <f32dbg.h>
       
    32 #endif
       
    33 #include "t_std.h"
       
    34 
       
    35 
       
    36 GLDEF_D	RFs TheFs;
       
    37 GLDEF_D TFileName gSessionPath;
       
    38 GLDEF_D TInt gAllocFailOff=KAllocFailureOff;
       
    39 GLDEF_D TInt gAllocFailOn=KAllocFailureOff;
       
    40 GLDEF_D TInt64 gSeed=51703;
       
    41 const TInt KHeapSize=0x2000;
       
    42 
       
    43 
       
    44 
       
    45 GLDEF_C void TurnAllocFailureOff()
       
    46 //
       
    47 // Switch off all allocFailure
       
    48 //
       
    49 	{
       
    50 
       
    51 	test.Printf(_L("Disable Alloc Failure\n"));
       
    52 	TheFs.SetAllocFailure(gAllocFailOff);
       
    53 	gAllocFailOn=KAllocFailureOff;
       
    54 	}
       
    55 
       
    56 GLDEF_C void TurnAllocFailureOn()
       
    57 //
       
    58 // Switch off all allocFailure
       
    59 //
       
    60 	{
       
    61 
       
    62 	test.Printf(_L("Enable Alloc Failure\n"));
       
    63 	gAllocFailOn=KAllocFailureOn; 
       
    64 	TheFs.SetAllocFailure(gAllocFailOn);
       
    65 	}
       
    66 
       
    67 
       
    68 GLDEF_C void Format(TInt aDrive)
       
    69 //
       
    70 // Format current drive
       
    71 //
       
    72 	{
       
    73 
       
    74 	test.Next(_L("Format"));
       
    75 	TBuf<4> driveBuf=_L("?:\\");
       
    76 	driveBuf[0]=(TText)(aDrive+'A');
       
    77 	RFormat format;
       
    78 	TInt count;
       
    79 	TInt r=format.Open(TheFs,driveBuf,EHighDensity,count);
       
    80 	test(r==KErrNone);
       
    81 	while(count)
       
    82 		{
       
    83 		TInt r=format.Next(count);
       
    84 		test(r==KErrNone);
       
    85 		}
       
    86 	format.Close();
       
    87 	}
       
    88 
       
    89 LOCAL_C void PushLotsL()
       
    90 //
       
    91 // Expand the cleanup stack
       
    92 //
       
    93 	{
       
    94 	TInt i;
       
    95 	for(i=0;i<1000;i++)
       
    96 		CleanupStack::PushL((CBase*)NULL);
       
    97 	CleanupStack::Pop(1000);
       
    98 	}
       
    99 
       
   100 	
       
   101 LOCAL_C void DoTests(TInt aDrive)
       
   102 //
       
   103 // Do testing on aDrive
       
   104 //
       
   105 	{
       
   106 
       
   107 	gSessionPath=_L("?:\\F32-TST\\");
       
   108 	TChar driveLetter;
       
   109 	TInt r=TheFs.DriveToChar(aDrive,driveLetter);
       
   110 	test(r==KErrNone);
       
   111 	gSessionPath[0]=(TText)driveLetter;
       
   112 	r=TheFs.SetSessionPath(gSessionPath);
       
   113 	test(r==KErrNone);
       
   114 	r=TheFs.MkDirAll(gSessionPath);
       
   115 	test(r==KErrNone || r==KErrAlreadyExists);
       
   116 	TheFs.ResourceCountMarkStart();
       
   117 	
       
   118 	switch(aDrive)
       
   119 		{
       
   120 #if defined (__MARM__)
       
   121 	case EDriveC:
       
   122 		TRAP(r,CallTestsYL(aDrive));
       
   123 		break;
       
   124 	case EDriveD:
       
   125 		TRAP(r,CallTestsXL(aDrive));
       
   126 		break;
       
   127 #else
       
   128 	case EDriveX:
       
   129 		TRAP(r,CallTestsXL(aDrive));
       
   130 		break;
       
   131 	case EDriveY:
       
   132 		TRAP(r,CallTestsYL(aDrive));
       
   133 		break;
       
   134 #endif
       
   135 	case EDriveQ:
       
   136 		TRAP(r,CallTestsQL(aDrive));
       
   137 		break;
       
   138 	default:
       
   139 		TRAP(r,CallTestsDefaultL(aDrive));	
       
   140 		break;
       
   141 		}
       
   142 	
       
   143 	if (r==KErrNone)
       
   144 		TheFs.ResourceCountMarkEnd();
       
   145 	else
       
   146 		{
       
   147 		test.Printf(_L("Error: Leave %d\n"),r);
       
   148 		test.Getch();
       
   149 		}
       
   150 	}
       
   151 		
       
   152 
       
   153 LOCAL_C TInt TestXDrive(TAny * /*anArg*/)
       
   154 //
       
   155 //	MARM CF card drive testing (WINS emulates CF card on X)
       
   156 //
       
   157 	{
       
   158 	CTrapCleanup* cleanup;
       
   159 	cleanup=CTrapCleanup::New();
       
   160 
       
   161 	testx.Title();
       
   162 
       
   163 	TInt r=TheFs.Connect();
       
   164 	testx(r==KErrNone);
       
   165 //	TheFs.SetAllocFailure(gAllocFailOn);
       
   166 	
       
   167 #if defined (__WINS__)
       
   168 
       
   169 //	Run tests on WINS drive X:	
       
   170 	testx.Start(_L("Starting tests on drive X:"));
       
   171 	DoTests(EDriveX);
       
   172 	
       
   173 #elif defined (__MARM__)
       
   174 //	Run tests on MARM drive D:
       
   175 	testx.Start(_L("Starting tests on drive D:"));
       
   176 	DoTests(EDriveD);
       
   177 #endif
       
   178 
       
   179 //	TheFs.SetAllocFailure(gAllocFailOff);
       
   180 	delete cleanup;
       
   181 	testx.End();
       
   182 	
       
   183 	return KErrNone;
       
   184 	}
       
   185 
       
   186 
       
   187 LOCAL_C TInt TestYDrive(TAny * /*anArg*/)
       
   188 //
       
   189 //	MARM RAM drive testing (WINS emulates FAT filesystem on Y)  		
       
   190 //
       
   191 	{
       
   192 	CTrapCleanup* cleanup;
       
   193 	cleanup=CTrapCleanup::New();
       
   194 
       
   195 	testy.Title();
       
   196 	TInt r=TheFs.Connect();
       
   197 	testy(r==KErrNone);
       
   198 
       
   199 //	TheFs.SetAllocFailure(gAllocFailOn);
       
   200 
       
   201 #if defined (__WINS__)
       
   202 
       
   203 //	Run tests on WINS drive Y:
       
   204 	testy.Start(_L("Starting tests on drive Y:"));
       
   205 	DoTests(EDriveY);
       
   206 
       
   207 #elif defined (__MARM__)
       
   208 
       
   209 //	Run tests on MARM drive C:
       
   210 	testy.Start(_L("Starting tests on drive C:"));
       
   211 	DoTests(EDriveC);
       
   212 #endif
       
   213 	
       
   214 //	TheFs.SetAllocFailure(gAllocFailOff);	
       
   215 	delete cleanup;
       
   216 	testy.End();
       
   217 	return KErrNone;
       
   218 	}
       
   219 
       
   220 
       
   221 LOCAL_C TInt TestRemoteDrive(TAny * /*anArg*/)
       
   222 //
       
   223 // Run tests on remote drive Q:
       
   224 //
       
   225 	{	
       
   226 	CTrapCleanup* cleanup;
       
   227 	cleanup=CTrapCleanup::New();
       
   228 
       
   229 	testq.Title();
       
   230 	testq.Start(_L("Starting async tests..."));
       
   231 
       
   232 	TInt r=TheFs.Connect();
       
   233 	testq(r==KErrNone);
       
   234 //	TheFs.SetAllocFailure(gAllocFailOn);
       
   235 
       
   236 	testq.Next(_L("Mount Remote Drive simulator on Q:"));
       
   237 	
       
   238 	r=TheFs.AddFileSystem(_L("T_REMFSY"));
       
   239 	testq.Next(_L("Add remote file system"));
       
   240 	testq.Printf(_L("AddFileSystem returned %d\n"),r);
       
   241 //	testq(r==KErrNone || r==KErrAlreadyExists);
       
   242 
       
   243 	r=TheFs.MountFileSystem(_L("T_REMFSY"),EDriveQ);
       
   244 	testq.Next(_L("Mount remote file system"));
       
   245 	testq.Printf(_L("MountFileSystem returned %d\n"),r);
       
   246 	testq(r==KErrNone || r==KErrCorrupt || r==KErrNotReady || r==KErrAlreadyExists);
       
   247 	if (r==KErrCorrupt || r==KErrNotReady)
       
   248 		Format(EDriveQ);
       
   249 	
       
   250 	DoTests(EDriveQ);
       
   251 //	TheFs.SetAllocFailure(gAllocFailOff);
       
   252 	
       
   253 	delete cleanup;
       
   254 	testq.End();
       
   255 	return KErrNone;
       
   256 	}
       
   257 
       
   258 
       
   259 GLDEF_C TInt E32Main()
       
   260 //
       
   261 // Test with drive nearly full
       
   262 //
       
   263     {
       
   264 	CTrapCleanup* cleanup;
       
   265 	cleanup=CTrapCleanup::New();
       
   266 	TRAPD(r,PushLotsL());
       
   267  	__UHEAP_MARK;
       
   268 
       
   269 	test.Title();
       
   270 	test.Start(_L("Starting tests..."));
       
   271 	r=TheFs.Connect();
       
   272 	test(r==KErrNone);
       
   273 //	TheFs.SetAllocFailure(gAllocFailOn);
       
   274 
       
   275 //	Default drive testing
       
   276 	DoTests(KDefaultDrive);	
       
   277 
       
   278 //	Remote drive testing
       
   279 	RThread clientThreadQ;
       
   280 	r=clientThreadQ.Create(_L("TestRemoteDrive"), TestRemoteDrive, KDefaultStackSize,KHeapSize,KHeapSize,NULL);	
       
   281 	test(r==KErrNone);	
       
   282 	TRequestStatus statq;
       
   283 	clientThreadQ.Logon(statq);
       
   284 	test.Next(_L("Resume clientThreadQ"));	
       
   285 	clientThreadQ.Resume();
       
   286 
       
   287 //	MARM CF card drive testing (WINS emulates CF card on X)
       
   288 	RThread clientThreadX;
       
   289 	r=clientThreadX.Create(_L("TestXDrive"), TestXDrive, KDefaultStackSize,KHeapSize,KHeapSize,NULL);	
       
   290 	test(r==KErrNone);	
       
   291 	TRequestStatus statx;
       
   292 	clientThreadX.Logon(statx);
       
   293 	test.Next(_L("Resume clientThreadX"));	
       
   294 	clientThreadX.Resume();
       
   295 
       
   296 //	MARM RAM drive testing (WINS emulates FAT filesystem on Y)  	
       
   297 	RThread clientThreadY;
       
   298 	r=clientThreadY.Create(_L("TestYDrive"), TestYDrive, KDefaultStackSize,KHeapSize,KHeapSize,NULL);	
       
   299 	test(r==KErrNone);	
       
   300 	TRequestStatus staty;
       
   301 	clientThreadY.Logon(staty);
       
   302 	test.Next(_L("Resume clientThreadY"));	
       
   303 	clientThreadY.Resume();
       
   304 
       
   305 	User::WaitForRequest(statx);
       
   306 	User::WaitForRequest(staty);
       
   307 	User::WaitForRequest(statq);
       
   308 
       
   309 	clientThreadQ.Close();
       
   310 	clientThreadX.Close();
       
   311 	clientThreadY.Close();
       
   312 
       
   313 //	TheFs.SetAllocFailure(gAllocFailOff);
       
   314 	TheFs.Close();
       
   315 	  
       
   316 	test.End();
       
   317 	test.Close();
       
   318 	__UHEAP_MARKEND;
       
   319 	delete cleanup;
       
   320 	return(KErrNone);
       
   321     }