genericopenlibs/posixrealtimeextensions/test/testtimer/src/ttimerthread.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:test cases for concurrency test for timer_settime ,timer_gettime 
       
    15 * Name        : ttimerthread.cpp
       
    16 * 
       
    17 *
       
    18 */
       
    19 
       
    20 #include "ttimerthread.h"
       
    21 #include <stdapis/errno.h>
       
    22 
       
    23 CTimerTestThread* CTimerTestThread::NewL(TTimerTestThreadParams& aParams)
       
    24     {
       
    25     CTimerTestThread* self = new (ELeave) CTimerTestThread(aParams); 
       
    26      return self;
       
    27     }
       
    28 CTimerTestThread::CTimerTestThread(TTimerTestThreadParams& aParams)
       
    29     :iParentStep(aParams.iTestStep),iParams(aParams)
       
    30     {
       
    31     }
       
    32 
       
    33 CTimerTestThread::~CTimerTestThread()
       
    34     {
       
    35     }
       
    36 
       
    37 TInt CTimerTestThread::OEEntry(TAny* aData)
       
    38     {
       
    39     TTimerTestThreadParams* params = static_cast<TTimerTestThreadParams*>(aData);
       
    40     CTrapCleanup* cleanup = CTrapCleanup::New();
       
    41     if (!cleanup)
       
    42         {
       
    43         return KErrNoMemory;
       
    44         }
       
    45 
       
    46     TRAPD(err, OEMainL(*params));
       
    47     delete cleanup;
       
    48     return err;
       
    49     }
       
    50 void CTimerTestThread::OEMainL(TTimerTestThreadParams& aParams)
       
    51     {
       
    52 
       
    53     CTimerTestThread* timerThread = CTimerTestThread::NewL(aParams);
       
    54     timerThread->doOperation();
       
    55     delete timerThread;
       
    56     }
       
    57 void CTimerTestThread::doOperation()
       
    58     {   
       
    59     timer_t timerid;
       
    60     struct itimerspec timeSpec1;
       
    61     struct itimerspec timeSpec2;
       
    62 
       
    63     iParams.iTestResult=EFalse;
       
    64 
       
    65     int ret = timer_create(CLOCK_REALTIME, NULL, &timerid);
       
    66     if(ret != -1)
       
    67     {
       
    68         iParams.iTestStep.INFO_PRINTF1(_L("Timer Created"));
       
    69     
       
    70         timeSpec1.it_value.tv_sec = 10;
       
    71         /* 500 million nsecs = .5 secs */
       
    72         timeSpec1.it_value.tv_nsec = 500000000;
       
    73 
       
    74         timeSpec1.it_interval.tv_sec = 10;
       
    75         /* 500 million nsecs = .5 secs */
       
    76         timeSpec1.it_interval.tv_nsec = 500000000;
       
    77 
       
    78         ret = timer_settime(timerid, 0, &timeSpec1, NULL);
       
    79         if (ret == -1)
       
    80         {
       
    81 
       
    82             iParams.iTestStep.ERR_PRINTF2(_L("Timer Set Time Failed - %d"), errno);
       
    83             return;
       
    84         }
       
    85         iParams.iTestStep.INFO_PRINTF1(_L("Set Timer Success"));
       
    86 
       
    87         //    get_timer()
       
    88         ret = timer_gettime(timerid, &timeSpec2);
       
    89 
       
    90         if(ret == -1)
       
    91         {
       
    92             iParams.iTestStep.ERR_PRINTF2(_L("Timer Get Time Failed - %d"), errno);
       
    93             return;
       
    94 
       
    95         }
       
    96         iParams.iTestStep.INFO_PRINTF1(_L("Get Timer Success"));
       
    97         
       
    98         compareTimeSpec(timeSpec1, timeSpec2);
       
    99 
       
   100         ret = timer_delete(timerid);
       
   101 
       
   102         if(ret == -1)
       
   103         {
       
   104             iParams.iTestStep.ERR_PRINTF2(_L("Timer Get Time Failed - %d"), errno);
       
   105             return;
       
   106 
       
   107         }
       
   108       iParams.iTestStep.INFO_PRINTF1(_L("Timer Deleted"));
       
   109 
       
   110 
       
   111     }
       
   112     else
       
   113     {
       
   114         iParams.iTestStep.ERR_PRINTF2(_L("Timer Create Failed - %d"), errno);
       
   115         return;
       
   116 
       
   117     }
       
   118    iParams.iTestResult=ETrue;
       
   119     return;
       
   120 
       
   121     }
       
   122 
       
   123 TBool CTimerTestThread::compareTimeSpec(struct itimerspec timeSpec1, struct itimerspec timeSpec2)
       
   124     {
       
   125 
       
   126     if((timeSpec1.it_value.tv_sec == timeSpec2.it_value.tv_sec )
       
   127         && (timeSpec1.it_value.tv_nsec  == timeSpec2.it_value.tv_nsec )
       
   128         && (timeSpec1.it_interval.tv_sec == timeSpec2.it_interval.tv_sec )
       
   129         && (timeSpec1.it_interval.tv_nsec == timeSpec2.it_interval.tv_nsec ))
       
   130         {
       
   131             iParams.iTestStep.INFO_PRINTF1(_L("Timer Spec Matched"));
       
   132             return ETrue;
       
   133 
       
   134         }
       
   135     else
       
   136         {
       
   137             iParams.iTestStep.INFO_PRINTF1(_L("Timer spec Not Matched"));
       
   138             return EFalse;
       
   139         }
       
   140 
       
   141 
       
   142     }