wip killed redirection
This commit is contained in:
78
tester.sh
78
tester.sh
@@ -1,20 +1,47 @@
|
||||
#!/bin/bash
|
||||
|
||||
path="mini_serv.c"
|
||||
if [ ! -z "$1" ]; then
|
||||
path="$1"
|
||||
fi
|
||||
|
||||
id=1
|
||||
test_directory="logs"
|
||||
mkdir -p "$test_directory"
|
||||
test_file_name="log"
|
||||
test_number=0
|
||||
GRAY="\e[0;30m"
|
||||
RED="\e[0;31m"
|
||||
GREEN="\e[0;32m"
|
||||
YELLOW="\e[0;33m"
|
||||
BLUE="\e[0;34m"
|
||||
PURPLE="\e[0;35m"
|
||||
CYAN="\e[0;36m"
|
||||
WHITE="\e[0;37m"
|
||||
|
||||
B_GRAY="\e[1;30m"
|
||||
B_RED="\e[1;31m"
|
||||
B_GREEN="\e[1;32m"
|
||||
B_YELLOW="\e[1;33m"
|
||||
B_BLUE="\e[1;34m"
|
||||
B_PURPLE="\e[1;35m"
|
||||
B_CYAN="\e[1;36m"
|
||||
B_WHITE="\e[1;37m"
|
||||
|
||||
COLOR_RESET="\e[0m"
|
||||
|
||||
path="mini_serv.c"
|
||||
compare_path="utils/mini_serv_luke.c"
|
||||
|
||||
port=0
|
||||
while [ $port -lt 1024 -o $port -gt 10000 ]; do
|
||||
port=$RANDOM
|
||||
done
|
||||
compare_port=0
|
||||
while [ $compare_port -lt 1024 -o $compare_port -gt 10000 ]; do
|
||||
compare_port=$RANDOM
|
||||
if [ $compare_port -eq $port ]; then
|
||||
compare_port=0
|
||||
fi
|
||||
done
|
||||
|
||||
id=1
|
||||
test_directory="logs"
|
||||
rm -rf "$test_directory"
|
||||
mkdir -p "$test_directory"
|
||||
test_file_name="log"
|
||||
test_number=0
|
||||
|
||||
|
||||
new_test() {
|
||||
@@ -22,23 +49,35 @@ new_test() {
|
||||
id=0
|
||||
((++test_number))
|
||||
test_file_name="test_$test_number"
|
||||
echo "" > $test_directory/$test_file_name.txt
|
||||
launch_client
|
||||
}
|
||||
# parameter 1 : text
|
||||
launch_client() {
|
||||
# my miniserv
|
||||
while read -r line
|
||||
do
|
||||
echo "received $id : $line"
|
||||
done < <(echo "$1" | nc localhost "$port" 2>&1) | sort >> $test_directory/$test_file_name.txt &
|
||||
# the compared miniserv
|
||||
while read -r line
|
||||
do
|
||||
echo "received $id : $line"
|
||||
done < <(echo "$1" | nc localhost "$compare_port" 2>&1) | sort >> $test_directory/${test_file_name}_compare.txt &
|
||||
((++id))
|
||||
}
|
||||
stop_last_client() {
|
||||
kill -KILL $(pidof nc | tr ' ' '\n' | head -n1)
|
||||
pid=$(pidof nc | tr ' ' '\n' | head -n1)
|
||||
kill -KILL $pid
|
||||
wait $pid 2>/dev/null
|
||||
pid=$(pidof nc | tr ' ' '\n' | head -n1)
|
||||
kill -KILL $pid
|
||||
wait $pid 2>/dev/null
|
||||
}
|
||||
|
||||
clang -Wall -Wextra -Werror $path 2>&1
|
||||
./a.out "$port" 2>&1 &
|
||||
clang -Wall -Wextra -Werror $path -o mini_serv 2>&1
|
||||
clang -Wall -Wextra -Werror $compare_path -o mini_serv_compare 2>&1
|
||||
./mini_serv "$port" 2>&1 &
|
||||
./mini_serv_compare "$compare_port" 2>&1 &
|
||||
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
@@ -104,5 +143,18 @@ do
|
||||
done
|
||||
|
||||
|
||||
|
||||
# COMPARE # # # # # # # # # # # # # # # # # # # #
|
||||
#
|
||||
number_of_tests=$((`ls -1 "$test_directory" | wc -l` / 2))
|
||||
for i in $(seq 1 $number_of_tests); do
|
||||
test_diff=$(diff -U 3 $test_directory/test_${i}.txt $test_directory/test_${i}_compare.txt)
|
||||
if [ -z "$test_diff" ]; then
|
||||
echo -e $B_GREEN"ok"$COLOR_RESET
|
||||
else
|
||||
echo -e $B_RED"ko"$COLOR_RESET
|
||||
fi
|
||||
done
|
||||
|
||||
killall -q a.out nc
|
||||
|
||||
|
||||
Reference in New Issue
Block a user