os/kernelhwsrv/kerneltest/f32test/bench/t_notify_perf_util.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
// f32test\bench\t_notify_perf_util.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "t_notify_perf.h"
sl@0
    19
#include "t_server.h"
sl@0
    20
sl@0
    21
void DoKillThreadsL()
sl@0
    22
    {
sl@0
    23
    TInt count = 0;
sl@0
    24
    while (count < gNotiThreads.Count())
sl@0
    25
        {
sl@0
    26
        gNotiThreads[count].Kill(KErrGeneral);
sl@0
    27
        count++;
sl@0
    28
        }
sl@0
    29
    gFileThread.Kill(KErrGeneral);
sl@0
    30
    }
sl@0
    31
sl@0
    32
// Safe way of checking in sub threads, it leaves when check fails, Main thread will catch the error and exit.
sl@0
    33
// if use test() directly in sub-threads, the threads may hang if check fails
sl@0
    34
void SafeTestL(TBool aResult, TInt aId, TInt aLine, TText* aFile)
sl@0
    35
    {
sl@0
    36
    if (!aResult)
sl@0
    37
        {
sl@0
    38
        if (aId >= 0)
sl@0
    39
            {
sl@0
    40
            RDebug::Print(_L("NotificationThread%02d: Failed check in %s at line %d"), aId, aFile, aLine);
sl@0
    41
            }
sl@0
    42
        else if (aId == KNoThreadId)
sl@0
    43
            {
sl@0
    44
            RDebug::Print(_L("Failed check in %s at line %d"), aFile, aLine);
sl@0
    45
            }
sl@0
    46
        CTestExecutor::KillAllTestThreads();
sl@0
    47
        }
sl@0
    48
    }
sl@0
    49
sl@0
    50
void SafeTestL(TInt aResult, TInt aExpected, TInt aId, TInt aLine, TText* aFile)
sl@0
    51
    {
sl@0
    52
    if (aResult != aExpected)
sl@0
    53
        {
sl@0
    54
        if (aId >= 0)
sl@0
    55
            {
sl@0
    56
            RDebug::Print(_L("NotificationThread%02d: Failed check in %s at line %d, expected %d, got %d"), aId, aFile, aLine, aExpected, aResult);
sl@0
    57
            }
sl@0
    58
        else if (aId == KNoThreadId)
sl@0
    59
            {
sl@0
    60
            RDebug::Print(_L("Failed check in %s at line %d, expected %d, got %d"), aFile, aLine, aExpected, aResult);
sl@0
    61
            }
sl@0
    62
        CTestExecutor::KillAllTestThreads();
sl@0
    63
        }
sl@0
    64
    }
sl@0
    65
sl@0
    66
void SetTestPaths()
sl@0
    67
    {
sl@0
    68
    gTestPath.FillZ();
sl@0
    69
    gLogFilePath.FillZ();
sl@0
    70
    
sl@0
    71
    gTestPath.Append(gDriveToTest);
sl@0
    72
    gTestPath.Append(_L(":\\F32-TST\\T_Notify_Perf\\"));
sl@0
    73
    
sl@0
    74
#ifndef __WINSCW__
sl@0
    75
    gLogFilePath.Append(gDriveToTest);
sl@0
    76
#else
sl@0
    77
    gLogFilePath.Append((TChar)'C');  //If emulator lets stick it on C: (\epoc32\wisncw\c\)
sl@0
    78
#endif
sl@0
    79
    if (gPerfMeasure)
sl@0
    80
        gLogFilePath.Append(_L(":\\F32-TST\\NPTestLog\\"));
sl@0
    81
    else
sl@0
    82
        gLogFilePath.Append(_L(":\\F32-TST\\Temp\\"));
sl@0
    83
    }
sl@0
    84
sl@0
    85
// Mapping from file operations to notification types
sl@0
    86
