Compare commits

..

10 Commits

Author SHA1 Message Date
openharmony_ci
1ae62ebf2e !1000 fix:mutex trace中ArchLRGet等接口改变实现方式
Merge pull request !1000 from zhangdengyu/mutexTraceFix
2023-01-10 06:44:48 +00:00
zhangdengyu
25278a02eb fix:mutex trace中ArchLRGet接口改变实现方式
方案描述:
将ArchLRGet接口的实现方式由内联函数修改为宏,
防止产品添加--no_inline等编译选项导致函数无法在调用点展开,
造成由于函数调用过程中函数栈帧的变化带来的LR寄存器中存储的值的变化。

Close #I69D9N

Signed-off-by: zhangdengyu <zhangdengyu2@huawei.com>
Change-Id: If417bc2ec9febf064c63da198faf4ac000d70c52
2023-01-10 14:28:15 +08:00
openharmony_ci
733b6e6c6c !988 fix: mktime测试用例不依赖固定时区
Merge pull request !988 from Zhaotianyu/20230104fix_mktime_test
2023-01-04 09:36:32 +00:00
arvinzzz
6562536db7 fix: mktime testcase
Eliminate the effects of different time zones

Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I22f0dc7057df642e255bec9a8b663c2b544b107e
2023-01-04 16:39:01 +08:00
openharmony_ci
ddf3dc8237 !985 fix: mktime测试用例配套修改
Merge pull request !985 from Zhaotianyu/20230103fix_mktime_test
2023-01-03 07:45:12 +00:00
arvinzzz
399e7647bb fix: mktime testcase
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I50e0252aa8611e9a269b836c552bfdf33ade8f44
2023-01-03 11:27:26 +08:00
openharmony_ci
f7af2cdf9b !983 修复codecheck告警
Merge pull request !983 from 夏不白/codecheck
2022-12-30 06:19:55 +00:00
xiacong
07091c5a75 fix:修复codecheck告警
1、修复空格、空行使用错误告警;
2、将超过10行的inline函数去除内联符号

fix #I685E3

Signed-off-by: xiacong <xiacong4@huawei.com>
2022-12-30 12:11:01 +08:00
openharmony_ci
6633aabf89 !979 fix: mktime获取的时间缺少时区信息
Merge pull request !979 from Zhaotianyu/20221228mktime_fix
2022-12-29 10:21:38 +00:00
arvinzzz
2a4282f912 fix: The tm struct obtained by mktime lacks timezone information
BREAKING CHANGE:
The tm struct obtained by mktime lacks timezone information
变更API:
time_t mktime(struct tm *tmptr)
原先mktime从入参中获取时区信息进行计算,变更后tm结构体和返回值time_t的计算使用系统g_timezone时区环境变量。

Close I67UIA

Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I766cffbff3c1a25bb33cbd245225ee117909af3a
2022-12-29 16:26:08 +08:00
6 changed files with 71 additions and 59 deletions

View File

@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
@@ -63,12 +63,13 @@ STATIC INLINE UINTPTR ArchMspGet(VOID)
return msp;
}
STATIC INLINE UINTPTR ArchLRGet(VOID)
{
UINTPTR lr;
__asm("mov %0, lr" : "=r" (lr));
return lr;
}
#define ARCH_LR_GET() \
({ \
UINTPTR lr; \
__asm("mov %0, lr" : "=r" (lr)); \
(lr); \
})
#define ArchLRGet ARCH_LR_GET
#elif defined(__CLANG_ARM) || defined(__GNUC__)
STATIC INLINE UINTPTR ArchSpGet(VOID)
{
@@ -91,12 +92,13 @@ STATIC INLINE UINTPTR ArchMspGet(VOID)
return msp;
}
STATIC INLINE UINTPTR ArchLRGet(VOID)
{
UINTPTR lr;
__asm volatile("mov %0, lr" : "=r" (lr));
return lr;
}
#define ARCH_LR_GET() \
({ \
UINTPTR lr; \
__asm volatile("mov %0, lr" : "=r" (lr)); \
(lr); \
})
#define ArchLRGet ARCH_LR_GET
#else
/* Other platforms to be improved */
#endif

View File

@@ -170,7 +170,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsCpupInit()
return LOS_OK;
}
/* The calculation time unit is changed to us to decouple the influence of
/* The calculation time unit is changed to us to decouple the influence of
* system frequency modulation on CPUP
*/
STATIC UINT64 CpupTimeUsGet(VOID)

View File

