提交 555e0681 编写于 作者: V vcbchang

test: clock用例结构调整

【背景】当前kernel的unittest下的用例全量与门禁用例结构不合理,当前上传clock修改后版本

【修改方案】
1 原来没有测试clock模块的基本场景,这里补上基本场景作为smoke用例,并命名为clock_test_smoke.cpp
2 将原来smoke用例移到full中
3 删除与xts测试重复的用例和标记宏TEST_ON_LINUX的用例(即原来版本的clock_test_002,003,004用例)
4 原来clock_test_012用例用于测试进程的运行时间,里面存在正常场景和异常场景,现在将其分成两个用例
5 对所有用例重新排序,使得结构完整

re #I44170
Signed-off-by: Nvcbchang <vcbchang@qq.com>

Change-Id: I30852a5f9c414668c00eddbcc9631d70818514a1
上级 1aa9f988
......@@ -41,20 +41,18 @@ sources_entry = [
"time_clock_test.cpp",
]
sources_smoke = [
"smoke/clock_test_001.cpp",
"smoke/clock_test_002.cpp",
"smoke/clock_test_003.cpp",
"smoke/clock_test_004.cpp",
"smoke/clock_test_006.cpp",
"smoke/clock_test_007.cpp",
"smoke/clock_test_008.cpp",
"smoke/clock_test_009.cpp",
"smoke/clock_test_011.cpp",
"smoke/clock_test_012.cpp",
]
sources_smoke = [ "smoke/clock_test_smoke.cpp" ]
sources_full = [
"full/clock_test_001.cpp",
"full/clock_test_002.cpp",
"full/clock_test_003.cpp",
"full/clock_test_004.cpp",
"full/clock_test_005.cpp",
"full/clock_test_006.cpp",
"full/clock_test_007.cpp",
"full/clock_test_008.cpp",
"full/clock_test_009.cpp",
"full/clock_test_010.cpp",
]
......
......@@ -45,36 +45,38 @@ static int ClockTest(void)
clockid_t clk = CLOCK_REALTIME;
struct timespec res, tp, oldtp;
int ret;
int passflag = 0;
/* get clock resolution */
ret = clock_getres(clk, &res);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(res.tv_sec, CLOCK_RES_SEC, res.tv_sec);
ICUNIT_ASSERT_EQUAL(res.tv_nsec, CLOCK_RES_NSEC, res.tv_nsec);
/* get current real time */
ret = clock_gettime(clk, &oldtp);
printf("The current real time: sec is %lld, nsec is %ld\n", oldtp.tv_sec, oldtp.tv_nsec);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
printf("sleep 2 seconds\n");
sleep(2); // 2, seconds.
tp.tv_sec = 5 * res.tv_sec; // 5, times the number of seconds.
tp.tv_nsec = 5 * res.tv_nsec; // 5, times the number of nseconds.
tp.tv_sec = oldtp.tv_sec + 2; // 2, use for testing clock setting
tp.tv_nsec = oldtp.tv_nsec;
/* set real time */
ret = clock_settime(clk, &tp);
#if TEST_ON_LINUX
/* on linux host we need root to set clock time */
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
ICUNIT_ASSERT_EQUAL(errno, EPERM, errno);
#else
printf("Setting time: sec is %lld, nsec is %ld\n", tp.tv_sec, tp.tv_nsec);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
#endif
LogPrintln("get real time clock again\n");
printf("get real time clock again\n");
/* get current real time again */
ret = clock_gettime(clk, &tp);
printf("Obtaining the current time after setting: sec = %lld, nsec = %ld\n", tp.tv_sec, tp.tv_nsec);
passflag = (tp.tv_sec >= 2 + oldtp.tv_sec) && (tp.tv_sec <= 2 + oldtp.tv_sec + 1); // 2, use for testing clock setting
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(passflag, true, passflag);
return 0;
}
......
......@@ -46,7 +46,7 @@ static int ThreadClock(const char *msg, clockid_t cid)
ret = clock_gettime(cid, &ts);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
printf("%4jd.%03ld\n", ts.tv_sec, ts.tv_nsec / 1000000); // 1000000, 1ms.
printf("%lld.%03ld s\n", ts.tv_sec, ts.tv_nsec / 1000000); // 1000000, 1ms.
return 0;
}
......@@ -57,11 +57,6 @@ static int ClockTest(void)
int ret;
struct timespec ts;
/* check param invalid */
ret = clock_gettime(-2050, &ts); // 2050, clock id.
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
ret = pthread_create(&thread, NULL, ThreadFuncTest, 0);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
......@@ -69,9 +64,7 @@ static int ClockTest(void)
sleep(1);
printf("Main thread consuming some CPU time...\n");
for (int j = 0; j < 4000000; j++) { // 4000000, The loop frequency.
getppid();
}
usleep(400000); // 400000 delay for test
/* get current pthread clockid */
ret = pthread_getcpuclockid(pthread_self(), &clockid);
......@@ -84,13 +77,13 @@ static int ClockTest(void)
ret = pthread_getcpuclockid(thread, &clockid);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = ThreadClock("Subthread CPU time: 1 ", clockid);
ret = ThreadClock("Subthread CPU time: ", clockid);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return 0;
}
void ClockTest011(void)
void ClockTest002(void)
{
TEST_ADD_CASE(__FUNCTION__, ClockTest, TEST_POSIX, TEST_TIMES, TEST_LEVEL0, TEST_FUNCTION);
}
......@@ -35,42 +35,46 @@ static int ClockTest(void)
clockid_t clockid;
struct timespec ts;
int ret;
pid_t pid = 0;
int passflag = 0;
/* check param invalid */
ret = clock_getcpuclockid(0, &clockid);
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
ret = clock_getcpuclockid(65, &clockid); // 65, pthread id.
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
/* get user process2 clockid */
ret = clock_getcpuclockid(2, &clockid);
/* get kernel process 1 clockid */
pid = 1;
ret = clock_getcpuclockid(1, &clockid);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(clockid, CLOCK_GET_CPU_CLOCKID(pid), clockid);
/* get clockid time */
ret = clock_gettime(clockid, &ts);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
printf("Obtaining the process running time: %lld second, %ld nanosecond\n", ts.tv_sec, ts.tv_nsec);
/* get kernel process1 clockid */
ret = clock_getcpuclockid(1, &clockid);
/* get user process 2 clockid */
pid = 2; // 2, test the process 2 (An existent pid)
ret = clock_getcpuclockid(2, &clockid);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(clockid, CLOCK_GET_CPU_CLOCKID(pid), clockid);
/* get clockid time */
ret = clock_gettime(clockid, &ts);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
printf("Obtaining the process running time: %lld second, %ld nanosecond\n", ts.tv_sec, ts.tv_nsec);
/* get current process clockid */
pid = getpid();
ret = clock_getcpuclockid(getpid(), &clockid);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(clockid, CLOCK_GET_CPU_CLOCKID(pid), clockid);
/* get clockid time */
ret = clock_gettime(clockid, &ts);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
printf("Obtaining the process running time: %lld second, %ld nanosecond\n", ts.tv_sec, ts.tv_nsec);
return 0;
}
void ClockTest012(void)
void ClockTest003(void)
{
TEST_ADD_CASE(__FUNCTION__, ClockTest, TEST_POSIX, TEST_TIMES, TEST_LEVEL0, TEST_FUNCTION);
}
\ No newline at end of file
}
......@@ -30,24 +30,22 @@
*/
#include "lt_clock_test.h"
static int CpuClockTest(void)
static int ClockTest(void)
{
int pid = 0;
int ret;
pthread_t thread;
clockid_t clockid;
int ret;
struct timespec ts;
/* CLOCK_PROCESS_CPUTIME_ID if pid == 0 */
ret = clock_getcpuclockid(pid, &clockid);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = clock_gettime(clockid, &ts);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
/* check param invalid */
ret = clock_gettime(-2050, &ts); // 2050, clock id.
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
return 0;
}
void ClockTest004(void)
{
TEST_ADD_CASE(__FUNCTION__, CpuClockTest, TEST_POSIX, TEST_TIMES, TEST_LEVEL0, TEST_FUNCTION);
TEST_ADD_CASE(__FUNCTION__, ClockTest, TEST_POSIX, TEST_TIMES, TEST_LEVEL0, TEST_FUNCTION);
}
......@@ -30,19 +30,25 @@
*/
#include "lt_clock_test.h"
static int ClockMonotonicTest(void)
static int ClockTest(void)
{
clockid_t clk = CLOCK_MONOTONIC;
struct timespec res, ts;
clockid_t clockid;
struct timespec ts;
int ret;
pid_t pid = 0;
ret = clock_gettime(clk, &ts);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
/* check param invalid */
ret = clock_getcpuclockid(pid, &clockid);
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
pid = 65; // 65, non existent process id.
ret = clock_getcpuclockid(pid, &clockid);
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
return 0;
}
void ClockTest002(void)
void ClockTest005(void)
{
TEST_ADD_CASE(__FUNCTION__, ClockMonotonicTest, TEST_POSIX, TEST_TIMES, TEST_LEVEL0, TEST_FUNCTION);
}
\ No newline at end of file
TEST_ADD_CASE(__FUNCTION__, ClockTest, TEST_POSIX, TEST_TIMES, TEST_LEVEL0, TEST_FUNCTION);
}
......@@ -45,31 +45,35 @@ static int ClockTest(void)
clockid_t clk = CLOCK_REALTIME_COARSE;
struct timespec res, tp, oldtp;
int ret;
int passflag = 0;
/* get clock resolution */
ret = clock_getres(clk, &res);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(res.tv_sec, CLOCK_COARSE_RES_SEC, res.tv_sec);
ICUNIT_ASSERT_EQUAL(res.tv_nsec, CLOCK_COARSE_RES_NSEC, res.tv_nsec);
/* get current real coarse time */
ret = clock_gettime(clk, &oldtp);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
printf("The current coarse real time: sec is %lld, nsec is %ld\n", oldtp.tv_sec, oldtp.tv_nsec);
LogPrintln("sleep 2 seconds\n");
sleep(2); // 2, seconds.
tp.tv_sec = 5 * res.tv_sec; // 5, times the number of seconds.
tp.tv_nsec = 5 * res.tv_nsec; // 5, times the number of nseconds.
tp.tv_sec = 5 * oldtp.tv_sec; // 5, times the number of seconds.
tp.tv_nsec = oldtp.tv_nsec; // 5, times the number of nseconds.
/* set real coarse time */
ret = clock_settime(clk, &tp);
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
ICUNIT_ASSERT_EQUAL(errno, EOPNOTSUPP, errno);
LogPrintln("get coarse real time clock again\n");
printf("get coarse real time clock again\n");
/* get current real coarse time again */
ret = clock_gettime(clk, &tp);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
printf("The current coarse real time again: sec is %lld, nsec is %ld\n", tp.tv_sec, tp.tv_nsec);
passflag = (tp.tv_sec >= oldtp.tv_sec) && (tp.tv_sec <= oldtp.tv_sec + 1);
ICUNIT_ASSERT_EQUAL(passflag, 1, passflag);
return 0;
}
......
......@@ -45,31 +45,34 @@ static int ClockTest(void)
clockid_t clk = CLOCK_MONOTONIC_COARSE;
struct timespec res, tp, oldtp;
int ret;
int passflag = 0;
/* get clock resolution */
ret = clock_getres(clk, &res);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(res.tv_sec, CLOCK_COARSE_RES_SEC, res.tv_sec);
ICUNIT_ASSERT_EQUAL(res.tv_nsec, CLOCK_COARSE_RES_NSEC, res.tv_nsec);
/* get current monotonic coarse time */
ret = clock_gettime(clk, &oldtp);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
LogPrintln("sleep 2 seconds\n");
sleep(2); // 2, seconds.
printf("The current monotonic coarse time: sec is %lld, nsec is %ld\n", oldtp.tv_sec, oldtp.tv_nsec);
tp.tv_sec = 5 * res.tv_sec; // 5, times the number of seconds.
tp.tv_nsec = 5 * res.tv_nsec; // 5, times the number of nseconds.
tp.tv_nsec = res.tv_nsec;
/* set monotonic coarse time */
ret = clock_settime(clk, &tp);
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
ICUNIT_ASSERT_EQUAL(errno, EOPNOTSUPP, errno);
LogPrintln("get coarse monotonic time clock again\n");
printf("get coarse monotonic time clock again\n");
/* get current monotonic coarse time again */
ret = clock_gettime(clk, &tp);
passflag = (tp.tv_sec >= oldtp.tv_sec) && (tp.tv_sec <= oldtp.tv_sec + 1);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(passflag, 1, passflag);
printf("The current monotonic coarse time again: sec is %lld, nsec is %ld\n", tp.tv_sec, tp.tv_nsec);
return 0;
}
......
......@@ -34,8 +34,8 @@
#include <time.h>
#include <sys/times.h>
#include <errno.h>
#include "lt_clock_test.h"
#include <osTest.h>
#include "lt_clock_test.h"
/* When clock time is changed, timers for a relative interval are unaffected,
* but timers for an absolute point in time are affected.
......@@ -45,20 +45,21 @@ static int ClockTest(void)
clockid_t clk = CLOCK_MONOTONIC;
struct timespec res, tp, oldtp;
int ret;
int passflag = 0;
/* get clock resolution */
ret = clock_getres(clk, &res);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(res.tv_sec, CLOCK_RES_SEC, res.tv_sec);
ICUNIT_ASSERT_EQUAL(res.tv_nsec, CLOCK_RES_NSEC, res.tv_nsec);
/* get current monotonic time */
ret = clock_gettime(clk, &oldtp);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
printf("The current monotonic time: sec is %lld, nsec is %ld\n", oldtp.tv_sec, oldtp.tv_nsec);
LogPrintln("sleep 2 seconds\n");
sleep(2); // 2, seconds.
tp.tv_sec = 5 * res.tv_sec; // 5, times the number of seconds.
tp.tv_nsec = 5 * res.tv_nsec; // 5, times the number of nseconds.
tp.tv_sec = 5 * oldtp.tv_sec; // 5, times the number of seconds.
tp.tv_nsec = oldtp.tv_nsec;
/* set real time */
ret = clock_settime(clk, &tp);
......@@ -69,7 +70,10 @@ static int ClockTest(void)
/* get current monotonic time again */
ret = clock_gettime(clk, &tp);
passflag = (tp.tv_sec >= oldtp.tv_sec) && (tp.tv_sec <= oldtp.tv_sec + 1);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(passflag, 1, passflag);
printf("The current monotonic time: sec is %lld, nsec is %ld\n", tp.tv_sec, tp.tv_nsec);
return 0;
}
......
......@@ -45,31 +45,35 @@ static int ClockTest(void)
clockid_t clk = CLOCK_MONOTONIC_RAW;
struct timespec res, tp, oldtp;
int ret;
int passflag = 0;
/* get clock resolution */
ret = clock_getres(clk, &res);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(res.tv_sec, CLOCK_RES_SEC, res.tv_sec);
ICUNIT_ASSERT_EQUAL(res.tv_nsec, CLOCK_RES_NSEC, res.tv_nsec);
/* get current monotonic raw time */
ret = clock_gettime(clk, &oldtp);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
LogPrintln("sleep 2 seconds\n");
sleep(2); // 2, seconds.
printf("The current monotonic raw time: sec is %lld, nsec is %ld\n", oldtp.tv_sec, oldtp.tv_nsec);
tp.tv_sec = 5 * res.tv_sec; // 5, times the number of seconds.
tp.tv_nsec = 5 * res.tv_nsec; // 5, times the number of nseconds.
tp.tv_nsec = res.tv_nsec;
/* set monotonic raw time */
ret = clock_settime(clk, &tp);
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
ICUNIT_ASSERT_EQUAL(errno, EOPNOTSUPP, errno);
LogPrintln("get monotonic raw time clock again\n");
printf("get monotonic raw time clock again\n");
/* get current monotonic raw time again */
ret = clock_gettime(clk, &tp);
passflag = (tp.tv_sec >= oldtp.tv_sec) && (tp.tv_sec <= oldtp.tv_sec + 1);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(passflag, 1, passflag);
printf("The current monotonic raw time again: sec is %lld, nsec is %ld\n", tp.tv_sec, tp.tv_nsec);
return 0;
}
......
......@@ -37,6 +37,13 @@
#include <sys/times.h>
#include "osTest.h"
#define CLOCK_RES_SEC 0
#define CLOCK_RES_NSEC 1000
#define CLOCK_COARSE_RES_SEC 0
#define CLOCK_COARSE_RES_NSEC 1000000
#define CLOCK_GET_CPU_CLOCKID(pid) ((-pid - 1) * 8U + 2)
void ClockTestSmoke(void);
void ClockTest001(void);
void ClockTest002(void);
void ClockTest003(void);
......@@ -47,7 +54,5 @@ void ClockTest007(void);
void ClockTest008(void);
void ClockTest009(void);
void ClockTest010(void);
void ClockTest011(void);
void ClockTest012(void);
#endif /* TIME_CLOCK_LT_CLOCK_TEST_H_ */
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <sys/times.h>
#include "lt_clock_test.h"
#include <osTest.h>
static int ClockCoarseTest(void)
{
clockid_t clk = CLOCK_REALTIME_COARSE;
struct timespec res, realts, monots;
int ret;
ret = clock_gettime(clk, &realts);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
LogPrintln("sleep 2 seconds\n");
sleep(2); // 2, seconds.
LogPrintln("get real coarse time again\n");
ret = clock_gettime(clk, &realts);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
clk = CLOCK_MONOTONIC_COARSE;
ret = clock_gettime(clk, &monots);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return 0;
}
void ClockTest003(void)
{
TEST_ADD_CASE(__FUNCTION__, ClockCoarseTest, TEST_POSIX, TEST_TIMES, TEST_LEVEL0, TEST_FUNCTION);
}
\ No newline at end of file
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "lt_clock_test.h"
static int ClockSmokeTest(void)
{
clockid_t clk = CLOCK_REALTIME;
struct timespec res = {0,0}, setts = {0,0}, oldtp = {0,0}, ts = {0,0};
int ret;
int passflag = 0;
/* get clock resolution */
ret = clock_getres(clk, &res);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(res.tv_sec, CLOCK_RES_SEC, res.tv_sec);
ICUNIT_ASSERT_EQUAL(res.tv_nsec, CLOCK_RES_NSEC, res.tv_nsec);
/* get clock realtime */
ret = clock_gettime(clk, &oldtp);
printf("the clock current time: %lld second, %ld nanosecond\n", oldtp.tv_sec, oldtp.tv_nsec);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
/* set clock realtime */
setts.tv_sec = oldtp.tv_sec + 1;
setts.tv_nsec = oldtp.tv_nsec;
printf("the clock setting time: %lld second, %ld nanosecond\n", setts.tv_sec, setts.tv_nsec);
ret = clock_settime(CLOCK_REALTIME, &setts);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = clock_gettime(clk, &ts);
printf("obtaining the current time after setting: %lld second, %ld nanosecond\n", ts.tv_sec, ts.tv_nsec);
passflag = (ts.tv_sec >= setts.tv_sec) && (ts.tv_sec <= setts.tv_sec + 1); // 1, means obtaining time's errno is 1 second.
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(passflag, true, passflag);
return 0;
}
void ClockTestSmoke(void)
{
TEST_ADD_CASE(__FUNCTION__, ClockSmokeTest, TEST_POSIX, TEST_TIMES, TEST_LEVEL0, TEST_FUNCTION);
}
......@@ -43,6 +43,19 @@ public:
};
#if defined(LOSCFG_USER_TEST_SMOKE)
/* *
* @tc.name: ClockTestSmoke
* @tc.desc: function for TimeClockTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(TimeClockTest, ClockTestSmoke, TestSize.Level0)
{
ClockTestSmoke();
}
#endif
#if defined(LOSCFG_USER_TEST_FULL)
/* *
* @tc.name: ClockTest001
* @tc.desc: function for TimeClockTest
......@@ -76,7 +89,6 @@ HWTEST_F(TimeClockTest, ClockTest003, TestSize.Level0)
ClockTest003();
}
#if TEST_ON_LINUX
/* *
* @tc.name: ClockTest004
* @tc.desc: function for TimeClockTest
......@@ -88,7 +100,16 @@ HWTEST_F(TimeClockTest, ClockTest004, TestSize.Level0)
ClockTest004(); // clock_getcpuclockid not supported on HMOS currently
}
#endif
/* *
* @tc.name: ClockTest005
* @tc.desc: function for TimeClockTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(TimeClockTest, ClockTest005, TestSize.Level0)
{
ClockTest005();
}
/* *
* @tc.name: ClockTest006
......@@ -133,9 +154,7 @@ HWTEST_F(TimeClockTest, ClockTest009, TestSize.Level0)
{
ClockTest009();
}
#endif
#if defined(LOSCFG_USER_TEST_FULL)
/* *
* @tc.name: ClockTest010
* @tc.desc: function for TimeClockTest
......@@ -147,27 +166,5 @@ HWTEST_F(TimeClockTest, ClockTest010, TestSize.Level0)
ClockTest010();
}
/* *
* @tc.name: ClockTest011
* @tc.desc: test pthread_getcpuclockid:get pthread time
* @tc.type: FUNC
* @tc.require: AR000E0QAB
*/
HWTEST_F(TimeClockTest, ClockTest011, TestSize.Level0)
{
ClockTest011();
}
/* *
* @tc.name: ClockTest012
* @tc.desc: test clock_getcpuclockid:get process time
* @tc.type: FUNC
* @tc.require: AR000E0QAB
*/
HWTEST_F(TimeClockTest, ClockTest012, TestSize.Level0)
{
ClockTest012();
}
#endif
} // namespace OHOS
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册