Fix server_epoll test

1. Change the port for server_poll to listen to avoid "address in use" conflict
between test/server and test/server_epoll, and add port as an argument for
test/client to send message
2. As posix-spwan may fail, change the fixed number of processes to spawn to
the number of processes successfully spawned in server_epoll
This commit is contained in:
He Sun 2019-09-26 07:41:56 +00:00 committed by Tate, Hongliang Tian
parent f414aa3eec
commit dba6467c2d
4 changed files with 20 additions and 12 deletions

@ -3,10 +3,10 @@ PROJECT_DIR := $(realpath $(CUR_DIR)/../)
BUILD_DIR := $(PROJECT_DIR)/build
# Dependencies: need to be compiled but not to run by any Makefile target
TEST_DEPS := dev_null
TEST_DEPS := dev_null client
# Tests: need to be compiled and run by test-% target
TESTS := empty env hello_world malloc mmap file getpid spawn sched pipe time \
truncate readdir mkdir link tls pthread uname rlimit client server \
truncate readdir mkdir link tls pthread uname rlimit server \
server_epoll unix_socket cout hostfs cpuid rdtsc device
# Benchmarks: need to be compiled and run by bench-% target
BENCHES := spawn_and_exit_latency pipe_throughput unix_socket_throughput

@ -13,8 +13,8 @@ int main(int argc, const char *argv[]) {
const char* message = "Hello world!";
int ret;
if (argc != 2) {
printf("usage: ./client <ipaddress>\n");
if (argc != 3) {
printf("usage: ./client <ipaddress> <port>\n");
return 0;
}
@ -27,7 +27,7 @@ int main(int argc, const char *argv[]) {
struct sockaddr_in servaddr;
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(6666);
servaddr.sin_port = htons((uint16_t)strtol(argv[2], NULL, 10));
ret = inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
if (ret <= 0) {

@ -37,7 +37,7 @@ int main(int argc, const char *argv[]) {
}
int client_pid;
char* client_argv[] = {"client", "127.0.0.1", NULL};
char* client_argv[] = {"client", "127.0.0.1", "6666", NULL};
ret = posix_spawn(&client_pid, "/bin/client", NULL, NULL, client_argv, NULL);
if (ret < 0) {
printf("spawn client process error: %s(errno: %d)\n", strerror(errno), errno);

@ -12,6 +12,7 @@
#include <spawn.h>
#define MAXEVENTS 64
#define DEFAULT_PROC_NUM 3
static int
create_and_bind() {
@ -25,7 +26,7 @@ create_and_bind() {
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(6666);
servaddr.sin_port = htons(6667);
int ret = bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr));
if (ret < 0) {
@ -65,18 +66,25 @@ main(int argc, char *argv[]) {
// spawn clients
int client_pid;
char* client_argv[] = {"client", "127.0.0.1", NULL};
for(int i=0; i<3; ++i) {
int proc_num = DEFAULT_PROC_NUM;
char* client_argv[] = {"client", "127.0.0.1", "6667", NULL};
for(int i=0; i<DEFAULT_PROC_NUM; ++i) {
int ret = posix_spawn(&client_pid, "/bin/client", NULL, NULL, client_argv, NULL);
if (ret < 0) {
printf("spawn client process error: %s(errno: %d)\n", strerror(errno), errno);
return -1;
printf("spawn client process error: %s(errno: %d), %d process(es) spawned\n", strerror(errno), errno, i);
if (i == 0) {
perror("no client is successfully spawned");
return -1;
} else {
proc_num = i;
break;
}
}
}
/* The event loop */
int done_count = 0;
while (done_count < 3) {
while (done_count < proc_num) {
int n = epoll_wait(efd, events, MAXEVENTS, -1);
for (int i = 0; i < n; i++) {
if ((events[i].events & EPOLLERR) ||