os/kernelhwsrv/kerneltest/f32test/filesystem/fat/t_scn32dr3.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/filesystem/fat/t_scn32dr3.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,158 @@
     1.4 +// Copyright (c) 1998-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\scndrv\t_scn32dr3.cpp
    1.18 +//
    1.19 +//
    1.20 +
    1.21 +#include <f32file.h>
    1.22 +#include <e32test.h>
    1.23 +#include <e32svr.h>
    1.24 +#include "t_server.h"
    1.25 +
    1.26 +#include "fat_utils.h"
    1.27 +using namespace Fat_Test_Utils;
    1.28 +
    1.29 +
    1.30 +/* Tests rugged fat filing system for epoc platforms. Copies \t_scn32dr3.exe to
    1.31 +\sys\bin\eshell.exe to enable the test to carry on after a reset.
    1.32 +See t_tscan for a fuller description of the tests carried out. Good idea to
    1.33 +disable crash debugger via \e32\inc\m32std.h. Drive to be tested is selected at
    1.34 +the command line. Also useful to disable beep in \e32\kpepoc\kp_ini.cpp to
    1.35 +avoid excessive noise.*/
    1.36 +
    1.37 +GLDEF_D RTest test(_L("T_SCN32DR3"));
    1.38 +
    1.39 +GLREF_D TInt TheFunctionNumber;
    1.40 +GLREF_D TInt TheOpNumber;
    1.41 +GLREF_D TInt TheFailCount;
    1.42 +GLREF_D TBool IsReset;
    1.43 +GLREF_D RFs TheFs;
    1.44 +GLREF_D TFileName TestExeName;
    1.45 +GLREF_D TFileName StartupExeName;
    1.46 +GLREF_D TFileName LogFileName;
    1.47 +
    1.48 +#if defined( _DEBUG) && !defined(__WINS__)
    1.49 +const TInt KControlIoRuggedOn=2;
    1.50 +const TInt KControlIoRuggedOff=3;
    1.51 +const TInt KControlIoIsRugged=4;
    1.52 +#endif
    1.53 +GLREF_D TInt WriteFailValue;
    1.54 +GLREF_C void ReadLogFile();
    1.55 +GLREF_C void DoTests();
    1.56 +
    1.57 +#if defined(_DEBUG)
    1.58 +LOCAL_C void OverrideEShell(void)
    1.59 +//
    1.60 +// Copies the executable file as the eshell so that it is automatically run
    1.61 +//
    1.62 +    {
    1.63 +    test.Next(_L("OverideEShell"));
    1.64 +    RProcess myProc;
    1.65 +    if (myProc.FileName().CompareF(StartupExeName) == 0)
    1.66 +        test.Printf(_L("OverrideEShell: running as eshell\n"));
    1.67 +    else
    1.68 +        {
    1.69 +        RFile logFile;
    1.70 +        TInt r;
    1.71 +        TFileName tempDirName=_L("");
    1.72 +        // Copy over this executable and create a progress file.
    1.73 +        test.Printf(_L("Copying %S to %S\n"), &TestExeName, &StartupExeName);
    1.74 +        if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
    1.75 +            tempDirName = _L("?:\\SYS\\BIN\\");
    1.76 +        else
    1.77 +            tempDirName = _L("?:\\SYSTEM\\BIN\\");
    1.78 +        tempDirName[0] = gSessionPath[0];
    1.79 +        r=TheFs.MkDirAll(tempDirName);
    1.80 +        test(r==KErrNone||r==KErrAlreadyExists);
    1.81 +        CFileMan* fileMan=NULL;
    1.82 +        TRAP(r,fileMan = CFileMan::NewL(TheFs));
    1.83 +        test(r==KErrNone);
    1.84 +        //Copy the test from Z drive.
    1.85 +        TFileName temp=_L("Z:\\SYS\\BIN\\T_SCN32DR3.EXE");
    1.86 +        r = fileMan->Copy(temp, TestExeName, CFileMan::EOverWrite);
    1.87 +        test(r==KErrNone);
    1.88 +        r = fileMan->Copy(TestExeName, StartupExeName, CFileMan::EOverWrite);
    1.89 +        test(r == KErrNone);
    1.90 +        //Mask read attribute. Fix for DEF081323
    1.91 +        r = fileMan->Attribs(StartupExeName, 0, KEntryAttReadOnly, 0);
    1.92 +        test(r == KErrNone);
    1.93 +        r = fileMan->Attribs(TestExeName, 0, KEntryAttReadOnly, 0);
    1.94 +        test(r == KErrNone);
    1.95 +        r = logFile.Replace(TheFs,LogFileName,EFileShareExclusive|EFileWrite);
    1.96 +        test(r == KErrNone);
    1.97 +        logFile.Close();
    1.98 +        delete fileMan;
    1.99 +        }
   1.100 +    }
   1.101 +#endif
   1.102 +
   1.103 +GLDEF_C void CallTestsL()
   1.104 +//
   1.105 +//
   1.106 +//
   1.107 +    {
   1.108 +    if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
   1.109 +        StartupExeName=_L("?:\\SYS\\BIN\\ESHELL.EXE");
   1.110 +    else
   1.111 +        StartupExeName=_L("?:\\SYSTEM\\BIN\\ESHELL.EXE");
   1.112 +    //RFs::ControlIo only supported in debug build
   1.113 +#ifndef _DEBUG
   1.114 +    test.Printf(_L("Error: Supported only debug testing\n"));
   1.115 +    return;
   1.116 +#else
   1.117 +#if defined(__WINS__)
   1.118 +    test.Printf(_L("WINS not tested\n"));
   1.119 +    return;
   1.120 +#else
   1.121 +    const TInt KWriteFailReset=-99;         // soft reset after write fail
   1.122 +
   1.123 +    TInt r;
   1.124 +    TestExeName[0]=StartupExeName[0]=LogFileName[0]=gSessionPath[0];
   1.125 +    // ensure file system is rugged
   1.126 +    TUint8 oldFsys;
   1.127 +    TPtr8 pRugged(&oldFsys,1,1);
   1.128 +    r=TheFs.ControlIo(gSessionPath[0]-'A',KControlIoIsRugged,pRugged);
   1.129 +    test(r==KErrNone);
   1.130 +    if(oldFsys==0)
   1.131 +        {
   1.132 +        r=TheFs.ControlIo(gSessionPath[0]-'A',KControlIoRuggedOn);
   1.133 +        test(r==KErrNone);
   1.134 +        }
   1.135 +    TheFunctionNumber=0;
   1.136 +    TheOpNumber=0;
   1.137 +    TheFailCount=0;
   1.138 +    IsReset=ETrue;
   1.139 +    WriteFailValue=KWriteFailReset;
   1.140 +    test.Printf(_L("IsReset=%d\n"),IsReset);
   1.141 +    OverrideEShell();
   1.142 +    ReadLogFile();
   1.143 +    r=TheFs.ScanDrive(gSessionPath);
   1.144 +    test(r==KErrNone);
   1.145 +    r=TheFs.CheckDisk(gSessionPath);
   1.146 +    test(r==KErrNone);
   1.147 +    DoTests();
   1.148 +    r=TheFs.Delete(LogFileName);
   1.149 +    test(r==KErrNone);
   1.150 +    r=TheFs.Delete(StartupExeName);
   1.151 +    test(r==KErrNone);
   1.152 +    // return file system to original state
   1.153 +    if(oldFsys==0)
   1.154 +        r=TheFs.ControlIo(gSessionPath[0]-'A',KControlIoRuggedOff);
   1.155 +    UserSvr::ResetMachine(EStartupWarmReset);
   1.156 +    return;
   1.157 +#endif
   1.158 +#endif
   1.159 +    }
   1.160 +
   1.161 +