Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
f4e7f1ef
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
f4e7f1ef
编写于
6月 02, 2021
作者:
O
openharmony_ci
提交者:
Gitee
6月 02, 2021
浏览文件
操作
浏览文件
下载
差异文件
!232 【轻鸿蒙内核子系统集成测试】time模块修复不稳定用例:SleepTest.cpp#testUsleepAccuracy/testClockNanosleepInvalidID
Merge pull request !232 from 南先森/kernel_lite_20210602_02
上级
7c088f70
52af560d
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
57 addition
and
36 deletion
+57
-36
kernel_lite/time_posix/src/SleepTest.cpp
kernel_lite/time_posix/src/SleepTest.cpp
+57
-36
未找到文件。
kernel_lite/time_posix/src/SleepTest.cpp
浏览文件 @
f4e7f1ef
...
@@ -27,29 +27,31 @@ using namespace testing::ext;
...
@@ -27,29 +27,31 @@ using namespace testing::ext;
const
int
SLEEP_ACCURACY
=
21
*
1000
;
// 20 ms, with 1ms deviation
const
int
SLEEP_ACCURACY
=
21
*
1000
;
// 20 ms, with 1ms deviation
const
int
ACCURACY_TEST_LOOPS
=
5
;
// loops for accuracy test, than count average value
const
int
ACCURACY_TEST_LOOPS
=
5
;
// loops for accuracy test, than count average value
class
UsleepParamTest
:
public
testing
::
TestWithParam
<
int
>
{};
class
UsleepParamTest
:
public
testing
::
TestWithParam
<
int
>
class
SleepParamTest
:
public
testing
::
TestWithParam
<
int
>
{};
{
class
SleepTest
:
public
testing
::
Test
{};
};
class
SleepParamTest
:
public
testing
::
TestWithParam
<
int
>
{
};
class
SleepTest
:
public
testing
::
Test
{
};
/**
static
void
usleepAccuracyTest
(
int
interVal
)
* @tc.number SUB_KERNEL_TIME_API_USLEEP_0100
* @tc.name usleep accuracy test
* @tc.desc [C- SOFTWARE -0200]
*/
HWTEST_P
(
UsleepParamTest
,
testUsleepAccuracy
,
Performance
|
SmallTest
|
Level1
)
{
{
int
interval
=
GetParam
()
;
int
interval
=
interVal
;
LOG
(
"
\n
test interval:%d"
,
interval
);
LOG
(
"
\n
test interval:%d"
,
interval
);
struct
timespec
time1
=
{
0
},
time2
=
{
0
};
struct
timespec
time1
=
{
0
},
time2
=
{
0
};
long
duration
;
// unit: us
long
duration
;
// unit: us
double
d
=
0.0
;
double
d
=
0.0
;
for
(
int
i
=
1
;
i
<=
ACCURACY_TEST_LOOPS
;
i
++
)
{
for
(
int
i
=
1
;
i
<=
ACCURACY_TEST_LOOPS
;
i
++
)
{
clock_gettime
(
CLOCK_MONOTONIC
,
&
time1
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
time1
);
int
rt
=
usleep
(
interval
);
int
rt
=
usleep
(
interval
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
time2
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
time2
);
EXPECT_EQ
(
rt
,
0
);
EXPECT_EQ
(
rt
,
0
);
duration
=
(
time2
.
tv_sec
*
1000000
+
time2
.
tv_nsec
/
1000
)
-
(
time1
.
tv_sec
*
1000000
+
time1
.
tv_nsec
/
1000
)
;
//duration = (time2.tv_sec - time1.tv_sec)*1000000 + (time2.tv_nsec - time1.tv_nsec)/1000
;
LOG
(
"testloop %d, actual usleep duration: %ld us"
,
i
,
duration
);
duration
=
(
time2
.
tv_sec
*
1000000
+
time2
.
tv_nsec
/
1000
)
-
(
time1
.
tv_sec
*
1000000
+
time1
.
tv_nsec
/
1000
);
d
+=
duration
;
d
+=
duration
;
}
}
d
=
d
/
ACCURACY_TEST_LOOPS
;
// average
d
=
d
/
ACCURACY_TEST_LOOPS
;
// average
...
@@ -57,8 +59,29 @@ HWTEST_P(UsleepParamTest, testUsleepAccuracy, Performance | SmallTest | Level1)
...
@@ -57,8 +59,29 @@ HWTEST_P(UsleepParamTest, testUsleepAccuracy, Performance | SmallTest | Level1)
EXPECT_GE
(
d
,
interval
)
<<
"actual sleep time shoud greater or equal to the input-parameter
\n
"
;
EXPECT_GE
(
d
,
interval
)
<<
"actual sleep time shoud greater or equal to the input-parameter
\n
"
;
ASSERT_NEAR
(
d
,
interval
,
SLEEP_ACCURACY
)
<<
"usleep accuracy check fail
\n
"
;
ASSERT_NEAR
(
d
,
interval
,
SLEEP_ACCURACY
)
<<
"usleep accuracy check fail
\n
"
;
}
}
static
void
*
ttestUsleepAccuracyThread
(
void
*
param
)
{
int
interval
=
(
int
)
param
;
usleepAccuracyTest
(
interval
);
return
0
;
}
/**
* @tc.number SUB_KERNEL_TIME_API_USLEEP_0100
* @tc.name usleep accuracy test
* @tc.desc [C- SOFTWARE -0200]
*/
HWTEST_P
(
UsleepParamTest
,
testUsleepAccuracy
,
Performance
|
SmallTest
|
Level1
)
{
int
interVal
=
GetParam
();
pthread_t
tid
;
pthread_create
(
&
tid
,
0
,
ttestUsleepAccuracyThread
,
(
void
*
)
interVal
);
pthread_setschedprio
(
tid
,
1
);
pthread_join
(
tid
,
0
);
}
INSTANTIATE_TEST_CASE_P
(
SleepTest
,
UsleepParamTest
,
INSTANTIATE_TEST_CASE_P
(
SleepTest
,
UsleepParamTest
,
testing
::
Values
(
1000
,
10
*
1000
,
20
*
1000
,
30
*
1000
,
300
*
1000
,
3000
*
1000
));
testing
::
Values
(
100
,
1000
,
10
*
1000
,
20
*
1000
,
30
*
1000
,
300
*
1000
,
3000
*
1000
));
/**
/**
* @tc.number SUB_KERNEL_TIME_API_SLEEP_0100
* @tc.number SUB_KERNEL_TIME_API_SLEEP_0100
...
@@ -73,18 +96,19 @@ HWTEST_P(SleepParamTest, testSleepAccuracy, Performance | SmallTest | Level1)
...
@@ -73,18 +96,19 @@ HWTEST_P(SleepParamTest, testSleepAccuracy, Performance | SmallTest | Level1)
struct
timespec
time1
=
{
0
},
time2
=
{
0
};
struct
timespec
time1
=
{
0
},
time2
=
{
0
};
double
duration
;
double
duration
;
double
d
=
0.0
;
double
d
=
0.0
;
for
(
int
i
=
1
;
i
<=
testLoop
;
i
++
)
{
for
(
int
i
=
1
;
i
<=
testLoop
;
i
++
)
{
clock_gettime
(
CLOCK_MONOTONIC
,
&
time1
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
time1
);
int
rt
=
sleep
(
interval
);
int
rt
=
sleep
(
interval
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
time2
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
time2
);
EXPECT_EQ
(
rt
,
0
);
EXPECT_EQ
(
rt
,
0
);
duration
=
(
time2
.
tv_sec
-
time1
.
tv_sec
)
+
(
time2
.
tv_nsec
-
time1
.
tv_nsec
)
/
1000000000.0
;
duration
=
(
time2
.
tv_sec
-
time1
.
tv_sec
)
+
(
time2
.
tv_nsec
-
time1
.
tv_nsec
)
/
1000000000.0
;
LOG
(
"testloop %d, actual sleep duration: %.1f s"
,
i
,
duration
);
LOG
(
"testloop %d, actual sleep duration: %.1f s"
,
i
,
duration
);
d
+=
duration
;
d
+=
duration
;
}
}
d
=
d
/
testLoop
;
// average
d
=
d
/
testLoop
;
// average
LOG
(
"average duration: %.2f"
,
d
);
LOG
(
"average duration: %.2f"
,
d
);
ASSERT_NEAR
(
d
,
interval
,
interval
*
0.03
)
<<
"sleep accuracy check fail
\n
"
;
ASSERT_NEAR
(
d
,
interval
,
interval
*
0.03
)
<<
"sleep accuracy check fail
\n
"
;
}
}
INSTANTIATE_TEST_CASE_P
(
SleepTest
,
SleepParamTest
,
testing
::
Values
(
1
,
5
,
30
));
INSTANTIATE_TEST_CASE_P
(
SleepTest
,
SleepParamTest
,
testing
::
Values
(
1
,
5
,
30
));
...
@@ -95,25 +119,26 @@ INSTANTIATE_TEST_CASE_P(SleepTest, SleepParamTest, testing::Values(1, 5, 30));
...
@@ -95,25 +119,26 @@ INSTANTIATE_TEST_CASE_P(SleepTest, SleepParamTest, testing::Values(1, 5, 30));
*/
*/
HWTEST_F
(
SleepTest
,
testNanosleepAccuracy
,
Performance
|
SmallTest
|
Level2
)
HWTEST_F
(
SleepTest
,
testNanosleepAccuracy
,
Performance
|
SmallTest
|
Level2
)
{
{
long
interval
=
50
*
1000
*
1000
;
long
interval
=
50
*
1000
*
1000
;
struct
timespec
req
=
{
0
,
interval
};
struct
timespec
req
=
{
0
,
interval
};
struct
timespec
rem
=
{
0
,
0
};
struct
timespec
rem
=
{
0
,
0
};
struct
timespec
time1
=
{
0
},
time2
=
{
0
};
struct
timespec
time1
=
{
0
},
time2
=
{
0
};
double
duration
;
double
duration
;
double
d
=
0.0
;
double
d
=
0.0
;
for
(
int
i
=
1
;
i
<=
ACCURACY_TEST_LOOPS
;
i
++
)
{
for
(
int
i
=
1
;
i
<=
ACCURACY_TEST_LOOPS
;
i
++
)
{
clock_gettime
(
CLOCK_MONOTONIC
,
&
time1
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
time1
);
int
rt
=
nanosleep
(
&
req
,
&
rem
);
int
rt
=
nanosleep
(
&
req
,
&
rem
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
time2
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
time2
);
EXPECT_EQ
(
rt
,
0
);
EXPECT_EQ
(
rt
,
0
);
duration
=
(
time2
.
tv_sec
*
1000000
+
time2
.
tv_nsec
/
1000
)
-
(
time1
.
tv_sec
*
1000000
+
time1
.
tv_nsec
/
1000
);
duration
=
(
time2
.
tv_sec
*
1000000
+
time2
.
tv_nsec
/
1000
)
-
(
time1
.
tv_sec
*
1000000
+
time1
.
tv_nsec
/
1000
);
LOG
(
"testloop %d, actual sleep duration: %.1f s"
,
i
,
duration
);
LOG
(
"testloop %d, actual sleep duration: %.1f s"
,
i
,
duration
);
d
+=
duration
;
d
+=
duration
;
}
}
d
=
d
/
ACCURACY_TEST_LOOPS
;
// average
d
=
d
/
ACCURACY_TEST_LOOPS
;
// average
LOG
(
"average duration: %.2f"
,
d
);
LOG
(
"average duration: %.2f"
,
d
);
ASSERT_NEAR
(
d
,
interval
/
1000
,
SLEEP_ACCURACY
)
<<
"sleep accuracy check fail
\n
"
;
ASSERT_NEAR
(
d
,
interval
/
1000
,
SLEEP_ACCURACY
)
<<
"sleep accuracy check fail
\n
"
;
}
}
/**
/**
...
@@ -123,24 +148,25 @@ HWTEST_F(SleepTest, testNanosleepAccuracy, Performance | SmallTest | Level2)
...
@@ -123,24 +148,25 @@ HWTEST_F(SleepTest, testNanosleepAccuracy, Performance | SmallTest | Level2)
*/
*/
HWTEST_F
(
SleepTest
,
testClockNanosleepAccuracy
,
Performance
|
SmallTest
|
Level2
)
HWTEST_F
(
SleepTest
,
testClockNanosleepAccuracy
,
Performance
|
SmallTest
|
Level2
)
{
{
long
interval
=
25
*
1000
*
1000
;
long
interval
=
25
*
1000
*
1000
;
struct
timespec
req
=
{
0
,
interval
};
struct
timespec
req
=
{
0
,
interval
};
struct
timespec
rem
=
{
0
,
0
};
struct
timespec
rem
=
{
0
,
0
};
struct
timespec
time1
=
{
0
},
time2
=
{
0
};
struct
timespec
time1
=
{
0
},
time2
=
{
0
};
double
duration
;
double
duration
;
double
d
=
0.0
;
double
d
=
0.0
;
for
(
int
i
=
1
;
i
<=
ACCURACY_TEST_LOOPS
;
i
++
)
{
for
(
int
i
=
1
;
i
<=
ACCURACY_TEST_LOOPS
;
i
++
)
{
clock_gettime
(
CLOCK_MONOTONIC
,
&
time1
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
time1
);
int
rt
=
clock_nanosleep
(
CLOCK_REALTIME
,
0
,
&
req
,
&
rem
);
int
rt
=
clock_nanosleep
(
CLOCK_REALTIME
,
0
,
&
req
,
&
rem
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
time2
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
time2
);
EXPECT_EQ
(
rt
,
0
);
EXPECT_EQ
(
rt
,
0
);
duration
=
(
time2
.
tv_sec
*
1000000
+
time2
.
tv_nsec
/
1000
)
-
(
time1
.
tv_sec
*
1000000
+
time1
.
tv_nsec
/
1000
);
duration
=
(
time2
.
tv_sec
*
1000000
+
time2
.
tv_nsec
/
1000
)
-
(
time1
.
tv_sec
*
1000000
+
time1
.
tv_nsec
/
1000
);
LOG
(
"testloop %d, actual sleep duration: %.1f s"
,
i
,
duration
);
LOG
(
"testloop %d, actual sleep duration: %.1f s"
,
i
,
duration
);
d
+=
duration
;
d
+=
duration
;
}
}
d
=
d
/
ACCURACY_TEST_LOOPS
;
// average
d
=
d
/
ACCURACY_TEST_LOOPS
;
// average
LOG
(
"average duration: %.2f"
,
d
);
LOG
(
"average duration: %.2f"
,
d
);
ASSERT_NEAR
(
d
,
interval
/
1000
,
SLEEP_ACCURACY
)
<<
"sleep accuracy check fail
\n
"
;
ASSERT_NEAR
(
d
,
interval
/
1000
,
SLEEP_ACCURACY
)
<<
"sleep accuracy check fail
\n
"
;
}
}
/**
/**
...
@@ -156,17 +182,12 @@ HWTEST_P(AllClockIDTest, testClockNanosleepInvalidID, Reliability | SmallTest |
...
@@ -156,17 +182,12 @@ HWTEST_P(AllClockIDTest, testClockNanosleepInvalidID, Reliability | SmallTest |
struct
timespec
req
=
{
0
,
100
};
struct
timespec
req
=
{
0
,
100
};
struct
timespec
rem
=
{
0
};
struct
timespec
rem
=
{
0
};
int
rt
=
clock_nanosleep
(
cid
,
0
,
&
req
,
&
rem
);
int
rt
=
clock_nanosleep
(
cid
,
0
,
&
req
,
&
rem
);
if
(
cid
==
CLOCK_REALTIME
)
{
if
(
cid
==
CLOCK_SGI_CYCLE
)
{
ASSERT_EQ
(
rt
,
0
);
}
else
if
(
cid
==
CLOCK_THREAD_CPUTIME_ID
)
{
ASSERT_EQ
(
rt
,
EINVAL
)
<<
cname
<<
" should not support.
\n
"
;
ASSERT_EQ
(
rt
,
EINVAL
)
<<
cname
<<
" should not support.
\n
"
;
}
else
{
ASSERT_EQ
(
rt
,
ENOTSUP
)
<<
cname
<<
" should not support.
\n
"
;
}
}
}
}
INSTANTIATE_TEST_CASE_P
(
SleepTest
,
AllClockIDTest
,
ALL_CLOCK_IDS
);
INSTANTIATE_TEST_CASE_P
(
SleepTest
,
AllClockIDTest
,
ALL_CLOCK_IDS
);
/**
/**
* @tc.number SUB_KERNEL_TIME_API_CLOCK_NANOSLEEP_0300
* @tc.number SUB_KERNEL_TIME_API_CLOCK_NANOSLEEP_0300
* @tc.name clock_nanosleep fail test - invalid parameter
* @tc.name clock_nanosleep fail test - invalid parameter
...
@@ -215,7 +236,7 @@ HWTEST_F(SleepTest, testClockNanosleepInvalidPara, Reliability | SmallTest | Lev
...
@@ -215,7 +236,7 @@ HWTEST_F(SleepTest, testClockNanosleepInvalidPara, Reliability | SmallTest | Lev
rt
=
clock_nanosleep
(
CLOCK_REALTIME
,
0
,
&
req
,
&
rem
);
rt
=
clock_nanosleep
(
CLOCK_REALTIME
,
0
,
&
req
,
&
rem
);
EXPECT_EQ
(
rt
,
EINVAL
);
EXPECT_EQ
(
rt
,
EINVAL
);
req
.
tv_sec
=
1
;
req
.
tv_sec
=
1
;
req
.
tv_nsec
=
1000
*
1000
*
1000
+
1
;
req
.
tv_nsec
=
1000
*
1000
*
1000
+
1
;
LOG
(
"check invlid timespec: tv_nsec overflow ..."
);
LOG
(
"check invlid timespec: tv_nsec overflow ..."
);
rt
=
clock_nanosleep
(
CLOCK_REALTIME
,
0
,
&
req
,
&
rem
);
rt
=
clock_nanosleep
(
CLOCK_REALTIME
,
0
,
&
req
,
&
rem
);
EXPECT_EQ
(
rt
,
EINVAL
);
EXPECT_EQ
(
rt
,
EINVAL
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录