TUint OpNotifyMapping(TUint16& aOption, TInt aOperation)
sl@0
    87
    {
sl@0
    88
    if (aOption & EEnhanced)
sl@0
    89
        {
sl@0
    90
        switch(aOperation)
sl@0
    91
            {       
sl@0
    92
            case EOpCreate:
sl@0
    93
            case EOpCreateDir:
sl@0
    94
                return TFsNotification::ECreate;
sl@0
    95
            case EOpReplace:
sl@0
    96
            case EOpRename:
sl@0
    97
            case EOpRenameDir:
sl@0
    98
                return TFsNotification::ERename;
sl@0
    99
            case EOpChgAttr:
sl@0
   100
                return TFsNotification::EAttribute;
sl@0
   101
            case EOpWrite:
sl@0
   102
            case EOpResize:
sl@0
   103
            case EOpManyChanges:
sl@0
   104
            case EOpManyFiles:
sl@0
   105
                return TFsNotification::EFileChange;
sl@0
   106
            case EOpDelete:
sl@0
   107
            case EOpDeleteDir:
sl@0
   108
                return TFsNotification::EDelete;
sl@0
   109
            case EOpMixed:
sl@0
   110
                return (TUint) (TFsNotification::EAllOps & (~TFsNotification::EOverflow));
sl@0
   111
            default:
sl@0
   112
                return (TUint) TFsNotification::EAllOps;
sl@0
   113
            }
sl@0
   114
        }
sl@0
   115
    else if (aOption & EOriginal)
sl@0
   116
        {
sl@0
   117
        switch(aOperation)
sl@0
   118
            {   
sl@0
   119
            case EOpCreate:
sl@0
   120
            case EOpReplace:
sl@0
   121
            case EOpRename:
sl@0
   122
                return ENotifyFile;
sl@0
   123
            case EOpChgAttr:
sl@0
   124
            case EOpResize:
sl@0
   125
                return ENotifyAttributes;
sl@0
   126
            case EOpWrite:
sl@0
   127
            case EOpManyChanges:
sl@0
   128
            case EOpManyFiles:
sl@0
   129
                return ENotifyWrite;
sl@0
   130
            case EOpDelete:
sl@0
   131
                return ENotifyEntry;
sl@0
   132
            case EOpCreateDir:
sl@0
   133
            case EOpRenameDir:
sl@0
   134
            case EOpDeleteDir:
sl@0
   135
                return ENotifyDir;
sl@0
   136
            case EOpMixed:
sl@0
   137
            default:
sl@0
   138
                return ENotifyAll;
sl@0
   139
            }
sl@0
   140
        }
sl@0
   141
    else if (aOption & EPlugin)
sl@0
   142
        {
sl@0
   143
        switch(aOperation)
sl@0
   144
            {
sl@0
   145
            case EOpCreate:
sl@0
   146
                return EMdsFileCreated;
sl@0
   147
            case EOpReplace:
sl@0
   148
                return EMdsFileReplaced;
sl@0
   149
            case EOpRename:
sl@0
   150
                return EMdsFileRenamed;
sl@0
   151
            case EOpDelete:
sl@0
   152
                return EMdsFileDeleted;
sl@0
   153
            case EOpRenameDir:
sl@0
   154
                return EMdsDirRenamed;
sl@0
   155
            default:
sl@0
   156
                // All other operations are not testable
sl@0
   157
                return EMdsFileUnknown;
sl@0
   158
            }
sl@0
   159
        }
sl@0
   160
    return 0;
sl@0
   161
    }
sl@0
   162
sl@0
   163
// generate file names for testing
sl@0
   164
void FileNameGen(TFileName& aName, TInt aNum, TBool aIsFile = ETrue)
sl@0
   165
    {
sl@0
   166
    aName.FillZ();
sl@0
   167
    aName.Copy(gTestPath);
sl@0
   168
    if (aIsFile)
sl@0
   169
        aName.AppendFormat(_L("%04d.tst"), aNum);
sl@0
   170
    else
sl@0
   171
        aName.AppendFormat(_L("DIR%04d\\"), aNum);
sl@0
   172
    }
sl@0
   173
sl@0
   174
void ClearTestPathL()
sl@0
   175
    {
sl@0
   176
    RDebug::Print(_L("Clearing test path..."));
sl@0
   177
    RFs fs;
sl@0
   178
    User::LeaveIfError(fs.Connect());
sl@0
   179
    CFileMan* fm = CFileMan::NewL(fs);
sl@0
   180
    TInt r = fm->RmDir(gTestPath);
sl@0
   181
    test(r==KErrNone || r==KErrPathNotFound || r==KErrNotFound);
sl@0
   182
    r = fs.MkDirAll(gTestPath);
sl@0
   183
    test(r==KErrNone || r==KErrAlreadyExists);
sl@0
   184
    
sl@0
   185
    delete fm;
sl@0
   186
    fs.Close();
sl@0
   187
    }
sl@0
   188
sl@0
   189
