未验证 提交 067175f8 编写于 作者: O openharmony_ci 提交者: Gitee

!712 修正libc-test中绝对路径为相对路径

Merge pull request !712 from dhy308/releaseTestPath
/**
* 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,9 +17,7 @@
#include <signal.h>
#include <stdlib.h>
#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);
......
......@@ -18,9 +18,7 @@
#include <stdlib.h>
#include <string.h>
#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);
......
......@@ -16,9 +16,7 @@
#include <dirent.h>
#include <stdlib.h>
#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);
......
......@@ -15,6 +15,7 @@
#include <sys/ipc.h>
#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);
}
......
......@@ -18,12 +18,10 @@
#include <string.h>
#include <sys/sem.h>
#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);
......
......@@ -17,10 +17,8 @@
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#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__);
......
......@@ -19,9 +19,8 @@
#include <string.h>
#include <sys/xattr.h>
#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);
......
......@@ -19,10 +19,7 @@
#include <string.h>
#include <sys/sendfile.h>
#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);
......
......@@ -19,9 +19,8 @@
#include <string.h>
#include <sys/xattr.h>
#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);
......
......@@ -19,10 +19,8 @@
#include <string.h>
#include <unistd.h>
#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);
......
......@@ -17,7 +17,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/swap.h>
#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__);
}
......
......@@ -17,7 +17,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/swap.h>
#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) {
......
......@@ -17,9 +17,8 @@
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#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__);
......
......@@ -17,9 +17,8 @@
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#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__);
......
......@@ -17,7 +17,7 @@
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#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) {
......
......@@ -19,6 +19,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#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) {
......
......@@ -16,6 +16,7 @@
#include <fcntl.h>
#include <sys/stat.h>
#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);
}
/**
......
......@@ -17,6 +17,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#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;
}
/**
......
......@@ -18,6 +18,7 @@
#include <stdbool.h>
#include <stdlib.h>
#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
}
......@@ -15,6 +15,7 @@
#include <sys/stat.h>
#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);
}
......
......@@ -17,10 +17,8 @@
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#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}};
......
......@@ -15,6 +15,7 @@
#include <stdio_ext.h>
#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__);
......
......@@ -19,6 +19,7 @@
#include <stdint.h>
#include <stddef.h>
#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);
......
......@@ -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);
......
......@@ -15,6 +15,7 @@
#include <fcntl.h>
#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);
......
......@@ -15,8 +15,7 @@
#include <fcntl.h>
#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);
......
......@@ -17,9 +17,8 @@
#include <stdio.h>
#include <string.h>
#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;
......
......@@ -16,9 +16,8 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
#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;
......
......@@ -16,9 +16,8 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
#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;
......
......@@ -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[])
......
......@@ -18,9 +18,7 @@
#include <stdlib.h>
#include <wchar.h>
#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__);
......
......@@ -16,9 +16,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#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__);
......
......@@ -16,6 +16,7 @@
#include <fcntl.h>
#include <unistd.h>
#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);
......
......@@ -15,6 +15,7 @@
#include <stdlib.h>
#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";
......
......@@ -17,6 +17,7 @@
#include <stdlib.h>
#include <stdio.h>
#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[] = {
......
......@@ -17,6 +17,7 @@
#include <unistd.h>
#include <sys/stat.h>
#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[])
......
......@@ -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__);
......
......@@ -18,6 +18,7 @@
#include <stdlib.h>
#include <unistd.h>
#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)) {
......
......@@ -15,6 +15,7 @@
#include <unistd.h>
#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);
}
......
......@@ -19,16 +19,13 @@
#include <string.h>
#include <unistd.h>
#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);
......
......@@ -19,9 +19,7 @@
#include <string.h>
#include <sys/uio.h>
#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";
......
......@@ -18,12 +18,10 @@
#include <string.h>
#include <unistd.h>
#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);
......
......@@ -17,7 +17,7 @@
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#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);
......
......@@ -16,9 +16,7 @@
#include <errno.h>
#include <fcntl.h>
#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);
......
......@@ -17,7 +17,7 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册