diff --git a/syscall/fs_syscall.c b/syscall/fs_syscall.c index f3e10416..530e30d2 100644 --- a/syscall/fs_syscall.c +++ b/syscall/fs_syscall.c @@ -1279,7 +1279,7 @@ OUT: return ret; } -int SysFstat(int fd, struct stat *buf) +int SysFstat(int fd, struct kstat *buf) { int ret; struct stat bufRet = {0}; @@ -1302,7 +1302,7 @@ int SysFstat(int fd, struct stat *buf) return -get_errno(); } - ret = LOS_ArchCopyToUser(buf, &bufRet, sizeof(struct stat)); + ret = LOS_ArchCopyToUser(buf, &bufRet, sizeof(struct kstat)); if (ret != 0) { return -EFAULT; } @@ -2068,7 +2068,7 @@ OUT: } #endif -int SysFstat64(int fd, struct stat64 *buf) +int SysFstat64(int fd, struct kstat *buf) { int ret; struct stat64 bufRet = {0}; @@ -2081,7 +2081,7 @@ int SysFstat64(int fd, struct stat64 *buf) return -get_errno(); } - ret = LOS_ArchCopyToUser(buf, &bufRet, sizeof(struct stat64)); + ret = LOS_ArchCopyToUser(buf, &bufRet, sizeof(struct kstat)); if (ret != 0) { return -EFAULT; } @@ -2385,7 +2385,7 @@ OUT: return ret; } -int SysFstatat64(int dirfd, const char *restrict path, struct stat *restrict buf, int flag) +int SysFstatat64(int dirfd, const char *restrict path, struct kstat *restrict buf, int flag) { int ret; struct stat bufRet = {0}; @@ -2415,7 +2415,7 @@ int SysFstatat64(int dirfd, const char *restrict path, struct stat *restrict buf goto OUT; } - ret = LOS_ArchCopyToUser(buf, &bufRet, sizeof(struct stat)); + ret = LOS_ArchCopyToUser(buf, &bufRet, sizeof(struct kstat)); if (ret != 0) { ret = -EFAULT; goto OUT; diff --git a/syscall/los_syscall.h b/syscall/los_syscall.h index c9594143..eb2ae132 100644 --- a/syscall/los_syscall.h +++ b/syscall/los_syscall.h @@ -268,15 +268,15 @@ extern int SysFstatfs64(int fd, size_t sz, struct statfs *buf); extern int SysStat(const char *path, struct kstat *buf); extern int SysLstat(const char *path, struct kstat *buffer); -extern int SysFstat(int fildes, struct stat *buf); +extern int SysFstat(int fildes, struct kstat *buf); extern int SysStatx(int fd, const char *restrict path, int flag, unsigned mask, struct statx *restrict stx); extern int SysFsync(int fd); extern ssize_t SysReadv(int fd, const struct iovec *iov, int iovcnt); extern ssize_t SysWritev(int fd, const struct iovec *iov, int iovcnt); extern int SysPipe(int pipefd[2]); /* 2 : pipe fds for read and write */ extern int SysFormat(const char *dev, int sectors, int option); -extern int SysFstat64(int fd, struct stat64 *buf); -extern int SysFstatat64(int fd, const char *restrict path, struct stat *restrict buf, int flag); +extern int SysFstat64(int fd, struct kstat *buf); +extern int SysFstatat64(int fd, const char *restrict path, struct kstat *restrict buf, int flag); extern int SysFcntl64(int fd, int cmd, void *arg); extern int SysPoll(struct pollfd *fds, nfds_t nfds, int timeout); extern int SysPpoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, diff --git a/testsuites/unittest/IO/It_test_IO.h b/testsuites/unittest/IO/It_test_IO.h index 353010d3..003c9036 100644 --- a/testsuites/unittest/IO/It_test_IO.h +++ b/testsuites/unittest/IO/It_test_IO.h @@ -118,6 +118,8 @@ extern VOID IO_TEST_CONFSTR_001(void); extern VOID IO_TEST_NL_LANGINFO_001(VOID); extern VOID IO_TEST_STRCASECMP_L_001(VOID); extern VOID IO_TEST_STRCASECMP_L_002(VOID); +extern VOID IO_TEST_STRNCASECMP_L_001(VOID); +extern VOID IO_TEST_STRNCASECMP_L_002(VOID); extern VOID IO_TEST_DUPLOCALE_001(void); extern VOID IO_TEST_NL_LANGINFO_l_001(VOID); extern VOID IO_TEST_DNGETTEXT_001(VOID); diff --git a/testsuites/unittest/IO/full/IO_test_duplocale_001.cpp b/testsuites/unittest/IO/full/IO_test_duplocale_001.cpp index 0ba8e346..85157281 100644 --- a/testsuites/unittest/IO/full/IO_test_duplocale_001.cpp +++ b/testsuites/unittest/IO/full/IO_test_duplocale_001.cpp @@ -28,63 +28,123 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "It_test_IO.h" #include #include +#include +#include "It_test_IO.h" -static UINT32 testcase(VOID) +/* Zh_cn.utf-8 File content */ +int fileWords[] = { + 0x950412de, 0x0, 0x3, 0x1c, 0x34, 0x5, + 0x4c, 0x0, 0x60, 0x3, 0x61, 0x3, + 0x65, 0x14f, 0x69, 0x9, 0x1b9, 0x6, + 0x1c3, 0x1, 0x3, 0x0, 0x0, 0x2, + 0x69724600, 0x6e614a00, 0x6f725000, 0x7463656a, 0x2d64492d, 0x73726556, + 0x3a6e6f69, 0x6d695620, 0x6d695328, 0x66696c70, 0x20646569, 0x6e696843, + 0x29657365, 0x7065520a, 0x2d74726f, 0x6967734d, 0x75422d64, 0x542d7367, + 0xa203a6f, 0x522d4f50, 0x73697665, 0x2d6e6f69, 0x65746144, 0x3032203a, + 0x302d3630, 0x31322d34, 0x3a343120, 0x302b3030, 0xa303038, 0x7473614c, + 0x6172542d, 0x616c736e, 0x3a726f74, 0x68755920, 0x20676e65, 0xa656958, + 0x676e614c, 0x65676175, 0x6165542d, 0x53203a6d, 0x6c706d69, 0x65696669, + 0x68432064, 0x73656e69, 0x494d0a65, 0x562d454d, 0x69737265, 0x203a6e6f, + 0xa302e31, 0x746e6f43, 0x2d746e65, 0x65707954, 0x6574203a, 0x702f7478, + 0x6e69616c, 0x6863203b, 0x65737261, 0x54553d74, 0xa382d46, 0x746e6f43, + 0x2d746e65, 0x6e617254, 0x72656673, 0x636e452d, 0x6e69646f, 0x38203a67, + 0xa746962, 0x72756c50, 0x462d6c61, 0x736d726f, 0x706e203a, 0x6172756c, + 0x313d736c, 0x6c70203b, 0x6c617275, 0xa3b303d, 0x676e614c, 0x65676175, + 0x687a203a, 0xa4e435f, 0x65472d58, 0x6172656e, 0x3a726f74, 0x656f5020, + 0x20746964, 0xa302e33, 0x9f98e600, 0xe49f9ce6, 0xe40094ba, 0x9ce680b8, + 0x88 +}; + +UINT32 SonFunc(VOID) { - time_t currtime; - struct tm *timer = {nullptr}; - char buffer[80]; - locale_t oldloc = LC_GLOBAL_LOCALE; - locale_t newloc = nullptr; - - printf("[INFO]newloc=0x%x,oldloc=0x%x\n", (int)newloc, (int)oldloc); - newloc = duplocale(oldloc); - printf("[INFO]newloc=0x%x,oldloc=0x%x\n", (int)newloc, (int)oldloc); - ICUNIT_ASSERT_NOT_EQUAL_NULL(newloc, nullptr, -1); - - time(&currtime); - timer = localtime(&currtime); + int ret; + struct tm timer_; + struct tm *timer = &timer_; + char buffer[80]; /* 80, The number of characters returned by strftime */ + char *retptr = nullptr; /* set timer as 'Thu Jan 1 23:48:56 1970'" */ - timer->tm_sec = 32; - timer->tm_min = 3; + timer->tm_sec = 32; /* 32, example */ + timer->tm_min = 3; /* 3, example */ timer->tm_hour = 1; timer->tm_mday = 2; timer->tm_mon = 0; - timer->tm_year = 70; - timer->tm_wday = 5; + timer->tm_year = 70; /* 70, example */ + timer->tm_wday = 5; /* 5, example */ timer->tm_yday = 1; timer->tm_isdst = 0; timer->__tm_gmtoff = 0; timer->__tm_zone = nullptr; - setenv("MUSL_LOCPATH", "/storage", 1); - printf("[INFO]getenv MUSL_LOCPATH=%s\n", getenv("MUSL_LOCPATH")); - ICUNIT_GOTO_STRING_EQUAL(getenv("MUSL_LOCPATH"), "/storage", getenv("MUSL_LOCPATH"), OUT); + ret = setenv("MUSL_LOCPATH", "/storage", 1); + ICUNIT_ASSERT_EQUAL(ret, 0, -1); + retptr = getenv("MUSL_LOCPATH"); + ICUNIT_ASSERT_NOT_EQUAL(retptr, NULL, -1); + ICUNIT_ASSERT_STRING_EQUAL(retptr, "/storage", -1); - printf("[INFO]Locale is: %s\n", setlocale(LC_TIME, "en_US.UTF-8")); - strftime(buffer, 80, "%c", timer); - printf("[INFO]Date is: %s\n", buffer); - ICUNIT_GOTO_STRING_EQUAL(buffer, "星期五 一月 2 01:03:32 1970", -1, OUT); + retptr = setlocale(LC_TIME, "en_US.UTF-8"); + ICUNIT_ASSERT_NOT_EQUAL(retptr, NULL, -1); + ICUNIT_ASSERT_STRING_EQUAL(retptr, "en_US.UTF-8", -1); - printf("[INFO]Locale is: %s\n", setlocale(LC_TIME, "zh_CN.UTF-8")); - strftime(buffer, 80, "%c", timer); - printf("[INFO]Date is: %s\n", buffer); - ICUNIT_GOTO_STRING_EQUAL(buffer, "星期五 一月 2 01:03:32 1970", -1, OUT); + ret = strftime(buffer, 80, "%c", timer); /* 80, The maximum number of characters in the string str */ + ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1); + ICUNIT_ASSERT_STRING_EQUAL(buffer, "Fri Jan 2 01:03:32 1970", -1); - printf("[INFO]Locale is: %s\n", setlocale(LC_TIME, "")); - strftime(buffer, 80, "%c", timer); - printf("[INFO]Date is: %s\n", buffer); - ICUNIT_GOTO_STRING_EQUAL(buffer, "Fri Jan 2 01:03:32 1970", -1, OUT); + retptr = setlocale(LC_TIME, "zh_CN.UTF-8"); + ICUNIT_ASSERT_NOT_EQUAL(retptr, NULL, -1); + ICUNIT_ASSERT_STRING_EQUAL(retptr, "zh_CN.UTF-8", -1); + + ret = strftime(buffer, 80, "%c", timer); /* 80, The maximum number of characters in the string str */ + ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1); + ICUNIT_ASSERT_STRING_EQUAL(buffer, "星期五 一月 2 01:03:32 1970", -1); + + retptr = setlocale(LC_TIME, ""); + ICUNIT_ASSERT_NOT_EQUAL(retptr, NULL, -1); + ICUNIT_ASSERT_STRING_EQUAL(retptr, "C", -1); + ret = strftime(buffer, 80, "%c", timer); /* 80, The maximum number of characters in the string str */ + ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1); + ICUNIT_ASSERT_STRING_EQUAL(buffer, "Fri Jan 2 01:03:32 1970", -1); + + return 0; +} + +static UINT32 testcase(VOID) +{ + int ret, status; + locale_t oldloc = LC_GLOBAL_LOCALE; + locale_t newloc = nullptr; + + char *pathList[] = {"/storage/zh_CN.UTF-8"}; + char *streamList[] = {(char *)fileWords}; + int streamLen[] = {sizeof(fileWords) - 2}; + + newloc = duplocale(oldloc); + ICUNIT_ASSERT_NOT_EQUAL(newloc, nullptr, -1); free(newloc); + + ret = PrepareFileEnv(pathList, streamList, streamLen, 1); + if (ret != 0) { + printf("error: need some env file, but prepare is not ok"); + (VOID)RecoveryFileEnv(pathList, 1); + return -1; + } + + pid_t pid = fork(); + if (pid == 0) { + ret = SonFunc(); + exit(ret); + } + + ret = waitpid(pid, &status, 0); + ICUNIT_ASSERT_EQUAL(ret, pid, ret); + (VOID)RecoveryFileEnv(pathList, 1); + status = WEXITSTATUS(status); + ICUNIT_ASSERT_EQUAL(status, 0, status); + return LOS_OK; -OUT: - free(newloc); - return LOS_NOK; } VOID IO_TEST_DUPLOCALE_001(void) diff --git a/testsuites/unittest/IO/full/It_stdio_hasmntopt_001.cpp b/testsuites/unittest/IO/full/It_stdio_hasmntopt_001.cpp index 3e27bef4..2169f01c 100644 --- a/testsuites/unittest/IO/full/It_stdio_hasmntopt_001.cpp +++ b/testsuites/unittest/IO/full/It_stdio_hasmntopt_001.cpp @@ -41,6 +41,18 @@ static UINT32 testcase(VOID) char *opt = argv[1]; char *ret = nullptr; + char fileWords[] = "/dev/disk/by-uuid/c4992556-a86e-45e8-ba5f-190b16a9073x /usr1 ext3 errors=remount-ro,nofail 0 1"; + char *pathList[] = {"/etc/fstab"}; + char *streamList[] = {(char *)fileWords}; + int streamLen[] = {sizeof(fileWords)}; + + int flag = PrepareFileEnv(pathList, streamList, streamLen, 1); + if (flag != 0) { + printf("error: need some env file, but prepare is not ok"); + (VOID)RecoveryFileEnv(pathList, 1); + return -1; + } + mnt_new = (struct mntent *)malloc(sizeof(struct mntent)); mnt_new->mnt_fsname = "UUID=c4992556-a86e-45e8-ba5f-190b16a9073x"; mnt_new->mnt_dir = "/usr1"; @@ -79,7 +91,7 @@ static UINT32 testcase(VOID) if (fp != NULL) { endmntent(fp); } - + (VOID)RecoveryFileEnv(pathList, 1); return LOS_OK; } diff --git a/testsuites/unittest/IO/io_test.cpp b/testsuites/unittest/IO/io_test.cpp index cda69475..a689f7c6 100644 --- a/testsuites/unittest/IO/io_test.cpp +++ b/testsuites/unittest/IO/io_test.cpp @@ -192,7 +192,6 @@ HWTEST_F(IoTest, ItStdioReadv001, TestSize.Level0) ItStdioReadv001(); } - /* * * @tc.name: IT_STDIO_RINDEX_001 * @tc.desc: function for IoTest @@ -291,5 +290,225 @@ HWTEST_F(IoTest, ItStdioMbrlen001, TestSize.Level0) { ItStdioMbrlen001(); } + +/* * + * @tc.name: IT_STDIO_HASMNTOPT_001 + * @tc.desc: function for IoTest-normal testcase + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(IoTest, IT_STDIO_HASMNTOPT_001, TestSize.Level0) +{ + IT_STDIO_HASMNTOPT_001(); +} + +/* * + * @tc.name: IO_TEST_DUPLOCALE_001 + * @tc.desc: function for IoTest-dup the locale global pointer + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(IoTest, IO_TEST_DUPLOCALE_001, TestSize.Level0) +{ + IO_TEST_DUPLOCALE_001(); +} + +/* * + * @tc.name: IO_TEST_NL_LANGINFO_001 + * @tc.desc: function for IoTest-normal testcase + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(IoTest, IO_TEST_NL_LANGINFO_001, TestSize.Level0) +{ + IO_TEST_NL_LANGINFO_001(); +} + +/* * + * @tc.name: IO_TEST_STRCASECMP_L_001 + * @tc.desc: function for IoTest-normal testcase + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(IoTest, IO_TEST_STRCASECMP_L_001, TestSize.Level0) +{ + IO_TEST_STRCASECMP_L_001(); +} + +/* * + * @tc.name: IO_TEST_STRCASECMP_L_002 + * @tc.desc: function for IoTest-normal testcase + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(IoTest, IO_TEST_STRCASECMP_L_002, TestSize.Level0) +{ + IO_TEST_STRCASECMP_L_002(); +} + +/* * + * @tc.name: IO_TEST_STRNCASECMP_L_001 + * @tc.desc: function for IoTest-normal testcase + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(IoTest, IO_TEST_STRNCASECMP_L_001, TestSize.Level0) +{ + IO_TEST_STRNCASECMP_L_001(); +} + +/* * + * @tc.name: IO_TEST_STRNCASECMP_L_002 + * @tc.desc: function for IoTest-normal testcase + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(IoTest, IO_TEST_STRNCASECMP_L_002, TestSize.Level0) +{ + IO_TEST_STRNCASECMP_L_002(); +} + +/* * + * @tc.name: IO_TEST_NL_LANGINFO_l_001 + * @tc.desc: function for IoTest-query language and locale information + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(IoTest, IO_TEST_NL_LANGINFO_l_001, TestSize.Level0) +{ + IO_TEST_NL_LANGINFO_l_001(); +} + +/* * + * @tc.name: IO_TEST_DNGETTEXT_001 + * @tc.desc: function for IoTest-print the translated string1 or string2 + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(IoTest, IO_TEST_DNGETTEXT_001, TestSize.Level0) +{ + IO_TEST_DNGETTEXT_001(); +} + +/* * + * @tc.name: IO_TEST_DNGETTEXT_002 + * @tc.desc: function for IoTest-innormal testcases + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(IoTest, IO_TEST_DNGETTEXT_002, TestSize.Level0) +{ + IO_TEST_DNGETTEXT_002(); +} + +/* * + * @tc.name: IO_TEST_DCNGETTEXT_001 + * @tc.desc: function for IoTest-print the translated string1 or string2 with locale parameter + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(IoTest, IO_TEST_DCNGETTEXT_001, TestSize.Level0) +{ + IO_TEST_DCNGETTEXT_001(); +} + +/* * + * @tc.name: IO_TEST_DCNGETTEXT_002 + * @tc.desc: function for IoTest-innormal testcases + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(IoTest, IO_TEST_DCNGETTEXT_002, TestSize.Level0) +{ + IO_TEST_DCNGETTEXT_002(); +} +/* * + * @tc.name: IO_TEST_DCGETTEXT_001 + * @tc.desc: function for IoTest-print the translated string with locale parameter + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(IoTest, IO_TEST_DCGETTEXT_001, TestSize.Level0) +{ + IO_TEST_DCGETTEXT_001(); +} + +/* * + * @tc.name: IO_TEST_DCGETTEXT_002 + * @tc.desc: function for IoTest-innormal testcases + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(IoTest, IO_TEST_DCGETTEXT_002, TestSize.Level0) +{ + IO_TEST_DCGETTEXT_002(); +} + +/* * + * @tc.name: IO_TEST_GETTEXT_001 + * @tc.desc: function for IoTest-normal testcases + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(IoTest, IO_TEST_GETTEXT_001, TestSize.Level0) +{ + IO_TEST_GETTEXT_001(); +} + +/* * + * @tc.name: IO_TEST_LOCALE_001 + * @tc.desc: function for IoTest-normal testcases + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(IoTest, IO_TEST_LOCALE_001, TestSize.Level0) +{ + IO_TEST_LOCALE_001(); +} + +/* * + * @tc.name: IO_TEST_LOCALE_002 + * @tc.desc: function for IoTest-innormal testcases + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(IoTest, IO_TEST_LOCALE_002, TestSize.Level0) +{ + IO_TEST_LOCALE_002(); +} + +/* * + * @tc.name: IO_TEST_STRFMON_L_001 + * @tc.desc: function for IoTest-normal testcases + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(IoTest, IO_TEST_STRFMON_L_001, TestSize.Level0) +{ + IO_TEST_STRFMON_L_001(); +} + +/* * + * @tc.name: IO_TEST_STRFMON_L_002 + * @tc.desc: function for IoTest-innormal testcases + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(IoTest, IO_TEST_STRFMON_L_002, TestSize.Level0) +{ + IO_TEST_STRFMON_L_002(); +} + +/* * + * @tc.name: IO_TEST_NGETTEXT_001 + * @tc.desc: function for IoTest-normal testcases + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(IoTest, IO_TEST_NGETTEXT_001, TestSize.Level0) +{ + IO_TEST_NGETTEXT_001(); +} + #endif } // namespace OHOS