Fix the compiler's warnings in make test with glibc
This commit is contained in:
parent
b2b86b796a
commit
33876e122f
@ -1,3 +1,4 @@
|
|||||||
|
#define _GNU_SOURCE
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -94,16 +95,11 @@ int client_sendmsg(int server_fd, char *buf) {
|
|||||||
|
|
||||||
#ifdef __GLIBC__
|
#ifdef __GLIBC__
|
||||||
|
|
||||||
struct mmsghdr {
|
|
||||||
struct msghdr msg;
|
|
||||||
unsigned int len;
|
|
||||||
};
|
|
||||||
|
|
||||||
int client_sendmmsg(int server_fd, char *buf) {
|
int client_sendmmsg(int server_fd, char *buf) {
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct mmsghdr msg_v[2] = {};
|
struct mmsghdr msg_v[2] = {};
|
||||||
struct iovec iov[1];
|
struct iovec iov[1];
|
||||||
struct msghdr *msg_ptr = &msg_v[0].msg;
|
struct msghdr *msg_ptr = &msg_v[0].msg_hdr;
|
||||||
|
|
||||||
// Set msg0
|
// Set msg0
|
||||||
msg_ptr->msg_name = NULL;
|
msg_ptr->msg_name = NULL;
|
||||||
@ -118,14 +114,15 @@ int client_sendmmsg(int server_fd, char *buf) {
|
|||||||
|
|
||||||
// Set msg1
|
// Set msg1
|
||||||
msg_v[1] = msg_v[0];
|
msg_v[1] = msg_v[0];
|
||||||
msg_ptr = &msg_v[1].msg;
|
msg_ptr = &msg_v[1].msg_hdr;
|
||||||
msg_ptr->msg_iov = NULL;
|
msg_ptr->msg_iov = NULL;
|
||||||
msg_ptr->msg_iovlen = 0;
|
msg_ptr->msg_iovlen = 0;
|
||||||
|
|
||||||
ret = sendmmsg(server_fd, msg_v, 2, 0);
|
ret = sendmmsg(server_fd, msg_v, 2, 0);
|
||||||
if (ret != 2 || msg_v[0].len <= 0 || msg_v[1].len != 0) {
|
if (ret != 2 || msg_v[0].msg_len <= 0 || msg_v[1].msg_len != 0) {
|
||||||
THROW_ERROR("sendmsg failed");
|
THROW_ERROR("sendmsg failed");
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#define _GNU_SOURCE
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -158,7 +159,9 @@ int test_dev_fd() {
|
|||||||
if (fd_str == NULL) {
|
if (fd_str == NULL) {
|
||||||
THROW_ERROR("calloc failed");
|
THROW_ERROR("calloc failed");
|
||||||
}
|
}
|
||||||
asprintf(&fd_str, "%d", fd);
|
if (asprintf(&fd_str, "%d", fd) < 0) {
|
||||||
|
THROW_ERROR("failed to asprintf");
|
||||||
|
}
|
||||||
strcat(dev_fd_path, fd_str);
|
strcat(dev_fd_path, fd_str);
|
||||||
int dev_fd = open(dev_fd_path, O_WRONLY, 0666);
|
int dev_fd = open(dev_fd_path, O_WRONLY, 0666);
|
||||||
if (dev_fd < 0) {
|
if (dev_fd < 0) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
include ../test_common.mk
|
include ../test_common.mk
|
||||||
|
|
||||||
EXTRA_C_FLAGS := -Wno-incompatible-pointer-types-discards-qualifiers
|
EXTRA_C_FLAGS := -Wno-incompatible-pointer-types-discards-qualifiers -Wno-unused-result
|
||||||
EXTRA_LINK_FLAGS := -lpthread
|
EXTRA_LINK_FLAGS := -lpthread
|
||||||
BIN_ARGS :=
|
BIN_ARGS :=
|
||||||
|
@ -45,7 +45,8 @@ int test_execve_error_return(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// during the time, try execve a non-exit process
|
// during the time, try execve a non-exit process
|
||||||
int ret = execve("/bin/joke", NULL, NULL);
|
char *args[] = {"joke", NULL};
|
||||||
|
int ret = execve("/bin/joke", args, NULL);
|
||||||
if (ret != -1 || errno != ENOENT) {
|
if (ret != -1 || errno != ENOENT) {
|
||||||
THROW_ERROR("execve error code wrong");
|
THROW_ERROR("execve error code wrong");
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#define _GNU_SOURCE
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -5,7 +6,6 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#define _GNU_SOURCE
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -547,9 +547,11 @@ int test_ioctl_FIOCLEX(void) {
|
|||||||
child_argv[0] = strdup("naughty_child");
|
child_argv[0] = strdup("naughty_child");
|
||||||
child_argv[1] = strdup("-t");
|
child_argv[1] = strdup("-t");
|
||||||
child_argv[2] = strdup("fioclex");
|
child_argv[2] = strdup("fioclex");
|
||||||
asprintf(&child_argv[3], "%d", fd);
|
if (asprintf(&child_argv[3], "%d", fd) < 0 ||
|
||||||
asprintf(&child_argv[4], "%d", pipefds[0]);
|
asprintf(&child_argv[4], "%d", pipefds[0]) < 0 ||
|
||||||
asprintf(&child_argv[5], "%d", pipefds[1]);
|
asprintf(&child_argv[5], "%d", pipefds[1]) < 0) {
|
||||||
|
THROW_ERROR("failed to call asprintf");
|
||||||
|
}
|
||||||
|
|
||||||
ret = posix_spawn(&child_pid, "/bin/naughty_child", NULL, NULL, child_argv, NULL);
|
ret = posix_spawn(&child_pid, "/bin/naughty_child", NULL, NULL, child_argv, NULL);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
|
@ -12,10 +12,15 @@ char *read_resolv_conf(void) {
|
|||||||
fseek(fp, 0, SEEK_SET);
|
fseek(fp, 0, SEEK_SET);
|
||||||
char *resolv_conf_buffer = malloc(fsize + 1);
|
char *resolv_conf_buffer = malloc(fsize + 1);
|
||||||
if (resolv_conf_buffer == NULL) {
|
if (resolv_conf_buffer == NULL) {
|
||||||
printf("ERROR: Failed to malloc for /etc/resolv.conf buffer");
|
printf("ERROR: Failed to malloc for /etc/resolv.conf buffer\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
size_t len = fread(resolv_conf_buffer, 1, fsize, fp);
|
||||||
|
if (len != fsize) {
|
||||||
|
printf("ERROR: failed to fread correct len\n");
|
||||||
|
fclose(fp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
fread(resolv_conf_buffer, 1, fsize, fp);
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return resolv_conf_buffer;
|
return resolv_conf_buffer;
|
||||||
}
|
}
|
||||||
@ -45,4 +50,4 @@ static test_case_t test_cases[] = {
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
return test_suite_run(test_cases, ARRAY_SIZE(test_cases));
|
return test_suite_run(test_cases, ARRAY_SIZE(test_cases));
|
||||||
}
|
}
|
||||||
|
@ -381,7 +381,7 @@ int test_poll() {
|
|||||||
char buf[512];
|
char buf[512];
|
||||||
if ((count = read(client_fd, buf, sizeof buf)) != 0) {
|
if ((count = read(client_fd, buf, sizeof buf)) != 0) {
|
||||||
if (strcmp(buf, DEFAULT_MSG) != 0) {
|
if (strcmp(buf, DEFAULT_MSG) != 0) {
|
||||||
printf(buf);
|
printf("%s", buf);
|
||||||
THROW_ERROR("msg mismatched");
|
THROW_ERROR("msg mismatched");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -160,8 +160,8 @@ int verify_child_echo(int *connected_sockets) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char actual_str[32] = {0};
|
char actual_str[32] = {0};
|
||||||
read(connected_sockets[1], actual_str, 32);
|
ssize_t len = read(connected_sockets[1], actual_str, 32);
|
||||||
if (strncmp(actual_str, ECHO_MSG, sizeof(ECHO_MSG) - 1) != 0) {
|
if (len != sizeof(ECHO_MSG) || strncmp(actual_str, ECHO_MSG, strlen(ECHO_MSG)) != 0) {
|
||||||
printf("data read is :%s\n", actual_str);
|
printf("data read is :%s\n", actual_str);
|
||||||
THROW_ERROR("received string is not as expected");
|
THROW_ERROR("received string is not as expected");
|
||||||
}
|
}
|
||||||
@ -269,7 +269,9 @@ int test_poll() {
|
|||||||
THROW_ERROR("socketpair failed");
|
THROW_ERROR("socketpair failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
write(socks[0], "not today\n", 10);
|
if (write(socks[0], "not today\n", 10) < 0) {
|
||||||
|
THROW_ERROR("failed to write to socket");
|
||||||
|
}
|
||||||
|
|
||||||
struct pollfd polls[] = {
|
struct pollfd polls[] = {
|
||||||
{ .fd = socks[0], .events = POLLOUT },
|
{ .fd = socks[0], .events = POLLOUT },
|
||||||
@ -358,8 +360,8 @@ int test_ioctl_fionread() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char actual_str[32] = {0};
|
char actual_str[32] = {0};
|
||||||
read(sockets[1], actual_str, 32);
|
ssize_t len = read(sockets[1], actual_str, 32);
|
||||||
if (strncmp(actual_str, ECHO_MSG, sizeof(ECHO_MSG) - 1) != 0) {
|
if (len != sizeof(ECHO_MSG) || strncmp(actual_str, ECHO_MSG, strlen(ECHO_MSG)) != 0) {
|
||||||
printf("data read is :%s\n", actual_str);
|
printf("data read is :%s\n", actual_str);
|
||||||
THROW_ERROR("received string is not as expected");
|
THROW_ERROR("received string is not as expected");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user