Compare commits
40 Commits
weekly_202
...
weekly_202
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e74deedba3 | ||
|
|
24f52e0259 | ||
|
|
d4df4d1e54 | ||
|
|
2d1e7e8c29 | ||
|
|
a96f535cd3 | ||
|
|
1669455ba9 | ||
|
|
b637b1d979 | ||
|
|
c6d021bede | ||
|
|
d7f3aef326 | ||
|
|
db32ad90bf | ||
|
|
59fbe91d8b | ||
|
|
c7088f4d0f | ||
|
|
705bfbdc76 | ||
|
|
9a4e9677bd | ||
|
|
6134d4bd22 | ||
|
|
c119b7e9e2 | ||
|
|
dbf0498bab | ||
|
|
68b142cf78 | ||
|
|
22b7eb87ca | ||
|
|
ed50f7e373 | ||
|
|
2f2a0b7a75 | ||
|
|
1ae62ebf2e | ||
|
|
25278a02eb | ||
|
|
52bc16c3db | ||
|
|
733b6e6c6c | ||
|
|
6562536db7 | ||
|
|
ddf3dc8237 | ||
|
|
399e7647bb | ||
|
|
f7af2cdf9b | ||
|
|
07091c5a75 | ||
|
|
6633aabf89 | ||
|
|
2a4282f912 | ||
|
|
685688b21c | ||
|
|
67ee38e1e3 | ||
|
|
6cd48f6f90 | ||
|
|
662aefb700 | ||
|
|
83fc93cc84 | ||
|
|
b817c490ba | ||
|
|
705e4c323a | ||
|
|
b7f906ef8a |
3
BUILD.gn
3
BUILD.gn
@@ -91,8 +91,9 @@ config("dialect_config") {
|
||||
}
|
||||
|
||||
config("misc_config") {
|
||||
defines = []
|
||||
if (!defined(LOSCFG_COMPILER_ICCARM)) {
|
||||
defines = [ "__LITEOS__" ]
|
||||
defines += [ "__LITEOS__" ]
|
||||
defines += [ "__LITEOS_M__" ]
|
||||
}
|
||||
if (!defined(LOSCFG_DEBUG_VERSION)) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
judgment condition to support multiple code sections. */
|
||||
WEAK BOOL OsStackDataIsCodeAddr(UINTPTR value)
|
||||
{
|
||||
if ((value >= CODE_START_ADDR) && (value < CODE_END_ADDR)) {
|
||||
if ((value > CODE_START_ADDR) && (value < CODE_END_ADDR)) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -60,7 +60,6 @@
|
||||
#endif /* FS_LOCK_TIMEOUT_SEC */
|
||||
|
||||
static UINT8 g_workBuffer[FF_MAX_SS];
|
||||
static pthread_mutex_t g_fatfsMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static char *g_volPath[FF_VOLUMES] = {FF_VOLUME_STRS};
|
||||
|
||||
PARTITION VolToPart[] = {
|
||||
@@ -70,31 +69,6 @@ PARTITION VolToPart[] = {
|
||||
{ 0, 0, 4, 0, 0 }
|
||||
};
|
||||
|
||||
static int FsLock(void)
|
||||
{
|
||||
int ret = 0;
|
||||
struct timespec absTimeout = {0};
|
||||
if (!OsCheckKernelRunning()) {
|
||||
return ret;
|
||||
}
|
||||
ret = clock_gettime(CLOCK_REALTIME, &absTimeout);
|
||||
if (ret != 0) {
|
||||
PRINT_ERR("clock gettime err 0x%x!\r\n", errno);
|
||||
return errno;
|
||||
}
|
||||
absTimeout.tv_sec += FS_LOCK_TIMEOUT_SEC;
|
||||
ret = pthread_mutex_timedlock(&g_fatfsMutex, &absTimeout);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void FsUnlock(void)
|
||||
{
|
||||
if (!OsCheckKernelRunning()) {
|
||||
return;
|
||||
}
|
||||
(void)pthread_mutex_unlock(&g_fatfsMutex);
|
||||
}
|
||||
|
||||
static int FsChangeDrive(const char *path)
|
||||
{
|
||||
INT32 res;
|
||||
@@ -275,95 +249,69 @@ int FatfsMount(struct MountPoint *mp, unsigned long mountflags,
|
||||
{
|
||||
FRESULT res;
|
||||
FATFS *fs = NULL;
|
||||
int ret;
|
||||
|
||||
ret = FsLock();
|
||||
if (ret != 0) {
|
||||
errno = ret;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
if (mountflags & MS_REMOUNT) {
|
||||
ret = Remount(mp, mountflags);
|
||||
FsUnlock();
|
||||
return ret;
|
||||
return Remount(mp, mountflags);
|
||||
}
|
||||
|
||||
char *ldPath = GetLdPath(mp->mDev);
|
||||
if (ldPath == NULL) {
|
||||
errno = EFAULT;
|
||||
ret = (int)LOS_NOK;
|
||||
goto ERROUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
fs = (FATFS *)LOSCFG_FS_MALLOC_HOOK(sizeof(FATFS));
|
||||
if (fs == NULL) {
|
||||
errno = ENOMEM;
|
||||
ret = (int)LOS_NOK;
|
||||
goto ERROUT;
|
||||
PutLdPath(ldPath);
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
(void)memset_s(fs, sizeof(FATFS), 0, sizeof(FATFS));
|
||||
|
||||
res = f_mount(fs, ldPath, 1);
|
||||
if (res != FR_OK) {
|
||||
LOSCFG_FS_FREE_HOOK(fs);
|
||||
PutLdPath(ldPath);
|
||||
errno = FatfsErrno(res);
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
mp->mData = (void *)fs;
|
||||
|
||||
res = f_mount((FATFS *)mp->mData, ldPath, 1);
|
||||
if (res != FR_OK) {
|
||||
errno = FatfsErrno(res);
|
||||
ret = (int)LOS_NOK;
|
||||
goto ERROUT;
|
||||
}
|
||||
|
||||
PutLdPath(ldPath);
|
||||
FsUnlock();
|
||||
return (int)LOS_OK;
|
||||
|
||||
ERROUT:
|
||||
LOSCFG_FS_FREE_HOOK(fs);
|
||||
mp->mData = NULL;
|
||||
PutLdPath(ldPath);
|
||||
FsUnlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FatfsUmount(struct MountPoint *mp)
|
||||
{
|
||||
int ret;
|
||||
int volId;
|
||||
FRESULT res;
|
||||
char *ldPath = NULL;
|
||||
FATFS *fatfs = (FATFS *)mp->mData;
|
||||
|
||||
ret = FsLock();
|
||||
if (ret != 0) {
|
||||
errno = ret;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
char *ldPath = GetLdPath(mp->mDev);
|
||||
if (ldPath == NULL) {
|
||||
errno = EFAULT;
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
/* The volume is not mounted */
|
||||
if (fatfs->fs_type == 0) {
|
||||
errno = EINVAL;
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
volId = GetPartIdByPartName(mp->mDev);
|
||||
/* umount is not allowed when a file or directory is opened. */
|
||||
if (f_checkopenlock(volId) != FR_OK) {
|
||||
errno = EBUSY;
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ldPath = GetLdPath(mp->mDev);
|
||||
if (ldPath == NULL) {
|
||||
errno = EFAULT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
res = f_mount((FATFS *)NULL, ldPath, 0);
|
||||
if (res != FR_OK) {
|
||||
errno = FatfsErrno(res);
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
PutLdPath(ldPath);
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
if (fatfs->win != NULL) {
|
||||
@@ -373,19 +321,15 @@ int FatfsUmount(struct MountPoint *mp)
|
||||
LOSCFG_FS_FREE_HOOK(mp->mData);
|
||||
mp->mData = NULL;
|
||||
|
||||
ret = (int)LOS_OK;
|
||||
|
||||
OUT:
|
||||
PutLdPath(ldPath);
|
||||
FsUnlock();
|
||||
return ret;
|
||||
return (int)LOS_OK;
|
||||
}
|
||||
|
||||
int FatfsUmount2(struct MountPoint *mp, int flag)
|
||||
{
|
||||
int ret;
|
||||
UINT32 flags;
|
||||
FRESULT res;
|
||||
char *ldPath = NULL;
|
||||
FATFS *fatfs = (FATFS *)mp->mData;
|
||||
|
||||
flags = MNT_FORCE | MNT_DETACH | MNT_EXPIRE | UMOUNT_NOFOLLOW;
|
||||
@@ -394,31 +338,23 @@ int FatfsUmount2(struct MountPoint *mp, int flag)
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = FsLock();
|
||||
if (ret != 0) {
|
||||
errno = ret;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
char *ldPath = GetLdPath(mp->mDev);
|
||||
if (ldPath == NULL) {
|
||||
errno = EFAULT;
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
/* The volume is not mounted */
|
||||
if (fatfs->fs_type == 0) {
|
||||
errno = EINVAL;
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ldPath = GetLdPath(mp->mDev);
|
||||
if (ldPath == NULL) {
|
||||
errno = EFAULT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
res = f_mount((FATFS *)NULL, ldPath, 0);
|
||||
if (res != FR_OK) {
|
||||
PutLdPath(ldPath);
|
||||
errno = FatfsErrno(res);
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
if (fatfs->win != NULL) {
|
||||
@@ -428,12 +364,8 @@ int FatfsUmount2(struct MountPoint *mp, int flag)
|
||||
LOSCFG_FS_FREE_HOOK(mp->mData);
|
||||
mp->mData = NULL;
|
||||
|
||||
ret = (int)LOS_OK;
|
||||
|
||||
OUT:
|
||||
PutLdPath(ldPath);
|
||||
FsUnlock();
|
||||
return ret;
|
||||
return (int)LOS_OK;
|
||||
}
|
||||
|
||||
int FatfsOpen(struct File *file, const char *path, int oflag)
|
||||
@@ -456,20 +388,12 @@ int FatfsOpen(struct File *file, const char *path, int oflag)
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = FsLock();
|
||||
if (ret != 0) {
|
||||
errno = ret;
|
||||
LOSCFG_FS_FREE_HOOK(fp);
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = FsChangeDrive(path);
|
||||
if (ret != (int)LOS_OK) {
|
||||
PRINT_ERR("FAT open ChangeDrive err 0x%x!\r\n", ret);
|
||||
errno = ENOENT;
|
||||
ret = (int)LOS_NOK;
|
||||
LOSCFG_FS_FREE_HOOK(fp);
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
res = f_open(fp, path, fmode);
|
||||
@@ -477,31 +401,20 @@ int FatfsOpen(struct File *file, const char *path, int oflag)
|
||||
PRINT_ERR("FAT open err 0x%x!\r\n", res);
|
||||
LOSCFG_FS_FREE_HOOK(fp);
|
||||
errno = FatfsErrno(res);
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
file->fData = (void *)fp;
|
||||
|
||||
OUT:
|
||||
FsUnlock();
|
||||
return ret;
|
||||
return (int)LOS_OK;
|
||||
}
|
||||
|
||||
int FatfsClose(struct File *file)
|
||||
{
|
||||
FRESULT res;
|
||||
FIL *fp = (FIL *)file->fData;
|
||||
int ret;
|
||||
|
||||
ret = FsLock();
|
||||
if (ret != 0) {
|
||||
errno = ret;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
if ((fp == NULL) || (fp->obj.fs == NULL)) {
|
||||
FsUnlock();
|
||||
errno = ENOENT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
@@ -509,7 +422,6 @@ int FatfsClose(struct File *file)
|
||||
res = f_close(fp);
|
||||
if (res != FR_OK) {
|
||||
PRINT_ERR("FAT close err 0x%x!\r\n", res);
|
||||
FsUnlock();
|
||||
errno = FatfsErrno(res);
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
@@ -521,7 +433,6 @@ int FatfsClose(struct File *file)
|
||||
#endif
|
||||
LOSCFG_FS_FREE_HOOK(file->fData);
|
||||
file->fData = NULL;
|
||||
FsUnlock();
|
||||
|
||||
return (int)LOS_OK;
|
||||
}
|
||||
@@ -531,31 +442,22 @@ ssize_t FatfsRead(struct File *file, char *buf, size_t nbyte)
|
||||
FRESULT res;
|
||||
UINT32 lenRead;
|
||||
FIL *fp = (FIL *)file->fData;
|
||||
int ret;
|
||||
|
||||
if (buf == NULL) {
|
||||
errno = EFAULT;
|
||||
return (ssize_t)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = FsLock();
|
||||
if (ret != 0) {
|
||||
errno = ret;
|
||||
return (ssize_t)LOS_NOK;
|
||||
}
|
||||
if (fp == NULL) {
|
||||
FsUnlock();
|
||||
errno = ENOENT;
|
||||
return (ssize_t)LOS_NOK;
|
||||
}
|
||||
|
||||
res = f_read(fp, buf, nbyte, &lenRead);
|
||||
if (res != FR_OK) {
|
||||
FsUnlock();
|
||||
errno = FatfsErrno(res);
|
||||
return (ssize_t)LOS_NOK;
|
||||
}
|
||||
FsUnlock();
|
||||
|
||||
return (ssize_t)lenRead;
|
||||
}
|
||||
@@ -566,22 +468,15 @@ ssize_t FatfsWrite(struct File *file, const char *buf, size_t nbyte)
|
||||
UINT32 lenWrite;
|
||||
static BOOL overFlow = FALSE;
|
||||
FIL *fp = (FIL *)file->fData;
|
||||
int ret;
|
||||
|
||||
if (buf == NULL) {
|
||||
errno = EFAULT;
|
||||
return (ssize_t)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = FsLock();
|
||||
if (ret != 0) {
|
||||
errno = ret;
|
||||
return (ssize_t)LOS_NOK;
|
||||
}
|
||||
|
||||
if ((fp ==NULL) || (fp->obj.fs == NULL)) {
|
||||
if ((fp == NULL) || (fp->obj.fs == NULL)) {
|
||||
errno = ENOENT;
|
||||
goto ERROUT;
|
||||
return (ssize_t)LOS_NOK;
|
||||
}
|
||||
|
||||
res = f_write(fp, buf, nbyte, &lenWrite);
|
||||
@@ -592,15 +487,10 @@ ssize_t FatfsWrite(struct File *file, const char *buf, size_t nbyte)
|
||||
|
||||
if ((res != FR_OK) || (nbyte != lenWrite)) {
|
||||
errno = FatfsErrno(res);
|
||||
goto ERROUT;
|
||||
return (ssize_t)LOS_NOK;
|
||||
}
|
||||
|
||||
FsUnlock();
|
||||
return (ssize_t)lenWrite;
|
||||
|
||||
ERROUT:
|
||||
FsUnlock();
|
||||
return (ssize_t)LOS_NOK;
|
||||
}
|
||||
|
||||
off_t FatfsLseek(struct File *file, off_t offset, int whence)
|
||||
@@ -608,17 +498,10 @@ off_t FatfsLseek(struct File *file, off_t offset, int whence)
|
||||
FRESULT res;
|
||||
off_t pos;
|
||||
FIL *fp = (FIL *)file->fData;
|
||||
int ret;
|
||||
|
||||
ret = FsLock();
|
||||
if (ret != 0) {
|
||||
errno = ret;
|
||||
return (off_t)LOS_NOK;
|
||||
}
|
||||
|
||||
if ((fp == NULL) || (fp->obj.fs == NULL)) {
|
||||
errno = ENOENT;
|
||||
goto ERROUT;
|
||||
return (off_t)LOS_NOK;
|
||||
}
|
||||
|
||||
if (whence == SEEK_SET) {
|
||||
@@ -629,22 +512,17 @@ off_t FatfsLseek(struct File *file, off_t offset, int whence)
|
||||
pos = f_size(fp);
|
||||
} else {
|
||||
errno = EINVAL;
|
||||
goto ERROUT;
|
||||
return (off_t)LOS_NOK;
|
||||
}
|
||||
|
||||
res = f_lseek(fp, offset + pos);
|
||||
if (res != FR_OK) {
|
||||
errno = FatfsErrno(res);
|
||||
goto ERROUT;
|
||||
return (off_t)LOS_NOK;
|
||||
}
|
||||
|
||||
pos = f_tell(fp);
|
||||
FsUnlock();
|
||||
return pos;
|
||||
|
||||
ERROUT:
|
||||
FsUnlock();
|
||||
return (off_t)LOS_NOK;
|
||||
}
|
||||
|
||||
/* Remove the specified FILE */
|
||||
@@ -658,39 +536,26 @@ int FatfsUnlink(struct MountPoint *mp, const char *path)
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = FsLock();
|
||||
if (ret != 0) {
|
||||
errno = ret;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
if (!mp->mWriteEnable) {
|
||||
errno = EACCES;
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = FsChangeDrive(path);
|
||||
if (ret != (int)LOS_OK) {
|
||||
PRINT_ERR("FAT unlink ChangeDrive err 0x%x!\r\n", ret);
|
||||
errno = ENOENT;
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
res = f_unlink(path);
|
||||
if (res != FR_OK) {
|
||||
PRINT_ERR("FAT unlink err 0x%x!\r\n", res);
|
||||
errno = FatfsErrno(res);
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = (int)LOS_OK;
|
||||
|
||||
OUT:
|
||||
FsUnlock();
|
||||
return ret;
|
||||
return (int)LOS_OK;
|
||||
}
|
||||
|
||||
int FatfsStat(struct MountPoint *mp, const char *path, struct stat *buf)
|
||||
@@ -704,26 +569,18 @@ int FatfsStat(struct MountPoint *mp, const char *path, struct stat *buf)
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = FsLock();
|
||||
if (ret != 0) {
|
||||
errno = ret;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = FsChangeDrive(path);
|
||||
if (ret != (int)LOS_OK) {
|
||||
PRINT_ERR("FAT stat ChangeDrive err 0x%x!\r\n", ret);
|
||||
errno = ENOENT;
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
res = f_stat(path, &fileInfo);
|
||||
if (res != FR_OK) {
|
||||
PRINT_ERR("FAT stat err 0x%x!\r\n", res);
|
||||
errno = FatfsErrno(res);
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
buf->st_size = fileInfo.fsize;
|
||||
@@ -740,43 +597,27 @@ int FatfsStat(struct MountPoint *mp, const char *path, struct stat *buf)
|
||||
buf->st_mode |= S_IFDIR;
|
||||
}
|
||||
|
||||
ret = (int)LOS_OK;
|
||||
|
||||
OUT:
|
||||
FsUnlock();
|
||||
return ret;
|
||||
return (int)LOS_OK;
|
||||
}
|
||||
|
||||
/* Synchronize all changes to Flash */
|
||||
int FatfsSync(struct File *file)
|
||||
{
|
||||
int ret;
|
||||
FRESULT res;
|
||||
FIL *fp = (FIL *)file->fData;
|
||||
|
||||
ret = FsLock();
|
||||
if (ret != 0) {
|
||||
errno = ret;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
if ((fp == NULL) || (fp->obj.fs == NULL)) {
|
||||
errno = ENOENT;
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
res = f_sync(fp);
|
||||
if (res != FR_OK) {
|
||||
errno = FatfsErrno(res);
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
ret = (int)LOS_OK;
|
||||
|
||||
OUT:
|
||||
FsUnlock();
|
||||
return ret;
|
||||
return (int)LOS_OK;
|
||||
}
|
||||
|
||||
int FatfsMkdir(struct MountPoint *mp, const char *path)
|
||||
@@ -789,38 +630,26 @@ int FatfsMkdir(struct MountPoint *mp, const char *path)
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = FsLock();
|
||||
if (ret != 0) {
|
||||
errno = ret;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
if (!mp->mWriteEnable) {
|
||||
errno = EACCES;
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = FsChangeDrive(path);
|
||||
if (ret != (int)LOS_OK) {
|
||||
PRINT_ERR("FAT mkdir ChangeDrive err 0x%x!\r\n", ret);
|
||||
errno = ENOENT;
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
res = f_mkdir(path);
|
||||
if (res != FR_OK) {
|
||||
PRINT_ERR("FAT mkdir err 0x%x!\r\n", res);
|
||||
errno = FatfsErrno(res);
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
ret = (int)LOS_OK;
|
||||
|
||||
OUT:
|
||||
FsUnlock();
|
||||
return ret;
|
||||
return (int)LOS_OK;
|
||||
}
|
||||
|
||||
int FatfsOpendir(struct Dir *dir, const char *dirName)
|
||||
@@ -831,47 +660,34 @@ int FatfsOpendir(struct Dir *dir, const char *dirName)
|
||||
|
||||
if (dirName == NULL) {
|
||||
errno = EFAULT;
|
||||
goto ERROUT;
|
||||
}
|
||||
|
||||
dp = (DIR *)LOSCFG_FS_MALLOC_HOOK(sizeof(DIR));
|
||||
if (dp == NULL) {
|
||||
errno = ENOENT;
|
||||
goto ERROUT;
|
||||
}
|
||||
|
||||
ret = FsLock();
|
||||
if (ret != 0) {
|
||||
errno = ret;
|
||||
goto ERROUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = FsChangeDrive(dirName);
|
||||
if (ret != (int)LOS_OK) {
|
||||
PRINT_ERR("FAT opendir ChangeDrive err 0x%x!\r\n", ret);
|
||||
errno = ENOENT;
|
||||
goto ERROUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
dp = (DIR *)LOSCFG_FS_MALLOC_HOOK(sizeof(DIR));
|
||||
if (dp == NULL) {
|
||||
errno = ENOENT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
res = f_opendir(dp, dirName);
|
||||
if (res != FR_OK) {
|
||||
PRINT_ERR("FAT opendir err 0x%x!\r\n", res);
|
||||
LOSCFG_FS_FREE_HOOK(dp);
|
||||
errno = FatfsErrno(res);
|
||||
goto ERROUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
dir->dData = dp;
|
||||
dir->dOffset = 0;
|
||||
|
||||
FsUnlock();
|
||||
return (int)LOS_OK;
|
||||
|
||||
ERROUT:
|
||||
if (dp != NULL) {
|
||||
LOSCFG_FS_FREE_HOOK(dp);
|
||||
}
|
||||
FsUnlock();
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
int FatfsReaddir(struct Dir *dir, struct dirent *dent)
|
||||
@@ -879,7 +695,6 @@ int FatfsReaddir(struct Dir *dir, struct dirent *dent)
|
||||
FRESULT res;
|
||||
FILINFO fileInfo = {0};
|
||||
DIR *dp = NULL;
|
||||
int ret;
|
||||
|
||||
if ((dir == NULL) || (dir->dData == NULL)) {
|
||||
errno = EBADF;
|
||||
@@ -887,18 +702,11 @@ int FatfsReaddir(struct Dir *dir, struct dirent *dent)
|
||||
}
|
||||
|
||||
dp = (DIR *)dir->dData;
|
||||
ret = FsLock();
|
||||
if (ret != 0) {
|
||||
errno = ret;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
res = f_readdir(dp, &fileInfo);
|
||||
/* if res not ok or fname is NULL , return NULL */
|
||||
if ((res != FR_OK) || (fileInfo.fname[0] == 0x0)) {
|
||||
PRINT_ERR("FAT readdir err 0x%x!\r\n", res);
|
||||
errno = FatfsErrno(res);
|
||||
FsUnlock();
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
@@ -909,7 +717,6 @@ int FatfsReaddir(struct Dir *dir, struct dirent *dent)
|
||||
} else {
|
||||
dent->d_type = DT_REG;
|
||||
}
|
||||
FsUnlock();
|
||||
|
||||
return (int)LOS_OK;
|
||||
}
|
||||
@@ -918,7 +725,6 @@ int FatfsClosedir(struct Dir *dir)
|
||||
{
|
||||
FRESULT res;
|
||||
DIR *dp = NULL;
|
||||
int ret;
|
||||
|
||||
if ((dir == NULL) || (dir->dData == NULL)) {
|
||||
errno = EBADF;
|
||||
@@ -926,23 +732,15 @@ int FatfsClosedir(struct Dir *dir)
|
||||
}
|
||||
|
||||
dp = dir->dData;
|
||||
ret = FsLock();
|
||||
if (ret != 0) {
|
||||
errno = ret;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
res = f_closedir(dp);
|
||||
if (res != FR_OK) {
|
||||
PRINT_ERR("FAT closedir err 0x%x!\r\n", res);
|
||||
FsUnlock();
|
||||
errno = FatfsErrno(res);
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
LOSCFG_FS_FREE_HOOK(dir->dData);
|
||||
dir->dData = NULL;
|
||||
FsUnlock();
|
||||
|
||||
return (int)LOS_OK;
|
||||
}
|
||||
@@ -957,38 +755,26 @@ int FatfsRmdir(struct MountPoint *mp, const char *path)
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = FsLock();
|
||||
if (ret != 0) {
|
||||
errno = ret;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
if (!mp->mWriteEnable) {
|
||||
errno = EACCES;
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = FsChangeDrive(path);
|
||||
if (ret != (int)LOS_OK) {
|
||||
PRINT_ERR("FAT rmdir ChangeDrive err 0x%x!\r\n", ret);
|
||||
errno = ENOENT;
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
res = f_rmdir(path);
|
||||
if (res != FR_OK) {
|
||||
PRINT_ERR("FAT rmdir err 0x%x!\r\n", res);
|
||||
errno = FatfsErrno(res);
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
ret = (int)LOS_OK;
|
||||
|
||||
OUT:
|
||||
FsUnlock();
|
||||
return ret;
|
||||
return (int)LOS_OK;
|
||||
}
|
||||
|
||||
int FatfsRename(struct MountPoint *mp, const char *oldName, const char *newName)
|
||||
@@ -1001,38 +787,26 @@ int FatfsRename(struct MountPoint *mp, const char *oldName, const char *newName)
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = FsLock();
|
||||
if (ret != 0) {
|
||||
errno = ret;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
if (!mp->mWriteEnable) {
|
||||
errno = EACCES;
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = FsChangeDrive(oldName);
|
||||
if (ret != (int)LOS_OK) {
|
||||
PRINT_ERR("FAT f_getfree ChangeDrive err 0x%x!\r\n", ret);
|
||||
errno = ENOENT;
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
res = f_rename(oldName, newName);
|
||||
if (res != FR_OK) {
|
||||
PRINT_ERR("FAT frename err 0x%x!\r\n", res);
|
||||
errno = FatfsErrno(res);
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
ret = (int)LOS_OK;
|
||||
|
||||
OUT:
|
||||
FsUnlock();
|
||||
return ret;
|
||||
return (int)LOS_OK;
|
||||
}
|
||||
|
||||
int FatfsStatfs(const char *path, struct statfs *buf)
|
||||
@@ -1047,26 +821,18 @@ int FatfsStatfs(const char *path, struct statfs *buf)
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = FsLock();
|
||||
if (ret != 0) {
|
||||
errno = ret;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = FsChangeDrive(path);
|
||||
if (ret != FR_OK) {
|
||||
PRINT_ERR("FAT f_getfree ChangeDrive err %d.", ret);
|
||||
errno = FatfsErrno(FR_INVALID_PARAMETER);
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
res = f_getfree(path, &freeClust, &fs);
|
||||
if (res != FR_OK) {
|
||||
PRINT_ERR("FAT f_getfree err 0x%x.", res);
|
||||
errno = FatfsErrno(res);
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
buf->f_bfree = freeClust;
|
||||
buf->f_bavail = freeClust;
|
||||
@@ -1078,11 +844,7 @@ int FatfsStatfs(const char *path, struct statfs *buf)
|
||||
buf->f_bsize = FF_MIN_SS * fs->csize;
|
||||
#endif
|
||||
|
||||
ret = (int)LOS_OK;
|
||||
|
||||
OUT:
|
||||
FsUnlock();
|
||||
return ret;
|
||||
return (int)LOS_OK;
|
||||
}
|
||||
|
||||
static int DoTruncate(struct File *file, off_t length, UINT32 count)
|
||||
@@ -1090,7 +852,6 @@ static int DoTruncate(struct File *file, off_t length, UINT32 count)
|
||||
FRESULT res = FR_OK;
|
||||
DWORD csz;
|
||||
FIL *fp = (FIL *)file->fData;
|
||||
int ret = (int)LOS_OK;
|
||||
|
||||
csz = (DWORD)(fp->obj.fs)->csize * SS(fp->obj.fs); /* Cluster size */
|
||||
if (length > csz * count) {
|
||||
@@ -1098,8 +859,7 @@ static int DoTruncate(struct File *file, off_t length, UINT32 count)
|
||||
res = f_expand(fp, 0, (FSIZE_t)(length), FALLOC_FL_KEEP_SIZE);
|
||||
#else
|
||||
errno = ENOSYS;
|
||||
ret = (int)LOS_NOK;
|
||||
return ret;
|
||||
return (int)LOS_NOK;
|
||||
#endif
|
||||
} else if (length < csz * count) {
|
||||
res = f_truncate(fp, (FSIZE_t)length);
|
||||
@@ -1107,14 +867,13 @@ static int DoTruncate(struct File *file, off_t length, UINT32 count)
|
||||
|
||||
if (res != FR_OK) {
|
||||
errno = FatfsErrno(res);
|
||||
ret = (int)LOS_NOK;
|
||||
return ret;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
fp->obj.objsize = length; /* Set file size to length */
|
||||
fp->flag |= 0x40; /* Set modified flag */
|
||||
|
||||
return ret;
|
||||
return (int)LOS_OK;
|
||||
}
|
||||
|
||||
int FatfsTruncate(struct File *file, off_t length)
|
||||
@@ -1123,49 +882,30 @@ int FatfsTruncate(struct File *file, off_t length)
|
||||
UINT count;
|
||||
DWORD fclust;
|
||||
FIL *fp = (FIL *)file->fData;
|
||||
int ret;
|
||||
|
||||
if ((length < 0) || (length > UINT_MAX)) {
|
||||
errno = EINVAL;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = FsLock();
|
||||
if (ret != 0) {
|
||||
errno = ret;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
if ((fp == NULL) || (fp->obj.fs == NULL)) {
|
||||
errno = ENOENT;
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
res = f_getclustinfo(fp, &fclust, &count);
|
||||
if (res != FR_OK) {
|
||||
errno = FatfsErrno(res);
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = DoTruncate(file, length, count);
|
||||
if (ret != FR_OK) {
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
ret = (int)LOS_OK;
|
||||
|
||||
OUT:
|
||||
FsUnlock();
|
||||
return ret;
|
||||
return DoTruncate(file, length, count);
|
||||
}
|
||||
|
||||
int FatfsFdisk(const char *dev, int *partTbl, int arrayNum)
|
||||
{
|
||||
int pdrv;
|
||||
FRESULT res;
|
||||
int ret;
|
||||
|
||||
if ((dev == NULL) || (partTbl == NULL)) {
|
||||
errno = EFAULT;
|
||||
@@ -1178,25 +918,13 @@ int FatfsFdisk(const char *dev, int *partTbl, int arrayNum)
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = FsLock();
|
||||
if (ret != 0) {
|
||||
errno = ret;
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
res = f_fdisk(pdrv, (DWORD const *)partTbl, g_workBuffer);
|
||||
if (res != FR_OK) {
|
||||
errno = FatfsErrno(res);
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = (int)LOS_OK;
|
||||
|
||||
OUT:
|
||||
FsUnlock();
|
||||
return ret;
|
||||
return (int)LOS_OK;
|
||||
}
|
||||
|
||||
int FatfsFormat(const char *partName, void *privData)
|
||||
@@ -1205,7 +933,6 @@ int FatfsFormat(const char *partName, void *privData)
|
||||
MKFS_PARM opt = {0};
|
||||
int option = *(int *)privData;
|
||||
char *dev = NULL; /* logical driver */
|
||||
int ret;
|
||||
|
||||
if (partName == NULL) {
|
||||
errno = EFAULT;
|
||||
@@ -1218,29 +945,17 @@ int FatfsFormat(const char *partName, void *privData)
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = FsLock();
|
||||
if (ret != 0) {
|
||||
errno = ret;
|
||||
PutLdPath(dev);
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
opt.fmt = option;
|
||||
opt.n_sect = 0; /* use default allocation unit size depends on the volume
|
||||
size. */
|
||||
res = f_mkfs(dev, &opt, g_workBuffer, FF_MAX_SS);
|
||||
if (res != FR_OK) {
|
||||
errno = FatfsErrno(res);
|
||||
ret = (int)LOS_NOK;
|
||||
goto OUT;
|
||||
PutLdPath(dev);
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
ret = (int)LOS_OK;
|
||||
|
||||
OUT:
|
||||
PutLdPath(dev);
|
||||
FsUnlock();
|
||||
return ret;
|
||||
return (int)LOS_OK;
|
||||
}
|
||||
|
||||
static struct MountOps g_fatfsMnt = {
|
||||
|
||||
@@ -41,8 +41,6 @@
|
||||
#include "securec.h"
|
||||
#include "los_fs.h"
|
||||
|
||||
static pthread_mutex_t g_fsLocalMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static struct PartitionCfg g_partitionCfg;
|
||||
static struct DeviceDesc *g_lfsDevice = NULL;
|
||||
|
||||
@@ -378,7 +376,6 @@ int LfsReaddir(struct Dir *dir, struct dirent *dent)
|
||||
|
||||
ret = lfs_dir_read(lfs, dirInfo, &lfsInfo);
|
||||
if (ret == TRUE) {
|
||||
pthread_mutex_lock(&g_fsLocalMutex);
|
||||
(void)strncpy_s(dent->d_name, sizeof(dent->d_name), lfsInfo.name, strlen(lfsInfo.name) + 1);
|
||||
if (lfsInfo.type == LFS_TYPE_DIR) {
|
||||
dent->d_type = DT_DIR;
|
||||
@@ -387,7 +384,6 @@ int LfsReaddir(struct Dir *dir, struct dirent *dent)
|
||||
}
|
||||
|
||||
dent->d_reclen = lfsInfo.size;
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
@@ -567,10 +563,7 @@ int LfsClose(struct File *file)
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&g_fsLocalMutex);
|
||||
ret = lfs_file_close((lfs_t *)mp->mData, lfsHandle);
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = (int)LOS_NOK;
|
||||
|
||||
@@ -34,3 +34,19 @@ config FS_VFS
|
||||
|
||||
help
|
||||
Answer Y to enable LiteOS support VFS.
|
||||
|
||||
if FS_VFS
|
||||
config FS_LOCK_TIMEOUT
|
||||
int "Filesystem global lock timeout value in tick. -1 for waiting forever"
|
||||
default -1
|
||||
help
|
||||
The timeout value of getting filesystem lock in tick. -1 for waiting forever
|
||||
|
||||
config FS_SUPPORT_MOUNT_TARGET_RECURSIVE
|
||||
bool "Mount target can be recursive"
|
||||
default n
|
||||
depends on FS_VFS
|
||||
|
||||
help
|
||||
Answer Y to enable LiteOS support VFS mount recursively. For example, "/system/bin".
|
||||
endif
|
||||
|
||||
@@ -139,6 +139,17 @@ int LOS_PartitionFormat(const char *partName, char *fsType, void *data);
|
||||
int LOS_FsRegister(const char *fsType, const struct MountOps *fsMops,
|
||||
const struct FileOps *fsFops, const struct FsManagement *fsMgt);
|
||||
|
||||
/*
|
||||
* @brief Lock the whole filesystem to forbid filesystem access.
|
||||
*
|
||||
* @return Return LOS_NOK if error. Return LOS_OK if seccess.
|
||||
*/
|
||||
int LOS_FsLock(void);
|
||||
|
||||
/*
|
||||
* @brief Unlock the whole filesystem to allow filesystem access.
|
||||
*/
|
||||
void LOS_FsUnlock(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -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:
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/uio.h>
|
||||
#include "errno.h"
|
||||
@@ -49,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"
|
||||
@@ -100,20 +93,20 @@ int PollQueryFd(int fd, struct PollTable *table)
|
||||
UINT32 g_fsMutex;
|
||||
static UINT32 g_dirNum = 0;
|
||||
|
||||
int VfsLock(void)
|
||||
int LOS_FsLock(void)
|
||||
{
|
||||
if (!OsCheckKernelRunning()) {
|
||||
return LOS_OK;
|
||||
}
|
||||
if (LOS_MuxPend(g_fsMutex, LOS_WAIT_FOREVER) != LOS_OK) {
|
||||
PRINT_ERR("VfsLock failed!");
|
||||
if (LOS_MuxPend(g_fsMutex, (UINT32)LOSCFG_FS_LOCK_TIMEOUT) != LOS_OK) {
|
||||
PRINT_ERR("LOS_FsLock failed!");
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
void VfsUnlock(void)
|
||||
void LOS_FsUnlock(void)
|
||||
{
|
||||
if (!OsCheckKernelRunning()) {
|
||||
return;
|
||||
@@ -211,6 +204,28 @@ static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, siz
|
||||
}
|
||||
#endif
|
||||
|
||||
static int VfsPathCheck(const char *path, bool isFile)
|
||||
{
|
||||
size_t len;
|
||||
if ((path == NULL) || (path[0] == '\0')) {
|
||||
VFS_ERRNO_SET(EINVAL);
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
len = strlen(path);
|
||||
if (len >= PATH_MAX) {
|
||||
VFS_ERRNO_SET(ENAMETOOLONG);
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
if (isFile && path[len - 1] == '/') {
|
||||
VFS_ERRNO_SET(EINVAL);
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
static int VfsOpen(const char *path, int flags)
|
||||
{
|
||||
size_t len;
|
||||
@@ -219,12 +234,11 @@ static int VfsOpen(const char *path, int flags)
|
||||
const char *pathInMp = NULL;
|
||||
struct MountPoint *mp = NULL;
|
||||
|
||||
if ((path == NULL) || (path[strlen(path) - 1] == '/')) {
|
||||
VFS_ERRNO_SET(EINVAL);
|
||||
if (VfsPathCheck(path, TRUE) != LOS_OK) {
|
||||
return fd;
|
||||
}
|
||||
|
||||
if (VfsLock() != LOS_OK) {
|
||||
if (LOS_FsLock() != LOS_OK) {
|
||||
VFS_ERRNO_SET(EAGAIN);
|
||||
return fd;
|
||||
}
|
||||
@@ -234,7 +248,7 @@ static int VfsOpen(const char *path, int flags)
|
||||
(mp->mFs->fsFops == NULL) || (mp->mFs->fsFops->open == NULL)) {
|
||||
/* path is not in any mountpoint */
|
||||
VFS_ERRNO_SET(ENOENT);
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return fd;
|
||||
}
|
||||
|
||||
@@ -242,14 +256,14 @@ static int VfsOpen(const char *path, int flags)
|
||||
(flags & (O_CREAT | O_WRONLY | O_RDWR))) {
|
||||
/* can't create file in read only mp */
|
||||
VFS_ERRNO_SET(EACCES);
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return fd;
|
||||
}
|
||||
|
||||
file = VfsFileGet();
|
||||
if (file == NULL) {
|
||||
VFS_ERRNO_SET(ENFILE);
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return fd;
|
||||
}
|
||||
|
||||
@@ -258,7 +272,7 @@ static int VfsOpen(const char *path, int flags)
|
||||
if (file->fullPath == NULL) {
|
||||
VFS_ERRNO_SET(ENOMEM);
|
||||
VfsFilePut(file);
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
(void)strcpy_s((char *)file->fullPath, len, path);
|
||||
@@ -279,7 +293,7 @@ static int VfsOpen(const char *path, int flags)
|
||||
VfsFilePut(file);
|
||||
}
|
||||
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return fd;
|
||||
}
|
||||
|
||||
@@ -294,7 +308,7 @@ static struct File *VfsAttachFile(int fd, UINT32 status)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (VfsLock() != LOS_OK) {
|
||||
if (LOS_FsLock() != LOS_OK) {
|
||||
VFS_ERRNO_SET(EFAULT);
|
||||
return NULL;
|
||||
}
|
||||
@@ -302,13 +316,13 @@ static struct File *VfsAttachFile(int fd, UINT32 status)
|
||||
file = FdToFile(fd);
|
||||
if ((file == NULL) || (file->fMp == NULL)) {
|
||||
VFS_ERRNO_SET(EBADF);
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (file->fStatus != FILE_STATUS_READY) {
|
||||
VFS_ERRNO_SET(EBADF);
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -329,7 +343,7 @@ static struct File *VfsAttachFileWithStatus(int fd, int status)
|
||||
static void VfsDetachFile(const struct File *file)
|
||||
{
|
||||
(void)file;
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
}
|
||||
|
||||
static int VfsClose(int fd)
|
||||
@@ -539,9 +553,11 @@ int open(const char *path, int flags, ...)
|
||||
#endif
|
||||
|
||||
int ret = VfsOpen(path, flags);
|
||||
return MapToPosixRet(ret);
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
#if (LOSCFG_LIBC_NEWLIB == 1)
|
||||
FUNC_ALIAS(open, _open, (const char *path, int flags, ...), int);
|
||||
#endif
|
||||
|
||||
int close(int fd)
|
||||
{
|
||||
@@ -567,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)
|
||||
{
|
||||
@@ -608,9 +626,11 @@ ssize_t read(int fd, void *buff, size_t bytes)
|
||||
ret = VfsRead(fd, buff, bytes);
|
||||
}
|
||||
|
||||
return MapToPosixRet(ret);
|
||||
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)
|
||||
{
|
||||
@@ -640,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)
|
||||
{
|
||||
@@ -661,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)
|
||||
{
|
||||
@@ -669,12 +693,16 @@ int stat(const char *path, struct stat *stat)
|
||||
const char *pathInMp = NULL;
|
||||
int ret = (int)LOS_NOK;
|
||||
|
||||
if ((path == NULL) || (stat == NULL)) {
|
||||
if (VfsPathCheck(path, FALSE) != LOS_OK) {
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
|
||||
if (stat == NULL) {
|
||||
VFS_ERRNO_SET(EINVAL);
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
|
||||
if (VfsLock() != LOS_OK) {
|
||||
if (LOS_FsLock() != LOS_OK) {
|
||||
VFS_ERRNO_SET(EAGAIN);
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
@@ -682,7 +710,7 @@ int stat(const char *path, struct stat *stat)
|
||||
mp = VfsMpFind(path, &pathInMp);
|
||||
if ((mp == NULL) || (pathInMp == NULL) || (*pathInMp == '\0')) {
|
||||
VFS_ERRNO_SET(ENOENT);
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
|
||||
@@ -692,10 +720,12 @@ int stat(const char *path, struct stat *stat)
|
||||
VFS_ERRNO_SET(ENOTSUP);
|
||||
}
|
||||
|
||||
VfsUnlock();
|
||||
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)
|
||||
{
|
||||
@@ -703,12 +733,16 @@ int statfs(const char *path, struct statfs *buf)
|
||||
const char *pathInMp = NULL;
|
||||
int ret = (int)LOS_NOK;
|
||||
|
||||
if ((path == NULL) || (buf == NULL)) {
|
||||
if (VfsPathCheck(path, FALSE) != LOS_OK) {
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
|
||||
if (buf == NULL) {
|
||||
VFS_ERRNO_SET(EINVAL);
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
|
||||
if (VfsLock() != LOS_OK) {
|
||||
if (LOS_FsLock() != LOS_OK) {
|
||||
VFS_ERRNO_SET(EAGAIN);
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
@@ -716,17 +750,17 @@ int statfs(const char *path, struct statfs *buf)
|
||||
mp = VfsMpFind(path, &pathInMp);
|
||||
if ((mp == NULL) || (pathInMp == NULL) || (*pathInMp == '\0')) {
|
||||
VFS_ERRNO_SET(ENOENT);
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
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);
|
||||
}
|
||||
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
|
||||
@@ -736,12 +770,11 @@ int unlink(const char *path)
|
||||
const char *pathInMp = NULL;
|
||||
int ret = (int)LOS_NOK;
|
||||
|
||||
if (path == NULL) {
|
||||
VFS_ERRNO_SET(EINVAL);
|
||||
if (VfsPathCheck(path, FALSE) != LOS_OK) {
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
|
||||
if (VfsLock() != LOS_OK) {
|
||||
if (LOS_FsLock() != LOS_OK) {
|
||||
VFS_ERRNO_SET(EAGAIN);
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
@@ -750,16 +783,18 @@ int unlink(const char *path)
|
||||
if ((mp == NULL) || (pathInMp == NULL) || (*pathInMp == '\0') ||
|
||||
(mp->mFs->fsFops->unlink == NULL)) {
|
||||
VFS_ERRNO_SET(ENOENT);
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
|
||||
ret = mp->mFs->fsFops->unlink(mp, pathInMp);
|
||||
|
||||
VfsUnlock();
|
||||
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)
|
||||
{
|
||||
@@ -769,12 +804,14 @@ int rename(const char *oldpath, const char *newpath)
|
||||
const char *pathInMpNew = NULL;
|
||||
int ret = (int)LOS_NOK;
|
||||
|
||||
if ((oldpath == NULL) || (newpath == NULL)) {
|
||||
VFS_ERRNO_SET(EINVAL);
|
||||
if (VfsPathCheck(oldpath, FALSE) != LOS_OK) {
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
if (VfsPathCheck(newpath, FALSE) != LOS_OK) {
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
|
||||
if (VfsLock() != LOS_OK) {
|
||||
if (LOS_FsLock() != LOS_OK) {
|
||||
VFS_ERRNO_SET(EAGAIN);
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
@@ -783,27 +820,27 @@ int rename(const char *oldpath, const char *newpath)
|
||||
|
||||
if (pathInMpOld == NULL) {
|
||||
VFS_ERRNO_SET(EINVAL);
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
|
||||
if ((mpOld == NULL) || (*pathInMpOld == '\0') ||
|
||||
(mpOld->mFs->fsFops->unlink == NULL)) {
|
||||
VFS_ERRNO_SET(EINVAL);
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
|
||||
mpNew = VfsMpFind(newpath, &pathInMpNew);
|
||||
if ((mpNew == NULL) || (pathInMpNew == NULL) || (*pathInMpNew == '\0') || (mpNew->mFs->fsFops->unlink == NULL)) {
|
||||
VFS_ERRNO_SET(EINVAL);
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
|
||||
if (mpOld != mpNew) {
|
||||
VFS_ERRNO_SET(EXDEV);
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
|
||||
@@ -813,7 +850,7 @@ int rename(const char *oldpath, const char *newpath)
|
||||
VFS_ERRNO_SET(ENOTSUP);
|
||||
}
|
||||
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
|
||||
@@ -850,8 +887,7 @@ DIR *opendir(const char *path)
|
||||
struct Dir *dir = NULL;
|
||||
UINT32 ret;
|
||||
|
||||
if (path == NULL) {
|
||||
VFS_ERRNO_SET(EINVAL);
|
||||
if (VfsPathCheck(path, FALSE) != LOS_OK) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -861,7 +897,7 @@ DIR *opendir(const char *path)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (VfsLock() != LOS_OK) {
|
||||
if (LOS_FsLock() != LOS_OK) {
|
||||
VFS_ERRNO_SET(EAGAIN);
|
||||
LOSCFG_FS_FREE_HOOK(dir);
|
||||
return NULL;
|
||||
@@ -869,7 +905,7 @@ DIR *opendir(const char *path)
|
||||
|
||||
if (g_dirNum >= LOSCFG_MAX_OPEN_DIRS) {
|
||||
VFS_ERRNO_SET(ENFILE);
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
LOSCFG_FS_FREE_HOOK(dir);
|
||||
return NULL;
|
||||
}
|
||||
@@ -877,14 +913,14 @@ DIR *opendir(const char *path)
|
||||
mp = VfsMpFind(path, &pathInMp);
|
||||
if ((mp == NULL) || (pathInMp == NULL)) {
|
||||
VFS_ERRNO_SET(ENOENT);
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
LOSCFG_FS_FREE_HOOK(dir);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mp->mFs->fsFops->opendir == NULL) {
|
||||
VFS_ERRNO_SET(ENOTSUP);
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
LOSCFG_FS_FREE_HOOK(dir);
|
||||
return NULL;
|
||||
}
|
||||
@@ -901,7 +937,7 @@ DIR *opendir(const char *path)
|
||||
dir = NULL;
|
||||
}
|
||||
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return (DIR *)dir;
|
||||
}
|
||||
|
||||
@@ -915,7 +951,7 @@ struct dirent *readdir(DIR *dir)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (VfsLock() != LOS_OK) {
|
||||
if (LOS_FsLock() != LOS_OK) {
|
||||
VFS_ERRNO_SET(EAGAIN);
|
||||
return NULL;
|
||||
}
|
||||
@@ -929,7 +965,7 @@ struct dirent *readdir(DIR *dir)
|
||||
VFS_ERRNO_SET(ENOTSUP);
|
||||
}
|
||||
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -947,7 +983,7 @@ int closedir(DIR *dir)
|
||||
|
||||
mp = d->dMp;
|
||||
|
||||
if (VfsLock() != LOS_OK) {
|
||||
if (LOS_FsLock() != LOS_OK) {
|
||||
VFS_ERRNO_SET(EAGAIN);
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
@@ -966,7 +1002,7 @@ int closedir(DIR *dir)
|
||||
VFS_ERRNO_SET(EBADF);
|
||||
}
|
||||
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
LOSCFG_FS_FREE_HOOK(d);
|
||||
d = NULL;
|
||||
return MapToPosixRet(ret);
|
||||
@@ -979,12 +1015,11 @@ int mkdir(const char *path, mode_t mode)
|
||||
int ret = (int)LOS_NOK;
|
||||
(void)mode;
|
||||
|
||||
if (path == NULL) {
|
||||
VFS_ERRNO_SET(EINVAL);
|
||||
if (VfsPathCheck(path, FALSE) != LOS_OK) {
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
|
||||
if (VfsLock() != LOS_OK) {
|
||||
if (LOS_FsLock() != LOS_OK) {
|
||||
VFS_ERRNO_SET(EAGAIN);
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
@@ -992,7 +1027,7 @@ int mkdir(const char *path, mode_t mode)
|
||||
mp = VfsMpFind(path, &pathInMp);
|
||||
if ((mp == NULL) || (pathInMp == NULL) || (*pathInMp == '\0')) {
|
||||
VFS_ERRNO_SET(ENOENT);
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
|
||||
@@ -1002,7 +1037,7 @@ int mkdir(const char *path, mode_t mode)
|
||||
VFS_ERRNO_SET(ENOTSUP);
|
||||
}
|
||||
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
|
||||
@@ -1017,7 +1052,7 @@ int rmdir(const char *path)
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
|
||||
if (VfsLock() != LOS_OK) {
|
||||
if (LOS_FsLock() != LOS_OK) {
|
||||
VFS_ERRNO_SET(EAGAIN);
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
@@ -1026,13 +1061,13 @@ int rmdir(const char *path)
|
||||
if ((mp == NULL) || (pathInMp == NULL) || (*pathInMp == '\0') ||
|
||||
(mp->mFs->fsFops->rmdir == NULL)) {
|
||||
VFS_ERRNO_SET(ENOENT);
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
|
||||
ret = mp->mFs->fsFops->rmdir(mp, pathInMp);
|
||||
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return MapToPosixRet(ret);
|
||||
}
|
||||
|
||||
@@ -1053,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, ...)
|
||||
{
|
||||
@@ -1064,7 +1101,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
|
||||
@@ -1312,31 +1349,31 @@ ssize_t pread(int fd, void *buff, size_t bytes, off_t off)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (VfsLock() != LOS_OK) {
|
||||
if (LOS_FsLock() != LOS_OK) {
|
||||
VFS_ERRNO_SET(EAGAIN);
|
||||
return MapToPosixRet((int)ret);
|
||||
}
|
||||
|
||||
savepos = lseek(fd, 0, SEEK_CUR);
|
||||
if (savepos == (off_t)-1) {
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return MapToPosixRet((int)ret);
|
||||
}
|
||||
|
||||
pos = lseek(fd, off, SEEK_SET);
|
||||
if (pos == (off_t)-1) {
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return MapToPosixRet((int)ret);
|
||||
}
|
||||
|
||||
ret = read(fd, buff, bytes);
|
||||
pos = lseek(fd, savepos, SEEK_SET);
|
||||
if ((pos == (off_t)-1) && (ret >= 0)) {
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return MapToPosixRet((int)LOS_NOK);
|
||||
}
|
||||
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
|
||||
return MapToPosixRet((int)ret);
|
||||
}
|
||||
@@ -1359,31 +1396,31 @@ ssize_t pwrite(int fd, const void *buff, size_t bytes, off_t off)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (VfsLock() != LOS_OK) {
|
||||
if (LOS_FsLock() != LOS_OK) {
|
||||
VFS_ERRNO_SET(EAGAIN);
|
||||
return MapToPosixRet((int)ret);
|
||||
}
|
||||
|
||||
savepos = lseek(fd, 0, SEEK_CUR);
|
||||
if (savepos == (off_t)-1) {
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return MapToPosixRet((int)ret);
|
||||
}
|
||||
|
||||
pos = lseek(fd, off, SEEK_SET);
|
||||
if (pos == (off_t)-1) {
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return MapToPosixRet((int)ret);
|
||||
}
|
||||
|
||||
ret = write(fd, buff, bytes);
|
||||
pos = lseek(fd, savepos, SEEK_SET);
|
||||
if ((pos == (off_t)-1) && (ret >= 0)) {
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return MapToPosixRet((int)LOS_NOK);
|
||||
}
|
||||
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
|
||||
return MapToPosixRet((int)ret);
|
||||
}
|
||||
|
||||
@@ -41,17 +41,17 @@ struct FsMap *VfsFsMapGet(const char *fsType)
|
||||
{
|
||||
struct FsMap *curr = g_fsMap;
|
||||
|
||||
(void)VfsLock();
|
||||
(void)LOS_FsLock();
|
||||
while (curr != NULL) {
|
||||
if ((curr->fsType != NULL) && (fsType != NULL) &&
|
||||
(strcmp(curr->fsType, fsType) == 0)) {
|
||||
(void)VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return curr;
|
||||
}
|
||||
curr = curr->next;
|
||||
}
|
||||
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -86,11 +86,11 @@ int OsFsRegister(const char *fsType, const struct MountOps *fsMops,
|
||||
newfs->fsMgt = fsMgt;
|
||||
newfs->fsRefs = 0;
|
||||
|
||||
(void)VfsLock();
|
||||
(void)LOS_FsLock();
|
||||
newfs->next = g_fsMap;
|
||||
g_fsMap = newfs;
|
||||
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "vfs_config.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include "limits.h"
|
||||
#include "errno.h"
|
||||
#include "securec.h"
|
||||
#include "vfs_operations.h"
|
||||
@@ -62,14 +63,13 @@ static void MpDeleteFromList(struct MountPoint *mp)
|
||||
}
|
||||
}
|
||||
|
||||
#if (LOSCFG_FS_SUPPORT_MOUNT_TARGET_RECURSIVE == 1)
|
||||
struct MountPoint *VfsMpFind(const char *path, const char **pathInMp)
|
||||
{
|
||||
struct MountPoint *mp = g_mountPoints;
|
||||
struct MountPoint *bestMp = NULL;
|
||||
int bestMatches = 0;
|
||||
if (path == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pathInMp != NULL) {
|
||||
*pathInMp = NULL;
|
||||
}
|
||||
@@ -121,29 +121,85 @@ struct MountPoint *VfsMpFind(const char *path, const char **pathInMp)
|
||||
next:
|
||||
mp = mp->mNext;
|
||||
}
|
||||
|
||||
return bestMp;
|
||||
}
|
||||
#else
|
||||
struct MountPoint *VfsMpFind(const char *path, const char **pathInMp)
|
||||
{
|
||||
struct MountPoint *mp = g_mountPoints;
|
||||
const char *iPath = path;
|
||||
const char *mPath = NULL;
|
||||
const char *target = NULL;
|
||||
|
||||
STATIC struct MountPoint *VfsMountPointInit(const char *target, const char *fsType, unsigned long mountflags)
|
||||
if (pathInMp != NULL) {
|
||||
*pathInMp = NULL;
|
||||
}
|
||||
while (*iPath == '/') {
|
||||
++iPath;
|
||||
}
|
||||
|
||||
while ((mp != NULL) && (mp->mPath != NULL)) {
|
||||
mPath = mp->mPath;
|
||||
target = iPath;
|
||||
|
||||
while (*mPath == '/') {
|
||||
++mPath;
|
||||
}
|
||||
|
||||
while ((*mPath != '\0') && (*mPath != '/') &&
|
||||
(*target != '\0') && (*target != '/')) {
|
||||
if (*mPath != *target) {
|
||||
break;
|
||||
}
|
||||
++mPath;
|
||||
++target;
|
||||
}
|
||||
if (((*mPath == '\0') || (*mPath == '/')) &&
|
||||
((*target == '\0') || (*target == '/'))) {
|
||||
if (pathInMp != NULL) {
|
||||
*pathInMp = path;
|
||||
}
|
||||
return mp;
|
||||
}
|
||||
mp = mp->mNext;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC struct MountPoint *VfsMountPointInit(const char *source, const char *target,
|
||||
const char *fsType, unsigned long mountflags)
|
||||
{
|
||||
struct MountPoint *mp = NULL;
|
||||
const char *pathInMp = NULL;
|
||||
struct FsMap *mFs = NULL;
|
||||
size_t ssize = 0;
|
||||
size_t tsize;
|
||||
|
||||
/* find mp by target, to see if it was mounted */
|
||||
mp = VfsMpFind(target, &pathInMp);
|
||||
if (mp != NULL && pathInMp != NULL) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Find fsMap coresponding to the fsType */
|
||||
mFs = VfsFsMapGet(fsType);
|
||||
if ((mFs == NULL) || (mFs->fsMops == NULL) || (mFs->fsMops->mount == NULL)) {
|
||||
errno = ENODEV;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mp = (struct MountPoint *)LOSCFG_FS_MALLOC_HOOK(sizeof(struct MountPoint));
|
||||
if (source != NULL) {
|
||||
ssize = strlen(source) + 1;
|
||||
}
|
||||
|
||||
tsize = strlen(target) + 1;
|
||||
|
||||
mp = (struct MountPoint *)LOSCFG_FS_MALLOC_HOOK(sizeof(struct MountPoint) + ssize + tsize);
|
||||
if (mp == NULL) {
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -152,7 +208,20 @@ STATIC struct MountPoint *VfsMountPointInit(const char *target, const char *fsTy
|
||||
mp->mRefs = 0;
|
||||
mp->mWriteEnable = (mountflags & MS_RDONLY) ? FALSE : TRUE;
|
||||
mp->mFs->fsRefs++;
|
||||
mp->mNext = g_mountPoints;
|
||||
|
||||
if (source != NULL && strcpy_s((char *)mp + sizeof(struct MountPoint), ssize, source) != EOK) {
|
||||
LOSCFG_FS_FREE_HOOK(mp);
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (strcpy_s((char *)mp + sizeof(struct MountPoint) + ssize, tsize, target) != EOK) {
|
||||
LOSCFG_FS_FREE_HOOK(mp);
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
mp->mDev = source ? (char *)mp + sizeof(struct MountPoint) : NULL;
|
||||
mp->mPath = (char *)mp + sizeof(struct MountPoint) + ssize;
|
||||
|
||||
return mp;
|
||||
}
|
||||
@@ -178,51 +247,47 @@ STATIC int VfsRemount(const char *source, const char *target,
|
||||
return mp->mFs->fsMops->mount(mp, mountflags, data);
|
||||
}
|
||||
|
||||
STATIC int VfsMountPathCheck(const char *target)
|
||||
{
|
||||
/* target must begin with '/', for example /system, /data, etc. */
|
||||
if ((target == NULL) || (target[0] != '/')) {
|
||||
errno = EINVAL;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
if (strlen(target) >= PATH_MAX) {
|
||||
errno = ENAMETOOLONG;
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
int mount(const char *source, const char *target,
|
||||
const char *fsType, unsigned long mountflags,
|
||||
const void *data)
|
||||
{
|
||||
size_t len;
|
||||
int ret;
|
||||
struct MountPoint *mp = NULL;
|
||||
|
||||
/* target must begin with '/', for example /system, /data, etc. */
|
||||
if ((target == NULL) || (target[0] != '/')) {
|
||||
if (VfsMountPathCheck(target) != LOS_OK) {
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
(void)VfsLock();
|
||||
(void)LOS_FsLock();
|
||||
|
||||
if (mountflags & MS_REMOUNT) {
|
||||
ret = VfsRemount(source, target, fsType, mountflags, data);
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
mp = VfsMountPointInit(target, fsType, mountflags);
|
||||
mp = VfsMountPointInit(source, target, fsType, mountflags);
|
||||
if (mp == NULL) {
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
if (source != NULL) {
|
||||
len = strlen(source) + 1;
|
||||
mp->mDev = LOSCFG_FS_MALLOC_HOOK(len);
|
||||
if (mp->mDev == NULL) {
|
||||
LOSCFG_FS_FREE_HOOK(mp);
|
||||
VfsUnlock();
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
(void)strcpy_s((char *)mp->mDev, len, source);
|
||||
}
|
||||
|
||||
len = strlen(target) + 1;
|
||||
mp->mPath = LOSCFG_FS_MALLOC_HOOK(len);
|
||||
if (mp->mPath == NULL) {
|
||||
goto errout;
|
||||
}
|
||||
(void)strcpy_s((char *)mp->mPath, len, target);
|
||||
|
||||
ret = mp->mFs->fsMops->mount(mp, mountflags, data);
|
||||
if (ret != 0) {
|
||||
/* errno is set */
|
||||
@@ -230,30 +295,28 @@ int mount(const char *source, const char *target,
|
||||
goto errout;
|
||||
}
|
||||
|
||||
mp->mNext = g_mountPoints;
|
||||
g_mountPoints = mp;
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return LOS_OK;
|
||||
|
||||
errout:
|
||||
LOSCFG_FS_FREE_HOOK((void *)mp->mPath);
|
||||
LOSCFG_FS_FREE_HOOK((void *)mp->mDev);
|
||||
LOSCFG_FS_FREE_HOOK(mp);
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
int umount(const char *target)
|
||||
{
|
||||
struct MountPoint *mp = NULL;
|
||||
const char *pathInMp = NULL;
|
||||
int ret = (int)LOS_NOK;
|
||||
|
||||
(void)VfsLock();
|
||||
if (target == NULL) {
|
||||
(void)LOS_FsLock();
|
||||
if (VfsMountPathCheck(target) != LOS_OK) {
|
||||
goto errout;
|
||||
}
|
||||
|
||||
mp = VfsMpFind(target, &pathInMp);
|
||||
mp = VfsMpFind(target, NULL);
|
||||
if ((mp == NULL) || (mp->mRefs != 0)) {
|
||||
goto errout;
|
||||
}
|
||||
@@ -272,16 +335,14 @@ int umount(const char *target)
|
||||
/* delete mp from mount list */
|
||||
MpDeleteFromList(mp);
|
||||
mp->mFs->fsRefs--;
|
||||
LOSCFG_FS_FREE_HOOK((void *)mp->mPath);
|
||||
LOSCFG_FS_FREE_HOOK((void *)mp->mDev);
|
||||
LOSCFG_FS_FREE_HOOK(mp);
|
||||
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return LOS_OK;
|
||||
|
||||
errout:
|
||||
PRINT_ERR("umount2 failed, target %s.\n", target);
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
@@ -303,15 +364,14 @@ static void CloseFdsInMp(const struct MountPoint *mp)
|
||||
int umount2(const char *target, int flag)
|
||||
{
|
||||
struct MountPoint *mp = NULL;
|
||||
const char *pathInMp = NULL;
|
||||
int ret = (int)LOS_NOK;
|
||||
|
||||
(void)VfsLock();
|
||||
if (target == NULL) {
|
||||
(void)LOS_FsLock();
|
||||
if (VfsMountPathCheck(target) != LOS_OK) {
|
||||
goto errout;
|
||||
}
|
||||
|
||||
mp = VfsMpFind(target, &pathInMp);
|
||||
mp = VfsMpFind(target, NULL);
|
||||
if ((mp == NULL) || (mp->mRefs != 0) ||
|
||||
(mp->mFs == NULL) || (mp->mFs->fsMops == NULL) ||
|
||||
(mp->mFs->fsMops->umount2 == NULL)) {
|
||||
@@ -332,15 +392,13 @@ int umount2(const char *target, int flag)
|
||||
/* delete mp from mount list */
|
||||
MpDeleteFromList(mp);
|
||||
mp->mFs->fsRefs--;
|
||||
LOSCFG_FS_FREE_HOOK((void *)mp->mPath);
|
||||
LOSCFG_FS_FREE_HOOK((void *)mp->mDev);
|
||||
LOSCFG_FS_FREE_HOOK(mp);
|
||||
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return LOS_OK;
|
||||
|
||||
errout:
|
||||
PRINT_ERR("umount2 failed, target %s.\n", target);
|
||||
VfsUnlock();
|
||||
LOS_FsUnlock();
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
@@ -52,8 +52,6 @@ extern "C" {
|
||||
extern UINT32 g_fsMutex;
|
||||
|
||||
int OsVfsInit(void);
|
||||
int VfsLock(void);
|
||||
void VfsUnlock(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -93,20 +93,25 @@ EXIT:
|
||||
STATIC LmsMemListNode *OsLmsGetPoolNodeFromAddr(UINTPTR addr)
|
||||
{
|
||||
LmsMemListNode *current = NULL;
|
||||
LmsMemListNode *previous = NULL;
|
||||
LOS_DL_LIST *listHead = &g_lmsCheckPoolList;
|
||||
|
||||
if (LOS_ListEmpty(&g_lmsCheckPoolList)) {
|
||||
goto EXIT;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(current, listHead, LmsMemListNode, node) {
|
||||
if ((addr >= current->poolAddr) && (addr < current->poolAddr + current->poolSize)) {
|
||||
return current;
|
||||
if ((addr < current->poolAddr) || (addr >= (current->poolAddr + current->poolSize))) {
|
||||
continue;
|
||||
}
|
||||
if ((previous == NULL) ||
|
||||
((previous->poolAddr <= current->poolAddr) &&
|
||||
((current->poolAddr + current->poolSize) <= (previous->poolAddr + previous->poolSize)))) {
|
||||
previous = current;
|
||||
}
|
||||
}
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
return previous;
|
||||
}
|
||||
|
||||
STATIC LmsMemListNode *OsLmsCheckPoolCreate(VOID)
|
||||
@@ -136,18 +141,12 @@ UINT32 LOS_LmsCheckPoolAdd(const VOID *pool, UINT32 size)
|
||||
|
||||
LMS_LOCK(intSave);
|
||||
|
||||
lmsPoolNode = OsLmsGetPoolNodeFromAddr((UINTPTR)pool);
|
||||
if (lmsPoolNode != NULL) { /* if pool range already on checklist */
|
||||
if (lmsPoolNode->poolAddr != (UINTPTR)pool) { /* pool is a subset of lmsPoolNode->poolAddr */
|
||||
/* do not add it again, just return */
|
||||
PRINT_DEBUG("[LMS]pool %p already on lms checklist !\n", pool);
|
||||
LMS_UNLOCK(intSave);
|
||||
return size; /* return size indicate the shadow memory init successful */
|
||||
} else { /* Re-initialize the same pool, maybe with different size */
|
||||
/* delete the old node, then add a new one */
|
||||
lmsPoolNode->used = LMS_POOL_UNUSED;
|
||||
LOS_ListDelete(&(lmsPoolNode->node));
|
||||
}
|
||||
lmsPoolNode = OsLmsGetPoolNode(pool);
|
||||
if (lmsPoolNode != NULL) { /* if pool already on checklist */
|
||||
/* Re-initialize the same pool, maybe with different size */
|
||||
/* delete the old node, then add a new one */
|
||||
lmsPoolNode->used = LMS_POOL_UNUSED;
|
||||
LOS_ListDelete(&(lmsPoolNode->node));
|
||||
}
|
||||
|
||||
lmsPoolNode = OsLmsCheckPoolCreate();
|
||||
@@ -163,7 +162,7 @@ UINT32 LOS_LmsCheckPoolAdd(const VOID *pool, UINT32 size)
|
||||
lmsPoolNode->shadowStart = (UINTPTR)poolAddr + realSize;
|
||||
lmsPoolNode->shadowSize = poolAddr + size - lmsPoolNode->shadowStart;
|
||||
/* init shadow value */
|
||||
(VOID)memset((VOID *)lmsPoolNode->shadowStart, LMS_SHADOW_AFTERFREE_U8, lmsPoolNode->shadowSize);
|
||||
(VOID)memset_s((VOID *)lmsPoolNode->shadowStart, lmsPoolNode->shadowSize, LMS_SHADOW_AFTERFREE_U8, lmsPoolNode->shadowSize);
|
||||
|
||||
LOS_ListAdd(&g_lmsCheckPoolList, &(lmsPoolNode->node));
|
||||
|
||||
@@ -193,10 +192,11 @@ RELEASE:
|
||||
|
||||
VOID OsLmsInit(VOID)
|
||||
{
|
||||
(VOID)memset(g_lmsCheckPoolArray, 0, sizeof(g_lmsCheckPoolArray));
|
||||
(VOID)memset_s(g_lmsCheckPoolArray, sizeof(g_lmsCheckPoolArray), 0, sizeof(g_lmsCheckPoolArray));
|
||||
LOS_ListInit(&g_lmsCheckPoolList);
|
||||
static LmsHook hook = {
|
||||
.init = LOS_LmsCheckPoolAdd,
|
||||
.deInit = LOS_LmsCheckPoolDel,
|
||||
.mallocMark = OsLmsLosMallocMark,
|
||||
.freeMark = OsLmsLosFreeMark,
|
||||
.simpleMark = OsLmsSimpleMark,
|
||||
@@ -609,7 +609,7 @@ VOID OsLmsReportError(UINTPTR p, UINT32 size, UINT32 errMod)
|
||||
|
||||
LMS_LOCK(intSave);
|
||||
g_checkDepth += 1;
|
||||
(VOID)memset(&info, 0, sizeof(LmsAddrInfo));
|
||||
(VOID)memset_s(&info, sizeof(LmsAddrInfo), 0, sizeof(LmsAddrInfo));
|
||||
|
||||
PRINT_ERR("***** Kernel Address Sanitizer Error Detected Start *****\n");
|
||||
|
||||
|
||||
@@ -95,6 +95,7 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
UINT32 (*init)(const VOID *pool, UINT32 size);
|
||||
VOID (*deInit)(const VOID *pool);
|
||||
VOID (*mallocMark)(const VOID *curNodeStart, const VOID *nextNodeStart, UINT32 nodeHeadSize);
|
||||
VOID (*freeMark)(const VOID *curNodeStart, const VOID *nextNodeStart, UINT32 nodeHeadSize);
|
||||
VOID (*simpleMark)(UINTPTR startAddr, UINTPTR endAddr, UINT32 value);
|
||||
@@ -133,4 +134,4 @@ extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_handle_no_return(VOID);
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_LMS_PRI_H */
|
||||
#endif /* _LOS_LMS_PRI_H */
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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" ]
|
||||
|
||||
@@ -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" ]
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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") {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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 -= tm->__tm_gmtoff; // sub time zone to get UTC time
|
||||
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, tmptr->__tm_gmtoff, 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -453,7 +453,7 @@ extern UINT32 LOS_QueueCreateStatic(const CHAR *queueName,
|
||||
* first.</li>
|
||||
* <li>bufferAddr stores the obtained data.</li>
|
||||
* <li>Do not read or write a queue in unblocking modes such as an interrupt.</li>
|
||||
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
|
||||
* <li>This API cannot be called before the kernel is initialized.</li>
|
||||
* <li>The argument timeOut is a relative time.</li>
|
||||
* </ul>
|
||||
*
|
||||
@@ -498,7 +498,7 @@ extern UINT32 LOS_QueueReadCopy(UINT32 queueID,
|
||||
* <ul>
|
||||
* <li>The specific queue should be created firstly.</li>
|
||||
* <li>Do not read or write a queue in unblocking modes such as interrupt.</li>
|
||||
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
|
||||
* <li>This API cannot be called before the kernel is initialized.</li>
|
||||
* <li>The data to be written is of the size specified by bufferSize and is stored at the address specified by
|
||||
* BufferAddr.</li>
|
||||
* <li>The argument timeOut is a relative time.</li>
|
||||
@@ -547,7 +547,7 @@ extern UINT32 LOS_QueueWriteCopy(UINT32 queueID,
|
||||
* read first.</li>
|
||||
* <li>bufferAddr stores the obtained data address.</li>
|
||||
* <li>Do not read or write a queue in unblocking modes such as an interrupt.</li>
|
||||
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
|
||||
* <li>This API cannot be called before the kernel is initialized.</li>
|
||||
* <li>The argument timeOut is a relative time.</li>
|
||||
* <li>The bufferSize is not really used in LOS_QueueRead, because the interface is only used to
|
||||
* obtain the address of data.</li>
|
||||
@@ -592,7 +592,7 @@ extern UINT32 LOS_QueueRead(UINT32 queueID,
|
||||
* <ul>
|
||||
* <li>The specific queue should be created firstly.</li>
|
||||
* <li>Do not read or write a queue in unblocking modes such as an interrupt.</li>
|
||||
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
|
||||
* <li>This API cannot be called before the kernel is initialized.</li>
|
||||
* <li>The address of the data of the size specified by bufferSize and stored at the address specified by
|
||||
* BufferAddr is to be written.</li>
|
||||
* <li>The argument timeOut is a relative time.</li>
|
||||
@@ -639,7 +639,7 @@ extern UINT32 LOS_QueueWrite(UINT32 queueID,
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>Do not read or write a queue in unblocking modes such as an interrupt.</li>
|
||||
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
|
||||
* <li>This API cannot be called before the kernel is initialized.</li>
|
||||
* <li>The address of the data of the size specified by bufferSize and stored at the address specified by
|
||||
* BufferAddr is to be written.</li>
|
||||
* <li>The argument timeOut is a relative time.</li>
|
||||
@@ -686,7 +686,7 @@ extern UINT32 LOS_QueueWriteHead(UINT32 queueID,
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>Do not read or write a queue in unblocking modes such as an interrupt.</li>
|
||||
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
|
||||
* <li>This API cannot be called before the kernel is initialized.</li>
|
||||
* <li>The address of the data of the size specified by bufferSize and stored at the address specified by
|
||||
* BufferAddr is to be written.</li>
|
||||
* <li>The argument timeOut is a relative time.</li>
|
||||
@@ -889,7 +889,7 @@ extern LosQueueCB *g_allQueue;
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>Do not alloc memory in unblocking modes such as interrupt.</li>
|
||||
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
|
||||
* <li>This API cannot be called before the kernel is initialized.</li>
|
||||
* <li>The argument timeOut is a relative time.</li>
|
||||
* </ul>
|
||||
*
|
||||
@@ -913,7 +913,7 @@ extern VOID *OsQueueMailAlloc(UINT32 queueID, VOID *mailPool, UINT32 timeOut);
|
||||
* This API is used to free a stationary memory for a mail according to queueID.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
|
||||
* <li>This API cannot be called before the kernel is initialized.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param queueID [IN] Queue ID. The value range is [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
|
||||
|
||||
@@ -474,7 +474,7 @@ RETRY:
|
||||
OsMemFreeNodeAdd(pool, (struct OsMemFreeNodeHead *)newNode);
|
||||
|
||||
endNode = OS_MEM_END_NODE(newNode, size);
|
||||
(VOID)memset(endNode, 0, sizeof(*endNode));
|
||||
(VOID)memset_s(endNode, sizeof(*endNode), 0, sizeof(*endNode));
|
||||
endNode->ptr.next = NULL;
|
||||
OS_MEM_SET_MAGIC(endNode);
|
||||
OsMemSentinelNodeSet(endNode, NULL, 0);
|
||||
@@ -584,7 +584,8 @@ STATIC INLINE VOID OsMemLeakCheckInfoRecord(struct OsMemNodeHead *node)
|
||||
|
||||
STATIC INLINE VOID OsMemLeakCheckInit(VOID)
|
||||
{
|
||||
(VOID)memset(g_leakCheckRecord, 0, sizeof(struct OsMemLeakCheckInfo) * LOSCFG_MEM_LEAKCHECK_RECORD_MAX_NUM);
|
||||
(VOID)memset_s(g_leakCheckRecord, sizeof(struct OsMemLeakCheckInfo) * LOSCFG_MEM_LEAKCHECK_RECORD_MAX_NUM,
|
||||
0, sizeof(struct OsMemLeakCheckInfo) * LOSCFG_MEM_LEAKCHECK_RECORD_MAX_NUM);
|
||||
g_leakCheckRecordCnt = 0;
|
||||
}
|
||||
|
||||
@@ -858,6 +859,9 @@ STATIC UINT32 OsMemPoolInit(VOID *pool, UINT32 size)
|
||||
struct OsMemPoolHead *poolHead = (struct OsMemPoolHead *)pool;
|
||||
struct OsMemNodeHead *newNode = NULL;
|
||||
struct OsMemNodeHead *endNode = NULL;
|
||||
|
||||
(VOID)memset_s(poolHead, size, 0, sizeof(struct OsMemPoolHead));
|
||||
|
||||
#ifdef LOSCFG_KERNEL_LMS
|
||||
UINT32 resize = 0;
|
||||
if (g_lms != NULL) {
|
||||
@@ -869,7 +873,6 @@ STATIC UINT32 OsMemPoolInit(VOID *pool, UINT32 size)
|
||||
size = (resize == 0) ? size : resize;
|
||||
}
|
||||
#endif
|
||||
(VOID)memset(poolHead, 0, sizeof(struct OsMemPoolHead));
|
||||
|
||||
poolHead->info.pool = pool;
|
||||
poolHead->info.totalSize = size;
|
||||
@@ -907,9 +910,14 @@ STATIC UINT32 OsMemPoolInit(VOID *pool, UINT32 size)
|
||||
}
|
||||
|
||||
#if (LOSCFG_MEM_MUL_POOL == 1)
|
||||
STATIC VOID OsMemPoolDeinit(VOID *pool)
|
||||
STATIC VOID OsMemPoolDeInit(VOID *pool, UINT32 size)
|
||||
{
|
||||
(VOID)memset(pool, 0, sizeof(struct OsMemPoolHead));
|
||||
#ifdef LOSCFG_KERNEL_LMS
|
||||
if (g_lms != NULL) {
|
||||
g_lms->deInit(pool);
|
||||
}
|
||||
#endif
|
||||
(VOID)memset_s(pool, size, 0, sizeof(struct OsMemPoolHead));
|
||||
}
|
||||
|
||||
STATIC UINT32 OsMemPoolAdd(VOID *pool, UINT32 size)
|
||||
@@ -988,7 +996,7 @@ UINT32 LOS_MemInit(VOID *pool, UINT32 size)
|
||||
|
||||
#if (LOSCFG_MEM_MUL_POOL == 1)
|
||||
if (OsMemPoolAdd(pool, size)) {
|
||||
(VOID)OsMemPoolDeinit(pool);
|
||||
(VOID)OsMemPoolDeInit(pool, size);
|
||||
return LOS_NOK;
|
||||
}
|
||||
#endif
|
||||
@@ -1001,17 +1009,23 @@ UINT32 LOS_MemInit(VOID *pool, UINT32 size)
|
||||
#if (LOSCFG_MEM_MUL_POOL == 1)
|
||||
UINT32 LOS_MemDeInit(VOID *pool)
|
||||
{
|
||||
if (pool == NULL) {
|
||||
struct OsMemPoolHead *tmpPool = (struct OsMemPoolHead *)pool;
|
||||
|
||||
if (tmpPool == NULL) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if (OsMemPoolDelete(pool)) {
|
||||
if ((tmpPool->info.pool != pool) || (tmpPool->info.totalSize <= OS_MEM_MIN_POOL_SIZE)) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
OsMemPoolDeinit(pool);
|
||||
if (OsMemPoolDelete(tmpPool)) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_MEM_DEINIT, pool);
|
||||
OsMemPoolDeInit(tmpPool, tmpPool->info.totalSize);
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_MEM_DEINIT, tmpPool);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
@@ -1950,7 +1964,7 @@ UINT32 LOS_MemInfoGet(VOID *pool, LOS_MEM_POOL_STATUS *poolStatus)
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
(VOID)memset(poolStatus, 0, sizeof(LOS_MEM_POOL_STATUS));
|
||||
(VOID)memset_s(poolStatus, sizeof(LOS_MEM_POOL_STATUS), 0, sizeof(LOS_MEM_POOL_STATUS));
|
||||
|
||||
OsAllMemNodeDoHandle(pool, OsMemNodeInfoGetHandle, (VOID *)poolStatus);
|
||||
|
||||
@@ -2232,7 +2246,7 @@ STATIC VOID OsMemExcInfoGetSub(struct OsMemPoolHead *pool, MemInfoCB *memExcInfo
|
||||
UINT32 taskID = OS_TASK_ERRORID;
|
||||
UINT32 intSave = 0;
|
||||
|
||||
(VOID)memset(memExcInfo, 0, sizeof(MemInfoCB));
|
||||
(VOID)memset_s(memExcInfo, sizeof(MemInfoCB), 0, sizeof(MemInfoCB));
|
||||
|
||||
MEM_LOCK(pool, intSave);
|
||||
memExcInfo->type = MEM_MANG_MEMORY;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#include "osTest.h"
|
||||
#include "It_los_event.h"
|
||||
|
||||
static VOID TaskF01()
|
||||
static VOID TaskF01(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ static VOID HwiF01(VOID)
|
||||
|
||||
return;
|
||||
}
|
||||
#undef HWI_NUM_INT0
|
||||
#define HWI_NUM_INT0 HWI_NUM_TEST1
|
||||
static UINT32 Testcase(VOID)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -42,7 +42,7 @@ static UINT32 Testcase(VOID)
|
||||
|
||||
g_testQueueID01 = LOSCFG_BASE_IPC_QUEUE_LIMIT - 1;
|
||||
|
||||
ret = LOS_QueueCreateStatic("Q1", QUEUE_OVERSIZE_NUM, &g_testQueueID01, buff3, 0, 0xFFFF);
|
||||
ret = LOS_QueueCreateStatic("Q1", QUEUE_OVERSIZE_NUM, &g_testQueueID01, (UINT8 *)buff3, 0, 0xFFFF);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_ERRNO_QUEUE_SIZE_TOO_BIG, ret, EXIT);
|
||||
|
||||
ret = LOS_QueueWrite(g_testQueueID01, &buff1, QUEUE_BASE_MSGSIZE, 0);
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -48,7 +48,7 @@ static VOID Case1(UINT32 arg)
|
||||
return;
|
||||
}
|
||||
|
||||
static VOID Case2()
|
||||
static VOID Case2(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ static VOID Case1(UINT32 arg)
|
||||
return;
|
||||
}
|
||||
|
||||
static VOID Case2()
|
||||
static VOID Case2(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 uwloop = 1000;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -51,7 +51,7 @@ EXIT:
|
||||
LOS_TaskDelete(g_testTaskID01);
|
||||
}
|
||||
|
||||
static VOID Case2()
|
||||
static VOID Case2(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -62,10 +62,10 @@ static UINT32 Testcase(VOID)
|
||||
OS_SWTMR_ROUSES_IGNORE, OS_SWTMR_ALIGN_SENSITIVE
|
||||
#endif
|
||||
);
|
||||
id2 = swtmrId1;
|
||||
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
id2 = swtmrId1;
|
||||
ICUNIT_GOTO_NOT_EQUAL(id1, id2, swtmrId1, EXIT);
|
||||
|
||||
ret = LOS_SwtmrDelete(id1);
|
||||
|
||||
@@ -69,7 +69,7 @@ static UINT32 Testcase(VOID)
|
||||
);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
id2 = swtmrId1;
|
||||
ICUNIT_GOTO_NOT_EQUAL(id1, id2, swtmrId1, EXIT);
|
||||
ICUNIT_GOTO_NOT_EQUAL(id1, id2, swtmrId1, EXIT1);
|
||||
|
||||
ret = LOS_SwtmrDelete(id1);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
@@ -78,9 +78,10 @@ static UINT32 Testcase(VOID)
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
|
||||
return LOS_OK;
|
||||
EXIT1:
|
||||
LOS_SwtmrDelete(id2);
|
||||
EXIT:
|
||||
LOS_SwtmrDelete(id1);
|
||||
LOS_SwtmrDelete(id2);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
|
||||
#ifndef IT_POSIX_QUEUE_H
|
||||
#define IT_POSIX_QUEUE_H
|
||||
#undef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <mqueue.h>
|
||||
@@ -40,6 +42,7 @@
|
||||
#include <signal.h>
|
||||
#include <osTest.h>
|
||||
#include "pthread.h"
|
||||
#include "unistd.h"
|
||||
|
||||
#define MAXMSG5 5
|
||||
#define MSGLEN 10
|
||||
@@ -57,18 +60,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 +95,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];
|
||||
|
||||
@@ -58,7 +58,6 @@ static UINT32 Testcase(VOID)
|
||||
return LOS_OK;
|
||||
EXIT1:
|
||||
mq_close(mqueue);
|
||||
EXIT:
|
||||
mq_unlink(mqname);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
@@ -35,9 +35,6 @@ static UINT32 Testcase(VOID)
|
||||
CHAR msgrv1[MQUEUE_STANDARD_NAME_LENGTH] = {0};
|
||||
struct mq_attr attr = {0};
|
||||
INT32 ret = 0;
|
||||
INT32 i;
|
||||
pthread_t pthread1;
|
||||
pthread_t pthread2;
|
||||
mqd_t mqueue1;
|
||||
mqd_t mqueue2;
|
||||
struct timespec ts;
|
||||
@@ -59,7 +56,6 @@ static UINT32 Testcase(VOID)
|
||||
ret = mq_timedreceive(mqueue1, msgrv1, MQUEUE_STANDARD_NAME_LENGTH, NULL, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
|
||||
EXIT:
|
||||
mq_close(mqueue1);
|
||||
mq_close(mqueue2);
|
||||
mq_unlink(mqname);
|
||||
|
||||
@@ -34,8 +34,6 @@ static UINT32 Testcase(VOID)
|
||||
INT32 ret;
|
||||
CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = "";
|
||||
mqd_t mqueue;
|
||||
struct sigevent ev;
|
||||
struct sigaction act;
|
||||
|
||||
ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1,
|
||||
"/mq013_%d", LOS_CurTaskIDGet());
|
||||
|
||||
@@ -34,7 +34,6 @@ static UINT32 Testcase(VOID)
|
||||
INT32 ret;
|
||||
CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = {0};
|
||||
mqd_t mqueue;
|
||||
struct sigevent se;
|
||||
|
||||
ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1,
|
||||
"/mq021_%d", LOS_CurTaskIDGet());
|
||||
|
||||
@@ -55,7 +55,7 @@ EXIT:
|
||||
|
||||
static VOID *PthreadF02(VOID *argument)
|
||||
{
|
||||
INT32 j, ret;
|
||||
INT32 ret;
|
||||
|
||||
CHAR msgrcd[MQUEUE_STANDARD_NAME_LENGTH] = "";
|
||||
|
||||
@@ -82,8 +82,6 @@ static UINT32 Testcase(VOID)
|
||||
{
|
||||
pthread_t newTh1, newTh2;
|
||||
UINT32 ret;
|
||||
CHAR msgrcd[MQUEUE_STANDARD_NAME_LENGTH] = "";
|
||||
const CHAR *msgptr = MQUEUE_SEND_STRING_TEST;
|
||||
struct mq_attr attr = {0};
|
||||
pthread_attr_t attr1;
|
||||
|
||||
|
||||
@@ -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, \
|
||||
|
||||
@@ -36,7 +36,7 @@ static VOID *PthreadF01(VOID *argument)
|
||||
|
||||
g_testCount = 1;
|
||||
|
||||
TestAssertWaitDelay(&g_testCount, 3); // 3, Here, assert the g_testCount.
|
||||
TestAssertWaitDelay((UINT32 *)&g_testCount, 3); // 3, Here, assert the g_testCount.
|
||||
|
||||
ret = mq_send(g_gqueue, msgptr, strlen(msgptr), 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
@@ -104,7 +104,7 @@ static UINT32 Testcase(VOID)
|
||||
ret = pthread_create(&newTh1, &attr1, PthreadF01, NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1);
|
||||
|
||||
TestAssertWaitDelay(&g_testCount, 1);
|
||||
TestAssertWaitDelay((UINT32 *)&g_testCount, 1);
|
||||
|
||||
ret = PosixPthreadInit(&attr1, MQUEUE_PTHREAD_PRIORITY_TEST2);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2);
|
||||
@@ -115,7 +115,7 @@ static UINT32 Testcase(VOID)
|
||||
ret = MqueueTaskDelay(10); // 10, Set delay time.
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2);
|
||||
|
||||
TestAssertWaitDelay(&g_testCount, 4); // 4, Here, assert the g_testCount.
|
||||
TestAssertWaitDelay((UINT32 *)&g_testCount, 4); // 4, Here, assert the g_testCount.
|
||||
|
||||
ret = PosixPthreadDestroy(&attr1, newTh2);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1);
|
||||
|
||||
@@ -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, \
|
||||
|
||||
@@ -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, \
|
||||
|
||||
@@ -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, \
|
||||
|
||||
@@ -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, \
|
||||
|
||||
@@ -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, \
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -37,7 +37,7 @@ static UINT32 Testcase(VOID)
|
||||
pthread_mutex_t mutex = TEST_MUTEX_INIT;
|
||||
|
||||
sem_t sem;
|
||||
int pshared;
|
||||
int pshared = 0;
|
||||
|
||||
ret = pthread_mutexattr_init(&mta);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#define THREAD_NUM 5
|
||||
#define LOOPS 4
|
||||
|
||||
static g_value;
|
||||
static int g_value;
|
||||
static pthread_mutex_t g_mutex036 = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/* pthread_mutex_lock 1-1.c
|
||||
|
||||
@@ -28,13 +28,17 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#undef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include "It_posix_mutex.h"
|
||||
#include "unistd.h"
|
||||
|
||||
#define THREAD_NUM 6
|
||||
#define LOOPS 3
|
||||
|
||||
static pthread_mutex_t g_mutex040 = PTHREAD_MUTEX_INITIALIZER;
|
||||
static g_value;
|
||||
static int g_value;
|
||||
|
||||
static void *TaskF01(void *parm)
|
||||
{
|
||||
|
||||
@@ -38,7 +38,7 @@ pthread_t TestPthreadSelf(void)
|
||||
{
|
||||
pthread_t tid = pthread_self();
|
||||
if (tid == 0) {
|
||||
tid = ((LosTaskCB *)(OsCurrTaskGet()))->taskID;
|
||||
tid = (pthread_t)(((LosTaskCB *)(OsCurrTaskGet()))->taskID);
|
||||
}
|
||||
return tid;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#undef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <securec.h>
|
||||
#include "osTest.h"
|
||||
#include "pthread.h"
|
||||
|
||||
@@ -102,7 +102,7 @@ char *g_strType[] = {
|
||||
"FUNCTION", "PRESSURE", "PERFORMANCE"
|
||||
};
|
||||
|
||||
iUINT32 ICunitRunF()
|
||||
iUINT32 ICunitRunF(void)
|
||||
{
|
||||
iUINT32 idx, idx1;
|
||||
ICUNIT_CASE_S *psubCaseArray;
|
||||
|
||||
@@ -231,7 +231,7 @@ void TestCmsis2(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
VOID TestTaskEntry()
|
||||
VOID TestTaskEntry(VOID)
|
||||
{
|
||||
PRINTF("\t\n --- Test Start --- \n\n");
|
||||
ICunitInit();
|
||||
|
||||
@@ -60,15 +60,20 @@ static_library("posix_test") {
|
||||
"src/time/time_func_test_01.c",
|
||||
]
|
||||
|
||||
if (defined(LOSCFG_SUPPORT_FATFS) || defined(LOSCFG_SUPPORT_LITTLEFS)) {
|
||||
deps = [ "src/fs" ]
|
||||
}
|
||||
|
||||
include_dirs = [
|
||||
"//test/xts/tools/hctest/include",
|
||||
"src",
|
||||
]
|
||||
if (defined(LOSCFG_SUPPORT_FATFS) || defined(LOSCFG_SUPPORT_LITTLEFS)) {
|
||||
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" ]
|
||||
}
|
||||
|
||||
@@ -95,7 +95,8 @@ LITE_TEST_CASE(PosixSysFuncTestSuite, testOsSysStrerror001, Function | MediumTes
|
||||
LOG("strerror(10) = %s\n", strerror(10));
|
||||
TEST_ASSERT_EQUAL_STRING("No children", strerror(10));
|
||||
#endif
|
||||
|
||||
|
||||
return LOS_OK;
|
||||
};
|
||||
|
||||
RUN_TEST_SUITE(PosixSysFuncTestSuite);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2023-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:
|
||||
@@ -26,12 +26,36 @@
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
if LIBC_ICCARM
|
||||
static_library("fs") {
|
||||
sources = [
|
||||
"api/posix_fs_access_test.c",
|
||||
"api/posix_fs_close_test.c",
|
||||
"api/posix_fs_closedir_test.c",
|
||||
"api/posix_fs_fstat_test.c",
|
||||
"api/posix_fs_fsync_test.c",
|
||||
"api/posix_fs_ftruncate_test.c",
|
||||
"api/posix_fs_lseek_test.c",
|
||||
"api/posix_fs_mkdir_test.c",
|
||||
"api/posix_fs_open_test.c",
|
||||
"api/posix_fs_opendir_test.c",
|
||||
"api/posix_fs_pread_test.c",
|
||||
"api/posix_fs_pwrite_test.c",
|
||||
"api/posix_fs_read_test.c",
|
||||
"api/posix_fs_readdir_test.c",
|
||||
"api/posix_fs_rename_test.c",
|
||||
"api/posix_fs_rmdir_test.c",
|
||||
"api/posix_fs_stat_test.c",
|
||||
"api/posix_fs_statfs_test.c",
|
||||
"api/posix_fs_unlink_test.c",
|
||||
"api/posix_fs_write_test.c",
|
||||
"full/posix_fs_full_test.c",
|
||||
"posix_fs_func_test.c",
|
||||
"pressure/posix_fs_pressure_test.c",
|
||||
]
|
||||
|
||||
config LIBC_ICCARM_MALLOC
|
||||
bool "Enable POSIX malloc/free API support"
|
||||
default y
|
||||
help
|
||||
This enables POSIX malloc/free related APIs.
|
||||
|
||||
endif # LIBC_ICCARM
|
||||
include_dirs = [
|
||||
".",
|
||||
"../",
|
||||
"../../../../include",
|
||||
]
|
||||
}
|
||||
90
testsuites/unittest/posix/src/fs/api/posix_fs_access_test.c
Normal file
90
testsuites/unittest/posix/src/fs/api/posix_fs_access_test.c
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2023-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:
|
||||
*
|
||||
* 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 "posix_fs_test.h"
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_ACCESS_OK
|
||||
* @tc.name access
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsAccessOK, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = FILE1;
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR, TEST_MODE_HIGH);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = access(tmpFileName, F_OK);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
#if (LOSCFG_SUPPORT_FATFS == 1)
|
||||
ret = access(tmpFileName, R_OK);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
ret = access(tmpFileName, W_OK);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
ret = access(tmpFileName, X_OK);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
#endif
|
||||
|
||||
EXIT:
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_ACCESS_EINVAL
|
||||
* @tc.name access
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsAccessEINVAL, Function | MediumTest | Level1)
|
||||
{
|
||||
char *tmpFileName = NULL;
|
||||
|
||||
int32_t ret = access(tmpFileName, F_OK);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
void PosixFsAccessTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(TestFsAccessOK);
|
||||
RUN_ONE_TESTCASE(TestFsAccessEINVAL);
|
||||
}
|
||||
@@ -1,6 +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) 2023-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:
|
||||
@@ -29,28 +28,31 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef COMMON_TEST_H
|
||||
#define COMMON_TEST_H
|
||||
#include "posix_fs_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
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_CLOSE_OK
|
||||
* @tc.name close
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsCloseOK, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = FILE1;
|
||||
|
||||
#define DELAY_TICKS_1 1
|
||||
#define DELAY_TICKS_5 5
|
||||
#define DELAY_TICKS_10 10
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
#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
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
#endif
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
void PosixFsCloseTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(TestFsCloseOK);
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2023-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:
|
||||
*
|
||||
* 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 "posix_fs_test.h"
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_CLOSEDIR_OK
|
||||
* @tc.name closedir
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsClosedirOK, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
DIR *dir = opendir(TEST_ROOT);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(dir, NULL, dir);
|
||||
|
||||
ret = closedir(dir);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_CLOSEDIR_EBADF
|
||||
* @tc.name closedir
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsClosedirEBADF, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
DIR *dir = opendir(TEST_ROOT);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(dir, NULL, dir);
|
||||
|
||||
ret = closedir(NULL);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
ret = closedir(dir);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
EXIT:
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
void PosixFsClosedirTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(TestFsClosedirOK);
|
||||
RUN_ONE_TESTCASE(TestFsClosedirEBADF);
|
||||
}
|
||||
181
testsuites/unittest/posix/src/fs/api/posix_fs_fstat_test.c
Normal file
181
testsuites/unittest/posix/src/fs/api/posix_fs_fstat_test.c
Normal file
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* Copyright (c) 2023-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:
|
||||
*
|
||||
* 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 "posix_fs_test.h"
|
||||
#include "vfs_config.h"
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FSTAT_OK
|
||||
* @tc.name fstat
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFstatOK, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
struct stat buf = { 0 };
|
||||
const char tmpFileName[TEST_BUF_SIZE] = FILE1;
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = fstat(fd, &buf);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FSTAT_EBADF001
|
||||
* @tc.name fstat
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFstatEBADF001, Function | MediumTest | Level1)
|
||||
{
|
||||
struct stat buf = { 0 };
|
||||
|
||||
int32_t ret = fstat(-1, &buf); /* -1, bad fd */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FSTAT_EBADF002
|
||||
* @tc.name fstat
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFstatEBADF002, Function | MediumTest | Level1)
|
||||
{
|
||||
struct stat buf = { 0 };
|
||||
|
||||
int32_t ret = fstat(ERROR_CONFIG_NFILE_DESCRIPTORS, &buf);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FSTAT_EBADF003
|
||||
* @tc.name fstat
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFstatEBADF003, Function | MediumTest | Level1)
|
||||
{
|
||||
struct stat buf = { 0 };
|
||||
|
||||
int32_t ret = fstat(0, &buf); /* 0, used for stdin */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = fstat(1, &buf); /* 1, used for stdout */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = fstat(2, &buf); /* 2, used for stderr */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FSTAT_EINVAL
|
||||
* @tc.name fstat
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFstatEINVAL, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
struct stat *buf = NULL;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = FILE1;
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = fstat(fd, buf);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FSTAT_ENOENT
|
||||
* @tc.name fstat
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFstatENOENT, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
struct stat buf = { 0 };
|
||||
const char tmpFileName[TEST_BUF_SIZE] = FILE1;
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
struct MountPoint *mountBak = g_mountPoints;
|
||||
g_mountPoints = NULL;
|
||||
ret = fstat(fd, &buf);
|
||||
g_mountPoints = mountBak;
|
||||
ICUNIT_ASSERT_EQUAL(errno, ENOENT, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
void PosixFsFstatTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(TestFsFstatOK);
|
||||
RUN_ONE_TESTCASE(TestFsFstatEBADF001);
|
||||
RUN_ONE_TESTCASE(TestFsFstatEBADF002);
|
||||
RUN_ONE_TESTCASE(TestFsFstatEBADF003);
|
||||
RUN_ONE_TESTCASE(TestFsFstatEINVAL);
|
||||
RUN_ONE_TESTCASE(TestFsFstatENOENT);
|
||||
}
|
||||
115
testsuites/unittest/posix/src/fs/api/posix_fs_fsync_test.c
Normal file
115
testsuites/unittest/posix/src/fs/api/posix_fs_fsync_test.c
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (c) 2023-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:
|
||||
*
|
||||
* 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 "posix_fs_test.h"
|
||||
#include "vfs_config.h"
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FSYNC_OK
|
||||
* @tc.name fsync
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFsyncOK, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = FILE1;
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = fsync(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FSYNC_EBADF001
|
||||
* @tc.name fsync
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFsyncEBADF001, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret = fsync(-1); /* -1, bad fd */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FSYNC_EBADF002
|
||||
* @tc.name fsync
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFsyncEBADF002, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret = fsync(ERROR_CONFIG_NFILE_DESCRIPTORS);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FSYNC_EBADF003
|
||||
* @tc.name fsync
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFsyncEBADF003, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret = fsync(0); /* 0, used for stdin */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = fsync(1); /* 1, used for stdout */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = fsync(2); /* 2, used for stderr */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
void PosixFsFsyncTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(TestFsFsyncOK);
|
||||
RUN_ONE_TESTCASE(TestFsFsyncEBADF001);
|
||||
RUN_ONE_TESTCASE(TestFsFsyncEBADF002);
|
||||
RUN_ONE_TESTCASE(TestFsFsyncEBADF003);
|
||||
}
|
||||
163
testsuites/unittest/posix/src/fs/api/posix_fs_ftruncate_test.c
Normal file
163
testsuites/unittest/posix/src/fs/api/posix_fs_ftruncate_test.c
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Copyright (c) 2023-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:
|
||||
*
|
||||
* 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 "posix_fs_test.h"
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FTRUNCATE_OK
|
||||
* @tc.name ftruncate
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFtruncateOK, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = FILE2;
|
||||
const char writeBuf[TEST_BUF_SIZE] = "hello";
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR, TEST_MODE_HIGH);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = write(fd, writeBuf, TEST_BUF_SIZE);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
ret = ftruncate(fd, MODIFIED_FILE_SIZE);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FTRUNCATE_EBADF001
|
||||
* @tc.name ftruncate
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFtruncateEBADF001, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret = ftruncate(-1, MODIFIED_FILE_SIZE); /* -1, bad fd */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = ftruncate(ERROR_CONFIG_NFILE_DESCRIPTORS, MODIFIED_FILE_SIZE);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FTRUNCATE_EBADF002
|
||||
* @tc.name ftruncate
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFtruncateEBADF002, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret = ftruncate(0, MODIFIED_FILE_SIZE); /* 0, used for stdin */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = ftruncate(1, MODIFIED_FILE_SIZE); /* 1, used for stdout */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = ftruncate(2, MODIFIED_FILE_SIZE); /* 2, used for stderr */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FTRUNCATE_EINVAL
|
||||
* @tc.name ftruncate
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFtruncateEINVAL, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = FILE1;
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR, TEST_MODE_HIGH);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = ftruncate(fd, -1); /* -1, length after modification */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FTRUNCATE_EACCES
|
||||
* @tc.name ftruncate
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFtruncateEACCES, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = FILE1;
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDONLY, TEST_MODE_HIGH);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = ftruncate(fd, MODIFIED_FILE_SIZE);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EACCES, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
void PosixFsFtruncateTest(void)
|
||||
{
|
||||
#if (LOSCFG_SUPPORT_FATFS == 1)
|
||||
RUN_ONE_TESTCASE(TestFsFtruncateOK);
|
||||
#endif
|
||||
RUN_ONE_TESTCASE(TestFsFtruncateEBADF001);
|
||||
RUN_ONE_TESTCASE(TestFsFtruncateEBADF002);
|
||||
RUN_ONE_TESTCASE(TestFsFtruncateEINVAL);
|
||||
RUN_ONE_TESTCASE(TestFsFtruncateEACCES);
|
||||
}
|
||||
238
testsuites/unittest/posix/src/fs/api/posix_fs_lseek_test.c
Normal file
238
testsuites/unittest/posix/src/fs/api/posix_fs_lseek_test.c
Normal file
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
* Copyright (c) 2023-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:
|
||||
*
|
||||
* 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 "posix_fs_test.h"
|
||||
#include "vfs_config.h"
|
||||
|
||||
#define TEST_SEEK_WRITE_BUF "AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDDD"
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_LSEEK_OK001
|
||||
* @tc.name lseek
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsLseekOK001, Function | MediumTest | Level1)
|
||||
{
|
||||
off_t off;
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = FILE1;
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
off = lseek(fd, 0, SEEK_SET); /* 0, offset distance */
|
||||
ICUNIT_ASSERT_NOT_EQUAL(off, POSIX_FS_IS_ERROR, off);
|
||||
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_LSEEK_OK002
|
||||
* @tc.name lseek
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsLseekOK002, Function | MediumTest | Level1)
|
||||
{
|
||||
off_t off;
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = FILE1;
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
off = lseek(fd, 0, SEEK_CUR); /* 0, offset distance */
|
||||
ICUNIT_ASSERT_NOT_EQUAL(off, POSIX_FS_IS_ERROR, off);
|
||||
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_LSEEK_OK003
|
||||
* @tc.name lseek
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsLseekOK003, Function | MediumTest | Level1)
|
||||
{
|
||||
off_t off;
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = FILE1;
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
off = lseek(fd, 0, SEEK_END); /* 0, offset distance */
|
||||
ICUNIT_ASSERT_NOT_EQUAL(off, POSIX_FS_IS_ERROR, off);
|
||||
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_LSEEK_EBADF001
|
||||
* @tc.name lseek
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsLseekEBADF001, Function | MediumTest | Level1)
|
||||
{
|
||||
off_t off = lseek(-1, 0, SEEK_SET); /* -1, bad fd 0, offset distance */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL((int32_t)off, POSIX_FS_IS_ERROR, (int32_t)off);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_LSEEK_EBADF002
|
||||
* @tc.name lseek
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsLseekEBADF002, Function | MediumTest | Level1)
|
||||
{
|
||||
off_t off = lseek(ERROR_CONFIG_NFILE_DESCRIPTORS, 0, SEEK_SET); /* 0, offset distance */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL((int32_t)off, POSIX_FS_IS_ERROR, (int32_t)off);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_LSEEK_EBADF003
|
||||
* @tc.name lseek
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsLseekEBADF003, Function | MediumTest | Level1)
|
||||
{
|
||||
off_t off = lseek(0, 0, SEEK_SET); /* 0, used for stdin 0, offet distance */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL((int32_t)off, POSIX_FS_IS_ERROR, (int32_t)off);
|
||||
|
||||
off = lseek(1, 0, SEEK_SET); /* 1, used for stdout 0, offet distance */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL((int32_t)off, POSIX_FS_IS_ERROR, (int32_t)off);
|
||||
|
||||
off = lseek(2, 0, SEEK_SET); /* 2 used for stderr 0, offet distance */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL((int32_t)off, POSIX_FS_IS_ERROR, (int32_t)off);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_LSEEK_standard
|
||||
* @tc.name lseek
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsLseekStandard, Function | MediumTest | Level1)
|
||||
{
|
||||
off_t off;
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = { FILE1 };
|
||||
char writeBuf[TEST_BUF_SIZE] = { TEST_SEEK_WRITE_BUF };
|
||||
char readBuf[TEST_BUF_SIZE] = { 0 };
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = write(fd, writeBuf, TEST_BUF_SIZE);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
off = lseek(fd, 0, SEEK_SET); /* 0, offet distance */
|
||||
ICUNIT_ASSERT_NOT_EQUAL(off, POSIX_FS_IS_ERROR, off);
|
||||
|
||||
ret = read(fd, readBuf, 10); /* 10, common data for test, no special meaning */
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
ret = strcmp(readBuf, "AAAAAAAAAA");
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_FS_NO_ERROR, ret, EXIT);
|
||||
|
||||
off = lseek(fd, 10, SEEK_CUR); /* 10, common data for test, no special meaning */
|
||||
ICUNIT_GOTO_NOT_EQUAL(off, POSIX_FS_IS_ERROR, off, EXIT);
|
||||
|
||||
ret = read(fd, readBuf, 10); /* 10, common data for test, no special meaning */
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
ret = strcmp(readBuf, "CCCCCCCCCC");
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_FS_NO_ERROR, ret, EXIT);
|
||||
|
||||
off = lseek(fd, -10, SEEK_END); /* -10, common data for test, no special meaning */
|
||||
ICUNIT_GOTO_NOT_EQUAL(off, POSIX_FS_IS_ERROR, off, EXIT);
|
||||
|
||||
ret = read(fd, readBuf, 10);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
ret = strcmp(readBuf, "DDDDDDDDDD");
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_FS_NO_ERROR, ret, EXIT);
|
||||
|
||||
off = lseek(fd, 10, SEEK_END); /* 10, common data for test, no special meaning */
|
||||
ICUNIT_GOTO_NOT_EQUAL(off, POSIX_FS_IS_ERROR, off, EXIT);
|
||||
|
||||
ret = write(fd, "E", 1); /* 1, common data for test, no special meaning */
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
off = lseek(fd, 0, SEEK_END); /* 0, offet distance */
|
||||
ICUNIT_GOTO_EQUAL(off, 51, off, EXIT); /* 51, common data for test, no special meaning */
|
||||
|
||||
EXIT:
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
void PosixFsLseekTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(TestFsLseekOK001);
|
||||
RUN_ONE_TESTCASE(TestFsLseekOK002);
|
||||
RUN_ONE_TESTCASE(TestFsLseekOK003);
|
||||
RUN_ONE_TESTCASE(TestFsLseekEBADF001);
|
||||
RUN_ONE_TESTCASE(TestFsLseekEBADF002);
|
||||
RUN_ONE_TESTCASE(TestFsLseekEBADF003);
|
||||
RUN_ONE_TESTCASE(TestFsLseekStandard);
|
||||
}
|
||||
89
testsuites/unittest/posix/src/fs/api/posix_fs_mkdir_test.c
Normal file
89
testsuites/unittest/posix/src/fs/api/posix_fs_mkdir_test.c
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2023-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:
|
||||
*
|
||||
* 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 "posix_fs_test.h"
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_MKDIR_OK
|
||||
* @tc.name mkdir
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsMkdirOK, Function | MediumTest | Level1)
|
||||
{
|
||||
char pathF[50] = { DIRB };
|
||||
|
||||
int32_t ret = mkdir(pathF, TEST_MODE_NORMAL);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
ret = rmdir(pathF);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_MKDIR_EINVAL
|
||||
* @tc.name mkdir
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsMkdirEINVAL, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret = mkdir(NULL, TEST_MODE_HIGH);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_MKDIR_ENOENT
|
||||
* @tc.name mkdir
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsMkdirENOENT, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
char tmpDir[TEST_BUF_SIZE] = { DIRC };
|
||||
struct MountPoint *mountBak = g_mountPoints;
|
||||
|
||||
g_mountPoints = NULL;
|
||||
ret = mkdir(tmpDir, TEST_MODE_HIGH);
|
||||
g_mountPoints = mountBak;
|
||||
ICUNIT_ASSERT_EQUAL(errno, ENOENT, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
void PosixFsMkdirTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(TestFsMkdirOK);
|
||||
RUN_ONE_TESTCASE(TestFsMkdirEINVAL);
|
||||
RUN_ONE_TESTCASE(TestFsMkdirENOENT);
|
||||
}
|
||||
107
testsuites/unittest/posix/src/fs/api/posix_fs_open_test.c
Normal file
107
testsuites/unittest/posix/src/fs/api/posix_fs_open_test.c
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (c) 2023-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:
|
||||
*
|
||||
* 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 "posix_fs_test.h"
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_OPEN_OK
|
||||
* @tc.name open
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsOpenOK, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = { FILE1 };
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR, TEST_MODE_HIGH);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
fd = open(tmpFileName, O_CREAT | O_RDWR, TEST_MODE_NORMAL);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_OPEN_EINVAL
|
||||
* @tc.name open
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsOpenEINVAL, Function | MediumTest | Level1)
|
||||
{
|
||||
const char *tmpFileName1 = NULL;
|
||||
const char *tmpFileName2 = "/";
|
||||
|
||||
int32_t fd = open(tmpFileName1, O_CREAT | O_RDWR);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
fd = open(tmpFileName2, O_CREAT | O_RDWR);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_OPEN_ENOENT
|
||||
* @tc.name open
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsOpenENOENT, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t fd = -1;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = { FILE1 };
|
||||
struct MountPoint *mountBak = g_mountPoints;
|
||||
|
||||
g_mountPoints = NULL;
|
||||
fd = open(tmpFileName, O_CREAT | O_RDWR);
|
||||
g_mountPoints = mountBak;
|
||||
ICUNIT_ASSERT_EQUAL(errno, ENOENT, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
void PosixFsOpenTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(TestFsOpenOK);
|
||||
RUN_ONE_TESTCASE(TestFsOpenEINVAL);
|
||||
RUN_ONE_TESTCASE(TestFsOpenENOENT);
|
||||
}
|
||||
89
testsuites/unittest/posix/src/fs/api/posix_fs_opendir_test.c
Normal file
89
testsuites/unittest/posix/src/fs/api/posix_fs_opendir_test.c
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2023-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:
|
||||
*
|
||||
* 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 "posix_fs_test.h"
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_OPENDIR_OK
|
||||
* @tc.name opendir
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsOpendirOK, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
DIR *dir = opendir(TEST_ROOT);
|
||||
ICUNIT_ASSERT_NOT_EQUAL_VOID(dir, NULL, dir);
|
||||
|
||||
ret = closedir(dir);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_OPENDIR_EINVAL
|
||||
* @tc.name opendir
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsOpendirEINVAL, Function | MediumTest | Level1)
|
||||
{
|
||||
DIR *dir = opendir(NULL);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL_VOID(dir, NULL, dir);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_OPENDIR_ENOENT
|
||||
* @tc.name opendir
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsOpendirENOENT, Function | MediumTest | Level1)
|
||||
{
|
||||
DIR *dir = NULL;
|
||||
struct MountPoint *mountBak = g_mountPoints;
|
||||
|
||||
g_mountPoints = NULL;
|
||||
dir = opendir(TEST_ROOT);
|
||||
g_mountPoints = mountBak;
|
||||
ICUNIT_ASSERT_EQUAL(errno, ENOENT, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL_VOID(dir, NULL, dir);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
void PosixFsOpendirTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(TestFsOpendirOK);
|
||||
RUN_ONE_TESTCASE(TestFsOpendirEINVAL);
|
||||
RUN_ONE_TESTCASE(TestFsOpendirENOENT);
|
||||
}
|
||||
121
testsuites/unittest/posix/src/fs/api/posix_fs_pread_test.c
Normal file
121
testsuites/unittest/posix/src/fs/api/posix_fs_pread_test.c
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) 2023-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:
|
||||
*
|
||||
* 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 "posix_fs_test.h"
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_PREAD_OK
|
||||
* @tc.name pread
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsPreadOK, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = { FILE1 };
|
||||
char readBuf[TEST_BUF_SIZE] = "fsPreadTest";
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR, TEST_MODE_HIGH);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = pread(fd, readBuf, TEST_BUF_SIZE, 0);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_PREAD_EFAULT
|
||||
* @tc.name pread
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsPreadEFAULT, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = { FILE1 };
|
||||
char *readBuf = NULL;
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR, TEST_MODE_HIGH);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = pread(fd, readBuf, TEST_BUF_SIZE, 0);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EFAULT, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_PREAD_EACCES
|
||||
* @tc.name pread
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsPreadEACCES, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = FILE1;
|
||||
char readBuf[TEST_BUF_SIZE] = "fsPreadTest";
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_WRONLY, TEST_MODE_HIGH);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = pread(fd, readBuf, TEST_BUF_SIZE, 0);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EACCES, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
void PosixFsPreadTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(TestFsPreadOK);
|
||||
RUN_ONE_TESTCASE(TestFsPreadEFAULT);
|
||||
RUN_ONE_TESTCASE(TestFsPreadEACCES);
|
||||
}
|
||||
121
testsuites/unittest/posix/src/fs/api/posix_fs_pwrite_test.c
Normal file
121
testsuites/unittest/posix/src/fs/api/posix_fs_pwrite_test.c
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) 2023-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:
|
||||
*
|
||||
* 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 "posix_fs_test.h"
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_PRWRITE_OK
|
||||
* @tc.name pwrite
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsPwriteOK, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = { FILE1 };
|
||||
char writeBuf[TEST_BUF_SIZE] = "fsPwrtiteTest";
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR, TEST_MODE_HIGH);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = pwrite(fd, writeBuf, TEST_BUF_SIZE, 0); /* 0, offset distance */
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_PRWRITE_EFAULT
|
||||
* @tc.name pwrite
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsPwriteEFAULT, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = { FILE1 };
|
||||
char *writeBuf = NULL;
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR, TEST_MODE_HIGH);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = pwrite(fd, writeBuf, TEST_BUF_SIZE, 0); /* 0, offset distance */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EFAULT, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_PRWRITE_EACCES
|
||||
* @tc.name pwrite
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsPwriteEACCES, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = { FILE1 };
|
||||
char writeBuf[TEST_BUF_SIZE] = "fsPwriteTest";
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDONLY, TEST_MODE_HIGH);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = pwrite(fd, writeBuf, TEST_BUF_SIZE, 0); /* 0, offset distance */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EACCES, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
void PosixFsPwriteTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(TestFsPwriteOK);
|
||||
RUN_ONE_TESTCASE(TestFsPwriteEFAULT);
|
||||
RUN_ONE_TESTCASE(TestFsPwriteEACCES);
|
||||
}
|
||||
119
testsuites/unittest/posix/src/fs/api/posix_fs_read_test.c
Normal file
119
testsuites/unittest/posix/src/fs/api/posix_fs_read_test.c
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (c) 2023-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:
|
||||
*
|
||||
* 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 "posix_fs_test.h"
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_READ_OK
|
||||
* @tc.name read
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsReadOK, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = { FILE1 };
|
||||
char readBuf[TEST_BUF_SIZE] = "hello";
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = read(fd, readBuf, sizeof(readBuf));
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_READ_EFAULT
|
||||
* @tc.name read
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsReadEFAULT, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = { FILE1 };
|
||||
char *readBuf = NULL;
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = read(fd, readBuf, sizeof(readBuf));
|
||||
ICUNIT_ASSERT_EQUAL(errno, EFAULT, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_READ_EACCES
|
||||
* @tc.name read
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsReadEACCES, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = { FILE1 };
|
||||
char readBuf[TEST_BUF_SIZE] = "hello";
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_WRONLY);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = read(fd, readBuf, sizeof(readBuf));
|
||||
ICUNIT_ASSERT_EQUAL(errno, EACCES, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
void PosixFsReadTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(TestFsReadOK);
|
||||
RUN_ONE_TESTCASE(TestFsReadEFAULT);
|
||||
RUN_ONE_TESTCASE(TestFsReadEACCES);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2023-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:
|
||||
@@ -28,27 +28,31 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_tick.h"
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include "posix_fs_test.h"
|
||||
|
||||
#define SECS_PER_MIN 60
|
||||
|
||||
int _gettimeofday(struct timeval *__tp, void *__tzp)
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_READDIR_OK
|
||||
* @tc.name readdir
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsReaddirOK, Function | MediumTest | Level1)
|
||||
{
|
||||
struct timespec ts;
|
||||
struct timezone *tz = (struct timezone *)__tzp;
|
||||
int32_t ret;
|
||||
struct dirent *dResult = NULL;
|
||||
|
||||
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;
|
||||
}
|
||||
DIR *dir = opendir(TEST_ROOT);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(dir, NULL, POSIX_FS_IS_ERROR);
|
||||
|
||||
dResult = readdir(dir);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(dResult, NULL, POSIX_FS_IS_ERROR);
|
||||
|
||||
ret = closedir(dir);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
void PosixFsReaddirTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(TestFsReaddirOK);
|
||||
}
|
||||
126
testsuites/unittest/posix/src/fs/api/posix_fs_rename_test.c
Normal file
126
testsuites/unittest/posix/src/fs/api/posix_fs_rename_test.c
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (c) 2023-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:
|
||||
*
|
||||
* 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 "posix_fs_test.h"
|
||||
#include "vfs_config.h"
|
||||
|
||||
#define TEST_FILE1 TEST_ROOT"/file1.txt"
|
||||
#define TEST_FILE2 TEST_ROOT"/file2.txt"
|
||||
#define TEST_FILE3 TEST_ROOT"/file3.txt"
|
||||
#define TEST_FILE4 TEST_ROOT"/file4.txt"
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_RENAME_OK
|
||||
* @tc.name rename
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsRenameOK, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
const char fileNameOld[TEST_BUF_SIZE] = { TEST_FILE1 };
|
||||
const char fileNameNew[TEST_BUF_SIZE] = { TEST_FILE2 };
|
||||
|
||||
int32_t fd = open(fileNameOld, O_CREAT | O_RDWR);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = rename(fileNameOld, fileNameNew);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(fileNameNew);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_RENAME_EINVAL001
|
||||
* @tc.name rename
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsRenameEINVAL001, Function | MediumTest | Level1)
|
||||
{
|
||||
const char *fileNameOld = NULL;
|
||||
const char fileNameNew[TEST_BUF_SIZE] = { TEST_FILE3 };
|
||||
|
||||
int32_t ret = rename(fileNameOld, fileNameNew);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_RENAME_EINVAL002
|
||||
* @tc.name rename
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsRenameEINVAL002, Function | MediumTest | Level1)
|
||||
{
|
||||
const char fileNameOld[TEST_BUF_SIZE] = { TEST_FILE4 };
|
||||
const char *fileNameNew = NULL;
|
||||
|
||||
int32_t ret = rename(fileNameOld, fileNameNew);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_RENAME_EINVAL003
|
||||
* @tc.name rename
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsRenameEINVAL003, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
const char fileNameOld[TEST_BUF_SIZE] = { TEST_FILE3 };
|
||||
const char fileNameNew[TEST_BUF_SIZE] = { TEST_FILE4 };
|
||||
|
||||
struct MountPoint *mountBak = g_mountPoints;
|
||||
g_mountPoints = NULL;
|
||||
ret = rename(fileNameOld, fileNameNew);
|
||||
g_mountPoints = mountBak;
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
void PosixFsRenameTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(TestFsRenameOK);
|
||||
RUN_ONE_TESTCASE(TestFsRenameEINVAL001);
|
||||
RUN_ONE_TESTCASE(TestFsRenameEINVAL002);
|
||||
RUN_ONE_TESTCASE(TestFsRenameEINVAL003);
|
||||
}
|
||||
69
testsuites/unittest/posix/src/fs/api/posix_fs_rmdir_test.c
Normal file
69
testsuites/unittest/posix/src/fs/api/posix_fs_rmdir_test.c
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2023-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:
|
||||
*
|
||||
* 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 "posix_fs_test.h"
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_RMDIR_OK
|
||||
* @tc.name rmdir
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsRmdirOK, Function | MediumTest | Level1)
|
||||
{
|
||||
char pathH[TEST_BUF_SIZE] = { DIRD };
|
||||
|
||||
int32_t ret = mkdir(pathH, TEST_MODE_NORMAL);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = rmdir(pathH);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_RMDIR_EINVAL
|
||||
* @tc.name rmdir
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsRmdirEINVAL, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret = rmdir(NULL);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
void PosixFsRmdirTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(TestFsRmdirOK);
|
||||
RUN_ONE_TESTCASE(TestFsRmdirEINVAL);
|
||||
}
|
||||
107
testsuites/unittest/posix/src/fs/api/posix_fs_stat_test.c
Normal file
107
testsuites/unittest/posix/src/fs/api/posix_fs_stat_test.c
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (c) 2023-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:
|
||||
*
|
||||
* 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 "posix_fs_test.h"
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_STAT_OK
|
||||
* @tc.name stat
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsStatOK, Function | MediumTest | Level1)
|
||||
{
|
||||
struct stat buf = { 0 };
|
||||
|
||||
int32_t ret = stat(TEST_ROOT, &buf);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_sSTAT_EINVAL001
|
||||
* @tc.name stat
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsStatEINVAL001, Function | MediumTest | Level1)
|
||||
{
|
||||
struct stat buf = { 0 };
|
||||
const char *tmpFileName = NULL;
|
||||
|
||||
int32_t ret = stat(tmpFileName, &buf);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_sSTAT_EINVAL002
|
||||
* @tc.name stat
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsStatEINVAL002, Function | MediumTest | Level1)
|
||||
{
|
||||
struct stat *buf = NULL;
|
||||
|
||||
int32_t ret = stat(TEST_ROOT, buf);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_STAT_ENOENT
|
||||
* @tc.name stat
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsStatENOENT, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
struct stat buf = { 0 };
|
||||
|
||||
struct MountPoint *mountBak = g_mountPoints;
|
||||
g_mountPoints = NULL;
|
||||
ret = stat(TEST_ROOT, &buf);
|
||||
g_mountPoints = mountBak;
|
||||
ICUNIT_ASSERT_EQUAL(errno, ENOENT, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
void PosixFsStatTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(TestFsStatOK);
|
||||
RUN_ONE_TESTCASE(TestFsStatEINVAL001);
|
||||
RUN_ONE_TESTCASE(TestFsStatEINVAL002);
|
||||
RUN_ONE_TESTCASE(TestFsStatENOENT);
|
||||
}
|
||||
92
testsuites/unittest/posix/src/fs/api/posix_fs_statfs_test.c
Normal file
92
testsuites/unittest/posix/src/fs/api/posix_fs_statfs_test.c
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2023-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:
|
||||
*
|
||||
* 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 "posix_fs_test.h"
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_STATFS_OK
|
||||
* @tc.name statfs
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsStatfsOK, Function | MediumTest | Level1)
|
||||
{
|
||||
struct statfs buf = { 0 };
|
||||
|
||||
int32_t ret = statfs(TEST_ROOT, &buf);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_STATFS_EINVAL
|
||||
* @tc.name statfs
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsStatfsEINVAL, Function | MediumTest | Level1)
|
||||
{
|
||||
struct statfs buf = { 0 };
|
||||
|
||||
int32_t ret = statfs(NULL, &buf);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = statfs(TEST_ROOT, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_STATFS_ENOENT
|
||||
* @tc.name statfs
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsStatfsENOENT, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
struct statfs buf = { 0 };
|
||||
|
||||
struct MountPoint *mountBak = g_mountPoints;
|
||||
g_mountPoints = NULL;
|
||||
ret = statfs(TEST_ROOT, &buf);
|
||||
g_mountPoints = mountBak;
|
||||
ICUNIT_ASSERT_EQUAL(errno, ENOENT, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
void PosixFsStatfsTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(TestFsStatfsOK);
|
||||
RUN_ONE_TESTCASE(TestFsStatfsEINVAL);
|
||||
RUN_ONE_TESTCASE(TestFsStatfsENOENT);
|
||||
}
|
||||
88
testsuites/unittest/posix/src/fs/api/posix_fs_unlink_test.c
Normal file
88
testsuites/unittest/posix/src/fs/api/posix_fs_unlink_test.c
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (c) 2023-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:
|
||||
*
|
||||
* 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 "posix_fs_test.h"
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_UNLINK_OK
|
||||
* @tc.name unlink
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsUnlinkOK, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = { FILE4 };
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_UNLINK_ENOENT
|
||||
* @tc.name unlink
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsUnlinkENOENT, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE]= { FILE1 };
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
struct MountPoint *mountBak = g_mountPoints;
|
||||
g_mountPoints = NULL;
|
||||
ret = unlink(tmpFileName);
|
||||
g_mountPoints = mountBak;
|
||||
ICUNIT_ASSERT_EQUAL(errno, ENOENT, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
void PosixFsUnlinkTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(TestFsUnlinkOK);
|
||||
RUN_ONE_TESTCASE(TestFsUnlinkENOENT);
|
||||
}
|
||||
123
testsuites/unittest/posix/src/fs/api/posix_fs_write_test.c
Normal file
123
testsuites/unittest/posix/src/fs/api/posix_fs_write_test.c
Normal file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (c) 2023-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:
|
||||
*
|
||||
* 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 "posix_fs_test.h"
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_WRITE_OK
|
||||
* @tc.name write
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsWriteOK, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = { FILE1 };
|
||||
const char writeBuf[TEST_BUF_SIZE] = "hello";
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = write(fd, writeBuf, TEST_BUF_SIZE);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_WRITE_EINVAL
|
||||
* @tc.name write
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsWriteEINVAL, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = { FILE1 };
|
||||
const char *writeBuf1 = NULL;
|
||||
const char writeBuf2[TEST_BUF_SIZE] = "hello";
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = write(fd, writeBuf1, TEST_BUF_SIZE);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = write(fd, writeBuf2, 0);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_WRITE_EACCES
|
||||
* @tc.name write
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsWriteEACCES, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = { FILE1 };
|
||||
const char writeBuf[TEST_BUF_SIZE] = "hello";
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDONLY);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = write(fd, writeBuf, TEST_BUF_SIZE);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EACCES, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
void PosixFsWriteTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(TestFsWriteOK);
|
||||
RUN_ONE_TESTCASE(TestFsWriteEINVAL);
|
||||
RUN_ONE_TESTCASE(TestFsWriteEACCES);
|
||||
}
|
||||
463
testsuites/unittest/posix/src/fs/full/posix_fs_full_test.c
Normal file
463
testsuites/unittest/posix/src/fs/full/posix_fs_full_test.c
Normal file
@@ -0,0 +1,463 @@
|
||||
/*
|
||||
* Copyright (c) 2023-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:
|
||||
*
|
||||
* 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 "posix_fs_test.h"
|
||||
|
||||
#define TEST_OPEN_DIR_NUM 16
|
||||
#define TEST_OPEN_FILE_NUM 16
|
||||
#define WRITE_BUF_SIZE 128
|
||||
#define READ_WRITE_BUF_SIZE 1024
|
||||
#define TEMP_DIRE TEST_ROOT"/e"
|
||||
#define TEMP_DIRE_FILE TEST_ROOT"/e/eFile"
|
||||
#define TEMP_DIRF TEST_ROOT"/f"
|
||||
#define TEMP_DIRF_DIR TEST_ROOT"/f/fDir"
|
||||
#define TEST_DIRG TEST_ROOT"/g"
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FULL001
|
||||
* @tc.name open close unlink
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFull001, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
int32_t fd1 = -1;
|
||||
int32_t fd2 = -1;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = { FILE1 };
|
||||
|
||||
fd1 = open(tmpFileName, O_CREAT | O_RDWR, TEST_MODE_HIGH);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd1, POSIX_FS_IS_ERROR, fd1);
|
||||
|
||||
#if (LOSCFG_SUPPORT_FATFS == 1)
|
||||
fd2 = open(tmpFileName, O_CREAT | O_RDWR, TEST_MODE_HIGH);
|
||||
ICUNIT_ASSERT_EQUAL(fd2, POSIX_FS_IS_ERROR, fd2);
|
||||
#endif
|
||||
|
||||
ret = close(fd1);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
fd2 = open(tmpFileName, O_CREAT | O_RDWR, TEST_MODE_HIGH);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd2, POSIX_FS_IS_ERROR, fd2);
|
||||
|
||||
ret = close(fd2);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FULL002
|
||||
* @tc.name open write read lseek read close unlink
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFull002, Function | MediumTest | Level1)
|
||||
{
|
||||
off_t off;
|
||||
int32_t ret;
|
||||
int32_t fd = -1;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = { FILE1 };
|
||||
char *writeBuf = (char *)malloc(READ_WRITE_BUF_SIZE * sizeof(char));
|
||||
char *readBuf = (char *)malloc(READ_WRITE_BUF_SIZE * sizeof(char));
|
||||
|
||||
(void)memset_s(writeBuf, READ_WRITE_BUF_SIZE, 'w', READ_WRITE_BUF_SIZE);
|
||||
(void)memset_s(readBuf, READ_WRITE_BUF_SIZE, 'r', READ_WRITE_BUF_SIZE);
|
||||
|
||||
fd = open(tmpFileName, O_CREAT | O_RDWR, TEST_MODE_HIGH);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = write(fd, writeBuf, READ_WRITE_BUF_SIZE / 2); /* 2, number of writes */
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
ret = write(fd, writeBuf, READ_WRITE_BUF_SIZE / 2); /* 2, number of writes */
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
off = lseek(fd, 0, SEEK_SET); /* 0, offset distance */
|
||||
ICUNIT_GOTO_NOT_EQUAL(off, POSIX_FS_IS_ERROR, off, EXIT);
|
||||
|
||||
for (int32_t i = 0; i < 8; i++) { /* 8, number of reads */
|
||||
ret = read(fd, readBuf + i * 128, 128); /* 128, 128, length per read */
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
}
|
||||
|
||||
for (int32_t j = 0; j < READ_WRITE_BUF_SIZE; j++) {
|
||||
ICUNIT_GOTO_EQUAL(writeBuf[j], readBuf[j], POSIX_FS_IS_ERROR, EXIT);
|
||||
}
|
||||
|
||||
EXIT:
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FULL003
|
||||
* @tc.name mkdir opendir closedir rmdir fstat
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFull003, Function | MediumTest | Level1)
|
||||
{
|
||||
int res;
|
||||
DIR *dir = NULL;
|
||||
int32_t index = 0;
|
||||
bool flag = true;
|
||||
struct dirent *dirmsg = NULL;
|
||||
struct stat buf = { 0 };
|
||||
int32_t i, fd[TEST_OPEN_FILE_NUM];
|
||||
char tmpFileName[TEST_BUF_SIZE] = { 0 };
|
||||
char fileName[TEST_BUF_SIZE] = { 0 };
|
||||
|
||||
int32_t ret = mkdir(TEMP_DIRE, TEST_MODE_NORMAL);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
for (i = 0; i < TEST_OPEN_FILE_NUM; i++) {
|
||||
res = sprintf_s(tmpFileName, TEST_BUF_SIZE, "%s%02d", TEMP_DIRE_FILE, i);
|
||||
if (res < 0) {
|
||||
printf("[%s:%d] sprintf_s failed\n", __func__, __LINE__);
|
||||
goto EXIT1;
|
||||
}
|
||||
fd[i] = open(tmpFileName, O_CREAT | O_RDWR, TEST_MODE_HIGH);
|
||||
flag = fd[i] == -1 ? false : true;
|
||||
ICUNIT_GOTO_NOT_EQUAL(fd[i], POSIX_FS_IS_ERROR, fd[i], EXIT1);
|
||||
}
|
||||
dir = opendir(TEMP_DIRE);
|
||||
flag = dir == NULL ? false : true;
|
||||
ICUNIT_GOTO_NOT_EQUAL(dir, NULL, POSIX_FS_IS_ERROR, EXIT1);
|
||||
while ((dirmsg = readdir(dir)) != NULL) {
|
||||
res = sprintf_s(fileName, TEST_BUF_SIZE, "%s%02d", "eFile", index);
|
||||
if (res < 0) {
|
||||
printf("[%s:%d] sprintf_s failed\n", __func__, __LINE__);
|
||||
goto EXIT1;
|
||||
}
|
||||
ret = strcmp(dirmsg->d_name, fileName);
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_FS_NO_ERROR, ret, EXIT1);
|
||||
ret = fstat(fd[index], &buf);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT1);
|
||||
ICUNIT_GOTO_EQUAL(buf.st_mode & S_IFMT, S_IFREG, POSIX_FS_IS_ERROR, EXIT1);
|
||||
index++;
|
||||
}
|
||||
ICUNIT_GOTO_EQUAL(index, TEST_OPEN_FILE_NUM, POSIX_FS_IS_ERROR, EXIT1);
|
||||
EXIT1:
|
||||
for (int32_t j = 0; j < i; j++) {
|
||||
res = sprintf_s(tmpFileName, TEST_BUF_SIZE, "%s%02d", TEMP_DIRE_FILE, j);
|
||||
if (res < 0) {
|
||||
printf("[%s:%d] sprintf_s failed\n", __func__, __LINE__);
|
||||
return POSIX_FS_IS_ERROR;
|
||||
}
|
||||
ret = close(fd[j]);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
}
|
||||
if (flag == false) {
|
||||
goto EXIT;
|
||||
}
|
||||
ret = closedir(dir);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
EXIT:
|
||||
ret = rmdir(TEMP_DIRE);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FULL004
|
||||
* @tc.name mkdir readdir opendir stat closedir rmdir
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFull004, Function | MediumTest | Level1)
|
||||
{
|
||||
int res;
|
||||
int32_t i;
|
||||
int32_t index = 0;
|
||||
DIR *dir = NULL;
|
||||
struct dirent *dirmsg = NULL;
|
||||
struct stat buf = { 0 };
|
||||
char dirName[TEST_BUF_SIZE] = { 0 };
|
||||
char tmpDirName[TEST_BUF_SIZE] = { 0 };
|
||||
|
||||
int32_t ret = mkdir(TEMP_DIRF, TEST_MODE_HIGH);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
for (i = 0; i < TEST_OPEN_DIR_NUM; i++) {
|
||||
res = sprintf_s(tmpDirName, TEST_BUF_SIZE, "%s%02d", TEMP_DIRF_DIR, i);
|
||||
if (res < 0) {
|
||||
printf("[%s:%d] sprintf_s failed\n", __func__, __LINE__);
|
||||
goto EXIT;
|
||||
}
|
||||
ret = mkdir(tmpDirName, TEST_MODE_HIGH);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
}
|
||||
|
||||
dir = opendir(TEMP_DIRF);
|
||||
ICUNIT_GOTO_NOT_EQUAL(dir, NULL, POSIX_FS_IS_ERROR, EXIT1);
|
||||
while ((dirmsg = readdir(dir)) != NULL) {
|
||||
res = sprintf_s(dirName, TEST_BUF_SIZE, "%s%02d", "fDir", index);
|
||||
if (res < 0) {
|
||||
printf("[%s:%d] sprintf_s failed\n", __func__, __LINE__);
|
||||
goto EXIT1;
|
||||
}
|
||||
ret = strcmp(dirmsg->d_name, dirName);
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_FS_NO_ERROR, ret, EXIT1);
|
||||
res = sprintf_s(tmpDirName, TEST_BUF_SIZE, "%s%02d", TEMP_DIRF_DIR, index);
|
||||
if (res < 0) {
|
||||
printf("[%s:%d] sprintf_s failed\n", __func__, __LINE__);
|
||||
goto EXIT1;
|
||||
}
|
||||
ret = stat(tmpDirName, &buf);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT1);
|
||||
ICUNIT_GOTO_EQUAL(buf.st_mode & S_IFMT, S_IFDIR, POSIX_FS_IS_ERROR, EXIT1);
|
||||
index++;
|
||||
}
|
||||
ICUNIT_GOTO_EQUAL(index, TEST_OPEN_DIR_NUM, POSIX_FS_IS_ERROR, EXIT1);
|
||||
EXIT1:
|
||||
ret = closedir(dir);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
EXIT:
|
||||
for (int32_t j = 0; j < i; j++) {
|
||||
res = sprintf_s(tmpDirName, TEST_BUF_SIZE, "%s%02d", TEMP_DIRF_DIR, j);
|
||||
if (res < 0) {
|
||||
printf("[%s:%d] sprintf_s failed\n", __func__, __LINE__);
|
||||
return POSIX_FS_IS_ERROR;
|
||||
}
|
||||
ret = rmdir(tmpDirName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
}
|
||||
ret = rmdir(TEMP_DIRF);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FULL005
|
||||
* @tc.name read write lseek close unlink
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFull005, Function | MediumTest | Level1)
|
||||
{
|
||||
off_t off;
|
||||
int32_t ret;
|
||||
int32_t fd = -1;
|
||||
bool flag = true;
|
||||
char readBuf = 'r';
|
||||
const char tmpFileName[TEST_BUF_SIZE] = { FILE1 };
|
||||
char *writeBuf = (char*)malloc(WRITE_BUF_SIZE * sizeof(char));
|
||||
|
||||
(void)memset_s(writeBuf, WRITE_BUF_SIZE, 'w', WRITE_BUF_SIZE);
|
||||
|
||||
fd = open(tmpFileName, O_CREAT | O_RDWR);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = write(fd, writeBuf, WRITE_BUF_SIZE);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
off = lseek(fd, 0, SEEK_SET);
|
||||
ICUNIT_GOTO_NOT_EQUAL(off, POSIX_FS_IS_ERROR, off, EXIT);
|
||||
|
||||
for (int i = 1; i <= TEST_OPEN_FILE_NUM; i++) {
|
||||
ret = read(fd, &readBuf, 1);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
if (readBuf != 'w') {
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
readBuf = 'r';
|
||||
off = lseek(fd, 7, SEEK_CUR); /* 7, offset distance */
|
||||
ICUNIT_GOTO_NOT_EQUAL(off, POSIX_FS_IS_ERROR, off, EXIT);
|
||||
}
|
||||
|
||||
EXIT:
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FULL006
|
||||
* @tc.name open fstat close unlink
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFull006, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
struct stat buf = { 0 };
|
||||
const char tmpFileName[TEST_BUF_SIZE] = { FILE1 };
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = fstat(fd, &buf);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(buf.st_mode & S_IFMT, S_IFREG, POSIX_FS_IS_ERROR, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FULL007
|
||||
* @tc.name open stat close unlink
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFull007, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
struct stat buf = { 0 };
|
||||
const char tmpFileName[TEST_BUF_SIZE] = { FILE1 };
|
||||
|
||||
int32_t fd = open(tmpFileName, O_CREAT | O_RDWR);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = stat(tmpFileName, &buf);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(buf.st_mode & S_IFMT, S_IFREG, POSIX_FS_IS_ERROR, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = stat(tmpFileName, &buf);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FULL008
|
||||
* @tc.name mkdir stat rmdir
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFull008, Function | MediumTest | Level1)
|
||||
{
|
||||
char dirName[TEST_BUF_SIZE] = { TEST_DIRG };
|
||||
struct stat buf = { 0 };
|
||||
|
||||
int32_t ret = mkdir(dirName, TEST_MODE_HIGH);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = stat(dirName, &buf);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT1);
|
||||
ICUNIT_GOTO_EQUAL(buf.st_mode & S_IFMT, S_IFDIR, POSIX_FS_IS_ERROR, EXIT1);
|
||||
|
||||
ret = rmdir(dirName);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT1);
|
||||
|
||||
ret = stat(dirName, &buf);
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
|
||||
EXIT1:
|
||||
ret = rmdir(dirName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
EXIT:
|
||||
return POSIX_FS_IS_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FULL009
|
||||
* @tc.name open close stat rename unlink
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsFull009, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
struct stat buf = { 0 };
|
||||
char tmpFileName1[TEST_BUF_SIZE] = { FILE5 };
|
||||
char tmpFileName2[TEST_BUF_SIZE] = { FILE6 };
|
||||
|
||||
int32_t fd = open(tmpFileName1, O_CREAT | O_RDWR, TEST_MODE_HIGH);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = close(fd);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT1);
|
||||
|
||||
ret = stat(tmpFileName1, &buf);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(buf.st_mode & S_IFMT, S_IFREG, POSIX_FS_IS_ERROR, EXIT);
|
||||
|
||||
ret = rename(tmpFileName1, tmpFileName2);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
ret = stat(tmpFileName1, &buf);
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
|
||||
ret = stat(tmpFileName2, &buf);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(buf.st_mode & S_IFMT, S_IFREG, POSIX_FS_IS_ERROR, EXIT);
|
||||
|
||||
ret = unlink(tmpFileName1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
ret = unlink(tmpFileName2);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
|
||||
EXIT1:
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
EXIT:
|
||||
ret = unlink(tmpFileName1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
void PosixFsFullTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(TestFsFull001);
|
||||
RUN_ONE_TESTCASE(TestFsFull002);
|
||||
#if (LOSCFG_SUPPORT_FATFS == 1)
|
||||
RUN_ONE_TESTCASE(TestFsFull003);
|
||||
RUN_ONE_TESTCASE(TestFsFull004);
|
||||
#endif
|
||||
RUN_ONE_TESTCASE(TestFsFull005);
|
||||
RUN_ONE_TESTCASE(TestFsFull006);
|
||||
RUN_ONE_TESTCASE(TestFsFull007);
|
||||
RUN_ONE_TESTCASE(TestFsFull008);
|
||||
RUN_ONE_TESTCASE(TestFsFull009);
|
||||
}
|
||||
@@ -33,18 +33,7 @@
|
||||
#define __NEED_mode_t
|
||||
#endif
|
||||
|
||||
#include <securec.h>
|
||||
#include <stdio.h>
|
||||
#include <libgen.h>
|
||||
#include "ohos_types.h"
|
||||
#include "posix_test.h"
|
||||
#include "los_config.h"
|
||||
#include "kernel_test.h"
|
||||
#include "log.h"
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include "posix_fs_test.h"
|
||||
|
||||
/* *
|
||||
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
|
||||
@@ -54,31 +43,6 @@
|
||||
*/
|
||||
LITE_TEST_SUIT(Posix, PosixFs, PosixFsFuncTestSuite);
|
||||
|
||||
#if (LOSCFG_SUPPORT_FATFS == 1)
|
||||
#define TEST_ROOT "system"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_SUPPORT_LITTLEFS == 1)
|
||||
#define TEST_ROOT "/littlefs"
|
||||
#endif
|
||||
|
||||
#define TEST_FILE_PTAH_RIGHT TEST_ROOT"/FILE0" /* file path, to open/rd/close */
|
||||
#define FILE0 "FILE0" /* common file name used for testing */
|
||||
#define FILE1 TEST_ROOT"/FILE1" /* common file under test root path name used for testing */
|
||||
#define FILE2 TEST_ROOT"/FILE2" /* common file under test root path name used for testing */
|
||||
#define DIRA TEST_ROOT"/a" /* common file under test root path name used for testing */
|
||||
#define FILE_IN_DIRA TEST_ROOT"/a/FILE0" /* common file under test root path name used for testing */
|
||||
#define DIRAB TEST_ROOT"/a/b" /* common file under test root path name used for testing */
|
||||
#define DIRAC TEST_ROOT"/a/c" /* common file under test root path name used for testing */
|
||||
|
||||
#define TEST_BUF_SIZE 40 /* 40, common data for test, no special meaning */
|
||||
#define TEST_SEEK_SIZE 10 /* 10, common data for test, no special meaning */
|
||||
#define TEST_RW_SIZE 20 /* 20, common data for test, no special meaning */
|
||||
#define TEST_LOOPUP_TIME 20 /* 100, common data for test, no special meaning */
|
||||
|
||||
#define TEST_MODE_NORMAL 0666
|
||||
#define TEST_MODE_HIGH 0777
|
||||
|
||||
/* *
|
||||
* @tc.setup : setup for all testcases
|
||||
* @return : setup result, TRUE is success, FALSE is fail
|
||||
@@ -2012,9 +1976,8 @@ LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFcntl002, Function | MediumTest | Lev
|
||||
|
||||
RUN_TEST_SUITE(PosixFsFuncTestSuite);
|
||||
|
||||
void PosixFsFuncTest()
|
||||
void PosixFsAPITest(void)
|
||||
{
|
||||
LOG("begin PosixFsFuncTest....\r\n");
|
||||
RUN_ONE_TESTCASE(testFsFopenFclose001);
|
||||
RUN_ONE_TESTCASE(testFsFopenFclose002);
|
||||
RUN_ONE_TESTCASE(testFsFopenFclose003);
|
||||
@@ -2103,6 +2066,34 @@ void PosixFsFuncTest()
|
||||
RUN_ONE_TESTCASE(testFsFcntl001);
|
||||
RUN_ONE_TESTCASE(testFsFcntl002);
|
||||
#endif
|
||||
}
|
||||
|
||||
void PosixFsFuncTest()
|
||||
{
|
||||
PosixFsAPITest();
|
||||
PosixFsOpenTest();
|
||||
PosixFsCloseTest();
|
||||
PosixFsOpendirTest();
|
||||
PosixFsClosedirTest();
|
||||
PosixFsReadTest();
|
||||
PosixFsWriteTest();
|
||||
PosixFsReaddirTest();
|
||||
PosixFsMkdirTest();
|
||||
PosixFsRmdirTest();
|
||||
PosixFsLseekTest();
|
||||
PosixFsUnlinkTest();
|
||||
PosixFsStatTest();
|
||||
PosixFsFstatTest();
|
||||
PosixFsFsyncTest();
|
||||
PosixFsRenameTest();
|
||||
#if (LOSCFG_SUPPORT_FATFS == 1)
|
||||
PosixFsStatfsTest();
|
||||
#endif
|
||||
PosixFsFtruncateTest();
|
||||
PosixFsPreadTest();
|
||||
PosixFsPwriteTest();
|
||||
PosixFsAccessTest();
|
||||
PosixFsFullTest();
|
||||
PosixFsPressureTest();
|
||||
return;
|
||||
}
|
||||
|
||||
90
testsuites/unittest/posix/src/fs/posix_fs_test.h
Normal file
90
testsuites/unittest/posix/src/fs/posix_fs_test.h
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2023-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:
|
||||
*
|
||||
* 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 __POSIX_FS_TEST_H
|
||||
#define __POSIX_FS_TEST_H
|
||||
|
||||
#include "posix_test.h"
|
||||
#include <securec.h>
|
||||
#include <stdio.h>
|
||||
#include <libgen.h>
|
||||
#include "ohos_types.h"
|
||||
#include "los_config.h"
|
||||
#include "vfs_files.h"
|
||||
#include "vfs_mount.h"
|
||||
#include "vfs_maps.h"
|
||||
#include "kernel_test.h"
|
||||
#include "log.h"
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include "limits.h"
|
||||
|
||||
#if (LOSCFG_SUPPORT_FATFS == 1)
|
||||
#define TEST_ROOT "system"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_SUPPORT_LITTLEFS == 1)
|
||||
#define TEST_ROOT "/littlefs"
|
||||
#endif
|
||||
|
||||
#define TEST_FILE_PTAH_RIGHT TEST_ROOT"/FILE0" /* file path, to open/rd/close */
|
||||
#define FILE0 "FILE0" /* common file name used for testing */
|
||||
#define FILE1 TEST_ROOT"/FILE1" /* common file under test root path name used for testing */
|
||||
#define FILE2 TEST_ROOT"/FILE2" /* common file under test root path name used for testing */
|
||||
#define FILE3 TEST_ROOT"/FILE3" /* common file under test root path name used for testing */
|
||||
#define FILE4 TEST_ROOT"/FILE4" /* common file under test root path name used for testing */
|
||||
#define FILE5 TEST_ROOT"/FILE5" /* common file under test root path name used for testing */
|
||||
#define FILE6 TEST_ROOT"/FILE6" /* common file under test root path name used for testing */
|
||||
#define DIRA TEST_ROOT"/a" /* common file under test root path name used for testing */
|
||||
#define DIRB TEST_ROOT"/b" /* common file under test root path name used for testing */
|
||||
#define DIRC TEST_ROOT"/c" /* common file under test root path name used for testing */
|
||||
#define DIRD TEST_ROOT"/d" /* common file under test root path name used for testing */
|
||||
|
||||
#define FILE_IN_DIRA TEST_ROOT"/a/FILE0" /* common file under test root path name used for testing */
|
||||
#define DIRAB TEST_ROOT"/a/b" /* common file under test root path name used for testing */
|
||||
#define DIRAC TEST_ROOT"/a/c" /* common file under test root path name used for testing */
|
||||
|
||||
#define TEST_BUF_SIZE 40 /* 40, common data for test, no special meaning */
|
||||
#define TEST_SEEK_SIZE 10 /* 10, common data for test, no special meaning */
|
||||
#define TEST_RW_SIZE 20 /* 20, common data for test, no special meaning */
|
||||
#define TEST_LOOPUP_TIME 20 /* 100, common data for test, no special meaning */
|
||||
|
||||
#define ERROR_CONFIG_NFILE_DESCRIPTORS 88888 /* 88888, common data for test, no special meaning */
|
||||
#define MODIFIED_FILE_SIZE 1024 /* 1024, common data for test, no special meaning */
|
||||
|
||||
#define TEST_MODE_NORMAL 0666 /* 0666, common data for test, no special meaning */
|
||||
#define TEST_MODE_HIGH 0777 /* 0777, common data for test, no special meaning */
|
||||
|
||||
#define POSIX_FS_IS_ERROR (-1) /* -1, common data for test, no special meaning */
|
||||
#define POSIX_FS_NO_ERROR 0 /* 0, common data for test, no special meaning */
|
||||
|
||||
#endif /* __POSIX_FS_TEST_H */
|
||||
@@ -0,0 +1,292 @@
|
||||
/*
|
||||
* Copyright (c) 2023-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:
|
||||
*
|
||||
* 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 "posix_fs_test.h"
|
||||
#include "vfs_config.h"
|
||||
|
||||
#define MAX_OPEN_FILE_NUM 16
|
||||
#define PRESSURE_RUN_TIMES 200
|
||||
#define PRESSURE_RUN_TIMES003 150
|
||||
#define READ_WRITE_BUF_SIZE 1024
|
||||
#define PATH_MAX_NAME_LEN PATH_MAX
|
||||
#define MAX_OPEN_DIRS_NUM LOSCFG_MAX_OPEN_DIRS
|
||||
#define TEMP_FILE_PATH TEST_ROOT"/FILE7"
|
||||
#define TEMP_DIR_PATH TEST_ROOT"/DIRE"
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FRESSURE001
|
||||
* @tc.name open close unlink
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsPressure001, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
int32_t fd = -1;
|
||||
char tmpFileName[PATH_MAX_NAME_LEN + 1] = TEST_ROOT"/";
|
||||
|
||||
int32_t len = strlen(TEST_ROOT);
|
||||
for (int32_t i = len + 1; i < PATH_MAX_NAME_LEN - 1; i++) {
|
||||
tmpFileName[i] = 'F';
|
||||
}
|
||||
tmpFileName[PATH_MAX_NAME_LEN - 1] = '\0';
|
||||
|
||||
for (int32_t times = 0; times < PRESSURE_RUN_TIMES; times++) {
|
||||
fd = open(tmpFileName, O_CREAT | O_RDWR, TEST_MODE_HIGH);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = close(fd);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT1);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
}
|
||||
|
||||
tmpFileName[PATH_MAX_NAME_LEN - 1] = 'E';
|
||||
tmpFileName[PATH_MAX_NAME_LEN] = '\0';
|
||||
fd = open(tmpFileName, O_CREAT | O_RDWR, TEST_MODE_HIGH);
|
||||
ICUNIT_ASSERT_EQUAL(errno, ENAMETOOLONG, POSIX_FS_IS_ERROR);
|
||||
ICUNIT_ASSERT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
|
||||
EXIT1:
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
EXIT:
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_PRESSURE002
|
||||
* @tc.name open write lseek read close unlink
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsPressure002, Function | MediumTest | Level1)
|
||||
{
|
||||
off_t off;
|
||||
int32_t ret;
|
||||
int32_t fd = -1;
|
||||
bool flag = true;
|
||||
const char tmpFileName[TEST_BUF_SIZE] = FILE1;
|
||||
char *writeBuf = (char *)malloc(READ_WRITE_BUF_SIZE * sizeof(char));
|
||||
char *readBuf = (char *)malloc(READ_WRITE_BUF_SIZE * sizeof(char));
|
||||
|
||||
(void)memset_s(writeBuf, READ_WRITE_BUF_SIZE, 'w', READ_WRITE_BUF_SIZE);
|
||||
|
||||
for (int32_t times = 0; times < PRESSURE_RUN_TIMES; times++) {
|
||||
(void)memset_s(readBuf, READ_WRITE_BUF_SIZE, 'r', READ_WRITE_BUF_SIZE);
|
||||
fd = open(tmpFileName, O_CREAT | O_RDWR, TEST_MODE_HIGH);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, POSIX_FS_IS_ERROR, fd);
|
||||
|
||||
ret = write(fd, writeBuf, READ_WRITE_BUF_SIZE / 2); /* 2, common data for test, no special meaning */
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT1);
|
||||
ret = write(fd, writeBuf, READ_WRITE_BUF_SIZE / 2); /* 2, common data for test, no special meaning */
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT1);
|
||||
|
||||
off = lseek(fd, 0, SEEK_SET); /* 0, offset distance */
|
||||
ICUNIT_GOTO_NOT_EQUAL(off, POSIX_FS_IS_ERROR, off, EXIT1);
|
||||
|
||||
for (int32_t i = 0; i < 8; i++) { /* 8, number of reads */
|
||||
ret = read(fd, readBuf + i * 128, 128); /* 128, length per read */
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT1);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < READ_WRITE_BUF_SIZE; i++) {
|
||||
ICUNIT_GOTO_EQUAL(writeBuf[i], readBuf[i], POSIX_FS_IS_ERROR, EXIT1);
|
||||
}
|
||||
|
||||
ret = close(fd);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT1);
|
||||
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT);
|
||||
}
|
||||
|
||||
return POSIX_FS_NO_ERROR;
|
||||
|
||||
EXIT1:
|
||||
ret = close(fd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
EXIT:
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_ORESSURE003
|
||||
* @tc.name open fstat stat mkdir unlink rmdir close
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, TestFsPressure003, Function | MediumTest | Level1)
|
||||
{
|
||||
int res;
|
||||
int32_t ret;
|
||||
bool flagMkdir = true;
|
||||
struct stat buf = { 0 };
|
||||
int32_t j, k, fd[MAX_OPEN_FILE_NUM];
|
||||
char tmpDirName[TEST_BUF_SIZE] = { 0 };
|
||||
char tmpFileName[TEST_BUF_SIZE] = { 0 };
|
||||
|
||||
for (int32_t times = 0; times < PRESSURE_RUN_TIMES003; times++) {
|
||||
for (j = 0; j < MAX_OPEN_FILE_NUM; j++) {
|
||||
res = sprintf_s(tmpFileName, TEST_BUF_SIZE, "%s%02d", TEMP_FILE_PATH, j);
|
||||
if (res < 0) {
|
||||
printf("[%s:%d] sprintf_s failed\n", __func__, __LINE__);
|
||||
goto EXIT3;
|
||||
}
|
||||
fd[j] = open(tmpFileName, O_CREAT | O_RDWR, TEST_MODE_HIGH);
|
||||
ICUNIT_GOTO_NOT_EQUAL(fd[j], POSIX_FS_IS_ERROR, fd[j], EXIT3);
|
||||
}
|
||||
for (int32_t i = 0; i < MAX_OPEN_FILE_NUM; i++) {
|
||||
ret = fstat(fd[i], &buf);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT3);
|
||||
ICUNIT_GOTO_EQUAL(buf.st_mode & S_IFMT, S_IFREG, POSIX_FS_IS_ERROR, EXIT3);
|
||||
}
|
||||
for (int32_t i = 0; i < MAX_OPEN_FILE_NUM; i++) {
|
||||
ret = close(fd[i]);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT2);
|
||||
}
|
||||
for (int32_t i = 0; i < MAX_OPEN_FILE_NUM; i++) {
|
||||
res = sprintf_s(tmpFileName, TEST_BUF_SIZE, "%s%02d", TEMP_FILE_PATH, i);
|
||||
if (res < 0) {
|
||||
printf("[%s:%d] sprintf_s failed\n", __func__, __LINE__);
|
||||
goto EXIT1;
|
||||
}
|
||||
ret = stat(tmpFileName, &buf);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT1);
|
||||
ICUNIT_GOTO_EQUAL(buf.st_mode & S_IFMT, S_IFREG, POSIX_FS_IS_ERROR, EXIT1);
|
||||
}
|
||||
for (k = 0; k < MAX_OPEN_DIRS_NUM; k++) {
|
||||
res = sprintf_s(tmpDirName, TEST_BUF_SIZE, "%s%02d", TEMP_DIR_PATH, k);
|
||||
if (res < 0) {
|
||||
printf("[%s:%d] sprintf_s failed\n", __func__, __LINE__);
|
||||
goto EXIT1;
|
||||
}
|
||||
ret = mkdir(tmpDirName, TEST_MODE_HIGH);
|
||||
if (ret == POSIX_FS_IS_ERROR) {
|
||||
flagMkdir = false;
|
||||
}
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT1);
|
||||
}
|
||||
for (int32_t i = 0; i < MAX_OPEN_DIRS_NUM; i++) {
|
||||
res = sprintf_s(tmpDirName, TEST_BUF_SIZE, "%s%02d", TEMP_DIR_PATH, i);
|
||||
if (res < 0) {
|
||||
printf("[%s:%d] sprintf_s failed\n", __func__, __LINE__);
|
||||
goto EXIT1;
|
||||
}
|
||||
ret = stat(tmpDirName, &buf);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret, EXIT1);
|
||||
ICUNIT_GOTO_EQUAL(buf.st_mode & S_IFMT, S_IFDIR, POSIX_FS_IS_ERROR, EXIT1);
|
||||
}
|
||||
for (int32_t i = 0; i < MAX_OPEN_FILE_NUM; i++) {
|
||||
res = sprintf_s(tmpFileName, TEST_BUF_SIZE, "%s%02d", TEMP_FILE_PATH, i);
|
||||
if (res < 0) {
|
||||
printf("[%s:%d] sprintf_s failed\n", __func__, __LINE__);
|
||||
return POSIX_FS_IS_ERROR;
|
||||
}
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
}
|
||||
for (int32_t i = 0; i < MAX_OPEN_DIRS_NUM; i++) {
|
||||
res = sprintf_s(tmpDirName, TEST_BUF_SIZE, "%s%02d", TEMP_DIR_PATH, i);
|
||||
if (res < 0) {
|
||||
printf("[%s:%d] sprintf_s failed\n", __func__, __LINE__);
|
||||
return POSIX_FS_IS_ERROR;
|
||||
}
|
||||
ret = rmdir(tmpDirName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
}
|
||||
for (int32_t i = 0; i < MAX_OPEN_FILE_NUM; i++) {
|
||||
res = sprintf_s(tmpFileName, TEST_BUF_SIZE, "%s%02d", TEMP_FILE_PATH, i);
|
||||
if (res < 0) {
|
||||
printf("[%s:%d] sprintf_s failed\n", __func__, __LINE__);
|
||||
return POSIX_FS_IS_ERROR;
|
||||
}
|
||||
ret = stat(tmpFileName, &buf);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
}
|
||||
for (int32_t i = 0; i < MAX_OPEN_DIRS_NUM; i++) {
|
||||
res = sprintf_s(tmpDirName, TEST_BUF_SIZE, "%s%02d", TEMP_DIR_PATH, i);
|
||||
if (res < 0) {
|
||||
printf("[%s:%d] sprintf_s failed\n", __func__, __LINE__);
|
||||
return POSIX_FS_IS_ERROR;
|
||||
}
|
||||
ret = stat(tmpDirName, &buf);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
}
|
||||
}
|
||||
return POSIX_FS_NO_ERROR;
|
||||
EXIT3:
|
||||
for (int32_t m = 0; m < j; m++) {
|
||||
ret = close(fd[m]);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
}
|
||||
goto EXIT1;
|
||||
EXIT2:
|
||||
for (int32_t m = j; m < MAX_OPEN_FILE_NUM; m++) {
|
||||
ret = close(fd[m]);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
}
|
||||
EXIT1:
|
||||
for (int32_t m = 0; m < j; m++) {
|
||||
res = sprintf_s(tmpFileName, TEST_BUF_SIZE, "%s%02d", TEMP_FILE_PATH, m);
|
||||
if (res < 0) {
|
||||
printf("[%s:%d] sprintf_s failed\n", __func__, __LINE__);
|
||||
return POSIX_FS_IS_ERROR;
|
||||
}
|
||||
ret = unlink(tmpFileName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
}
|
||||
if (flagMkdir == false) {
|
||||
goto EXIT;
|
||||
}
|
||||
return POSIX_FS_NO_ERROR;
|
||||
EXIT:
|
||||
for (int32_t m = 0; m < k; m++) {
|
||||
res = sprintf_s(tmpDirName, TEST_BUF_SIZE, "%s%02d", TEMP_DIR_PATH, m);
|
||||
if (res < 0) {
|
||||
printf("[%s:%d] sprintf_s failed\n", __func__, __LINE__);
|
||||
return POSIX_FS_IS_ERROR;
|
||||
}
|
||||
ret = rmdir(tmpDirName);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, POSIX_FS_IS_ERROR, ret);
|
||||
}
|
||||
return POSIX_FS_NO_ERROR;
|
||||
}
|
||||
|
||||
void PosixFsPressureTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(TestFsPressure001);
|
||||
RUN_ONE_TESTCASE(TestFsPressure002);
|
||||
RUN_ONE_TESTCASE(TestFsPressure003);
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -62,4 +62,7 @@ void ItSuitePosix(void)
|
||||
PosixSemaphoreFuncTest();
|
||||
PosixTimeFuncTest();
|
||||
#endif
|
||||
#if (LOSCFG_SUPPORT_LITTLEFS == 1 || LOSCFG_SUPPORT_FATFS == 1)
|
||||
PosixFsFuncTest();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -85,6 +85,7 @@ extern void PosixIslowerFuncTest(void);
|
||||
extern void PosixIsxdigitFuncTest(void);
|
||||
extern void PosixTolowerFuncTest(void);
|
||||
extern void PosixToupperFuncTest(void);
|
||||
extern void ItSuitePosixMqueue(void);
|
||||
|
||||
extern void PosixStrerrorTest(void);
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -91,12 +91,12 @@ LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll001, Function | MediumTest |
|
||||
LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll002, Function | MediumTest | Level1)
|
||||
{
|
||||
long long value = atoll("-9223372036854775808");
|
||||
if (value == -9223372036854775808LL) {
|
||||
if (value == -9223372036854775808ULL) {
|
||||
LOG("[DEMO] posix stdlib test case 2:atoll(%lld) ok.\n", value);
|
||||
} else {
|
||||
LOG("[DEMO] posix stdlib test case 2:atoll(%lld) fail.\n", value);
|
||||
}
|
||||
TEST_ASSERT_TRUE(value == -9223372036854775808LL);
|
||||
TEST_ASSERT_TRUE(value == -9223372036854775808ULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll003, Function | MediumTest |
|
||||
LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll004, Function | MediumTest | Level1)
|
||||
{
|
||||
long long value = atoll("9223372036854775808");
|
||||
if (value == -9223372036854775808LL) {
|
||||
if (value == -9223372036854775808ULL) {
|
||||
LOG("[DEMO] posix stdlib test case 4(except):atoll(%lld) != 9223372036854775808 ok.\n", value);
|
||||
} else {
|
||||
LOG("[DEMO] posix stdlib test case 4(except):atoll(%lld) fail.\n", value);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user