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