diff --git a/osal/mpp_time.cpp b/osal/mpp_time.cpp index 8a2fc569..36cb184d 100644 --- a/osal/mpp_time.cpp +++ b/osal/mpp_time.cpp @@ -29,13 +29,13 @@ RK_S64 mpp_time() } #else -#include +#include RK_S64 mpp_time() { - struct timeval tv_date; - gettimeofday(&tv_date, NULL); - return (RK_S64)tv_date.tv_sec * 1000000 + (RK_S64)tv_date.tv_usec; + struct timespec time = {0, 0}; + clock_gettime(CLOCK_MONOTONIC, &time); + return (RK_S64)time.tv_sec * 1000000 + (RK_S64)time.tv_nsec / 1000; } #endif diff --git a/osal/test/CMakeLists.txt b/osal/test/CMakeLists.txt index c2150a97..e263ff45 100644 --- a/osal/test/CMakeLists.txt +++ b/osal/test/CMakeLists.txt @@ -28,6 +28,9 @@ add_mpp_osal_test(mpp_env) # malloc system unit test add_mpp_osal_test(mpp_mem) +# time system unit test +add_mpp_osal_test(mpp_time) + # hardware platform feature detection unit test add_mpp_osal_test(mpp_platform) diff --git a/osal/test/mpp_time_test.c b/osal/test/mpp_time_test.c new file mode 100644 index 00000000..59a941ad --- /dev/null +++ b/osal/test/mpp_time_test.c @@ -0,0 +1,42 @@ +/* + * Copyright 2015 Rockchip Electronics Co. LTD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define MODULE_TAG "mpp_time_test" + +#include "mpp_log.h" +#include "mpp_time.h" + +int main() +{ + RK_S64 time_0; + RK_S64 time_1; + + mpp_err("mpp time test start\n"); + + time_0 = mpp_time(); + + msleep(10); + + time_1 = mpp_time(); + + mpp_log("time 0 %lld us\n", time_0); + mpp_log("time 1 %lld us\n", time_1); + mpp_log("diff expected 10 ms real %.2f ms\n", (float)(time_1 - time_0) / 1000); + + mpp_err("mpp time test done\n"); + + return 0; +}