Compare commits

...

18 Commits

Author SHA1 Message Date
openharmony_ci
c6d021bede !1016 refactor: 不同C库malloc归一
Merge pull request !1016 from Zhaotianyu/20230117libc_malloc
2023-01-18 09:56:58 +00:00
arvinzzz
d7f3aef326 refactor: 不同C库的malloc适配归一
1. 不同C库的malloc实现归一化,由原先//kal/libc/musl、//kal/libc/newlib、
   //../../third_party/musl/porting/liteos_m_iccarm/kernel 各自实现,
   统一至//kal/posix/src/malloc.c实现,并实现对三种C库的兼容

2. Kconfig归一化的配套调整,删除Top->"Compat"->"Choose libc implementation"下
   malloc API的开关控制,统一归入"Top"->"Compat"->"Enable POSIX API"下
   "Enable POSIX MALLOC API"进行能力开关控制

BREAKING CHANGE:
Kconfig变更:
删除:
LOSCFG_LIBC_ICCARM_MALLOC
LOSCFG_LIBC_NEWLIB_MALLOC
新增:
LOSCFG_POSIX_MALLOC_API

close: I6AGOW

Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I584e337cdb36184cf40c36c4f7c73ab780c31a42
2023-01-18 11:22:01 +08:00
openharmony_ci
59fbe91d8b !1009 Fix : OsLs 内存泄漏问题
Merge pull request !1009 from yinjiaming/fix
2023-01-13 08:54:49 +00:00
openharmony_ci
c7088f4d0f !1010 告警清理
Merge pull request !1010 from 乔克叔叔/release
2023-01-13 05:42:29 +00:00
liuwenxin
705bfbdc76 fix:release告警清理
release分支告警清理

close:#I6AD15

Signed-off-by: liuwenxin <liuwenxin11@huawei.com>
2023-01-13 11:34:52 +08:00
yinjiaming
9a4e9677bd fix:修复OsLs函数内存泄漏问题
当d = NULL时,path没有释放,现释放path所指向的内存

close #I6A07U

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: Iee9fd8d2171c6fdcf353a48e7af385bbd1660520
2023-01-12 15:30:19 +08:00
openharmony_ci
6134d4bd22 !989 修复-Werror编译选项产生的告警
Merge pull request !989 from 乔克叔叔/lwx
2023-01-11 07:55:48 +00:00
openharmony_ci
c119b7e9e2 !1006 Fix : statfs函数内部判断错误
Merge pull request !1006 from yinjiaming/fix
2023-01-11 07:37:51 +00:00
openharmony_ci
dbf0498bab !1008 fix: 非gcc形态下FUNC_ALIAS编译错误
Merge pull request !1008 from Zhaotianyu/20230111symbol_fix
2023-01-11 06:49:43 +00:00
arvinzzz
68b142cf78 fix: 修复非gcc形态FUNC_ALIAS编译错误
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I7f199366d8173d9fc504f89b26329ea5f7d1eb9e
2023-01-11 10:45:18 +08:00
openharmony_ci
22b7eb87ca !998 fix: 不同C库下gettimeofday特性规格统一
Merge pull request !998 from Zhaotianyu/20230107gettimeofday
2023-01-11 00:46:21 +00:00
arvinzzz
ed50f7e373 fix: 不同libc下gettimeofday特性规格统一
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: Iaaf1fed24101f43c636737294dbe870d2f467b0a
2023-01-10 20:36:34 +08:00
yinjiaming
2f2a0b7a75 fix:修复statfs函数内部判断错误
修复函数调用的是statfs却用stat!=NULL来判断,当文件系统是little_fs时导致死机的问题。

close #I69BXB

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: Ib9784c017f4260433c3f12e352470108ea83ec19
2023-01-10 15:49:01 +08:00
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
liuwenxin
52bc16c3db fix:修复-Werror编译选项产生的告警
清理框架定义未使用告警,宏重定义,以及变量定义未使用等告警。

Close #I68RLA

