-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.sh
More file actions
167 lines (147 loc) · 4.55 KB
/
script.sh
File metadata and controls
167 lines (147 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/bash
#para dar formato
ROJO=`tput setaf 1`
VERDE=`tput setaf 2`
AMARILLO=`tput setaf 3`
RESET=`tput sgr0`
SUBR=`tput smul`
#para cálculos resultados
totalLineas=0
lineasDiferentes=0
porcentajeLineas=0
MAIN_NAME=main
usage() { echo "Usage: $0 [-p <main|test>] [-v]" 1>&2; exit 1; }
# Comprobar parametros de entrada
VERBOSE=false
while getopts "p:v" opt; do
case "$opt" in
p) MAIN_NAME=$OPTARG
if [[ "$MAIN_NAME" != "main" && "$MAIN_NAME" != "test" ]]; then
usage
fi
;;
v)
VERBOSE=true
echo VERBOSETRUE
;;
*)
usage
;;
esac
done
MAIN="./"$MAIN_NAME
if [ "$MAIN_NAME" = "main" ]
then
ficherosEntrada=("script_minimos/new" "script_minimos/play" "script_minimos/upgrade" "script_minimos/delete1" "script_minimos/delete2")
ficherosRef=("script_minimos/new_ref" "script_minimos/play_ref" "script_minimos/upgrade_ref" "script_minimos/delete1_ref" "script_minimos/delete2_ref")
else
ficherosEntrada=("")
ficherosRef=("script_test/ref")
fi
# Funcion para comprobar la salida del programa
# Parametros de entrada:
# - descripcion tipo de lista
# - nombre unit a probar
# - salida verbosa
# Parametros de salida:
# - Exito (1) o fallo (0) en la comprobacion
function check_output {
LIST_TYPE_DESC=$1
DEPS=$2
VERBOSE=$3
rm -f ${MAIN}
printf "${AMARILLO}Running script for ${LIST_TYPE_DESC} list...${RESET}"
printf "\n${AMARILLO}Compiling "$MAIN_NAME" program using ${LIST_TYPE_DESC} list with\ngcc -Wall -Wextra ${DEPS} ${MAIN}.c -o ${MAIN}${RESET}\n"
gcc -Wall -Wextra ${DEPS} ${MAIN}.c -o ${MAIN}
if [ -f ${MAIN} ]
then
allOK=1
printf "\n${AMARILLO}Checking "$MAIN_NAME" program output using ${LIST_TYPE_DESC} list...\n${RESET}"
printf "\n${SUBR}Input file${RESET} ${SUBR}Result${RESET} ${SUBR}Notes${RESET}\n"
for index in ${!ficherosEntrada[*]}
do
nombre=${ficherosEntrada[$index]}
if [ "$nombre" != "" ]
then
ficheroEntrada="$nombre".txt
else
ficheroEntrada=""
nombre="script_test/test"
#nombre=$index
fi
ficheroReferencia=${ficherosRef[$index]}.txt
ficheroSalida="$nombre"_${LIST_TYPE_DESC}.txt
ficheroDiff="$nombre"_diff.txt
${MAIN} $ficheroEntrada > $ficheroSalida
diff -w -B -b -y --suppress-common-lines --width=170 $ficheroReferencia $ficheroSalida > $ficheroDiff
iguales=$(stat -c%s $ficheroDiff)
if [ "$ficheroEntrada" = "" ]; then
ficheroEntrada="(no input file)"
fi
if [ ${iguales} -eq "0" ]
then
printf "%-35s %-12s %s\n" "$ficheroEntrada" "${VERDE}OK" "${RESET}"
else
printf "%-35s %-12s %s\n" "$ficheroEntrada" "${ROJO}FAIL" "${RESET}Check ${ficheroReferencia} and ${ficheroSalida}"
allOK=0
if ${VERBOSE}
then
printf '\nFile: %-77s | File: %s\n' $ficheroReferencia $ficheroSalida
printf '=%.0s' {1..170}
printf '\n'
cat ${ficheroDiff}
printf '\n'
fi
fi
rm $ficheroDiff
done
else
allOK=0
printf "\n${ROJO}Compilation failed${RESET}"
fi
printf "\n"
return ${allOK}
}
function show_result {
MESSAGE=$1
RESULT=$2
printf "${AMARILLO}${MESSAGE} "
if [ ${RESULT} -eq 1 ]
then
printf "${VERDE}OK${RESET}"
else
printf "${ROJO}FAIL${RESET}"
fi
printf "\n"
}
#Comprobar que existen en path actual los ficheros output de referencia
#(sino, tal y como está el script da un OK a pesar de mostrar un error en el diff)
for file in ${ficherosRef[@]}
do
if [ ! -f "${file}.txt" ]
then
printf "${ROJO}Please add the reference file ${file}.txt to the current path${RESET}\n"
exit 1
fi
done
check_output "Static" "-DSTATIC_LIST static_list.h static_list.c" ${VERBOSE}
STATIC_OK=$?
if [ "$MAIN_NAME" = "test" ]; then
smesss=" (checkpoint #1 - March 5th)"
fi
show_result "Static List result${smesss}:" $STATIC_OK
printf "\n\n"
check_output "Dynamic" "-DDYNAMIC_LIST dynamic_list.h dynamic_list.c" ${VERBOSE}
DYNAMIC_OK=$?
if [ "$MAIN_NAME" = "test" ]; then
smessd=" (checkpoint #2 - March 12th)"
fi
show_result "Dynamic List result${smessd}:" $DYNAMIC_OK
printf "\n\n"
ALL_OK=$((${STATIC_OK} * ${DYNAMIC_OK}))
printf "${AMARILLO}Summary:\n"
printf "========\n"
show_result "Static List result${smesss}:" $STATIC_OK
show_result "Dynamic List result${smessd}:" $DYNAMIC_OK
show_result "Global result:" $ALL_OK
printf "\n"