kerneltest/f32test/server/t_rand.cpp
branchRCL_3
changeset 44 3e88ff8f41d5
parent 43 c1f20ce4abcf
equal deleted inserted replaced
43:c1f20ce4abcf 44:3e88ff8f41d5
    13 // Description:
    13 // Description:
    14 // f32test\server\t_rand.cpp
    14 // f32test\server\t_rand.cpp
    15 // 
    15 // 
    16 //
    16 //
    17 
    17 
    18 #define __E32TEST_EXTENSION__
       
    19 #include <f32file.h>
    18 #include <f32file.h>
    20 #include <e32test.h>
    19 #include <e32test.h>
    21 #include <e32math.h>
    20 #include <e32math.h>
    22 #include <e32hal.h>
    21 #include <e32hal.h>
    23 #include "t_server.h"
    22 #include "t_server.h"
    42 
    41 
    43 	TUint8* bufPtr=(TUint8*)testBuf.Ptr();
    42 	TUint8* bufPtr=(TUint8*)testBuf.Ptr();
    44 	testBuf.SetLength(testBuf.MaxSize());
    43 	testBuf.SetLength(testBuf.MaxSize());
    45 	Mem::Fill(bufPtr,testBuf.MaxSize(),aCluster);
    44 	Mem::Fill(bufPtr,testBuf.MaxSize(),aCluster);
    46 	TInt r=aFile.Write(testBuf);
    45 	TInt r=aFile.Write(testBuf);
    47 	test_KErrNone(r);
    46 	test(r==KErrNone);
    48 	}
    47 	}
    49 
    48 
    50 LOCAL_C void SeekToCluster(RFile& aFile,TInt aCluster)
    49 LOCAL_C void SeekToCluster(RFile& aFile,TInt aCluster)
    51 //
    50 //
    52 // Seek to aCluster and check it is found correctly
    51 // Seek to aCluster and check it is found correctly
    53 //
    52 //
    54 	{
    53 	{
    55 	TBuf8<508> seekBuf(508);
    54 	TBuf8<508> seekBuf(508);
    56 	TInt r=aFile.Read(aCluster*testBuf.MaxSize(),seekBuf);
    55 	TInt r=aFile.Read(aCluster*testBuf.MaxSize(),seekBuf);
    57 	test_KErrNone(r);
    56 	test(r==KErrNone);
    58 	test(seekBuf[0]==(TUint8)aCluster && seekBuf[507]==(TUint8)aCluster);
    57 	test(seekBuf[0]==(TUint8)aCluster && seekBuf[507]==(TUint8)aCluster);
    59 	}
    58 	}
    60 
    59 
    61 LOCAL_C void SeekToCluster(RFile& aFile,TInt aCluster1,TInt aCluster2)
    60 LOCAL_C void SeekToCluster(RFile& aFile,TInt aCluster1,TInt aCluster2)
    62 //
    61 //
    63 // Seek to aCluster and check it is found correctly
    62 // Seek to aCluster and check it is found correctly
    64 //
    63 //
    65 	{
    64 	{
    66 	TBuf8<508> seekBuf(508);
    65 	TBuf8<508> seekBuf(508);
    67 	TInt r=aFile.Read(aCluster1*testBuf.MaxSize(),seekBuf);
    66 	TInt r=aFile.Read(aCluster1*testBuf.MaxSize(),seekBuf);
    68 	test_KErrNone(r);
    67 	test(r==KErrNone);
    69 	test(seekBuf[0]==(TUint8)aCluster1 && seekBuf[507]==(TUint8)aCluster1);
    68 	test(seekBuf[0]==(TUint8)aCluster1 && seekBuf[507]==(TUint8)aCluster1);
    70 	r=aFile.Read(aCluster2*testBuf.MaxSize(),seekBuf);
    69 	r=aFile.Read(aCluster2*testBuf.MaxSize(),seekBuf);
    71 	test_KErrNone(r);
    70 	test(r==KErrNone);
    72 	test(seekBuf[0]==(TUint8)aCluster2 && seekBuf[507]==(TUint8)aCluster2);
    71 	test(seekBuf[0]==(TUint8)aCluster2 && seekBuf[507]==(TUint8)aCluster2);
    73 	}
    72 	}
    74 
    73 
    75 LOCAL_C void ExhaustiveTest(RFile& aFile,TInt aCount1)
    74 LOCAL_C void ExhaustiveTest(RFile& aFile,TInt aCount1)
    76 //
    75 //
    99 
    98 
   100 	test.Next(_L("Create interleaved files"));
    99 	test.Next(_L("Create interleaved files"));
   101 	RFile f1,f2;
   100 	RFile f1,f2;
   102 //
   101 //
   103 	TInt r=f1.Replace(TheFs,_L("BIGFILE1.TST"),EFileWrite);
   102 	TInt r=f1.Replace(TheFs,_L("BIGFILE1.TST"),EFileWrite);
   104 	test_KErrNone(r);
   103 	test(r==KErrNone);
   105 	r=f2.Replace(TheFs,_L("BIGFILE2.TST"),EFileWrite);
   104 	r=f2.Replace(TheFs,_L("BIGFILE2.TST"),EFileWrite);
   106 	test_KErrNone(r);
   105 	test(r==KErrNone);
   107 //
   106 //
   108 	TInt maxListLength=4;
   107 	TInt maxListLength=4;
   109 	TInt i=0,k=0;
   108 	TInt i=0,k=0;
   110 	TInt countf1=0;
   109 	TInt countf1=0;
   111 	TInt countf2=0;
   110 	TInt countf2=0;
   146 	SeekToCluster(f1,5,5);
   145 	SeekToCluster(f1,5,5);
   147 
   146 
   148 	f1.Close();
   147 	f1.Close();
   149 	f2.Close();
   148 	f2.Close();
   150 	r=TheFs.Delete(_L("BIGFile1.tst"));
   149 	r=TheFs.Delete(_L("BIGFile1.tst"));
   151 	test_KErrNone(r);
   150 	test(r==KErrNone);
   152 	r=TheFs.Delete(_L("BIGFile2.tst"));
   151 	r=TheFs.Delete(_L("BIGFile2.tst"));
   153 	test_KErrNone(r);
   152 	test(r==KErrNone);
   154 	CheckDisk();
   153 	CheckDisk();
   155 	}
   154 	}
   156 
   155 
   157 LOCAL_C void Test2()
   156 LOCAL_C void Test2()
   158 //
   157 //
   162 
   161 
   163 	test.Next(_L("Regression Protection"));
   162 	test.Next(_L("Regression Protection"));
   164 	RFile f1,f2;
   163 	RFile f1,f2;
   165 //
   164 //
   166 	TInt r=f1.Replace(TheFs,_L("BIGFILE1.TST"),EFileWrite);
   165 	TInt r=f1.Replace(TheFs,_L("BIGFILE1.TST"),EFileWrite);
   167 	test_KErrNone(r);
   166 	test(r==KErrNone);
   168 	r=f2.Replace(TheFs,_L("BIGFILE2.TST"),EFileWrite);
   167 	r=f2.Replace(TheFs,_L("BIGFILE2.TST"),EFileWrite);
   169 	test_KErrNone(r);
   168 	test(r==KErrNone);
   170 //
   169 //
   171 	WriteCluster(f1,0);
   170 	WriteCluster(f1,0);
   172 	WriteCluster(f1,1);
   171 	WriteCluster(f1,1);
   173 	WriteCluster(f1,2);
   172 	WriteCluster(f1,2);
   174 	WriteCluster(f1,3);
   173 	WriteCluster(f1,3);
   181 	SeekToCluster(f1,4);
   180 	SeekToCluster(f1,4);
   182 //
   181 //
   183 	f1.Close();
   182 	f1.Close();
   184 	f2.Close();
   183 	f2.Close();
   185 	r=TheFs.Delete(_L("BIGFile1.tst"));
   184 	r=TheFs.Delete(_L("BIGFile1.tst"));
   186 	test_KErrNone(r);
   185 	test(r==KErrNone);
   187 	r=TheFs.Delete(_L("BIGFile2.tst"));
   186 	r=TheFs.Delete(_L("BIGFile2.tst"));
   188 	test_KErrNone(r);
   187 	test(r==KErrNone);
   189 	CheckDisk();
   188 	CheckDisk();
   190 	}
   189 	}
   191 
   190 
   192 LOCAL_C void Test3()
   191 LOCAL_C void Test3()
   193 //
   192 //
   199 	RFile f1;
   198 	RFile f1;
   200 	TheSeed=917824;
   199 	TheSeed=917824;
   201 	TInt i=0,j=0;
   200 	TInt i=0,j=0;
   202 //
   201 //
   203 	TInt r=f1.Replace(TheFs,_L("BIGFILE1.TST"),EFileWrite);
   202 	TInt r=f1.Replace(TheFs,_L("BIGFILE1.TST"),EFileWrite);
   204 	test_KErrNone(r);
   203 	test(r==KErrNone);
   205 	
   204 	
   206 	r=f1.SetSize(65534);
   205 	r=f1.SetSize(65534);
   207 	test_KErrNone(r);
   206 	test(r==KErrNone);
   208 
   207 
   209 	for(i=0;i<=15;i++)
   208 	for(i=0;i<=15;i++)
   210 		WriteCluster(f1,i);
   209 		WriteCluster(f1,i);
   211 
   210 
   212 	for (j=0;j<100;j++)
   211 	for (j=0;j<100;j++)
   216 		SeekToCluster(f1,cluster2,cluster1);
   215 		SeekToCluster(f1,cluster2,cluster1);
   217 		}
   216 		}
   218 
   217 
   219 	test.Next(_L("Increase Size"));
   218 	test.Next(_L("Increase Size"));
   220 	r=f1.SetSize(1048577);
   219 	r=f1.SetSize(1048577);
   221 	test_Value(r, r == KErrNone || r==KErrDiskFull);
   220 	test(r==KErrNone || r==KErrDiskFull);
   222 	if (r==KErrDiskFull)
   221 	if (r==KErrDiskFull)
   223 		{
   222 		{
   224 		test.Printf(_L("File too big\n"));
   223 		test.Printf(_L("File too big\n"));
   225 		f1.Close();
   224 		f1.Close();
   226 		return;
   225 		return;
   234 		SeekToCluster(f1,cluster2,cluster1);
   233 		SeekToCluster(f1,cluster2,cluster1);
   235 		}
   234 		}
   236 
   235 
   237 	TInt newPos=8192;
   236 	TInt newPos=8192;
   238 	r=f1.Seek(ESeekStart,newPos);
   237 	r=f1.Seek(ESeekStart,newPos);
   239 	test_KErrNone(r);
   238 	test(r==KErrNone);
   240 
   239 
   241 	test.Next(_L("Write more data"));
   240 	test.Next(_L("Write more data"));
   242 	for(i=16;i<83;i++)
   241 	for(i=16;i<83;i++)
   243 		WriteCluster(f1,i);
   242 		WriteCluster(f1,i);
   244 
   243 
   250 		SeekToCluster(f1,cluster2,cluster1);
   249 		SeekToCluster(f1,cluster2,cluster1);
   251 		}
   250 		}
   252 
   251 
   253 	test.Next(_L("Reduce file size"));
   252 	test.Next(_L("Reduce file size"));
   254 	r=f1.SetSize(135000);
   253 	r=f1.SetSize(135000);
   255 	test_KErrNone(r);
   254 	test(r==KErrNone);
   256 
   255 
   257 	test.Next(_L("Test data still present"));
   256 	test.Next(_L("Test data still present"));
   258 	for (j=0;j<200;j++)
   257 	for (j=0;j<200;j++)
   259 		{
   258 		{
   260 		TInt cluster1=Math::Rand(TheSeed)%31;
   259 		TInt cluster1=Math::Rand(TheSeed)%31;
   283 //
   282 //
   284 	: iFile(*aFile), iPos(0)
   283 	: iFile(*aFile), iPos(0)
   285 	{
   284 	{
   286 
   285 
   287 	TInt r=iFile.Read(0,iData);
   286 	TInt r=iFile.Read(0,iData);
   288 	test_KErrNone(r);
   287 	test(r==KErrNone);
   289 	}
   288 	}
   290 
   289 
   291 void TFileReader::Next(TUint8& aVal,TInt& aLength)
   290 void TFileReader::Next(TUint8& aVal,TInt& aLength)
   292 //
   291 //
   293 // Read aLength contiguous bytes with aVal
   292 // Read aLength contiguous bytes with aVal
   295 	{
   294 	{
   296 
   295 
   297 	if (iPos==iData.Length())
   296 	if (iPos==iData.Length())
   298 		{
   297 		{
   299 		TInt r=iFile.Read(iData);
   298 		TInt r=iFile.Read(iData);
   300 		test_KErrNone(r);
   299 		test(r==KErrNone);
   301 		iPos=0;
   300 		iPos=0;
   302 		if (iData.Length()==0)
   301 		if (iData.Length()==0)
   303 			{
   302 			{
   304 			aLength=0;
   303 			aLength=0;
   305 			return;
   304 			return;
   425 
   424 
   426 	RFile f[KMaxFiles];
   425 	RFile f[KMaxFiles];
   427 	HBufC8* dataBuf=HBufC8::NewL(KMaxBufferLength);
   426 	HBufC8* dataBuf=HBufC8::NewL(KMaxBufferLength);
   428 
   427 
   429 	TInt r=f[0].Replace(TheFs,_L("TEST1.DAT"),EFileWrite);
   428 	TInt r=f[0].Replace(TheFs,_L("TEST1.DAT"),EFileWrite);
   430 	test_KErrNone(r);
   429 	test(r==KErrNone);
   431 	r=f[1].Replace(TheFs,_L("TEST2.DAT"),EFileWrite);
   430 	r=f[1].Replace(TheFs,_L("TEST2.DAT"),EFileWrite);
   432 	test_KErrNone(r);
   431 	test(r==KErrNone);
   433 	r=f[2].Replace(TheFs,_L("TEST3.DAT"),EFileWrite);
   432 	r=f[2].Replace(TheFs,_L("TEST3.DAT"),EFileWrite);
   434 	test_KErrNone(r);
   433 	test(r==KErrNone);
   435 	r=f[3].Replace(TheFs,_L("TEST4.DAT"),EFileWrite);
   434 	r=f[3].Replace(TheFs,_L("TEST4.DAT"),EFileWrite);
   436 	test_KErrNone(r);
   435 	test(r==KErrNone);
   437 	
   436 	
   438 	TInt size=0;
   437 	TInt size=0;
   439 	TInt iteration=0;
   438 	TInt iteration=0;
   440 
   439 
   441 	FOREVER
   440 	FOREVER
   456 			{
   455 			{
   457 			TInt fileNum=(order+i)%KMaxFiles;
   456 			TInt fileNum=(order+i)%KMaxFiles;
   458 			TInt s=len*mult[fileNum];
   457 			TInt s=len*mult[fileNum];
   459 			TInt filePos=pos*mult[fileNum];
   458 			TInt filePos=pos*mult[fileNum];
   460 			r=f[fileNum].Seek(ESeekStart,filePos);
   459 			r=f[fileNum].Seek(ESeekStart,filePos);
   461 			test_KErrNone(r);
   460 			test(r==KErrNone);
   462 
   461 
   463 			while(s>0)
   462 			while(s>0)
   464 				{
   463 				{
   465 				TInt l=(s>KMaxBufferLength) ? KMaxBufferLength : s;
   464 				TInt l=(s>KMaxBufferLength) ? KMaxBufferLength : s;
   466 				dataBuf->Des().SetLength(l);
   465 				dataBuf->Des().SetLength(l);
   470 				if ((gDriveCacheFlags & EFileCacheWriteOn) && (r == KErrNone))
   469 				if ((gDriveCacheFlags & EFileCacheWriteOn) && (r == KErrNone))
   471 					r = f[fileNum].Flush();
   470 					r = f[fileNum].Flush();
   472 			
   471 			
   473 				if (r==KErrDiskFull)
   472 				if (r==KErrDiskFull)
   474 					goto End;
   473 					goto End;
   475 				test_KErrNone(r);
   474 				test(r==KErrNone);
   476 				s-=l;
   475 				s-=l;
   477 				}
   476 				}
   478 			
   477 			
   479 			}
   478 			}
   480 
   479 
   491 			test.Printf(_L("\nReduceSize newsize=%d\n"),size);
   490 			test.Printf(_L("\nReduceSize newsize=%d\n"),size);
   492 			for (TInt i=0;i<KMaxFiles;i++)
   491 			for (TInt i=0;i<KMaxFiles;i++)
   493 				{
   492 				{
   494 				TInt fileNum=(order+i)%KMaxFiles;
   493 				TInt fileNum=(order+i)%KMaxFiles;
   495 				r=f[fileNum].SetSize(size*mult[fileNum]);
   494 				r=f[fileNum].SetSize(size*mult[fileNum]);
   496 				test_KErrNone(r);
   495 				test(r==KErrNone);
   497 				}
   496 				}
   498 			CheckFileContents(&f[0]);
   497 			CheckFileContents(&f[0]);
   499 			}
   498 			}
   500 		}
   499 		}
   501 End:
   500 End: