提交 97e158a5 编写于 作者: D dhy308

Add filepath_util.h and replace the code with macro

Issue: I63QQ9
Test: libc-test pass
Signed-off-by: Ndhy308 <tony.gan@huawei.com>
上级 e9e4016d
/**
* 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 <stdlib.h>
#include <limits.h>
#include <string.h>
#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
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include <signal.h> #include <signal.h>
#include <stdlib.h> #include <stdlib.h>
#include "test.h" #include "filepath_util.h"
void handler(int sig) void handler(int sig)
{ {
...@@ -31,12 +31,8 @@ void handler(int sig) ...@@ -31,12 +31,8 @@ void handler(int sig)
*/ */
void readdir_r_0100(void) void readdir_r_0100(void)
{ {
char name[128] = {0}; char name[PATH_MAX] = {0};
char *cwd = getcwd(name, sizeof(name)); FILE_ABSOLUTE_DIR(name);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
DIR *dir = opendir(name); DIR *dir = opendir(name);
if (dir == NULL) { if (dir == NULL) {
t_error("%s failed: opendir. name = %s\n", __func__, name); t_error("%s failed: opendir. name = %s\n", __func__, name);
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "test.h" #include "filepath_util.h"
void handler(int sig) void handler(int sig)
{ {
...@@ -32,13 +32,8 @@ void handler(int sig) ...@@ -32,13 +32,8 @@ void handler(int sig)
*/ */
void rewinddir_0100(void) void rewinddir_0100(void)
{ {
char name[128] = {0}; char name[PATH_MAX] = {0};
char *cwd = getcwd(name, sizeof(name)); FILE_ABSOLUTE_DIR(name);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
DIR *dir = opendir(name); DIR *dir = opendir(name);
if (dir == NULL) { if (dir == NULL) {
t_error("%s failed: opendir. name = %s\n", __func__, name); t_error("%s failed: opendir. name = %s\n", __func__, name);
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include <dirent.h> #include <dirent.h>
#include <stdlib.h> #include <stdlib.h>
#include "test.h" #include "filepath_util.h"
int filter(const struct dirent *entry) int filter(const struct dirent *entry)
{ {
...@@ -31,12 +31,8 @@ int filter(const struct dirent *entry) ...@@ -31,12 +31,8 @@ int filter(const struct dirent *entry)
void scandir_0100(void) void scandir_0100(void)
{ {
struct dirent **namelist; struct dirent **namelist;
char name[128] = {0}; char name[PATH_MAX] = {0};
char *cwd = getcwd(name, sizeof(name)); FILE_ABSOLUTE_DIR(name);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
int n = scandir(name, &namelist, NULL, alphasort); int n = scandir(name, &namelist, NULL, alphasort);
if (n < 0) { if (n < 0) {
...@@ -58,12 +54,8 @@ void scandir_0100(void) ...@@ -58,12 +54,8 @@ void scandir_0100(void)
void scandir_0200(void) void scandir_0200(void)
{ {
struct dirent **namelist; struct dirent **namelist;
char name[128] = {0}; char name[PATH_MAX] = {0};
char *cwd = getcwd(name, sizeof(name)); FILE_ABSOLUTE_DIR(name);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
int n = scandir(name, &namelist, NULL, versionsort); int n = scandir(name, &namelist, NULL, versionsort);
if (n < 0) { if (n < 0) {
...@@ -85,13 +77,8 @@ void scandir_0200(void) ...@@ -85,13 +77,8 @@ void scandir_0200(void)
void scandir_0300(void) void scandir_0300(void)
{ {
struct dirent **namelist; struct dirent **namelist;
char name[128] = {0}; char name[PATH_MAX] = {0};
char *cwd = getcwd(name, sizeof(name)); FILE_ABSOLUTE_DIR(name);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
int n = scandir(name, &namelist, filter, versionsort); int n = scandir(name, &namelist, filter, versionsort);
if (n < 0) { if (n < 0) {
t_error("%s failed: scandir. n = %d\n", __func__, n); t_error("%s failed: scandir. n = %d\n", __func__, n);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <sys/ipc.h> #include <sys/ipc.h>
#include "functionalext.h" #include "functionalext.h"
#include "filepath_util.h"
/* /*
* @tc.name : ftok_0100 * @tc.name : ftok_0100
...@@ -23,14 +24,9 @@ ...@@ -23,14 +24,9 @@
*/ */
void ftok_0100(void) void ftok_0100(void)
{ {
char dir_path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(dir_path, sizeof(dir_path)); FILE_ABSOLUTE_PATH("ftok", path);
if (!cwd) { key_t result = ftok(path, 1);
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(dir_path, "/ftok");
key_t result = ftok(dir_path, 1);
EXPECT_NE("ftok_0100", result, -1); EXPECT_NE("ftok_0100", result, -1);
} }
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include <string.h> #include <string.h>
#include <sys/sem.h> #include <sys/sem.h>
#include "test.h" #include "filepath_util.h"
extern int __semtimedop_time64(int, struct sembuf *, size_t, const struct timespec *); extern int __semtimedop_time64(int, struct sembuf *, size_t, const struct timespec *);
...@@ -29,14 +29,8 @@ extern int __semtimedop_time64(int, struct sembuf *, size_t, const struct timesp ...@@ -29,14 +29,8 @@ extern int __semtimedop_time64(int, struct sembuf *, size_t, const struct timesp
*/ */
void semtimedop_0100(void) void semtimedop_0100(void)
{ {
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT);
if (fd < 0) { if (fd < 0) {
t_error("%s failed: fd = %d\n", __func__, fd); t_error("%s failed: fd = %d\n", __func__, fd);
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "test.h" #include "filepath_util.h"
const char *str = "Hello"; const char *str = "Hello";
...@@ -31,20 +31,10 @@ void copy_file_range_0100(void) ...@@ -31,20 +31,10 @@ void copy_file_range_0100(void)
int fd_in, fd_out, wlen, result; int fd_in, fd_out, wlen, result;
char buffer[BUFSIZ]; char buffer[BUFSIZ];
char path_in[128] = {0}; char path_in[PATH_MAX] = {0};
char path_out[128] = {0}; char path_out[PATH_MAX] = {0};
char *cwd = getcwd(path_in, sizeof(path_in)); FILE_ABSOLUTE_PATH(STR_FILE_IN_TXT, path_in);
if (!cwd) { FILE_ABSOLUTE_PATH(STR_FILE_OUT_TXT, path_out);
t_error("%s getcwd path_in failed\n", __func__);
return;
}
cwd = getcwd(path_out, sizeof(path_out));
if (!cwd) {
t_error("%s getcwd path_out failed\n", __func__);
return;
}
strcat(path_in, "/file_in.txt");
strcat(path_out, "/file_out.txt");
fd_in = open(path_in, O_RDWR | O_CREAT); fd_in = open(path_in, O_RDWR | O_CREAT);
if (fd_in == -1) { if (fd_in == -1) {
...@@ -120,21 +110,11 @@ void copy_file_range_0300(void) ...@@ -120,21 +110,11 @@ void copy_file_range_0300(void)
int fd_in, fd_out, wlen, result; int fd_in, fd_out, wlen, result;
char buffer[BUFSIZ]; char buffer[BUFSIZ];
char path_in[128] = {0}; char path_in[PATH_MAX] = {0};
char path_out[128] = {0}; char path_out[PATH_MAX] = {0};
char *cwd = getcwd(path_in, sizeof(path_in)); FILE_ABSOLUTE_PATH(STR_FILE_IN_TXT, path_in);
if (!cwd) { FILE_ABSOLUTE_PATH(STR_FILE_OUT_TXT, path_out);
t_error("%s getcwd path_in failed\n", __func__);
return;
}
cwd = getcwd(path_out, sizeof(path_out));
if (!cwd) {
t_error("%s getcwd path_out failed\n", __func__);
return;
}
strcat(path_in, "/file_in.txt");
strcat(path_out, "/file_out.txt");
fd_in = open(path_in, O_WRONLY | O_CREAT); fd_in = open(path_in, O_WRONLY | O_CREAT);
if (fd_in == -1) { if (fd_in == -1) {
t_error("%s open path_in failed\n", __func__); t_error("%s open path_in failed\n", __func__);
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include <string.h> #include <string.h>
#include <sys/xattr.h> #include <sys/xattr.h>
#include "test.h" #include "filepath_util.h"
const char *name = "user.foo"; const char *name = "user.foo";
const char *value = "bar"; const char *value = "bar";
...@@ -31,14 +31,8 @@ const char *value = "bar"; ...@@ -31,14 +31,8 @@ const char *value = "bar";
*/ */
void removexattr_0100(void) void removexattr_0100(void)
{ {
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT);
if (fd < 0) { if (fd < 0) {
t_error("%s failed: fd = %d\n", __func__, fd); t_error("%s failed: fd = %d\n", __func__, fd);
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include <string.h> #include <string.h>
#include <sys/sendfile.h> #include <sys/sendfile.h>
#include "test.h" #include "filepath_util.h"
/** /**
* @tc.name : sendfile_0100 * @tc.name : sendfile_0100
...@@ -28,20 +28,10 @@ ...@@ -28,20 +28,10 @@
*/ */
void sendfile_0100(void) void sendfile_0100(void)
{ {
char fromfile[128] = {0}; char fromfile[PATH_MAX] = {0};
char tofile[128] = {0}; char tofile[PATH_MAX] = {0};
char *cwd = getcwd(fromfile, sizeof(fromfile)); FILE_ABSOLUTE_PATH(STR_FILE_FROM_TXT, fromfile);
if (!cwd) { FILE_ABSOLUTE_PATH(STR_FILE_TO_TXT, tofile);
t_error("%s getcwd fromfile failed\n", __func__);
return;
}
cwd = getcwd(tofile, sizeof(tofile));
if (!cwd) {
t_error("%s getcwd tofile failed\n", __func__);
return;
}
strcat(fromfile, "/fromfile.txt");
strcat(tofile, "/tofile.txt");
FILE *f = fopen(fromfile, "w+"); FILE *f = fopen(fromfile, "w+");
const char src[] = "A"; const char src[] = "A";
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include <string.h> #include <string.h>
#include <sys/xattr.h> #include <sys/xattr.h>
#include "test.h" #include "filepath_util.h"
const char *name = "user.foo"; const char *name = "user.foo";
const char *value = "bar"; const char *value = "bar";
...@@ -31,14 +31,8 @@ const char *value = "bar"; ...@@ -31,14 +31,8 @@ const char *value = "bar";
*/ */
void setxattr_0100(void) void setxattr_0100(void)
{ {
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT);
if (fd < 0) { if (fd < 0) {
t_error("%s failed: fd = %d\n", __func__, fd); t_error("%s failed: fd = %d\n", __func__, fd);
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "test.h" #include "filepath_util.h"
const char *path = "/proc/version"; const char *path = "/proc/version";
...@@ -30,20 +30,10 @@ const char *path = "/proc/version"; ...@@ -30,20 +30,10 @@ const char *path = "/proc/version";
*/ */
void splice_0100(void) void splice_0100(void)
{ {
char fromfile[128] = {0}; char fromfile[PATH_MAX] = {0};
char tofile[128] = {0}; char tofile[PATH_MAX] = {0};
char *cwd = getcwd(fromfile, sizeof(fromfile)); FILE_ABSOLUTE_PATH(STR_FILE_FROM_TXT, fromfile);
if (!cwd) { FILE_ABSOLUTE_PATH(STR_FILE_TO_TXT, tofile);
t_error("%s getcwd fromfile failed\n", __func__);
return;
}
cwd = getcwd(tofile, sizeof(tofile));
if (!cwd) {
t_error("%s getcwd tofile failed\n", __func__);
return;
}
strcat(fromfile, "/fromfile.txt");
strcat(tofile, "/tofile.txt");
int fromfd = open(fromfile, O_RDWR | O_CREAT); int fromfd = open(fromfile, O_RDWR | O_CREAT);
if (fromfd < 0) { if (fromfd < 0) {
......
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/swap.h> #include <sys/swap.h>
#include <string.h>
#include "test.h" #include "filepath_util.h"
/** /**
* @tc.name : swapoff_0100 * @tc.name : swapoff_0100
...@@ -27,22 +27,19 @@ ...@@ -27,22 +27,19 @@
*/ */
void swapoff_0100(void) void swapoff_0100(void)
{ {
char dir_path[128] = {0}; char dir_path[PATH_MAX] = {0};
char *cwd = getcwd(dir_path, sizeof(dir_path)); FILE_ABSOLUTE_DIR(dir_path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
errno = 0; errno = 0;
char cmd[256] = {0}; 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); snprintf(cmd, sizeof(cmd), "cd %s; dd if=/dev/zero of=swapfile count=1 bs=1k; mkswap swapfile", dir_path);
system(cmd); system(cmd);
strcat(dir_path, "/swapfile");
int result = swapon(dir_path, SWAP_FLAG_PREFER); char path[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_FILE_SWAP, path);
int result = swapon(path, SWAP_FLAG_PREFER);
if (result == -1) { if (result == -1) {
t_error("%s swapon failed\n", __func__); t_error("%s swapon failed\n", __func__);
remove(dir_path); remove(path);
return; return;
} }
if (errno == ENOSYS) { if (errno == ENOSYS) {
...@@ -50,7 +47,7 @@ void swapoff_0100(void) ...@@ -50,7 +47,7 @@ void swapoff_0100(void)
return; return;
} }
result = swapoff(dir_path); result = swapoff(path);
if (result == -1) { if (result == -1) {
t_error("%s swapoff failed", __func__); t_error("%s swapoff failed", __func__);
} }
......
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/swap.h> #include <sys/swap.h>
#include <string.h>
#include "test.h" #include "filepath_util.h"
/** /**
* @tc.name : swapon_0100 * @tc.name : swapon_0100
...@@ -27,22 +27,19 @@ ...@@ -27,22 +27,19 @@
*/ */
void swapon_0100(void) void swapon_0100(void)
{ {
char dir_path[128] = {0}; char dir_path[PATH_MAX] = {0};
char *cwd = getcwd(dir_path, sizeof(dir_path)); FILE_ABSOLUTE_DIR(dir_path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
errno = 0; errno = 0;
char cmd[256] = {0}; 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); snprintf(cmd, sizeof(cmd), "cd %s; dd if=/dev/zero of=swapfile count=1 bs=1k; mkswap swapfile", dir_path);
system(cmd); system(cmd);
strcat(dir_path, "/swapfile");
int result = swapon(dir_path, SWAP_FLAG_PREFER); char path[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_FILE_SWAP, path);
int result = swapon(path, SWAP_FLAG_PREFER);
if (result == -1) { if (result == -1) {
t_error("%s swapon failed\n", __func__); t_error("%s swapon failed\n", __func__);
remove(dir_path); remove(path);
} }
if (errno == ENOSYS) { if (errno == ENOSYS) {
......
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <string.h>
#include "test.h" #include "filepath_util.h"
/** /**
* @tc.name : sync_file_range_0100 * @tc.name : sync_file_range_0100
...@@ -27,16 +27,10 @@ ...@@ -27,16 +27,10 @@
*/ */
void sync_file_range_0100(void) void sync_file_range_0100(void)
{ {
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/sync_file_range.txt");
errno = 0; errno = 0;
int result, fd; int result, fd;
char path[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_FILE_SYNC_TXT, path);
fd = open(path, O_RDWR | O_CREAT); fd = open(path, O_RDWR | O_CREAT);
if (fd == -1) { if (fd == -1) {
...@@ -78,17 +72,11 @@ void sync_file_range_0200(void) ...@@ -78,17 +72,11 @@ void sync_file_range_0200(void)
*/ */
void sync_file_range_0300(void) void sync_file_range_0300(void)
{ {
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/sync_file_range.txt");
errno = 0; errno = 0;
int result, fd; int result, fd;
char path[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_FILE_SYNC_TXT, path);
fd = open(path, O_RDWR | O_CREAT); fd = open(path, O_RDWR | O_CREAT);
if (fd == -1) { if (fd == -1) {
t_error("%s open failed\n", __func__); t_error("%s open failed\n", __func__);
...@@ -113,17 +101,11 @@ void sync_file_range_0300(void) ...@@ -113,17 +101,11 @@ void sync_file_range_0300(void)
*/ */
void sync_file_range_0400(void) void sync_file_range_0400(void)
{ {
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/sync_file_range.txt");
errno = 0; errno = 0;
int result, fd; int result, fd;
char path[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_FILE_SYNC_TXT, path);
fd = open(path, O_RDWR | O_CREAT); fd = open(path, O_RDWR | O_CREAT);
if (fd == -1) { if (fd == -1) {
t_error("%s open failed\n", __func__); t_error("%s open failed\n", __func__);
......
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <string.h>
#include "test.h" #include "filepath_util.h"
/** /**
* @tc.name : syncfs_0100 * @tc.name : syncfs_0100
...@@ -27,15 +27,9 @@ ...@@ -27,15 +27,9 @@
*/ */
void syncfs_0100(void) void syncfs_0100(void)
{ {
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/syncfs.txt");
errno = 0; errno = 0;
char path[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH("syncfs.txt", path);
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT);
if (fd == -1) { if (fd == -1) {
t_error("%s open failed\n", __func__); t_error("%s open failed\n", __func__);
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "test.h" #include "filepath_util.h"
#define BUFF_SIZE (20) #define BUFF_SIZE (20)
...@@ -74,14 +74,9 @@ void tee_0200(void) ...@@ -74,14 +74,9 @@ void tee_0200(void)
{ {
char buf[BUFF_SIZE]; char buf[BUFF_SIZE];
char *text = "Hello"; char *text = "Hello";
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int result; 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); int fd = open(path, O_CREAT | O_WRONLY | O_TRUNC, 0666);
if (fd < 0) { if (fd < 0) {
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include "functionalext.h" #include "functionalext.h"
#include "filepath_util.h"
#define TEST_SIZE 4096 #define TEST_SIZE 4096
...@@ -30,14 +31,9 @@ ...@@ -30,14 +31,9 @@
void mincore_0100(void) void mincore_0100(void)
{ {
struct stat st; struct stat st;
char pathname[128] = {0}; char pathname[PATH_MAX] = {0};
char *cwd = getcwd(pathname, sizeof(pathname)); FILE_ABSOLUTE_PATH("mincore", pathname);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(pathname, "/mincore");
int ret = stat(pathname, &st); int ret = stat(pathname, &st);
EXPECT_EQ("mincore_0100", ret, CMPFLAG); EXPECT_EQ("mincore_0100", ret, CMPFLAG);
if (ret != 0) { if (ret != 0) {
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "functionalext.h" #include "functionalext.h"
#include "filepath_util.h"
int success = 36863; int success = 36863;
int SUCCESS = 33279; int SUCCESS = 33279;
...@@ -28,16 +29,10 @@ int failed = -1; ...@@ -28,16 +29,10 @@ int failed = -1;
*/ */
void fchmodat_0100(void) void fchmodat_0100(void)
{ {
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/test.txt");
int fd; int fd;
struct stat buf; struct stat buf;
char path[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_TEST_TXT, path);
fd = open(path, O_RDWR | O_CREAT); fd = open(path, O_RDWR | O_CREAT);
int result = fchmodat(fd, int result = fchmodat(fd,
path, path,
...@@ -58,16 +53,10 @@ void fchmodat_0100(void) ...@@ -58,16 +53,10 @@ void fchmodat_0100(void)
*/ */
void fchmodat_0200(void) void fchmodat_0200(void)
{ {
char path[128] = {0};
char *cwd = getcwd(path, sizeof(path));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/test.txt");
int fd; int fd;
struct stat buf; struct stat buf;
char path[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_TEST_TXT, path);
fd = open(path, O_RDWR | O_CREAT); fd = open(path, O_RDWR | O_CREAT);
int result = fchmodat(fd, int result = fchmodat(fd,
path, path,
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include "functionalext.h" #include "functionalext.h"
#include "filepath_util.h"
const int SUCCESS = 0; const int SUCCESS = 0;
...@@ -84,13 +85,8 @@ void fstatat_0200(void) ...@@ -84,13 +85,8 @@ void fstatat_0200(void)
*/ */
void fstatat_0300(void) void fstatat_0300(void)
{ {
char ptr[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(ptr, sizeof(ptr)); FILE_ABSOLUTE_PATH("fstatattest.txt", ptr);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/fstatattest.txt");
struct stat st; struct stat st;
int fd = open(ptr, O_RDWR | O_CREAT); int fd = open(ptr, O_RDWR | O_CREAT);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include "functionalext.h" #include "functionalext.h"
#include "filepath_util.h"
extern int __lstat_time64(const char *__restrict, struct stat *__restrict); extern int __lstat_time64(const char *__restrict, struct stat *__restrict);
...@@ -30,13 +31,8 @@ typedef void (*TEST_FUN)(); ...@@ -30,13 +31,8 @@ typedef void (*TEST_FUN)();
*/ */
void lstat_0100(void) void lstat_0100(void)
{ {
char ptr[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(ptr, sizeof(ptr)); FILE_ABSOLUTE_PATH(STR_STAT_TEST_TXT, ptr);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/stattest.txt");
const char str[] = "this is a sample!"; const char str[] = "this is a sample!";
FILE *fptr = fopen(ptr, "w+"); FILE *fptr = fopen(ptr, "w+");
...@@ -57,13 +53,8 @@ void lstat_0100(void) ...@@ -57,13 +53,8 @@ void lstat_0100(void)
*/ */
void lstat_time64_0100(void) void lstat_time64_0100(void)
{ {
char ptr[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(ptr, sizeof(ptr)); FILE_ABSOLUTE_PATH(STR_STAT_TEST_TXT, ptr);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/stattest.txt");
const char str[] = "this is a sample!"; const char str[] = "this is a sample!";
FILE *fptr = fopen(ptr, "w+"); FILE *fptr = fopen(ptr, "w+");
...@@ -85,7 +76,7 @@ void lstat_time64_0100(void) ...@@ -85,7 +76,7 @@ void lstat_time64_0100(void)
void lstat_0200(void) void lstat_0200(void)
{ {
struct stat statbuff; struct stat statbuff;
int32_t back = lstat("test.txt", &statbuff); int32_t back = lstat(STR_TEST_TXT, &statbuff);
EXPECT_EQ("lstat_0200", back, -1); EXPECT_EQ("lstat_0200", back, -1);
} }
...@@ -96,24 +87,14 @@ void lstat_0200(void) ...@@ -96,24 +87,14 @@ void lstat_0200(void)
*/ */
void lstat_0300(void) void lstat_0300(void)
{ {
char ptr[128] = {0};
char ptrlink[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd file failed\n", __func__);
return;
}
cwd = getcwd(ptrlink, sizeof(ptrlink));
if (!cwd) {
t_error("%s getcwd link failed\n", __func__);
return;
}
strcat(ptr, "/tests.txt");
strcat(ptrlink, "/tests.txt.soft");
struct stat buf[3]; struct stat buf[3];
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+"); FILE *fptr = fopen(ptr, "w+");
char cmd[256] = {0}; char cmd[PATH_MAX] = {0};
snprintf(cmd, sizeof(cmd), "ln -s %s %s", ptr, ptrlink); snprintf(cmd, sizeof(cmd), "ln -s %s %s", ptr, ptrlink);
system(cmd); system(cmd);
struct stat statbuff; struct stat statbuff;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include "functionalext.h" #include "functionalext.h"
#include "filepath_util.h"
#define TEST_MODE 0666 #define TEST_MODE 0666
...@@ -25,14 +26,8 @@ ...@@ -25,14 +26,8 @@
*/ */
void mknod_0100(void) void mknod_0100(void)
{ {
char pathname[128] = {0}; char pathname[PATH_MAX] = {0};
char *cwd = getcwd(pathname, sizeof(pathname)); FILE_ABSOLUTE_PATH("mknod", pathname);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(pathname, "/mknod");
int ret = mknod(pathname, TEST_MODE, 0); int ret = mknod(pathname, TEST_MODE, 0);
EXPECT_EQ("mknod_0100", ret, ERREXPECT); EXPECT_EQ("mknod_0100", ret, ERREXPECT);
} }
......
...@@ -17,8 +17,7 @@ ...@@ -17,8 +17,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <string.h> #include "filepath_util.h"
#include "test.h"
const long sec = 123840; const long sec = 123840;
...@@ -31,14 +30,8 @@ extern int __utimensat_time64(int, const char *, const struct timespec [2], int) ...@@ -31,14 +30,8 @@ extern int __utimensat_time64(int, const char *, const struct timespec [2], int)
*/ */
void utimensat_0100(void) void utimensat_0100(void)
{ {
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT);
struct timespec times[] = {{.tv_sec = 0}, {.tv_sec = sec}}; struct timespec times[] = {{.tv_sec = 0}, {.tv_sec = sec}};
...@@ -87,14 +80,8 @@ void utimensat_0200(void) ...@@ -87,14 +80,8 @@ void utimensat_0200(void)
*/ */
void utimensat_time64_0100(void) void utimensat_time64_0100(void)
{ {
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT);
struct timespec times[] = {{.tv_sec = 0}, {.tv_sec = sec}}; struct timespec times[] = {{.tv_sec = 0}, {.tv_sec = sec}};
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <stdio_ext.h> #include <stdio_ext.h>
#include "functionalext.h" #include "functionalext.h"
#include "filepath_util.h"
const int32_t NUM_ZERO = 0; const int32_t NUM_ZERO = 0;
...@@ -25,14 +26,8 @@ const int32_t NUM_ZERO = 0; ...@@ -25,14 +26,8 @@ const int32_t NUM_ZERO = 0;
*/ */
void __fwritable_0100(void) void __fwritable_0100(void)
{ {
char ptr[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(ptr, sizeof(ptr)); FILE_ABSOLUTE_PATH(STR_FREAD_TEST_TXT, ptr);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/Freadtest.txt");
FILE *fptr = fopen(ptr, "w+"); FILE *fptr = fopen(ptr, "w+");
if (!fptr) { if (!fptr) {
t_error("%s fopen failed\n", __func__); t_error("%s fopen failed\n", __func__);
...@@ -49,14 +44,8 @@ void __fwritable_0100(void) ...@@ -49,14 +44,8 @@ void __fwritable_0100(void)
*/ */
void __fwritable_0200(void) void __fwritable_0200(void)
{ {
char ptr[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(ptr, sizeof(ptr)); FILE_ABSOLUTE_PATH(STR_FREAD_TEST_TXT, ptr);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/Freadtest.txt");
FILE *fptr = fopen(ptr, "r"); FILE *fptr = fopen(ptr, "r");
if (!fptr) { if (!fptr) {
t_error("%s fopen failed\n", __func__); t_error("%s fopen failed\n", __func__);
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include "functionalext.h" #include "functionalext.h"
#include "filepath_util.h"
const int32_t NUM_ZERO = 0; const int32_t NUM_ZERO = 0;
...@@ -29,14 +30,8 @@ const int32_t NUM_ZERO = 0; ...@@ -29,14 +30,8 @@ const int32_t NUM_ZERO = 0;
*/ */
void __fwriting_0100(void) void __fwriting_0100(void)
{ {
char ptr[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(ptr, sizeof(ptr)); FILE_ABSOLUTE_PATH(STR_FREAD_TEST_TXT, ptr);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/Freadtest.txt");
FILE *fptr = fopen(ptr, "w"); FILE *fptr = fopen(ptr, "w");
int result = __fwriting(fptr); int result = __fwriting(fptr);
EXPECT_NE("__fwriting_0100", result, NUM_ZERO); EXPECT_NE("__fwriting_0100", result, NUM_ZERO);
...@@ -51,15 +46,9 @@ void __fwriting_0100(void) ...@@ -51,15 +46,9 @@ void __fwriting_0100(void)
*/ */
void __fwriting_0200(void) void __fwriting_0200(void)
{ {
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/Freadtest.txt");
const char *wrstring = "helloworld"; const char *wrstring = "helloworld";
char ptr[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_FREAD_TEST_TXT, ptr);
FILE *fptr = fopen(ptr, "w+"); FILE *fptr = fopen(ptr, "w+");
fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); fwrite(wrstring, sizeof(char), strlen(wrstring), fptr);
int result = __fwriting(fptr); int result = __fwriting(fptr);
...@@ -75,16 +64,10 @@ void __fwriting_0200(void) ...@@ -75,16 +64,10 @@ void __fwriting_0200(void)
*/ */
void __fwriting_0300(void) void __fwriting_0300(void)
{ {
char ptr[128] = {0};
char *cwd = getcwd(ptr, sizeof(ptr));
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/Freadtest.txt");
char abc[100] = {0}; char abc[100] = {0};
const char *wrstring = "helloworld"; const char *wrstring = "helloworld";
char ptr[PATH_MAX] = {0};
FILE_ABSOLUTE_PATH(STR_FREAD_TEST_TXT, ptr);
FILE *fptr = fopen(ptr, "w+"); FILE *fptr = fopen(ptr, "w+");
fwrite(wrstring, sizeof(char), strlen(wrstring), fptr); fwrite(wrstring, sizeof(char), strlen(wrstring), fptr);
fseek(fptr, 0, SEEK_SET); fseek(fptr, 0, SEEK_SET);
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
#include "functionalext.h" #include "functionalext.h"
#include "filepath_util.h"
/** /**
* @tc.name : fputc_0100 * @tc.name : fputc_0100
...@@ -22,14 +23,8 @@ ...@@ -22,14 +23,8 @@
*/ */
void fputc_0100(void) void fputc_0100(void)
{ {
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FPUTC_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/fputc.txt");
FILE *fptr = fopen(path, "w"); FILE *fptr = fopen(path, "w");
int Exit = fputc('a', fptr); int Exit = fputc('a', fptr);
EXPECT_EQ("fputc_0100", Exit, 97); EXPECT_EQ("fputc_0100", Exit, 97);
...@@ -43,14 +38,8 @@ void fputc_0100(void) ...@@ -43,14 +38,8 @@ void fputc_0100(void)
*/ */
void fputc_0200(void) void fputc_0200(void)
{ {
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FPUTC_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/fputc.txt");
FILE *fptr = fopen(path, "r"); FILE *fptr = fopen(path, "r");
int Exit = fputc('a', fptr); int Exit = fputc('a', fptr);
EXPECT_EQ("fputc_0200", Exit, EOF); EXPECT_EQ("fputc_0200", Exit, EOF);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <fcntl.h> #include <fcntl.h>
#include "functionalext.h" #include "functionalext.h"
#include "filepath_util.h"
/** /**
* @tc.name : freopen_0100 * @tc.name : freopen_0100
...@@ -23,13 +24,8 @@ ...@@ -23,13 +24,8 @@
*/ */
void freopen_0100(void) void freopen_0100(void)
{ {
char ptr[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(ptr, sizeof(ptr)); FILE_ABSOLUTE_PATH("freopen.txt", ptr);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/freopen.txt");
FILE *fp; FILE *fp;
fp = freopen(ptr, "w+", stdin); fp = freopen(ptr, "w+", stdin);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <fcntl.h> #include <fcntl.h>
#include "functionalext.h" #include "functionalext.h"
#include "filepath_util.h"
/** /**
* @tc.name : getline_0100 * @tc.name : getline_0100
...@@ -26,15 +27,9 @@ void getline_0100(void) ...@@ -26,15 +27,9 @@ void getline_0100(void)
char *wrstring = "helloworld"; char *wrstring = "helloworld";
char *line = NULL; char *line = NULL;
size_t len = 0; size_t len = 0;
char path[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_TEST_TXT, ptr);
if (!cwd) { FILE *fp = fopen(ptr, "w+");
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/test.txt");
FILE *fp = fopen(path, "w+");
EXPECT_PTRNE("getline_0100", fp, NULL); EXPECT_PTRNE("getline_0100", fp, NULL);
fwrite(wrstring, sizeof(char), strlen(wrstring), fp); fwrite(wrstring, sizeof(char), strlen(wrstring), fp);
fseek(fp, 0, SEEK_SET); fseek(fp, 0, SEEK_SET);
...@@ -44,7 +39,7 @@ void getline_0100(void) ...@@ -44,7 +39,7 @@ void getline_0100(void)
EXPECT_STREQ("getline_0100", line, "helloworld"); EXPECT_STREQ("getline_0100", line, "helloworld");
fclose(fp); fclose(fp);
remove(path); remove(ptr);
} }
/** /**
...@@ -55,21 +50,16 @@ void getline_0100(void) ...@@ -55,21 +50,16 @@ void getline_0100(void)
void getline_0200(void) void getline_0200(void)
{ {
size_t len = 0; size_t len = 0;
char path[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FILE_TXT, ptr);
if (!cwd) { FILE *fp = fopen(ptr, "w+");
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
FILE *fp = fopen(path, "w+");
EXPECT_PTRNE("getline_0100", fp, NULL); EXPECT_PTRNE("getline_0100", fp, NULL);
ssize_t read = getline(NULL, &len, fp); ssize_t read = getline(NULL, &len, fp);
EXPECT_EQ("getline_0200", read, -1); EXPECT_EQ("getline_0200", read, -1);
fclose(fp); fclose(fp);
remove(path); remove(ptr);
} }
/** /**
...@@ -80,20 +70,15 @@ void getline_0200(void) ...@@ -80,20 +70,15 @@ void getline_0200(void)
void getline_0300(void) void getline_0300(void)
{ {
char *line = NULL; char *line = NULL;
char path[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FILE_TXT, ptr);
if (!cwd) { FILE *fp = fopen(ptr, "w+");
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
FILE *fp = fopen(path, "w+");
EXPECT_PTRNE("getline_0100", fp, NULL); EXPECT_PTRNE("getline_0100", fp, NULL);
ssize_t read = getline(&line, 0, fp); ssize_t read = getline(&line, 0, fp);
EXPECT_EQ("getline_0300", read, -1); EXPECT_EQ("getline_0300", read, -1);
fclose(fp); fclose(fp);
remove(path); remove(ptr);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "test.h" #include "filepath_util.h"
const char *str = "Hello"; const char *str = "Hello";
...@@ -29,13 +29,8 @@ const char *str = "Hello"; ...@@ -29,13 +29,8 @@ const char *str = "Hello";
void setbuf_0100(void) void setbuf_0100(void)
{ {
char buf[BUFSIZ] = {0}; char buf[BUFSIZ] = {0};
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
FILE *f = fopen(path, "w+"); FILE *f = fopen(path, "w+");
errno = 0; errno = 0;
setbuf(f, buf); setbuf(f, buf);
...@@ -62,13 +57,8 @@ void setbuf_0100(void) ...@@ -62,13 +57,8 @@ void setbuf_0100(void)
*/ */
void setbuf_0200(void) void setbuf_0200(void)
{ {
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
FILE *f = fopen(path, "w+"); FILE *f = fopen(path, "w+");
errno = 0; errno = 0;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "test.h" #include "filepath_util.h"
const char *str = "Hello"; const char *str = "Hello";
...@@ -27,13 +27,8 @@ const char *str = "Hello"; ...@@ -27,13 +27,8 @@ const char *str = "Hello";
*/ */
void setbuffer_0100(void) void setbuffer_0100(void)
{ {
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
FILE *fp = fopen(path, "w+"); FILE *fp = fopen(path, "w+");
char buf[BUFSIZ] = {0}; char buf[BUFSIZ] = {0};
errno = 0; errno = 0;
...@@ -66,13 +61,8 @@ void setbuffer_0100(void) ...@@ -66,13 +61,8 @@ void setbuffer_0100(void)
*/ */
void setbuffer_0200(void) void setbuffer_0200(void)
{ {
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
FILE *f = fopen(path, "w+"); FILE *f = fopen(path, "w+");
errno = 0; errno = 0;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "test.h" #include "filepath_util.h"
const char *str = "Hello"; const char *str = "Hello";
...@@ -27,13 +27,8 @@ const char *str = "Hello"; ...@@ -27,13 +27,8 @@ const char *str = "Hello";
*/ */
void setlinebuf_0100(void) void setlinebuf_0100(void)
{ {
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
FILE *f = fopen(path, "w+"); FILE *f = fopen(path, "w+");
char buffer[BUFSIZ]; char buffer[BUFSIZ];
errno = 0; errno = 0;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
#include "functionalext.h" #include "functionalext.h"
#include "filepath_util.h"
/** /**
* @tc.name : setvbuf_0100 * @tc.name : setvbuf_0100
...@@ -23,13 +24,8 @@ ...@@ -23,13 +24,8 @@
void setvbuf_0100(void) void setvbuf_0100(void)
{ {
char buff[1024] = {0}; char buff[1024] = {0};
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
FILE *fptr = fopen(path, "w+"); FILE *fptr = fopen(path, "w+");
EXPECT_PTRNE("setvbuf_0100", fptr, NULL); EXPECT_PTRNE("setvbuf_0100", fptr, NULL);
...@@ -48,13 +44,8 @@ void setvbuf_0100(void) ...@@ -48,13 +44,8 @@ void setvbuf_0100(void)
void setvbuf_0200(void) void setvbuf_0200(void)
{ {
char buff[1024] = {0}; char buff[1024] = {0};
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
FILE *fptr = fopen(path, "w+"); FILE *fptr = fopen(path, "w+");
EXPECT_PTRNE("setvbuf_0100", fptr, NULL); EXPECT_PTRNE("setvbuf_0100", fptr, NULL);
......
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <wchar.h> #include <wchar.h>
#include <string.h>
#include "test.h" #include "filepath_util.h"
void handler(int sig) void handler(int sig)
{ {
...@@ -32,13 +32,8 @@ void handler(int sig) ...@@ -32,13 +32,8 @@ void handler(int sig)
*/ */
void ungetwc_0100(void) void ungetwc_0100(void)
{ {
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
FILE *file = fopen(path, "a+"); FILE *file = fopen(path, "a+");
if (!file) { if (!file) {
t_error("%s failed: fopen\n", __func__); t_error("%s failed: fopen\n", __func__);
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "test.h" #include "filepath_util.h"
int readFile(FILE *stream, char *fmt, ...) int readFile(FILE *stream, char *fmt, ...)
{ {
...@@ -37,13 +37,8 @@ void vfscanf_0100(void) ...@@ -37,13 +37,8 @@ void vfscanf_0100(void)
FILE *fp = NULL; FILE *fp = NULL;
int val = 0; int val = 0;
char buffer[BUFSIZ]; char buffer[BUFSIZ];
char file[128] = {0}; char file[PATH_MAX] = {0};
char *cwd = getcwd(file, sizeof(file)); FILE_ABSOLUTE_PATH(STR_VFSCANF_TXT, file);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(file, "/vfscanf.txt");
fp = fopen(file, "w+"); fp = fopen(file, "w+");
if (fp == NULL) { if (fp == NULL) {
t_error("%s fopen failed\n", __func__); t_error("%s fopen failed\n", __func__);
...@@ -79,13 +74,8 @@ void vfscanf_0200(void) ...@@ -79,13 +74,8 @@ void vfscanf_0200(void)
FILE *fp = NULL; FILE *fp = NULL;
char val[BUFSIZ]; char val[BUFSIZ];
char buffer[BUFSIZ]; char buffer[BUFSIZ];
char file[128] = {0}; char file[PATH_MAX] = {0};
char *cwd = getcwd(file, sizeof(file)); FILE_ABSOLUTE_PATH(STR_VFSCANF_TXT, file);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(file, "/vfscanf.txt");
fp = fopen(file, "w+"); fp = fopen(file, "w+");
if (fp == NULL) { if (fp == NULL) {
t_error("%s fopen failed\n", __func__); t_error("%s fopen failed\n", __func__);
...@@ -121,13 +111,8 @@ void vfscanf_0300(void) ...@@ -121,13 +111,8 @@ void vfscanf_0300(void)
FILE *fp = NULL; FILE *fp = NULL;
int val1 = 0; int val1 = 0;
int val2 = 0; int val2 = 0;
char file[128] = {0}; char file[PATH_MAX] = {0};
char *cwd = getcwd(file, sizeof(file)); FILE_ABSOLUTE_PATH(STR_VFSCANF_TXT, file);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(file, "/vfscanf.txt");
fp = fopen(file, "w+"); fp = fopen(file, "w+");
if (fp == NULL) { if (fp == NULL) {
t_error("%s fopen failed", __func__); t_error("%s fopen failed", __func__);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include "functionalext.h" #include "functionalext.h"
#include "filepath_util.h"
/** /**
* @tc.name : acct_0100 * @tc.name : acct_0100
...@@ -35,14 +36,8 @@ void acct_0100(void) ...@@ -35,14 +36,8 @@ void acct_0100(void)
*/ */
void acct_0200(void) void acct_0200(void)
{ {
char filePath[128] = {0}; char filePath[PATH_MAX] = {0};
char *cwd = getcwd(filePath, sizeof(filePath)); FILE_ABSOLUTE_PATH("accttest.txt", filePath);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(filePath, "/accttest.txt");
int result = acct(filePath); int result = acct(filePath);
EXPECT_EQ("acct_0300", result, -1); EXPECT_EQ("acct_0300", result, -1);
remove(filePath); remove(filePath);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "functionalext.h" #include "functionalext.h"
#include "filepath_util.h"
/* /*
* @tc.name : exit_0100 * @tc.name : exit_0100
...@@ -24,13 +25,9 @@ ...@@ -24,13 +25,9 @@
*/ */
void exit_0100(void) void exit_0100(void)
{ {
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_DIR(path);
if (!cwd) { char cmd[PATH_MAX] = {0};
t_error("%s getcwd failed\n", __func__);
return;
}
char cmd[256] = {0};
snprintf(cmd, sizeof(cmd), "cd %s; ./exittest01", path); snprintf(cmd, sizeof(cmd), "cd %s; ./exittest01", path);
system(cmd); system(cmd);
...@@ -62,13 +59,9 @@ void exit_0100(void) ...@@ -62,13 +59,9 @@ void exit_0100(void)
*/ */
void exit_0200(void) void exit_0200(void)
{ {
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_DIR(path);
if (!cwd) { char cmd[PATH_MAX] = {0};
t_error("%s getcwd failed\n", __func__);
return;
}
char cmd[256] = {0};
snprintf(cmd, sizeof(cmd), "cd %s; ./exittest02", path); snprintf(cmd, sizeof(cmd), "cd %s; ./exittest02", path);
system(cmd); system(cmd);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "functionalext.h" #include "functionalext.h"
#include "filepath_util.h"
typedef void (*TEST_FUN)(); typedef void (*TEST_FUN)();
const int SUCCESS = 0; const int SUCCESS = 0;
...@@ -29,13 +30,8 @@ const int FAILED = -1; ...@@ -29,13 +30,8 @@ const int FAILED = -1;
*/ */
void faccessat_0100(void) void faccessat_0100(void)
{ {
char ptr[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(ptr, sizeof(ptr)); FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/faccessattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT); int fd = open(ptr, O_RDWR | O_CREAT);
EXPECT_TRUE("faccessat_0100", fd >= 0); EXPECT_TRUE("faccessat_0100", fd >= 0);
int isExist = faccessat(fd, ptr, F_OK, 0); int isExist = faccessat(fd, ptr, F_OK, 0);
...@@ -51,13 +47,8 @@ void faccessat_0100(void) ...@@ -51,13 +47,8 @@ void faccessat_0100(void)
*/ */
void faccessat_0200(void) void faccessat_0200(void)
{ {
char ptr[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(ptr, sizeof(ptr)); FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/faccessattest.txt");
int fd = -1; int fd = -1;
int isExist = faccessat(fd, ptr, F_OK, 0); int isExist = faccessat(fd, ptr, F_OK, 0);
EXPECT_EQ("faccessat_0200", isExist, FAILED); EXPECT_EQ("faccessat_0200", isExist, FAILED);
...@@ -72,13 +63,8 @@ void faccessat_0200(void) ...@@ -72,13 +63,8 @@ void faccessat_0200(void)
*/ */
void faccessat_0300(void) void faccessat_0300(void)
{ {
char ptr[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(ptr, sizeof(ptr)); FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/faccessattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT, 00040); int fd = open(ptr, O_RDWR | O_CREAT, 00040);
EXPECT_TRUE("faccessat_0300", fd >= 0); EXPECT_TRUE("faccessat_0300", fd >= 0);
int isRead = faccessat(fd, ptr, R_OK, 0); int isRead = faccessat(fd, ptr, R_OK, 0);
...@@ -94,13 +80,8 @@ void faccessat_0300(void) ...@@ -94,13 +80,8 @@ void faccessat_0300(void)
*/ */
void faccessat_0400(void) void faccessat_0400(void)
{ {
char ptr[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(ptr, sizeof(ptr)); FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/faccessattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT, 00020); int fd = open(ptr, O_RDWR | O_CREAT, 00020);
EXPECT_TRUE("faccessat_0400", fd >= 0); EXPECT_TRUE("faccessat_0400", fd >= 0);
int isWrite = faccessat(fd, ptr, W_OK, 0); int isWrite = faccessat(fd, ptr, W_OK, 0);
...@@ -116,13 +97,8 @@ void faccessat_0400(void) ...@@ -116,13 +97,8 @@ void faccessat_0400(void)
*/ */
void faccessat_0500(void) void faccessat_0500(void)
{ {
char ptr[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(ptr, sizeof(ptr)); FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/faccessattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT, 00010); int fd = open(ptr, O_RDWR | O_CREAT, 00010);
char cmd[256] = {0}; char cmd[256] = {0};
snprintf(cmd, sizeof(cmd), "chmod 777 %s", ptr); snprintf(cmd, sizeof(cmd), "chmod 777 %s", ptr);
...@@ -141,13 +117,8 @@ void faccessat_0500(void) ...@@ -141,13 +117,8 @@ void faccessat_0500(void)
*/ */
void faccessat_0600(void) void faccessat_0600(void)
{ {
char ptr[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(ptr, sizeof(ptr)); FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/faccessattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT); int fd = open(ptr, O_RDWR | O_CREAT);
EXPECT_TRUE("faccessat_0600", fd >= 0); EXPECT_TRUE("faccessat_0600", fd >= 0);
int isExecute = faccessat(fd, ptr, X_OK, 0); int isExecute = faccessat(fd, ptr, X_OK, 0);
...@@ -163,13 +134,8 @@ void faccessat_0600(void) ...@@ -163,13 +134,8 @@ void faccessat_0600(void)
*/ */
void faccessat_0700(void) void faccessat_0700(void)
{ {
char ptr[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(ptr, sizeof(ptr)); FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/faccessattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT, 00070); int fd = open(ptr, O_RDWR | O_CREAT, 00070);
EXPECT_TRUE("faccessat_0700", fd >= 0); EXPECT_TRUE("faccessat_0700", fd >= 0);
int isExecute = faccessat(fd, ptr, R_OK | W_OK | X_OK, 0); int isExecute = faccessat(fd, ptr, R_OK | W_OK | X_OK, 0);
...@@ -185,13 +151,8 @@ void faccessat_0700(void) ...@@ -185,13 +151,8 @@ void faccessat_0700(void)
*/ */
void faccessat_0800(void) void faccessat_0800(void)
{ {
char ptr[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(ptr, sizeof(ptr)); FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/faccessattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT); int fd = open(ptr, O_RDWR | O_CREAT);
EXPECT_TRUE("faccessat_0800", fd >= 0); EXPECT_TRUE("faccessat_0800", fd >= 0);
int isExecute = faccessat(fd, ptr, R_OK | W_OK | X_OK, 0); int isExecute = faccessat(fd, ptr, R_OK | W_OK | X_OK, 0);
...@@ -207,13 +168,8 @@ void faccessat_0800(void) ...@@ -207,13 +168,8 @@ void faccessat_0800(void)
*/ */
void faccessat_0900(void) void faccessat_0900(void)
{ {
char ptr[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(ptr, sizeof(ptr)); FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/faccessattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT, 00070); int fd = open(ptr, O_RDWR | O_CREAT, 00070);
EXPECT_TRUE("faccessat_0900", fd >= 0); EXPECT_TRUE("faccessat_0900", fd >= 0);
int ret = faccessat(fd, ptr, R_OK, AT_SYMLINK_NOFOLLOW); int ret = faccessat(fd, ptr, R_OK, AT_SYMLINK_NOFOLLOW);
...@@ -231,13 +187,8 @@ void faccessat_0900(void) ...@@ -231,13 +187,8 @@ void faccessat_0900(void)
*/ */
void faccessat_1000(void) void faccessat_1000(void)
{ {
char ptr[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(ptr, sizeof(ptr)); FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/faccessattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT, 00070); int fd = open(ptr, O_RDWR | O_CREAT, 00070);
EXPECT_TRUE("faccessat_1000", fd >= 0); EXPECT_TRUE("faccessat_1000", fd >= 0);
int isExecute = faccessat(AT_FDCWD, ptr, R_OK | W_OK | X_OK, AT_EACCESS); int isExecute = faccessat(AT_FDCWD, ptr, R_OK | W_OK | X_OK, AT_EACCESS);
...@@ -254,13 +205,8 @@ void faccessat_1000(void) ...@@ -254,13 +205,8 @@ void faccessat_1000(void)
*/ */
void faccessat_1100(void) void faccessat_1100(void)
{ {
char ptr[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(ptr, sizeof(ptr)); FILE_ABSOLUTE_PATH(STR_FACCESSAT_TEST_TXT, ptr);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/faccessattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT); int fd = open(ptr, O_RDWR | O_CREAT);
EXPECT_TRUE("faccessat_1100", fd >= 0); EXPECT_TRUE("faccessat_1100", fd >= 0);
int isExecute = faccessat(AT_FDCWD, ptr, R_OK | W_OK | X_OK, AT_EACCESS); int isExecute = faccessat(AT_FDCWD, ptr, R_OK | W_OK | X_OK, AT_EACCESS);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <unistd.h> #include <unistd.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "functionalext.h" #include "functionalext.h"
#include "filepath_util.h"
/** /**
* @tc.name : fchownat_0100 * @tc.name : fchownat_0100
...@@ -25,13 +26,8 @@ ...@@ -25,13 +26,8 @@
*/ */
void fchownat_0100(void) void fchownat_0100(void)
{ {
char ptr[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(ptr, sizeof(ptr)); FILE_ABSOLUTE_PATH(STR_FCHOWNAT_TEST_TXT, ptr);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/fchownattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT); int fd = open(ptr, O_RDWR | O_CREAT);
EXPECT_TRUE("fchownat_0100", fd >= 0); EXPECT_TRUE("fchownat_0100", fd >= 0);
int ret = fchownat(fd, ptr, 0, 0, AT_SYMLINK_NOFOLLOW); int ret = fchownat(fd, ptr, 0, 0, AT_SYMLINK_NOFOLLOW);
...@@ -52,13 +48,8 @@ void fchownat_0100(void) ...@@ -52,13 +48,8 @@ void fchownat_0100(void)
*/ */
void fchownat_0200(void) void fchownat_0200(void)
{ {
char ptr[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(ptr, sizeof(ptr)); FILE_ABSOLUTE_PATH(STR_FCHOWNAT_TEST_TXT, ptr);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(ptr, "/fchownattest.txt");
int fd = open(ptr, O_RDWR | O_CREAT); int fd = open(ptr, O_RDWR | O_CREAT);
EXPECT_TRUE("fchownat_0200", fd >= 0); EXPECT_TRUE("fchownat_0200", fd >= 0);
int ret = fchownat(AT_FDCWD, ptr, 0, 0, AT_SYMLINK_NOFOLLOW); int ret = fchownat(AT_FDCWD, ptr, 0, 0, AT_SYMLINK_NOFOLLOW);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include "functionalext.h" #include "functionalext.h"
#include "filepath_util.h"
/** /**
* @tc.name : getpid_0100 * @tc.name : getpid_0100
...@@ -26,19 +27,14 @@ ...@@ -26,19 +27,14 @@
*/ */
void getpid_0100(void) void getpid_0100(void)
{ {
char path[128] = {0}; char ptr[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH("ps.txt", ptr);
if (!cwd) { char cmd[PATH_MAX] = {0};
t_error("%s getcwd failed\n", __func__); snprintf(cmd, sizeof(cmd), "ps -eo command,pid | grep -E \"PID|getpid\" > %s", ptr);
return;
}
strcat(path, "/ps.txt");
char cmd[256] = {0};
snprintf(cmd, sizeof(cmd), "ps -eo command,pid | grep -E \"PID|getpid\" > %s", path);
system(cmd); system(cmd);
char abc[256] = {0}; char abc[256] = {0};
bool successflag = false; bool successflag = false;
FILE *fptr = fopen(path, "r"); FILE *fptr = fopen(ptr, "r");
if (fptr) { if (fptr) {
while (!feof(fptr)) { while (!feof(fptr)) {
fread(abc, sizeof(abc), 1, fptr); fread(abc, sizeof(abc), 1, fptr);
...@@ -58,7 +54,7 @@ void getpid_0100(void) ...@@ -58,7 +54,7 @@ void getpid_0100(void)
} }
EXPECT_TRUE("getpid_0100", successflag); EXPECT_TRUE("getpid_0100", successflag);
fclose(fptr); fclose(fptr);
remove(path); remove(ptr);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <unistd.h> #include <unistd.h>
#include "functionalext.h" #include "functionalext.h"
#include "filepath_util.h"
#define TEST_ID_VALUE 100 #define TEST_ID_VALUE 100
...@@ -25,14 +26,9 @@ ...@@ -25,14 +26,9 @@
*/ */
void lchown_0100(void) void lchown_0100(void)
{ {
char path[128] = {0}; char pathname[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH("lchown", pathname);
if (!cwd) { int ret = lchown(pathname, TEST_ID_VALUE, TEST_ID_VALUE);
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/lchown");
int ret = lchown(path, TEST_ID_VALUE, TEST_ID_VALUE);
EXPECT_EQ("lchown_0100", ret, CMPFLAG); EXPECT_EQ("lchown_0100", ret, CMPFLAG);
} }
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "test.h" #include "filepath_util.h"
const char buf[] = "hello"; const char buf[] = "hello";
const char *filename = "./file.txt"; const char *filename = "./file.txt";
...@@ -52,26 +52,16 @@ int create_file(char *path) ...@@ -52,26 +52,16 @@ int create_file(char *path)
*/ */
void readlinkat_0100(void) void readlinkat_0100(void)
{ {
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
if (!cwd) {
t_error("%s getcwd file failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int result = create_file(path); int result = create_file(path);
if (result != 0) { if (result != 0) {
t_error("%s failed: result = %d\n", __func__, result); t_error("%s failed: result = %d\n", __func__, result);
return; return;
} }
char linkpath[128] = {0}; char linkpath[PATH_MAX] = {0};
cwd = getcwd(linkpath, sizeof(linkpath)); FILE_ABSOLUTE_PATH(STR_FILE_LINK_TXT, linkpath);
if (!cwd) {
t_error("%s getcwd link failed\n", __func__);
return;
}
strcat(linkpath, "/linkfile.txt");
remove(linkpath); remove(linkpath);
result = symlink(path, linkpath); result = symlink(path, linkpath);
...@@ -107,25 +97,16 @@ void readlinkat_0100(void) ...@@ -107,25 +97,16 @@ void readlinkat_0100(void)
*/ */
void readlinkat_0200(void) void readlinkat_0200(void)
{ {
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
if (!cwd) {
t_error("%s getcwd file failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int result = create_file(path); int result = create_file(path);
if (result != 0) { if (result != 0) {
t_error("%s failed: result = %d\n", __func__, result); t_error("%s failed: result = %d\n", __func__, result);
return; return;
} }
char dirname[128] = {0}; char dirname[PATH_MAX] = {0};
cwd = getcwd(dirname, sizeof(dirname)); FILE_ABSOLUTE_DIR(dirname);
if (!cwd) {
t_error("%s getcwd dir failed\n", __func__);
return;
}
DIR *dir = opendir(dirname); DIR *dir = opendir(dirname);
if (dir == NULL) { if (dir == NULL) {
t_error("%s failed: dirname = %s\n", __func__, dirname); t_error("%s failed: dirname = %s\n", __func__, dirname);
...@@ -137,13 +118,8 @@ void readlinkat_0200(void) ...@@ -137,13 +118,8 @@ void readlinkat_0200(void)
t_error("%s failed: fd = %d\n", __func__, fd); t_error("%s failed: fd = %d\n", __func__, fd);
} }
char linkpath[128] = {0}; char linkpath[PATH_MAX] = {0};
cwd = getcwd(linkpath, sizeof(linkpath)); FILE_ABSOLUTE_PATH(STR_FILE_LINK_TXT, linkpath);
if (!cwd) {
t_error("%s getcwd link failed\n", __func__);
return;
}
strcat(linkpath, "/linkfile.txt");
remove(linkpath); remove(linkpath);
result = symlinkat(filename, fd, linkfilename); result = symlinkat(filename, fd, linkfilename);
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include <string.h> #include <string.h>
#include <sys/uio.h> #include <sys/uio.h>
#include "test.h" #include "filepath_util.h"
/** /**
* @tc.name : readv_0100 * @tc.name : readv_0100
...@@ -28,13 +28,8 @@ ...@@ -28,13 +28,8 @@
*/ */
void readv_0100(void) void readv_0100(void)
{ {
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int fd = open(path, O_RDWR | O_CREAT); int fd = open(path, O_RDWR | O_CREAT);
char buf1[] = "hello"; char buf1[] = "hello";
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "test.h" #include "filepath_util.h"
const int nlen = -1; const int nlen = -1;
const int vlen = 5; const int vlen = 5;
...@@ -33,13 +33,8 @@ const char *content = "Hello world!"; ...@@ -33,13 +33,8 @@ const char *content = "Hello world!";
*/ */
void truncate_0100(void) void truncate_0100(void)
{ {
char path_n[128] = {0}; char path_n[PATH_MAX] = {0};
char *cwd = getcwd(path_n, sizeof(path_n)); FILE_ABSOLUTE_PATH("files.txt", path_n);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path_n, "/files.txt");
FILE *f = fopen(path_n, "a"); FILE *f = fopen(path_n, "a");
if (f == NULL) { if (f == NULL) {
t_error("%s failed: fopen\n", __func__); t_error("%s failed: fopen\n", __func__);
...@@ -62,13 +57,8 @@ void truncate_0100(void) ...@@ -62,13 +57,8 @@ void truncate_0100(void)
*/ */
void truncate_0200(void) void truncate_0200(void)
{ {
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
FILE *f = fopen(path, "a"); FILE *f = fopen(path, "a");
if (f == NULL) { if (f == NULL) {
t_error("%s failed: fopen\n", __func__); t_error("%s failed: fopen\n", __func__);
...@@ -111,13 +101,8 @@ void truncate_0200(void) ...@@ -111,13 +101,8 @@ void truncate_0200(void)
*/ */
void truncate_0300(void) void truncate_0300(void)
{ {
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int result = truncate(path, nlen); int result = truncate(path, nlen);
if (result == 0) { if (result == 0) {
t_error("%s failed: result = %d\n", __func__, result); t_error("%s failed: result = %d\n", __func__, result);
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include "test.h" #include "filepath_util.h"
/** /**
* @tc.name : unlink_0100 * @tc.name : unlink_0100
...@@ -26,13 +26,8 @@ ...@@ -26,13 +26,8 @@
*/ */
void unlink_0100(void) void unlink_0100(void)
{ {
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH("test_unlink.txt", path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/test_unlink.txt");
int fd = open(path, O_CREAT); int fd = open(path, O_CREAT);
int error_code = -1; int error_code = -1;
if (fd == error_code) { if (fd == error_code) {
...@@ -53,13 +48,8 @@ void unlink_0100(void) ...@@ -53,13 +48,8 @@ void unlink_0100(void)
*/ */
void unlink_0200(void) void unlink_0200(void)
{ {
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH("unexist_test_unlink.txt", path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/unexist_test_unlink.txt");
int result = unlink(path); int result = unlink(path);
int error_code = -1; int error_code = -1;
if (result != error_code) { if (result != error_code) {
......
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h>
#include "test.h" #include "filepath_util.h"
/** /**
* @tc.name : unlinkat_0100 * @tc.name : unlinkat_0100
...@@ -25,14 +25,8 @@ ...@@ -25,14 +25,8 @@
*/ */
void unlinkat_0100(void) void unlinkat_0100(void)
{ {
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int fd = open(path, O_CREAT, 0664); int fd = open(path, O_CREAT, 0664);
int result = unlinkat(fd, path, 0); int result = unlinkat(fd, path, 0);
...@@ -51,13 +45,8 @@ void unlinkat_0100(void) ...@@ -51,13 +45,8 @@ void unlinkat_0100(void)
void unlinkat_0200(void) void unlinkat_0200(void)
{ {
errno = 0; errno = 0;
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/file.txt");
int result = unlinkat(AT_FDCWD, path, AT_REMOVEDIR); int result = unlinkat(AT_FDCWD, path, AT_REMOVEDIR);
if (result == 0) { if (result == 0) {
t_error("%s failed: result = %d\n", __func__, result); t_error("%s failed: result = %d\n", __func__, result);
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "test.h" #include "filepath_util.h"
/** /**
* @tc.name : write_0100 * @tc.name : write_0100
...@@ -27,13 +27,8 @@ ...@@ -27,13 +27,8 @@
void write_0100(void) void write_0100(void)
{ {
const char *msg = "This is a c test code for write function"; const char *msg = "This is a c test code for write function";
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_WRITE_TEST_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/test_write.txt");
int len = strlen(msg); int len = strlen(msg);
char buf[1024] = {0}; char buf[1024] = {0};
int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664); int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664);
...@@ -67,13 +62,8 @@ void write_0100(void) ...@@ -67,13 +62,8 @@ void write_0100(void)
void write_0200(void) void write_0200(void)
{ {
const char *msg = "This is a c test code for write function"; const char *msg = "This is a c test code for write function";
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_WRITE_TEST_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/test_write.txt");
int len = 0; int len = 0;
int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664); int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664);
if (fd == -1) { if (fd == -1) {
...@@ -96,13 +86,8 @@ void write_0200(void) ...@@ -96,13 +86,8 @@ void write_0200(void)
void write_0300(void) void write_0300(void)
{ {
const char *msg = "This is a c test code for write function"; const char *msg = "This is a c test code for write function";
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_WRITE_TEST_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/test_write.txt");
int len = strlen(msg) + 1; int len = strlen(msg) + 1;
int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664); int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664);
if (fd == -1) { if (fd == -1) {
...@@ -125,13 +110,8 @@ void write_0300(void) ...@@ -125,13 +110,8 @@ void write_0300(void)
void write_0400(void) void write_0400(void)
{ {
const char *msg = "This is a c test code for write function"; const char *msg = "This is a c test code for write function";
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_WRITE_TEST_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/test_write.txt");
int len = strlen(msg); int len = strlen(msg);
int fd = open(path, O_RDWR); int fd = open(path, O_RDWR);
int result = write(fd, msg, len); int result = write(fd, msg, len);
...@@ -150,13 +130,8 @@ void write_0400(void) ...@@ -150,13 +130,8 @@ void write_0400(void)
void write_0500(void) void write_0500(void)
{ {
const char *msg = NULL; const char *msg = NULL;
char path[128] = {0}; char path[PATH_MAX] = {0};
char *cwd = getcwd(path, sizeof(path)); FILE_ABSOLUTE_PATH(STR_WRITE_TEST_TXT, path);
if (!cwd) {
t_error("%s getcwd failed\n", __func__);
return;
}
strcat(path, "/test_write.txt");
int len = 1; int len = 1;
int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664); int fd = open(path, O_RDWR | O_RSYNC | O_CREAT, 0664);
if (fd == -1) { if (fd == -1) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册