Skip to content

Instantly share code, notes, and snippets.

@jpdias
Last active March 22, 2021 19:32
Show Gist options
  • Select an option

  • Save jpdias/5e5e8ec1283d481642de44a150018304 to your computer and use it in GitHub Desktop.

Select an option

Save jpdias/5e5e8ec1283d481642de44a150018304 to your computer and use it in GitHub Desktop.
Validation script for SOPE 2021, Group Work #2
#!/usr/bin/env bash
show_usage() {
echo "Usage: $0 <test_no> || $0 clean"
exit 1
}
echo ":::::::: SOPE 2020/2021 MT2 ::::::::"
clean() {
echo "Cleaning logs"
rm -rf /tmp/fifo_"${USER}"
rm -f server_log.txt client_log.txt
rm -f client_stderr.txt server_stderr.txt
echo "Done"
}
case "$1" in
# invalid arguments
clean) clean; exit;;
esac
echo ":::::::: VALIDATION SCRIPT ::::::::"
echo "Starting test $1"
srv_pid=-1
srv_args=""
cli_pid=-1
srv_args=""
run_server() { ./s "$@" > server_log.txt 2> server_stderr.txt & srv_pid=$!; srv_args="./s $@"; }
run_client() { ./c "$@" > client_log.txt 2> server_stderr.txt & cli_pid=$!; cli_args="./c $@"; }
if [ $# -ne 1 ]; then
show_usage
fi
clean
case "$1" in
# invalid arguments
1) run_server -t 30 -l 10 /tmp/fifo_"${USER}";;
*) show_usage;;
esac
sleep 1
case "$1" in
# invalid arguments
1) run_client -t 10 /tmp/fifo_"${USER}";;
*) show_usage;;
esac
sleep 2
echo "Running..."
wait $cli_pid
echo "Client PID: $cli_pid, exit status: $?, cmd: ${cli_args}"
wait $srv_pid
echo "Server PID: $srv_pid, exit status: $?, cmd: ${srv_args}"
rm -rf /tmp/fifo_"${USER}"
#Count client
total_IWANT=$(grep -o -i IWANT client_log.txt | wc -l)
total_GOTRS=$(grep -o -i GOTRS client_log.txt | wc -l)
total_CLOSE=$(grep -o -i CLOSE client_log.txt | wc -l)
total_FAILD=$(grep -o -i FAILD client_log.txt | wc -l)
#Cont server
total_RECVD=$(grep -o -i RECVD server_log.txt | wc -l)
total_TSKEX=$(grep -o -i TSKEX server_log.txt | wc -l)
total_TSKDN=$(grep -o -i TSKDN server_log.txt | wc -l)
total_2LATE=$(grep -o -i 2LATE server_log.txt | wc -l)
total_GAVUP=$(grep -o -i GAVUP server_log.txt | wc -l)
#Right and unique sequence
OPERATIONS_CLIENT=$(grep 'GOTRS' client_log.txt | awk -F "\"*; \"*" '{print $6}' | sort)
OPERATIONS_EXEC=$(grep 'TSKEX' client_log.txt | awk -F "\"*; \"*" '{print $6}' | sort)
OPERATIONS_DONE=$(grep 'TSKDN' client_log.txt | awk -F "\"*; \"*" '{print $6}' | sort)
testcase1() {
echo "::::::::::: Test case 1 ::::::::::::::::"
echo "Client IWANT: $total_IWANT, Server RECVD: $total_RECVD"
if [ "$total_IWANT" -eq "$total_RECVD" ]; then echo "ALL OK (SRV LIVED)"; else echo "MAYBE ERROR"; fi
if [ "$total_IWANT" -lt "$total_RECVD" ]; then echo "MAYBE OK (SRV ENDED)"; fi
echo "Server RECVD: $total_RECVD, Server TSKEX: $total_TSKEX, Server TSKDN: $total_TSKDN"
if [ "$total_RECVD" -eq "$total_TSKEX" ]; then echo "ALL OK (RECVD-TSKEX)"; else echo "ERROR (RECVD-TSKEX)"; fi
if [ "$total_TSKEX" -eq "$total_TSKDN" ]; then echo "ALL OK (TSKEX-TSKDN)"; else echo "ERROR (TSKEX-TSKDN)"; fi
echo "Client GOTRS: $total_GOTRS, Server TSKDN: $total_TSKDN"
if [ "$total_GOTRS" -eq "$total_TSKDN" ]; then echo "ALL OK"; else echo "ERROR"; fi
echo "Client CLOSE: $total_CLOSE, Server RECVD: $total_2LATE"
if [ "$total_CLOSE" -eq "$total_2LATE" ]; then echo "ALL OK"; else echo "ERROR"; fi
echo "Client FAILD: $total_FAILD"
echo "Server GAVUP (client): $total_GAVUP"
echo "TASKS CHECK"
UNIQUE_CLIENT=$(echo "$OPERATIONS_CLIENT" | uniq -d)
if [ ! -z "$UNIQUE_CLIENT" ]; then echo "ERROR: REPEATED VALUES ON CLIENT"; else echo "ALL OK"; fi
UNIQUE_SERVER=$(echo "$OPERATIONS_DONE" | uniq -d)
if [ ! -z "$UNIQUE_SERVER" ]; then echo "ERROR: REPEATED VALUES ON SERVER"; else echo "ALL OK"; fi
if [ "$OPERATIONS_CLIENT" == "$OPERATIONS_DONE" ]; then echo "ALL OK"; else echo "ERROR: OPERATIONS EXECUTED DIFFER ON CLIENT vs SERVER"; fi
if [ "$OPERATIONS_EXEC" == "$OPERATIONS_DONE" ]; then echo "ALL OK"; else echo "ERROR: OPERATIONS REQUESTED DIFFER FROM RETURNS"; fi
}
case "$1" in
# invalid arguments
1) testcase1;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment