From 895de2f659d6530814b9d938c83772a7cae887ec Mon Sep 17 00:00:00 2001 From: nan-xiansen Date: Wed, 2 Jun 2021 17:30:07 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90kernel=5Flite=20subsystem=20integratio?= =?UTF-8?q?n=20test=E3=80=91:Remove=20the=20Time=20module=20performance=20?= =?UTF-8?q?use=20case=20to=20ynchronize=20Release=20branch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: nan-xiansen Change-Id: I13fbb2e1e0a77cbda050e0c845eb60260f202f20 --- kernel_lite/time_posix/src/SleepTest.cpp | 141 ++--------------------- 1 file changed, 12 insertions(+), 129 deletions(-) diff --git a/kernel_lite/time_posix/src/SleepTest.cpp b/kernel_lite/time_posix/src/SleepTest.cpp index f74f0f7eb..cb0d5095f 100755 --- a/kernel_lite/time_posix/src/SleepTest.cpp +++ b/kernel_lite/time_posix/src/SleepTest.cpp @@ -24,124 +24,12 @@ 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 - -class UsleepParamTest : public testing::TestWithParam {}; -class SleepParamTest : public testing::TestWithParam {}; -class SleepTest : public testing::Test {}; - -/** - * @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(); - 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*1000000 + time2.tv_nsec/1000) - (time1.tv_sec*1000000 + time1.tv_nsec/1000); - LOG("testloop %d, actual usleep duration: %ld us", i, duration); - 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"; -} -INSTANTIATE_TEST_CASE_P(SleepTest, UsleepParamTest, - testing::Values(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"; -} +class UsleepParamTest : public testing::TestWithParam { +}; +class SleepParamTest : public testing::TestWithParam { +}; +class SleepTest : public testing::Test { +}; /** * @tc.number SUB_KERNEL_TIME_API_CLOCK_NANOSLEEP_0200 @@ -156,17 +44,12 @@ HWTEST_P(AllClockIDTest, testClockNanosleepInvalidID, Reliability | SmallTest | struct timespec req = {0, 100}; struct timespec rem = {0}; int rt = clock_nanosleep(cid, 0, &req, &rem); - if (cid == CLOCK_REALTIME) { - ASSERT_EQ(rt, 0); - } else if (cid == CLOCK_THREAD_CPUTIME_ID) { + if (cid == CLOCK_SGI_CYCLE) { 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); - /** * @tc.number SUB_KERNEL_TIME_API_CLOCK_NANOSLEEP_0300 * @tc.name clock_nanosleep fail test - invalid parameter @@ -204,18 +87,18 @@ HWTEST_F(SleepTest, testClockNanosleepInvalidPara, Reliability | SmallTest | Lev EXPECT_EQ(rt, EINVAL); // invlid timespec - req.tv_sec = -1; + req.tv_sec = -1; req.tv_nsec = 1; LOG("check invlid timespec: tv_sec=-1 ..."); rt = clock_nanosleep(CLOCK_REALTIME, 0, &req, &rem); EXPECT_EQ(rt, EINVAL); - req.tv_sec = 1; + req.tv_sec = 1; req.tv_nsec = -1; LOG("check invlid timespec: tv_nsec=-1 ..."); rt = clock_nanosleep(CLOCK_REALTIME, 0, &req, &rem); EXPECT_EQ(rt, EINVAL); - req.tv_sec = 1; - req.tv_nsec = 1000*1000*1000 + 1; + req.tv_sec = 1; + req.tv_nsec = 1000 * 1000 * 1000 + 1; LOG("check invlid timespec: tv_nsec overflow ..."); rt = clock_nanosleep(CLOCK_REALTIME, 0, &req, &rem); EXPECT_EQ(rt, EINVAL); -- GitLab