kerneltest/f32test/filesystem/fat/t_scn32dr3.cpp
changeset 0 a41df078684a
child 33 0173bcd7697c
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\scndrv\t_scn32dr3.cpp
       
    15 //
       
    16 //
       
    17 
       
    18 #include <f32file.h>
       
    19 #include <e32test.h>
       
    20 #include "t_server.h"
       
    21 
       
    22 #include "fat_utils.h"
       
    23 using namespace Fat_Test_Utils;
       
    24 
       
    25 
       
    26 /* Tests rugged fat filing system for epoc platforms. Copies \t_scn32dr3.exe to
       
    27 \sys\bin\eshell.exe to enable the test to carry on after a reset.
       
    28 See t_tscan for a fuller description of the tests carried out. Good idea to
       
    29 disable crash debugger via \e32\inc\m32std.h. Drive to be tested is selected at
       
    30 the command line. Also useful to disable beep in \e32\kpepoc\kp_ini.cpp to
       
    31 avoid excessive noise.*/
       
    32 
       
    33 GLDEF_D RTest test(_L("T_SCN32DR3"));
       
    34 
       
    35 GLREF_D TInt TheFunctionNumber;
       
    36 GLREF_D TInt TheOpNumber;
       
    37 GLREF_D TInt TheFailCount;
       
    38 GLREF_D TBool IsReset;
       
    39 GLREF_D RFs TheFs;
       
    40 GLREF_D TFileName TestExeName;
       
    41 GLREF_D TFileName StartupExeName;
       
    42 GLREF_D TFileName LogFileName;
       
    43 
       
    44 #if defined( _DEBUG) && !defined(__WINS__)
       
    45 const TInt KControlIoRuggedOn=2;
       
    46 const TInt KControlIoRuggedOff=3;
       
    47 const TInt KControlIoIsRugged=4;
       
    48 #endif
       
    49 GLREF_D TInt WriteFailValue;
       
    50 GLREF_C void ReadLogFile();
       
    51 GLREF_C void DoTests();
       
    52 
       
    53 #if defined(_DEBUG)
       
    54 LOCAL_C void OverrideEShell(void)
       
    55 //
       
    56 // Copies the executable file as the eshell so that it is automatically run
       
    57 //
       
    58     {
       
    59     test.Next(_L("OverideEShell"));
       
    60     RProcess myProc;
       
    61     if (myProc.FileName().CompareF(StartupExeName) == 0)
       
    62         test.Printf(_L("OverrideEShell: running as eshell\n"));
       
    63     else
       
    64         {
       
    65         RFile logFile;
       
    66         TInt r;
       
    67         TFileName tempDirName=_L("");
       
    68         // Copy over this executable and create a progress file.
       
    69         test.Printf(_L("Copying %S to %S\n"), &TestExeName, &StartupExeName);
       
    70         if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
       
    71             tempDirName = _L("?:\\SYS\\BIN\\");
       
    72         else
       
    73             tempDirName = _L("?:\\SYSTEM\\BIN\\");
       
    74         tempDirName[0] = gSessionPath[0];
       
    75         r=TheFs.MkDirAll(tempDirName);
       
    76         test(r==KErrNone||r==KErrAlreadyExists);
       
    77         CFileMan* fileMan=NULL;
       
    78         TRAP(r,fileMan = CFileMan::NewL(TheFs));
       
    79         test(r==KErrNone);
       
    80         //Copy the test from Z drive.
       
    81         TFileName temp=_L("Z:\\SYS\\BIN\\T_SCN32DR3.EXE");
       
    82         r = fileMan->Copy(temp, TestExeName, CFileMan::EOverWrite);
       
    83         test(r==KErrNone);
       
    84         r = fileMan->Copy(TestExeName, StartupExeName, CFileMan::EOverWrite);
       
    85         test(r == KErrNone);
       
    86         //Mask read attribute. Fix for DEF081323
       
    87         r = fileMan->Attribs(StartupExeName, 0, KEntryAttReadOnly, 0);
       
    88         test(r == KErrNone);
       
    89         r = fileMan->Attribs(TestExeName, 0, KEntryAttReadOnly, 0);
       
    90         test(r == KErrNone);
       
    91         r = logFile.Replace(TheFs,LogFileName,EFileShareExclusive|EFileWrite);
       
    92         test(r == KErrNone);
       
    93         logFile.Close();
       
    94         delete fileMan;
       
    95         }
       
    96     }
       
    97 #endif
       
    98 
       
    99 GLDEF_C void CallTestsL()
       
   100 //
       
   101 //
       
   102 //
       
   103     {
       
   104     if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
       
   105         StartupExeName=_L("?:\\SYS\\BIN\\ESHELL.EXE");
       
   106     else
       
   107         StartupExeName=_L("?:\\SYSTEM\\BIN\\ESHELL.EXE");
       
   108     //RFs::ControlIo only supported in debug build
       
   109 #ifndef _DEBUG
       
   110     test.Printf(_L("Error: Supported only debug testing\n"));
       
   111     return;
       
   112 #else
       
   113 #if defined(__WINS__)
       
   114     test.Printf(_L("WINS not tested\n"));
       
   115     return;
       
   116 #else
       
   117     const TInt KWriteFailReset=-99;         // soft reset after write fail
       
   118 
       
   119     TInt r;
       
   120     TestExeName[0]=StartupExeName[0]=LogFileName[0]=gSessionPath[0];
       
   121     // ensure file system is rugged
       
   122     TUint8 oldFsys;
       
   123     TPtr8 pRugged(&oldFsys,1,1);
       
   124     r=TheFs.ControlIo(gSessionPath[0]-'A',KControlIoIsRugged,pRugged);
       
   125     test(r==KErrNone);
       
   126     if(oldFsys==0)
       
   127         {
       
   128         r=TheFs.ControlIo(gSessionPath[0]-'A',KControlIoRuggedOn);
       
   129         test(r==KErrNone);
       
   130         }
       
   131     TheFunctionNumber=0;
       
   132     TheOpNumber=0;
       
   133     TheFailCount=0;
       
   134     IsReset=ETrue;
       
   135     WriteFailValue=KWriteFailReset;
       
   136     test.Printf(_L("IsReset=%d\n"),IsReset);
       
   137     OverrideEShell();
       
   138     ReadLogFile();
       
   139     r=TheFs.ScanDrive(gSessionPath);
       
   140     test(r==KErrNone);
       
   141     r=TheFs.CheckDisk(gSessionPath);
       
   142     test(r==KErrNone);
       
   143     DoTests();
       
   144     r=TheFs.Delete(LogFileName);
       
   145     test(r==KErrNone);
       
   146     r=TheFs.Delete(StartupExeName);
       
   147     test(r==KErrNone);
       
   148     // return file system to original state
       
   149     if(oldFsys==0)
       
   150         r=TheFs.ControlIo(gSessionPath[0]-'A',KControlIoRuggedOff);
       
   151     UserSvr::ResetMachine(EStartupWarmReset);
       
   152     return;
       
   153 #endif
       
   154 #endif
       
   155     }
       
   156 
       
   157