void DeleteLogFilesL()
sl@0
   190
    {
sl@0
   191
    RDebug::Print(_L("Clearing test logs if exist..."));
sl@0
   192
    RFs fs;
sl@0
   193
    User::LeaveIfError(fs.Connect());
sl@0
   194
    CFileMan* fm = CFileMan::NewL(fs);
sl@0
   195
    
sl@0
   196
    TFileName logFiles;
sl@0
   197
    logFiles.Copy(gLogFilePath);
sl@0
   198
    logFiles.Append('*');
sl@0
   199
    logFiles.Append(gLogPostFix);
sl@0
   200
    
sl@0
   201
    TInt r = fm->Delete(logFiles);
sl@0
   202
    test(r==KErrNone || r==KErrPathNotFound || r==KErrNotFound);
sl@0
   203
    if (r != KErrNone)
sl@0
   204
        {
sl@0
   205
        r = fs.MkDirAll(gLogFilePath);
sl@0
   206
        test(r==KErrNone || r==KErrAlreadyExists);
sl@0
   207
        }
sl@0
   208
    
sl@0
   209
    delete fm;
sl@0
   210
    fs.Close();
sl@0
   211
    }
sl@0
   212
sl@0
   213
// Copy log files from test drive to MMC
sl@0
   214
void CopyLogFilesL()
sl@0
   215
    {
sl@0
   216
    RFs fs;
sl@0
   217
    User::LeaveIfError(fs.Connect());
sl@0
   218
    CFileMan* fm = CFileMan::NewL(fs);
sl@0
   219
    
sl@0
   220
    TFileName path;
sl@0
   221
    path.Append(_L("D:\\NPTLogs\\"));
sl@0
   222
    TInt r = fs.MkDirAll(path);
sl@0
   223
    test(r == KErrNone || r == KErrAlreadyExists);
sl@0
   224
    fm->Copy(gLogFilePath, path);
sl@0
   225
    
sl@0
   226
    delete fm;
sl@0
   227
    fs.Close();
sl@0
   228
    }
sl@0
   229
sl@0
   230
// compare the name of two entries
sl@0
   231
TBool CompareEntryName(const TEntry& aEntry1, const TEntry& aEntry2)
sl@0
   232
    {
sl@0
   233
    return (aEntry1.iName.Compare(aEntry2.iName) == 0);
sl@0
   234
    }
sl@0
   235
sl@0
   236
// start file operations
sl@0
   237
void DoFileOperationL(TThreadParam* aParam)
sl@0
   238
    {
sl@0
   239
    CFileOperator fileOperator(aParam->iSetting, *(aParam->iLoggerArray), aParam->iSmphFT, aParam->iSmphNT);
sl@0
   240
    fileOperator.DoChangesL();
sl@0
   241
    }
sl@0
   242
sl@0
   243
// start monitoring notification
sl@0
   244
void DoNotificationOperationL(TThreadParam* aParam)
sl@0
   245
    {
sl@0
   246
    CActiveScheduler* sch = new(ELeave) CActiveScheduler(); 
sl@0
   247
    CleanupStack::PushL(sch);
sl@0
   248
    CActiveScheduler::Install(sch);
sl@0
   249
    
sl@0
   250
    CNotifyOperator notifyOperator(aParam->iSetting, aParam->iSmphFT, aParam->iSmphNT, aParam->iLogger);
sl@0
   251
    aParam->iSmphFT->Signal();
sl@0
   252
    notifyOperator.StartOperationL();
sl@0
   253
    
sl@0
   254
    CleanupStack::PopAndDestroy();
sl@0
   255
    }
sl@0
   256
sl@0
   257
// entry function of file operaton thread
sl@0
   258
TInt FileOperationThread(TAny* aParam)
sl@0
   259
    {
sl@0
   260
    CTrapCleanup* cleanup;
sl@0
   261
    cleanup = CTrapCleanup::New();
sl@0
   262
    
sl@0
   263
    TRAPD(r, DoFileOperationL(static_cast<TThreadParam*>(aParam)));
sl@0
   264
sl@0
   265
    delete cleanup;
sl@0
   266
    
sl@0
   267
    return r;
sl@0
   268
    }
sl@0
   269
sl@0
   270
// entry function of notification thread
sl@0
   271
TInt NotificationOperationThread(TAny* aParam)
sl@0
   272
    {
sl@0
   273
    CTrapCleanup* cleanup;
sl@0
   274
    cleanup = CTrapCleanup::New();
sl@0
   275
    
sl@0
   276
    TRAPD(r, DoNotificationOperationL(static_cast<TThreadParam*>(aParam)));
sl@0
   277
    
sl@0
   278
    delete cleanup;
sl@0
   279
    
sl@0
   280
    return r;
sl@0
   281
    }
sl@0
   282
sl@0
   283
TInt KillerThread(TAny*)
sl@0
   284
    {
sl@0
   285
    CTrapCleanup* cleanup;
sl@0
   286
    cleanup = CTrapCleanup::New();
sl@0
   287
    
sl@0
   288
    TRAPD(r, DoKillThreadsL());
sl@0
   289
    
sl@0
   290
    delete cleanup;
sl@0
   291
    
sl@0
   292
    return r;
sl@0
   293
    }