diff --git a/libc-test/src/functionalext/common/filepath_util.h b/libc-test/src/functionalext/common/filepath_util.h new file mode 100644 index 0000000000000000000000000000000000000000..0cd0e363e88dd4f6b923b562c0cd1533c476808c --- /dev/null +++ b/libc-test/src/functionalext/common/filepath_util.h @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __FUNCTIONALEXT_FILEPATH_UTIL_H__ +#define __FUNCTIONALEXT_FILEPATH_UTIL_H__ + +#include +#include +#include + +#include "test.h" + +#define STR_SLASH "/" +#define STR_FILE_TXT "file.txt" +#define STR_FILE_LINK_TXT "linkfile.txt" +#define STR_FILE_IN_TXT "file_in.txt" +#define STR_FILE_OUT_TXT "file_out.txt" +#define STR_FILE_FROM_TXT "fromfile.txt" +#define STR_FILE_TO_TXT "tofile.txt" +#define STR_FILE_SWAP "swapfile" +#define STR_FILE_SYNC_TXT "sync_file_range.txt" +#define STR_TEST_TXT "test.txt" +#define STR_STAT_TEST_TXT "stattest.txt" +#define STR_FREAD_TEST_TXT "Freadtest.txt" +#define STR_FPUTC_TXT "fputc.txt" +#define STR_VFSCANF_TXT "vfscanf.txt" +#define STR_FACCESSAT_TEST_TXT "faccessattest.txt" +#define STR_FCHOWNAT_TEST_TXT "fchownattest.txt" +#define STR_WRITE_TEST_TXT "test_write.txt" + +#define FILE_ABSOLUTE_PATH(file_name, path) do { \ + if(!getcwd(path, sizeof(path))) { \ + t_error("%s getcwd for path failed\n", __func__); \ + return; \ + } \ + strncat(path, STR_SLASH, 1); \ + strncat(path, file_name, strlen(file_name)); \ +} while (0) + +#define FILE_ABSOLUTE_DIR(path) do { \ + if(!getcwd(path, sizeof(path))) { \ + t_error("%s getcwd for dir failed\n", __func__); \ + return; \ + } \ +} while (0) + +#endif diff --git a/libc-test/src/functionalext/supplement/dirent/readdir_r.c b/libc-test/src/functionalext/supplement/dirent/readdir_r.c index a5dd5eaf30aa77316ebf88c8bfdafde1080b4cc4..dcaa3ab3addb2f739422e1805fcb32ee9eae6e7e 100644 --- a/libc-test/src/functionalext/supplement/dirent/readdir_r.c +++ b/libc-test/src/functionalext/supplement/dirent/readdir_r.c @@ -17,9 +17,7 @@ #include #include -#include "test.h" - -const char *name = "/data/tests/libc-test/src"; +#include "filepath_util.h" void handler(int sig) { @@ -33,6 +31,8 @@ void handler(int sig) */ void readdir_r_0100(void) { + char name[PATH_MAX] = {0}; + FILE_ABSOLUTE_DIR(name); DIR *dir = opendir(name); if (dir == NULL) { t_error("%s failed: opendir. name = %s\n", __func__, name); diff --git a/libc-test/src/functionalext/supplement/dirent/rewinddir.c b/libc-test/src/functionalext/supplement/dirent/rewinddir.c index 99ea4abff963266bbd91f0416a3ce3b7b20c6ec9..f39a4e414888cc31042f103dcd821e9a5cdcdf31 100644 --- a/libc-test/src/functionalext/supplement/dirent/rewinddir.c +++ b/libc-test/src/functionalext/supplement/dirent/rewinddir.c @@ -18,9 +18,7 @@ #include #include -#include "test.h" - -const char *name = "/data/tests/libc-test/src"; +#include "filepath_util.h" void handler(int sig) { @@ -34,6 +32,8 @@ void handler(int sig) */ void rewinddir_0100(void) { + char name[PATH_MAX] = {0}; + FILE_ABSOLUTE_DIR(name); DIR *dir = opendir(name); if (dir == NULL) { t_error("%s failed: opendir. name = %s\n", __func__, name); diff --git a/libc-test/src/functionalext/supplement/dirent/scandir.c b/libc-test/src/functionalext/supplement/dirent/scandir.c index ed3ca57366fc12122407b79240f45639026d8027..cb3a799c6dc23f28ac53cb85baae9b1b9f58e6a6 100644 --- a/libc-test/src/functionalext/supplement/dirent/scandir.c +++ b/libc-test/src/functionalext/supplement/dirent/scandir.c @@ -16,9 +16,7 @@ #include #include -#include "test.h" - -const char *name = "/data/tests/libc-test/src"; +#include "filepath_util.h" int filter(const struct dirent *entry) { @@ -33,6 +31,9 @@ int filter(const struct dirent *entry) void scandir_0100(void) { struct dirent **namelist; + char name[PATH_MAX] = {0}; + FILE_ABSOLUTE_DIR(name); + int n = scandir(name, &namelist, NULL, alphasort); if (n < 0) { t_error("%s failed: scandir. n = %d\n", __func__, n); @@ -53,6 +54,9 @@ void scandir_0100(void) void scandir_0200(void) { struct dirent **namelist; + char name[PATH_MAX] = {0}; + FILE_ABSOLUTE_DIR(name); + int n = scandir(name, &namelist, NULL, versionsort); if (n < 0) { t_error("%s failed: scandir. n = %d\n", __func__, n); @@ -73,6 +77,8 @@ void scandir_0200(void) void scandir_0300(void) { struct dirent **namelist; + char name[PATH_MAX] = {0}; + FILE_ABSOLUTE_DIR(name); int n = scandir(name, &namelist, filter, versionsort); if (n < 0) { t_error("%s failed: scandir. n = %d\n", __func__, n); diff --git a/libc-test/src/functionalext/supplement/ipc/ftok.c b/libc-test/src/functionalext/supplement/ipc/ftok.c index dcf4a245fded6801567bb8f1aee4b8c339c8b36a..d28a51ad7bff367984bc91c8b1e457c8e6604131 100755 --- a/libc-test/src/functionalext/supplement/ipc/ftok.c +++ b/libc-test/src/functionalext/supplement/ipc/ftok.c @@ -15,6 +15,7 @@ #include #include "functionalext.h" +#include "filepath_util.h" /* * @tc.name : ftok_0100 @@ -23,7 +24,9 @@ */ void ftok_0100(void) { - key_t result = ftok("/data/tests/libc-test/src/functionalext/supplement/ipc/ftok", 1); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("ftok", path); + key_t result = ftok(path, 1); EXPECT_NE("ftok_0100", result, -1); } diff --git a/libc-test/src/functionalext/supplement/ipc/semtimedop.c b/libc-test/src/functionalext/supplement/ipc/semtimedop.c index 344dee5cc7962868f9a2678291a3f00b42682822..dca870d64b54aef6c2aeaaa4e4c70aedfd1c4e93 100644 --- a/libc-test/src/functionalext/supplement/ipc/semtimedop.c +++ b/libc-test/src/functionalext/supplement/ipc/semtimedop.c @@ -18,12 +18,10 @@ #include #include -#include "test.h" +#include "filepath_util.h" extern int __semtimedop_time64(int, struct sembuf *, size_t, const struct timespec *); -const char *path = "/data/tests/libc-test/src/file.txt"; - /** * @tc.name : semtimedop_0100 * @tc.desc : System V semaphore operations @@ -31,6 +29,8 @@ const char *path = "/data/tests/libc-test/src/file.txt"; */ void semtimedop_0100(void) { + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); int fd = open(path, O_RDWR | O_CREAT); if (fd < 0) { t_error("%s failed: fd = %d\n", __func__, fd); diff --git a/libc-test/src/functionalext/supplement/linux/copy_file_range.c b/libc-test/src/functionalext/supplement/linux/copy_file_range.c index 06afe1f674cc2397238bd4a393641bdec23bbf67..8f28c563d6a336d175f122744c1afc8c7c4a4fc2 100644 --- a/libc-test/src/functionalext/supplement/linux/copy_file_range.c +++ b/libc-test/src/functionalext/supplement/linux/copy_file_range.c @@ -17,10 +17,8 @@ #include #include #include -#include "test.h" +#include "filepath_util.h" -const char *path_in = "/data/tests/libc-test/src/file_in.txt"; -const char *path_out = "/data/tests/libc-test/src/file_out.txt"; const char *str = "Hello"; /** @@ -33,6 +31,11 @@ void copy_file_range_0100(void) int fd_in, fd_out, wlen, result; char buffer[BUFSIZ]; + char path_in[PATH_MAX] = {0}; + char path_out[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_IN_TXT, path_in); + FILE_ABSOLUTE_PATH(STR_FILE_OUT_TXT, path_out); + fd_in = open(path_in, O_RDWR | O_CREAT); if (fd_in == -1) { t_error("%s open path_in failed\n", __func__); @@ -107,6 +110,11 @@ void copy_file_range_0300(void) int fd_in, fd_out, wlen, result; char buffer[BUFSIZ]; + char path_in[PATH_MAX] = {0}; + char path_out[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_IN_TXT, path_in); + FILE_ABSOLUTE_PATH(STR_FILE_OUT_TXT, path_out); + fd_in = open(path_in, O_WRONLY | O_CREAT); if (fd_in == -1) { t_error("%s open path_in failed\n", __func__); diff --git a/libc-test/src/functionalext/supplement/linux/removexattr.c b/libc-test/src/functionalext/supplement/linux/removexattr.c index 4f0fdc5aecf00ee4f705b631a1921fd6e0279d22..71e92991a5e1c1dc787d723fcb0f9d39c64ded56 100644 --- a/libc-test/src/functionalext/supplement/linux/removexattr.c +++ b/libc-test/src/functionalext/supplement/linux/removexattr.c @@ -19,9 +19,8 @@ #include #include -#include "test.h" +#include "filepath_util.h" -const char *path = "/data/tests/libc-test/src/file.txt"; const char *name = "user.foo"; const char *value = "bar"; @@ -32,6 +31,8 @@ const char *value = "bar"; */ void removexattr_0100(void) { + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); int fd = open(path, O_RDWR | O_CREAT); if (fd < 0) { t_error("%s failed: fd = %d\n", __func__, fd); diff --git a/libc-test/src/functionalext/supplement/linux/sendfile.c b/libc-test/src/functionalext/supplement/linux/sendfile.c index 6d91621833b1bbf6d48b80c7d9be5f37b5a69696..017934ad8a3a582bfeb0c1eb46ffe737308f1637 100644 --- a/libc-test/src/functionalext/supplement/linux/sendfile.c +++ b/libc-test/src/functionalext/supplement/linux/sendfile.c @@ -19,10 +19,7 @@ #include #include -#include "test.h" - -const char *fromfile = "/data/tests/libc-test/src/fromfile.txt"; -const char *tofile = "/data/tests/libc-test/src/tofile.txt"; +#include "filepath_util.h" /** * @tc.name : sendfile_0100 @@ -31,6 +28,11 @@ const char *tofile = "/data/tests/libc-test/src/tofile.txt"; */ void sendfile_0100(void) { + char fromfile[PATH_MAX] = {0}; + char tofile[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_FROM_TXT, fromfile); + FILE_ABSOLUTE_PATH(STR_FILE_TO_TXT, tofile); + FILE *f = fopen(fromfile, "w+"); const char src[] = "A"; fwrite(src, strlen(src), 1, f); diff --git a/libc-test/src/functionalext/supplement/linux/setxattr.c b/libc-test/src/functionalext/supplement/linux/setxattr.c index fb71224be4e420b5e0b40daabfbe4b70dd062968..60981eec651565d922e57146ab90779bdcfe13ad 100644 --- a/libc-test/src/functionalext/supplement/linux/setxattr.c +++ b/libc-test/src/functionalext/supplement/linux/setxattr.c @@ -19,9 +19,8 @@ #include #include -#include "test.h" +#include "filepath_util.h" -const char *path = "/data/tests/libc-test/src/file.txt"; const char *name = "user.foo"; const char *value = "bar"; @@ -32,6 +31,8 @@ const char *value = "bar"; */ void setxattr_0100(void) { + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); int fd = open(path, O_RDWR | O_CREAT); if (fd < 0) { t_error("%s failed: fd = %d\n", __func__, fd); diff --git a/libc-test/src/functionalext/supplement/linux/splice.c b/libc-test/src/functionalext/supplement/linux/splice.c index 725e4d60e746eeab5bd88edcaeb6185a425fd721..ef00033aa69ac1765100f0a7c2e9da558cd4ce3b 100644 --- a/libc-test/src/functionalext/supplement/linux/splice.c +++ b/libc-test/src/functionalext/supplement/linux/splice.c @@ -19,10 +19,8 @@ #include #include -#include "test.h" +#include "filepath_util.h" -const char *fromfile = "/data/tests/libc-test/src/fromfile.txt"; -const char *tofile = "/data/tests/libc-test/src/tofile.txt"; const char *path = "/proc/version"; /** @@ -32,6 +30,11 @@ const char *path = "/proc/version"; */ void splice_0100(void) { + char fromfile[PATH_MAX] = {0}; + char tofile[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_FROM_TXT, fromfile); + FILE_ABSOLUTE_PATH(STR_FILE_TO_TXT, tofile); + int fromfd = open(fromfile, O_RDWR | O_CREAT); if (fromfd < 0) { t_error("%s failed: fromfd = %d\n", __func__, fromfd); diff --git a/libc-test/src/functionalext/supplement/linux/swapoff.c b/libc-test/src/functionalext/supplement/linux/swapoff.c index 4a9fd576606e49963ef77c749527ba975664c40b..f774d5c727e81ea808da3e6307f153821533d8d4 100644 --- a/libc-test/src/functionalext/supplement/linux/swapoff.c +++ b/libc-test/src/functionalext/supplement/linux/swapoff.c @@ -17,7 +17,8 @@ #include #include #include -#include "test.h" + +#include "filepath_util.h" /** * @tc.name : swapoff_0100 @@ -26,12 +27,19 @@ */ void swapoff_0100(void) { + char dir_path[PATH_MAX] = {0}; + FILE_ABSOLUTE_DIR(dir_path); errno = 0; - system("cd /data/tests/libc-test/src; dd if=/dev/zero of=swapfile count=1 bs=1k; mkswap swapfile"); - int result = swapon("/data/tests/libc-test/src/swapfile", SWAP_FLAG_PREFER); + char cmd[PATH_MAX] = {0}; + snprintf(cmd, sizeof(cmd), "cd %s; dd if=/dev/zero of=swapfile count=1 bs=1k; mkswap swapfile", dir_path); + system(cmd); + + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_SWAP, path); + int result = swapon(path, SWAP_FLAG_PREFER); if (result == -1) { t_error("%s swapon failed\n", __func__); - remove("/data/tests/libc-test/src/swapfile"); + remove(path); return; } if (errno == ENOSYS) { @@ -39,7 +47,7 @@ void swapoff_0100(void) return; } - result = swapoff("/data/tests/libc-test/src/swapfile"); + result = swapoff(path); if (result == -1) { t_error("%s swapoff failed", __func__); } diff --git a/libc-test/src/functionalext/supplement/linux/swapon.c b/libc-test/src/functionalext/supplement/linux/swapon.c index 31bb7de99f8a51cf9aef361cccb06b0dd35b4b37..c0dd521386637cff4fa28f4f55e171660ce00982 100644 --- a/libc-test/src/functionalext/supplement/linux/swapon.c +++ b/libc-test/src/functionalext/supplement/linux/swapon.c @@ -17,7 +17,8 @@ #include #include #include -#include "test.h" + +#include "filepath_util.h" /** * @tc.name : swapon_0100 @@ -26,12 +27,19 @@ */ void swapon_0100(void) { + char dir_path[PATH_MAX] = {0}; + FILE_ABSOLUTE_DIR(dir_path); errno = 0; - system("cd /data/tests/libc-test/src; dd if=/dev/zero of=swapfile count=1 bs=1k; mkswap swapfile"); - int result = swapon("/data/tests/libc-test/src/swapfile", SWAP_FLAG_PREFER); + char cmd[PATH_MAX] = {0}; + snprintf(cmd, sizeof(cmd), "cd %s; dd if=/dev/zero of=swapfile count=1 bs=1k; mkswap swapfile", dir_path); + system(cmd); + + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_SWAP, path); + int result = swapon(path, SWAP_FLAG_PREFER); if (result == -1) { t_error("%s swapon failed\n", __func__); - remove("/data/tests/libc-test/src/swapfile"); + remove(path); } if (errno == ENOSYS) { diff --git a/libc-test/src/functionalext/supplement/linux/sync_file_range.c b/libc-test/src/functionalext/supplement/linux/sync_file_range.c index 32f24c049e0edde7479287cb695534ebcc43d21e..824a9975b9e9cade713eca9cecf5cb9fafa9f449 100644 --- a/libc-test/src/functionalext/supplement/linux/sync_file_range.c +++ b/libc-test/src/functionalext/supplement/linux/sync_file_range.c @@ -17,9 +17,8 @@ #include #include #include -#include "test.h" -const char *path = "/data/tests/libc-test/src/sync_file_range.txt"; +#include "filepath_util.h" /** * @tc.name : sync_file_range_0100 @@ -30,6 +29,8 @@ void sync_file_range_0100(void) { errno = 0; int result, fd; + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_SYNC_TXT, path); fd = open(path, O_RDWR | O_CREAT); if (fd == -1) { @@ -74,6 +75,8 @@ void sync_file_range_0300(void) errno = 0; int result, fd; + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_SYNC_TXT, path); fd = open(path, O_RDWR | O_CREAT); if (fd == -1) { t_error("%s open failed\n", __func__); @@ -101,6 +104,8 @@ void sync_file_range_0400(void) errno = 0; int result, fd; + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_SYNC_TXT, path); fd = open(path, O_RDWR | O_CREAT); if (fd == -1) { t_error("%s open failed\n", __func__); diff --git a/libc-test/src/functionalext/supplement/linux/syncfs.c b/libc-test/src/functionalext/supplement/linux/syncfs.c index cb731f9bcc770f2ffc3638da65b131bc07d7f18c..9f92349f7b64c66a4e229faf3c29bf60c72ad77c 100644 --- a/libc-test/src/functionalext/supplement/linux/syncfs.c +++ b/libc-test/src/functionalext/supplement/linux/syncfs.c @@ -17,9 +17,8 @@ #include #include #include -#include "test.h" -const char *path = "/data/tests/libc-test/src/syncfs.txt"; +#include "filepath_util.h" /** * @tc.name : syncfs_0100 @@ -29,6 +28,8 @@ const char *path = "/data/tests/libc-test/src/syncfs.txt"; void syncfs_0100(void) { errno = 0; + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("syncfs.txt", path); int fd = open(path, O_RDWR | O_CREAT); if (fd == -1) { t_error("%s open failed\n", __func__); diff --git a/libc-test/src/functionalext/supplement/linux/tee.c b/libc-test/src/functionalext/supplement/linux/tee.c index b62561f5ce74c257e4bad1eb506f8936558f8d43..3c21bd72dd961421a84fe7851618d85ea0a6b190 100644 --- a/libc-test/src/functionalext/supplement/linux/tee.c +++ b/libc-test/src/functionalext/supplement/linux/tee.c @@ -17,7 +17,7 @@ #include #include #include -#include "test.h" +#include "filepath_util.h" #define BUFF_SIZE (20) @@ -74,8 +74,9 @@ void tee_0200(void) { char buf[BUFF_SIZE]; char *text = "Hello"; - char *path = "/data/tests/libc-test/src/file.txt"; int result; + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); int fd = open(path, O_CREAT | O_WRONLY | O_TRUNC, 0666); if (fd < 0) { diff --git a/libc-test/src/functionalext/supplement/mman/mincore.c b/libc-test/src/functionalext/supplement/mman/mincore.c index 6f4c1b3ab5f46a966bd05505ca07e592b19721ab..b954174d0cead1386947c4d5e9b81d7dac3e5a0d 100755 --- a/libc-test/src/functionalext/supplement/mman/mincore.c +++ b/libc-test/src/functionalext/supplement/mman/mincore.c @@ -19,6 +19,7 @@ #include #include #include "functionalext.h" +#include "filepath_util.h" #define TEST_SIZE 4096 @@ -30,7 +31,9 @@ void mincore_0100(void) { struct stat st; - const char *pathname = "/data/tests/libc-test/src/functionalext/supplement/mman/mincore"; + char pathname[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("mincore", pathname); + int ret = stat(pathname, &st); EXPECT_EQ("mincore_0100", ret, CMPFLAG); if (ret != 0) { diff --git a/libc-test/src/functionalext/supplement/stat/fchmodat.c b/libc-test/src/functionalext/supplement/stat/fchmodat.c index acdb77144e3db8fe80c245f5f85262d1a466fffa..216aa97ab7ce886fd1698b2d672eec915353dba0 100755 --- a/libc-test/src/functionalext/supplement/stat/fchmodat.c +++ b/libc-test/src/functionalext/supplement/stat/fchmodat.c @@ -16,6 +16,7 @@ #include #include #include "functionalext.h" +#include "filepath_util.h" int success = 36863; int SUCCESS = 33279; @@ -30,17 +31,19 @@ void fchmodat_0100(void) { int fd; struct stat buf; - fd = open("/data/tests/libc-test/src/functionalext/supplement/stat/test.txt", O_RDWR | O_CREAT); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_TEST_TXT, path); + fd = open(path, O_RDWR | O_CREAT); int result = fchmodat(fd, - "/data/tests/libc-test/src/functionalext/supplement/stat/test.txt", + path, S_ISUID | S_ISGID | S_ISVTX | S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH, AT_SYMLINK_NOFOLLOW); - stat("/data/tests/libc-test/src/functionalext/supplement/stat/test.txt", &buf); + stat(path, &buf); EXPECT_EQ("fchmodat_0100", result, 0); EXPECT_EQ("fchmodat_0100", buf.st_mode, success); close(fd); - remove("/data/tests/libc-test/src/functionalext/supplement/stat/test.txt"); + remove(path); } /** @@ -52,16 +55,18 @@ void fchmodat_0200(void) { int fd; struct stat buf; - fd = open("/data/tests/libc-test/src/functionalext/supplement/stat/test.txt", O_RDWR | O_CREAT); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_TEST_TXT, path); + fd = open(path, O_RDWR | O_CREAT); int result = fchmodat(fd, - "/data/tests/libc-test/src/functionalext/supplement/stat/test.txt", + path, S_IRWXU | S_IRWXG | S_IRWXO, AT_SYMLINK_NOFOLLOW); - stat("/data/tests/libc-test/src/functionalext/supplement/stat/test.txt", &buf); + stat(path, &buf); EXPECT_EQ("fchmodat_0200", result, 0); EXPECT_EQ("fchmodat_0200", buf.st_mode, SUCCESS); close(fd); - remove("/data/tests/libc-test/src/functionalext/supplement/stat/test.txt"); + remove(path); } /** diff --git a/libc-test/src/functionalext/supplement/stat/fstatat.c b/libc-test/src/functionalext/supplement/stat/fstatat.c index 447f36d78e124b06a6cb5a63fd3184a3ff044366..631a9adb3335685fc119c49ba7cc737e8ef8d1ef 100644 --- a/libc-test/src/functionalext/supplement/stat/fstatat.c +++ b/libc-test/src/functionalext/supplement/stat/fstatat.c @@ -17,6 +17,7 @@ #include #include #include "functionalext.h" +#include "filepath_util.h" const int SUCCESS = 0; @@ -84,7 +85,9 @@ void fstatat_0200(void) */ void fstatat_0300(void) { - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stat/fstatattest.txt"; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("fstatattest.txt", ptr); + struct stat st; int fd = open(ptr, O_RDWR | O_CREAT); EXPECT_TRUE("fstatat_0300", fd >= 0); @@ -97,7 +100,6 @@ void fstatat_0300(void) EXPECT_EQ("fstatat_0300", st.st_gid, gid); close(fd); remove(ptr); - ptr = NULL; } /** diff --git a/libc-test/src/functionalext/supplement/stat/lstat.c b/libc-test/src/functionalext/supplement/stat/lstat.c index 5f7819c93f1e82939821c905a6ee086c17b8f762..47479fd9cc204643471bde773c71eee3a9104da0 100755 --- a/libc-test/src/functionalext/supplement/stat/lstat.c +++ b/libc-test/src/functionalext/supplement/stat/lstat.c @@ -18,6 +18,7 @@ #include #include #include "functionalext.h" +#include "filepath_util.h" extern int __lstat_time64(const char *__restrict, struct stat *__restrict); @@ -30,7 +31,9 @@ typedef void (*TEST_FUN)(); */ void lstat_0100(void) { - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stattest.txt"; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_STAT_TEST_TXT, ptr); + const char str[] = "this is a sample!"; FILE *fptr = fopen(ptr, "w+"); struct stat statbuff; @@ -50,7 +53,9 @@ void lstat_0100(void) */ void lstat_time64_0100(void) { - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stattest.txt"; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_STAT_TEST_TXT, ptr); + const char str[] = "this is a sample!"; FILE *fptr = fopen(ptr, "w+"); struct stat statbuff; @@ -71,7 +76,7 @@ void lstat_time64_0100(void) void lstat_0200(void) { struct stat statbuff; - int32_t back = lstat("test.txt", &statbuff); + int32_t back = lstat(STR_TEST_TXT, &statbuff); EXPECT_EQ("lstat_0200", back, -1); } @@ -83,12 +88,15 @@ void lstat_0200(void) void lstat_0300(void) { struct stat buf[3]; - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stat/tests.txt"; - const char *ptrlink = "/data/tests/libc-test/src/functionalext/supplement/stat/tests.txt.soft"; + char ptr[PATH_MAX] = {0}; + char ptrlink[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("tests.txt", ptr); + FILE_ABSOLUTE_PATH("tests.txt.soft", ptrlink); FILE *fptr = fopen(ptr, "w+"); - system("ln -s /data/tests/libc-test/src/functionalext/supplement/stat/tests.txt " - "/data/tests/libc-test/src/functionalext/supplement/stat/tests.txt.soft"); + char cmd[PATH_MAX] = {0}; + snprintf(cmd, sizeof(cmd), "ln -s %s %s", ptr, ptrlink); + system(cmd); struct stat statbuff; int32_t back = lstat(ptrlink, &statbuff); EXPECT_EQ("lstat_0300", back, 0); @@ -119,4 +127,4 @@ int main(int argc, char *argv[]) } return t_status; -} \ No newline at end of file +} diff --git a/libc-test/src/functionalext/supplement/stat/mknod.c b/libc-test/src/functionalext/supplement/stat/mknod.c index beceed4062e104f7fd9c0a794d95e4ed9da4e624..0dff1c6e75b4a385ba90cf1f130718d84ac0aed7 100755 --- a/libc-test/src/functionalext/supplement/stat/mknod.c +++ b/libc-test/src/functionalext/supplement/stat/mknod.c @@ -15,6 +15,7 @@ #include #include "functionalext.h" +#include "filepath_util.h" #define TEST_MODE 0666 @@ -25,7 +26,8 @@ */ void mknod_0100(void) { - const char *pathname = "/data/tests/libc-test/src/functionalext/supplement/stat/mknod"; + char pathname[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("mknod", pathname); int ret = mknod(pathname, TEST_MODE, 0); EXPECT_EQ("mknod_0100", ret, ERREXPECT); } diff --git a/libc-test/src/functionalext/supplement/stat/utimensat.c b/libc-test/src/functionalext/supplement/stat/utimensat.c index 441414468eef30b80f425c8e457459ea95fbbf1f..86274c9b67a11899f6c5809348932a4bae1be16c 100644 --- a/libc-test/src/functionalext/supplement/stat/utimensat.c +++ b/libc-test/src/functionalext/supplement/stat/utimensat.c @@ -17,10 +17,8 @@ #include #include #include +#include "filepath_util.h" -#include "test.h" - -const char *path = "/data/tests/libc-test/src/file.txt"; const long sec = 123840; extern int __utimensat_time64(int, const char *, const struct timespec [2], int); @@ -32,6 +30,8 @@ extern int __utimensat_time64(int, const char *, const struct timespec [2], int) */ void utimensat_0100(void) { + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); int fd = open(path, O_RDWR | O_CREAT); struct timespec times[] = {{.tv_sec = 0}, {.tv_sec = sec}}; @@ -80,6 +80,8 @@ void utimensat_0200(void) */ void utimensat_time64_0100(void) { + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); int fd = open(path, O_RDWR | O_CREAT); struct timespec times[] = {{.tv_sec = 0}, {.tv_sec = sec}}; diff --git a/libc-test/src/functionalext/supplement/stdio/__fwritable.c b/libc-test/src/functionalext/supplement/stdio/__fwritable.c index 1cad01b0baafc1bb0ba26131748397de136d31aa..667654dcce1faf39d4cdce5d45dd0ff80d7e19e2 100644 --- a/libc-test/src/functionalext/supplement/stdio/__fwritable.c +++ b/libc-test/src/functionalext/supplement/stdio/__fwritable.c @@ -15,6 +15,7 @@ #include #include "functionalext.h" +#include "filepath_util.h" const int32_t NUM_ZERO = 0; @@ -25,7 +26,8 @@ const int32_t NUM_ZERO = 0; */ void __fwritable_0100(void) { - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stdio/Freadtest.txt"; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FREAD_TEST_TXT, ptr); FILE *fptr = fopen(ptr, "w+"); if (!fptr) { t_error("%s fopen failed\n", __func__); @@ -42,7 +44,8 @@ void __fwritable_0100(void) */ void __fwritable_0200(void) { - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stdio/Freadtest.txt"; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FREAD_TEST_TXT, ptr); FILE *fptr = fopen(ptr, "r"); if (!fptr) { t_error("%s fopen failed\n", __func__); diff --git a/libc-test/src/functionalext/supplement/stdio/__fwriting.c b/libc-test/src/functionalext/supplement/stdio/__fwriting.c index b029c9d67f702199fc5a890ef52ad9cbd0aa204c..35a5a41be9f3e010f70b7ced904c7be5d0b0956c 100644 --- a/libc-test/src/functionalext/supplement/stdio/__fwriting.c +++ b/libc-test/src/functionalext/supplement/stdio/__fwriting.c @@ -19,6 +19,7 @@ #include #include #include "functionalext.h" +#include "filepath_util.h" const int32_t NUM_ZERO = 0; @@ -29,7 +30,8 @@ const int32_t NUM_ZERO = 0; */ void __fwriting_0100(void) { - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stdio/Freadtest.txt"; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FREAD_TEST_TXT, ptr); FILE *fptr = fopen(ptr, "w"); int result = __fwriting(fptr); EXPECT_NE("__fwriting_0100", result, NUM_ZERO); @@ -45,7 +47,8 @@ void __fwriting_0100(void) void __fwriting_0200(void) { const char *wrstring = "helloworld"; - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stdio/Freadtest.txt"; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FREAD_TEST_TXT, ptr); FILE *fptr = fopen(ptr, "w+"); fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); int result = __fwriting(fptr); @@ -63,7 +66,8 @@ void __fwriting_0300(void) { char abc[100] = {0}; const char *wrstring = "helloworld"; - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stdio/Freadtest.txt"; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FREAD_TEST_TXT, ptr); FILE *fptr = fopen(ptr, "w+"); fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); fseek(fptr, 0, SEEK_SET); diff --git a/libc-test/src/functionalext/supplement/stdio/fputc.c b/libc-test/src/functionalext/supplement/stdio/fputc.c index 4d26ff34d6165b55952bc02d0353427915e5edc0..f4b504a7cd32df339cb633e315ff665b95ed7c1f 100644 --- a/libc-test/src/functionalext/supplement/stdio/fputc.c +++ b/libc-test/src/functionalext/supplement/stdio/fputc.c @@ -14,8 +14,7 @@ */ #include "functionalext.h" - -const char *path = "/data/tests/libc-test/src/functionalext/supplement/stdio/fputc.txt"; +#include "filepath_util.h" /** * @tc.name : fputc_0100 @@ -24,6 +23,8 @@ const char *path = "/data/tests/libc-test/src/functionalext/supplement/stdio/fpu */ void fputc_0100(void) { + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FPUTC_TXT, path); FILE *fptr = fopen(path, "w"); int Exit = fputc('a', fptr); EXPECT_EQ("fputc_0100", Exit, 97); @@ -37,6 +38,8 @@ void fputc_0100(void) */ void fputc_0200(void) { + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FPUTC_TXT, path); FILE *fptr = fopen(path, "r"); int Exit = fputc('a', fptr); EXPECT_EQ("fputc_0200", Exit, EOF); diff --git a/libc-test/src/functionalext/supplement/stdio/freopen.c b/libc-test/src/functionalext/supplement/stdio/freopen.c index 3ab010d56b474026a7efef6ffaba11cab0ce865b..742d907caca402ffae4ce7bc6cfe0441560ab121 100644 --- a/libc-test/src/functionalext/supplement/stdio/freopen.c +++ b/libc-test/src/functionalext/supplement/stdio/freopen.c @@ -15,6 +15,7 @@ #include #include "functionalext.h" +#include "filepath_util.h" /** * @tc.name : freopen_0100 @@ -23,8 +24,10 @@ */ void freopen_0100(void) { + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("freopen.txt", ptr); + FILE *fp; - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stdio/freopen.txt"; fp = freopen(ptr, "w+", stdin); EXPECT_PTRNE("freopen_0100", fp, NULL); diff --git a/libc-test/src/functionalext/supplement/stdio/getline.c b/libc-test/src/functionalext/supplement/stdio/getline.c index 4b9cc31472c69f0778fbcea973558358fb7305c2..3e74f6b4caf6eb237dab1da7c1e52dbcac52add2 100644 --- a/libc-test/src/functionalext/supplement/stdio/getline.c +++ b/libc-test/src/functionalext/supplement/stdio/getline.c @@ -15,8 +15,7 @@ #include #include "functionalext.h" - -const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stdio/test.txt"; +#include "filepath_util.h" /** * @tc.name : getline_0100 @@ -28,7 +27,8 @@ void getline_0100(void) char *wrstring = "helloworld"; char *line = NULL; size_t len = 0; - + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_TEST_TXT, ptr); FILE *fp = fopen(ptr, "w+"); EXPECT_PTRNE("getline_0100", fp, NULL); fwrite(wrstring, sizeof(char), strlen(wrstring), fp); @@ -50,6 +50,8 @@ void getline_0100(void) void getline_0200(void) { size_t len = 0; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, ptr); FILE *fp = fopen(ptr, "w+"); EXPECT_PTRNE("getline_0100", fp, NULL); @@ -68,6 +70,8 @@ void getline_0200(void) void getline_0300(void) { char *line = NULL; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, ptr); FILE *fp = fopen(ptr, "w+"); EXPECT_PTRNE("getline_0100", fp, NULL); diff --git a/libc-test/src/functionalext/supplement/stdio/setbuf.c b/libc-test/src/functionalext/supplement/stdio/setbuf.c index dbbd0e17d80474338726c446b7cc3914ee8d6093..98f1409d16f50008f1d62000a08a32d2c5bb6583 100644 --- a/libc-test/src/functionalext/supplement/stdio/setbuf.c +++ b/libc-test/src/functionalext/supplement/stdio/setbuf.c @@ -17,9 +17,8 @@ #include #include -#include "test.h" +#include "filepath_util.h" -const char *path = "/data/tests/libc-test/src/file.txt"; const char *str = "Hello"; /** @@ -30,6 +29,8 @@ const char *str = "Hello"; void setbuf_0100(void) { char buf[BUFSIZ] = {0}; + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); FILE *f = fopen(path, "w+"); errno = 0; setbuf(f, buf); @@ -56,6 +57,8 @@ void setbuf_0100(void) */ void setbuf_0200(void) { + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); FILE *f = fopen(path, "w+"); errno = 0; diff --git a/libc-test/src/functionalext/supplement/stdio/setbuffer.c b/libc-test/src/functionalext/supplement/stdio/setbuffer.c index e74ffdf8d46e91300fc51f30a8c6194dc59f8da5..1413f143a62c7b1b43b5fc7d474952b01fe25a99 100644 --- a/libc-test/src/functionalext/supplement/stdio/setbuffer.c +++ b/libc-test/src/functionalext/supplement/stdio/setbuffer.c @@ -16,9 +16,8 @@ #include #include #include -#include "test.h" +#include "filepath_util.h" -const char *path = "/data/tests/libc-test/src/file.txt"; const char *str = "Hello"; /** @@ -28,6 +27,8 @@ const char *str = "Hello"; */ void setbuffer_0100(void) { + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); FILE *fp = fopen(path, "w+"); char buf[BUFSIZ] = {0}; errno = 0; @@ -60,6 +61,8 @@ void setbuffer_0100(void) */ void setbuffer_0200(void) { + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); FILE *f = fopen(path, "w+"); errno = 0; diff --git a/libc-test/src/functionalext/supplement/stdio/setlinebuf.c b/libc-test/src/functionalext/supplement/stdio/setlinebuf.c index 25e0f1a9b6374048f71876ad66ce2709d65ddc26..635b4db007bb45ad62fa7c407f836d2325f52050 100644 --- a/libc-test/src/functionalext/supplement/stdio/setlinebuf.c +++ b/libc-test/src/functionalext/supplement/stdio/setlinebuf.c @@ -16,9 +16,8 @@ #include #include #include -#include "test.h" +#include "filepath_util.h" -const char *path = "/data/tests/libc-test/src/file.txt"; const char *str = "Hello"; /** @@ -28,6 +27,8 @@ const char *str = "Hello"; */ void setlinebuf_0100(void) { + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); FILE *f = fopen(path, "w+"); char buffer[BUFSIZ]; errno = 0; diff --git a/libc-test/src/functionalext/supplement/stdio/setvbuf.c b/libc-test/src/functionalext/supplement/stdio/setvbuf.c index 5be1fae0fdf767c28327c67beadbfd73c640494e..6a15f29b4f837b488278e3e21f7ae1fa9acc8b61 100644 --- a/libc-test/src/functionalext/supplement/stdio/setvbuf.c +++ b/libc-test/src/functionalext/supplement/stdio/setvbuf.c @@ -14,8 +14,7 @@ */ #include "functionalext.h" - -const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stdio/test.txt"; +#include "filepath_util.h" /** * @tc.name : setvbuf_0100 @@ -24,15 +23,17 @@ const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stdio/test */ void setvbuf_0100(void) { - char buff[1024]; - FILE *fptr = fopen(ptr, "w+"); + char buff[1024] = {0}; + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); + FILE *fptr = fopen(path, "w+"); EXPECT_PTRNE("setvbuf_0100", fptr, NULL); int result = setvbuf(fptr, buff, _IOFBF, 1024); EXPECT_EQ("setvbuf_0100", result, 0); fclose(fptr); - remove(ptr); + remove(path); } /** @@ -42,15 +43,17 @@ void setvbuf_0100(void) */ void setvbuf_0200(void) { - char buff[1024]; - FILE *fptr = fopen(ptr, "w+"); + char buff[1024] = {0}; + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); + FILE *fptr = fopen(path, "w+"); EXPECT_PTRNE("setvbuf_0100", fptr, NULL); int result = setvbuf(fptr, buff, -1, 1024); EXPECT_EQ("setvbuf_0200", result, -1); fclose(fptr); - remove(ptr); + remove(path); } int main(int argc, char *argv[]) diff --git a/libc-test/src/functionalext/supplement/stdio/ungetwc.c b/libc-test/src/functionalext/supplement/stdio/ungetwc.c index 8c09ba0aece567639e4c4716154c874eeb15e8a5..9f245c7d2d206fcf34aa84767bdf46db42eb7af5 100644 --- a/libc-test/src/functionalext/supplement/stdio/ungetwc.c +++ b/libc-test/src/functionalext/supplement/stdio/ungetwc.c @@ -18,9 +18,7 @@ #include #include -#include "test.h" - -const char *path = "/data/tests/libc-test/src/file.txt"; +#include "filepath_util.h" void handler(int sig) { @@ -34,6 +32,8 @@ void handler(int sig) */ void ungetwc_0100(void) { + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); FILE *file = fopen(path, "a+"); if (!file) { t_error("%s failed: fopen\n", __func__); diff --git a/libc-test/src/functionalext/supplement/stdio/vfscanf.c b/libc-test/src/functionalext/supplement/stdio/vfscanf.c index f5a99db350f09efaf08db21ecfd7739e19c15760..9611c7c20c554ee2222496c5ec6ebc20a8cac8bd 100644 --- a/libc-test/src/functionalext/supplement/stdio/vfscanf.c +++ b/libc-test/src/functionalext/supplement/stdio/vfscanf.c @@ -16,9 +16,7 @@ #include #include #include -#include "test.h" - -const char *file = "/data/tests/libc-test/src/functionalext/supplement/stdio/vfscanf.txt"; +#include "filepath_util.h" int readFile(FILE *stream, char *fmt, ...) { @@ -39,6 +37,8 @@ void vfscanf_0100(void) FILE *fp = NULL; int val = 0; char buffer[BUFSIZ]; + char file[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_VFSCANF_TXT, file); fp = fopen(file, "w+"); if (fp == NULL) { t_error("%s fopen failed\n", __func__); @@ -74,6 +74,8 @@ void vfscanf_0200(void) FILE *fp = NULL; char val[BUFSIZ]; char buffer[BUFSIZ]; + char file[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_VFSCANF_TXT, file); fp = fopen(file, "w+"); if (fp == NULL) { t_error("%s fopen failed\n", __func__); @@ -109,6 +111,8 @@ void vfscanf_0300(void) FILE *fp = NULL; int val1 = 0; int val2 = 0; + char file[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_VFSCANF_TXT, file); fp = fopen(file, "w+"); if (fp == NULL) { t_error("%s fopen failed", __func__); diff --git a/libc-test/src/functionalext/supplement/unistd/acct.c b/libc-test/src/functionalext/supplement/unistd/acct.c index a4f5ef36ab3dc9d488ee9a0bf5a8a91963ecac67..9286d752a6e6d9a4a0f989042638023da69715f5 100644 --- a/libc-test/src/functionalext/supplement/unistd/acct.c +++ b/libc-test/src/functionalext/supplement/unistd/acct.c @@ -16,6 +16,7 @@ #include #include #include "functionalext.h" +#include "filepath_util.h" /** * @tc.name : acct_0100 @@ -35,7 +36,8 @@ void acct_0100(void) */ void acct_0200(void) { - const char *filePath = "/data/tests/libc-test/src/functionalext/supplement/unistd/accttest.txt"; + char filePath[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("accttest.txt", filePath); int result = acct(filePath); EXPECT_EQ("acct_0300", result, -1); remove(filePath); diff --git a/libc-test/src/functionalext/supplement/unistd/exit.c b/libc-test/src/functionalext/supplement/unistd/exit.c index 22eec7bc0cad2ad8e81d2cf1b070197be7c3dc39..6cd8c218830082f475abf4904c826e60061a4ae4 100755 --- a/libc-test/src/functionalext/supplement/unistd/exit.c +++ b/libc-test/src/functionalext/supplement/unistd/exit.c @@ -15,6 +15,7 @@ #include #include "functionalext.h" +#include "filepath_util.h" /* * @tc.name : exit_0100 @@ -24,7 +25,11 @@ */ void exit_0100(void) { - system("cd /data/tests/libc-test/src/functionalext/supplement/unistd/; ./exittest01"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_DIR(path); + char cmd[PATH_MAX] = {0}; + snprintf(cmd, sizeof(cmd), "cd %s; ./exittest01", path); + system(cmd); char str[100] = {0}; const char *ptr = "/data/Exittest01.txt"; @@ -54,7 +59,11 @@ void exit_0100(void) */ void exit_0200(void) { - system("cd /data/tests/libc-test/src/functionalext/supplement/unistd/; ./exittest02"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_DIR(path); + char cmd[PATH_MAX] = {0}; + snprintf(cmd, sizeof(cmd), "cd %s; ./exittest02", path); + system(cmd); char abc[100] = {0}; const char *ptr = "/data/Exittest02.txt"; diff --git a/libc-test/src/functionalext/supplement/unistd/faccessat.c b/libc-test/src/functionalext/supplement/unistd/faccessat.c index 24b91b2191f1fc9813a718030b037bd2a7d57be5..a732e015e74cf320d1a467e6a6c382a715c92bde 100644 --- a/libc-test/src/functionalext/supplement/unistd/faccessat.c +++ b/libc-test/src/functionalext/supplement/unistd/faccessat.c @@ -17,6 +17,7 @@ #include #include #include "functionalext.h" +#include "filepath_util.h" typedef void (*TEST_FUN)(); const int SUCCESS = 0; @@ -29,14 +30,14 @@ const int FAILED = -1; */ void faccessat_0100(void) { - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT); EXPECT_TRUE("faccessat_0100", fd >= 0); int isExist = faccessat(fd, ptr, F_OK, 0); EXPECT_EQ("faccessat_0100", isExist, SUCCESS); close(fd); remove(ptr); - ptr = NULL; } /** @@ -46,13 +47,13 @@ void faccessat_0100(void) */ void faccessat_0200(void) { - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); int fd = -1; int isExist = faccessat(fd, ptr, F_OK, 0); EXPECT_EQ("faccessat_0200", isExist, FAILED); close(fd); remove(ptr); - ptr = NULL; } /** @@ -62,14 +63,14 @@ void faccessat_0200(void) */ void faccessat_0300(void) { - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT, 00040); EXPECT_TRUE("faccessat_0300", fd >= 0); int isRead = faccessat(fd, ptr, R_OK, 0); EXPECT_EQ("faccessat_0300", isRead, SUCCESS); close(fd); remove(ptr); - ptr = NULL; } /** @@ -79,14 +80,14 @@ void faccessat_0300(void) */ void faccessat_0400(void) { - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT, 00020); EXPECT_TRUE("faccessat_0400", fd >= 0); int isWrite = faccessat(fd, ptr, W_OK, 0); EXPECT_EQ("faccessat_0400", isWrite, SUCCESS); close(fd); remove(ptr); - ptr = NULL; } /** @@ -96,15 +97,17 @@ void faccessat_0400(void) */ void faccessat_0500(void) { - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT, 00010); - system("chmod 777 /data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"); + char cmd[256] = {0}; + snprintf(cmd, sizeof(cmd), "chmod 777 %s", ptr); + system(cmd); EXPECT_TRUE("faccessat_0500", fd >= 0); int isExecute = faccessat(fd, ptr, X_OK, 0); EXPECT_EQ("faccessat_0500", isExecute, SUCCESS); close(fd); remove(ptr); - ptr = NULL; } /** @@ -114,14 +117,14 @@ void faccessat_0500(void) */ void faccessat_0600(void) { - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT); EXPECT_TRUE("faccessat_0600", fd >= 0); int isExecute = faccessat(fd, ptr, X_OK, 0); EXPECT_EQ("faccessat_0600", isExecute, FAILED); close(fd); remove(ptr); - ptr = NULL; } /** @@ -131,14 +134,14 @@ void faccessat_0600(void) */ void faccessat_0700(void) { - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT, 00070); EXPECT_TRUE("faccessat_0700", fd >= 0); int isExecute = faccessat(fd, ptr, R_OK | W_OK | X_OK, 0); EXPECT_EQ("faccessat_0700", isExecute, SUCCESS); close(fd); remove(ptr); - ptr = NULL; } /** @@ -148,14 +151,14 @@ void faccessat_0700(void) */ void faccessat_0800(void) { - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT); EXPECT_TRUE("faccessat_0800", fd >= 0); int isExecute = faccessat(fd, ptr, R_OK | W_OK | X_OK, 0); EXPECT_EQ("faccessat_0800", isExecute, FAILED); close(fd); remove(ptr); - ptr = NULL; } /** @@ -165,7 +168,8 @@ void faccessat_0800(void) */ void faccessat_0900(void) { - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT, 00070); EXPECT_TRUE("faccessat_0900", fd >= 0); int ret = faccessat(fd, ptr, R_OK, AT_SYMLINK_NOFOLLOW); @@ -173,7 +177,6 @@ void faccessat_0900(void) EXPECT_EQ("faccessat_0900", errno, 22); close(fd); remove(ptr); - ptr = NULL; } /** @@ -184,14 +187,14 @@ void faccessat_0900(void) */ void faccessat_1000(void) { - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT, 00070); EXPECT_TRUE("faccessat_1000", fd >= 0); int isExecute = faccessat(AT_FDCWD, ptr, R_OK | W_OK | X_OK, AT_EACCESS); EXPECT_EQ("faccessat_1000", isExecute, SUCCESS); close(fd); remove(ptr); - ptr = NULL; } /** @@ -202,14 +205,14 @@ void faccessat_1000(void) */ void faccessat_1100(void) { - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/faccessattest.txt"; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT); EXPECT_TRUE("faccessat_1100", fd >= 0); int isExecute = faccessat(AT_FDCWD, ptr, R_OK | W_OK | X_OK, AT_EACCESS); EXPECT_EQ("faccessat_1100", isExecute, FAILED); close(fd); remove(ptr); - ptr = NULL; } TEST_FUN G_Fun_Array[] = { diff --git a/libc-test/src/functionalext/supplement/unistd/fchownat.c b/libc-test/src/functionalext/supplement/unistd/fchownat.c index 16e7e81c51d66925c8330ba8005759c076b35a0b..e20599c1454fbdeef443697bd1fb54cedc9d34aa 100644 --- a/libc-test/src/functionalext/supplement/unistd/fchownat.c +++ b/libc-test/src/functionalext/supplement/unistd/fchownat.c @@ -17,6 +17,7 @@ #include #include #include "functionalext.h" +#include "filepath_util.h" /** * @tc.name : fchownat_0100 @@ -25,7 +26,8 @@ */ void fchownat_0100(void) { - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/fchownattest.txt"; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FCHOWNAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT); EXPECT_TRUE("fchownat_0100", fd >= 0); int ret = fchownat(fd, ptr, 0, 0, AT_SYMLINK_NOFOLLOW); @@ -37,7 +39,6 @@ void fchownat_0100(void) EXPECT_EQ("fchownat_0100", buf.st_gid, 0); close(fd); remove(ptr); - ptr = NULL; } /** @@ -47,7 +48,8 @@ void fchownat_0100(void) */ void fchownat_0200(void) { - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/fchownattest.txt"; + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FCHOWNAT_TEST_TXT, ptr); int fd = open(ptr, O_RDWR | O_CREAT); EXPECT_TRUE("fchownat_0200", fd >= 0); int ret = fchownat(AT_FDCWD, ptr, 0, 0, AT_SYMLINK_NOFOLLOW); @@ -59,7 +61,6 @@ void fchownat_0200(void) EXPECT_EQ("fchownat_0200", buf.st_gid, 0); close(fd); remove(ptr); - ptr = NULL; } int main(int argc, char *argv[]) diff --git a/libc-test/src/functionalext/supplement/unistd/getcwd.c b/libc-test/src/functionalext/supplement/unistd/getcwd.c index 07b9c583dbd4beda3c25891b0e2964ef57efa10e..38538094d21586ea305b413bf2a6e787bba15b58 100755 --- a/libc-test/src/functionalext/supplement/unistd/getcwd.c +++ b/libc-test/src/functionalext/supplement/unistd/getcwd.c @@ -20,7 +20,7 @@ #include "functionalext.h" // Manual test result -char *manual = "/data/tests/libc-test/src/functionalext/supplement/unistd"; +char *manual = "/data/tests/libc-test/src/"; // hdc shell test result char *hdc_auto = "/"; @@ -33,7 +33,7 @@ char *hdc_auto = "/"; void getcwd_0100(void) { char *result; - char buf[200]; + char buf[200] = {0}; result = getcwd(buf, sizeof(buf)); if (!(strcmp(result, manual) ^ strcmp(result, hdc_auto))) { @@ -63,7 +63,7 @@ void getcwd_0200(void) void getcwd_0300(void) { char *result; - char buf[200]; + char buf[200] = {0}; result = getcwd(buf, 0); if (result) { t_error("%s getcwd should failed, the result should be null\n", __func__); diff --git a/libc-test/src/functionalext/supplement/unistd/getpid.c b/libc-test/src/functionalext/supplement/unistd/getpid.c index 6f1239e1666500069dabecea767e52fe98fc01dd..439ae457e711827a14b34b3241ec50206fef28b5 100755 --- a/libc-test/src/functionalext/supplement/unistd/getpid.c +++ b/libc-test/src/functionalext/supplement/unistd/getpid.c @@ -18,6 +18,7 @@ #include #include #include "functionalext.h" +#include "filepath_util.h" /** * @tc.name : getpid_0100 @@ -26,11 +27,13 @@ */ void getpid_0100(void) { - system("ps -eo command,pid | grep -E \"PID|getpid\" > " - "/data/tests/libc-test/src/functionalext/supplement/unistd/ps.txt"); + char ptr[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("ps.txt", ptr); + char cmd[PATH_MAX] = {0}; + snprintf(cmd, sizeof(cmd), "ps -eo command,pid | grep -E \"PID|getpid\" > %s", ptr); + system(cmd); char abc[256] = {0}; bool successflag = false; - const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/unistd/ps.txt"; FILE *fptr = fopen(ptr, "r"); if (fptr) { while (!feof(fptr)) { diff --git a/libc-test/src/functionalext/supplement/unistd/lchown.c b/libc-test/src/functionalext/supplement/unistd/lchown.c index 8e5a1ad27691fcf9dd6d91f45d601c9e5f76fcd2..32823bf30a0ad87ea60deefdd7d79b16e8efd37c 100755 --- a/libc-test/src/functionalext/supplement/unistd/lchown.c +++ b/libc-test/src/functionalext/supplement/unistd/lchown.c @@ -15,6 +15,7 @@ #include #include "functionalext.h" +#include "filepath_util.h" #define TEST_ID_VALUE 100 @@ -25,7 +26,8 @@ */ void lchown_0100(void) { - const char *pathname = "/data/tests/libc-test/src/functionalext/supplement/unistd/lchown"; + char pathname[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("lchown", pathname); int ret = lchown(pathname, TEST_ID_VALUE, TEST_ID_VALUE); EXPECT_EQ("lchown_0100", ret, CMPFLAG); } diff --git a/libc-test/src/functionalext/supplement/unistd/readlinkat.c b/libc-test/src/functionalext/supplement/unistd/readlinkat.c index c149ef834a4b4869ca4369b19e1944eee58d0650..803e7b90e6daa2479cc721aaa18928ca15c25317 100644 --- a/libc-test/src/functionalext/supplement/unistd/readlinkat.c +++ b/libc-test/src/functionalext/supplement/unistd/readlinkat.c @@ -19,16 +19,13 @@ #include #include -#include "test.h" +#include "filepath_util.h" -const char *path = "/data/tests/file.txt"; -const char *linkpath = "/data/tests/linkfile.txt"; const char buf[] = "hello"; -const char *dirname = "/data/tests"; const char *filename = "./file.txt"; const char *linkfilename = "./linkfile.txt"; -int create_file(void) +int create_file(char *path) { int fd = open(path, O_RDWR | O_CREAT); if (fd < 0) { @@ -55,12 +52,16 @@ int create_file(void) */ void readlinkat_0100(void) { - int result = create_file(); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); + int result = create_file(path); if (result != 0) { t_error("%s failed: result = %d\n", __func__, result); return; } + char linkpath[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_LINK_TXT, linkpath); remove(linkpath); result = symlink(path, linkpath); @@ -96,12 +97,16 @@ void readlinkat_0100(void) */ void readlinkat_0200(void) { - int result = create_file(); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); + int result = create_file(path); if (result != 0) { t_error("%s failed: result = %d\n", __func__, result); return; } + char dirname[PATH_MAX] = {0}; + FILE_ABSOLUTE_DIR(dirname); DIR *dir = opendir(dirname); if (dir == NULL) { t_error("%s failed: dirname = %s\n", __func__, dirname); @@ -113,6 +118,8 @@ void readlinkat_0200(void) t_error("%s failed: fd = %d\n", __func__, fd); } + char linkpath[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_LINK_TXT, linkpath); remove(linkpath); result = symlinkat(filename, fd, linkfilename); diff --git a/libc-test/src/functionalext/supplement/unistd/readv.c b/libc-test/src/functionalext/supplement/unistd/readv.c index 5d761554f5f9d33415fd3e1355eefa3e9829e7c1..d2ae41689e5909dd59edb8fa4fff9486a3920cee 100644 --- a/libc-test/src/functionalext/supplement/unistd/readv.c +++ b/libc-test/src/functionalext/supplement/unistd/readv.c @@ -19,9 +19,7 @@ #include #include -#include "test.h" - -const char *path = "/data/tests/libc-test/src/file.txt"; +#include "filepath_util.h" /** * @tc.name : readv_0100 @@ -30,6 +28,8 @@ const char *path = "/data/tests/libc-test/src/file.txt"; */ void readv_0100(void) { + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); int fd = open(path, O_RDWR | O_CREAT); char buf1[] = "hello"; diff --git a/libc-test/src/functionalext/supplement/unistd/truncate.c b/libc-test/src/functionalext/supplement/unistd/truncate.c index fada943a11710c86f126120a61f8fdcd4af1ef01..2486a7f10498402c254b5a89fd0226dc623347ca 100644 --- a/libc-test/src/functionalext/supplement/unistd/truncate.c +++ b/libc-test/src/functionalext/supplement/unistd/truncate.c @@ -18,12 +18,10 @@ #include #include -#include "test.h" +#include "filepath_util.h" const int nlen = -1; const int vlen = 5; -const char *path = "/data/tests/libc-test/src/file.txt"; -const char *path_n = "/data/tests/libc-test/src/files.txt"; const char *content = "Hello world!"; #define CONTENT_LENGTH (13) @@ -35,6 +33,8 @@ const char *content = "Hello world!"; */ void truncate_0100(void) { + char path_n[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("files.txt", path_n); FILE *f = fopen(path_n, "a"); if (f == NULL) { t_error("%s failed: fopen\n", __func__); @@ -57,6 +57,8 @@ void truncate_0100(void) */ void truncate_0200(void) { + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); FILE *f = fopen(path, "a"); if (f == NULL) { t_error("%s failed: fopen\n", __func__); @@ -99,6 +101,8 @@ void truncate_0200(void) */ void truncate_0300(void) { + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); int result = truncate(path, nlen); if (result == 0) { t_error("%s failed: result = %d\n", __func__, result); diff --git a/libc-test/src/functionalext/supplement/unistd/unlink.c b/libc-test/src/functionalext/supplement/unistd/unlink.c index c1256c4fdb50d681cfff989e49b530de969df609..2149e60226a5d8f42c5d1c54a5511b2eceef6f3b 100644 --- a/libc-test/src/functionalext/supplement/unistd/unlink.c +++ b/libc-test/src/functionalext/supplement/unistd/unlink.c @@ -17,7 +17,7 @@ #include #include #include -#include "test.h" +#include "filepath_util.h" /** * @tc.name : unlink_0100 @@ -26,14 +26,16 @@ */ void unlink_0100(void) { - int fd = open("/data/tests/libc-test/src/test_unlink.txt", O_CREAT); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("test_unlink.txt", path); + int fd = open(path, O_CREAT); int error_code = -1; if (fd == error_code) { t_error("%s unlink create file error", __func__); return; } close(fd); - int result = unlink("/data/tests/libc-test/src/test_unlink.txt"); + int result = unlink(path); if (result != 0) { t_error("%s unlink get result is %d not want 0", __func__, result); } @@ -46,7 +48,9 @@ void unlink_0100(void) */ void unlink_0200(void) { - int result = unlink("/data/tests/libc-test/src/unexist_test_unlink.txt"); + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH("unexist_test_unlink.txt", path); + int result = unlink(path); int error_code = -1; if (result != error_code) { t_error("%s unlink get result is %d not want -1", __func__, result); diff --git a/libc-test/src/functionalext/supplement/unistd/unlinkat.c b/libc-test/src/functionalext/supplement/unistd/unlinkat.c index 89ec83a3aff3b27302edd0054a14588029ee05a0..ad9bfff2b1b3ba31ca2e1506f9474850dc285ab6 100644 --- a/libc-test/src/functionalext/supplement/unistd/unlinkat.c +++ b/libc-test/src/functionalext/supplement/unistd/unlinkat.c @@ -16,9 +16,7 @@ #include #include -#include "test.h" - -const char *path = "/data/tests/libc-test/src/file.txt"; +#include "filepath_util.h" /** * @tc.name : unlinkat_0100 @@ -27,6 +25,8 @@ const char *path = "/data/tests/libc-test/src/file.txt"; */ void unlinkat_0100(void) { + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); int fd = open(path, O_CREAT, 0664); int result = unlinkat(fd, path, 0); @@ -45,6 +45,8 @@ void unlinkat_0100(void) void unlinkat_0200(void) { errno = 0; + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_FILE_TXT, path); int result = unlinkat(AT_FDCWD, path, AT_REMOVEDIR); if (result == 0) { t_error("%s failed: result = %d\n", __func__, result); diff --git a/libc-test/src/functionalext/supplement/unistd/write.c b/libc-test/src/functionalext/supplement/unistd/write.c index 315b7e8868680b9b5d5134238c1ea59b5ed402d8..aa665ac0b9b3bcfeac81425c2c1427cbe943d6c5 100644 --- a/libc-test/src/functionalext/supplement/unistd/write.c +++ b/libc-test/src/functionalext/supplement/unistd/write.c @@ -17,7 +17,7 @@ #include #include #include -#include "test.h" +#include "filepath_util.h" /** * @tc.name : write_0100 @@ -27,7 +27,8 @@ void write_0100(void) { const char *msg = "This is a c test code for write function"; - const char *path = "/data/tests/libc-test/src/test_write.txt"; + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_WRITE_TEST_TXT, path); int len = strlen(msg); char buf[1024] = {0}; int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664); @@ -61,7 +62,8 @@ void write_0100(void) void write_0200(void) { const char *msg = "This is a c test code for write function"; - const char *path = "/data/tests/libc-test/src/test_write.txt"; + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_WRITE_TEST_TXT, path); int len = 0; int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664); if (fd == -1) { @@ -84,7 +86,8 @@ void write_0200(void) void write_0300(void) { const char *msg = "This is a c test code for write function"; - const char *path = "/data/tests/libc-test/src/test_write.txt"; + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_WRITE_TEST_TXT, path); int len = strlen(msg) + 1; int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664); if (fd == -1) { @@ -107,7 +110,8 @@ void write_0300(void) void write_0400(void) { const char *msg = "This is a c test code for write function"; - const char *path = "/data/tests/libc-test/src/test_write.txt"; + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_WRITE_TEST_TXT, path); int len = strlen(msg); int fd = open(path, O_RDWR); int result = write(fd, msg, len); @@ -126,7 +130,8 @@ void write_0400(void) void write_0500(void) { const char *msg = NULL; - const char *path = "/data/tests/libc-test/src/test_write.txt"; + char path[PATH_MAX] = {0}; + FILE_ABSOLUTE_PATH(STR_WRITE_TEST_TXT, path); int len = 1; int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664); if (fd == -1) {