@@ -564,7 +564,6 @@ int LfsClose(struct File *file)
}
ret = lfs_file_close((lfs_t *)mp->mData, lfsHandle);
if (ret != 0) {
errno = LittlefsErrno(ret);
ret = (int)LOS_NOK;

View File

@@ -212,7 +212,7 @@ static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, siz
}
#endif
static inline int VfsPathCheck(const char *path, bool isFile)
static int VfsPathCheck(const char *path, bool isFile)
{
size_t len;
if ((path == NULL) || (path[0] == '\0')) {
@@ -561,7 +561,7 @@ int open(const char *path, int flags, ...)
#endif
int ret = VfsOpen(path, flags);
return MapToPosixRet(ret);
return MapToPosixRet(ret);
}
FUNC_ALIAS(open, _open, (const char *path, int flags, ...), int);
@@ -630,7 +630,7 @@ ssize_t read(int fd, void *buff, size_t bytes)
ret = VfsRead(fd, buff, bytes);
}
return MapToPosixRet(ret);
return MapToPosixRet(ret);
}
FUNC_ALIAS(read, _read, (int fd, void *buff, size_t bytes), ssize_t);
@@ -1093,7 +1093,7 @@ int fcntl(int fd, int cmd, ...)
va_start(ap, cmd);
if (fd < CONFIG_NFILE_DESCRIPTORS) {
filep = VfsAttachFileReady(fd);
ret = VfsVfcntl(filep, cmd, ap);
ret = VfsVfcntl(filep, cmd, ap);
VfsDetachFile(filep);
} else {
#ifndef LOSCFG_NET_LWIP_SACK

View File

@@ -664,7 +664,7 @@ 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 -= tm->__tm_gmtoff; // sub time zone to get UTC time
seconds += g_timezone;
return seconds;
}
@@ -690,7 +690,7 @@ time_t mktime(struct tm *tmptr)
}
timeInSeconds = ConvertUtc2Secs(tmptr);
/* normalize tm_wday and tm_yday */
ConvertSecs2Utc(timeInSeconds, tmptr->__tm_gmtoff, tmptr);
ConvertSecs2Utc(timeInSeconds, -g_timezone, tmptr);
return timeInSeconds;
}

View File

