1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/bench/t_fsrrepeat.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,442 @@
1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// f32test\bench\t_fsrrepeat.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <f32file.h>
1.22 +#include <e32test.h>
1.23 +#include "t_select.h"
1.24 +#include "t_benchmain.h"
1.25 +
1.26 +
1.27 +GLDEF_D RTest test(_L("FS Benchmarks, Open and read 4 KB"));
1.28 +
1.29 +//----------------------------------------------------------------------------------------------
1.30 +//! @SYMTestCaseID PBASE-T_FSRREPEAT-0276
1.31 +//! @SYMTestType CIT
1.32 +//! @SYMPREQ PREQ000
1.33 +//! @SYMTestCaseDesc This test case is measuring performance of the FAT implementation
1.34 +//! @SYMTestActions 0. Expects the files to exist in order to successful execution
1.35 +//! 1. Time the opening and read 3 times 4 Kb of last.txt file in each directory
1.36 +//! 2. Time the opening and read 3 times 4 Kb of last.txt file in each directory
1.37 +//! with two clients accessing the directory
1.38 +//! 3. Time the opening and read 3 times of 4 Kb of last.txt file in each directory
1.39 +//! with two clients accessing different directories
1.40 +//!
1.41 +//! @SYMTestExpectedResults Finishes if the system behaves as expected, panics otherwise
1.42 +//! @SYMTestPriority High
1.43 +//! @SYMTestStatus Implemented
1.44 +//----------------------------------------------------------------------------------------------
1.45 +
1.46 +
1.47 +LOCAL_D RSemaphore client,write_screen;
1.48 +LOCAL_D const TInt KHeapSize=0x4000;
1.49 +
1.50 +LOCAL_D TDriveList gDriveList;
1.51 +
1.52 +LOCAL_D TFileName gDelEntryDir;
1.53 +LOCAL_D TFileName gDelEntryDir2;
1.54 +
1.55 +// Concurrent threads
1.56 +RThread gSpeedy;
1.57 +RThread gSpeedyII;
1.58 +TInt gT1;
1.59 +TInt gT2;
1.60 +TBool gKillMe = EFalse;
1.61 +
1.62 +LOCAL_D TInt ThreadCount = 0;
1.63 +LOCAL_D TBuf8<4096> buf;
1.64 +
1.65 +_LIT(KDirMultipleName2, "dir%d_%d\\");
1.66 +
1.67 +_LIT(KDeleteMe,"DELETE%d.ME");
1.68 +_LIT(KDeleteMe2,"BLABLA%d.RHD");
1.69 +
1.70 +
1.71 +/** Delete entry in directory
1.72 +
1.73 +*/
1.74 +LOCAL_C TInt DeleteEntryAccess2(TAny* )
1.75 + {
1.76 + RFs fs;
1.77 + TInt r = fs.Connect();
1.78 + TBuf<100> dirfile;
1.79 + TBuf<50> filename;
1.80 + RFile file;
1.81 +
1.82 + fs.SetSessionPath(gSessionPath);
1.83 + filename.Format(KDeleteMe2, gT2);
1.84 +
1.85 + dirfile = gDelEntryDir2;
1.86 + dirfile.Append(filename);
1.87 +
1.88 + client.Signal();
1.89 +
1.90 + FOREVER
1.91 + {
1.92 + if(!gKillMe)
1.93 + {
1.94 + r = file.Create(fs, dirfile, EFileShareAny|EFileWrite);
1.95 + if(r == KErrAlreadyExists)
1.96 + r = file.Open(fs, dirfile, EFileShareAny|EFileWrite);
1.97 + file.Close();
1.98 + FailIfError(r);
1.99 +
1.100 + r = fs.Delete(dirfile);
1.101 + if((r != KErrNone) && (r != KErrInUse))
1.102 + {
1.103 + test.Printf(_L("error = %d\n"), r);
1.104 + }
1.105 + test((r == KErrNone) || (r == KErrInUse));
1.106 + }
1.107 + }
1.108 + }
1.109 +
1.110 +/** Delete entry in directory
1.111 +
1.112 +*/
1.113 +LOCAL_C TInt DeleteEntryAccess(TAny*)
1.114 + {
1.115 + RFs fs2;
1.116 + TInt r = fs2.Connect();
1.117 + TBuf<100> dirfile;
1.118 + TBuf<50> filename;
1.119 + RFile file2;
1.120 + RTest test(_L("test 2"));
1.121 +
1.122 + fs2.SetSessionPath(gSessionPath);
1.123 + filename.Format(KDeleteMe,gT1);
1.124 +
1.125 + dirfile = gDelEntryDir;
1.126 + dirfile.Append(filename);
1.127 +
1.128 + client.Signal();
1.129 +
1.130 + FOREVER
1.131 + {
1.132 + if(!gKillMe)
1.133 + {
1.134 + r = file2.Create(fs2, dirfile, EFileShareAny|EFileWrite);
1.135 + if(r == KErrAlreadyExists)
1.136 + r = file2.Open(fs2, dirfile, EFileShareAny|EFileWrite);
1.137 + file2.Close();
1.138 + FailIfError(r);
1.139 +
1.140 + r = fs2.Delete(dirfile);
1.141 + if((r != KErrNone) && (r != KErrInUse))
1.142 + {
1.143 + test.Printf(_L("error = %d\n"), r);
1.144 + }
1.145 + test((r == KErrNone) || (r == KErrInUse));
1.146 + }
1.147 + }
1.148 + }
1.149 +
1.150 +/** Starts two concurrent client sessions in different directories
1.151 +
1.152 +*/
1.153 +LOCAL_C void DoTest2(TThreadFunction aFunction)
1.154 + {
1.155 + gKillMe = EFalse;
1.156 +
1.157 + TBuf<20> buf = _L("Speedy");
1.158 + buf.AppendNum(ThreadCount++);
1.159 + gT1 = ThreadCount;
1.160 + TInt r = gSpeedy.Create(buf, aFunction, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.161 + FailIfError(r);
1.162 +
1.163 + buf = _L("Speedy");
1.164 + buf.AppendNum(ThreadCount++);
1.165 + gT2 = ThreadCount;
1.166 + r = gSpeedyII.Create(buf, DeleteEntryAccess2, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
1.167 + FailIfError(r);
1.168 +
1.169 + gSpeedy.SetPriority(EPriorityLess);
1.170 + gSpeedyII.SetPriority(EPriorityLess);
1.171 +
1.172 + gSpeedy.Resume();
1.173 + gSpeedyII.Resume();
1.174 +
1.175 + client.Wait();
1.176 + client.Wait();
1.177 + }
1.178 +
1.179 +/** Kills the concurrent session
1.180 +
1.181 +*/
1.182 +LOCAL_C void DoTestKill()
1.183 + {
1.184 + gKillMe = ETrue;
1.185 + User::After(10000000);
1.186 +
1.187 + gSpeedy.Kill(KErrNone);
1.188 + gSpeedy.Close();
1.189 +
1.190 + gSpeedyII.Kill(KErrNone);
1.191 + gSpeedyII.Close();
1.192 + }
1.193 +
1.194 +/** Open last.txt with RFs and without any other process
1.195 +
1.196 + @param aN Number of files in the directory
1.197 + @param aType Type of files
1.198 + @param aStep Test step
1.199 +*/
1.200 +LOCAL_C void OpenFile(TInt aN, TInt aType, TInt aStep)
1.201 + {
1.202 + TBuf16<100> file;
1.203 + TBuf16<100> dir;
1.204 +
1.205 + TInt r = 0;
1.206 + TTime startTime;
1.207 + TTime endTime;
1.208 + TTimeIntervalMicroSeconds timeTaken(0);
1.209 + TInt timeTakenArray[3] = {-1, -1, -1};
1.210 + TInt i;
1.211 + RFile f;
1.212 +
1.213 + if(aN <= gFilesLimit)
1.214 + {
1.215 + if(aType <= gTypes)
1.216 + {
1.217 + file = gSessionPath;
1.218 +
1.219 + dir.Format(KDirMultipleName2, aType, aN);
1.220 + file.Append(dir);
1.221 +
1.222 + file.Append(KCommonFile);
1.223 +
1.224 + i = 0;
1.225 + while(i < 3)
1.226 + {
1.227 + startTime.HomeTime();
1.228 +
1.229 + r = f.Open(TheFs, file, EFileShareAny|EFileRead);
1.230 + FailIfError(r);
1.231 + r = f.Read(buf);
1.232 + FailIfError(r);
1.233 +
1.234 + f.Close();
1.235 +
1.236 + endTime.HomeTime();
1.237 +
1.238 + timeTaken = endTime.MicroSecondsFrom(startTime);
1.239 + timeTakenArray[i++] = I64LOW(timeTaken.Int64() / gTimeUnit);
1.240 + }
1.241 + }
1.242 + }
1.243 +
1.244 + dir.Format(KDirMultipleName,aType,aN);
1.245 +
1.246 + PrintResultS(aStep, 1, dir);
1.247 + PrintResultTime(aStep, 2, timeTakenArray[0]);
1.248 + PrintResultTime(aStep, 3, timeTakenArray[1]);
1.249 + PrintResultTime(aStep, 4, timeTakenArray[2]);
1.250 + }
1.251 +
1.252 +/** Times the opening of a file and read operation
1.253 + Precondition: This test expects the drive already filled with the right files
1.254 +
1.255 + @param aSelector Configuration in case of manual execution
1.256 +*/
1.257 +LOCAL_C TInt TestOpen(TAny* aSelector)
1.258 + {
1.259 + TInt i = 100, j;
1.260 + TInt testStep;
1.261 +
1.262 + Validate(aSelector);
1.263 +
1.264 + test.Printf(_L("#~TS_Title_%d,%d: Open last.txt and read 4 K repeatedly, RFs::Open\n"), gTestHarness, gTestCase);
1.265 +
1.266 + i = 100;
1.267 + testStep = 1;
1.268 + while(i <= KMaxFiles)
1.269 + {
1.270 + if(i == 100 || i == 1000 || i == 5000 || i == 10000)
1.271 + {
1.272 + j = 1;
1.273 + while(j <= KMaxTypes)
1.274 + {
1.275 + OpenFile(i, j, testStep++);
1.276 + j++;
1.277 + }
1.278 + }
1.279 + i += 100;
1.280 + }
1.281 +
1.282 + gTestCase++;
1.283 + return(KErrNone);
1.284 + }
1.285 +
1.286 +/** Times the opening of a file and read operation with two threads accessing
1.287 + different directories
1.288 +
1.289 + @param aSelector Configuration in case of manual execution
1.290 +*/
1.291 +LOCAL_C TInt TestOpenMultSame(TAny* aSelector)
1.292 + {
1.293 + TInt i = 100,j;
1.294 + TBuf16<50> directory;
1.295 + TBuf16<50> dirtemp;
1.296 + TInt testStep;
1.297 +
1.298 + Validate(aSelector);
1.299 +
1.300 + test.Printf(_L("#~TS_Title_%d,%d: Open last.txt and read 4 K repeatedly with mult clients accessing, RFs::Open\n"), gTestHarness, gTestCase);
1.301 +
1.302 + i = 100;
1.303 + testStep = 1;
1.304 + while(i <= KMaxFiles)
1.305 + {
1.306 + if(i == 100 || i == 1000 || i == 5000 || i == 10000)
1.307 + {
1.308 + j = 1;
1.309 + while(j <= KMaxTypes)
1.310 + {
1.311 + directory = gSessionPath;
1.312 + dirtemp.Format(KDirMultipleName2, j, i);
1.313 + directory.Append(dirtemp);
1.314 + gDelEntryDir = directory;
1.315 + gDelEntryDir2 = directory;
1.316 +
1.317 + DoTest2(DeleteEntryAccess);
1.318 +
1.319 + OpenFile(i, j, testStep++);
1.320 +
1.321 + DoTestKill();
1.322 +
1.323 + j++;
1.324 + }
1.325 + }
1.326 + i += 100;
1.327 + }
1.328 +
1.329 + gTestCase++;
1.330 + return(KErrNone);
1.331 + }
1.332 +
1.333 +/** Times the opening of a file and read operation with two threads accessing
1.334 + different directories
1.335 +
1.336 + @param aSelector Configuration in case of manual execution
1.337 +*/
1.338 +LOCAL_C TInt TestOpenMultDif(TAny* aSelector)
1.339 + {
1.340 + TInt i = 100,j;
1.341 + TBuf16<50> directory;
1.342 + TBuf16<50> dirtemp;
1.343 + TInt testStep;
1.344 +
1.345 + Validate(aSelector);
1.346 +
1.347 + CreateDirWithNFiles(300,3);
1.348 +
1.349 + directory = gSessionPath;
1.350 + dirtemp.Format(KDirMultipleName2, 3, 300);
1.351 + directory.Append(dirtemp);
1.352 +
1.353 + gDelEntryDir2 = directory;
1.354 +
1.355 + test.Printf(_L("#~TS_Title_%d,%d: Open last.txt and read 4 K repeatedly mult clients accessing dif dirs, RFs::Open\n"), gTestHarness, gTestCase);
1.356 +
1.357 + i = 100;
1.358 + testStep = 1;
1.359 + while(i <= KMaxFiles)
1.360 + {
1.361 + if(i == 100 || i == 1000 || i == 5000 || i == 10000)
1.362 + {
1.363 + j = 1;
1.364 + while(j <= KMaxTypes)
1.365 + {
1.366 + directory = gSessionPath;
1.367 + dirtemp.Format(KDirMultipleName2, j, i);
1.368 + directory.Append(dirtemp);
1.369 + gDelEntryDir = directory;
1.370 +
1.371 + DoTest2(DeleteEntryAccess);
1.372 +
1.373 + OpenFile(i, j, testStep++);
1.374 +
1.375 + DoTestKill();
1.376 +
1.377 + j++;
1.378 + }
1.379 + }
1.380 + i += 100;
1.381 + }
1.382 +
1.383 + gTestCase++;
1.384 + return(KErrNone);
1.385 + }
1.386 +
1.387 +/** It goes automatically through all the options
1.388 +
1.389 + @param aSelector Configuration in case of manual execution
1.390 +*/
1.391 +LOCAL_C TInt TestAll(TAny* aSelector)
1.392 + {
1.393 +
1.394 + TestOpen(aSelector);
1.395 + TestOpenMultSame(aSelector);
1.396 + TestOpenMultDif(aSelector);
1.397 +
1.398 + return(KErrNone);
1.399 + }
1.400 +
1.401 +/** Call all tests
1.402 +
1.403 +*/
1.404 +GLDEF_C void CallTestsL()
1.405 + {
1.406 +
1.407 + TInt r=client.CreateLocal(0);
1.408 + FailIfError(r);
1.409 +
1.410 + gFileSize = 8;
1.411 +
1.412 + // Each test case of the suite has an identifyer for parsing purposes of the results
1.413 + gTestHarness = 5;
1.414 + gTestCase = 1;
1.415 +
1.416 + PrintHeaders(2, _L("t_fsrrepeat. Repeat reading"));
1.417 +
1.418 + CSelectionBox* TheSelector = CSelectionBox::NewL(test.Console());
1.419 +
1.420 +
1.421 + if(gMode == 0)
1.422 + { // Manual
1.423 + gSessionPath = _L("?:\\");
1.424 + TCallBack createFiles(TestFileCreate,TheSelector);
1.425 + TCallBack openF(TestOpen,TheSelector);
1.426 + TCallBack openMultSame(TestOpenMultSame,TheSelector);
1.427 + TCallBack openMultDif(TestOpenMultDif,TheSelector);
1.428 + TCallBack openAll(TestAll,TheSelector);
1.429 + TheSelector->AddDriveSelectorL(TheFs);
1.430 + TheSelector->AddLineL(_L("Create all files"),createFiles);
1.431 + TheSelector->AddLineL(_L("Open and read repeatedly"),openF);
1.432 + TheSelector->AddLineL(_L("Same mult clients same dir "),openMultSame);
1.433 + TheSelector->AddLineL(_L("Same mult clients dif dir"),openMultDif);
1.434 + TheSelector->AddLineL(_L("Execute all options"),openAll);
1.435 + TheSelector->Run();
1.436 + }
1.437 + else
1.438 + { // Automatic
1.439 + TestAll(TheSelector);
1.440 + }
1.441 +
1.442 + client.Close();
1.443 + test.Printf(_L("#~TestEnd_%d\n"), gTestHarness);
1.444 + delete TheSelector;
1.445 + }