Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Kernel Liteos M
提交
1125b1c1
K
Kernel Liteos M
项目概览
OpenHarmony
/
Kernel Liteos M
9 个月 前同步成功
通知
20
Star
28
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
Kernel Liteos M
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
1125b1c1
编写于
5月 19, 2023
作者:
O
openharmony_ci
提交者:
Gitee
5月 19, 2023
浏览文件
操作
浏览文件
下载
差异文件
!1065 【挑单3.2Release】内核time模块RTC与settimeofday接口逻辑修复
Merge pull request !1065 from zhangdengyu/RTC_3.2Release_0516
上级
7bae14ff
9603f02f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
82 addition
and
18 deletion
+82
-18
kal/posix/src/time.c
kal/posix/src/time.c
+45
-18
testsuites/unittest/posix/src/time/time_func_test_01.c
testsuites/unittest/posix/src/time/time_func_test_01.c
+37
-0
未找到文件。
kal/posix/src/time.c
浏览文件 @
1125b1c1
...
...
@@ -617,11 +617,22 @@ struct tm *gmtime(const time_t *timer)
struct
tm
*
localtime_r
(
const
time_t
*
timep
,
struct
tm
*
result
)
{
INT32
ret
;
if
((
timep
==
NULL
)
||
(
result
==
NULL
))
{
errno
=
EFAULT
;
return
NULL
;
}
if
(
!
ConvertSecs2Utc
(
*
timep
,
-
g_timezone
,
result
))
{
if
(
g_rtcTimeFunc
.
RtcGetTimezoneHook
!=
NULL
)
{
INT32
tempTimezone
=
0
;
g_rtcTimeFunc
.
RtcGetTimezoneHook
(
&
tempTimezone
);
ret
=
ConvertSecs2Utc
(
*
timep
,
-
tempTimezone
,
result
);
}
else
{
ret
=
ConvertSecs2Utc
(
*
timep
,
-
g_timezone
,
result
);
}
if
(
!
ret
)
{
errno
=
EINVAL
;
return
NULL
;
}
...
...
@@ -664,7 +675,14 @@ static time_t ConvertUtc2Secs(struct tm *tm)
seconds
+=
(
tm
->
tm_mday
-
1
)
*
SECS_PER_DAY
;
seconds
+=
tm
->
tm_hour
*
SECS_PER_HOUR
+
tm
->
tm_min
*
SECS_PER_MIN
+
tm
->
tm_sec
;
seconds
+=
g_timezone
;
if
(
g_rtcTimeFunc
.
RtcGetTimezoneHook
!=
NULL
)
{
INT32
tempTimezone
=
0
;
g_rtcTimeFunc
.
RtcGetTimezoneHook
(
&
tempTimezone
);
seconds
+=
tempTimezone
;
}
else
{
seconds
+=
g_timezone
;
}
return
seconds
;
}
...
...
@@ -690,7 +708,14 @@ time_t mktime(struct tm *tmptr)
}
timeInSeconds
=
ConvertUtc2Secs
(
tmptr
);
/* normalize tm_wday and tm_yday */
ConvertSecs2Utc
(
timeInSeconds
,
-
g_timezone
,
tmptr
);
if
(
g_rtcTimeFunc
.
RtcGetTimezoneHook
!=
NULL
)
{
INT32
tempTimezone
=
0
;
g_rtcTimeFunc
.
RtcGetTimezoneHook
(
&
tempTimezone
);
ConvertSecs2Utc
(
timeInSeconds
,
-
tempTimezone
,
tmptr
);
}
else
{
ConvertSecs2Utc
(
timeInSeconds
,
-
g_timezone
,
tmptr
);
}
return
timeInSeconds
;
}
...
...
@@ -722,7 +747,7 @@ int gettimeofday(struct timeval *tv, void *ptz)
tv
->
tv_usec
=
ts
.
tv_nsec
/
OS_SYS_NS_PER_US
;
}
}
if
(
tz
!=
NULL
)
{
INT32
timeZone
=
0
;
if
(
g_rtcTimeFunc
.
RtcGetTimezoneHook
!=
NULL
)
{
...
...
@@ -742,12 +767,12 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz)
{
struct
timespec
ts
;
if
(
tv
==
NULL
)
{
if
(
(
tv
==
NULL
)
&&
(
tz
==
NULL
)
)
{
errno
=
EFAULT
;
return
-
1
;
}
if
(
tv
->
tv_usec
>=
OS_SYS_US_PER_SECOND
)
{
if
(
(
tv
!=
NULL
)
&&
(
tv
->
tv_usec
>=
OS_SYS_US_PER_SECOND
)
)
{
errno
=
EINVAL
;
return
-
1
;
}
...
...
@@ -766,18 +791,20 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz)
}
}
if
(
g_rtcTimeFunc
.
RtcSetTimeHook
!=
NULL
)
{
UINT64
usec
;
g_rtcTimeBase
=
tv
->
tv_sec
*
OS_SYS_MS_PER_SECOND
+
tv
->
tv_usec
/
OS_SYS_MS_PER_SECOND
;
usec
=
tv
->
tv_sec
*
OS_SYS_US_PER_SECOND
+
tv
->
tv_usec
;
if
(
-
1
==
g_rtcTimeFunc
.
RtcSetTimeHook
(
g_rtcTimeBase
,
&
usec
))
{
return
-
1
;
}
}
else
{
ts
.
tv_sec
=
tv
->
tv_sec
;
ts
.
tv_nsec
=
tv
->
tv_usec
*
OS_SYS_NS_PER_US
;
if
(
-
1
==
clock_settime
(
CLOCK_REALTIME
,
&
ts
))
{
return
-
1
;
if
(
tv
!=
NULL
)
{
if
(
g_rtcTimeFunc
.
RtcSetTimeHook
!=
NULL
)
{
UINT64
usec
;
g_rtcTimeBase
=
tv
->
tv_sec
*
OS_SYS_MS_PER_SECOND
+
tv
->
tv_usec
/
OS_SYS_MS_PER_SECOND
;
usec
=
tv
->
tv_sec
*
OS_SYS_US_PER_SECOND
+
tv
->
tv_usec
;
if
(
g_rtcTimeFunc
.
RtcSetTimeHook
(
g_rtcTimeBase
,
&
usec
)
<
0
)
{
return
-
1
;
}
}
else
{
ts
.
tv_sec
=
tv
->
tv_sec
;
ts
.
tv_nsec
=
tv
->
tv_usec
*
OS_SYS_NS_PER_US
;
if
(
clock_settime
(
CLOCK_REALTIME
,
&
ts
)
<
0
)
{
return
-
1
;
}
}
}
...
...
testsuites/unittest/posix/src/time/time_func_test_01.c
浏览文件 @
1125b1c1
...
...
@@ -288,6 +288,42 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeLocaltime002, Function | MediumTe
return
0
;
}
/* *
* @tc.number SUB_KERNEL_TIME_LOCALTIME_003
* @tc.name test settimeofday api
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE
(
PosixTimeFuncTestSuite
,
testTimeLocaltime003
,
Function
|
MediumTest
|
Level1
)
{
char
cTime
[
32
];
/* 32, no special meaning */
time_t
tStart
;
time_t
tEnd
;
struct
timezone
tz
;
struct
timeval
timeSet
=
{
.
tv_sec
=
86399
,
/* 86399, no special meaning */
.
tv_usec
=
0
};
int
ret
=
gettimeofday
(
NULL
,
&
tz
);
ICUNIT_ASSERT_EQUAL
(
ret
,
0
,
ret
);
ret
=
settimeofday
(
&
timeSet
,
&
tz
);
time
(
&
tStart
);
sleep
(
2
);
/* 2, no special meaning */
time
(
&
tEnd
);
ICUNIT_ASSERT_EQUAL
(
ret
,
0
,
ret
);
struct
tm
*
tmStart
=
localtime
(
&
tStart
);
strftime
(
cTime
,
sizeof
(
cTime
),
"%H:%M:%S"
,
tmStart
);
ICUNIT_ASSERT_STRING_EQUAL
(
cTime
,
"07:59:59"
,
0
);
LOG
(
"
\n
time_t=%lld, first time:%s"
,
tStart
,
cTime
);
struct
tm
*
tmEnd
=
localtime
(
&
tEnd
);
strftime
(
cTime
,
sizeof
(
cTime
),
"%H:%M:%S"
,
tmEnd
);
ICUNIT_ASSERT_STRING_EQUAL
(
cTime
,
"08:00:01"
,
0
);
LOG
(
"
\n
time_t=%lld, first time:%s"
,
tEnd
,
cTime
);
return
0
;
}
/* *
* @tc.number SUB_KERNEL_TIME_LOCALTIMER_001
* @tc.name localtime_r api base test
...
...
@@ -579,6 +615,7 @@ void PosixTimeFuncTest(void)
#if (LOSCFG_LIBC_MUSL == 1)
RUN_ONE_TESTCASE
(
testTimeLocaltime001
);
RUN_ONE_TESTCASE
(
testTimeLocaltime002
);
RUN_ONE_TESTCASE
(
testTimeLocaltime003
);
RUN_ONE_TESTCASE
(
testTimeLocaltimer001
);
RUN_ONE_TESTCASE
(
testTimeLocaltimer002
);
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录