Compare commits

...

4 Commits

Author SHA1 Message Date
ubuntu201711081 f04d3d86ea add bash script for test 2020-12-06 06:42:27 +00:00
ubuntu201711081 0b148fe3f0 chg bench readable measure 2020-12-06 05:25:42 +00:00
ubuntu201711081 ee2310cb39 add client get input from pipe 2020-12-06 05:19:22 +00:00
ubuntu201711081 7cf9f22037 change client option name 2020-12-06 04:12:20 +00:00
8 changed files with 77 additions and 20 deletions

4
.gitignore vendored
View File

@ -54,10 +54,10 @@ dkms.conf
#Bin #Bin
bin/* bin/*
client_test/* tmp/*
server_test/*
p-client p-client
p-server p-server
server server
client client
slowclient

View File

@ -23,14 +23,13 @@ p-mulclient: socket_wrapper.o p-client.c
slowclient: socket_wrapper.o client.c slowclient: socket_wrapper.o client.c
$(CC) -o slowclient client.c socket_wrapper.o $(CFLAGS) -D SLOW_CLIENT=1000 $(CC) -o slowclient client.c socket_wrapper.o $(CFLAGS) -D SLOW_CLIENT=1000
.PHONY: clean moveall .PHONY: clean test
clean: clean:
rm *.o $(Bin) rm *.o $(Bin)
rm $(addprefix client_test/,$(ClientBin)) rm $(addprefix client_test/,$(ClientBin))
rm $(addprefix server_test/,$(ServerBin)) rm $(addprefix server_test/,$(ServerBin))
moveall: test:
mv client client_test/client make all
mv p-client client_test/p-client make slowclient
mv server server_test/server ./test.sh
mv p-server server_test/p-server

View File

@ -16,7 +16,7 @@ Server OPTION and arguments:
Client option and arguments: Client option and arguments:
- `-b` or `--benchmark` :benchmark mode - `-b` or `--benchmark` :benchmark mode
- `--nogui` :no progress bar - `-nv` or `--no-verbose` :no progress bar
Available macro: Available macro:

View File

@ -133,6 +133,7 @@ int recvFile(int sock, const char * filename,size_t file_size){
DisplayProgressBar100Percent(file_size); DisplayProgressBar100Percent(file_size);
END: END:
free(buf); free(buf);
close(fd);
return return_value; return return_value;
} }
@ -198,6 +199,9 @@ static inline struct timespec timespec_sub(struct timespec a,struct timespec b){
return ret; return ret;
} }
static char filename_buf[1024];
static bool stdinisatty;
int main(int argc, const char *argv[]){ int main(int argc, const char *argv[]){
struct sockaddr_in addr; struct sockaddr_in addr;
const char * filename; const char * filename;
@ -207,27 +211,26 @@ int main(int argc, const char *argv[]){
int sock, err; int sock, err;
int retval = 0; int retval = 0;
init_bench_data(); init_bench_data();
stdinisatty = isatty(STDIN_FILENO);
if (argc < (stdinisatty ? 4 : 3)){
if (argc < 4){
fprintf(stderr,"USAUE: %s SERVERNAME PORT [Option]... [FILENAME]...\n",argv[0]); fprintf(stderr,"USAUE: %s SERVERNAME PORT [Option]... [FILENAME]...\n",argv[0]);
return 1; return 1;
} }
server_name = argv[1]; server_name = argv[1];
server_port = atoi(argv[2]); server_port = atoi(argv[2]);
for(;;){ while(arg_filename_start < argc){
if (strcmp("-b",argv[arg_filename_start])==0 if (strcmp("-b",argv[arg_filename_start])==0
||strcmp("--benchmark",argv[arg_filename_start])==0){ ||strcmp("--benchmark",argv[arg_filename_start])==0){
arg_filename_start++; arg_filename_start++;
bench.benchmode = true; bench.benchmode = true;
} }
else if(strcmp("--nogui",argv[arg_filename_start])==0){ else if(strcmp("-nv",argv[arg_filename_start]) == 0||strcmp("--no-verbose",argv[arg_filename_start])==0){
arg_filename_start++; arg_filename_start++;
DisplayProgress = false; DisplayProgress = false;
} }
else break; else break;
} }
if (server_port == 0){ if (server_port == 0){
fprintf(stderr,"port invalid\n"); fprintf(stderr,"port invalid\n");
return 1; return 1;
@ -251,8 +254,19 @@ int main(int argc, const char *argv[]){
if (bench.benchmode){ if (bench.benchmode){
clock_gettime(bench.clock_id,&bench.begin); clock_gettime(bench.clock_id,&bench.begin);
} }
while (arg_filename_start < argc){ for (;;){
filename = argv[arg_filename_start++]; if (stdinisatty){
if (arg_filename_start >= argc) break;
filename = argv[arg_filename_start++];
}
else{
//unsafe.
int t = fscanf(stdin,"%s",filename_buf);
if (t != 1) break;
filename = filename_buf;
}
fprintf(stdout,"request %s\n",filename);
sock = socket(AF_INET,SOCK_STREAM,0); sock = socket(AF_INET,SOCK_STREAM,0);
if(sock < 0){ if(sock < 0){
perror("sock create fail"); perror("sock create fail");
@ -278,7 +292,7 @@ int main(int argc, const char *argv[]){
if (result.tv_sec == 0) avg = result.tv_nsec; if (result.tv_sec == 0) avg = result.tv_nsec;
else avg = result.tv_sec * 1e9 + result.tv_nsec; else avg = result.tv_sec * 1e9 + result.tv_nsec;
avg /= bench.op_count; avg /= bench.op_count;
fprintf(stdout,"operation: %lf ns/op\n",avg); fprintf(stdout,"operation: %lf us/op\n",avg / 1000.0);
fprintf(stdout,"resolution: %ld sec %ld ns\n",bench.resolution.tv_sec,bench.resolution.tv_nsec); fprintf(stdout,"resolution: %ld sec %ld ns\n",bench.resolution.tv_sec,bench.resolution.tv_nsec);
} }

View File

@ -1,3 +0,0 @@
#! /bin/bash
cd server_test
./server

45
test.sh Executable file
View File

@ -0,0 +1,45 @@
#! /bin/bash
function do_test(){
local testname=$1
if [ $? -eq 0 ];then
echo -e "${testname} test \e[92m[success]\e[0m"
else
echo -e "${testname} test \e[91m[fail\e[0m"
fi
}
cd testdata
../server &
server_pid=$!
sleep 1
cd ../tmp
../client localhost 9091 test.txt
do_test "normal"
../client localhost 9091 notexistfile.txt
do_test "notexistfile"
echo test.txt | ../client localhost 9091
do_test "pipeinput"
../slowclient localhost 9091 test.txt &
process_id1=$!
../p-client localhost 9091 test.txt &
process_id2=$!
../p-client localhost 9091 test.txt &
process_id3=$!
wait $process_id1
return_code1=$?
wait $process_id2
return_code2=$?
wait $process_id3
return_code3=$?
if [ $return_code1 -eq 0 -a $return_code2 -eq 0 -a $return_code3 -eq 0 ];then
echo -e "multiconnection test \e[92m[success]\e[0m"
else
echo -e "multiconnection test \e[91m[fail\e[0m"
fi
rm *.txt
echo turn off server :$server_pid
kill $server_pid

1
testdata/list.txt vendored Normal file
View File

@ -0,0 +1 @@
test.txt

1
testdata/test.txt vendored Executable file
View File

@ -0,0 +1 @@
teststring