Signed-off-by: liuwenxin <liuwenxin11@huawei.com>
2023-01-10 10:26:22 +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
49 changed files with 231 additions and 476 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

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2022-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:
@@ -50,14 +50,6 @@
#include "vfs_mount.h"
#include "vfs_operations.h"
#if (LOSCFG_LIBC_NEWLIB == 1)
#define ALIAS_OF(of) __attribute__((alias(#of)))
#define FUNC_ALIAS(real_func, new_alias, args_list, return_type) \
return_type new_alias args_list ALIAS_OF(real_func)
#else
#define FUNC_ALIAS(real_func, new_alias, args_list, return_type)
#endif
#ifdef LOSCFG_NET_LWIP_SACK
#include "lwipopts.h"
#include "lwip/sockets.h"
@@ -563,7 +555,9 @@ int open(const char *path, int flags, ...)
int ret = VfsOpen(path, flags);
return MapToPosixRet(ret);
}
#if (LOSCFG_LIBC_NEWLIB == 1)
FUNC_ALIAS(open, _open, (const char *path, int flags, ...), int);
#endif
int close(int fd)
{
@@ -589,7 +583,9 @@ int close(int fd)
}
return MapToPosixRet(ret);
}
#if (LOSCFG_LIBC_NEWLIB == 1)
FUNC_ALIAS(close, _close, (int fd), int);
#endif
ssize_t read(int fd, void *buff, size_t bytes)
{
@@ -632,7 +628,9 @@ ssize_t read(int fd, void *buff, size_t bytes)
return MapToPosixRet(ret);
}
#if (LOSCFG_LIBC_NEWLIB == 1)
FUNC_ALIAS(read, _read, (int fd, void *buff, size_t bytes), ssize_t);
#endif
ssize_t write(int fd, const void *buff, size_t bytes)
{
@@ -662,7 +660,9 @@ ssize_t write(int fd, const void *buff, size_t bytes)
return MapToPosixRet(ret);
}
#if (LOSCFG_LIBC_NEWLIB == 1)
FUNC_ALIAS(write, _write, (int fd, const void *buff, size_t bytes), ssize_t);
#endif
off_t lseek(int fd, off_t off, int whence)
{
@@ -683,7 +683,9 @@ off_t lseek(int fd, off_t off, int whence)
VfsDetachFile(file);
return ret;
}
#if (LOSCFG_LIBC_NEWLIB == 1)
FUNC_ALIAS(lseek, _lseek, (int fd, off_t off, int whence), off_t);
#endif
int stat(const char *path, struct stat *stat)
{
@@ -721,7 +723,9 @@ int stat(const char *path, struct stat *stat)
LOS_FsUnlock();
return MapToPosixRet(ret);
}
#if (LOSCFG_LIBC_NEWLIB == 1)
FUNC_ALIAS(stat, _stat, (const char *path, struct stat *stat), int);
#endif
int statfs(const char *path, struct statfs *buf)
{
@@ -750,7 +754,7 @@ int statfs(const char *path, struct statfs *buf)
return MapToPosixRet(ret);
}
if (mp->mFs->fsFops->stat != NULL) {
if (mp->mFs->fsMops->statfs != NULL) {
ret = mp->mFs->fsMops->statfs(pathInMp, buf);
} else {
VFS_ERRNO_SET(ENOTSUP);
@@ -788,7 +792,9 @@ int unlink(const char *path)
LOS_FsUnlock();
return MapToPosixRet(ret);
}
#if (LOSCFG_LIBC_NEWLIB == 1)
FUNC_ALIAS(unlink, _unlink, (const char *path), int);
#endif
int rename(const char *oldpath, const char *newpath)
{
@@ -1082,7 +1088,9 @@ int fstat(int fd, struct stat *buf)
VfsDetachFile(filep);
return ret;
}
#if (LOSCFG_LIBC_NEWLIB == 1)
FUNC_ALIAS(fstat, _fstat, (int fd, struct stat *buf), int);
#endif
int fcntl(int fd, int cmd, ...)
{

View File

@@ -250,7 +250,7 @@ STATIC int VfsRemount(const char *source, const char *target,
STATIC int VfsMountPathCheck(const char *target)
{
/* target must begin with '/', for example /system, /data, etc. */
if ((target == NULL) || (target[0] != '/') || (target[0] == '\0')) {
if ((target == NULL) || (target[0] != '/')) {
errno = EINVAL;
return (int)LOS_NOK;
}

View File

@@ -181,6 +181,7 @@ VOID OsLs(const CHAR *pathname)
d = opendir(path);
if (d == NULL) {
PRINT_ERR("No such directory = %s\n", path);
free(path);
} else {
PRINTK("Directory %s:\n", path);
do {

View File

@@ -1,5 +1,5 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2022 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:
@@ -38,11 +38,9 @@ config LIBC_MUSL
config LIBC_NEWLIB
bool "newlibc"
rsource "newlib/Kconfig"
config LIBC_ICCARM
bool "iar libc"
depends on COMPILER_ICCARM
rsource "iccarm/Kconfig"
endchoice

View File

@@ -1,37 +0,0 @@
# Copyright (c) 2022-2022 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:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
if LIBC_ICCARM
config LIBC_ICCARM_MALLOC
bool "Enable POSIX malloc/free API support"
default y
help
This enables POSIX malloc/free related APIs.
endif # LIBC_ICCARM

View File

@@ -1,5 +1,5 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2022 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:
@@ -33,7 +33,6 @@ import("//third_party/musl/porting/liteos_m/kernel/musl.gni")
module_switch = defined(LOSCFG_LIBC_MUSL)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [ "malloc.c" ]
configs += [ "$LITEOSTOPDIR:warn_config" ]
deps = [ "//third_party/musl/porting/liteos_m/kernel" ]

View File

@@ -1,5 +1,5 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2022 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:
@@ -33,13 +33,11 @@ module_switch = defined(LOSCFG_LIBC_NEWLIB)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [
"porting/src/malloc.c",
"porting/src/hook_adapt.c",
"porting/src/network/htonl.c",
"porting/src/network/htons.c",
"porting/src/network/ntohl.c",
"porting/src/network/ntohs.c",
"porting/src/other_adapt.c",
"porting/src/time.c",
]
configs += [ "$LITEOSTOPDIR:warn_config" ]

View File

@@ -1,38 +0,0 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 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:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
if LIBC_NEWLIB
config LIBC_NEWLIB_MALLOC
bool "Enable POSIX malloc/free API support"
default y
help
This enables POSIX malloc/free related APIs.
endif # LIBC_NEWLIB

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2021-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:
@@ -35,6 +35,12 @@
#include <unistd.h>
#include <pthread.h>
/*
* fs adapter interface, such as _read, see component/fs
* time adapter interface, such as _gettimeofday, see posix/src/time.c
* malloc adapter interface, such as _malloc_r, see posix/src/malloc.c
*/
int _isatty(int file)
{
return (int)(file <= 2); // 2: stderr

View File

@@ -1,115 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "securec.h"
#include "los_config.h"
#include "los_memory.h"
#include <malloc.h>
#ifdef LOSCFG_LIBC_NEWLIB_MALLOC
void *zalloc(size_t size)
{
void *ptr = NULL;
if (size == 0) {
return NULL;
}
ptr = LOS_MemAlloc(OS_SYS_MEM_ADDR, size);
if (ptr != NULL) {
(void)memset_s(ptr, size, 0, size);
}
return ptr;
}
void __wrap__free_r(struct _reent *reent, void *aptr)
{
if (aptr == NULL) {
return;
}
LOS_MemFree(OS_SYS_MEM_ADDR, aptr);
}
size_t __wrap__malloc_usable_size_r(struct _reent *reent, void *aptr)
{
return 0;
}
void *__wrap__malloc_r(struct _reent *reent, size_t nbytes)
{
if (nbytes == 0) {
return NULL;
}
return LOS_MemAlloc(OS_SYS_MEM_ADDR, nbytes);
}
void *__wrap__memalign_r(struct _reent *reent, size_t align, size_t nbytes)
{
if (nbytes == 0) {
return NULL;
}
return LOS_MemAllocAlign(OS_SYS_MEM_ADDR, nbytes, align);
}
void *__wrap__realloc_r(struct _reent *reent, void *aptr, size_t nbytes)
{
if (aptr == NULL) {
return malloc(nbytes);
}
if (nbytes == 0) {
free(aptr);
return NULL;
}
return LOS_MemRealloc(OS_SYS_MEM_ADDR, aptr, nbytes);
}
void *__wrap__calloc_r(struct _reent *reent, size_t nitems, size_t size)
{
size_t real_size;
void *ptr = NULL;
if (nitems == 0 || size == 0) {
return NULL;
}
real_size = (size_t)(nitems * size);
ptr = LOS_MemAlloc(OS_SYS_MEM_ADDR, real_size);
if (ptr != NULL) {
(void)memset_s(ptr, real_size, 0, real_size);
}
return ptr;
}
#endif

View File

@@ -1,54 +0,0 @@
/*
* Copyright (c) 2021-2021 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:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "los_tick.h"
#include <time.h>
#include <sys/time.h>
#define SECS_PER_MIN 60
int _gettimeofday(struct timeval *__tp, void *__tzp)
{
struct timespec ts;
struct timezone *tz = (struct timezone *)__tzp;
if (__tp != NULL) {
if (-1 == clock_gettime(CLOCK_REALTIME, &ts)) {
return -1;
}
__tp->tv_sec = ts.tv_sec;
__tp->tv_usec = ts.tv_nsec / OS_SYS_NS_PER_US;
}
if (tz != NULL) {
tz->tz_minuteswest = _timezone / SECS_PER_MIN;
tz->tz_dsttime = 0;
}
return 0;
}

View File

@@ -1,5 +1,5 @@
# 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:
@@ -67,6 +67,10 @@ kernel_module(module_name) {
if (defined(LOSCFG_POSIX_SIGNAL_API)) {
sources += [ "src/signal.c" ]
}
if (defined(LOSCFG_POSIX_MALLOC_API)) {
sources += [ "src/malloc.c" ]
}
}
config("public") {

View File

@@ -1,5 +1,5 @@
# 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:
@@ -80,4 +80,10 @@ config POSIX_FS_API
help
Answer Y to enable LiteOS support POSIX FS API.
config POSIX_MALLOC_API
bool "Enable POSIX MALLOC API"
default y
help
Answer Y to enable LiteOS support POSIX MALLOC API.
endif # POSIX_API

View File

@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 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:
@@ -34,8 +34,15 @@
#include "los_config.h"
#include "los_memory.h"
#if (LOSCFG_LIBC_NEWLIB == 1)
void *__wrap__calloc_r(struct _reent *reent, size_t nitems, size_t size)
#else
void *calloc(size_t nitems, size_t size)
#endif
{
#if (LOSCFG_LIBC_NEWLIB == 1)
(void)reent;
#endif
size_t real_size;
void *ptr = NULL;
@@ -51,8 +58,15 @@ void *calloc(size_t nitems, size_t size)
return ptr;
}
#if (LOSCFG_LIBC_NEWLIB == 1)
void __wrap__free_r(struct _reent *reent, void *ptr)
#else
void free(void *ptr)
#endif
{
#if (LOSCFG_LIBC_NEWLIB == 1)
(void)reent;
#endif
if (ptr == NULL) {
return;
}
@@ -60,8 +74,24 @@ void free(void *ptr)
LOS_MemFree(OS_SYS_MEM_ADDR, ptr);
}
void *malloc(size_t size)
#if (LOSCFG_LIBC_NEWLIB == 1)
size_t __wrap__malloc_usable_size_r(struct _reent *reent, void *aptr)
{
(void)reent;
(void)aptr;
return 0;
}
#endif
#if (LOSCFG_LIBC_NEWLIB == 1)
void *__wrap__malloc_r(struct _reent *reent, size_t size)
#else
void *malloc(size_t size)
#endif
{
#if (LOSCFG_LIBC_NEWLIB == 1)
(void)reent;
#endif
if (size == 0) {
return NULL;
}
@@ -84,8 +114,15 @@ void *zalloc(size_t size)
return ptr;
}
#if (LOSCFG_LIBC_NEWLIB == 1)
void *__wrap__memalign_r(struct _reent *reent, size_t boundary, size_t size)
#else
void *memalign(size_t boundary, size_t size)
#endif
{
#if (LOSCFG_LIBC_NEWLIB == 1)
(void)reent;
#endif
if (size == 0) {
return NULL;
}
@@ -93,8 +130,15 @@ void *memalign(size_t boundary, size_t size)
return LOS_MemAllocAlign(OS_SYS_MEM_ADDR, size, boundary);
}
#if (LOSCFG_LIBC_NEWLIB == 1)
void *__wrap__realloc_r(struct _reent *reent, void *ptr, size_t size)
#else
void *realloc(void *ptr, size_t size)
#endif
{
#if (LOSCFG_LIBC_NEWLIB == 1)
(void)reent;
#endif
if (ptr == NULL) {
return malloc(size);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2022-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:
@@ -50,7 +50,6 @@
/* accumulative time delta from discontinuous modify */
STATIC struct timespec g_accDeltaFromSet;
#ifndef __USE_NEWLIB__
STATIC const UINT16 g_daysInMonth[2][13] = {
/* Normal years. */
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
@@ -59,20 +58,18 @@ STATIC const UINT16 g_daysInMonth[2][13] = {
};
STATIC const UINT8 g_montbl[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
#endif
#ifndef __USE_NEWLIB__
#define g_timezone timezone
#if (LOSCFG_LIBC_NEWLIB == 1)
#define TIMEZONE _timezone
#else
#define g_Timezone _timezone
#endif
#define TIMEZONE timezone
/*
* Time zone information, stored in seconds,
* negative values indicate the east of UTC,
* positive values indicate the west of UTC.
*/
long g_timezone = -8 * 60 * 60; // set default to CST(UTC+8)
long TIMEZONE = -8 * 60 * 60; // set default to CST(UTC+8)
#endif
/*
* store register rtc func
@@ -529,7 +526,6 @@ time_t time(time_t *timer)
}
}
#ifndef __USE_NEWLIB__
/*
* Compute the `struct tm' representation of T,
* offset OFFSET seconds east of UTC,
@@ -621,7 +617,7 @@ struct tm *localtime_r(const time_t *timep, struct tm *result)
errno = EFAULT;
return NULL;
}
if (!ConvertSecs2Utc(*timep, -g_timezone, result)) {
if (!ConvertSecs2Utc(*timep, -TIMEZONE, result)) {
errno = EINVAL;
return NULL;
}
@@ -664,7 +660,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 += g_timezone;
seconds += TIMEZONE;
return seconds;
}
@@ -690,7 +686,7 @@ time_t mktime(struct tm *tmptr)
}
timeInSeconds = ConvertUtc2Secs(tmptr);
/* normalize tm_wday and tm_yday */
ConvertSecs2Utc(timeInSeconds, -g_timezone, tmptr);
ConvertSecs2Utc(timeInSeconds, -TIMEZONE, tmptr);
return timeInSeconds;
}
@@ -724,18 +720,20 @@ int gettimeofday(struct timeval *tv, void *ptz)
}
if (tz != NULL) {
INT32 timeZone = 0;
if (g_rtcTimeFunc.RtcGetTimezoneHook != NULL) {
g_rtcTimeFunc.RtcGetTimezoneHook(&timeZone);
tz->tz_minuteswest = timezone / SECS_PER_MIN;
INT32 tempTimezone = 0;
g_rtcTimeFunc.RtcGetTimezoneHook(&tempTimezone);
tz->tz_minuteswest = tempTimezone / SECS_PER_MIN;
} else {
tz->tz_minuteswest = g_timezone / SECS_PER_MIN;
tz->tz_minuteswest = TIMEZONE / SECS_PER_MIN;
}
tz->tz_dsttime = 0;
}
return 0;
}
#if (LOSCFG_LIBC_NEWLIB == 1)
FUNC_ALIAS(gettimeofday, _gettimeofday, (struct timeval *tv, void *ptz), int);
#endif
int settimeofday(const struct timeval *tv, const struct timezone *tz)
@@ -755,14 +753,14 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz)
if (tz != NULL) {
if ((tz->tz_minuteswest >= TIME_ZONE_MIN) &&
(tz->tz_minuteswest <= TIME_ZONE_MAX)) {
g_timezone = tz->tz_minuteswest * SECS_PER_MIN;
TIMEZONE = tz->tz_minuteswest * SECS_PER_MIN;
} else {
errno = EINVAL;
return -1;
}
if (g_rtcTimeFunc.RtcSetTimezoneHook != NULL) {
g_rtcTimeFunc.RtcSetTimezoneHook(g_timezone);
g_rtcTimeFunc.RtcSetTimezoneHook(TIMEZONE);
}
}

View File

@@ -352,15 +352,10 @@ LITE_TEST_CASE(CmsisFuncTestSuite, TestCmsis004, Function | MediumTest | Level1)
ret = strcmp(staticBuff, strbuff);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
ret = osMessageQueueDelete(msgQueueId);
ICUNIT_ASSERT_EQUAL(ret, osOK, ret);
#endif
return LOS_OK;
EXIT:
ret = osMessageQueueDelete(msgQueueId);
ICUNIT_ASSERT_EQUAL(ret, osOK, ret);
#endif
return LOS_OK;
}

View File

@@ -46,7 +46,7 @@ static VOID TaskF01(VOID)
ICUNIT_ASSERT_EQUAL_VOID(g_testAtomicID03, i, g_testAtomicID03);
ICUNIT_ASSERT_EQUAL_VOID(ret, g_testAtomicID03, ret);
LOS_AtomicAdd(&g_testCount, 1);
LOS_AtomicAdd((Atomic *)(&g_testCount), 1);
}
static UINT32 TestCase(VOID)

View File

@@ -33,7 +33,7 @@
#include "osTest.h"
#include "It_los_event.h"
static VOID TaskF01()
static VOID TaskF01(VOID)
{
UINT32 ret;

View File

@@ -47,6 +47,7 @@ static int g_uwIndex;
#else
#define TEST_MAX_NUMBER_HWI (OS_USER_HWI_MAX - HWI_NUM_INT0)
#define TEST_HWI_COUNT (TEST_MAX_NUMBER_HWI - 2)
#undef HWI_NUM_INT0
#define HWI_NUM_INT0 HWI_NUM_INT1
#endif

View File

@@ -43,6 +43,7 @@ static VOID HwiF01(VOID)
return;
}
#undef HWI_NUM_INT0
#define HWI_NUM_INT0 HWI_NUM_TEST1
static UINT32 Testcase(VOID)
{

View File

@@ -33,7 +33,7 @@
#include "los_timer.h"
#include "los_sched.h"
#define myprintf // printf
#define myprintf printf
#define TEST_LOOP 5
static EVENT_CB_S g_pmTestEvent;
static UINT32 g_taskID1, g_taskID2;

View File

@@ -36,6 +36,15 @@ EVENT_CB_S g_eventCB0;
EVENT_CB_S g_eventCB1;
EVENT_CB_S g_eventCB2;
EVENT_CB_S g_eventCB3;
UINT32 g_swtmrId1;
UINT32 g_swtmrId2;
UINT32 g_swtmrId3;
UINT32 g_swtmrCountA;
UINT32 g_swtmrCountB;
UINT32 g_swtmrCountC;
UINT32 g_uwsTick1;
UINT32 g_uwsTick2;
UINT32 g_uwsTick3;
VOID ItSuiteLosSwtmr(void)
{

View File

@@ -56,17 +56,17 @@ extern EVENT_CB_S g_eventCB3;
extern UINT32 g_idleTaskID;
static UINT32 g_swtmrId1;
static UINT32 g_swtmrId2;
static UINT32 g_swtmrId3;
extern UINT32 g_swtmrId1;
extern UINT32 g_swtmrId2;
extern UINT32 g_swtmrId3;
static UINT32 g_swtmrCountA;
static UINT32 g_swtmrCountB;
static UINT32 g_swtmrCountC;
extern UINT32 g_swtmrCountA;
extern UINT32 g_swtmrCountB;
extern UINT32 g_swtmrCountC;
static UINT32 g_uwsTick1;
static UINT32 g_uwsTick2;
static UINT32 g_uwsTick3;
extern UINT32 g_uwsTick1;
extern UINT32 g_uwsTick2;
extern UINT32 g_uwsTick3;
extern VOID LOS_GetCpuTick(UINT32 *puwCntHi, UINT32 *puwCntLo);
extern VOID ItSuiteLosSwtmr(VOID);

View File

@@ -48,7 +48,7 @@ static VOID Case1(UINT32 arg)
return;
}
static VOID Case2()
static VOID Case2(VOID)
{
UINT32 ret;

View File

@@ -44,7 +44,7 @@ static VOID Case1(UINT32 arg)
return;
}
static VOID Case2()
static VOID Case2(VOID)
{
UINT32 ret;
UINT32 uwloop = 1000;

View File

@@ -41,7 +41,7 @@ static VOID Case1(UINT32 arg)
g_testCount = 30;
}
static VOID Case2()
static VOID Case2(VOID)
{
// 10, Here, assert that g_testCount is equal to this .
ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 10, g_testCount);
@@ -49,7 +49,7 @@ static VOID Case2()
g_testCount = 20;
}
static VOID Case3()
static VOID Case3(VOID)
{
// 10, Set the number to determine whether the process is as expected.
g_testCount = 10;

View File

@@ -51,7 +51,7 @@ EXIT:
LOS_TaskDelete(g_testTaskID01);
}
static VOID Case2()
static VOID Case2(VOID)
{
UINT32 ret;

View File

@@ -50,14 +50,14 @@ static VOID Case1(UINT32 arg)
g_testCount = 10;
}
static VOID Case2()
static VOID Case2(VOID)
{
// 20, Here, assert that g_testCount is equal to this .
ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 20, g_testCount);
g_testCount++;
}
static VOID Case3()
static VOID Case3(VOID)
{
UINT32 index;

View File

@@ -33,7 +33,7 @@
#include "It_los_swtmr.h"
static VOID Case1()
static VOID Case1(VOID)
{
UINT32 ret;
@@ -43,7 +43,7 @@ static VOID Case1()
}
}
static VOID Case2()
static VOID Case2(VOID)
{
UINT32 ret;
@@ -53,7 +53,7 @@ static VOID Case2()
}
}
static VOID Case3()
static VOID Case3(VOID)
{
UINT32 ret;
@@ -64,7 +64,7 @@ static VOID Case3()
}
}
VOID Case4()
static VOID Case4(VOID)
{
UINT32 ret;
@@ -77,7 +77,7 @@ VOID Case4()
}
}
VOID Case5()
static VOID Case5(VOID)
{
UINT32 ret;
@@ -90,7 +90,7 @@ VOID Case5()
}
}
VOID Case6()
static VOID Case6(VOID)
{
UINT32 ret;

View File

@@ -41,6 +41,7 @@ mqd_t g_mqueueId[LOSCFG_BASE_IPC_QUEUE_CONFIG + 1];
SEM_HANDLE_T g_mqueueSem;
mqd_t g_messageQId;
mqd_t g_gqueue;
TSK_HANDLE_T g_mqueueTaskPID;
VOID TestAssertWaitDelay(UINT32 *testCount, UINT32 flag)
{

View File

@@ -57,18 +57,19 @@
#define MQUEUE_PRIORITY_TEST 0
#define MQUEUE_TIMEOUT_TEST 7
#define MQUEUE_PRIORITY_NUM_TEST 3
#define MQUEUE_MAX_NUM_TEST (LOSCFG_BASE_IPC_QUEUE_CONFIG - QUEUE_EXISTED_NUM)
#define MQ_MAX_MSG_NUM 16
#define MQ_MAX_MSG_LEN 64
#undef HWI_NUM_TEST
#define HWI_NUM_TEST 1
#undef HWI_NUM_TEST1
#define HWI_NUM_TEST1 2
#if (LOSCFG_LIBC_NEWLIB == 1)
#define MQ_PRIO_MAX 1
#endif
#undef LOSCFG_BASE_IPC_QUEUE_CONFIG
#define LOSCFG_BASE_IPC_QUEUE_CONFIG 1024
#define LOS_AtomicInc(a) (++*(a))
#define MqueueTaskDelay(tick) (usleep((tick) * 10000))
@@ -91,7 +92,7 @@ typedef UINT32 SEM_HANDLE_T ;
extern SEM_HANDLE_T g_mqueueSem;
static TSK_HANDLE_T g_mqueueTaskPID;
extern TSK_HANDLE_T g_mqueueTaskPID;
extern CHAR g_gqname[MQUEUE_STANDARD_NAME_LENGTH];
extern CHAR g_mqueueName[LOSCFG_BASE_IPC_QUEUE_CONFIG + 1][MQUEUE_STANDARD_NAME_LENGTH];
extern mqd_t g_mqueueId[LOSCFG_BASE_IPC_QUEUE_CONFIG + 1];

View File

@@ -34,8 +34,6 @@ static UINT32 Testcase(VOID)
CHAR qname[MQUEUE_STANDARD_NAME_LENGTH] = "";
const CHAR *msgptr = MQUEUE_SEND_STRING_TEST;
mqd_t queue;
INT32 unresolved = 0;
INT32 failure = 0;
INT32 ret = 0;
ret = snprintf_s(qname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \

View File

@@ -34,8 +34,6 @@ static UINT32 Testcase(VOID)
CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH], msgrv[MQUEUE_STANDARD_NAME_LENGTH];
mqd_t mqdes;
struct mq_attr attr = {0};
INT32 unresolved = 0;
INT32 failure = 0;
INT32 ret = 0;
ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \

View File

@@ -35,8 +35,6 @@ static UINT32 Testcase(VOID)
mqd_t mqdes;
CHAR msgrv[MQUEUE_STANDARD_NAME_LENGTH];
struct mq_attr attr = {0};
INT32 unresolved = 0;
INT32 failure = 0;
INT32 ret = 0;
ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \

View File

@@ -34,8 +34,6 @@ static UINT32 Testcase(VOID)
CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = "";
mqd_t mqdes;
struct mq_attr mqstat;
INT32 unresolved = 0;
INT32 failure = 0;
INT32 ret = 0;
ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \

View File

@@ -34,8 +34,6 @@ static UINT32 Testcase(VOID)
CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = "";
mqd_t mqdes;
struct mq_attr mqstat, nmqstat;
INT32 unresolved = 0;
INT32 failure = 0;
INT32 ret = 0;
ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \

View File

@@ -35,8 +35,6 @@ static UINT32 Testcase(VOID)
mqd_t mqdes;
struct mq_attr mqstat = {0};
struct mq_attr nmqstat = {0};
INT32 unresolved = 0;
INT32 failure = 0;
INT32 ret = 0;
ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \

View File

@@ -38,23 +38,7 @@
#include "semaphore.h"
#include "unistd.h"
#ifdef LOSCFG_DEBUG_DEADLOCK
#define TEST_MUTEX_INIT \
{ \
{ 0, 0, 0, 0 }, \
{ \
{ 0, 0 }, { 0, 0 }, 0, 0 \
} \
}
#else
#define TEST_MUTEX_INIT \
{ \
{ 0, 0, 0, 0 }, \
{ \
{ 0, 0 }, 0, 0 \
} \
}
#endif
#define TEST_MUTEX_INIT {0}
#define MUTEX_TEST_DEFAULT_PRIO LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO
#define MUTEX_TEST_HIGH_PRIO (MUTEX_TEST_DEFAULT_PRIO - 6)

View File

@@ -42,11 +42,6 @@
#include "mqueue.h"
#include "signal.h"
/* Some routines are part of the XSI Extensions */
#ifndef WITHOUT_XOPEN
#define _XOPEN_SOURCE 600
#endif
#define PTHREAD_IS_ERROR (-1)
#define PTHREAD_PRIORITY_TEST 20
#define PTHREAD_DEFAULT_STACK_SIZE (LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE)
@@ -71,9 +66,6 @@
/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */
#define _POSIX_C_SOURCE 200112L
#define PTHREAD_MUTEX_RECURSIVE 0
#define PTHREAD_MUTEX_ERRORCHECK 0
#define PRIORITY_OTHER (-1)
#define PRIORITY_FIFO 20
#define PRIORITY_RR 20

View File

@@ -102,7 +102,7 @@ char *g_strType[] = {
"FUNCTION", "PRESSURE", "PERFORMANCE"
};
iUINT32 ICunitRunF()
iUINT32 ICunitRunF(void)
{
iUINT32 idx, idx1;
ICUNIT_CASE_S *psubCaseArray;

View File

@@ -231,7 +231,7 @@ void TestCmsis2(void)
}
#endif
VOID TestTaskEntry()
VOID TestTaskEntry(VOID)
{
PRINTF("\t\n --- Test Start --- \n\n");
ICunitInit();

View File

@@ -68,7 +68,10 @@ static_library("posix_test") {
sources += [ "src/fs/posix_fs_func_test.c" ]
}
if (!defined(LOSCFG_COMPILER_ICCARM)) {
cflags = [ "-Wno-error" ]
cflags = [
"-Wno-error",
"-Wno-unused-function",
]
} else {
cflags = [ "--no_warnings" ]
}

View File

@@ -1,56 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef COMMON_TEST_H
#define COMMON_TEST_H
#define TESTCOUNT_NUM_1 1
#define TESTCOUNT_NUM_2 2
#define TESTCOUNT_NUM_3 3
#define TESTCOUNT_NUM_4 4
#define TESTCOUNT_NUM_5 5
#define DELAY_TICKS_1 1
#define DELAY_TICKS_5 5
#define DELAY_TICKS_10 10
#define TEST_TASK_STACK_SIZE 0x600
#define TASK_LOOP_NUM 0x10000000
#define TEST_TIME 10
#define THREAD_COUNT_MIN 3
#define THREAD_COUNT_MAX 30
#define THREAD_STACK_SPACE_MAX 4096
#ifdef __cplusplus
#if __cplusplus
#endif
#endif /* __cplusplus */
#endif

View File

@@ -42,8 +42,6 @@
#define DELAY_TICKS_5 5
#define DELAY_TICKS_10 10
#define TEST_TASK_STACK_SIZE 0x600
#define TASK_LOOP_NUM 0x10000000
#define TEST_TIME 10
#define THREAD_COUNT_MIN 3
#define THREAD_COUNT_MAX 30

View File

@@ -33,7 +33,6 @@
#include "posix_test.h"
#include <mqueue.h>
#include <fcntl.h>
#include "common_test.h"
#include "kernel_test.h"
#include "log.h"

View File

@@ -34,7 +34,6 @@
#include "hctest.h"
#include "los_config.h"
#include "cmsis_os2.h"
#include "common_test.h"
#include "kernel_test.h"
#include "pthread.h"
#include "log.h"

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(1596967800, 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(0, 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);

View File

@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 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:
@@ -525,8 +525,17 @@ static inline UINT64 __atomic_exchange_8(volatile void *mem, UINT64 val, int mod
free_lock (memP, model);
return ret;
}
#endif
#endif
#endif /* __XTENSA_LX6__ */
#define ALIAS_OF(of) __attribute__((alias(#of)))
#define FUNC_ALIAS(real_func, new_alias, args_list, return_type) \
return_type new_alias args_list ALIAS_OF(real_func)
#else
#define FUNC_ALIAS(real_func, new_alias, args_list, return_type)
#endif /* __GNUC__ */
#ifdef __cplusplus
#if __cplusplus