提交 1cd0a188 编写于 作者: N nan-xiansen

nanjinbin@huawei.com

Signed-off-by: Nnan-xiansen <nanjinbin@huawei.com>
Change-Id: I8c44f6eb94aeb7096e6403f8f40a84d03c88c31d
上级 37c99832
......@@ -24,11 +24,6 @@
using namespace testing::ext;
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 ONE_MILLION = 1000000;
const int ONE_THOUSAND = 1000;
class UsleepParamTest : public testing::TestWithParam<int> {
};
class SleepParamTest : public testing::TestWithParam<int> {
......@@ -36,137 +31,6 @@ class SleepParamTest : public testing::TestWithParam<int> {
class SleepTest : public testing::Test {
};
static void UsleepAccuracyTest(int interVal)
{
int interval = interVal;
LOG("\ntest interval:%d", interval);
struct timespec time1 = {0}, time2 = {0};
long duration; // unit: us
double d = 0.0;
for (int i = 1; i <= ACCURACY_TEST_LOOPS; i++)
{
clock_gettime(CLOCK_MONOTONIC, &time1);
int rt = usleep(interval);
clock_gettime(CLOCK_MONOTONIC, &time2);
EXPECT_EQ(rt, 0);
duration = (time2.tv_sec * ONE_MILLION + time2.tv_nsec / ONE_THOUSAND) - (time1.tv_sec * ONE_MILLION + time1.tv_nsec / ONE_THOUSAND);
d += duration;
}
d = d / ACCURACY_TEST_LOOPS; // average
LOG("average duration: %.2f", d);
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";
}
static void *TestUsleepAccuracyThread(void *param)
{
intptr_t interval = (intptr_t)param;
UsleepAccuracyTest(interval);
return nullptr;
}
/**
* @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, TestUsleepAccuracyThread, (void *)interVal);
pthread_setschedprio(tid, 1);
pthread_join(tid, 0);
}
INSTANTIATE_TEST_CASE_P(SleepTest, UsleepParamTest,
testing::Values(100, 1000, 10 * 1000, 20 * 1000, 30 * 1000, 300 * 1000, 3000 * 1000));
/**
* @tc.number SUB_KERNEL_TIME_API_SLEEP_0100
* @tc.name sleep accuracy test
* @tc.desc [C- SOFTWARE -0200]
*/
HWTEST_P(SleepParamTest, testSleepAccuracy, Performance | SmallTest | Level1)
{
int testLoop = 3;
int interval = GetParam();
LOG("\ntest interval:%d", interval);
struct timespec time1 = {0}, time2 = {0};
double duration;
double d = 0.0;
for (int i = 1; i <= testLoop; i++)
{
clock_gettime(CLOCK_MONOTONIC, &time1);
int rt = sleep(interval);
clock_gettime(CLOCK_MONOTONIC, &time2);
EXPECT_EQ(rt, 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);
d += duration;
}
d = d / testLoop; // average
LOG("average duration: %.2f", d);
ASSERT_NEAR(d, interval, interval * 0.03) << "sleep accuracy check fail\n";
}
INSTANTIATE_TEST_CASE_P(SleepTest, SleepParamTest, testing::Values(1, 5, 30));
/**
* @tc.number SUB_KERNEL_TIME_API_NANOSLEEP_0100
* @tc.name nanosleep accuracy test
* @tc.desc [C- SOFTWARE -0200]
*/
HWTEST_F(SleepTest, testNanosleepAccuracy, Performance | SmallTest | Level2)
{
long interval = 50 * 1000 * 1000;
struct timespec req = {0, interval};
struct timespec rem = {0, 0};
struct timespec time1 = {0}, time2 = {0};
double duration;
double d = 0.0;
for (int i = 1; i <= ACCURACY_TEST_LOOPS; i++)
{
clock_gettime(CLOCK_MONOTONIC, &time1);
int rt = nanosleep(&req, &rem);
clock_gettime(CLOCK_MONOTONIC, &time2);
EXPECT_EQ(rt, 0);
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);
d += duration;
}
d = d / ACCURACY_TEST_LOOPS; // average
LOG("average duration: %.2f", d);
ASSERT_NEAR(d, interval / 1000, SLEEP_ACCURACY) << "sleep accuracy check fail\n";
}
/**
* @tc.number SUB_KERNEL_TIME_API_CLOCK_NANOSLEEP_0100
* @tc.name clock_nanosleep accuracy test
* @tc.desc [C- SOFTWARE -0200]
*/
HWTEST_F(SleepTest, testClockNanosleepAccuracy, Performance | SmallTest | Level2)
{
long interval = 25 * 1000 * 1000;
struct timespec req = {0, interval};
struct timespec rem = {0, 0};
struct timespec time1 = {0}, time2 = {0};
double duration;
double d = 0.0;
for (int i = 1; i <= ACCURACY_TEST_LOOPS; i++)
{
clock_gettime(CLOCK_MONOTONIC, &time1);
int rt = clock_nanosleep(CLOCK_REALTIME, 0, &req, &rem);
clock_gettime(CLOCK_MONOTONIC, &time2);
EXPECT_EQ(rt, 0);
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);
d += duration;
}
d = d / ACCURACY_TEST_LOOPS; // average
LOG("average duration: %.2f", d);
ASSERT_NEAR(d, interval / 1000, SLEEP_ACCURACY) << "sleep accuracy check fail\n";
}
/**
* @tc.number SUB_KERNEL_TIME_API_CLOCK_NANOSLEEP_0200
* @tc.name clock_nanosleep fail test - non-support clock_id
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册