1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/concur/t_cfssimple.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,504 @@
1.4 +// Copyright (c) 1996-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\concur\t_cfssimple.cpp
1.18 +//
1.19 +//
1.20 +#define __E32TEST_EXTENSION__
1.21 +#include <f32file.h>
1.22 +#include <e32test.h>
1.23 +#include "t_server.h"
1.24 +#include "t_tdebug.h"
1.25 +
1.26 +GLDEF_D RTest test(_L("T_CFSSIMPLE"));
1.27 +GLDEF_D RFs TheFs;
1.28 +
1.29 +LOCAL_D TFullName OldFsName;
1.30 +LOCAL_D TFileName NewFsName;
1.31 +
1.32 +_LIT(KFsFile, "CFAFSDLY");
1.33 +_LIT(KFsName, "DelayFS");
1.34 +
1.35 +
1.36 +struct TExtension
1.37 + {
1.38 + TFullName iName;
1.39 + TBool iExists;
1.40 + };
1.41 +
1.42 +LOCAL_D TExtension gPrimaryExtensions[KMaxDrives];
1.43 +
1.44 +LOCAL_C TChar MountTestFileSystem(TInt aDrive)
1.45 +//
1.46 +// Mount a new test filesystem on the drive under test
1.47 +//
1.48 + {
1.49 + TBuf<64> b;
1.50 + TChar c;
1.51 + TInt r;
1.52 + if (aDrive > EDriveZ)
1.53 + {
1.54 + c = aDrive;
1.55 + r=TheFs.CharToDrive(c, aDrive);
1.56 + test_KErrNone(r);
1.57 + }
1.58 + else
1.59 + {
1.60 + r=TheFs.DriveToChar(aDrive,c);
1.61 + test_KErrNone(r);
1.62 + }
1.63 +
1.64 + b.Format(_L("Test mounting of test file system on %c:"),(TUint)c);
1.65 + test.Next(b);
1.66 +
1.67 + test.Printf(_L("Load filesystem from %S\n"), &KFsFile);
1.68 +
1.69 + r=TheFs.AddFileSystem(KFsFile);
1.70 + test_Value(r, r == KErrNone || r == KErrAlreadyExists);
1.71 +
1.72 + r=TheFs.FileSystemName(OldFsName,aDrive);
1.73 + test_Value(r, r == KErrNone || r == KErrNotFound);
1.74 +
1.75 + if (OldFsName.Length() > 0)
1.76 + {
1.77 + r = TheFs.ExtensionName(gPrimaryExtensions[aDrive].iName, aDrive, 0);
1.78 + if (r == KErrNone)
1.79 + gPrimaryExtensions[aDrive].iExists = ETrue;
1.80 +
1.81 + test.Printf(_L("Dismount %S filesystem on %c:\n"), &OldFsName, (TUint)c);
1.82 + r=TheFs.DismountFileSystem(OldFsName,aDrive);
1.83 + if (r == KErrNotReady)
1.84 + {
1.85 + TDriveInfo d;
1.86 + r=TheFs.Drive(d, aDrive);
1.87 + test_KErrNone(r);
1.88 + if (d.iType == EMediaNotPresent)
1.89 + test.Printf(_L("%c: Medium not present - cannot perform test.\n"), (TUint)c);
1.90 + else
1.91 + test.Printf(_L("medium found (type %d) but drive %c: not ready\nPrevious test may have hung; else, check hardware.\n"), (TInt)d.iType, (TUint)c);
1.92 + }
1.93 + else if (r == KErrCorrupt)
1.94 + test.Printf(_L("drive %c: corrupted, cannot unmount\nPrevious test may have aborted; else, check hardware.\n"), (TUint)c);
1.95 +
1.96 + test_KErrNone(r);
1.97 + }
1.98 +
1.99 + test.Printf(_L("Mount filesystem %S\n"), &KFsName);
1.100 +
1.101 + if (gPrimaryExtensions[aDrive].iExists == EFalse)
1.102 + r=TheFs.MountFileSystem(KFsName,aDrive);
1.103 + else
1.104 + r=TheFs.MountFileSystem(KFsName,gPrimaryExtensions[aDrive].iName,aDrive);
1.105 + test_KErrNone(r);
1.106 +
1.107 + r=TheFs.FileSystemName(NewFsName,aDrive);
1.108 + test_KErrNone(r);
1.109 + test(NewFsName.Compare(KFsName)==0);
1.110 + test.Printf(_L("New %S filesystem on %c:\n"), &NewFsName, (TUint)c);
1.111 +
1.112 + // Check attributes
1.113 + TDriveInfo info;
1.114 + r=TheFs.Drive(info,aDrive);
1.115 + test_KErrNone(r);
1.116 +
1.117 + test.Printf(_L("iType=%d,iConnctionBusType=%d,iDriveAtt=%x,iMediaAtt=%x\n"),(TUint)info.iType,\
1.118 + (TUint)info.iConnectionBusType,info.iDriveAtt,info.iMediaAtt);
1.119 + return c;
1.120 + }
1.121 +
1.122 +LOCAL_C void UnmountFileSystem(TInt aDrive)
1.123 +//
1.124 +// Unmount the test filesystem on the drive under test
1.125 +//
1.126 + {
1.127 + TChar c;
1.128 + TInt r;
1.129 + if (aDrive > EDriveZ)
1.130 + {
1.131 + c = aDrive;
1.132 + r=TheFs.CharToDrive(c, aDrive);
1.133 + test_KErrNone(r);
1.134 + }
1.135 + else
1.136 + {
1.137 + r=TheFs.DriveToChar(aDrive,c);
1.138 + test_KErrNone(r);
1.139 + }
1.140 + test.Printf(_L("Dismount %S filesystem on %c\n"), &NewFsName, (TUint)c);
1.141 + r=TheFs.DismountFileSystem(NewFsName,aDrive);
1.142 + test_KErrNone(r);
1.143 + if (OldFsName.Length() > 0)
1.144 + {
1.145 + test.Printf(_L("Remount %S filesystem on %c\n"), &OldFsName, (TUint)c);
1.146 +
1.147 + if (gPrimaryExtensions[aDrive].iExists == EFalse)
1.148 + r=TheFs.MountFileSystem(OldFsName,aDrive);
1.149 + else
1.150 + r=TheFs.MountFileSystem(OldFsName,gPrimaryExtensions[aDrive].iName,aDrive);
1.151 + test_KErrNone(r);
1.152 + }
1.153 + }
1.154 +
1.155 +template <TInt N>
1.156 +LOCAL_C TDes* cvtbuff(const TDesC8& buff, TBuf<N>& b)
1.157 +//
1.158 +// Copy an 8-bit buffer to a character one.
1.159 +//
1.160 + {
1.161 + TInt i;
1.162 + TInt len = buff.Length();
1.163 + TInt max = b.MaxLength();
1.164 + if (len > max)
1.165 + len = max;
1.166 + b.SetLength(len);
1.167 + for (i = 0; i < len; i++)
1.168 + b[i] = TText(buff[i]);
1.169 + return &b;
1.170 + }
1.171 +
1.172 +//---------------------------------------------
1.173 +//! @SYMTestCaseID FSBASE-CR-PCHY-6PALT2
1.174 +//! @SYMTestType CT
1.175 +//! @SYMREQ CR PCHY-6PALT2
1.176 +//! @SYMTestCaseDesc Test asynchronous RFs::Flush(TRequestStatus& aStatus)
1.177 +//! @SYMTestStatus Implemented
1.178 +//! @SYMTestActions Perform an asynchronous flush and wait for completion
1.179 +//! @SYMTestExpectedResults Asynchronous flush completes after expected delay
1.180 +//! @SYMTestPriority Low
1.181 +//! @SYMAuthor Stefan Williams
1.182 +//! @SYMCreationDate 01/06/2006
1.183 +//! @See EFSRV and EFILE components
1.184 +//! @file f32test\concur\t_cfssimple.cpp
1.185 +//---------------------------------------------
1.186 +
1.187 +LOCAL_C void testAsyncFlush(RFile& aFile)
1.188 + {
1.189 + TTest::Printf(_L("Test Async RFile::Flush()"));
1.190 +
1.191 + RTimer flushTimer;
1.192 + TRequestStatus flushTimerStatus;
1.193 + TInt err = flushTimer.CreateLocal();
1.194 + TEST(err == KErrNone);
1.195 +
1.196 + flushTimer.After(flushTimerStatus, 10000000); // 10 seconds timeout for RFile::Flush on CFAFSDLY file system
1.197 +
1.198 + TTime startFlush;
1.199 + startFlush.HomeTime();
1.200 +
1.201 + TRequestStatus flushStatus;
1.202 + aFile.Flush(flushStatus);
1.203 + TEST(flushStatus==KRequestPending);
1.204 +
1.205 + User::WaitForRequest(flushTimerStatus, flushStatus);
1.206 + if ((flushStatus == KRequestPending) && (flushTimerStatus == KErrNone))
1.207 + {
1.208 + TTest::Fail(HERE, _L("Flush : Timed Out"));
1.209 + }
1.210 +
1.211 + if (flushStatus != KErrNone)
1.212 + {
1.213 + TTest::Fail(HERE, flushStatus.Int(), _L("Flush : Error"));
1.214 + }
1.215 +
1.216 + TTime endFlush;
1.217 + endFlush.HomeTime();
1.218 +
1.219 + TTimeIntervalSeconds flushTime;
1.220 + err = endFlush.SecondsFrom(startFlush, flushTime);
1.221 + TEST(err == KErrNone);
1.222 +
1.223 + TTest::Printf(_L("Flush took %d seconds"), flushTime.Int());
1.224 +
1.225 + if(flushTime.Int() < 3)
1.226 + {
1.227 + TTest::Fail(HERE, _L("Flush took < 3 Seconds"));
1.228 + }
1.229 +
1.230 + flushTimer.Cancel();
1.231 + flushTimer.Close();
1.232 + }
1.233 +
1.234 +LOCAL_C TInt testAccessFile(TAny*)
1.235 +//
1.236 +// Test read file handling with two threads.
1.237 +//
1.238 + {
1.239 + TTest::Start(_L("Test write file"));
1.240 +
1.241 + TThreadData& data = TTest::Self();
1.242 + TFileName fileName = data.iFile;
1.243 +
1.244 + TTest::Printf(_L("Connect to myFs\n"));
1.245 +
1.246 + RFs myFs;
1.247 + TInt r = myFs.Connect();
1.248 + TEST(r==KErrNone);
1.249 +
1.250 + TTest::Printf(_L("Create %S\n"), &fileName);
1.251 +
1.252 + RFile f;
1.253 +
1.254 + r = f.Replace(myFs, fileName, EFileStreamText | EFileWrite);
1.255 + TEST(r==KErrNone);
1.256 +
1.257 + // wait for both tasks to have a chance to complete opening the files
1.258 + User::After(1000);
1.259 +
1.260 + const TInt KNumBuf = 10;
1.261 + const TInt KBufLen = 0x80;
1.262 + TBuf8<KBufLen> a[KNumBuf];
1.263 + TBuf8<KBufLen> b;
1.264 + TBuf<KBufLen> tbuf;
1.265 + TInt i;
1.266 +
1.267 + TUint base = 0;
1.268 + for (i = 0; i < fileName.Length(); i++)
1.269 + base = base * 0x11 + fileName[i];
1.270 + base += base / 32;
1.271 + base = base % 32 + 0x30;
1.272 +
1.273 + TRequestStatus status[10];
1.274 +
1.275 + TTest::Next(_L("Write file"));
1.276 + for (i = 0; i <= 9; i++)
1.277 + {
1.278 + TChar val = TChar(base + i);
1.279 + a[i].Fill(TText(val), i+1);
1.280 + TTest::Printf(_L("write '%S' started\n"), cvtbuff(a[i], tbuf));
1.281 + f.Write(a[i], status[i]);
1.282 + User::After(1);
1.283 + if (r != KErrNone)
1.284 + {
1.285 + TTest::Fail(HERE, r, _L("Write"));
1.286 + }
1.287 + }
1.288 +
1.289 + for (i = 0; i < 10; i++)
1.290 + {
1.291 + User::WaitForAnyRequest();
1.292 + if (status[i] == KRequestPending)
1.293 + {
1.294 + TTest::Printf(_L("write %d still pending!\n"), i);
1.295 + }
1.296 + else
1.297 + {
1.298 + TTest::Printf(_L("write %d completed with status %d\n"), i, status[i].Int());
1.299 + }
1.300 + }
1.301 +
1.302 + TTest::Printf(_L("Write 64 bytes at the end as padding\n"));
1.303 + TBuf8<32> fill;
1.304 + fill.Fill(TText('_'), 32);
1.305 + f.Write(fill);
1.306 + f.Write(fill);
1.307 +
1.308 + testAsyncFlush(f);
1.309 +
1.310 + f.Close();
1.311 +
1.312 + b.Fill(TText('*'), b.MaxLength());
1.313 + TTest::Next(_L("Read file"));
1.314 +
1.315 + // wait to allow the dust to settle
1.316 + User::After(1000000);
1.317 +
1.318 + r = f.Open(myFs, fileName, EFileStreamText);
1.319 + TEST(r==KErrNone);
1.320 +
1.321 + for (i = 0; i < 10; i++)
1.322 + {
1.323 + r=f.Read(b, 12-i);
1.324 + if (r == KErrNone)
1.325 + {
1.326 + TTest::Printf(_L("read %2d bytes <%S>\n"), b.Length(), cvtbuff(b, tbuf));
1.327 + }
1.328 + else
1.329 + {
1.330 + TTest::Fail(HERE, r, _L("Read"));
1.331 + }
1.332 + User::After(1);
1.333 + }
1.334 + r=f.Read(b);
1.335 + if (r != KErrNone)
1.336 + {
1.337 + TTest::Fail(HERE, r, _L("Read\n"));
1.338 + // TEST(r==KErrNone);
1.339 + }
1.340 + if (!(b.Length()==0))
1.341 + {
1.342 + cvtbuff(b, tbuf);
1.343 + TTest::Printf(_L("read %2d bytes <%.32S>\n"), b.Length(), &tbuf);
1.344 + }
1.345 +
1.346 + // wait to allow the dust to settle
1.347 + User::After(1000000);
1.348 +
1.349 + TTest::Printf(_L("Close file"));
1.350 + f.Close();
1.351 +
1.352 + TTest::Printf(_L("Close session"));
1.353 + myFs.Close();
1.354 + return r;
1.355 + }
1.356 +
1.357 +LOCAL_C TInt createThread(TThreadFunction aFunc, TChar aDrvCh)
1.358 +//
1.359 +// Create a thread using function aFunc on drive aDrvCh
1.360 +//
1.361 + {
1.362 + static TInt tnum = 0;
1.363 + TBuf<2> drive(_L("?"));
1.364 + TBuf<64> name;
1.365 + drive[0] = TText(aDrvCh);
1.366 + drive.UpperCase();
1.367 + TThreadData& d = TTest::Data(tnum);
1.368 + d.iFile.Format(_L("%S:\\TEST%d.FILE"), &drive, tnum);
1.369 + name.Format(_L("Test_%S_%d"), &drive, tnum);
1.370 + TInt r = TTest::Create(tnum, aFunc, name);
1.371 + ++tnum;
1.372 + return r;
1.373 + }
1.374 +
1.375 +LOCAL_C TInt testThreads(TChar aDrvCh1, TChar aDrvCh2)
1.376 +//
1.377 +// Create threads operating on files on two drives.
1.378 +//
1.379 + {
1.380 + TInt r;
1.381 + r = createThread(testAccessFile, aDrvCh1);
1.382 + r = createThread(testAccessFile, aDrvCh2);
1.383 + r = TTest::Run();
1.384 + return r;
1.385 + }
1.386 +
1.387 +LOCAL_C TBool isSpace(TChar c)
1.388 +//
1.389 +// Return true if the character is space or tab
1.390 +//
1.391 + {
1.392 + return (c == ' ' || c == '\t');
1.393 + }
1.394 +
1.395 +LOCAL_C void parseCmd(TDesC& cmd, TChar& dr0, TChar& dr1, TChar& dr2)
1.396 +//
1.397 +// Parse command line to get two characters for drive 1 and 2
1.398 +//
1.399 + {
1.400 + TInt i = 0;
1.401 + TInt n = cmd.Length();
1.402 + // skip to first non-space
1.403 + while (i < n && isSpace(cmd[i]))
1.404 + ++i;
1.405 + if (i < n)
1.406 + dr0 = cmd[i];
1.407 + // skip to first space
1.408 + while (i < n && !isSpace(cmd[i]))
1.409 + ++i;
1.410 + // skip to first non-space
1.411 + while (i < n && isSpace(cmd[i]))
1.412 + ++i;
1.413 + if (i < n)
1.414 + dr1 = cmd[i];
1.415 + // skip to first space
1.416 + while (i < n && !isSpace(cmd[i]))
1.417 + ++i;
1.418 + // skip to first non-space
1.419 + while (i < n && isSpace(cmd[i]))
1.420 + ++i;
1.421 + if (i < n)
1.422 + dr2 = cmd[i];
1.423 + // skip to first space
1.424 + while (i < n && !isSpace(cmd[i]))
1.425 + ++i;
1.426 + }
1.427 +
1.428 +GLDEF_C void CallTestsL()
1.429 +//
1.430 +// Do all tests
1.431 +//
1.432 + {
1.433 + TBuf<0x100> cmd;
1.434 + User::CommandLine(cmd);
1.435 + cmd.UpperCase();
1.436 +
1.437 + TChar dr0 = 'F';
1.438 + TChar dr1 = 0;
1.439 + TChar dr2 = 0;
1.440 + parseCmd(cmd, dr0, dr1, dr2);
1.441 +
1.442 + if (dr1 < 'A')
1.443 + dr1 = dr0;
1.444 +
1.445 + if (dr2 < 'A')
1.446 + dr2 = dr1;
1.447 +
1.448 + if (dr0 < 'A' || dr0 >= 'Z')
1.449 + {
1.450 + test.Printf(_L("Test cannnot run on drive\n"));
1.451 + return;
1.452 + }
1.453 +
1.454 + MountTestFileSystem(dr0);
1.455 + // TheFs.SetVolumeLabel(_L("TRACE"));
1.456 + TInt r = testThreads(dr1, dr2);
1.457 + TheFs.SetVolumeLabel(_L("OFF"));
1.458 + UnmountFileSystem(dr0);
1.459 + test_KErrNone(r);
1.460 + }
1.461 +
1.462 +GLDEF_C TInt E32Main()
1.463 +//
1.464 +// Main entry point
1.465 +//
1.466 + {
1.467 +
1.468 + for (TInt i = 0; i < KMaxDrives; i++)
1.469 + {
1.470 + gPrimaryExtensions[i].iExists = EFalse;
1.471 + }
1.472 +
1.473 + TInt r;
1.474 + CTrapCleanup* cleanup;
1.475 + cleanup=CTrapCleanup::New();
1.476 + __UHEAP_MARK;
1.477 +
1.478 + test.Title();
1.479 + test.Start(_L("Starting tests..."));
1.480 +
1.481 + r=TheFs.Connect();
1.482 + test_KErrNone(r);
1.483 +
1.484 + // TheFs.SetAllocFailure(gAllocFailOn);
1.485 + TTime timerC;
1.486 + timerC.HomeTime();
1.487 +
1.488 + TRAP(r,CallTestsL());
1.489 +
1.490 + // reset the debug register
1.491 + TheFs.SetDebugRegister(0);
1.492 +
1.493 + TTime endTimeC;
1.494 + endTimeC.HomeTime();
1.495 + TTimeIntervalSeconds timeTakenC;
1.496 + r=endTimeC.SecondsFrom(timerC,timeTakenC);
1.497 + test_KErrNone(r);
1.498 + test.Printf(_L("Time taken for test = %d seconds\n"),timeTakenC.Int());
1.499 + // TheFs.SetAllocFailure(gAllocFailOff);
1.500 + TheFs.Close();
1.501 + test.End();
1.502 + test.Close();
1.503 + __UHEAP_MARKEND;
1.504 + delete cleanup;
1.505 + return(KErrNone);
1.506 + }
1.507 +