提交 8c926ff0 编写于 作者: G ganlan

fix libctest codex

Signed-off-by: Nganlan <tony.gan@huawei.com>
上级 4f5c8ae2
......@@ -14,8 +14,6 @@
*/
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "functionalext.h"
......@@ -27,8 +25,7 @@
*/
void fpathconf_0100(void)
{
long result;
result = fpathconf(0, _PC_LINK_MAX);
long result = fpathconf(0, _PC_LINK_MAX);
EXPECT_EQ("fpathconf_0100", result, _POSIX_LINK_MAX);
}
......@@ -40,8 +37,7 @@ void fpathconf_0100(void)
*/
void fpathconf_0200(void)
{
long result;
result = fpathconf(0, _PC_SOCK_MAXBUF);
long result = fpathconf(0, _PC_SOCK_MAXBUF);
EXPECT_EQ("fpathconf_0200", result, -1);
}
......@@ -53,8 +49,7 @@ void fpathconf_0200(void)
*/
void fpathconf_0300(void)
{
long result;
result = fpathconf(0, _PC_FILESIZEBITS);
long result = fpathconf(0, _PC_FILESIZEBITS);
EXPECT_EQ("fpathconf_0300", result, FILESIZEBITS);
}
......@@ -66,8 +61,7 @@ void fpathconf_0300(void)
*/
void fpathconf_0400(void)
{
long result;
result = fpathconf(0, _PC_2_SYMLINKS);
long result = fpathconf(0, _PC_2_SYMLINKS);
EXPECT_EQ("fpathconf_0400", result, 1);
}
......@@ -79,8 +73,7 @@ void fpathconf_0400(void)
*/
void fpathconf_0500(void)
{
long result;
result = fpathconf(0, 1000);
long result = fpathconf(0, 1000);
EXPECT_EQ("fpathconf_0500", result, -1);
}
......
......@@ -14,13 +14,6 @@
*/
#include <ctype.h>
#include <dlfcn.h>
#include <errno.h>
#include <locale.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <wctype.h>
#include "functionalext.h"
/**
......@@ -87,7 +80,7 @@ void ispunct_0500(void)
EXPECT_EQ("ispunct_0500", cout, 32);
}
int main(void)
int main(int argc, char *argv[])
{
ispunct_0100();
ispunct_0200();
......
......@@ -13,13 +13,9 @@
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include "functionalext.h"
#define MAXPATH 1000
/**
* @tc.name : alphasort_0100
* @tc.desc : Verify that the directory structure can be sorted alphabetically
......@@ -28,8 +24,7 @@
void alphasort_0100(void)
{
struct dirent **namelist;
int n, total;
total = scandir("/", &namelist, 0, alphasort);
int total = scandir("/", &namelist, 0, alphasort);
EXPECT_TRUE("alphasort_0100", total > 0);
}
......@@ -41,8 +36,7 @@ void alphasort_0100(void)
void alphasort_0200(void)
{
struct dirent **namelist;
int n, total;
total = scandir(NULL, &namelist, 0, alphasort);
int total = scandir(NULL, &namelist, 0, alphasort);
EXPECT_TRUE("alphasort_0100", total < 0);
}
......
......@@ -14,45 +14,29 @@
*/
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <signal.h>
#include <sys/stat.h>
#include "test.h"
#include "functionalext.h"
struct __dirstream {
long long tell;
int fd;
int buf_pos;
int buf_end;
volatile int lock[1];
char buf[2048];
};
#define MAXPATH 1000
const int COUNT_NEGATIVE = -1;
/*
* @tc.name : dirfd_0100
* @tc.desc : Verify that the file descriptor for the directory file referred to by parameter d is available
* (parameter valid)
* @tc.desc : Get directory stream file descriptor
* @tc.level : Level 0
*/
void dirfd_0100(void)
{
bool flag = true;
char path[MAXPATH];
DIR *dir_ptr;
getcwd(path, MAXPATH);
dir_ptr = opendir(path);
int result = 0;
result = dirfd(dir_ptr);
if (result > 0) {
flag = true;
DIR *dir = opendir(".");
if (!dir) {
t_error("%s opendir failed\n", __func__);
}
int fd = dirfd(dir);
if (fd < 0) {
t_error("%s dirfd failed\n", __func__);
}
int result = close(fd);
if (result < 0) {
t_error("%s close fd failed\n", __func__);
}
EXPECT_TRUE("dirfd_0100", flag);
closedir(dir_ptr);
}
int main(int argc, char *argv[])
......
......@@ -17,7 +17,6 @@
#include <dirent.h>
#include <dlfcn.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
......@@ -33,16 +32,10 @@ void fdopendir_0100(void)
bool flag = false;
DIR *dir = NULL;
int fd = open("/data/data", O_RDONLY);
if (fd < 0) {
t_error("%s open failed, fd = %d\n", __func__, fd);
}
EXPECT_NE("fdopendir_0100", fd, -1);
dir = fdopendir(fd);
if (dir == 0) {
t_error("%s fdopendir failed\n", __func__);
} else {
flag = true;
}
EXPECT_TRUE("fdopendir_0100", flag);
EXPECT_TRUE("fdopendir_0100", dir != 0);
}
/**
......@@ -81,7 +74,7 @@ void fdopendir_0400(void)
int fd = open("/data/data/test.txt", O_RDONLY);
dir = fdopendir(fd);
EXPECT_EQ("fdopendir_0400", dir, NULL);
system("rm -rf /data/data/test.txt");
remove("/data/data/test.txt");
}
int main(int argc, char *argv[])
......
......@@ -16,6 +16,5 @@ functionalext_supplement_exit_test = [
"a_cxa_finalize",
"at_quick_exit",
"atexit",
"__aeabi_atexit",
"quick_exit",
]
......@@ -17,8 +17,6 @@
#include <sys/stat.h>
#include "functionalext.h"
typedef void (*TEST_FUN)();
/**
* @tc.name : creat_0100
* @tc.desc : Each parameter is valid and a new file can be created.
......@@ -27,7 +25,7 @@ typedef void (*TEST_FUN)();
void creat_0100(void)
{
int fd = -1;
const char *ptr = "creattest.txt";
const char *ptr = "/data/creattest.txt";
fd = creat(ptr, O_RDWR | O_CREAT);
EXPECT_NE("creat_0100", fd, -1);
close(fd);
......@@ -59,7 +57,7 @@ void creat_0200(void)
void creat_0300(void)
{
int fd = 0;
const char *ptr = "creattest.txt";
const char *ptr = "/data/creattest.txt";
fd = open(ptr, O_WRONLY);
EXPECT_EQ("creat_0300", fd, -1);
close(fd);
......
......@@ -14,9 +14,7 @@
*/
#include <sys/ipc.h>
#include <sys/stat.h>
#include "functionalext.h"
int failed = -1;
/*
* @tc.name : ftok_0100
......@@ -26,7 +24,7 @@ int failed = -1;
void ftok_0100(void)
{
key_t result = ftok("/data/tests/libc-test/src/functionalext/supplement/ipc/ftok", 1);
EXPECT_NE("ftok_0100", result, failed);
EXPECT_NE("ftok_0100", result, -1);
}
/*
......@@ -37,7 +35,7 @@ void ftok_0100(void)
void ftok_0200(void)
{
key_t result = ftok("./test", 1);
EXPECT_EQ("ftok_0200", result, failed);
EXPECT_EQ("ftok_0200", result, -1);
}
int main(int argc, char *argv[])
{
......
......@@ -15,9 +15,7 @@
#include <dlfcn.h>
#include <link.h>
#include <stdio.h>
#include <stdlib.h>
#include "functionalext.h"
static int header_handler(struct dl_phdr_info *info, size_t size, void *data)
......
......@@ -14,9 +14,7 @@
*/
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#include "functionalext.h"
void test1()
......@@ -34,13 +32,10 @@ void dladdr_0100(void)
int num = 0;
int ret = dladdr((void *)test1, &info);
EXPECT_EQ("dladdr_0100", ret, 1);
char *name = "dladdr";
if (strstr(info.dli_fname, name)) {
num = 1;
} else {
num = 2;
}
EXPECT_EQ("dladdr_0100", num, 1);
char *result = strstr(info.dli_fname, name);
EXPECT_PTRNE("dladdr_0100", result, NULL);
}
/**
......@@ -55,12 +50,7 @@ void dladdr_0200(void)
int num = 0;
int ret = dladdr(NULL, &info);
EXPECT_EQ("dladdr_0100", ret, 0);
if (info.dli_fname == NULL) {
num = 1;
} else {
num = 2;
}
EXPECT_EQ("dladdr_0200", num, 1);
EXPECT_TRUE("dladdr_0200", info.dli_fname == NULL);
}
int main(int argc, char *argv[])
......
......@@ -19,7 +19,6 @@
int successfully = 0;
int failed = -1;
typedef void (*TEST_FUN)();
/*
* @tc.name : daemon_0100
......
......@@ -14,7 +14,6 @@
*/
#include <ftw.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include "functionalext.h"
......
......@@ -14,7 +14,6 @@
*/
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <unistd.h>
......
......@@ -13,9 +13,8 @@
* limitations under the License.
*/
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <stdbool.h>
#include "functionalext.h"
/**
......@@ -25,14 +24,27 @@
*/
void getloadavg_0100(void)
{
bool flag = false;
double buf[1024];
int result = -10;
result = getloadavg(buf, 1024);
if (result > 0) {
flag = true;
}
EXPECT_TRUE("getloadavg_0100", flag);
int result;
double load[3];
result = getloadavg(load, -1);
EXPECT_EQ("getloadavg_0100", result, -1);
result = getloadavg(load, INT_MIN);
EXPECT_EQ("getloadavg_0100", result, -1);
result = getloadavg(load, 0);
EXPECT_EQ("getloadavg_0100", result, 0);
result = getloadavg(load, 1);
EXPECT_EQ("getloadavg_0100", result, 1);
result = getloadavg(load, 2);
EXPECT_EQ("getloadavg_0100", result, 2);
result = getloadavg(load, 3);
EXPECT_EQ("getloadavg_0100", result, 3);
result = getloadavg(load, 4);
EXPECT_EQ("getloadavg_0100", result, 3);
result = getloadavg(load, INT_MAX);
EXPECT_EQ("getloadavg_0100", result, 3);
}
int main(int argc, char *argv[])
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "functionalext.h"
......
......@@ -13,71 +13,53 @@
* limitations under the License.
*/
#include <unistd.h>
#include <stdio.h>
#include <netinet/in.h>
#include <sys/capability.h>
#include <sys/socket.h>
#include "functionalext.h"
#undef _POSIX_SOURCE
const int32_t COUNT_ZERO = 0;
const int32_t COUNT_NEGATIVE = -1;
#include "test.h"
/**
* @tc.name : capget_0100
* @tc.desc : Verify that you can obtain process permissions (parameter valid)
* @tc.desc : Verify that this function can obtain process permissions
* @tc.level : Level 0
*/
void capget_0100(void)
{
struct __user_cap_header_struct cap_header_data;
cap_user_header_t cap_header = &cap_header_data;
struct __user_cap_data_struct cap_data_data;
cap_user_data_t cap_data = &cap_data_data;
int result;
cap_header->pid = getpid();
cap_header->version = _LINUX_CAPABILITY_VERSION_1;
result = capget(cap_header, cap_data);
EXPECT_EQ("capget_0100", result, COUNT_ZERO);
int result = capget(cap_header, cap_data);
if (result < 0) {
t_error("%s capget failed\n", __func__);
}
printf("Cap data 0x%x, 0x%x, 0x%x \n", cap_data->effective, cap_data->permitted, cap_data->inheritable);
}
/**
* @tc.name : capget_0200
* @tc.desc : Validation could not obtain process permissions (parameter a is invalid)
* @tc.desc : Verify that this function could not obtain process permissions when parameter is invalid
* @tc.level : Level 2
*/
void capget_0200(void)
{
struct __user_cap_data_struct cap_data_data;
cap_user_data_t cap_data = &cap_data_data;
int result;
result = capget(NULL, cap_data);
EXPECT_EQ("capget_0200", result, COUNT_NEGATIVE);
}
/**
* @tc.name : capget_0300
* @tc.desc : Verify that the process permission can be obtained
* @tc.level : Level 1
*/
void capget_0300(void)
{
struct __user_cap_header_struct cap_header_data;
cap_user_header_t cap_header = &cap_header_data;
cap_header->pid = getpid();
cap_header->version = _LINUX_CAPABILITY_VERSION_1;
struct __user_cap_data_struct cap_data_data;
cap_user_data_t cap_data = NULL;
int result;
result = capget(cap_header, NULL);
EXPECT_EQ("capget_0300", result, COUNT_ZERO);
int result = capget(NULL, cap_data);
if (result != -1) {
t_error("%s capget should be failed\n", __func__);
}
}
int main(int argc, char *argv[])
{
capget_0100();
capget_0200();
capget_0300();
return t_status;
}
\ No newline at end of file
......@@ -13,73 +13,46 @@
* limitations under the License.
*/
#include <unistd.h>
#include <stdio.h>
#include <netinet/in.h>
#include <sys/capability.h>
#include <sys/socket.h>
#include "functionalext.h"
#undef _POSIX_SOURCE
const int32_t COUNT_ZERO = 0;
const int32_t COUNT_NEGATIVE = -1;
#include "test.h"
/**
* @tc.name : capset_0100
* @tc.desc : Verify that process permissions can be set (parameter valid)
* @tc.desc : Set capabilities of thread
* @tc.level : Level 0
*/
void capset_0100(void)
{
struct __user_cap_header_struct cap_header_data;
cap_user_header_t cap_header = &cap_header_data;
struct __user_cap_data_struct cap_data_data;
cap_user_data_t cap_data = &cap_data_data;
int result;
cap_header->pid = getpid();
cap_header->version = _LINUX_CAPABILITY_VERSION_1;
result = capset(cap_header, cap_data);
#ifdef __POSIX_SOURCE
EXPECT_EQ("capset_0100", result, COUNT_ZERO);
#endif
}
struct __user_cap_header_struct cap_header;
struct __user_cap_data_struct cap_data;
/**
* @tc.name : capset_0200
* @tc.desc : Validation cannot set process permissions (a parameter is invalid)
* @tc.level : Level 2
*/
void capset_0200(void)
{
struct __user_cap_data_struct cap_data_data;
cap_user_data_t cap_data = &cap_data_data;
int result;
result = capset(NULL, cap_data);
EXPECT_EQ("capset_0200", result, COUNT_NEGATIVE);
}
cap_header.pid = getpid();
cap_header.version = _LINUX_CAPABILITY_VERSION_1;
/**
* @tc.name : capset_0300
* @tc.desc : Validation cannot set process permissions (b parameter invalid)
* @tc.level : Level 2
*/
void capset_0300(void)
{
struct __user_cap_header_struct cap_header_data;
cap_user_header_t cap_header = &cap_header_data;
cap_header->pid = getpid();
cap_header->version = _LINUX_CAPABILITY_VERSION_1;
struct __user_cap_data_struct cap_data_data;
cap_user_data_t cap_data = NULL;
int result;
result = capset(cap_header, NULL);
EXPECT_EQ("capset_0300", result, COUNT_NEGATIVE);
if (capget(&cap_header, &cap_data) < 0) {
t_error("%s capget failed\n", __func__);
}
printf("capheader: %x %d\n", cap_header.version, cap_header.pid);
printf("capdata: %x %x %x\n", cap_data.effective, cap_data.permitted, cap_data.inheritable);
__u32 cap_mask = 0;
cap_mask |= (1 << CAP_NET_BIND_SERVICE);
cap_data.effective = cap_mask;
cap_data.permitted = cap_mask;
cap_data.inheritable = 0;
if (capset(&cap_header, &cap_data) < 0) {
t_error("%s capset failed\n", __func__);
}
printf("%d\n", capget(&cap_header, &cap_data));
printf("capheader: %x %d\n", cap_header.version, cap_header.pid);
printf("capdata: %x %x %x\n", cap_data.effective, cap_data.permitted, cap_data.inheritable);
}
int main(int argc, char *argv[])
{
capset_0100();
capset_0200();
capset_0300();
return t_status;
}
\ No newline at end of file
......@@ -13,6 +13,7 @@
* limitations under the License.
*/
#include <errno.h>
#include <unistd.h>
#include "functionalext.h"
......@@ -23,53 +24,26 @@
*/
void chroot_0100(void)
{
char *ftpr = "/";
int result = chroot(ftpr);
int result = chroot("/data");
EXPECT_EQ("chroot_0100", result, 0);
}
/*
* @tc.name : chroot_0200
* @tc.desc : Verify that the file root directory cannot be changed (parameter is NULL)
* @tc.desc : Verify that the file root directory cannot be changed (The file does not exist)
* @tc.level : Level 2
*/
void chroot_0200(void)
{
char *ftpr = "data/app";
int result = chroot(NULL);
EXPECT_EQ("chroot_0100", result, -1);
}
/*
* @tc.name : chroot_0300
* @tc.desc : Verify that the file root directory cannot be changed (parameter exceeds maximum length)
* @tc.level : Level 2
*/
void chroot_0300(void)
{
char *ftpr = "data/app/el1/bundle/public/com.example.disributedcalc/com.example.disributedcalc/assets/js";
int result = chroot(ftpr);
EXPECT_EQ("chroot_0100", result, -1);
}
/*
* @tc.name : chroot_0400
* @tc.desc : Verify that the file root directory cannot be changed (parameter invalid)
* @tc.level : Level 2
*/
void chroot_0400(void)
{
char *ftpr = "system/app";
int result = chroot(ftpr);
EXPECT_EQ("chroot_0100", result, -1);
errno = 0;
int result = chroot("/sub");
EXPECT_EQ("chroot_0200", result, -1);
EXPECT_EQ("chroot_0200", errno, ENOENT);
}
int main(int argc, char *argv[])
{
chroot_0100();
chroot_0200();
chroot_0300();
chroot_0400();
return t_status;
}
\ No newline at end of file
......@@ -13,15 +13,17 @@
* limitations under the License.
*/
#include <stdio.h>
#include <errno.h>
#include <signal.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/timex.h>
#include <stdbool.h>
#include <time.h>
#include "functionalext.h"
const int32_t COUNT_NEGATIVE = -1;
void exception_handler(int sig)
{
exit(t_status);
}
/**
* @tc.name : clock_adjtime_0100
......@@ -30,14 +32,11 @@ const int32_t COUNT_NEGATIVE = -1;
*/
void clock_adjtime_0100(void)
{
bool flag = false;
struct timex tx = {0};
int result = -1;
result = clock_adjtime(CLOCK_REALTIME, &tx);
if (result != -1) {
flag = true;
}
EXPECT_TRUE("clock_adjtime_0100", flag);
struct timex tx;
memset(&tx, 0, sizeof(tx));
int result = clock_adjtime(CLOCK_REALTIME, &tx);
EXPECT_NE("clock_adjtime_0100", result, -1);
}
/**
......@@ -49,9 +48,9 @@ void clock_adjtime_0100(void)
void clock_adjtime_0200(void)
{
struct timex tx = {ADJ_OFFSET_SS_READ};
int result = -1;
result = clock_adjtime(CLOCK_MONOTONIC, &tx);
EXPECT_EQ("clock_adjtime_0200", result, COUNT_NEGATIVE);
int result = clock_adjtime(CLOCK_MONOTONIC, &tx);
EXPECT_EQ("clock_adjtime_0200", result, -1);
}
/**
......@@ -62,10 +61,11 @@ void clock_adjtime_0200(void)
*/
void clock_adjtime_0300(void)
{
struct timex tx = {0};
int result = -1;
result = clock_adjtime(CLOCK_PROCESS_CPUTIME_ID, &tx);
EXPECT_EQ("clock_adjtime_0300", result, COUNT_NEGATIVE);
struct timex tx;
memset(&tx, 0, sizeof(tx));
int result = clock_adjtime(CLOCK_PROCESS_CPUTIME_ID, &tx);
EXPECT_EQ("clock_adjtime_0300", result, -1);
}
/**
......@@ -77,9 +77,10 @@ void clock_adjtime_0300(void)
void clock_adjtime_0400(void)
{
struct timex tx = {0};
int result = -1;
result = clock_adjtime(CLOCK_THREAD_CPUTIME_ID, &tx);
EXPECT_EQ("clock_adjtime_0400", result, COUNT_NEGATIVE);
memset(&tx, 0, sizeof(tx));
int result = clock_adjtime(CLOCK_THREAD_CPUTIME_ID, &tx);
EXPECT_EQ("clock_adjtime_0400", result, -1);
}
/**
......@@ -89,10 +90,12 @@ void clock_adjtime_0400(void)
*/
void clock_adjtime_0500(void)
{
struct timex tx = {100000};
int result = 0;
result = clock_adjtime(CLOCK_REALTIME, &tx);
EXPECT_EQ("clock_adjtime_0500", result, COUNT_NEGATIVE);
signal(SIGSEGV, exception_handler);
errno = 0;
int result = clock_adjtime(CLOCK_REALTIME, NULL);
EXPECT_EQ("clock_adjtime_0500", result, -1);
EXPECT_EQ("clock_adjtime_0500", errno, EFAULT);
}
int main(int argc, char *argv[])
......
......@@ -13,11 +13,9 @@
* limitations under the License.
*/
#include <sys/syscall.h>
#include <signal.h>
#include <malloc.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include "functionalext.h"
......
/**
/*
* 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.
......@@ -13,41 +13,42 @@
* limitations under the License.
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include "functionalext.h"
// Solve the build error of this test code when importing the header file <sys/epoll.h>
#ifndef _EPOLL_CREATE_TEST
#define _EPOLL_CREATE_TEST
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#undef _GNU_SOURCE
#undef _BSD_SOURCE
#endif
#endif
typedef void (*TEST_FUN)();
int __cxa_atexit(void (*func)(void *), void *arg, void *dso);
int __aeabi_atexit(void *obj, void (*func)(void *), void *d)
{
return __cxa_atexit(func, obj, d);
}
const int32_t COUNT_ZERO = 0;
#include <errno.h>
#include <sys/epoll.h>
#include "test.h"
/*
* @tc.name : aeabi_atexit_0100
* @tc.desc : Verify that __aeabi_atexit is called correctly (all arguments are valid)
/**
* @tc.name : epoll_create_0100
* @tc.desc : Returns a file descriptor referring to the new epoll instance
* @tc.level : Level 0
*/
void aeabi_atexit_0100()
void epoll_create_0100(void)
{
int result;
result = __aeabi_atexit(NULL, NULL, NULL);
EXPECT_EQ("aeabi_atexit_0100", result, COUNT_ZERO);
errno = 0;
int epoll_fd = epoll_create(1);
if (epoll_fd == -1) {
t_error("%s epoll_create failed\n", __func__);
}
if (errno != 0) {
t_error("%s errno is %d, not 0\n", __func__, errno);
}
}
TEST_FUN G_Fun_Array[] = {
aeabi_atexit_0100,
};
int main(int argc, char *argv[])
{
int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
for (int pos = 0; pos < num; ++pos) {
G_Fun_Array[pos]();
}
epoll_create_0100();
return t_status;
}
\ No newline at end of file
}
#ifdef _EPOLL_CREATE_TEST
#undef _EPOLL_CREATE_TEST
#endif
\ No newline at end of file
......@@ -13,51 +13,57 @@
* limitations under the License.
*/
#include <sys/stat.h>
// Solve the build error of this test code when importing the header file <sys/epoll.h>
#ifndef _EPOLL_CREATE1_TEST
#define _EPOLL_CREATE1_TEST
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#undef _GNU_SOURCE
#undef _BSD_SOURCE
#endif
#endif
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include "functionalext.h"
#include <sys/epoll.h>
#include "test.h"
#define LINE_SIZE 100
void close_on_exec(int fd, bool close_on_exec)
{
int flags = fcntl(fd, F_GETFD);
if (flags == -1) {
t_error("%s fcntl failed\n", __func__);
}
if ((close_on_exec ? FD_CLOEXEC : 0) != (flags & FD_CLOEXEC)) {
t_error("%s failed, expect equal\n", __func__);
}
}
/**
* @tc.name : open_by_handle_at_0100
* @tc.desc : Verify that the open_by_handle_at function was successfully called (all parameters are valid)
* @tc.name : epoll_create1_0100
* @tc.desc : Returns a file descriptor referring to the new epoll instance
* @tc.level : Level 0
*/
void open_by_handle_at_0100(void)
void epoll_create1_0100(void)
{
int result;
struct file_handle *fhp;
int mount_id, fhsize, flags, dirfd;
char *pathname;
pathname = "/data";
fhsize = sizeof(*fhp);
fhp = malloc(fhsize);
dirfd = AT_FDCWD;
flags = 0;
fhp->handle_bytes = 0;
name_to_handle_at(dirfd, pathname, fhp, &mount_id, flags);
fhsize = sizeof(struct file_handle) + fhp->handle_bytes;
fhp = realloc(fhp, fhsize);
name_to_handle_at(dirfd, pathname, fhp, &mount_id, flags);
result = open_by_handle_at(AT_FDCWD, fhp, O_NOFOLLOW);
bool flag = false;
if (result > 0) {
flag = true;
}
EXPECT_TRUE("open_by_handle_at_0100", flag);
errno = 0;
int fd;
fd = epoll_create1(0);
close_on_exec(fd, false);
close(fd);
fd = epoll_create1(EPOLL_CLOEXEC);
close_on_exec(fd, true);
close(fd);
}
int main(int argc, char *argv[])
{
// open_by_handle_at_0100();
epoll_create1_0100();
return t_status;
}
#ifdef _EPOLL_CREATE1_TEST
#undef _EPOLL_CREATE1_TEST
#endif
\ No newline at end of file
/*
* 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.
*/
// Solve the build error of this test code when importing the header file <sys/epoll.h>
#ifndef _EPOLL_CTL_TEST
#define _EPOLL_CTL_TEST
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#undef _GNU_SOURCE
#undef _BSD_SOURCE
#endif
#endif
#include <errno.h>
#include <sys/epoll.h>
#include "test.h"
/**
* @tc.name : epoll_ctl_0100
* @tc.desc : Add entries in the interest list of the epoll instance referred to by the file descriptor.
* @tc.level : Level 0
*/
void epoll_ctl_0100(void)
{
errno = 0;
int fds[2];
const uint64_t expected = 0x123456789abcdef0;
int fd = epoll_create(1);
if (fd == -1) {
t_error("%s epoll_create failed\n", __func__);
}
if (errno != 0) {
t_error("%s errno is %d\n", __func__, errno);
}
int ret = pipe(fds);
if (ret == -1) {
t_error("%s pipe failed\n", __func__);
}
struct epoll_event ev;
ev.events = EPOLLIN;
ev.data.u64 = expected;
int result = epoll_ctl(fd, EPOLL_CTL_ADD, fds[0], &ev);
if (result == -1) {
t_error("%s epoll_ctl failed\n", __func__);
}
ret = write(fds[1], "\n", 1);
if (ret != 1) {
t_error("%s nothing in pipe\n", __func__);
}
struct epoll_event events[1];
result = epoll_wait(fd, events, 1, 1);
if (events[0].data.u64 != expected) {
t_error("%s events[0].data.u64 is not right\n", __func__);
}
close(fds[0]);
close(fds[1]);
}
int main(int argc, char *argv[])
{
epoll_ctl_0100();
return t_status;
}
#ifdef _EPOLL_CTL_TEST
#undef _EPOLL_CTL_TEST
#endif
\ No newline at end of file
/*
* 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.
*/
// Solve the build error of this test code when importing the header file <sys/epoll.h>
#ifndef _EPOLL_PWAIT_TEST
#define _EPOLL_PWAIT_TEST
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#undef _GNU_SOURCE
#undef _BSD_SOURCE
#endif
#endif
#include <errno.h>
#include <signal.h>
#include <sys/epoll.h>
#include "test.h"
/**
* @tc.name : epoll_pwait_0100
* @tc.desc : epoll_pwait without a sigset
* @tc.level : Level 0
*/
void epoll_pwait_0100(void)
{
int epoll_fd = epoll_create(1);
if (epoll_fd == -1) {
t_error("%s epoll_create failed\n", __func__);
}
struct epoll_event events[1];
int result = epoll_pwait(epoll_fd, events, 1, 1, NULL);
if (result != 0) {
t_error("%s epoll_pwait failed\n", __func__);
}
}
/**
* @tc.name : epoll_pwait_0200
* @tc.desc : epoll_pwait with a sigset
* @tc.level : Level 0
*/
void epoll_pwait_0200(void)
{
int epoll_fd = epoll_create(1);
if (epoll_fd == -1) {
t_error("%s epoll_create failed\n", __func__);
}
struct epoll_event events[1];
sigset_t ss;
sigemptyset(&ss);
sigaddset(&ss, SIGPIPE);
int result = epoll_pwait(epoll_fd, events, 1, 1, &ss);
if (result != 0) {
t_error("%s epoll_pwait failed\n", __func__);
}
}
int main(int argc, char *argv[])
{
epoll_pwait_0100();
epoll_pwait_0200();
return t_status;
}
#ifdef _EPOLL_PWAIT_TEST
#undef _EPOLL_PWAIT_TEST
#endif
\ No newline at end of file
......@@ -4,7 +4,7 @@
* 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
* 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,
......@@ -13,31 +13,44 @@
* limitations under the License.
*/
#include <stdio.h>
#include <stdio_ext.h>
#include <stdlib.h>
#include <stdint.h>
#include "functionalext.h"
// Solve the build error of this test code when importing the header file <sys/epoll.h>
#ifndef _EPOLL_WAIT_TEST
#define _EPOLL_WAIT_TEST
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#undef _GNU_SOURCE
#undef _BSD_SOURCE
#endif
#endif
const int32_t COUNT_ZERO = 0;
#include <errno.h>
#include <sys/epoll.h>
#include "test.h"
/**
* @tc.name : __fsetlocking_0100
* @tc.desc : Function is not implemented, always return 0
* @tc.name : epoll_wait_0100
* @tc.desc : Regular epoll_wait
* @tc.level : Level 0
*/
void __fsetlocking_0100(void)
void epoll_wait_0100(void)
{
FILE *fptr = fopen("test.txt", "w+");
int result;
result = __fsetlocking(fptr, FSETLOCKING_INTERNAL);
EXPECT_EQ("__fsetlocking_0100", result, COUNT_ZERO);
fclose(fptr);
remove("test.txt");
int epoll_fd = epoll_create(1);
if (epoll_fd == -1) {
t_error("%s epoll_create failed\n", __func__);
}
struct epoll_event events[1];
int result = epoll_wait(epoll_fd, events, 1, 1);
if (result != 0) {
t_error("%s epoll_pwait failed\n", __func__);
}
}
int main(int argc, char *argv[])
{
__fsetlocking_0100();
epoll_wait_0100();
return t_status;
}
\ No newline at end of file
}
#ifdef _EPOLL_WAIT_TEST
#undef _EPOLL_WAIT_TEST
#endif
\ No newline at end of file
......@@ -14,36 +14,25 @@
*/
#include <fcntl.h>
#include <linux/types.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <unistd.h>
#include "functionalext.h"
const int SUCCESS = 0;
const int FAILED = -1;
/**
* @tc.name : flock_0100
* @tc.desc : Each parameter is valid, the op parameter is LOCK_SH, which can lock the file
* @tc.level : Level 0
*/
void flock_0100()
void flock_0100(void)
{
int fd = -1;
int result = -1;
fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666);
int fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666);
EXPECT_NE("flock_0100", fd, -1);
lseek(fd, 2, SEEK_SET);
if (fd < 0) {
t_error("%s open failed\n", __func__);
}
result = flock(fd, LOCK_SH);
EXPECT_EQ("flock_0100", result, SUCCESS);
EXPECT_EQ("flock_0100", result, 0);
close(fd);
system("rm -rf /data/test.txt");
remove("/data/test.txt");
}
/**
......@@ -51,19 +40,17 @@ void flock_0100()
* @tc.desc : Each parameter is valid, the op parameter is LOCK_SH|LOCK_NB, which can lock the file
* @tc.level : Level 1
*/
void flock_0200()
void flock_0200(void)
{
int fd = -1;
int result = -1;
fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666);
int fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666);
EXPECT_NE("flock_0200", fd, -1);
lseek(fd, 2, SEEK_SET);
if (fd < 0) {
t_error("%s open failed\n", __func__);
}
result = flock(fd, LOCK_SH | LOCK_NB);
EXPECT_EQ("flock_0200", result, SUCCESS);
EXPECT_EQ("flock_0200", result, 0);
close(fd);
system("rm -rf /data/test.txt");
remove("/data/test.txt");
}
/**
......@@ -71,19 +58,17 @@ void flock_0200()
* @tc.desc : Each parameter is valid, the op parameter is LOCK_EX, which can lock the file
* @tc.level : Level 0
*/
void flock_0300()
void flock_0300(void)
{
int fd = -1;
int result = -1;
fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666);
int fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666);
EXPECT_NE("flock_0300", fd, -1);
lseek(fd, 2, SEEK_SET);
if (fd < 0) {
t_error("%s open failed\n", __func__);
}
result = flock(fd, LOCK_EX);
EXPECT_EQ("flock_0300", result, SUCCESS);
EXPECT_EQ("flock_0300", result, 0);
close(fd);
system("rm -rf /data/test.txt");
remove("/data/test.txt");
}
/**
......@@ -91,19 +76,17 @@ void flock_0300()
* @tc.desc : Each parameter is valid, the op parameter is LOCK_EX|LOCK_NB, which can lock the file
* @tc.level : Level 1
*/
void flock_0400()
void flock_0400(void)
{
int fd = -1;
int result = -1;
fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666);
int fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666);
EXPECT_NE("flock_0400", fd, -1);
lseek(fd, 2, SEEK_SET);
if (fd < 0) {
t_error("%s open failed\n", __func__);
}
result = flock(fd, LOCK_EX | LOCK_NB);
EXPECT_EQ("flock_0400", result, SUCCESS);
EXPECT_EQ("flock_0400", result, 0);
close(fd);
system("rm -rf /data/test.txt");
remove("/data/test.txt");
}
/**
......@@ -111,19 +94,17 @@ void flock_0400()
* @tc.desc : Each parameter is valid, the op parameter is LOCK_UN, which can release the file lock state
* @tc.level : Level 0
*/
void flock_0500()
void flock_0500(void)
{
int fd = -1;
int result = -1;
fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666);
int fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666);
EXPECT_NE("flock_0500", fd, -1);
lseek(fd, 2, SEEK_SET);
if (fd < 0) {
t_error("%s open failed\n", __func__);
}
result = flock(fd, LOCK_UN);
EXPECT_EQ("flock_0500", result, SUCCESS);
EXPECT_EQ("flock_0500", result, 0);
close(fd);
system("rm -rf /data/test.txt");
remove("/data/test.txt");
}
/**
......@@ -131,13 +112,10 @@ void flock_0500()
* @tc.desc : The fd parameter is invalid, the file cannot be locked
* @tc.level : Level 2
*/
void flock_0600()
void flock_0600(void)
{
int fd = -1;
int result = 0;
result = flock(fd, LOCK_EX);
EXPECT_EQ("flock_0600", result, FAILED);
close(fd);
int result = flock(-1, LOCK_EX);
EXPECT_EQ("flock_0600", result, -1);
}
/**
......@@ -147,17 +125,15 @@ void flock_0600()
*/
void flock_0700()
{
int fd = -1;
int result = 0;
fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666);
int fd = open("/data/test.txt", O_RDWR | O_CREAT, 0666);
EXPECT_NE("flock_0700", fd, -1);
lseek(fd, 2, SEEK_SET);
if (fd < 0) {
t_error("%s open failed\n", __func__);
}
result = flock(fd, 0);
EXPECT_EQ("flock_0700", result, FAILED);
EXPECT_EQ("flock_0700", result, -1);
close(fd);
system("rm -rf /data/test.txt");
remove("/data/test.txt");
}
int main(int argc, char *argv[])
......
......@@ -14,13 +14,10 @@
*/
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/xattr.h>
#include <unistd.h>
#include "functionalext.h"
const int32_t COUNT_ZERO = 0;
const char *path = "/data/test.txt";
/**
* @tc.name : fremovexattr_0100
......@@ -29,15 +26,27 @@ const int32_t COUNT_ZERO = 0;
*/
void fremovexattr_0100(void)
{
int fd = open("/data/test.txt", O_CREAT | O_WRONLY, 0667);
char name[] = "user.x";
char value[] = "the past is not dead.";
int result;
fsetxattr(fd, name, value, strlen(value), 0);
result = fremovexattr(fd, name);
EXPECT_EQ("fremovexattr_0100", result, COUNT_ZERO);
char buf[10];
int fd = open(path, O_CREAT | O_WRONLY, 0667);
EXPECT_NE("fremovexattr_0100", fd, -1);
int result = fsetxattr(fd, "user.foo", "bar", 4, 0);
EXPECT_EQ("fremovexattr_0100", result, 0);
result = fgetxattr(fd, "user.foo", buf, sizeof(buf));
EXPECT_EQ("fremovexattr_0100", result, 4);
EXPECT_STREQ("fremovexattr_0100", buf, "bar");
result = fremovexattr(fd, "user.foo");
EXPECT_EQ("fremovexattr_0100", result, 0);
memset(buf, 0, sizeof(buf));
result = fgetxattr(fd, "user.foo", buf, sizeof(buf));
EXPECT_EQ("fremovexattr_0100", result, -1);
close(fd);
remove("/data/test.txt");
remove(path);
}
int main(int argc, char *argv[])
......
......@@ -14,29 +14,33 @@
*/
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/xattr.h>
#include <unistd.h>
#include "functionalext.h"
const int32_t COUNT_ZERO = 0;
const char *path = "/data/test.txt";
/**
* @tc.name : fsetxattr_0100
* @tc.desc : Verify that you can set the extended properties of the specified file (all parameters are valid)
* @tc.desc : Sets the value of the extended attribute identified by name and associated with the given path in the
* filesystem
* @tc.level : Level 0
*/
void fsetxattr_0100(void)
{
int fd = open("/data/test.txt", O_CREAT | O_WRONLY, 0667);
char name[] = "user.x";
char value[] = "the past is not dead.";
int result;
result = fsetxattr(fd, name, value, strlen(value), 0);
EXPECT_EQ("fsetxattr_0100", result, COUNT_ZERO);
char buf[10];
int fd = open(path, O_CREAT | O_WRONLY, 0667);
EXPECT_NE("fsetxattr_0100", fd, -1);
int result = fsetxattr(fd, "user.foo", "bar", 4, 0);
EXPECT_EQ("fsetxattr_0100", result, 0);
result = fgetxattr(fd, "user.foo", buf, sizeof(buf));
EXPECT_EQ("fsetxattr_0100", result, 4);
EXPECT_STREQ("fsetxattr_0100", buf, "bar");
close(fd);
remove("/data/test.txt");
remove(path);
}
int main(int argc, char *argv[])
......
......@@ -14,11 +14,8 @@
*/
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "functionalext.h"
......@@ -32,14 +29,10 @@ const int FAILED = -1;
*/
void getdents_0100(void)
{
int fd = -1;
int result = -1;
struct dirent buf;
fd = open("/data/data", O_RDONLY);
if (fd < 0) {
printf("open failed!\n");
}
result = getdents(fd, &buf, INT_MAX);
int fd = open("/data/data", O_RDONLY);
EXPECT_NE("getdents_0100", fd, -1);
int result = getdents(fd, &buf, INT_MAX);
EXPECT_TRUE("getdents_0100", result > 0);
}
......@@ -50,11 +43,9 @@ void getdents_0100(void)
*/
void getdents_0200(void)
{
int fd = 0;
int result = 0;
struct dirent buf;
fd = open("/getdents", O_RDONLY);
result = getdents(fd, &buf, INT_MAX);
int fd = open("/getdents", O_RDONLY);
int result = getdents(fd, &buf, INT_MAX);
EXPECT_EQ("getdents_0200", result, FAILED);
}
......@@ -65,14 +56,10 @@ void getdents_0200(void)
*/
void getdents_0300(void)
{
int fd = 0;
int result = 0;
struct dirent buf;
fd = open("/data/data", O_RDONLY);
if (fd < 0) {
printf("open failed!\n");
}
result = getdents(fd, NULL, INT_MAX);
int fd = open("/data/data", O_RDONLY);
EXPECT_NE("getdents_0300", fd, -1);
int result = getdents(fd, NULL, INT_MAX);
EXPECT_EQ("getdents_0300", result, FAILED);
}
......
......@@ -13,16 +13,9 @@
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <linux/membarrier.h>
#include <sys/membarrier.h>
#include "functionalext.h"
const int32_t COUNT_ZERO = 0;
const int32_t COUNT_NEGATIVE = -1;
int membarrier(int, int);
/**
* @tc.name : membarrier_0100
* @tc.desc : Verify memory masking
......@@ -31,9 +24,8 @@ int membarrier(int, int);
*/
void membarrier_0100(void)
{
int result;
result = membarrier(MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED, 0);
EXPECT_EQ("membarrier_0100", result, COUNT_ZERO);
int result = membarrier(MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED, 0);
EXPECT_EQ("membarrier_0100", result, 0);
}
/**
......@@ -43,9 +35,8 @@ void membarrier_0100(void)
*/
void membarrier_0200(void)
{
int result;
result = membarrier(MEMBARRIER_CMD_PRIVATE_EXPEDITED, 0);
EXPECT_EQ("membarrier_0200", result, COUNT_ZERO);
int result = membarrier(MEMBARRIER_CMD_PRIVATE_EXPEDITED, 0);
EXPECT_EQ("membarrier_0200", result, 0);
}
/**
......@@ -55,9 +46,8 @@ void membarrier_0200(void)
*/
void membarrier_0300(void)
{
int result;
result = membarrier(-1, 0);
EXPECT_EQ("membarrier_0300", result, COUNT_NEGATIVE);
int result = membarrier(-1, 0);
EXPECT_EQ("membarrier_0300", result, -1);
}
int main(int argc, char *argv[])
......
......@@ -12,18 +12,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <sys/stat.h>
// #define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <malloc.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include "functionalext.h"
#include "test.h"
const int32_t COUNT_ZERO = 0;
const char *pathname = "/proc/self/mountinfo";
/**
* @tc.name : name_to_handle_at_0100
......@@ -32,21 +28,44 @@ const int32_t COUNT_ZERO = 0;
*/
void name_to_handle_at_0100(void)
{
int result;
struct file_handle *fhp;
char buf[1000];
int mount_id, fhsize, flags, dirfd;
char *pathname;
pathname = "/data";
fhsize = sizeof(*fhp);
fhp = malloc(fhsize);
if (fhp == NULL) {
t_error("%s malloc failed\n", __func__);
}
dirfd = AT_FDCWD;
flags = 0;
fhp->handle_bytes = 0;
name_to_handle_at(dirfd, pathname, fhp, &mount_id, flags);
fhsize = sizeof(struct file_handle) + fhp->handle_bytes;
if (name_to_handle_at(dirfd, pathname, fhp, &mount_id, flags) != -1 || errno != EOVERFLOW) {
t_error("%s Unexpected name_to_handle_at\n", __func__);
}
fhsize = sizeof(*fhp) + fhp->handle_bytes;
fhp = realloc(fhp, fhsize);
result = name_to_handle_at(dirfd, pathname, fhp, &mount_id, flags);
EXPECT_EQ("name_to_handle_at_0100", result, COUNT_ZERO);
if (fhp == NULL) {
t_error("%s realloc failed\n", __func__);
}
int result = name_to_handle_at(dirfd, pathname, fhp, &mount_id, flags);
if (result == -1) {
t_error("%s name_to_handle_at failed\n");
}
int fd = open_by_handle_at(mount_id, fhp, O_RDONLY);
if (fd == -1) {
t_error("%s open_by_handle_at failed\n", __func__);
}
int nread = read(fd, buf, sizeof(buf));
if (nread == -1) {
t_error("%s read failed\n", __func__);
}
}
int main(int argc, char *argv[])
......
......@@ -71,7 +71,6 @@ functionalext_supplement_linux_test = [
"syncfs",
"copy_file_range",
"name_to_handle_at",
"open_by_handle_at",
"remap_file_pages",
"inotify",
"mlock2",
......@@ -80,4 +79,9 @@ functionalext_supplement_linux_test = [
"quotactl",
"chroot",
"fanotify_init",
"epoll_create",
"epoll_create1",
"epoll_ctl",
"epoll_pwait",
"epoll_wait",
]
......@@ -13,57 +13,38 @@
* limitations under the License.
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <sys/sysinfo.h>
#include <malloc.h>
#include <unistd.h>
#include "functionalext.h"
/**
* @tc.name : memalign_0100
* @tc.desc : Each parameter is valid, and align is obtained by getpagesize(),
* which can allocate a memory block whose size is specified
* by len and whose address is a multiple of align.
* @tc.desc : Each parameter is valid, and align is obtained by getpagesize(), which can allocate a memory block
* whose size is specified by len and whose address is a multiple of align.
* @tc.level : Level 0
*/
void memalign_0100(void)
{
int align = getpagesize();
void *buff = NULL;
if (align == -1) {
printf("getpagesize error!\n");
}
buff = (void *)memalign(align, 8 * align);
bool flag = false;
if (buff != NULL) {
flag = true;
}
EXPECT_TRUE("memalign_0100", flag);
EXPECT_NE("memalign_0100", align, -1);
void *buff = (void *)memalign(align, 8 * align);
EXPECT_TRUE("memalign_0100", buff != NULL);
free(buff);
buff = NULL;
}
/**
* @tc.name : memalign_0200
* @tc.desc : Each parameter is valid, and it can allocate a memory block
* with the size specified by len and the address is a multiple of align
* @tc.desc : Each parameter is valid, and it can allocate a memory block with the size specified by
* len and the address is a multiple of align
* @tc.level : Level 1
*/
void memalign_0200(void)
{
int align = 16;
void *buff = NULL;
if (align == -1) {
printf("getpagesize error!\n");
}
buff = (void *)memalign(align, 8 * align);
bool flag = false;
if (buff != NULL) {
flag = true;
}
EXPECT_TRUE("memalign_0200", flag);
EXPECT_TRUE("memalign_0200", buff != NULL);
free(buff);
buff = NULL;
}
......@@ -77,11 +58,8 @@ void memalign_0200(void)
void memalign_0300(void)
{
int align = getpagesize() - 1;
void *buff = NULL;
if (align == -1) {
printf("getpagesize error!\n");
}
buff = (void *)memalign(align, 128);
EXPECT_NE("memalign_0300", align, -1);
void *buff = (void *)memalign(align, 128);
EXPECT_EQ("memalign_0300", buff, NULL);
free(buff);
buff = NULL;
......@@ -96,11 +74,8 @@ void memalign_0300(void)
void memalign_0400(void)
{
int align = getpagesize();
void *buff = NULL;
if (align == -1) {
printf("getpagesize error!\n");
}
buff = (void *)memalign(align, SIZE_MAX - align + 1);
EXPECT_NE("memalign_0400", align, -1);
void *buff = (void *)memalign(align, SIZE_MAX - align + 1);
EXPECT_EQ("memalign_0400", buff, NULL);
free(buff);
buff = NULL;
......@@ -115,11 +90,7 @@ void memalign_0400(void)
void memalign_0500(void)
{
int align = (4 * sizeof(size_t)) + 1;
void *buff = NULL;
if (align == -1) {
printf("getpagesize error!\n");
}
buff = (void *)memalign(align, align * 1024);
void *buff = (void *)memalign(align, align * 1024);
EXPECT_EQ("memalign_0500", buff, NULL);
free(buff);
buff = NULL;
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
#include <stdio.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <sys/socket.h>
......@@ -30,11 +29,11 @@ void gethostbyaddre_0100(void)
struct hostent *hptr = NULL;
struct in_addr addr;
if (inet_pton(AF_INET, ptr, &addr) <= 0) {
printf("inet_pton error:%s\n", strerror(errno));
t_error("%s inet_pton error:%s\n", __func__, strerror(errno));
}
hptr = gethostbyaddr((const char *)&addr, sizeof(addr), AF_INET);
if (hptr == NULL) {
printf("gethostbyaddr error:%s\n", strerror(h_errno));
t_error("%s gethostbyaddr error:%s\n", __func__, strerror(h_errno));
}
EXPECT_TRUE("gethostbyaddre_0100", hptr != NULL);
EXPECT_EQ("gethostbyaddre_0100", strcmp(hptr->h_name, ptr), 0);
......
/*
* 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.
*/
#include <arpa/nameser.h>
#include <netinet/in.h>
#include <resolv.h>
#include "functionalext.h"
typedef void (*TEST_FUN)();
/**
* @tc.name : res_querydomain_0100
* @tc.desc : Verify that the domain name can be queried (parameters are valid)
* @tc.level : Level 0
*/
void res_querydomain_0100(void)
{
int aslen = 1024;
unsigned char aswr[1024];
char name[] = "test";
char domain[] = "hello";
int result = res_querydomain(name, domain, 1, 1, aswr, aslen);
EXPECT_EQ("res_querydomain_0100", result, 0);
}
/**
* @tc.name : res_querydomain_0200
* @tc.desc : Verify that the domain name cannot be queried (the name parameter is invalid)
* @tc.level : Level 2
*/
void res_querydomain_0200(void)
{
int aslen = 1024;
unsigned char aswr[1024];
char name[254];
for (int i = 0; i < 254; i++) {
name[i] = 'a';
}
char domain[] = "hello";
int result = res_querydomain(name, domain, 1, 1, aswr, aslen);
EXPECT_EQ("res_querydomain_0200", result, -1);
}
/**
* @tc.name : res_querydomain_0300
* @tc.desc : Verify that the domain name cannot be queried (the domain parameter is invalid)
* @tc.level : Level 2
*/
void res_querydomain_0300(void)
{
int aslen = 1024;
unsigned char aswr[1024];
char domain[254];
for (int i = 0; i < 254; i++) {
domain[i] = 'a';
}
char name[] = "test";
int result = res_querydomain(name, domain, 1, 1, aswr, aslen);
EXPECT_EQ("res_querydomain_0300", result, -1);
}
/**
* @tc.name : res_querydomain_0400
* @tc.desc : Verify that the domain name cannot be queried (the name parameter and domain parameter are invalid)
* @tc.level : Level 2
*/
void res_querydomain_0400(void)
{
int aslen = 1024;
unsigned char aswr[1024];
char name[254];
char domain[254];
for (int i = 0; i < 127; i++) {
name[i] = 'a';
}
for (int j = 0; j < 127; j++) {
domain[j] = 'b';
}
int result = res_querydomain(name, domain, 1, 1, aswr, aslen);
EXPECT_EQ("res_querydomain_0400", result, -1);
}
TEST_FUN G_Fun_Array[] = {
res_querydomain_0100,
res_querydomain_0200,
res_querydomain_0300,
res_querydomain_0400,
};
int main(int argc, char *argv[])
{
int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
for (int pos = 0; pos < num; ++pos) {
G_Fun_Array[pos]();
}
return t_status;
}
\ No newline at end of file
......@@ -13,27 +13,37 @@
* limitations under the License.
*/
#include <stdio.h>
#include <stdbool.h>
#include <resolv.h>
#include "functionalext.h"
#include <stdio.h>
#include <string.h>
#include "test.h"
const int op = QUERY;
const int class = C_IN;
const int type = T_TXT;
const char dname[] = "www.example.com";
const unsigned char *data = (const unsigned char *)"";
const char qbuf[] = "\0\1\0\0\0\0\0\0";
const char qname[] = "\3www\7example\3com";
/**
* @tc.name : res_send_0100
* @tc.desc : Verify that the response can be sent (all parameters are valid)
* @tc.desc : Send a preformatted query given in msg of length msglen
* @tc.level : Level 0
*/
void res_send_0100(void)
{
bool flag = false;
int result;
unsigned char buf1[1024] = "127.0.0.1";
unsigned char buf2[1024] = "\0";
result = res_send(buf1, 0, buf2, 10);
if (result >= 0) {
flag = true;
unsigned char buf[BUFSIZ] = {0};
unsigned char answer[512];
int ret = res_mkquery(op, dname, class, type, data, 0, NULL, buf, sizeof(buf));
if (ret < 0) {
t_error("%s failed: ret = %d\n", __func__, ret);
}
int result = res_send(buf, ret, answer, sizeof(answer));
if (result == -1) {
t_error("%s res_send failed\n", __func__);
}
EXPECT_TRUE("res_send_0100", flag);
}
int main(int argc, char *argv[])
......
......@@ -13,13 +13,10 @@
functionalext_supplement_manual_network_test = [
"getnameinfo",
"getnetbyaddr",
"res_send",
"res_querydomain",
"gethostbyname2",
"gethostbyname_r",
"gethostbyaddr_r",
"gethostbyname2_r",
"gethostbyaddr",
"getnetbyname",
]
......@@ -16,5 +16,4 @@ functionalext_supplement_manual_test = [
"termios:functionalext_supplement_manual_termios_test",
"unistd:functionalext_supplement_manual_unistd_test",
"network:functionalext_supplement_manual_network_test",
"thread:functionalext_supplement_manual_thread_test",
]
# 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.
import("../../../../../test_template.gni")
import("test_src_functionalext_supplement_manual_thread.gni")
foreach(s, functionalext_supplement_manual_thread_test) {
test_unittest(s) {
target_dir = "functionalext/supplement/manual/thread"
}
}
group("functionalext_supplement_manual_thread_test") {
testonly = true
deps = []
foreach(s, functionalext_supplement_manual_thread_test) {
deps += [ ":${s}" ]
}
}
# 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.
functionalext_supplement_manual_thread_test = [ "cnd_broadcast" ]
......@@ -15,7 +15,6 @@
#include <float.h>
#include <math.h>
#include <stdio.h>
#include "functionalext.h"
/**
......
......@@ -15,7 +15,6 @@
#include <float.h>
#include <math.h>
#include <stdio.h>
#include "functionalext.h"
/**
......
......@@ -13,51 +13,42 @@
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "functionalext.h"
const int32_t COUNT_ZERO = 0;
const int32_t COUNT_ONE = 1;
/**
* @tc.name : signbitl_0100
* @tc.desc : the sign bit of the returned argument is 0 (The value of the argument of type long is 0)
* @tc.desc : The sign bit of the returned argument is 0 (The value of the argument of type long is 0)
* @tc.level : Level 0
*/
void signbitl_0100(void)
{
long double x = 0.0L;
int result;
result = __signbitl(x);
EXPECT_EQ("signbitl_0100", result, COUNT_ZERO);
int result = __signbitl(x);
EXPECT_EQ("signbitl_0100", result, 0);
}
/**
* @tc.name : signbitl_0200
* @tc.desc : the sign bit of the returned argument is 0 (The value of the argument of type long is positive)
* @tc.desc : The sign bit of the returned argument is 0 (The value of the argument of type long is positive)
* @tc.level : Level 0
*/
void signbitl_0200(void)
{
long double x = 3.14;
int result;
result = __signbitl(x);
EXPECT_EQ("signbitl_0200", result, COUNT_ZERO);
int result = __signbitl(x);
EXPECT_EQ("signbitl_0200", result, 0);
}
/**
* @tc.name : signbitl_0300
* @tc.desc : the sign bit of the returned parameter is 1 (The parameter value of type long is negative)
* @tc.desc : The sign bit of the returned parameter is 1 (The parameter value of type long is negative)
* @tc.level : Level 0
*/
void signbitl_0300(void)
{
long double x = -3.14;
int result;
result = __signbitl(x);
EXPECT_EQ("signbitl_0300", result, COUNT_ONE);
int result = __signbitl(x);
EXPECT_EQ("signbitl_0300", result, 1);
}
int main(int argc, char *argv[])
......
......@@ -14,26 +14,20 @@
*/
#include <mntent.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "functionalext.h"
const int32_t COUNT_ONE = 1;
/**
* @tc.name : endmntent_0100
* @tc.desc : Verify that the stream and its associated file system description file can be closed
* (parameter valid)
* @tc.level : Level 0
*/
void endmntent_0100(void)
{
struct mntent *m;
int result = 0;
FILE *fptr = fopen("/data/test.txt", "w+");
result = endmntent(fptr);
EXPECT_EQ("endmntent_0100", result, COUNT_ONE);
FILE *fp = fopen("/data/test.txt", "w+");
EXPECT_PTRNE("endmntent_0100", fp, NULL);
int result = endmntent(fp);
EXPECT_EQ("endmntent_0100", result, 1);
remove("/data/test.txt");
}
......
......@@ -13,12 +13,6 @@
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <syslog.h>
#include <stdint.h>
#include <unistd.h>
#include "functionalext.h"
/**
......@@ -29,8 +23,7 @@
*/
void ffsll_0100(void)
{
int result;
result = ffsll(0);
int result = ffsll(0);
EXPECT_EQ("ffsll_0100", result, 0);
}
......@@ -42,8 +35,7 @@ void ffsll_0100(void)
*/
void ffsll_0200(void)
{
int result;
result = ffsll(0x8000000);
int result = ffsll(0x8000000);
EXPECT_EQ("ffsll_0200", result, 28);
}
......@@ -55,8 +47,7 @@ void ffsll_0200(void)
*/
void ffsll_0300(void)
{
int result;
result = ffsll(0x800000000);
int result = ffsll(0x800000000);
EXPECT_EQ("ffsll_0300", result, 36);
}
......
......@@ -13,16 +13,12 @@
* limitations under the License.
*/
#include <errno.h>
#include <pty.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
#include "functionalext.h"
typedef void (*TEST_FUN)();
/**
* @tc.name : forkpty_0100
* @tc.desc : Each parameter is valid and can open a pair of pseudo-terminals for a new
......@@ -39,7 +35,7 @@ void forkpty_0100(void)
char list2[2];
FILE *fp;
if (pid < 0) {
printf("error in fork!");
t_error("%s error in fork!", __func__);
} else if (pid == 0) {
fp = fopen("test1.txt", "w+");
fwrite(sign_r, sizeof(char), strlen(sign_r), fp);
......@@ -62,16 +58,8 @@ void forkpty_0100(void)
remove("test2.txt");
}
TEST_FUN G_Fun_Array[] = {
forkpty_0100,
};
int main(int argc, char *argv[])
{
int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
for (int pos = 0; pos < num; ++pos) {
G_Fun_Array[pos]();
}
forkpty_0100();
return t_status;
}
\ No newline at end of file
......@@ -13,10 +13,8 @@
* limitations under the License.
*/
#include <errno.h>
#include <sys/auxv.h>
#include "functionalext.h"
int successsfly = 0;
/*
* @tc.name : getauxval_0100
......@@ -25,7 +23,7 @@ int successsfly = 0;
*/
void getauxval_0100(void)
{
long int result;
unsigned long int result;
result = getauxval(AT_SECURE);
EXPECT_EQ("getauxval_0100", result, 0);
}
......@@ -37,7 +35,7 @@ void getauxval_0100(void)
*/
void getauxval_0200(void)
{
long int result;
unsigned long int result;
result = getauxval(AT_SYSINFO);
EXPECT_EQ("getauxval_0200", result, 0);
}
......@@ -49,7 +47,7 @@ void getauxval_0200(void)
*/
void getauxval_0300(void)
{
long int result;
unsigned long int result;
result = getauxval(AT_SYSINFO_EHDR);
EXPECT_TRUE("getauxval_0300", result != 0);
}
......
......@@ -13,16 +13,10 @@
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <sys/utsname.h>
#include <unistd.h>
#include "functionalext.h"
const int32_t SUCCESS = 0;
const int32_t FAILED = -1;
/**
* @tc.name : getdomainname_0100
* @tc.desc : Verify domain name (valid)
......@@ -30,11 +24,14 @@ const int32_t FAILED = -1;
*/
void getdomainname_0100(void)
{
int result;
char name[1024] = "\0";
result = getdomainname(name, 1024);
EXPECT_EQ("getdomainname_0100", result, SUCCESS);
EXPECT_TRUE("getdomainname_0100", strcmp(name, "\0") != 0);
struct utsname u;
int ret = uname(&u);
EXPECT_EQ("getdomainname_0100", ret, 0);
char buf[sizeof(u.domainname)];
int result = getdomainname(buf, sizeof(buf));
EXPECT_EQ("getdomainname_0100", result, 0);
EXPECT_STREQ("getdomainname_0100", u.domainname, buf);
}
/**
......@@ -44,10 +41,13 @@ void getdomainname_0100(void)
*/
void getdomainname_0200(void)
{
int result;
char name[1024] = "\0";
result = getdomainname(name, 0);
EXPECT_EQ("getdomainname_0200", result, FAILED);
struct utsname u;
int ret = uname(&u);
EXPECT_EQ("getdomainname_0100", ret, 0);
char buf[sizeof(u.domainname)];
int result = getdomainname(buf, 0);
EXPECT_EQ("getdomainname_0200", result, -1);
}
/**
......@@ -57,10 +57,13 @@ void getdomainname_0200(void)
*/
void getdomainname_0300(void)
{
int result;
char name[1024] = "\0";
result = getdomainname(name, 1);
EXPECT_EQ("getdomainname_0300", result, FAILED);
struct utsname u;
int ret = uname(&u);
EXPECT_EQ("getdomainname_0100", ret, 0);
char buf[sizeof(u.domainname)];
int result = getdomainname(buf, 1);
EXPECT_EQ("getdomainname_0300", result, -1);
}
int main(int argc, char *argv[])
......
......@@ -14,14 +14,8 @@
*/
#include <unistd.h>
#include <sys/random.h>
#include <pthread.h>
#include <errno.h>
#include "functionalext.h"
const int SUCCESS = 0;
const int FAILED = -1;
/*
* @tc.name : getentropy_0100
* @tc.desc : Verify that secure random numbers can be generated
......@@ -31,7 +25,7 @@ void getentropy_0100(void)
{
void *buffer[256];
int result = getentropy(buffer, 256);
EXPECT_EQ("getentrcopy_0100", result, SUCCESS);
EXPECT_EQ("getentrcopy_0100", result, 0);
}
/*
......@@ -41,9 +35,10 @@ void getentropy_0100(void)
*/
void getentropy_0200(void)
{
void *buffer[256];
int result = getentropy(buffer, 257);
EXPECT_EQ("getentrcopy_0200", result, FAILED);
errno = 0;
int result = getentropy(NULL, 1);
EXPECT_EQ("getentrcopy_0200", result, -1);
EXPECT_EQ("getentrcopy_0200", errno, EFAULT);
}
int main(int argc, char *argv[])
......
......@@ -28,27 +28,18 @@ void getmntent_0100(void)
char str[100];
FILE *fptr = NULL;
if ((fptr = fopen("/proc/mounts", "r")) == NULL) {
printf("Error! opening file");
t_error("%s Error! fopen failed\n", __func__);
}
fscanf(fptr, "%[^\n]", c);
fclose(fptr);
sscanf(c, "%[^ ]", str);
struct mntent *m = NULL;
FILE *ffp = setmntent("/proc/mounts", "r");
if (!ffp) {
printf("error:%s\n", strerror(errno));
}
EXPECT_PTRNE("getmntent_0100", ffp, NULL);
m = getmntent(ffp);
bool flag = false;
if (m != NULL) {
flag = true;
}
EXPECT_TRUE("getmntent_0100", flag);
if (m != NULL) {
EXPECT_EQ("getmntent_0100", strcmp(m->mnt_fsname, str), 0);
} else {
printf("error\n");
}
EXPECT_TRUE("getmntent_0100", m != NULL);
EXPECT_EQ("getmntent_0100", strcmp(m->mnt_fsname, str), 0);
endmntent(ffp);
}
......@@ -62,13 +53,13 @@ void getmntent_0200(void)
char c[1000];
char *str = "This is a test";
FILE *fp = fopen("/data/getmntent.txt", "w");
EXPECT_PTRNE("getmntent_0200", fp, NULL);
fputs(str, fp);
fclose(fp);
struct mntent *m = NULL;
FILE *ffp = setmntent("/data/getmntent.txt", "r");
if (!ffp) {
printf("error:%s\n", strerror(errno));
}
EXPECT_PTRNE("getmntent_0200", ffp, NULL);
m = getmntent(ffp);
EXPECT_EQ("getmntent_0200", m, NULL);
endmntent(ffp);
......
......@@ -18,10 +18,9 @@
#include <stdbool.h>
#include "functionalext.h"
typedef void (*TEST_FUN)();
const int32_t SUCCESS = 0;
static pthread_barrier_t g_barrier;
#define WAIT() pthread_barrier_wait(&g_barrier)
void *getmntent_rOne()
{
char c[1000];
......@@ -29,7 +28,7 @@ void *getmntent_rOne()
FILE *fptr = NULL;
char strings[1024];
if ((fptr = fopen("/proc/mounts", "r")) == NULL) {
printf("Error! opening file");
t_error("%s Error! fopen failed\n", __func__);
}
fscanf(fptr, "%[^\n]", c);
fclose(fptr);
......@@ -39,17 +38,14 @@ void *getmntent_rOne()
memset(&m, 0x00, sizeof(m));
memset(&strings[0], 0x00, sizeof(strings));
FILE *ffp = setmntent("/proc/mounts", "r");
if (!ffp) {
printf("error:%s\n", strerror(errno));
}
EXPECT_PTRNE("getmntent_r_0100", ffp, NULL);
WAIT();
m = getmntent_r(ffp, &mntbuf, strings, sizeof(strings));
if (m != NULL) {
EXPECT_EQ("getmntent_r_0100", strcmp(m->mnt_fsname, str), 0);
EXPECT_EQ("getmntent_r_0100", strcmp(mntbuf.mnt_fsname, str), 0);
} else {
printf("error\n");
}
EXPECT_TRUE("getmntent_r_0100", m != NULL);
EXPECT_EQ("getmntent_r_0100", strcmp(m->mnt_fsname, str), 0);
EXPECT_EQ("getmntent_r_0100", strcmp(mntbuf.mnt_fsname, str), 0);
endmntent(ffp);
return m;
}
......@@ -64,17 +60,17 @@ void getmntent_r_0100(void)
pthread_t srv;
pthread_t cli;
int ret = pthread_barrier_init(&g_barrier, 0, 2);
EXPECT_EQ("getmntent_r_0100", SUCCESS, ret);
EXPECT_EQ("getmntent_r_0100", 0, ret);
ret = pthread_create(&srv, NULL, getmntent_rOne, NULL);
EXPECT_EQ("getmntent_r_0100", SUCCESS, ret);
EXPECT_EQ("getmntent_r_0100", 0, ret);
ret = pthread_create(&cli, NULL, getmntent_rOne, NULL);
EXPECT_EQ("getmntent_r_0100", SUCCESS, ret);
EXPECT_EQ("getmntent_r_0100", 0, ret);
ret = pthread_join(cli, NULL);
EXPECT_EQ("getmntent_r_0100", SUCCESS, ret);
EXPECT_EQ("getmntent_r_0100", 0, ret);
ret = pthread_join(srv, NULL);
EXPECT_EQ("getmntent_r_0100", SUCCESS, ret);
EXPECT_EQ("getmntent_r_0100", 0, ret);
ret = pthread_barrier_destroy(&g_barrier);
EXPECT_EQ("getmntent_r_0100", SUCCESS, ret);
EXPECT_EQ("getmntent_r_0100", 0, ret);
}
/**
......@@ -86,37 +82,28 @@ void getmntent_r_0200(void)
{
char c[1000];
char str[100];
FILE *fptr = NULL;
char strings[1024];
if ((fptr = fopen("/data/getmntent.txt", "w")) == NULL) {
printf("Error! opening file");
}
FILE *fptr = fopen("/data/getmntent.txt", "w");
EXPECT_TRUE("getmntent_r_0200", fptr != NULL);
fclose(fptr);
struct mntent *m = NULL;
struct mntent mntbuf;
memset(&m, 0x00, sizeof(m));
memset(&strings[0], 0x00, sizeof(strings));
FILE *ffp = setmntent("/data/getmntent.txt", "r");
if (!ffp) {
printf("error:%s\n", strerror(errno));
}
EXPECT_PTRNE("getmntent_r_0200", ffp, NULL);
m = getmntent_r(ffp, &mntbuf, strings, sizeof(strings));
EXPECT_EQ("getmntent_r_0200", m, NULL);
endmntent(ffp);
remove("/data/getmntent.txt");
}
TEST_FUN G_Fun_Array[] = {
getmntent_r_0100,
getmntent_r_0200,
};
int main(int argc, char *argv[])
{
int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
for (int pos = 0; pos < num; ++pos) {
G_Fun_Array[pos]();
}
getmntent_r_0100();
getmntent_r_0200();
return t_status;
}
\ No newline at end of file
......@@ -14,7 +14,6 @@
*/
#include <getopt.h>
#include <stdint.h>
#include "functionalext.h"
const int32_t FAILED = -1;
......
......@@ -14,13 +14,8 @@
*/
#include <sys/resource.h>
#include <string.h>
#include <errno.h>
#include "functionalext.h"
int success = 0;
int fail = -1;
/**
* @tc.name : getrusage_0100
* @tc.desc : Verify the program running time (parameter is RUSAGE_SELF)
......@@ -30,7 +25,7 @@ void getrusage_0100(void)
{
struct rusage usage;
int result = getrusage(RUSAGE_SELF, &usage);
EXPECT_EQ("getrusage_0100", result, success);
EXPECT_EQ("getrusage_0100", result, 0);
}
/**
......@@ -42,7 +37,7 @@ void getrusage_0200(void)
{
struct rusage usage;
int result = getrusage(RUSAGE_CHILDREN, &usage);
EXPECT_EQ("getrusage_0200", result, success);
EXPECT_EQ("getrusage_0200", result, 0);
}
/**
......@@ -54,7 +49,7 @@ void getrusage_0300(void)
{
struct rusage usage;
int result = getrusage(RUSAGE_THREAD, &usage);
EXPECT_EQ("getrusage_0300", result, success);
EXPECT_EQ("getrusage_0300", result, 0);
}
/**
......@@ -66,7 +61,7 @@ void getrusage_0400(void)
{
struct rusage usage;
int result = getrusage(100, &usage);
EXPECT_EQ("getrusage_0400", result, fail);
EXPECT_EQ("getrusage_0400", result, -1);
}
/**
......@@ -78,7 +73,7 @@ void getrusage_0500(void)
{
struct rusage usage;
int result = getrusage(RUSAGE_SELF, NULL);
EXPECT_EQ("getrusage_0500", result, fail);
EXPECT_EQ("getrusage_0500", result, -1);
}
int main(void)
......
......@@ -14,15 +14,12 @@
*/
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <stdbool.h>
#include <unistd.h>
#include "functionalext.h"
typedef void (*TEST_FUN)();
const int EOK = 0;
const int SUCCESS = 0;
const int FAILED = -1;
......@@ -36,43 +33,33 @@ const int FAILED = -1;
*/
void mmap_0100(void)
{
int fd;
int mm;
int fd, mm;
void *start;
const char *ptr = "/data/test.txt";
static char str[] = "this is a sample!";
int number = 0;
FILE *fptr = fopen(ptr, "w+");
EXPECT_PTRNE("mmap_0100", fptr, NULL);
struct stat statbuff;
fwrite(str, sizeof(char), strlen(str), fptr);
fseek(fptr, 0L, SEEK_SET);
if (fgetc(fptr) == EOF) {
number = 1;
} else {
number = 2;
}
EXPECT_TRUE("mmap_0100", fgetc(fptr) != EOF);
int back = stat(ptr, &statbuff);
fclose(fptr);
fd = open("/data/test.txt", O_RDWR | O_CREAT, 0777);
if (fd < 0) {
printf("Error!1");
exit(1);
}
EXPECT_NE("mmap_0100", fd, -1);
start = mmap(NULL, statbuff.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
EXPECT_EQ("mmap_0100", number, 2);
EXPECT_EQ("mmap_0100", back, SUCCESS);
bool flag = false;
if (start != MAP_FAILED) {
flag = true;
}
EXPECT_TRUE("mmap_0100", flag);
EXPECT_TRUE("mmap_0100", start != MAP_FAILED);
mm = munmap(start, statbuff.st_size);
EXPECT_EQ("mmap_0100", mm, SUCCESS);
close(fd);
remove(ptr);
remove("/data/test.txt");
fptr = NULL;
ptr = NULL;
close(fd);
}
/**
......@@ -83,44 +70,34 @@ void mmap_0100(void)
*/
void mmap_0200(void)
{
int fd;
int mm;
int fd, mm;
void *start;
const char *ptr = "/data/test.txt";
static char str[] = "this is a sample!";
int number = 0;
FILE *fptr = fopen(ptr, "w+");
EXPECT_PTRNE("mmap_0200", fptr, NULL);
struct stat statbuff;
struct stat sb;
fwrite(str, sizeof(char), strlen(str), fptr);
fseek(fptr, 0L, SEEK_SET);
if (fgetc(fptr) == EOF) {
number = 1;
} else {
number = 2;
}
EXPECT_TRUE("mmap_0200", fgetc(fptr) != EOF);
int back = stat(ptr, &statbuff);
fclose(fptr);
fd = open("/data/test.txt", O_RDWR | O_CREAT, 0777);
if (fd < 0) {
printf("Error!2");
exit(1);
}
EXPECT_NE("mmap_0200", fd, -1);
start = mmap(NULL, statbuff.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
EXPECT_EQ("mmap_0200", number, 2);
EXPECT_EQ("mmap_0200", back, SUCCESS);
bool flag = false;
if (start != MAP_FAILED) {
flag = true;
}
EXPECT_TRUE("mmap_0200", flag);
EXPECT_TRUE("mmap_0200", start != MAP_FAILED);
mm = munmap(start, statbuff.st_size);
EXPECT_EQ("mmap_0200", mm, SUCCESS);
close(fd);
remove(ptr);
remove("/data/test.txt");
fptr = NULL;
ptr = NULL;
close(fd);
}
/**
......@@ -134,11 +111,7 @@ void mmap_0300(void)
void *start;
int mm;
start = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
bool flag = false;
if (start != MAP_FAILED) {
flag = true;
}
EXPECT_TRUE("mmap_0300", flag);
EXPECT_TRUE("mmap_0300", start != MAP_FAILED);
mm = munmap(start, getpagesize());
EXPECT_EQ("mmap_0300", mm, SUCCESS);
}
......@@ -151,37 +124,26 @@ void mmap_0300(void)
*/
void mmap_0400(void)
{
int fd;
int mm;
int fd, mm;
void *start;
const char *ptr = "/data/test.txt";
static char str[] = "this is a sample!";
int number = 0;
FILE *fptr = fopen(ptr, "w+");
EXPECT_PTRNE("mmap_0400", fptr, NULL);
struct stat statbuff;
struct stat sb;
fwrite(str, sizeof(char), strlen(str), fptr);
fseek(fptr, 0L, SEEK_SET);
if (fgetc(fptr) == EOF) {
number = 1;
} else {
number = 2;
}
EXPECT_TRUE("mmap_0400", fgetc(fptr) != EOF);
int back = stat(ptr, &statbuff);
fclose(fptr);
fd = open("/data/test.txt", O_RDWR | O_CREAT, 0777);
if (fd < 0) {
printf("Error!4");
exit(1);
}
EXPECT_NE("mmap_0400", fd, -1);
start = mmap(NULL, statbuff.st_size, PROT_EXEC, MAP_PRIVATE | MAP_LOCKED, fd, 0);
EXPECT_EQ("mmap_0400", number, 2);
EXPECT_EQ("mmap_0400", back, SUCCESS);
bool flag = false;
if (start != MAP_FAILED) {
flag = true;
}
EXPECT_TRUE("mmap_0400", flag);
EXPECT_TRUE("mmap_0400", start != MAP_FAILED);
mm = munmap(start, statbuff.st_size);
EXPECT_EQ("mmap_0400", mm, SUCCESS);
remove(ptr);
......@@ -199,37 +161,27 @@ void mmap_0400(void)
*/
void mmap_0500(void)
{
int fd;
int mm;
int fd, mm;
void *start;
const char *ptr = "/data/test.txt";
static char str[] = "this is a sample!";
int number = 0;
FILE *fptr = fopen(ptr, "w+");
EXPECT_PTRNE("mmap_0500", fptr, NULL);
struct stat statbuff;
struct stat sb;
fwrite(str, sizeof(char), strlen(str), fptr);
fseek(fptr, 0L, SEEK_SET);
if (fgetc(fptr) == EOF) {
number = 1;
} else {
number = 2;
}
EXPECT_TRUE("mmap_0500", fgetc(fptr) != EOF);
int back = stat(ptr, &statbuff);
fclose(fptr);
fd = open("/data/test.txt", O_RDWR | O_CREAT, 0777);
if (fd < 0) {
printf("Error!5");
exit(1);
}
EXPECT_NE("mmap_0500", fd, -1);
start = mmap(NULL, statbuff.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_DENYWRITE, fd, 0);
EXPECT_EQ("mmap_0500", number, 2);
EXPECT_EQ("mmap_0500", back, SUCCESS);
bool flag = false;
if (start != MAP_FAILED) {
flag = true;
}
EXPECT_TRUE("mmap_0500", flag);
EXPECT_TRUE("mmap_0500", start != MAP_FAILED);
mm = munmap(start, statbuff.st_size);
EXPECT_EQ("mmap_0500", mm, SUCCESS);
remove(ptr);
......@@ -247,31 +199,24 @@ void mmap_0500(void)
*/
void mmap_0600(void)
{
int fd;
int mm;
int fd, mm;
void *start;
const char *ptr = "/data/test.txt";
static char str[] = "this is a sample!";
int number = 0;
FILE *fptr = fopen(ptr, "w+");
EXPECT_PTRNE("mmap_0600", fptr, NULL);
struct stat statbuff;
struct stat sb;
fwrite(str, sizeof(char), strlen(str), fptr);
fseek(fptr, 0L, SEEK_SET);
if (fgetc(fptr) == EOF) {
number = 1;
} else {
number = 2;
}
EXPECT_TRUE("mmap_0600", fgetc(fptr) != EOF);
int back = stat(ptr, &statbuff);
fclose(fptr);
fd = open("/data/test.txt", O_RDONLY);
if (fd < 0) {
printf("Error!6");
exit(1);
}
EXPECT_NE("mmap_0600", fd, -1);
start = mmap(NULL, statbuff.st_size, PROT_NONE, MAP_PRIVATE | MAP_FIXED, -1, 0);
EXPECT_EQ("mmap_0600", number, 2);
EXPECT_EQ("mmap_0600", back, SUCCESS);
EXPECT_EQ("mmap_0600", start, MAP_FAILED);
remove(ptr);
......@@ -293,26 +238,21 @@ void mmap_0700(void)
void *start;
const char *ptr = "/data/test.txt";
static char str[] = "this is a sample!";
int number = 0;
FILE *fptr = fopen(ptr, "w+");
EXPECT_PTRNE("mmap_0700", fptr, NULL);
struct stat statbuff;
struct stat sb;
fwrite(str, sizeof(char), strlen(str), fptr);
fseek(fptr, 0L, SEEK_SET);
if (fgetc(fptr) == EOF) {
number = 1;
} else {
number = 2;
}
EXPECT_TRUE("mmap_0700", fgetc(fptr) != EOF);
int back = stat(ptr, &statbuff);
fclose(fptr);
fd = open("/data/test.txt", O_RDWR | O_CREAT, 0777);
if (fd < 0) {
printf("Error!7");
exit(1);
}
EXPECT_NE("mmap_0700", fd, -1);
start = mmap(NULL, statbuff.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, OFF_MASK);
EXPECT_EQ("mmap_0700", number, 2);
EXPECT_EQ("mmap_0700", back, SUCCESS);
EXPECT_EQ("mmap_0700", start, MAP_FAILED);
remove(ptr);
......@@ -334,23 +274,18 @@ void mmap_0800(void)
void *start;
const char *ptr = "/data/test.txt";
static char str[] = "this is a sample!";
int number = 0;
FILE *fptr = fopen(ptr, "w+");
EXPECT_PTRNE("mmap_0800", fptr, NULL);
fwrite(str, sizeof(char), strlen(str), fptr);
fseek(fptr, 0L, SEEK_SET);
if (fgetc(fptr) == EOF) {
number = 1;
} else {
number = 2;
}
EXPECT_TRUE("mmap_0800", fgetc(fptr) != EOF);
fclose(fptr);
fd = open("/data/test.txt", O_RDWR | O_CREAT, 0777);
if (fd < 0) {
printf("Error!8");
exit(1);
}
EXPECT_NE("mmap_0800", fd, -1);
start = mmap(NULL, PTRDIFF_MAX + 1, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
EXPECT_EQ("mmap_0800", number, 2);
EXPECT_EQ("mmap_0800", start, MAP_FAILED);
remove(ptr);
remove("/data/test.txt");
......@@ -370,23 +305,18 @@ void mmap_0900(void)
void *start;
const char *ptr = "/data/test.txt";
static char str[] = "this is a sample!";
int number = 0;
FILE *fptr = fopen(ptr, "w+");
EXPECT_PTRNE("mmap_0900", fptr, NULL);
fwrite(str, sizeof(char), strlen(str), fptr);
fseek(fptr, 0L, SEEK_SET);
if (fgetc(fptr) == EOF) {
number = 1;
} else {
number = 2;
}
EXPECT_TRUE("mmap_0900", fgetc(fptr) != EOF);
fclose(fptr);
fd = open("/data/test.txt", O_RDWR | O_CREAT, 0777);
if (fd < 0) {
printf("Error!9");
exit(1);
}
EXPECT_NE("mmap_0900", fd, -1);
start = mmap(NULL, 0, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
EXPECT_EQ("mmap_0900", number, 2);
EXPECT_EQ("mmap_0900", start, MAP_FAILED);
remove(ptr);
remove("/data/test.txt");
......@@ -407,26 +337,21 @@ void mmap_1000(void)
void *start;
const char *ptr = "/data/test.txt";
static char str[] = "this is a sample!";
int number = 0;
FILE *fptr = fopen(ptr, "w+");
EXPECT_PTRNE("mmap_1000", fptr, NULL);
struct stat statbuff;
struct stat sb;
fwrite(str, sizeof(char), strlen(str), fptr);
fseek(fptr, 0L, SEEK_SET);
if (fgetc(fptr) == EOF) {
number = 1;
} else {
number = 2;
}
EXPECT_TRUE("mmap_1000", fgetc(fptr) != EOF);
int back = stat(ptr, &statbuff);
fclose(fptr);
fd = open("/data/test.txt", O_RDWR | O_CREAT, 0777);
if (fd < 0) {
printf("Error!10");
exit(1);
}
EXPECT_NE("mmap_1000", fd, -1);
start = mmap(NULL, statbuff.st_size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, fd, getpagesize() - 1);
EXPECT_EQ("mmap_1000", number, 2);
EXPECT_EQ("mmap_1000", back, SUCCESS);
EXPECT_EQ("mmap_1000", start, MAP_FAILED);
remove(ptr);
......@@ -444,38 +369,28 @@ void mmap_1000(void)
*/
void mmap_1100(void)
{
int fd;
int mm;
int fd, mm;
void *start;
const char *ptr = "/data/test.txt";
static char str[] = "this is a sample!";
int number = 0;
FILE *fptr = fopen(ptr, "w+");
EXPECT_PTRNE("mmap_1100", fptr, NULL);
struct stat statbuff;
struct stat sb;
fwrite(str, sizeof(char), strlen(str), fptr);
fseek(fptr, 0L, SEEK_SET);
if (fgetc(fptr) == EOF) {
number = 1;
} else {
number = 2;
}
EXPECT_TRUE("mmap_1100", fgetc(fptr) != EOF);
int back = stat(ptr, &statbuff);
fclose(fptr);
fd = open("/data/test.txt", O_RDWR | O_CREAT, 0777);
if (fd < 0) {
printf("Error!11");
exit(1);
}
EXPECT_NE("mmap_1100", fd, -1);
int get = getpagesize() - 1;
start = mmap((void *)(&get), statbuff.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_DENYWRITE, fd, 0);
EXPECT_EQ("mmap_1100", number, 2);
EXPECT_EQ("mmap_1100", back, SUCCESS);
bool flag = false;
if (start != MAP_FAILED) {
flag = true;
}
EXPECT_TRUE("mmap_1100", flag);
EXPECT_TRUE("mmap_1100", start != MAP_FAILED);
mm = munmap(start, statbuff.st_size);
EXPECT_EQ("mmap_1100", mm, SUCCESS);
remove(ptr);
......
......@@ -20,7 +20,6 @@
#include <netdb.h>
#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/stat.h>
......
......@@ -13,17 +13,9 @@
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include "functionalext.h"
const int32_t COUNT_SUCCESS = 1;
const int32_t COUNT_FAILED = -1;
/**
* @tc.name : dn_comp_0100
* @tc.desc : Verify domain name compression (all parameters are valid)
......@@ -31,10 +23,9 @@ const int32_t COUNT_FAILED = -1;
*/
void dn_comp_0100(void)
{
int result;
char name[1024] = "www.baidu.com";
unsigned char buf[1024] = "\0";
result = dn_comp(name, buf, 1024, NULL, NULL);
int result = dn_comp(name, buf, 1024, NULL, NULL);
EXPECT_EQ("dn_comp_0100", result, 15);
}
......@@ -45,11 +36,10 @@ void dn_comp_0100(void)
*/
void dn_comp_0200(void)
{
int result;
char name[1024] = ".";
unsigned char buf[1024] = "\0";
result = dn_comp(name, buf, 1024, NULL, NULL);
EXPECT_EQ("dn_comp_0200", result, COUNT_SUCCESS);
int result = dn_comp(name, buf, 1024, NULL, NULL);
EXPECT_EQ("dn_comp_0200", result, 1);
}
/**
......@@ -59,14 +49,13 @@ void dn_comp_0200(void)
*/
void dn_comp_0300(void)
{
int result;
char name[1024];
for (int i = 0; i < 260; i++) {
name[i] = 'w';
}
unsigned char buf[1024] = "\0";
result = dn_comp(name, buf, 1024, NULL, NULL);
EXPECT_EQ("dn_comp_0300", result, COUNT_FAILED);
int result = dn_comp(name, buf, 1024, NULL, NULL);
EXPECT_EQ("dn_comp_0300", result, -1);
}
/**
......@@ -76,11 +65,10 @@ void dn_comp_0300(void)
*/
void dn_comp_0400(void)
{
int result;
char name[1024] = "www.baidu.com";
unsigned char buf[1024] = "\0";
result = dn_comp(name, buf, 0, NULL, NULL);
EXPECT_EQ("dn_comp_0400", result, COUNT_FAILED);
int result = dn_comp(name, buf, 0, NULL, NULL);
EXPECT_EQ("dn_comp_0400", result, -1);
}
/**
......@@ -90,11 +78,10 @@ void dn_comp_0400(void)
*/
void dn_comp_0500(void)
{
int result;
char name[1024] = "www.baidu.com";
unsigned char buf[1024] = "\0";
result = dn_comp(name, buf, -1, NULL, NULL);
EXPECT_EQ("dn_comp_0500", result, COUNT_FAILED);
int result = dn_comp(name, buf, -1, NULL, NULL);
EXPECT_EQ("dn_comp_0500", result, -1);
}
/**
......@@ -104,11 +91,10 @@ void dn_comp_0500(void)
*/
void dn_comp_0600(void)
{
int result;
char name[1024] = "www.baidu.com";
unsigned char buf[1024] = "\0";
result = dn_comp(name, buf, 1, NULL, NULL);
EXPECT_EQ("dn_comp_0600", result, COUNT_FAILED);
int result = dn_comp(name, buf, 1, NULL, NULL);
EXPECT_EQ("dn_comp_0600", result, -1);
}
int main(int argc, char *argv[])
......
......@@ -13,58 +13,50 @@
* limitations under the License.
*/
#include <arpa/inet.h>
#include <ctype.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <resolv.h>
#include "functionalext.h"
typedef void (*TEST_FUN)();
/**
* @tc.name : getnetbyname_0100
* @tc.desc : Verify the valid domain name to obtain network information successfully
* @tc.name : dn_skipname_0100
* @tc.desc : Verify that the domain name can be compressed (parameters are valid)
* @tc.level : Level 0
*/
void getnetbyname_0100(void)
void dn_skipname_0100(void)
{
struct netent *Socket = NULL;
Socket = getnetbyname("127.0.0.1");
if (!Socket) {
t_error("%s getnetbyname failed\n", __func__);
}
unsigned char s[10] = {0, 2, 34, 45, 75, 23, 12, 192, 87, 254};
int result = dn_skipname(&s[0], &s[1]);
EXPECT_EQ("dn_skipname_0100", result, 1);
}
/**
* @tc.name : getnetbyname_0200
* @tc.desc : Failed to verify invalid domain name to obtain network information.
* @tc.level : Level 2
* @tc.name : dn_skipname_0200
* @tc.desc : Verify that the domain name can be compressed (parameters are valid)
* @tc.level : Level 1
*/
void getnetbyname_0200(void)
void dn_skipname_0200(void)
{
struct netent *Socket = NULL;
Socket = getnetbyname("1ww.baidu.com");
bool flag = false;
if (Socket == NULL) {
flag = true;
}
EXPECT_TRUE("getnetbyname_0200", flag);
unsigned char s[10] = {0, 2, 34, 45, 75, 23, 12, 192, 87, 254};
int result = dn_skipname(&s[7], &s[9]);
EXPECT_EQ("dn_skipname_0200", result, 2);
}
TEST_FUN G_Fun_Array[] = {
getnetbyname_0100,
getnetbyname_0200,
};
/**
* @tc.name : dn_skipname_0300
* @tc.desc : Verify that the domain name cannot be compressed (s and end are equal)
* @tc.level : Level 2
*/
void dn_skipname_0300(void)
{
unsigned char s[10] = {0, 2, 2, 45, 75, 23, 12, 192, 87, 254};
int result = dn_skipname(&s[1], &s[2]);
EXPECT_EQ("dn_skipname_0300", result, -1);
}
int main(int argc, char *argv[])
{
int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
for (int pos = 0; pos < num; ++pos) {
G_Fun_Array[pos]();
}
dn_skipname_0100();
dn_skipname_0200();
dn_skipname_0300();
return t_status;
}
\ No newline at end of file
......@@ -13,9 +13,11 @@
* limitations under the License.
*/
#include <stdio.h>
#include <ifaddrs.h>
#include <stdbool.h>
#include "functionalext.h"
#include <netinet/in.h>
#include <string.h>
#include "test.h"
/**
* @tc.name : freeifaddrs_0100
......@@ -24,16 +26,42 @@
*/
void freeifaddrs_0100(void)
{
struct ifaddrs *ifaddr;
int ret = getifaddrs(&ifaddr);
ifaddr->ifa_next = NULL;
freeifaddrs(ifaddr);
ifaddr = NULL;
bool flag = false;
if (ifaddr == NULL) {
flag = true;
struct ifaddrs *addrs = NULL;
struct ifaddrs *lo_inet4 = NULL;
struct ifaddrs *lo_inet6 = NULL;
struct ifaddrs *lo_packet = NULL;
int result = getifaddrs(&addrs);
if (result != 0) {
t_error("%s getifaddrs failed\n", __func__);
}
if (!addrs) {
t_error("%s addrs is NULL\n", __func__);
}
EXPECT_TRUE("freeifaddrs_0100", flag);
for (struct ifaddrs *addr = addrs; addr != NULL; addr = addr->ifa_next) {
if (addr->ifa_name && strcmp(addr->ifa_name, "lo") == 0) {
if (addr->ifa_addr && addr->ifa_addr->sa_family == AF_INET) {
lo_inet4 = addr;
} else if (addr->ifa_addr && addr->ifa_addr->sa_family == AF_INET6) {
lo_inet6 = addr;
} else if (addr->ifa_addr && addr->ifa_addr->sa_family == AF_PACKET) {
lo_packet = addr;
}
}
}
if (lo_inet4 == NULL) {
t_error("%s lo_inet4 is NULL\n", __func__);
}
if (lo_inet6 == NULL) {
t_error("%s lo_inet4 is NULL\n", __func__);
}
if (lo_packet == NULL) {
t_error("%s lo_inet4 is NULL\n", __func__);
}
freeifaddrs(addrs);
}
int main(int argc, char *argv[])
......
......@@ -33,19 +33,12 @@ const int SOCKTYPE_NOTSUPPORTED = -8;
*/
void getaddrinfo_0100(void)
{
int ret = -1;
int num = -1;
struct addrinfo *result, hint;
hint.ai_flags = AI_ALL;
hint.ai_flags = AI_PASSIVE;
hint.ai_family = AF_UNSPEC;
ret = getaddrinfo("127.0.0.1", NULL, &hint, &result);
int ret = getaddrinfo("127.0.0.1", NULL, &hint, &result);
EXPECT_EQ("getaddrinfo_0100", ret, GETADDRINFO_RESULT);
if (result->ai_addr != NULL) {
num = 1;
} else {
num = 2;
}
EXPECT_EQ("getaddrinfo_0100", num, 1);
EXPECT_TRUE("getaddrinfo_0100", result->ai_addr != NULL);
freeaddrinfo(result);
result = NULL;
}
......@@ -57,19 +50,12 @@ void getaddrinfo_0100(void)
*/
void getaddrinfo_0200(void)
{
int ret = -1;
int num = -1;
struct addrinfo *result, hint;
hint.ai_flags = AI_ALL;
hint.ai_family = AF_UNSPEC;
ret = getaddrinfo("127.0.0.1", NULL, &hint, &result);
int ret = getaddrinfo("127.0.0.1", NULL, &hint, &result);
EXPECT_EQ("getaddrinfo_0200", ret, GETADDRINFO_RESULT);
if (result->ai_addr != NULL) {
num = 1;
} else {
num = 2;
}
EXPECT_EQ("getaddrinfo_0200", num, 1);
EXPECT_TRUE("getaddrinfo_0200", result->ai_addr != NULL);
freeaddrinfo(result);
result = NULL;
}
......@@ -82,20 +68,13 @@ void getaddrinfo_0200(void)
*/
void getaddrinfo_0300(void)
{
int ret = -1;
int num = -1;
struct addrinfo *result, hint;
hint.ai_flags = AI_NUMERICHOST;
hint.ai_family = AF_INET6;
char buf[] = "fe80::bed5:4695:6cac:bef8";
ret = getaddrinfo(buf, NULL, &hint, &result);
int ret = getaddrinfo(buf, NULL, &hint, &result);
EXPECT_EQ("getaddrinfo_0300", ret, GETADDRINFO_RESULT);
if (result->ai_addr != NULL) {
num = 1;
} else {
num = 2;
}
EXPECT_EQ("getaddrinfo_0300", num, 1);
EXPECT_TRUE("getaddrinfo_0300", result->ai_addr != NULL);
freeaddrinfo(result);
result = NULL;
}
......@@ -107,19 +86,12 @@ void getaddrinfo_0300(void)
*/
void getaddrinfo_0400(void)
{
int ret = -1;
int num = -1;
struct addrinfo *result, hint;
hint.ai_flags = AI_V4MAPPED;
hint.ai_family = AF_INET6;
ret = getaddrinfo("127.0.0.1", NULL, &hint, &result);
int ret = getaddrinfo("127.0.0.1", NULL, &hint, &result);
EXPECT_EQ("getaddrinfo_0400", ret, GETADDRINFO_RESULT);
if (result->ai_addr != NULL) {
num = 1;
} else {
num = 2;
}
EXPECT_EQ("getaddrinfo_0400", num, 1);
EXPECT_TRUE("getaddrinfo_0400", result->ai_addr != NULL);
freeaddrinfo(result);
result = NULL;
}
......@@ -131,19 +103,12 @@ void getaddrinfo_0400(void)
*/
void getaddrinfo_0500(void)
{
int ret = -1;
int num = -1;
struct addrinfo *result, hint;
hint.ai_flags = AI_ALL;
hint.ai_flags = AI_V4MAPPED;
hint.ai_family = AF_UNSPEC;
ret = getaddrinfo("127.0.0.1", NULL, &hint, &result);
int ret = getaddrinfo("127.0.0.1", NULL, &hint, &result);
EXPECT_EQ("getaddrinfo_0500", ret, GETADDRINFO_RESULT);
if (result->ai_addr != NULL) {
num = 1;
} else {
num = 2;
}
EXPECT_EQ("getaddrinfo_0500", num, 1);
EXPECT_TRUE("getaddrinfo_0500", result->ai_addr != NULL);
freeaddrinfo(result);
result = NULL;
}
......@@ -156,19 +121,12 @@ void getaddrinfo_0500(void)
*/
void getaddrinfo_0600(void)
{
int ret = -1;
int num = -1;
struct addrinfo *result, hint;
hint.ai_flags = AI_ADDRCONFIG;
hint.ai_family = AF_UNSPEC;
ret = getaddrinfo("127.0.0.1", NULL, &hint, &result);
int ret = getaddrinfo("127.0.0.1", NULL, &hint, &result);
EXPECT_EQ("getaddrinfo_0600", ret, GETADDRINFO_RESULT);
if (result->ai_addr != NULL) {
num = 1;
} else {
num = 2;
}
EXPECT_EQ("getaddrinfo_0600", num, 1);
EXPECT_TRUE("getaddrinfo_0600", result->ai_addr != NULL);
freeaddrinfo(result);
result = NULL;
}
......@@ -181,19 +139,12 @@ void getaddrinfo_0600(void)
*/
void getaddrinfo_0700(void)
{
int ret = -1;
int num = -1;
struct addrinfo *result, hint;
hint.ai_flags = AI_NUMERICSERV;
hint.ai_family = AF_UNSPEC;
ret = getaddrinfo("127.0.0.1", NULL, &hint, &result);
int ret = getaddrinfo("127.0.0.1", NULL, &hint, &result);
EXPECT_EQ("getaddrinfo_0700", ret, GETADDRINFO_RESULT);
if (result->ai_addr != NULL) {
num = 1;
} else {
num = 2;
}
EXPECT_EQ("getaddrinfo_0700", num, 1);
EXPECT_TRUE("getaddrinfo_0700", result->ai_addr != NULL);
freeaddrinfo(result);
result = NULL;
}
......@@ -205,17 +156,10 @@ void getaddrinfo_0700(void)
*/
void getaddrinfo_0800(void)
{
int ret = -1;
int num = -1;
struct addrinfo *result;
ret = getaddrinfo("127.0.0.1", NULL, NULL, &result);
int ret = getaddrinfo("127.0.0.1", NULL, NULL, &result);
EXPECT_EQ("getaddrinfo_0800", ret, GETADDRINFO_RESULT);
if (result->ai_addr != NULL) {
num = 1;
} else {
num = 2;
}
EXPECT_EQ("getaddrinfo_0800", num, 1);
EXPECT_TRUE("getaddrinfo_0800", result->ai_addr != NULL);
freeaddrinfo(result);
result = NULL;
}
......@@ -227,11 +171,10 @@ void getaddrinfo_0800(void)
*/
void getaddrinfo_0900(void)
{
int ret = -1;
struct addrinfo *result, hint;
hint.ai_flags = 0x4000;
hint.ai_family = AF_UNSPEC;
ret = getaddrinfo("127.0.0.1", NULL, &hint, &result);
int ret = getaddrinfo("127.0.0.1", NULL, &hint, &result);
EXPECT_EQ("getaddrinfo_0900", ret, FLAGS_FIELD);
}
......@@ -242,11 +185,10 @@ void getaddrinfo_0900(void)
*/
void getaddrinfo_1000(void)
{
int ret = -1;
struct addrinfo *result, hint;
hint.ai_flags = AI_ALL;
hint.ai_family = PF_AX25;
ret = getaddrinfo("127.0.0.1", NULL, &hint, &result);
int ret = getaddrinfo("127.0.0.1", NULL, &hint, &result);
EXPECT_EQ("getaddrinfo_1000", ret, FAMILY_NOTSUPPORTED);
}
......@@ -258,7 +200,6 @@ void getaddrinfo_1000(void)
*/
void getaddrinfo_1100(void)
{
int ret = -1;
struct addrinfo *result, hint;
hint.ai_flags = AI_NUMERICHOST;
hint.ai_family = AF_INET6;
......@@ -269,7 +210,7 @@ void getaddrinfo_1100(void)
strcat(one, two);
strcat(one, three);
strcat(one, four);
ret = getaddrinfo(one, NULL, &hint, &result);
int ret = getaddrinfo(one, NULL, &hint, &result);
EXPECT_EQ("getaddrinfo_1100", ret, SERVICE_UNKNOEN);
}
......@@ -281,11 +222,10 @@ void getaddrinfo_1100(void)
*/
void getaddrinfo_1200(void)
{
int ret = -1;
struct addrinfo *result, hint;
hint.ai_flags = AI_NUMERICHOST;
hint.ai_family = AF_INET6;
ret = getaddrinfo(NULL, NULL, &hint, &result);
int ret = getaddrinfo(NULL, NULL, &hint, &result);
EXPECT_EQ("getaddrinfo_1200", ret, SERVICE_UNKNOEN);
}
......@@ -296,13 +236,12 @@ void getaddrinfo_1200(void)
*/
void getaddrinfo_1300(void)
{
int ret = -1;
struct addrinfo *result, hint;
hint.ai_flags = AI_CANONNAME;
hint.ai_family = AF_INET;
hint.ai_protocol = IPPROTO_UDP;
hint.ai_socktype = SOCK_STREAM;
ret = getaddrinfo("127.0.0.1", NULL, &hint, &result);
int ret = getaddrinfo("127.0.0.1", NULL, &hint, &result);
EXPECT_EQ("getaddrinfo_1300", ret, SOCKTYPE_NOTSUPPORTED);
}
......@@ -313,13 +252,12 @@ void getaddrinfo_1300(void)
*/
void getaddrinfo_1400(void)
{
int ret = -1;
struct addrinfo *result, hint;
hint.ai_flags = AI_CANONNAME;
hint.ai_family = AF_INET;
hint.ai_protocol = IPPROTO_TCP;
hint.ai_socktype = SOCK_DGRAM;
ret = getaddrinfo("127.0.0.1", NULL, &hint, &result);
int ret = getaddrinfo("127.0.0.1", NULL, &hint, &result);
EXPECT_EQ("getaddrinfo_1400", ret, SOCKTYPE_NOTSUPPORTED);
}
......@@ -330,12 +268,11 @@ void getaddrinfo_1400(void)
*/
void getaddrinfo_1500(void)
{
int ret = -1;
struct addrinfo *result, hint;
hint.ai_flags = AI_CANONNAME;
hint.ai_family = AF_INET;
hint.ai_socktype = SOCK_RAW;
ret = getaddrinfo("127.0.0.1", "2000", &hint, &result);
int ret = getaddrinfo("127.0.0.1", "2000", &hint, &result);
EXPECT_EQ("getaddrinfo_1500", ret, SOCKTYPE_NOTSUPPORTED);
}
......
......@@ -15,8 +15,6 @@
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include "functionalext.h"
/**
......
......@@ -16,8 +16,6 @@
#include <ifaddrs.h>
#include "functionalext.h"
const int SUCCESS = 0;
/**
* @tc.name : getifaddrs_0100
* @tc.desc : The parameter is valid, and the information of the local network interface can be obtained.
......@@ -27,7 +25,7 @@ void getifaddrs_0100(void)
{
struct ifaddrs *ifaddr;
int ret = getifaddrs(&ifaddr);
EXPECT_EQ("getifaddrs_0100", ret, SUCCESS);
EXPECT_EQ("getifaddrs_0100", ret, 0);
freeifaddrs(ifaddr);
ifaddr = NULL;
}
......
......@@ -13,10 +13,6 @@
* limitations under the License.
*/
#include <errno.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/socket.h>
#include "functionalext.h"
#define IPPROTO_IP 0
......
......@@ -13,66 +13,75 @@
* limitations under the License.
*/
#include <resolv.h>
#include <stdio.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <string.h>
#include <stdlib.h>
#include "test.h"
const char *path = "/etc/networks";
const char *netinfo = "loopback 127.0.0.1";
const char name[] = "www";
const char domain[] = "example.com";
const int class = C_IN;
const int type = T_TXT;
const char options[] = "options timeout:0";
/**
* @tc.name : getnetbyaddr_0100
* @tc.desc : Verify that the network information is successfully obtained through a valid IPv4 address
* @tc.level : Level 0
*/
void getnetbyaddr_0100(void)
void set_timeout(void)
{
FILE *fd = fopen(path, "w+");
if (!fd) {
t_error("%s fopen failed\n", __func__);
}
fwrite(netinfo, sizeof(char), strlen(netinfo), fd);
system("cp /etc/resolv.conf /etc/resolv.conf.bak");
struct netent *nptr;
uint32_t ip = inet_network("127.0.0.1");
printf("ip: %d\n", ip);
nptr = getnetbyaddr(ip, AF_INET);
if (!nptr) {
t_error("%s getnetbyaddr failed\n", __func__);
FILE *f = fopen(_PATH_RESCONF, "a+");
if (f == NULL) {
t_error("%s failed: fopen\n", __func__);
return;
}
fwrite(options, sizeof(options), 1, f);
fclose(f);
}
/**
* @tc.name : getnetbyaddr_0200
* @tc.desc : Authentication failed to obtain network information through invalid IPv4 address
* @tc.level : Level 2
*/
void getnetbyaddr_0200(void)
{}
void restore_conf(void)
{
remove(_PATH_RESCONF);
rename("/etc/resolv.conf.bak", _PATH_RESCONF);
}
/**
* @tc.name : getnetbyaddr_0300
* @tc.desc : Verify that the network information is successfully obtained through a valid IPv6 address
* @tc.name : res_querydomain_0100
* @tc.desc : query the name server
* @tc.level : Level 0
*/
void getnetbyaddr_0300(void)
{}
void res_querydomain_0100(void)
{
set_timeout();
unsigned char buf[BUFSIZ] = {0};
int result = res_querydomain(name, domain, class, type, buf, sizeof(buf));
if (result != 0) {
t_error("%s failed: result = %d\n", __func__, result);
}
restore_conf();
}
/**
* @tc.name : getnetbyaddr_0400
* @tc.desc : Authentication failed to obtain network information through invalid IPv6 address
* @tc.name : res_querydomain_0200
* @tc.desc : query the name server with an invalid type
* @tc.level : Level 2
*/
void getnetbyaddr_0400(void)
{}
void res_querydomain_0200(void)
{
set_timeout();
int result = res_querydomain(name, domain, class, T_ANY + 1, NULL, 0);
if (result == 0) {
t_error("%s failed: result = %d\n", __func__, result);
}
restore_conf();
}
int main(int argc, char *argv[])
{
getnetbyaddr_0100();
getnetbyaddr_0200();
getnetbyaddr_0300();
getnetbyaddr_0400();
res_querydomain_0100();
res_querydomain_0200();
return t_status;
}
\ No newline at end of file
......@@ -54,4 +54,6 @@ functionalext_supplement_network_test = [
"gai_strerror",
"recv",
"freeaddrinfo",
"res_querydomain",
"dn_skipname",
]
......@@ -13,16 +13,8 @@
* limitations under the License.
*/
#include <fcntl.h>
#include <grp.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <stdbool.h>
#include <string.h>
#include <netdb.h>
#include <unistd.h>
#include "functionalext.h"
#include "test.h"
/**
* @tc.name : getgrent_0100
......@@ -31,13 +23,17 @@
*/
void getgrent_0100(void)
{
struct group *data;
bool flag = false;
data = getgrent();
if (data != NULL) {
flag = true;
struct group *grp;
setgrent();
while ((grp = getgrent()) != NULL) {
if (grp->gr_name == NULL) {
t_error("%s grp->gr_name is NULL\n", __func__);
}
if (grp->gr_mem == NULL) {
t_error("%s gr_mem is NULL\n", __func__);
}
}
EXPECT_TRUE("getgrent_0100", flag);
endgrent();
}
......
......@@ -13,74 +13,63 @@
* limitations under the License.
*/
#include <fcntl.h>
#include <errno.h>
#include <grp.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>
#include <sys/stat.h>
#include "functionalext.h"
#include <string.h>
#include "test.h"
/**
* @tc.name : getgrgid_r_0100
* @tc.desc : Verify that the specified gid data can be obtained from the group file (parameters are valid)
* @tc.desc :
* @tc.level : Level 0
*/
void getgrgid_r_0100(void)
{
system("ps -eo command,gid | grep -E \"GID|/data/tests/libc-test/src/functionalext/supplement/passwd/"
"getgrgid_r\" > ps.txt");
char abc[256] = {0};
bool successflag = false;
FILE *fptr = fopen("ps.txt", "r");
if (fptr) {
while (!feof(fptr)) {
fread(abc, sizeof(abc), 1, fptr);
char num[8] = {0};
int index = 0;
for (int i = 0; i < (int)strlen(abc); i++) {
if (abc[i] >= '0' && abc[i] <= '9') {
num[index++] += abc[i];
}
}
num[index] = '\0';
gid_t intgid = atoi(num);
int data;
short int lp;
struct group grp;
struct group *grpptr = &grp;
struct group *tempGrpPtr;
char grpbuffer[200];
int grplinelen = sizeof(grpbuffer);
data = getgrgid_r(91, grpptr, grpbuffer, grplinelen, &tempGrpPtr);
if (data == intgid) {
successflag = true;
}
}
errno = 0;
char buf[512];
gid_t gid = 0;
struct group *grp;
struct group grp_storage;
const char *group_name = "root";
int result = getgrgid_r(gid, &grp_storage, buf, sizeof(buf), &grp);
if (result != 0) {
t_error("%s getgrgid_r failed\n", __func__);
}
if (errno != 0) {
t_error("%s errno should be zero\n", __func__);
}
if (!grp) {
t_error("%s failed, grp is NULL\n", __func__);
}
if (strcmp(group_name, grp->gr_name)) {
t_error("%s grp->gr_name is %s\n", __func__, grp->gr_name);
}
if (gid != grp->gr_gid) {
t_error("%s gr_gid is %d\n", __func__, grp->gr_gid);
}
if (!grp->gr_mem) {
t_error("%s grp->gr_mem is NULL\n", __func__);
}
EXPECT_TRUE("getgrgid_r_0100", successflag);
fclose(fptr);
remove("ps.txt");
}
/**
* @tc.name : getgrgid_r_0200
* @tc.desc : Verify that the specified gid data can be obtained from the group file (the parameter is invalid)
* @tc.desc : Invalid parameter test
* @tc.level : Level 2
*/
void getgrgid_r_0200(void)
{
int data;
struct group grp;
struct group *grpptr = &grp;
struct group *tempGrpPtr;
char grpbuffer[200];
int grplinelen = sizeof(grpbuffer);
data = getgrgid_r(0, grpptr, grpbuffer, -1, &tempGrpPtr);
EXPECT_EQ("getgrgid_r_0200", data, 0);
char buf[512];
struct group *grp;
struct group grp_storage;
int result = getgrgid_r(-1, &grp_storage, buf, sizeof(buf), &grp);
if (result) {
t_error("%s getgrgid_r should be failed\n", __func__);
}
}
int main(int argc, char *argv[])
......
......@@ -13,73 +13,63 @@
* limitations under the License.
*/
#include <fcntl.h>
#include <errno.h>
#include <grp.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>
#include "functionalext.h"
#include <string.h>
#include "test.h"
/**
* @tc.name : getgrnam_r_0100
* @tc.desc : Verify that the specified group data can be obtained from the group file (parameters are valid)
* @tc.desc : Get group file entry
* @tc.level : Level 0
*/
void getgrnam_r_0100(void)
{
system("ps -eo command,gid | grep -E \"GID|getgrnam_r\" > "
"/data/tests/libc-test/src/functionalext/supplement/passwd/pss.txt");
char abc[256] = {0};
bool successflag = false;
FILE *fptr = fopen("/data/tests/libc-test/src/functionalext/supplement/passwd/pss.txt", "r");
if (fptr) {
while (!feof(fptr)) {
fread(abc, sizeof(abc), 1, fptr);
char num[8] = {0};
int index = 0;
for (int i = 0; i < (int)strlen(abc); i++) {
if (abc[i] >= '0' && abc[i] <= '9') {
num[index++] += abc[i];
}
}
num[index] = '\0';
gid_t intgid = atoi(num);
int data;
short int lp;
struct group grp;
struct group *grpptr = &grp;
struct group *tempGrpPtr;
char grpbuffer[200];
int grplinelen = sizeof(grpbuffer);
data = getgrnam_r("root", grpptr, grpbuffer, grplinelen, &tempGrpPtr);
if (data == intgid) {
successflag = true;
}
}
errno = 0;
char buf[512];
gid_t gid = 0;
struct group *grp;
struct group grp_storage;
const char *group_name = "root";
int result = getgrnam_r(group_name, &grp_storage, buf, sizeof(buf), &grp);
if (result != 0) {
t_error("%s getgrnam_r failed\n", __func__);
}
if (errno != 0) {
t_error("%s errno should be zero\n", __func__);
}
if (!grp) {
t_error("%s failed, grp is NULL\n", __func__);
}
if (strcmp(group_name, grp->gr_name)) {
t_error("%s grp->gr_name is %s\n", __func__, grp->gr_name);
}
if (gid != grp->gr_gid) {
t_error("%s gr_gid is %d\n", __func__, grp->gr_gid);
}
if (!grp->gr_mem) {
t_error("%s grp->gr_mem is NULL\n", __func__);
}
EXPECT_TRUE("getgrgid_r_0100", successflag);
fclose(fptr);
remove("/data/tests/libc-test/src/functionalext/supplement/passwd/pss.txt");
}
/**
* @tc.name : getgrnam_r_0200
* @tc.desc : Verify that the specified group data can be obtained from the group file (parameter invalid)
* @tc.desc : Invalid parameter test
* @tc.level : Level 2
*/
void getgrnam_r_0200(void)
{
int data;
struct group grp;
struct group *grpptr = &grp;
struct group *tempGrpPtr;
char grpbuffer[200];
int grplinelen = sizeof(grpbuffer);
data = getgrnam_r("root", grpptr, grpbuffer, -1, &tempGrpPtr);
EXPECT_EQ("getgrnam_r_0200", data, 0);
char buf[512];
struct group *grp;
struct group grp_storage;
int result = getgrnam_r("invalid_name", &grp_storage, buf, sizeof(buf), &grp);
if (result) {
t_error("%s getgrnam_r should be failed\n", __func__);
}
}
int main(int argc, char *argv[])
......
......@@ -13,77 +13,56 @@
* limitations under the License.
*/
#include <unistd.h>
#include <grp.h>
#include <limits.h>
#include <stdlib.h>
#include <signal.h>
#include <fcntl.h>
#include <stdarg.h>
#include <sys/wait.h>
#include <spawn.h>
#include <errno.h>
#include <limits.h>
#include <string.h>
#include "functionalext.h"
#include <malloc.h>
#include <pwd.h>
#include <stdio.h>
#include "test.h"
static int server_ngroups;
static gid_t *server_groups;
/*
* @tc.name : getgrouplist_0100
* @tc.desc : Verify that the list of group IDs can be obtained (parameters are valid)
* @tc.desc : Get list of groups to which a user belongs
* @tc.level : Level 0
*/
void getgrouplist_0100()
{
int ngroups;
char who[1024] = {0};
system("whoami > /data/user.txt");
FILE *fptr = fopen("/data/user.txt", "r");
fread(who, sizeof(who), 1, fptr);
int result;
struct group *gr;
const char *server_user = "root";
char buffer[1024] = {0};
system("id -g > /data/id.txt");
FILE *ptr = fopen("/data/id.txt", "r");
fread(buffer, sizeof(buffer), 1, ptr);
gid_t id = atoi(buffer);
gid_t gid = getgid();
int result = getgrouplist(who, gid, &id, &ngroups);
struct passwd *pwd = getpwnam(server_user);
if (!pwd) {
t_error("%s getpwnam failed\n", __func__);
}
EXPECT_TRUE("getgrouplist_0100", result != 0);
}
gid_t server_gid = pwd->pw_gid;
/*
* @tc.name : getgrouplist_0200
* @tc.desc : Validation cannot get group ID list (parameter invalid)
* @tc.level : Level 2
*/
void getgrouplist_0200()
{
int ngroups;
char who[1024] = {0};
char user[1024] = {0};
system("whoami > /data/user.txt");
FILE *fptr = fopen("/data/user.txt", "r");
fread(who, sizeof(who), 1, fptr);
char buffer[1204] = {0};
system("id -g > /data/id.txt");
FILE *ptr = fopen("/data/id.txt", "r");
fread(buffer, sizeof(buffer), 1, ptr);
gid_t id = atoi(buffer);
gid_t gid = getgid();
result = getgrouplist(server_user, server_gid, NULL, &server_ngroups);
if (result == 0) {
t_error("%s getgrouplist should be failed\n", __func__);
}
int result = getgrouplist(user, gid, &id, &ngroups);
server_groups = (gid_t *)malloc(server_ngroups * sizeof(gid_t));
result = getgrouplist(server_user, server_gid, server_groups, &server_ngroups);
if (result == -1) {
t_error("%s getgrouplist failed\n", __func__);
}
EXPECT_EQ("getgrouplist_0200", result, -1);
remove("/data/id.txt");
remove("/data/user.txt");
for (int i = 0; i < server_ngroups; i++) {
printf("%d", server_groups[i]);
gr = getgrgid(server_groups[i]);
if (gr != NULL) {
printf(" (%s)", gr->gr_name);
}
printf("\n");
}
}
int main(int argc, char *argv[])
{
getgrouplist_0100();
getgrouplist_0200();
return t_status;
}
\ No newline at end of file
......@@ -23,9 +23,8 @@
*/
void erand48_0100(void)
{
double result = 0;
unsigned short xseed[3] = {1, 2, 3};
result = erand48(xseed);
double result = erand48(xseed);
EXPECT_TRUE("erand48_0100", result >= 0.0 && result < 1.0);
}
......
......@@ -26,6 +26,7 @@ void execlp_0100(void)
fpid = fork();
if (fpid == 0) {
int ret = execlp("touch", "touch", "execlptest.txt", NULL);
EXPECT_NE("execlp_0100", ret, -1);
}
sleep(1);
......
......@@ -28,6 +28,7 @@ void execv_0100(void)
if (fpid == 0) {
char *argv[] = {"touch", "touch", "execvtest.txt", NULL};
int ret = execv("/bin/touch", argv);
EXPECT_NE("execv_0100", ret, -1);
}
sleep(1);
int isExist = access("execvtest.txt", F_OK);
......
......@@ -13,18 +13,11 @@
* limitations under the License.
*/
#include <errno.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include "functionalext.h"
const int32_t COUNT_NEGATIVE = -1;
char *my_env[] = {"THIS=environment will be", "PASSED=to new process by", "the EXEC=functions", NULL};
int result_1;
int result_2;
/**
* @tc.name : execvpe_0100
......@@ -34,22 +27,18 @@ int result_2;
*/
void execvpe_0100(void)
{
bool flag = false;
char *path;
path = getenv("touch");
char *path = getenv("touch");
pid_t fpid;
fpid = fork();
if (fpid == 0) {
char *argv[] = {"touch", "touch", "/data/test.txt", 0};
result_1 = execvpe("touch", argv, &path);
int result = execvpe("touch", argv, &path);
EXPECT_NE("execvpe_0100", result, -1);
}
sleep(1);
FILE *fptr = fopen("/data/test.txt", "r");
if (fptr != NULL) {
flag = true;
}
EXPECT_NE("execvpe_0100", result_1, COUNT_NEGATIVE);
EXPECT_TRUE("execvpe_0100", flag);
EXPECT_PTRNE("execvpe_0100", fptr, NULL);
fclose(fptr);
remove("/data/test.txt");
}
......@@ -61,24 +50,22 @@ void execvpe_0100(void)
*/
void execvpe_0200(void)
{
bool flag = false;
char *path = getenv("touch");
setenv("touch", "\0", 1);
pid_t fpid;
fpid = fork();
if (fpid == 0) {
char *argv[] = {"touch", "touch", "/data/test.txt", 0};
result_2 = execvpe("touch", argv, &path);
int result = execvpe("touch", argv, &path);
EXPECT_NE("execvpe_0100", result, -1);
}
sleep(1);
FILE *fptr = fopen("/data/test.txt", "r");
if (fptr != NULL) {
flag = true;
}
EXPECT_PTRNE("execvpe_0100", fptr, NULL);
fclose(fptr);
remove("/data/test.txt");
EXPECT_NE("execvpe_0200", result_2, COUNT_NEGATIVE);
EXPECT_TRUE("execvpe_0200", flag);
unsetenv("touch");
}
......@@ -90,11 +77,10 @@ void execvpe_0200(void)
*/
void execvpe_0300(void)
{
int result;
char buff[] = "\0";
char *argv[] = {"ls", "-al", "/etc/passwd", 0};
result = execvpe(buff, argv, my_env);
EXPECT_EQ("execvpe_0300", result, COUNT_NEGATIVE);
int result = execvpe(buff, argv, my_env);
EXPECT_EQ("execvpe_0300", result, -1);
}
/**
......@@ -105,14 +91,13 @@ void execvpe_0300(void)
*/
void execvpe_0400(void)
{
int result;
char *argv[] = {"ls", "-al", "/etc/passwd", 0};
char buff[300];
for (int i = 0; i < 300; i++) {
buff[i] = 'a';
}
result = execvpe(buff, argv, my_env);
EXPECT_EQ("execvpe_0400", result, COUNT_NEGATIVE);
int result = execvpe(buff, argv, my_env);
EXPECT_EQ("execvpe_0400", result, -1);
}
int main(int argc, char *argv[])
......
......@@ -14,7 +14,6 @@
*/
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include "functionalext.h"
......@@ -34,7 +33,6 @@ void fexecve_0100(void)
int ret = fexecve(fd, argv, environ);
EXPECT_NE("fexecve_0100", ret, -1);
}
sleep(1);
}
/**
......
......@@ -34,7 +34,7 @@ void fork_0100()
char list2[2];
FILE *fp;
if (fpid < 0) {
printf("error in fork!");
t_error("%s error in fork!", __func__);
} else if (fpid == 0) {
fp = fopen("test1.txt", "w+");
fwrite(sign_r, sizeof(char), strlen(sign_r), fp);
......@@ -51,6 +51,7 @@ void fork_0100()
fread(list2, sizeof(list2), 1, fp2);
EXPECT_EQ("fork_0100", list1[0], '1');
EXPECT_EQ("fork_0100", list2[0], '1');
fclose(fp1);
fclose(fp2);
remove("test1.txt");
......
......@@ -34,10 +34,8 @@ void __sched_cpucount_0100(void)
int num_cpus;
num_cpus = sysconf(_SC_NPROCESSORS_CONF);
cpusetp = CPU_ALLOC(num_cpus);
if (cpusetp == NULL) {
perror("CPU_ALLOC");
exit(EXIT_FAILURE);
}
EXPECT_PTRNE("__sched_cpucount_0100", cpusetp, NULL);
size = CPU_ALLOC_SIZE(num_cpus);
CPU_ZERO_S(size, cpusetp);
for (int cpu = 0; cpu < num_cpus; cpu++) {
......@@ -62,10 +60,8 @@ void __sched_cpucount_0200(void)
int num_cpus;
num_cpus = sysconf(_SC_NPROCESSORS_CONF);
cpusetp = CPU_ALLOC(num_cpus);
if (cpusetp == NULL) {
perror("CPU_ALLOC");
exit(EXIT_FAILURE);
}
EXPECT_PTRNE("__sched_cpucount_0200", cpusetp, NULL);
size = CPU_ALLOC_SIZE(num_cpus);
CPU_ZERO_S(size, cpusetp);
for (int cpu = 0; cpu < num_cpus; cpu++) {
......@@ -90,10 +86,8 @@ void __sched_cpucount_0300(void)
int num_cpus;
num_cpus = sysconf(_SC_NPROCESSORS_CONF);
cpusetp = CPU_ALLOC(num_cpus);
if (cpusetp == NULL) {
perror("CPU_ALLOC");
exit(EXIT_FAILURE);
}
EXPECT_PTRNE("__sched_cpucount_0300", cpusetp, NULL);
size = CPU_ALLOC_SIZE(num_cpus);
CPU_ZERO_S(size, cpusetp);
ret = __sched_cpucount(size, cpusetp);
......
......@@ -13,36 +13,31 @@
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <setjmp.h>
#include "functionalext.h"
#include "test.h"
static jmp_buf buf;
bool FLAG = false;
void second()
void FAIL(void)
{
longjmp(buf, 1);
}
void first()
{
FLAG = true;
second();
FLAG = false;
t_error("%s failed, this function should be unreachable\n", __func__);
}
/**
* @tc.name : _longjmp_0100
* @tc.desc : Verify that jumps between functions can be achieved
* @tc.desc : Restore the environment saved by the most recent invocation of setjmp() in the same process, with
* the corresponding jmp_buf argument
* @tc.level : Level 0
*/
void _longjmp_0100(void)
{
if (!setjmp(buf)) {
first();
jmp_buf jb;
int value = setjmp(jb);
if (value == 0) {
_longjmp(jb, 456);
FAIL();
} else {
EXPECT_TRUE("_longjmp_0100", FLAG);
if (value != 456) {
t_error("%s _longjmp failed\n", __func__);
}
}
}
......
......@@ -13,37 +13,29 @@
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <setjmp.h>
#include "functionalext.h"
#include "test.h"
bool FLAG = false;
static jmp_buf envbuf;
void second()
void FAIL(void)
{
FLAG = true;
longjmp(envbuf, 5);
t_error("%s failed, this function should be unreachable\n", __func__);
}
void first()
{
FLAG = false;
second();
FLAG = false;
}
/**
* @tc.name : _setjmp_0100
* @tc.desc : Verify that jumps between functions can be achieved
* @tc.desc :
* @tc.level : Level 0
*/
void _setjmp_0100(void)
{
if (setjmp(envbuf) == 0) {
first();
int value;
jmp_buf jb;
if ((value = _setjmp(jb)) == 0) {
_longjmp(jb, 456);
FAIL();
} else {
EXPECT_TRUE("_setjmp_0100", FLAG);
if (value != 456) {
t_error("%s _longjmp failed\n", __func__);
}
}
}
......
......@@ -15,7 +15,6 @@
#include <signal.h>
#include "functionalext.h"
#define MAXPATH 1000
/*
* @tc.name : libc_current_sigrtmax_0100
......
......@@ -15,7 +15,6 @@
#include <signal.h>
#include "functionalext.h"
#define MAXPATH 1000
/*
* @tc.name : libc_current_sigrtmin_0100
......@@ -31,6 +30,5 @@ void libc_current_sigrtmin_0100(void)
int main(int argc, char *argv[])
{
libc_current_sigrtmin_0100();
return t_status;
}
\ No newline at end of file
......@@ -13,11 +13,8 @@
* limitations under the License.
*/
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <sys/time.h>
#include <errno.h>
#include "functionalext.h"
static int count = 0;
......
......@@ -13,8 +13,8 @@
* limitations under the License.
*/
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/stat.h>
#include "functionalext.h"
/**
......@@ -24,7 +24,6 @@
*/
void chmod_0100(void)
{
struct stat buf;
open("test.txt", O_RDWR | O_CREAT);
int result = chmod("test.txt",
......@@ -60,36 +59,10 @@ void chmod_0200(void)
*/
void chmod_0300(void)
{
char filename[80];
char buf[100] = "";
int file;
gets(filename);
file = creat(filename, 0);
int num = chmod("data/AAA.txt",
int result = chmod("data/AAA.txt",
S_ISUID | S_ISGID | S_ISVTX | S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH |
S_IXOTH);
EXPECT_EQ("chmod_0300", num, -1);
struct stat res;
stat("/data/AAA.txt", &res);
}
/*
* @tc.name : chmod_0400
* @tc.desc : Verify that file permissions cannot be modified (parameter invalid)
* @tc.level : Level 2
*/
void chmod_0400(void)
{
char filename[80];
char buf[100] = "";
int file;
gets(filename);
file = creat(filename, 0);
int num = chmod("data/test.txt", -0000);
EXPECT_EQ("chmod_0400", num, -1);
struct stat res;
stat("/data/AAA.txt", &res);
remove("data/test.txt");
EXPECT_EQ("chmod_0300", result, -1);
}
int main(int argc, char *argv[])
......@@ -97,7 +70,5 @@ int main(int argc, char *argv[])
chmod_0100();
chmod_0200();
chmod_0300();
chmod_0400();
return t_status;
}
\ No newline at end of file
......@@ -14,14 +14,9 @@
*/
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include "functionalext.h"
typedef void (*TEST_FUN)();
int success = 36863;
int SUCCESS = 33279;
int failed = -1;
......
......@@ -14,48 +14,58 @@
*/
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <signal.h>
#include <sys/vfs.h>
#include <sys/statfs.h>
#include <unistd.h>
#include "functionalext.h"
const int32_t COUNT_ZERO = 0;
const int32_t COUNT_NEGATIVE = -1;
#include <sys/statvfs.h>
#include "test.h"
/**
* @tc.name : fstatvfs_0100
* @tc.desc : Verify that file system statistics can be obtained (all parameters are valid)
* @tc.desc : Returns the same information about an open file referenced by descriptor fd
* @tc.level : Level 0
*/
void fstatvfs_0100(void)
{
struct statvfs buff;
int result;
int fd = open("test.txt", O_RDWR | O_CREAT);
result = fstatvfs(fd, &buff);
EXPECT_EQ("fstatvfs_0100", result, COUNT_ZERO);
struct statvfs sts;
int fd = open("/proc", O_RDONLY);
if (fd < 0) {
t_error("%s open failed\n", __func__);
}
int result = fstatvfs(fd, &sts);
if (result != 0) {
t_error("%s fstatvfs failed\n", __func__);
}
close(fd);
remove("test.txt");
if (sts.f_bsize != 4096U) {
t_error("%s f_bsize invalid\n", __func__);
}
if (sts.f_bfree != 0U) {
t_error("%s f_bfree invalid\n", __func__);
}
if (sts.f_ffree != 0U) {
t_error("%s f_ffree invalid\n", __func__);
}
if (sts.f_fsid != 0U) {
t_error("%s f_fsid invalid\n", __func__);
}
if (sts.f_namemax != 255U) {
t_error("%s f_namemax invalid\n", __func__);
}
}
/**
* @tc.name : fstatvfs_0200
* @tc.desc : Verify that file system statistics cannot be obtained (fd argument is invalid)
* @tc.desc : Test case when parameter is invalid
* @tc.level : Level 2
*/
void fstatvfs_0200(void)
{
struct statvfs buff;
int result;
int fd = open("test.txt", O_RDWR | O_CREAT);
result = fstatvfs(-1, &buff);
EXPECT_EQ("fstatvfs_0200", result, COUNT_NEGATIVE);
close(fd);
remove("test.txt");
struct statvfs sts;
int result = fstatvfs(-1, &sts);
if (result != -1) {
t_error("%s fstatvfs should be failed\n", __func__);
}
}
int main(int argc, char *argv[])
......
......@@ -14,77 +14,117 @@
*/
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <unistd.h>
#include "functionalext.h"
#include "test.h"
const int32_t COUNT_ZERO = 0;
const int32_t COUNT_NEGATIVE = -1;
const char *path = "/data/file.txt";
const char *path = "/data";
/**
* @tc.name : futimesat_0100
* @tc.desc : Verify that you can set the file access time and modify time (valid parameters, times is not 0)
* @tc.desc : Change timestamps of a file relative to a directory file descriptor
* @tc.level : Level 0
*/
void futimesat_0100(void)
{
int result = 10;
int fd = open(path, O_RDWR | O_CREAT);
result = futimesat(fd, path, NULL);
EXPECT_EQ("futimesat_0100", result, COUNT_ZERO);
int dir_fd = open(path, O_RDONLY | O_DIRECTORY);
if (dir_fd < 0) {
t_error("%s open failed\n", __func__);
}
int fd = openat(dir_fd, "test.txt", O_CREAT | O_RDWR | O_EXCL, 0666);
if (fd < 0) {
t_error("%s openat failed\n", __func__);
}
write(fd, "helloworld", 5);
struct stat st1;
if (fstat(fd, &st1) != 0) {
t_error("%s fstat failed\n", __func__);
}
close(fd);
remove(path);
struct timeval tv[2];
tv[0].tv_sec = st1.st_atime + 1;
tv[0].tv_usec = 0;
tv[1].tv_sec = st1.st_mtime + 1;
tv[1].tv_usec = 0;
int result = futimesat(dir_fd, "test.txt", tv);
if (result != 0) {
t_error("%s futimesat failed\n", __func__);
}
struct stat st2;
if (fstatat(dir_fd, "test.txt", &st2, 0) != 0) {
t_error("%s fstatat failed\n", __func__);
}
if (st2.st_mtime != tv[1].tv_sec) {
t_error("%s stat shows different mtime\n", __func__);
}
if (unlinkat(dir_fd, "test.txt", 0) != 0) {
t_error("%s unlinkat failed\n", __func__);
}
close(dir_fd);
}
/**
* @tc.name : futimesat_0200
* @tc.desc : Verify that you can set the file access time and modify time (valid parameters, times is 0)
* @tc.desc : Test the return value of the function when timeval is NULL
* @tc.level : Level 1
*/
void futimesat_0200(void)
{
int result = 10;
int fd = open(path, O_RDWR | O_CREAT);
result = futimesat(fd, path, 0);
EXPECT_EQ("futimesat_0200", result, COUNT_ZERO);
close(fd);
remove(path);
int dir_fd = open(path, O_RDONLY | O_DIRECTORY);
if (dir_fd < 0) {
t_error("%s open failed\n", __func__);
}
int fd = openat(dir_fd, "test.txt", O_CREAT | O_RDWR | O_EXCL, 0666);
if (fd < 0) {
t_error("%s openat failed\n", __func__);
}
int result = futimesat(dir_fd, "test.txt", NULL);
if (result != 0) {
t_error("%s futimesat failed\n", __func__);
}
if (unlinkat(dir_fd, "test.txt", 0) != 0) {
t_error("%s unlinkat failed\n", __func__);
}
close(dir_fd);
}
/**
* @tc.name : futimesat_0300
* @tc.desc : Verify that file access time and modification time cannot be set (the dirfd parameter is invalid)
* @tc.desc : Test the return value of the function when dirfd is invalid
* @tc.level : Level 2
*/
void futimesat_0300(void)
{
int result = 10;
int fd = open(path, O_RDWR | O_CREAT);
close(fd);
remove(path);
result = futimesat(fd, path, NULL);
EXPECT_EQ("futimesat_0300", result, COUNT_NEGATIVE);
int result = futimesat(-1, "test.txt", NULL);
if (result != -1) {
t_error("%s futimesat should be failed\n", __func__);
}
}
/**
* @tc.name : futimesat_0400
* @tc.desc : Validation cannot set file access time and modify time (pathname parameter invalid)
* @tc.desc : Test the return value of the function when pathname is invalid
* @tc.level : Level 2
*/
void futimesat_0400(void)
{
int result = 10;
int fd = open(path, O_RDWR | O_CREAT);
result = futimesat(fd, "", NULL);
EXPECT_EQ("futimesat_0400", result, COUNT_NEGATIVE);
close(fd);
remove(path);
int result = futimesat(AT_FDCWD, NULL, NULL);
if (result != -1) {
t_error("%s futimesat should be failed\n", __func__);
}
}
int main(int argc, char *argv[])
......
......@@ -13,51 +13,46 @@
* limitations under the License.
*/
#include <stdio.h>
#include <stdio_ext.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdbool.h>
#include "functionalext.h"
const size_t COUNT_ZERO = 0;
/**
* @tc.name : __fbufsize_0100
* @tc.desc : Verify that you can get the size of the buffer used by the file
(In bytes. Valid, file size greater than 0)
* @tc.desc : Returns the size of the buffer currently used by the given stream
* @tc.level : Level 0
*/
void __fbufsize_0100(void)
{
bool flag = false;
FILE *fptr = fopen("test.txt", "w+");
fwrite("1", 1, 1, fptr);
size_t result = 0;
result = __fbufsize(fptr);
if (result > 0) {
flag = true;
}
EXPECT_TRUE("__fbufsize_0200", flag);
fclose(fptr);
remove("test.txt");
char buf[1024];
FILE *fp = fopen("/proc/version", "r");
EXPECT_PTRNE("__fbufsize_0100", fp, NULL);
int ret = setvbuf(fp, buf, _IOFBF, sizeof buf);
EXPECT_NE("__fbufsize_0100", ret, EOF);
size_t result = __fbufsize(fp);
EXPECT_TRUE("__fbufsize_0100", result <= sizeof buf);
fclose(fp);
}
/**
* @tc.name : __fbufsize_0200
* @tc.desc : Verify that you can get the size of the buffer used by the file
(In bytes. File size = 0)
* @tc.desc : Returns the size of the buffer currently used by the given stream when the file size is 0
* @tc.level : Level 0
*/
void __fbufsize_0200(void)
{
FILE *fptr = fopen("test.txt", "w+");
setbuf(fptr, NULL);
size_t result = 0;
result = __fbufsize(fptr);
EXPECT_EQ("__fbufsize_0200", result, COUNT_ZERO);
fclose(fptr);
remove("test.txt");
FILE *fp = fopen("/proc/version", "r");
EXPECT_PTRNE("__fbufsize_0200", fp, NULL);
int ret = setvbuf(fp, NULL, _IONBF, 0);
EXPECT_NE("__fbufsize_0100", ret, EOF);
size_t result = __fbufsize(fp);
EXPECT_EQ("__fbufsize_0200", result, 0U);
fclose(fp);
}
int main(int argc, char *argv[])
......
......@@ -13,69 +13,67 @@
* limitations under the License.
*/
#include <stdio.h>
#include <stdio_ext.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "functionalext.h"
const int32_t COUNT_ZERO = 0;
/**
* @tc.name : __flbf_0100
* @tc.desc : Verify file stream is row buffered (valid argument, is row buffered)
* @tc.desc : Line buffer test
* @tc.level : Level 0
*/
void __flbf_0100(void)
{
char buf[1024];
int result = 0;
bool flag = false;
FILE *fptr = fopen("test.txt", "w");
setvbuf(fptr, buf, _IOLBF, 1024);
result = __flbf(fptr);
if (result > 0) {
flag = true;
}
EXPECT_TRUE("__flbf_0100", flag);
fclose(fptr);
remove("test.txt");
char buf[BUFSIZ];
FILE *fp = fopen("/proc/version", "r");
EXPECT_PTRNE("__flbf_0100", fp, NULL);
int ret = setvbuf(fp, buf, _IOLBF, sizeof buf);
EXPECT_EQ("__flbf_0100", ret, 0);
int result = __flbf(fp);
EXPECT_TRUE("__flbf_0100", result);
fclose(fp);
}
/**
* @tc.name : __flbf_0200
* @tc.desc : Verify file stream is not row buffered (valid argument, is full buffered)
* @tc.level : Level 1
* @tc.desc : Full buffer test
* @tc.level : Level 2
*/
void __flbf_0200(void)
{
char buf[1024];
int result = 0;
FILE *fptr = fopen("test.txt", "w");
setvbuf(fptr, buf, _IOFBF, 1024);
result = __flbf(fptr);
EXPECT_EQ("__flbf_0200", result, COUNT_ZERO);
fclose(fptr);
remove("test.txt");
char buf[BUFSIZ];
FILE *fp = fopen("/proc/version", "r");
EXPECT_PTRNE("__flbf_0200", fp, NULL);
int ret = setvbuf(fp, buf, _IOFBF, sizeof buf);
EXPECT_EQ("__flbf_0200", ret, 0);
int result = __flbf(fp);
EXPECT_FALSE("__flbf_0200", result);
fclose(fp);
}
/**
* @tc.name : __flbf_0300
* @tc.desc :Verify file stream is not row buffered (parameter valid, is not buffered)
* @tc.level : Level 1
* @tc.desc : Unbuffered test
* @tc.level : Level 2
*/
void __flbf_0300(void)
{
char buf[1024];
int result = 0;
FILE *fptr = fopen("test.txt", "w");
setvbuf(fptr, buf, _IONBF, 1024);
result = __flbf(fptr);
EXPECT_EQ("__flbf_0300", result, COUNT_ZERO);
fclose(fptr);
remove("test.txt");
char buf[BUFSIZ];
FILE *fp = fopen("/proc/version", "r");
EXPECT_PTRNE("__flbf_0300", fp, NULL);
int ret = setvbuf(fp, buf, _IONBF, sizeof buf);
EXPECT_EQ("__flbf_0300", ret, 0);
int result = __flbf(fp);
EXPECT_FALSE("__flbf_0300", result);
fclose(fp);
}
int main(int argc, char *argv[])
......
......@@ -13,10 +13,11 @@
* limitations under the License.
*/
#include <stdio.h>
#include <stdio_ext.h>
#include "functionalext.h"
const char *path = "/data/fpending.txt";
/**
* @tc.name : __fpending_0100
* @tc.desc : The parameter is valid, f is the file opened in w mode, there is data in the buffer,
......@@ -26,13 +27,16 @@
void __fpending_0100(void)
{
char *str = "This is a test";
FILE *fp = fopen("fpending.txt", "w");
FILE *fp = fopen(path, "w");
EXPECT_PTRNE("__fpending_0100", fp, NULL);
fputs(str, fp);
size_t ret = __fpending(fp);
EXPECT_TRUE("__fpending_0100", ret > 0);
EXPECT_EQ("__fpending_0100", ret, strlen(str));
fclose(fp);
remove("fpending.txt");
remove(path);
}
/**
......@@ -44,13 +48,16 @@ void __fpending_0100(void)
void __fpending_0200(void)
{
char *str = "This is a test";
FILE *fp = fopen("fpending.txt", "w");
FILE *fp = fopen(path, "w");
EXPECT_PTRNE("__fpending_0200", fp, NULL);
fputs(str, fp);
fflush(fp);
size_t ret = __fpending(fp);
EXPECT_EQ("__fpending_0200", ret, 0);
fclose(fp);
remove("fpending.txt");
remove(path);
}
/**
......@@ -62,14 +69,18 @@ void __fpending_0200(void)
void __fpending_0300(void)
{
char *str = "This is a test";
FILE *fp = fopen("fpending.txt", "w");
FILE *fp = fopen(path, "w");
EXPECT_PTRNE("__fpending_0300", fp, NULL);
fputs(str, fp);
fclose(fp);
FILE *ffp = fopen("fpending.txt", "r");
FILE *ffp = fopen(path, "r");
size_t ret = __fpending(ffp);
EXPECT_EQ("__fpending_0300", ret, 0);
fclose(ffp);
remove("fpending.txt");
remove(path);
}
int main(int argc, char *argv[])
......
......@@ -13,9 +13,7 @@
* limitations under the License.
*/
#include <stdio.h>
#include <stdio_ext.h>
#include <string.h>
#include "functionalext.h"
/**
......@@ -27,14 +25,17 @@ void __fpurge_0100()
{
char buf[100];
char *str = "This is a test";
FILE *fp = fopen("fpurge.txt", "w");
FILE *fp = fopen("/data/fpurge.txt", "w");
EXPECT_PTRNE("__fpurge_0100", fp, NULL);
fputs(str, fp);
size_t ret = __fpurge(fp);
fgets(buf, 100, fp);
EXPECT_EQ("__fpurge_0100", strstr(buf, str), 0);
EXPECT_EQ("__fpurge_0100", ret, 0);
fclose(fp);
remove("fpurge.txt");
remove("/data/fpurge.txt");
}
int main(int argc, char *argv[])
......
......@@ -13,10 +13,11 @@
* limitations under the License.
*/
#include <stdio.h>
#include <stdio_ext.h>
#include "functionalext.h"
const char *path = "/data/freadable.txt";
/**
* @tc.name : __freadable_0100
* @tc.desc : The parameters are valid, and the file can be judged to be readable.
......@@ -25,13 +26,17 @@
void __freadable_0100(void)
{
char buf[100];
FILE *fp = fopen("freadable.txt", "w");
FILE *fp = fopen(path, "w");
EXPECT_PTRNE("__freadable_0100", fp, NULL);
fclose(fp);
FILE *ffp = fopen("freadable.txt", "r");
FILE *ffp = fopen(path, "r");
EXPECT_PTRNE("__freadable_0100", ffp, NULL);
size_t ret = __freadable(ffp);
EXPECT_NE("__freadable_0100", ret, 0);
fclose(ffp);
remove("freadable.txt");
remove(path);
}
/**
......@@ -41,11 +46,14 @@ void __freadable_0100(void)
*/
void __freadable_0200(void)
{
FILE *fp = fopen("freadable.txt", "wb");
FILE *fp = fopen(path, "wb");
EXPECT_PTRNE("__freadable_0200", fp, NULL);
size_t ret = __freadable(fp);
EXPECT_EQ("__freadable_0200", ret, 0);
fclose(fp);
remove("freadable.txt");
remove(path);
}
int main(int argc, char *argv[])
......
......@@ -13,36 +13,24 @@
* limitations under the License.
*/
#include <stdio.h>
#include <stdio_ext.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "functionalext.h"
const int32_t COUNT_ZERO = 0;
/**
* @tc.name : __fseterr_0100
* @tc.desc : Validate errors that can specify streams (parameter valid)
* @tc.desc : Set stream in error
* @tc.level : Level 0
*/
void __fseterr_0100(void)
{
bool flag = false;
int result1, result2;
FILE *fptr = fopen("test.txt", "w+");
result1 = ferror(fptr);
__fseterr(fptr);
result2 = ferror(fptr);
EXPECT_EQ("__fseterr_0100", result1, COUNT_ZERO);
if (result2 != 0) {
flag = true;
}
EXPECT_TRUE("__fseterr_0100", flag);
fclose(fptr);
remove("test.txt");
FILE *fp = fopen("/dev/null", "w");
EXPECT_FALSE("__fseterr_0100", ferror(fp));
__fseterr(fp);
EXPECT_TRUE("__fseterr_0100", ferror(fp));
clearerr(fp);
EXPECT_FALSE("__fseterr_0100", ferror(fp));
fclose(fp);
}
int main(int argc, char *argv[])
......
......@@ -14,7 +14,6 @@
*/
#include <stdbool.h>
#include <stdio.h>
#include "functionalext.h"
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册