os/kernelhwsrv/kerneltest/f32test/shostmassstorage/msman/test/t_msblock.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 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
//
sl@0
    15
sl@0
    16
sl@0
    17
#include <e32def.h>
sl@0
    18
#include <e32cmn.h>
sl@0
    19
#include <e32base.h>
sl@0
    20
#include <f32file.h>
sl@0
    21
#include <e32cons.h>
sl@0
    22
#include <e32debug.h>
sl@0
    23
#define __E32TEST_EXTENSION__
sl@0
    24
#include <e32test.h>
sl@0
    25
#include <e32property.h>
sl@0
    26
sl@0
    27
#include "f32_test_utils.h"
sl@0
    28
sl@0
    29
#include "cblockdevicetester.h"
sl@0
    30
#include "cmsdrive.h"
sl@0
    31
#include "tmsprintdrive.h"
sl@0
    32
#include "ttestutils.h"
sl@0
    33
#include "tmslog.h"
sl@0
    34
sl@0
    35
using namespace F32_Test_Utils;
sl@0
    36
sl@0
    37
extern CMsDrive* msDrive;
sl@0
    38
sl@0
    39
RTest test(_L("T_MSBLOCK"));
sl@0
    40
RFs fsSession;
sl@0
    41
sl@0
    42
sl@0
    43
class TTestMsBlock
sl@0
    44
    {
sl@0
    45
public:
sl@0
    46
    void tFileAccess();
sl@0
    47
    void tBlockAccessL();
sl@0
    48
    void tRawAccessL();
sl@0
    49
    void tLastLbaAccessL();
sl@0
    50
    };
sl@0
    51
sl@0
    52
sl@0
    53
void TTestMsBlock::tFileAccess()
sl@0
    54
    {
sl@0
    55
    test.Start(_L("tFileAccess\n"));
sl@0
    56
sl@0
    57
    test.Next(_L("DriveInfo"));
sl@0
    58
    PrintDrvInfo(fsSession, msDrive->DriveNumber());
sl@0
    59
sl@0
    60
    TVolumeInfo volInfo;
sl@0
    61
    TInt err = fsSession.Volume(volInfo);
sl@0
    62
    test(err == KErrNone);
sl@0
    63
sl@0
    64
    test.Printf(_L("Memory 'in use' = %lx\n"), (volInfo.iSize - volInfo.iFree));
sl@0
    65
    test.Printf(_L("volInfo.iSize = %lx\n"), volInfo.iSize);
sl@0
    66
    test.Printf(_L("volInfo.iFree = %lx\n"), volInfo.iFree);
sl@0
    67
sl@0
    68
    //-- 1. create a file
sl@0
    69
    _LIT(KFile, "\\test_file.file");
sl@0
    70
    const TUint KFileSz = 54321;
sl@0
    71
sl@0
    72
    test.Next(_L("Write file\n"));
sl@0
    73
    err = CreateCheckableStuffedFile(fsSession, KFile, KFileSz);
sl@0
    74
    test_KErrNone(err);
sl@0
    75
sl@0
    76
    //-- 2. verify the file, just in case.
sl@0
    77
    test.Next(_L("Verify file\n"));
sl@0
    78
    err = VerifyCheckableFile(fsSession, KFile);
sl@0
    79
    test_KErrNone(err);
sl@0
    80
sl@0
    81
    //-- 3. delete the file
sl@0
    82
    test.Next(_L("Delete file\n"));
sl@0
    83
    fsSession.Delete(KFile);
sl@0
    84
    test.End();
sl@0
    85
    }
sl@0
    86
sl@0
    87
