1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/server/t_corruptlog.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,216 @@
1.4 +// Copyright (c) 2004-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\server\t_corruptlog.cpp
1.18 +// Includes
1.19 +//
1.20 +//
1.21 +
1.22 +//! @file
1.23 +//! @SYMTestCaseID FSBASE_corrupt_log
1.24 +//! @SYMPREQ 908
1.25 +//! @SYMTestSuites Base tests
1.26 +//! @SYMInitialAuthor Bob Jackman
1.27 +//! @SYMCreationDate 1/11/04
1.28 +//! @SYMTestCaseDesc Check trap action of CorruptFileNames.lst
1.29 +
1.30 +#include <e32test.h>
1.31 +RTest test(_L("t_corruptlog"));
1.32 +
1.33 +#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
1.34 +#include <f32file.h>
1.35 +#include <f32dbg.h>
1.36 +
1.37 +// Error every time
1.38 +_LIT(KTestFile1,"z:\\system\\data\\BadFile1.txt");
1.39 +const TInt KTestFile1Error1=-6;
1.40 +const TInt KTestFile1Error2=KErrNone;
1.41 +//
1.42 +// Error once
1.43 +_LIT(KTestFile2,"z:\\system\\data\\BadFile2.txt");
1.44 +const TInt KTestFile2Error1=-20;
1.45 +const TInt KTestFile2Error2=-20;
1.46 +
1.47 +////////////////////////////////////////////////////////////
1.48 +// Globals
1.49 +//
1.50 +static RFs TheFs;
1.51 +
1.52 +static TInt numberOfTraps=0;
1.53 +
1.54 +////////////////////////////////////////////////////////////
1.55 +
1.56 +inline TInt controlIo(RFs &fs, TInt drv, TInt fn)
1.57 + {
1.58 + TPtr8 pDummy(NULL,0,0);
1.59 + TInt r = fs.ControlIo(drv, fn, pDummy);
1.60 + return r;
1.61 + }
1.62 +
1.63 +inline TInt controlIo(RFs &fs, TInt drv, TInt fn, TInt &aNumRecs)
1.64 + {
1.65 + TPtr8 pNum((TUint8*)(&aNumRecs),sizeof(aNumRecs),sizeof(aNumRecs));
1.66 + TInt r = fs.ControlIo(drv, fn, pNum);
1.67 + return r;
1.68 + }
1.69 +
1.70 +inline TInt controlIo(RFs &fs, TInt drv, TInt fn, TDes& aFileName)
1.71 + {
1.72 + TBuf8<KMaxFileName> fileName8;
1.73 + TInt r = fs.ControlIo(drv, fn, fileName8);
1.74 + if(r==KErrNone)
1.75 + {
1.76 + aFileName.Copy(fileName8);
1.77 + }
1.78 + return r;
1.79 + }
1.80 +
1.81 +
1.82 +inline TInt controlIo(RFs &fs, TInt drv, TInt fn, TFsDebugCorruptLogRecordBuf &alogRec, TInt aRecNum)
1.83 + {
1.84 + TInt r = fs.ControlIo(drv, fn, alogRec, *((TDes8*)aRecNum));
1.85 + return r;
1.86 + }
1.87 +
1.88 +void PrintLogRecord(TFsDebugCorruptLogRecordBuf &alogRec, TInt aRecordNumber)
1.89 + {
1.90 + test.Printf(_L("#%d Process: %S tried to access %S errorCode=%d\n"),aRecordNumber,
1.91 + &(alogRec().iProcessName),
1.92 + &(alogRec().iFileName),
1.93 + alogRec().iError);
1.94 + }
1.95 +
1.96 +TInt ResetCorruptLogRecords()
1.97 + {
1.98 + // Allows the test to be run again, by resetting the record to an unused state,
1.99 + // and destroying the trap records
1.100 + // Enables this test to be ran again.
1.101 + TInt r=controlIo(TheFs, EDriveC, KControlIoCorruptLogRecordReset);
1.102 + return r;
1.103 + }
1.104 +
1.105 +TInt GetNumberOfTraps()
1.106 + {
1.107 + // fetchs the number of corrupt file trap records that exist
1.108 + // there is a separate record for every attempted access to a nominated file
1.109 + // Note that C: is used in the IoControl call, which requires a valid drive, but has no other relevance
1.110 + TInt numberOfRecords;
1.111 + TInt r=controlIo(TheFs, EDriveC, KControlIoGetNumberOfCorruptLogRecords, numberOfRecords);
1.112 + test(r==KErrNone);
1.113 + return numberOfRecords;
1.114 + }
1.115 +
1.116 +TInt GetTrapLogRecord(TFsDebugCorruptLogRecordBuf &alogRec, TInt aRecordNumber)
1.117 + {
1.118 + // fetchs a trap record
1.119 + // Note that C: is used in the IoControl call, which requires a valid drive, but has no other relevance
1.120 + TInt r=controlIo(TheFs, EDriveC, KControlIoGetCorruptLogRecord, alogRec, aRecordNumber);
1.121 + test(r==KErrNone);
1.122 + return r;
1.123 + }
1.124 +
1.125 +TInt GetCorruptFileListFile(TDes& aFileName)
1.126 + {
1.127 + // Retrieves the name of the file containing the list of files, nominated as corrupt, used to generate
1.128 + // the corrupt files list.
1.129 + // Note that C: is used in the IoControl call, which requires a valid drive, but has no other relevance
1.130 + TInt r=controlIo(TheFs, EDriveC, KControlIoGetCorruptListFile, aFileName);
1.131 + test(r==KErrNone);
1.132 + return r;
1.133 + }
1.134 +
1.135 +void AccessFiles()
1.136 + {
1.137 + test.Next(_L("Access corrupt files"));
1.138 + RFile f;
1.139 + const TInt attribs=EFileShareExclusive|EFileStreamText|EFileRead;
1.140 + // File1
1.141 + TInt r=f.Open(TheFs,KTestFile1,attribs);
1.142 + test(r==KTestFile1Error1);
1.143 + f.Close();
1.144 + numberOfTraps+=(r==KErrNone?0:1);
1.145 + // try again
1.146 + r=f.Open(TheFs,KTestFile1,attribs);
1.147 + test(r==KTestFile1Error2);
1.148 + f.Close();
1.149 + numberOfTraps+=(r==KErrNone?0:1);
1.150 + // File2
1.151 + r=f.Open(TheFs,KTestFile2,attribs);
1.152 + test(r==KTestFile2Error1);
1.153 + f.Close();
1.154 + numberOfTraps+=(r==KErrNone?0:1);
1.155 + // try again
1.156 + r=f.Open(TheFs,KTestFile2,attribs);
1.157 + test(r==KTestFile2Error2);
1.158 + f.Close();
1.159 + numberOfTraps+=(r==KErrNone?0:1);
1.160 + }
1.161 +
1.162 +void DoTests()
1.163 + {
1.164 + TFileName corruptFileNamesList;
1.165 + test.Next(_L("Get name of file with list of nominated files"));
1.166 + TInt r=GetCorruptFileListFile(corruptFileNamesList);
1.167 + test(r==KErrNone);
1.168 + test.Printf(_L("Using %S\n"),&corruptFileNamesList);
1.169 +
1.170 + AccessFiles();
1.171 + test.Next(_L("Get Number of traps"));
1.172 + TInt nRecs=GetNumberOfTraps();
1.173 + test.Next(_L("Test Number of traps"));
1.174 + test(nRecs==numberOfTraps);
1.175 +
1.176 + TFsDebugCorruptLogRecordBuf logRec;
1.177 + for (TInt i=1;i<=nRecs;i++)
1.178 + { // fetch record #i
1.179 + TInt r=GetTrapLogRecord(logRec,i);
1.180 + test(r==KErrNone);
1.181 + r=logRec().iProcessName.CompareF(_L("t_corruptlog.exe"));
1.182 + test(r==KErrNone);
1.183 + PrintLogRecord(logRec,i);
1.184 + }
1.185 + }
1.186 +
1.187 +#endif
1.188 +
1.189 +extern TInt E32Main()
1.190 +{
1.191 +
1.192 + CTrapCleanup* cleanup;
1.193 + cleanup=CTrapCleanup::New();
1.194 + __UHEAP_MARK;
1.195 +
1.196 + test.Title();
1.197 + test.Start(_L("Corrupt File trap log"));
1.198 +#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
1.199 + TInt r=TheFs.Connect();
1.200 + test(r==KErrNone);
1.201 +
1.202 + TheFs.ResourceCountMarkStart();
1.203 +
1.204 + DoTests();
1.205 +
1.206 + TheFs.ResourceCountMarkEnd();
1.207 + ResetCorruptLogRecords();
1.208 + TheFs.Close();
1.209 +#endif
1.210 +
1.211 + test.End();
1.212 + test.Close();
1.213 + __UHEAP_MARKEND;
1.214 + delete cleanup;
1.215 +
1.216 +
1.217 +
1.218 + return KErrNone;
1.219 +}