os/kernelhwsrv/kerneltest/f32test/bench/t_notify_perf_util.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/bench/t_notify_perf_util.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,293 @@
     1.4 +// Copyright (c) 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\bench\t_notify_perf_util.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include "t_notify_perf.h"
    1.22 +#include "t_server.h"
    1.23 +
    1.24 +void DoKillThreadsL()
    1.25 +    {
    1.26 +    TInt count = 0;
    1.27 +    while (count < gNotiThreads.Count())
    1.28 +        {
    1.29 +        gNotiThreads[count].Kill(KErrGeneral);
    1.30 +        count++;
    1.31 +        }
    1.32 +    gFileThread.Kill(KErrGeneral);
    1.33 +    }
    1.34 +
    1.35 +// Safe way of checking in sub threads, it leaves when check fails, Main thread will catch the error and exit.
    1.36 +// if use test() directly in sub-threads, the threads may hang if check fails
    1.37 +void SafeTestL(TBool aResult, TInt aId, TInt aLine, TText* aFile)
    1.38 +    {
    1.39 +    if (!aResult)
    1.40 +        {
    1.41 +        if (aId >= 0)
    1.42 +            {
    1.43 +            RDebug::Print(_L("NotificationThread%02d: Failed check in %s at line %d"), aId, aFile, aLine);
    1.44 +            }
    1.45 +        else if (aId == KNoThreadId)
    1.46 +            {
    1.47 +            RDebug::Print(_L("Failed check in %s at line %d"), aFile, aLine);
    1.48 +            }
    1.49 +        CTestExecutor::KillAllTestThreads();
    1.50 +        }
    1.51 +    }
    1.52 +
    1.53 +void SafeTestL(TInt aResult, TInt aExpected, TInt aId, TInt aLine, TText* aFile)
    1.54 +    {
    1.55 +    if (aResult != aExpected)
    1.56 +        {
    1.57 +        if (aId >= 0)
    1.58 +            {
    1.59 +            RDebug::Print(_L("NotificationThread%02d: Failed check in %s at line %d, expected %d, got %d"), aId, aFile, aLine, aExpected, aResult);
    1.60 +            }
    1.61 +        else if (aId == KNoThreadId)
    1.62 +            {
    1.63 +            RDebug::Print(_L("Failed check in %s at line %d, expected %d, got %d"), aFile, aLine, aExpected, aResult);
    1.64 +            }
    1.65 +        CTestExecutor::KillAllTestThreads();
    1.66 +        }
    1.67 +    }
    1.68 +
    1.69 +void SetTestPaths()
    1.70 +    {
    1.71 +    gTestPath.FillZ();
    1.72 +    gLogFilePath.FillZ();
    1.73 +    
    1.74 +    gTestPath.Append(gDriveToTest);
    1.75 +    gTestPath.Append(_L(":\\F32-TST\\T_Notify_Perf\\"));
    1.76 +    
    1.77 +#ifndef __WINSCW__
    1.78 +    gLogFilePath.Append(gDriveToTest);
    1.79 +#else
    1.80 +    gLogFilePath.Append((TChar)'C');  //If emulator lets stick it on C: (\epoc32\wisncw\c\)
    1.81 +#endif
    1.82 +    if (gPerfMeasure)
    1.83 +        gLogFilePath.Append(_L(":\\F32-TST\\NPTestLog\\"));
    1.84 +    else
    1.85 +        gLogFilePath.Append(_L(":\\F32-TST\\Temp\\"));
    1.86 +    }
    1.87 +
    1.88 +// Mapping from file operations to notification types
    1.89 +TUint OpNotifyMapping(TUint16& aOption, TInt aOperation)
    1.90 +    {
    1.91 +    if (aOption & EEnhanced)
    1.92 +        {
    1.93 +        switch(aOperation)
    1.94 +            {       
    1.95 +            case EOpCreate:
    1.96 +            case EOpCreateDir:
    1.97 +                return TFsNotification::ECreate;
    1.98 +            case EOpReplace:
    1.99 +            case EOpRename:
   1.100 +            case EOpRenameDir:
   1.101 +                return TFsNotification::ERename;
   1.102 +            case EOpChgAttr:
   1.103 +                return TFsNotification::EAttribute;
   1.104 +            case EOpWrite:
   1.105 +            case EOpResize:
   1.106 +            case EOpManyChanges:
   1.107 +            case EOpManyFiles:
   1.108 +                return TFsNotification::EFileChange;
   1.109 +            case EOpDelete:
   1.110 +            case EOpDeleteDir:
   1.111 +                return TFsNotification::EDelete;
   1.112 +            case EOpMixed:
   1.113 +                return (TUint) (TFsNotification::EAllOps & (~TFsNotification::EOverflow));
   1.114 +            default:
   1.115 +                return (TUint) TFsNotification::EAllOps;
   1.116 +            }
   1.117 +        }
   1.118 +    else if (aOption & EOriginal)
   1.119 +        {
   1.120 +        switch(aOperation)
   1.121 +            {   
   1.122 +            case EOpCreate:
   1.123 +            case EOpReplace:
   1.124 +            case EOpRename:
   1.125 +                return ENotifyFile;
   1.126 +            case EOpChgAttr:
   1.127 +            case EOpResize:
   1.128 +                return ENotifyAttributes;
   1.129 +            case EOpWrite:
   1.130 +            case EOpManyChanges:
   1.131 +            case EOpManyFiles:
   1.132 +                return ENotifyWrite;
   1.133 +            case EOpDelete:
   1.134 +                return ENotifyEntry;
   1.135 +            case EOpCreateDir:
   1.136 +            case EOpRenameDir:
   1.137 +            case EOpDeleteDir:
   1.138 +                return ENotifyDir;
   1.139 +            case EOpMixed:
   1.140 +            default:
   1.141 +                return ENotifyAll;
   1.142 +            }
   1.143 +        }
   1.144 +    else if (aOption & EPlugin)
   1.145 +        {
   1.146 +        switch(aOperation)
   1.147 +            {
   1.148 +            case EOpCreate:
   1.149 +                return EMdsFileCreated;
   1.150 +            case EOpReplace:
   1.151 +                return EMdsFileReplaced;
   1.152 +            case EOpRename:
   1.153 +                return EMdsFileRenamed;
   1.154 +            case EOpDelete:
   1.155 +                return EMdsFileDeleted;
   1.156 +            case EOpRenameDir:
   1.157 +                return EMdsDirRenamed;
   1.158 +            default:
   1.159 +                // All other operations are not testable
   1.160 +                return EMdsFileUnknown;
   1.161 +            }
   1.162 +        }
   1.163 +    return 0;
   1.164 +    }
   1.165 +
   1.166 +// generate file names for testing
   1.167 +void FileNameGen(TFileName& aName, TInt aNum, TBool aIsFile = ETrue)
   1.168 +    {
   1.169 +    aName.FillZ();
   1.170 +    aName.Copy(gTestPath);
   1.171 +    if (aIsFile)
   1.172 +        aName.AppendFormat(_L("%04d.tst"), aNum);
   1.173 +    else
   1.174 +        aName.AppendFormat(_L("DIR%04d\\"), aNum);
   1.175 +    }
   1.176 +
   1.177 +void ClearTestPathL()
   1.178 +    {
   1.179 +    RDebug::Print(_L("Clearing test path..."));
   1.180 +    RFs fs;
   1.181 +    User::LeaveIfError(fs.Connect());
   1.182 +    CFileMan* fm = CFileMan::NewL(fs);
   1.183 +    TInt r = fm->RmDir(gTestPath);
   1.184 +    test(r==KErrNone || r==KErrPathNotFound || r==KErrNotFound);
   1.185 +    r = fs.MkDirAll(gTestPath);
   1.186 +    test(r==KErrNone || r==KErrAlreadyExists);
   1.187 +    
   1.188 +    delete fm;
   1.189 +    fs.Close();
   1.190 +    }
   1.191 +
   1.192 +void DeleteLogFilesL()
   1.193 +    {
   1.194 +    RDebug::Print(_L("Clearing test logs if exist..."));
   1.195 +    RFs fs;
   1.196 +    User::LeaveIfError(fs.Connect());
   1.197 +    CFileMan* fm = CFileMan::NewL(fs);
   1.198 +    
   1.199 +    TFileName logFiles;
   1.200 +    logFiles.Copy(gLogFilePath);
   1.201 +    logFiles.Append('*');
   1.202 +    logFiles.Append(gLogPostFix);
   1.203 +    
   1.204 +    TInt r = fm->Delete(logFiles);
   1.205 +    test(r==KErrNone || r==KErrPathNotFound || r==KErrNotFound);
   1.206 +    if (r != KErrNone)
   1.207 +        {
   1.208 +        r = fs.MkDirAll(gLogFilePath);
   1.209 +        test(r==KErrNone || r==KErrAlreadyExists);
   1.210 +        }
   1.211 +    
   1.212 +    delete fm;
   1.213 +    fs.Close();
   1.214 +    }
   1.215 +
   1.216 +// Copy log files from test drive to MMC
   1.217 +void CopyLogFilesL()
   1.218 +    {
   1.219 +    RFs fs;
   1.220 +    User::LeaveIfError(fs.Connect());
   1.221 +    CFileMan* fm = CFileMan::NewL(fs);
   1.222 +    
   1.223 +    TFileName path;
   1.224 +    path.Append(_L("D:\\NPTLogs\\"));
   1.225 +    TInt r = fs.MkDirAll(path);
   1.226 +    test(r == KErrNone || r == KErrAlreadyExists);
   1.227 +    fm->Copy(gLogFilePath, path);
   1.228 +    
   1.229 +    delete fm;
   1.230 +    fs.Close();
   1.231 +    }
   1.232 +
   1.233 +// compare the name of two entries
   1.234 +TBool CompareEntryName(const TEntry& aEntry1, const TEntry& aEntry2)
   1.235 +    {
   1.236 +    return (aEntry1.iName.Compare(aEntry2.iName) == 0);
   1.237 +    }
   1.238 +
   1.239 +// start file operations
   1.240 +void DoFileOperationL(TThreadParam* aParam)
   1.241 +    {
   1.242 +    CFileOperator fileOperator(aParam->iSetting, *(aParam->iLoggerArray), aParam->iSmphFT, aParam->iSmphNT);
   1.243 +    fileOperator.DoChangesL();
   1.244 +    }
   1.245 +
   1.246 +// start monitoring notification
   1.247 +void DoNotificationOperationL(TThreadParam* aParam)
   1.248 +    {
   1.249 +    CActiveScheduler* sch = new(ELeave) CActiveScheduler(); 
   1.250 +    CleanupStack::PushL(sch);
   1.251 +    CActiveScheduler::Install(sch);
   1.252 +    
   1.253 +    CNotifyOperator notifyOperator(aParam->iSetting, aParam->iSmphFT, aParam->iSmphNT, aParam->iLogger);
   1.254 +    aParam->iSmphFT->Signal();
   1.255 +    notifyOperator.StartOperationL();
   1.256 +    
   1.257 +    CleanupStack::PopAndDestroy();
   1.258 +    }
   1.259 +
   1.260 +// entry function of file operaton thread
   1.261 +TInt FileOperationThread(TAny* aParam)
   1.262 +    {
   1.263 +    CTrapCleanup* cleanup;
   1.264 +    cleanup = CTrapCleanup::New();
   1.265 +    
   1.266 +    TRAPD(r, DoFileOperationL(static_cast<TThreadParam*>(aParam)));
   1.267 +
   1.268 +    delete cleanup;
   1.269 +    
   1.270 +    return r;
   1.271 +    }
   1.272 +
   1.273 +// entry function of notification thread
   1.274 +TInt NotificationOperationThread(TAny* aParam)
   1.275 +    {
   1.276 +    CTrapCleanup* cleanup;
   1.277 +    cleanup = CTrapCleanup::New();
   1.278 +    
   1.279 +    TRAPD(r, DoNotificationOperationL(static_cast<TThreadParam*>(aParam)));
   1.280 +    
   1.281 +    delete cleanup;
   1.282 +    
   1.283 +    return r;
   1.284 +    }
   1.285 +
   1.286 +TInt KillerThread(TAny*)
   1.287 +    {
   1.288 +    CTrapCleanup* cleanup;
   1.289 +    cleanup = CTrapCleanup::New();
   1.290 +    
   1.291 +    TRAPD(r, DoKillThreadsL());
   1.292 +    
   1.293 +    delete cleanup;
   1.294 +    
   1.295 +    return r;
   1.296 +    }