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:
parent
f414aa3eec
commit
dba6467c2d
@ -3,10 +3,10 @@ PROJECT_DIR := $(realpath $(CUR_DIR)/../)
|
|||||||
BUILD_DIR := $(PROJECT_DIR)/build
|
BUILD_DIR := $(PROJECT_DIR)/build
|
||||||
|
|
||||||
# Dependencies: need to be compiled but not to run by any Makefile target
|
# 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: need to be compiled and run by test-% target
|
||||||
TESTS := empty env hello_world malloc mmap file getpid spawn sched pipe time \
|
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
|
server_epoll unix_socket cout hostfs cpuid rdtsc device
|
||||||
# Benchmarks: need to be compiled and run by bench-% target
|
# Benchmarks: need to be compiled and run by bench-% target
|
||||||
BENCHES := spawn_and_exit_latency pipe_throughput unix_socket_throughput
|
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!";
|
const char* message = "Hello world!";
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (argc != 2) {
|
if (argc != 3) {
|
||||||
printf("usage: ./client <ipaddress>\n");
|
printf("usage: ./client <ipaddress> <port>\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ int main(int argc, const char *argv[]) {
|
|||||||
struct sockaddr_in servaddr;
|
struct sockaddr_in servaddr;
|
||||||
memset(&servaddr, 0, sizeof(servaddr));
|
memset(&servaddr, 0, sizeof(servaddr));
|
||||||
servaddr.sin_family = AF_INET;
|
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);
|
ret = inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
|
@ -37,7 +37,7 @@ int main(int argc, const char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int client_pid;
|
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);
|
ret = posix_spawn(&client_pid, "/bin/client", NULL, NULL, client_argv, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
printf("spawn client process error: %s(errno: %d)\n", strerror(errno), errno);
|
printf("spawn client process error: %s(errno: %d)\n", strerror(errno), errno);
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include <spawn.h>
|
#include <spawn.h>
|
||||||
|
|
||||||
#define MAXEVENTS 64
|
#define MAXEVENTS 64
|
||||||
|
#define DEFAULT_PROC_NUM 3
|
||||||
|
|
||||||
static int
|
static int
|
||||||
create_and_bind() {
|
create_and_bind() {
|
||||||
@ -25,7 +26,7 @@ create_and_bind() {
|
|||||||
memset(&servaddr, 0, sizeof(servaddr));
|
memset(&servaddr, 0, sizeof(servaddr));
|
||||||
servaddr.sin_family = AF_INET;
|
servaddr.sin_family = AF_INET;
|
||||||
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
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));
|
int ret = bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@ -65,18 +66,25 @@ main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
// spawn clients
|
// spawn clients
|
||||||
int client_pid;
|
int client_pid;
|
||||||
char* client_argv[] = {"client", "127.0.0.1", NULL};
|
int proc_num = DEFAULT_PROC_NUM;
|
||||||
for(int i=0; i<3; ++i) {
|
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);
|
int ret = posix_spawn(&client_pid, "/bin/client", NULL, NULL, client_argv, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
printf("spawn client process error: %s(errno: %d)\n", strerror(errno), errno);
|
printf("spawn client process error: %s(errno: %d), %d process(es) spawned\n", strerror(errno), errno, i);
|
||||||
return -1;
|
if (i == 0) {
|
||||||
|
perror("no client is successfully spawned");
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
proc_num = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The event loop */
|
/* The event loop */
|
||||||
int done_count = 0;
|
int done_count = 0;
|
||||||
while (done_count < 3) {
|
while (done_count < proc_num) {
|
||||||
int n = epoll_wait(efd, events, MAXEVENTS, -1);
|
int n = epoll_wait(efd, events, MAXEVENTS, -1);
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
if ((events[i].events & EPOLLERR) ||
|
if ((events[i].events & EPOLLERR) ||
|
||||||
|
Loading…
Reference in New Issue
Block a user