HW12/test.sh
2020-12-06 06:42:27 +00:00

45 lines
960 B
Bash
Executable File

#! /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