sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Name : tclockblocks.cpp sl@0: // Test cases for blocking signal api's sl@0: // sl@0: // sl@0: sl@0: #include "tclock.h" sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CTestclock::Testgetclockid1 sl@0: // Test Case ID: OPENENV-LIBC-CIT-5946 sl@0: // API tested: clock_getcpuclockid() sl@0: // Description: To access the clock id of CPU time clock with pid = 0. API tested: clock_getcpuclockid() sl@0: // ----------------------------------------------------------------------------- sl@0: sl@0: TInt CTestclock::Testgetclockid1 ( ) sl@0: { sl@0: int ret, ret1 = KErrGeneral; sl@0: clockid_t clockid; sl@0: ret = clock_getcpuclockid(0,&clockid); sl@0: if (ret != 0) sl@0: { sl@0: ERR_PRINTF2(_L("Failed to retrieve the clock id of the calling process and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: if (clockid != CLOCK_REALTIME) sl@0: { sl@0: ERR_PRINTF1(_L("Failed to return the right clock id")); sl@0: goto close; sl@0: } sl@0: INFO_PRINTF1(_L("Successfully able to get the calling process's clock id") ); sl@0: ret1 = KErrNone; sl@0: sl@0: close: sl@0: return ret1; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CTestclock::Testgetclockid2 sl@0: // Test Case ID: OPENENV-LIBC-CIT-5946 sl@0: // API tested: clock_getcpuclockid() sl@0: // Description: To access the clock id of CPU time clock of self. API tested: clock_getcpuclockid() sl@0: // ----------------------------------------------------------------------------- sl@0: sl@0: TInt CTestclock::Testgetclockid2 ( ) sl@0: { sl@0: int ret, ret1 = KErrGeneral; sl@0: clockid_t clockid; sl@0: ret = clock_getcpuclockid(getpid(),&clockid); sl@0: if ((ret != -1) || (errno != ESRCH)) sl@0: { sl@0: ERR_PRINTF2(_L("clock_getcpuclockid() failed on negative test and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: INFO_PRINTF1(_L("clock_getcpuclockid() is successful on negative test") ); sl@0: ret1 = KErrNone; sl@0: sl@0: close: sl@0: return ret1; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CTestclock::Testgetclockid3 sl@0: // Test Case ID: OPENENV-LIBC-CIT-5946 sl@0: // API tested: clock_getcpuclockid() sl@0: // Description: To access the clock id of CPU time clock of other process sl@0: // ----------------------------------------------------------------------------- sl@0: sl@0: TInt CTestclock::Testgetclockid3 ( ) sl@0: { sl@0: int ret, ret1 = KErrGeneral; sl@0: pid_t pid; sl@0: clockid_t clockid; sl@0: char **argv = (char **)malloc(2*sizeof(char*)); sl@0: argv[0] = (char *)malloc(30*sizeof(char*)); sl@0: argv[1] = 0; sl@0: strcpy(argv[0],"z:\\sys\\bin\\getclockid.exe"); sl@0: ret = posix_spawn(&pid, "z:\\sys\\bin\\getclockid.exe", NULL, NULL, argv, (char**)NULL); sl@0: if(ret != 0) sl@0: { sl@0: ERR_PRINTF2(_L("Error in posix spawn and errno is set to %d"),errno); sl@0: goto close; sl@0: } sl@0: ret = clock_getcpuclockid(pid,&clockid); sl@0: if ((ret != -1) || (errno != ESRCH)) sl@0: { sl@0: ERR_PRINTF2(_L("clock_getcpuclockid() failed on negative test and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: INFO_PRINTF1(_L("clock_getcpuclockid() is successful on negative test") ); sl@0: ret1 = KErrNone; sl@0: sl@0: close: sl@0: free((void*)argv[0]); sl@0: free((void*)argv); sl@0: return ret1; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CTestclock::Testgetclockid4 sl@0: // Test Case ID: OPENENV-LIBC-CIT-5946 sl@0: // API tested: clock_getcpuclockid() sl@0: // Description: To access the clock id of CPU time clock of an invalid process. sl@0: // ----------------------------------------------------------------------------- sl@0: sl@0: TInt CTestclock::Testgetclockid4 ( ) sl@0: { sl@0: int ret, ret1 = KErrGeneral; sl@0: clockid_t clockid; sl@0: ret = clock_getcpuclockid(-1,&clockid); sl@0: if ((ret != -1) || (errno != ESRCH)) sl@0: { sl@0: ERR_PRINTF2(_L("clock_getcpuclockid() failed on negative test and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: INFO_PRINTF1(_L("clock_getcpuclockid() has successfully returned ESRCH on negative test") ); sl@0: ret1 = KErrNone; sl@0: sl@0: close: sl@0: return ret1; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CTestclock::Testgetclockid5 sl@0: // Test Case ID: OPENENV-LIBC-CIT-5946 sl@0: // API tested: clock_getcpuclockid() sl@0: // Description: Trying to access the clock id of an invalid id passing to it. sl@0: // ----------------------------------------------------------------------------- sl@0: sl@0: TInt CTestclock::Testgetclockid5 ( ) sl@0: { sl@0: int ret, ret1 = KErrGeneral; sl@0: ret = clock_getcpuclockid(0,NULL); sl@0: if ((ret != -1) || (errno != EFAULT)) sl@0: { sl@0: ERR_PRINTF2(_L("clock_getcpuclockid() failed on negative test and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: INFO_PRINTF1(_L("clock_getcpuclockid() has successfully returned EFAULT on negative test") ); sl@0: ret1 = KErrNone; sl@0: sl@0: close: sl@0: return ret1; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CTestclock::Testclockresolution1 sl@0: // Test Case ID: OPENENV-LIBC-CIT-5946 sl@0: // API tested: clock_getres() sl@0: // Description: To get the clock resolution with valid clock id using clock_getres() sl@0: // ----------------------------------------------------------------------------- sl@0: sl@0: TInt CTestclock::Testclockresolution1 ( ) sl@0: { sl@0: int ret, ret1 = KErrGeneral; sl@0: clockid_t clockid; sl@0: struct timespec tmspec; sl@0: ret = clock_getcpuclockid(0,&clockid); sl@0: if (ret != 0) sl@0: { sl@0: ERR_PRINTF2(_L("Failed to retrieve the clock id of the calling process and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: ret = clock_getres(clockid,&tmspec); sl@0: if (ret != 0) sl@0: { sl@0: ERR_PRINTF2(_L("Failed to retrieve resolution of the clock id specified and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: if ((tmspec.tv_nsec != 1000) || (tmspec.tv_sec != 0)) sl@0: { sl@0: ERR_PRINTF1(_L("Resolution of the clock id is not set properly")); sl@0: goto close; sl@0: } sl@0: INFO_PRINTF1(_L("Successfully able to get the clock resolution of the specified clock id") ); sl@0: ret1 = KErrNone; sl@0: sl@0: close: sl@0: return ret1; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CTestclock::Testclockresolution2 sl@0: // Test Case ID: OPENENV-LIBC-CIT-5946 sl@0: // API tested: clock_getres() sl@0: // Description: Trying to get the clock resolution using clock_getres() for a clockid other than CLOCK_REALTIME sl@0: // ----------------------------------------------------------------------------- sl@0: sl@0: TInt CTestclock::Testclockresolution2 ( ) sl@0: { sl@0: int ret, ret1 = KErrGeneral, Clockid, Error; sl@0: struct timespec tmspec; sl@0: ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); sl@0: if(ret == 0) sl@0: { sl@0: ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ; sl@0: goto close; sl@0: } sl@0: ret = GetIntFromConfig(ConfigSection(), _L("Error"), Error); sl@0: if(ret == 0) sl@0: { sl@0: ERR_PRINTF1(_L("Unable to read expected error num")) ; sl@0: goto close; sl@0: } sl@0: ret = clock_getres(Clockid,&tmspec); sl@0: if ((ret != -1) || (errno != Error)) sl@0: { sl@0: ERR_PRINTF2(_L("The expected and errno are not same and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: INFO_PRINTF1(_L("The output and expected value are same for clock_getres()") ); sl@0: ret1 = KErrNone; sl@0: sl@0: close: sl@0: return ret1; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CTestclock::Testclockresolution3 sl@0: // Test Case ID: OPENENV-LIBC-CIT-5946 sl@0: // API tested: clock_getres() sl@0: // Description: Negative Test: Trying to get the resolution with res = NULL using clock_getres() sl@0: // ----------------------------------------------------------------------------- sl@0: sl@0: TInt CTestclock::Testclockresolution3 ( ) sl@0: { sl@0: int ret, ret1 = KErrGeneral, Clockid; sl@0: ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); sl@0: if(ret == 0) sl@0: { sl@0: ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ; sl@0: goto close; sl@0: } sl@0: ret = clock_getres(Clockid,NULL); sl@0: if (ret != 0) sl@0: { sl@0: ERR_PRINTF2(_L("clock_getres() failed on negative test if timespec argument is NULL and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: INFO_PRINTF1(_L("clock_getres() successfully returned 0 on negative test") ); sl@0: ret1 = KErrNone; sl@0: sl@0: close: sl@0: return ret1; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CTestclock::Testclocknanosleep1 sl@0: // Test Case ID: OPENENV-LIBC-CIT-5946 sl@0: // API tested: clock_nanosleep() sl@0: // Description: Trying to suspend the process for the specified time using clock_nanosleep() in the absence of TIMER_ABSTIME sl@0: // Relative timer sl@0: // ----------------------------------------------------------------------------- sl@0: sl@0: TInt CTestclock::Testclocknanosleep1 ( ) sl@0: { sl@0: int ret, ret1 = KErrGeneral, Valuesec, Valuenanosec; sl@0: struct timespec gettmspec, oldtmpsec, sleeptmspec, sleeptmspec1; sl@0: ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec); sl@0: if(ret == 0) sl@0: { sl@0: ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ; sl@0: goto close; sl@0: } sl@0: ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec); sl@0: if(ret == 0) sl@0: { sl@0: ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ; sl@0: goto close; sl@0: } sl@0: sleeptmspec.tv_sec = Valuesec; sl@0: sleeptmspec.tv_nsec = Valuenanosec; sl@0: ret = clock_gettime(CLOCK_REALTIME,&gettmspec); sl@0: if (ret != 0) sl@0: { sl@0: ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: oldtmpsec = gettmspec; sl@0: ret = clock_nanosleep(CLOCK_REALTIME,0,&sleeptmspec,&sleeptmspec1); sl@0: if (ret != 0) sl@0: { sl@0: ERR_PRINTF2(_L("clock_nanosleep() failed and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: ret = clock_gettime(CLOCK_REALTIME,&gettmspec); sl@0: if (ret != 0) sl@0: { sl@0: ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: if (gettmspec.tv_sec != (oldtmpsec.tv_sec + Valuesec)) sl@0: { sl@0: ERR_PRINTF2(_L("clock_nanosleep() has failed to sleep for %d secs"),Valuesec); sl@0: goto close; sl@0: } sl@0: INFO_PRINTF1(_L("Relative timer")); sl@0: INFO_PRINTF2(_L("clock_nanosleep() successfully able to sleep for %d secs"),Valuesec ); sl@0: ret1 = KErrNone; sl@0: sl@0: close: sl@0: return ret1; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CTestclock::Testclocknanosleep2 sl@0: // Test Case ID: OPENENV-LIBC-CIT-5946 sl@0: // API tested: clock_nanosleep() sl@0: // Description: Trying to suspend the process for the specified time using clock_nanosleep() sl@0: // Absolute timer sl@0: // ----------------------------------------------------------------------------- sl@0: sl@0: TInt CTestclock::Testclocknanosleep2 ( ) sl@0: { sl@0: int ret, ret1 = KErrGeneral, Valuesec, Valuenanosec; sl@0: struct timespec gettmspec, oldtmpsec, sleeptmspec, sleeptmspec1; sl@0: ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec); sl@0: if(ret == 0) sl@0: { sl@0: ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ; sl@0: goto close; sl@0: } sl@0: ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec); sl@0: if(ret == 0) sl@0: { sl@0: ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ; sl@0: goto close; sl@0: } sl@0: sleeptmspec.tv_sec = Valuesec; sl@0: sleeptmspec.tv_nsec = Valuenanosec; sl@0: ret = clock_gettime(CLOCK_REALTIME,&gettmspec); sl@0: if (ret != 0) sl@0: { sl@0: ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: oldtmpsec = gettmspec; sl@0: sleeptmspec.tv_sec = gettmspec.tv_sec + Valuesec; sl@0: sleeptmspec.tv_nsec = gettmspec.tv_nsec + Valuenanosec; sl@0: ret = clock_nanosleep(CLOCK_REALTIME,TIMER_ABSTIME,&sleeptmspec,&sleeptmspec1); sl@0: if (ret != 0) sl@0: { sl@0: ERR_PRINTF2(_L("clock_nanosleep() failed and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: ret = clock_gettime(CLOCK_REALTIME,&gettmspec); sl@0: if (ret != 0) sl@0: { sl@0: ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: if (gettmspec.tv_sec < (oldtmpsec.tv_sec + Valuesec)) sl@0: { sl@0: ERR_PRINTF2(_L("clock_nanosleep() has failed to sleep for %d secs"),Valuesec); sl@0: goto close; sl@0: } sl@0: INFO_PRINTF1(_L("Absolute timer")); sl@0: INFO_PRINTF2(_L("clock_nanosleep() successfully able to sleep for %d secs"),Valuesec ); sl@0: ret1 = KErrNone; sl@0: sl@0: close: sl@0: return ret1; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CTestclock::Testclocknanosleep3 sl@0: // Test Case ID: OPENENV-LIBC-CIT-5946 sl@0: // API tested: clock_nanosleep() sl@0: // Description: Trying to suspend the process for an invalid time using clock_nanosleep() in the absence of TIMER_ABSTIME sl@0: // ----------------------------------------------------------------------------- sl@0: sl@0: TInt CTestclock::Testclocknanosleep3 ( ) sl@0: { sl@0: int ret, ret1 = KErrGeneral, Valuesec, Valuenanosec; sl@0: struct timespec sleeptmspec; sl@0: ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec); sl@0: if(ret == 0) sl@0: { sl@0: ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ; sl@0: goto close; sl@0: } sl@0: ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec); sl@0: if(ret == 0) sl@0: { sl@0: ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ; sl@0: goto close; sl@0: } sl@0: sleeptmspec.tv_sec = Valuesec; sl@0: sleeptmspec.tv_nsec = Valuenanosec; sl@0: ret = clock_nanosleep(CLOCK_REALTIME,0,&sleeptmspec,NULL); sl@0: if ((ret != -1) || (errno != EINVAL)) sl@0: { sl@0: ERR_PRINTF2(_L("clock_nanosleep() failed and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: INFO_PRINTF1(_L("clock_nanosleep() successfully able to sleep for 2 secs") ); sl@0: ret1 = KErrNone; sl@0: sl@0: close: sl@0: return ret1; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CTestclock::Testclocknanosleep4 sl@0: // Test Case ID: OPENENV-LIBC-CIT-5946 sl@0: // API tested: clock_nanosleep() sl@0: // Description: Trying to suspend the process with an invalid clock id clock_nanosleep() sl@0: // ----------------------------------------------------------------------------- sl@0: sl@0: TInt CTestclock::Testclocknanosleep4 ( ) sl@0: { sl@0: int ret, ret1 = KErrGeneral, Invalidid; sl@0: struct timespec sleeptmspec; sl@0: ret = GetIntFromConfig(ConfigSection(), _L("Invalidid"), Invalidid); sl@0: if(ret == 0) sl@0: { sl@0: ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ; sl@0: goto close; sl@0: } sl@0: sleeptmspec.tv_sec = 2; sl@0: sleeptmspec.tv_nsec = 0; sl@0: ret = clock_nanosleep(Invalidid,0,&sleeptmspec,NULL); sl@0: if ((ret != -1) || (errno != EINVAL)) sl@0: { sl@0: ERR_PRINTF2(_L("clock_nanosleep() failed to return EINVAL and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: INFO_PRINTF1(_L("clock_nanosleep() successfully able to return EINVAL ") ); sl@0: ret1 = KErrNone; sl@0: sl@0: close: sl@0: return ret1; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CTestclock::Testclocknanosleep5 sl@0: // Test Case ID: OPENENV-LIBC-CIT-5946 sl@0: // API tested: clock_nanosleep() sl@0: // Description: clock_nanosleep() with an invalid parameter of timespec sl@0: // ----------------------------------------------------------------------------- sl@0: sl@0: TInt CTestclock::Testclocknanosleep5 ( ) sl@0: { sl@0: int ret, ret1 = KErrGeneral; sl@0: ret = clock_nanosleep(CLOCK_REALTIME,0,NULL,NULL); sl@0: if ((ret != -1) || (errno != EFAULT)) sl@0: { sl@0: ERR_PRINTF2(_L("clock_nanosleep() failed to return EINVAL and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: INFO_PRINTF1(_L("clock_nanosleep() successfully able to return EINVAL ") ); sl@0: ret1 = KErrNone; sl@0: sl@0: close: sl@0: return ret1; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CTestclock::Testclocknanosleep6 sl@0: // Test Case ID: OPENENV-LIBC-CIT-5946 sl@0: // API tested: clock_nanosleep() sl@0: // Description: clock_nanosleep() with a flag other than Absolute value sl@0: // ----------------------------------------------------------------------------- sl@0: sl@0: TInt CTestclock::Testclocknanosleep6 ( ) sl@0: { sl@0: int ret, ret1 = KErrGeneral, Valuesec, Valuenanosec; sl@0: struct timespec gettmspec, oldtmpsec, sleeptmspec, sleeptmspec1; sl@0: ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec); sl@0: if(ret == 0) sl@0: { sl@0: ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ; sl@0: goto close; sl@0: } sl@0: ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec); sl@0: if(ret == 0) sl@0: { sl@0: ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ; sl@0: goto close; sl@0: } sl@0: sleeptmspec.tv_sec = Valuesec; sl@0: sleeptmspec.tv_nsec = Valuenanosec; sl@0: ret = clock_gettime(CLOCK_REALTIME,&gettmspec); sl@0: if (ret != 0) sl@0: { sl@0: ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: oldtmpsec = gettmspec; sl@0: ret = clock_nanosleep(CLOCK_REALTIME,15,&sleeptmspec,&sleeptmspec1); sl@0: if (ret != 0) sl@0: { sl@0: ERR_PRINTF2(_L("clock_nanosleep() failed and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: ret = clock_gettime(CLOCK_REALTIME,&gettmspec); sl@0: if (ret != 0) sl@0: { sl@0: ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: if (gettmspec.tv_sec != (oldtmpsec.tv_sec + Valuesec)) sl@0: { sl@0: ERR_PRINTF2(_L("clock_nanosleep() has failed to sleep for %d secs"),Valuesec); sl@0: goto close; sl@0: } sl@0: INFO_PRINTF1(_L("Relative timer")); sl@0: INFO_PRINTF2(_L("clock_nanosleep() successfully able to sleep for %d secs"),Valuesec ); sl@0: ret1 = KErrNone; sl@0: sl@0: close: sl@0: return ret1; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CTestclock::Testclockgettime1 sl@0: // Test Case ID: OPENENV-LIBC-CIT-5946 sl@0: // API tested: clock_gettime() sl@0: // Description: To get the current value for the specified valid clock_id sl@0: // ----------------------------------------------------------------------------- sl@0: sl@0: TInt CTestclock::Testclockgettime1 ( ) sl@0: { sl@0: int ret, ret1 = KErrGeneral; sl@0: clockid_t clockid; sl@0: struct timespec tmspec, oldtmspec; sl@0: ret = clock_getcpuclockid(0,&clockid); sl@0: if (ret != 0) sl@0: { sl@0: ERR_PRINTF2(_L("Failed to retrieve the clock id of the calling process and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: ret = clock_gettime(clockid,&tmspec); sl@0: if (ret != 0) sl@0: { sl@0: ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: sleep(2); sl@0: oldtmspec = tmspec; sl@0: ret = clock_gettime(clockid,&tmspec); sl@0: if (ret != 0) sl@0: { sl@0: ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: if (tmspec.tv_sec != (oldtmspec.tv_sec + 2)) sl@0: { sl@0: ERR_PRINTF1(_L("Failed to retrieve resolution of the clock id specified")); sl@0: goto close; sl@0: } sl@0: INFO_PRINTF1(_L("clock_gettime() successfully able to get the time") ); sl@0: ret1 = KErrNone; sl@0: sl@0: close: sl@0: return ret1; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CTestclock::Testclockgettime2 sl@0: // Test Case ID: OPENENV-LIBC-CIT-5946 sl@0: // API tested: clock_gettime() sl@0: // Description: Trying to get the current time value for an invalid clock id using clock_gettime() sl@0: // ----------------------------------------------------------------------------- sl@0: sl@0: TInt CTestclock::Testclockgettime2 ( ) sl@0: { sl@0: int ret, ret1 = KErrGeneral, Clockid, Error; sl@0: struct timespec tmspec; sl@0: ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); sl@0: if(ret == 0) sl@0: { sl@0: ERR_PRINTF1(_L("Unable to clock id value")) ; sl@0: goto close; sl@0: } sl@0: ret = GetIntFromConfig(ConfigSection(), _L("Error"), Error); sl@0: if(ret == 0) sl@0: { sl@0: ERR_PRINTF1(_L("Unable to read expected error num")) ; sl@0: goto close; sl@0: } sl@0: ret = clock_gettime(Clockid,&tmspec); sl@0: if ((ret != -1) || (errno != Error)) sl@0: { sl@0: ERR_PRINTF2(_L("clock_gettime() failed to return EINVAL for an invalid clock id and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: INFO_PRINTF1(_L("clock_gettime() successfully returned EINVAL for an invalid clock id") ); sl@0: ret1 = KErrNone; sl@0: sl@0: close: sl@0: return ret1; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CTestclock::Testclockgettime3 sl@0: // Test Case ID: OPENENV-LIBC-CIT-5946 sl@0: // API tested: clock_gettime() sl@0: // Description: Trying to get the current time value for a valid clock id with NULL as the timespec using clock_gettime() sl@0: // ----------------------------------------------------------------------------- sl@0: sl@0: TInt CTestclock::Testclockgettime3 ( ) sl@0: { sl@0: int ret, ret1 = KErrGeneral, Clockid; sl@0: ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); sl@0: if(ret == 0) sl@0: { sl@0: ERR_PRINTF1(_L("Unable to read clock id value")) ; sl@0: goto close; sl@0: } sl@0: ret = clock_gettime(Clockid,NULL); sl@0: if ((ret != -1) || (errno != EFAULT)) sl@0: { sl@0: ERR_PRINTF2(_L("clock_gettime() failed to return EFAULT for NULL timespec parameter and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: INFO_PRINTF1(_L("clock_gettime() successfully returned EFAULT for NULL timespec parameter ") ); sl@0: ret1 = KErrNone; sl@0: sl@0: close: sl@0: return ret1; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CTestclock::Testclocksettime1 sl@0: // Test Case ID: OPENENV-LIBC-CIT-5946 sl@0: // API tested: clock_settime() sl@0: // Description: Trying to set the current time value for an invalid clock id using clock_settime() sl@0: // ----------------------------------------------------------------------------- sl@0: sl@0: TInt CTestclock::Testclocksettime1 ( ) sl@0: { sl@0: int ret, ret1 = KErrGeneral, Clockid, Error; sl@0: struct timespec tmspec; sl@0: tmspec.tv_sec = 30; sl@0: tmspec.tv_nsec = 2000; sl@0: ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); sl@0: if(ret == 0) sl@0: { sl@0: ERR_PRINTF1(_L("Unable to read clock id value")) ; sl@0: goto close; sl@0: } sl@0: ret = GetIntFromConfig(ConfigSection(), _L("Error"), Error); sl@0: if(ret == 0) sl@0: { sl@0: ERR_PRINTF1(_L("Unable to read expected error num")) ; sl@0: goto close; sl@0: } sl@0: ret = clock_settime(Clockid,&tmspec); sl@0: if ((ret != -1) || (errno != Error)) sl@0: { sl@0: ERR_PRINTF2(_L("clock_settime() failed on negative test and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: INFO_PRINTF1(_L("clock_settime() is successfull on negative test") ); sl@0: ret1 = KErrNone; sl@0: sl@0: close: sl@0: return ret1; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CTestclock::Testclocksettime2 sl@0: // Test Case ID: OPENENV-LIBC-CIT-5946 sl@0: // API tested: clock_settime() sl@0: // Description: clock_settime() with NULL as the timespec parameter sl@0: // ----------------------------------------------------------------------------- sl@0: sl@0: TInt CTestclock::Testclocksettime2 ( ) sl@0: { sl@0: int ret, ret1 = KErrGeneral, Clockid; sl@0: ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); sl@0: if(ret == 0) sl@0: { sl@0: ERR_PRINTF1(_L("Unable to read clock id value")) ; sl@0: goto close; sl@0: } sl@0: ret = clock_settime(Clockid,NULL); sl@0: if ((ret != -1) || (errno != EFAULT)) sl@0: { sl@0: ERR_PRINTF2(_L("clock_settime() failed to return EFAULT on negative test and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: INFO_PRINTF1(_L("clock_settime() successfully returned EFAULT on negative test") ); sl@0: ret1 = KErrNone; sl@0: sl@0: close: sl@0: return ret1; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CTestclock::Testclocksettime3 sl@0: // Test Case ID: OPENENV-LIBC-CIT-5946 sl@0: // API tested: clock_settime() sl@0: // Description: Test case added to set the value of clock id current value to an invalid specified value using clock_settime() sl@0: // ----------------------------------------------------------------------------- sl@0: sl@0: TInt CTestclock::Testclocksettime3 ( ) sl@0: { sl@0: int ret, ret1 = KErrGeneral, Clockid, Valuesec, Valuenanosec; sl@0: struct timespec tmspec; sl@0: ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); sl@0: if(ret == 0) sl@0: { sl@0: ERR_PRINTF1(_L("Unable to read clock id value")) ; sl@0: goto close; sl@0: } sl@0: ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec); sl@0: if(ret == 0) sl@0: { sl@0: ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ; sl@0: goto close; sl@0: } sl@0: ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec); sl@0: if(ret == 0) sl@0: { sl@0: ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ; sl@0: goto close; sl@0: } sl@0: tmspec.tv_sec = Valuesec; sl@0: tmspec.tv_nsec = Valuenanosec; sl@0: ret = clock_settime(Clockid,&tmspec); sl@0: if ((ret != -1) || (errno != EINVAL)) sl@0: { sl@0: ERR_PRINTF2(_L("clock_settime() failed to return EINVAL on negative test and errno is %d"),errno); sl@0: goto close; sl@0: } sl@0: INFO_PRINTF1(_L("clock_settime() successfully returned EINVAL on negative test") ); sl@0: ret1 = KErrNone; sl@0: sl@0: close: sl@0: return ret1; sl@0: } sl@0: sl@0: //End of a file