void TTestMsBlock::tBlockAccessL()
sl@0
    88
    {
sl@0
    89
    test.Start(_L("tBlockAccess\n"));
sl@0
    90
sl@0
    91
    test.Next(_L("Create Test drive\n"));
sl@0
    92
    TInt driveNumber = msDrive->DriveNumber();
sl@0
    93
    CBlockDeviceTester* blockDeviceTester = CBlockDeviceTester::NewL(driveNumber);
sl@0
    94
sl@0
    95
    test.Next(_L("Verify Test area on drive\n"));
sl@0
    96
    TInt res = blockDeviceTester->VerifyDrive();
sl@0
    97
    test_KErrNone(res);
sl@0
    98
sl@0
    99
    test.Next(_L("Test Single Block access\n"));
sl@0
   100
    TLba lba = 1;
sl@0
   101
    TLba blocks = 1;
sl@0
   102
sl@0
   103
    test.Printf(_L("write block LBA=0x%x Blocks=0x%x\n"),lba, blocks);
sl@0
   104
    res = blockDeviceTester->UpdateBlock(lba, blocks);
sl@0
   105
    test_KErrNone(res);
sl@0
   106
sl@0
   107
    test.Printf(_L("read block LBA=0x%x Blocks=0x%x\n"),lba, blocks);
sl@0
   108
    res = blockDeviceTester->VerifyBlock(lba, blocks);
sl@0
   109
    test_KErrNone(res);
sl@0
   110
sl@0
   111
    test.Printf(_L("Verify drive\n"));
sl@0
   112
    res = blockDeviceTester->VerifyDrive();
sl@0
   113
    test_KErrNone(res);
sl@0
   114
sl@0
   115
    test.Next(_L("Test Multiple Block access\n"));
sl@0
   116
    lba = 6;
sl@0
   117
    blocks = 7;
sl@0
   118
    res = blockDeviceTester->UpdateBlock(lba, blocks);
sl@0
   119
    test_KErrNone(res);
sl@0
   120
    res = blockDeviceTester->VerifyBlock(lba, blocks);
sl@0
   121
    test_KErrNone(res);
sl@0
   122
    res = blockDeviceTester->VerifyDrive();
sl@0
   123
    test_KErrNone(res);
sl@0
   124
sl@0
   125
    delete blockDeviceTester;
sl@0
   126
    test.End();
sl@0
   127
    }
sl@0
   128
sl@0
   129
void TTestMsBlock::tRawAccessL()
sl@0
   130
    {
sl@0
   131
    test.Start(_L("tRawAccess\n"));
sl@0
   132
sl@0
   133
    // Head
sl@0
   134
    const TPos KPos_H = (KBlockSize * 5) + 0x7;
sl@0
   135
    const TUint KLen_H = 0x123;
sl@0
   136
sl@0
   137
    // Head + Tail
sl@0
   138
    const TPos KPos_HT = (KBlockSize * 7) + 0x180;
sl@0
   139
    const TUint KLen_HT = 0x100;
sl@0
   140
sl@0
   141
    // Head + Body + Tail
sl@0
   142
    const TPos KPos_HBT = (KBlockSize * 9) + 0x190;
sl@0
   143
    const TUint KLen_HBT = (KBlockSize * 4) + 0x110;
sl@0
   144
sl@0
   145
sl@0
   146
    test.Next(_L("Create Test drive\n"));
sl@0
   147
    TInt driveNumber = msDrive->DriveNumber();
sl@0
   148
    CBlockDeviceTester* blockDeviceTester = CBlockDeviceTester::NewL(driveNumber);
sl@0
   149
sl@0
   150
    test.Next(_L("Verify Test area on drive\n"));
sl@0
   151
    TInt res = blockDeviceTester->VerifyDrive();
sl@0
   152
    test_KErrNone(res);
sl@0
   153
sl@0
   154
sl@0
   155
    TPos pos = KPos_H;
sl@0
   156
    TUint len = KLen_H;
sl@0
   157
    test.Next(_L("Test head access\n"));
sl@0
   158
    test.Printf(_L("Pos=0x%lx Len=0x%x\n"), pos, len);
sl@0
   159
    res = blockDeviceTester->Update(pos, len);
sl@0
   160
    test_KErrNone(res);
sl@0
   161
    res = blockDeviceTester->Verify(pos, len);
sl@0
   162
    test_KErrNone(res);
sl@0
   163
    res = blockDeviceTester->VerifyDrive();
sl@0
   164
    test_KErrNone(res);
sl@0
   165
sl@0
   166
    pos = KPos_HT;
sl@0
   167
    len = KLen_HT;
sl@0
   168
    test.Next(_L("Test head + tail access\n"));
sl@0
   169
    test.Printf(_L("Pos=0x%lx Len=0x%x\n"), pos, len);
sl@0
   170
    res = blockDeviceTester->Update(pos, len);
sl@0
   171
    test_KErrNone(res);
sl@0
   172
    res = blockDeviceTester->Verify(pos, len);
sl@0
   173
    test_KErrNone(res);
sl@0
   174
    res = blockDeviceTester->VerifyDrive();
sl@0
   175
    test_KErrNone(res);
sl@0
   176
sl@0
   177
    pos = KPos_HBT;
sl@0
   178
    len = KLen_HBT;
sl@0
   179
    test.Next(_L("Test head + body+ tail access\n"));
sl@0
   180
    test.Printf(_L("Pos=0x%lx Len=0x%x\n"), pos, len);
sl@0
   181
    res = blockDeviceTester->Update(pos, len);
sl@0
   182
    test_KErrNone(res);
sl@0
   183
    res = blockDeviceTester->Verify(pos, len);
sl@0
   184
    test_KErrNone(res);
sl@0
   185
    res = blockDeviceTester->VerifyDrive();
sl@0
   186
    test_KErrNone(res);
sl@0
   187
sl@0
   188
    delete blockDeviceTester;
sl@0
   189
    test.End();
sl@0
   190
    }