@@ -29,6 +29,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE
#include <sys/time.h>
#include <sys/times.h>
#include <time.h>
@@ -45,6 +46,7 @@
#define RET_OK 0
#define SECS_PER_MIN 60
#define SLEEP_ACCURACY 21000 // 20 ms, with 1ms deviation
#define ACCURACY_TEST_LOOPS 3 // loops for accuracy test, than count average value
#define MILLISECONDS_PER_SECOND 1000
@@ -125,13 +127,13 @@ static int CheckValueClose(double target, double actual, double accuracy)
return (pct <= accuracy);
}
static char *TmToStr(const struct tm *stm, char *timeStr, unsigned len)
static char *TmToStr(const struct tm *timePtr, char *timeStr, unsigned len)
{
if (stm == NULL || timeStr == NULL) {
if (timePtr == NULL || timeStr == NULL) {
return "";
}
sprintf_s(timeStr, len, "%ld/%d/%d %02d:%02d:%02d WEEK(%d)", stm->tm_year + TM_BASE_YEAR, stm->tm_mon + 1,
stm->tm_mday, stm->tm_hour, stm->tm_min, stm->tm_sec, stm->tm_wday);
sprintf_s(timeStr, len, "%ld/%d/%d %02d:%02d:%02d WEEK(%d)", timePtr->tm_year + TM_BASE_YEAR, timePtr->tm_mon + 1,
timePtr->tm_mday, timePtr->tm_hour, timePtr->tm_min, timePtr->tm_sec, timePtr->tm_wday);
return timeStr;
}
@@ -195,28 +197,28 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeGmtime001, Function | MediumTest
time_t time1 = 18880;
char timeStr[TIME_STR_LEN] = {0};
LOG("\nsizeof(time_t) = %d, sizeof(struct tm) = %d", sizeof(time_t), sizeof(struct tm));
struct tm *stm = gmtime(&time1);
TEST_ASSERT_EQUAL_STRING("1970/1/1 05:14:40 WEEK(4)", TmToStr(stm, timeStr, TIME_STR_LEN));
struct tm *timePtr = gmtime(&time1);
TEST_ASSERT_EQUAL_STRING("1970/1/1 05:14:40 WEEK(4)", TmToStr(timePtr, timeStr, TIME_STR_LEN));
time1 = LONG_MAX;
stm = gmtime(&time1);
LOG("\n LONG_MAX = %lld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("2038/1/19 03:14:07 WEEK(2)", TmToStr(stm, timeStr, TIME_STR_LEN));
timePtr = gmtime(&time1);
LOG("\n LONG_MAX = %lld, cvt result : %s", time1, TmToStr(timePtr, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("2038/1/19 03:14:07 WEEK(2)", TmToStr(timePtr, timeStr, TIME_STR_LEN));
time1 = LONG_MAX - 1;
stm = gmtime(&time1);
LOG("\n LONG_MAX - 1 = %lld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("2038/1/19 03:14:06 WEEK(2)", TmToStr(stm, timeStr, TIME_STR_LEN));
timePtr = gmtime(&time1);
LOG("\n LONG_MAX - 1 = %lld, cvt result : %s", time1, TmToStr(timePtr, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("2038/1/19 03:14:06 WEEK(2)", TmToStr(timePtr, timeStr, TIME_STR_LEN));
time1 = LONG_MIN;
stm = gmtime(&time1);
LOG("\n LONG_MIN = %lld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("1901/12/13 20:45:52 WEEK(5)", TmToStr(stm, timeStr, TIME_STR_LEN));
timePtr = gmtime(&time1);
LOG("\n LONG_MIN = %lld, cvt result : %s", time1, TmToStr(timePtr, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("1901/12/13 20:45:52 WEEK(5)", TmToStr(timePtr, timeStr, TIME_STR_LEN));
time1 = LONG_MIN + 1;
stm = gmtime(&time1);
LOG("\n LONG_MIN + 1 = %lld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("1901/12/13 20:45:53 WEEK(5)", TmToStr(stm, timeStr, TIME_STR_LEN));
timePtr = gmtime(&time1);
LOG("\n LONG_MIN + 1 = %lld, cvt result : %s", time1, TmToStr(timePtr, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("1901/12/13 20:45:53 WEEK(5)", TmToStr(timePtr, timeStr, TIME_STR_LEN));
return 0;
};
@@ -369,38 +371,47 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeLocaltimer002, Function | MediumT
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeMktime001, Function | MediumTest | Level1)
{
// default time zone east 8
struct tm timeptr = { 0 };
struct tm testTM = { 0 };
time_t testTime = 18880;
char timeStr[TIME_STR_LEN] = {0};
struct timeval tv;
struct timezone tz;
INIT_TM(timeptr, 2020, 7, 9, 18, 10, 0, 7);
time_t timeRet = mktime(&timeptr);
// get system timezone
int ret = gettimeofday(&tv, &tz);
TEST_ASSERT_EQUAL_INT(0, ret);
long sysTimezone = (long)(-tz.tz_minuteswest) * SECS_PER_MIN;
LOG("\n system timezone = %ld\n", sysTimezone);
INIT_TM(testTM, 2020, 7, 9, 18, 10, 0, 7);
time_t timeRet = mktime(&testTM);
LOG("\n 2020-7-9 18:10:00, mktime Ret = %lld", timeRet);
TEST_ASSERT_EQUAL_INT(1596996600, timeRet);
TEST_ASSERT_EQUAL_INT(sysTimezone, testTM.__tm_gmtoff);
TEST_ASSERT_EQUAL_INT(1596996600 - testTM.__tm_gmtoff, timeRet);
INIT_TM(timeptr, 1970, 0, 1, 8, 0, 0, 0);
timeRet = mktime(&timeptr);
INIT_TM(testTM, 1970, 0, 1, 8, 0, 0, 0);
timeRet = mktime(&testTM);
LOG("\n 1970-1-1 08:00:00, mktime Ret = %lld", timeRet);
TEST_ASSERT_EQUAL_INT(28800, timeRet);
TEST_ASSERT_EQUAL_INT(sysTimezone, testTM.__tm_gmtoff);
TEST_ASSERT_EQUAL_INT(28800 - testTM.__tm_gmtoff, timeRet);
struct tm *stm = localtime(&testTime);
LOG("\n testTime 18880, tm : %s", TmToStr(stm, timeStr, TIME_STR_LEN));
timeRet = mktime(stm);
struct tm *timePtr = localtime(&testTime);
LOG("\n testTime 18880, tm : %s", TmToStr(timePtr, timeStr, TIME_STR_LEN));
timeRet = mktime(timePtr);
TEST_ASSERT_EQUAL_INT(18880, timeRet);
LOG("\n input 18880, mktime Ret = %lld", timeRet);
testTime = LONG_MAX;
stm = localtime(&testTime);
LOG("\n testTime LONG_MAX, tm : %s", TmToStr(stm, timeStr, TIME_STR_LEN));
timeRet = mktime(stm);
timePtr = localtime(&testTime);
LOG("\n testTime LONG_MAX, tm : %s", TmToStr(timePtr, timeStr, TIME_STR_LEN));
timeRet = mktime(timePtr);
TEST_ASSERT_EQUAL_INT(LONG_MAX, timeRet);
LOG("\n input LONG_MAX, mktime Ret = %lld", timeRet);
testTime = 0;
stm = localtime(&testTime);
LOG("\n testTime 0, tm : %s", TmToStr(stm, timeStr, TIME_STR_LEN));
timeRet = mktime(stm);
timePtr = localtime(&testTime);
LOG("\n testTime 0, tm : %s", TmToStr(timePtr, timeStr, TIME_STR_LEN));
timeRet = mktime(timePtr);
TEST_ASSERT_EQUAL_INT(0, timeRet);
LOG("\n input 0, mktime Ret = %lld", timeRet);
return 0;
@@ -413,10 +424,10 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeMktime001, Function | MediumTest
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeMktime002, Function | MediumTest | Level1)
{
struct tm timeptr = { 0 };
struct tm testTM = { 0 };
LOG("\n sizeof(time_t) = %d", sizeof(time_t));
INIT_TM(timeptr, 1969, 7, 9, 10, 10, 0, 7);
time_t timeRet = mktime(&timeptr);
INIT_TM(testTM, 1969, 7, 9, 10, 10, 0, 7);
time_t timeRet = mktime(&testTM);
LOG("\n 1800-8-9 10:10:00, mktime Ret lld = %lld", timeRet);
#if (LOSCFG_LIBC_MUSL == 1)
TEST_ASSERT_EQUAL_INT(-1, timeRet);