From f04d3d86eab8807861fc6058cc460a523fc767f4 Mon Sep 17 00:00:00 2001 From: ubuntu201711081 <201711081@jbnu.ac.kr> Date: Sun, 6 Dec 2020 06:22:56 +0000 Subject: [PATCH] add bash script for test --- .gitignore | 4 ++-- Makefile | 11 +++++------ pstest.sh | 3 --- test.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ testdata/list.txt | 1 + testdata/test.txt | 1 + 6 files changed, 54 insertions(+), 11 deletions(-) delete mode 100755 pstest.sh create mode 100755 test.sh create mode 100644 testdata/list.txt create mode 100755 testdata/test.txt diff --git a/.gitignore b/.gitignore index 277cf8d..533743c 100644 --- a/.gitignore +++ b/.gitignore @@ -54,10 +54,10 @@ dkms.conf #Bin bin/* -client_test/* -server_test/* +tmp/* p-client p-server server client +slowclient \ No newline at end of file diff --git a/Makefile b/Makefile index 78862e9..1d8275e 100644 --- a/Makefile +++ b/Makefile @@ -23,14 +23,13 @@ p-mulclient: socket_wrapper.o p-client.c slowclient: socket_wrapper.o client.c $(CC) -o slowclient client.c socket_wrapper.o $(CFLAGS) -D SLOW_CLIENT=1000 -.PHONY: clean moveall +.PHONY: clean test clean: rm *.o $(Bin) rm $(addprefix client_test/,$(ClientBin)) rm $(addprefix server_test/,$(ServerBin)) -moveall: - mv client client_test/client - mv p-client client_test/p-client - mv server server_test/server - mv p-server server_test/p-server \ No newline at end of file +test: + make all + make slowclient + ./test.sh \ No newline at end of file diff --git a/pstest.sh b/pstest.sh deleted file mode 100755 index 47ae48e..0000000 --- a/pstest.sh +++ /dev/null @@ -1,3 +0,0 @@ -#! /bin/bash -cd server_test -./server \ No newline at end of file diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..7b45319 --- /dev/null +++ b/test.sh @@ -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 \ No newline at end of file diff --git a/testdata/list.txt b/testdata/list.txt new file mode 100644 index 0000000..4871fd5 --- /dev/null +++ b/testdata/list.txt @@ -0,0 +1 @@ +test.txt diff --git a/testdata/test.txt b/testdata/test.txt new file mode 100755 index 0000000..796aac7 --- /dev/null +++ b/testdata/test.txt @@ -0,0 +1 @@ +teststring