sl@0
   191
sl@0
   192
sl@0
   193
void TTestMsBlock::tLastLbaAccessL()
sl@0
   194
    {
sl@0
   195
    test.Start(_L("tLastLbaAccess\n"));
sl@0
   196
    test.Next(_L("tLastLbaAccess\n"));
sl@0
   197
sl@0
   198
    TInt driveNumber = msDrive->DriveNumber();
sl@0
   199
sl@0
   200
    TVolumeInfo volInfo;
sl@0
   201
    TInt err = fsSession.Volume(volInfo);
sl@0
   202
    test(err == KErrNone);
sl@0
   203
sl@0
   204
    test.Printf(_L("Memory 'in use' = 0x%lx (0x%x)\n"),
sl@0
   205
                (volInfo.iSize - volInfo.iFree), (volInfo.iSize - volInfo.iFree)/KBlockSize);
sl@0
   206
    test.Printf(_L("volInfo.iSize   = 0x%lx (0x%x)\n"),
sl@0
   207
                volInfo.iSize, volInfo.iSize/KBlockSize);
sl@0
   208
    test.Printf(_L("volInfo.iFree   = 0x%lx (0x%x)\n"),
sl@0
   209
                volInfo.iFree, volInfo.iFree/KBlockSize);
sl@0
   210
sl@0
   211
    TLba lba = volInfo.iSize/KBlockSize;
sl@0
   212
    RBlockTargetMedia media(driveNumber);
sl@0
   213
    media.OpenL();
sl@0
   214
sl@0
   215
    TInt writeRes = KErrNone;
sl@0
   216
    TInt readRes = KErrNone;
sl@0
   217
    test.Printf(_L("LBA=%x\n"), lba);
sl@0
   218
    for (;writeRes == KErrNone && readRes == KErrNone; lba++)
sl@0
   219
        {
sl@0
   220
        writeRes = media.WriteBlock(lba);
sl@0
   221
        readRes = media.ReadBlock(lba);
sl@0
   222
        }
sl@0
   223
sl@0
   224
    test.Printf(_L("LBA=%x ERR Write=%d Read=%d\n"), lba, writeRes, readRes);
sl@0
   225
sl@0
   226
    media.Close();
sl@0
   227
    test.End();
sl@0
   228
    }
sl@0
   229
sl@0
   230
void CallTestsL()
sl@0
   231
    {
sl@0
   232
    TTestMsBlock t;
sl@0
   233
    t.tFileAccess();
sl@0
   234
    t.tBlockAccessL();
sl@0
   235
    t.tRawAccessL();
sl@0
   236
    t.tLastLbaAccessL();
sl@0
   237
    }