This repository has been archived by the owner on Jul 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pruebas.bash
executable file
·253 lines (189 loc) · 6.35 KB
/
pruebas.bash
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#!/usr/bin/env bash
set -eu
die() { >&2 echo "$@"; exit 1; }
BDIR="." # Carpeta con binarios
ODIR="obj" # Carpeta con objetos
MDIR="misc" # Carpeta con otros recursos
ALFALIB="$ODIR/alfalib.o" # Objeto alfalib
COMPILADOR="$BDIR/alfa" # Binario del compilador
TABLA_SIMBOLOS_PRUEBAS="$MDIR/tabla_simbolos_pruebas"
ANALIZADOR_MORFOLOGICO_PRUEBAS="$MDIR/analizador_morfologico_pruebas"
ANALIZADOR_SINTACTICO_PRUEBAS="$MDIR/analizador_sintactico_pruebas"
COMPILADOR_PRUEBAS="$MDIR/compilador_pruebas"
## Colorines
NC="$(tput sgr0)"
BOLD="$(tput bold)"
REVERSE="$(tput smso)"
RED="$(tput setaf 1)"
GREEN="$NC$(tput setaf 2)"
## Navegamos al directorio del script
cd "$( dirname "${BASH_SOURCE[0]}" )"
## Contador de numero de pruebas
n_pruebas=0
## Compilamos tests en carpeta BDIR
compile() {
title Compilando pruebas
echo
make debug test
echo
}
## Rutina auxiliar que limpia todos los ficheros generados
clean() {
rm -f $BDIR/prueba1 $BDIR/prueba2 $BDIR/prueba3
rm -f $ODIR/prueba1.o $ODIR/prueba2.o $ODIR/prueba3.o
rm -f prueba1.nasm prueba2.nasm prueba3.nasm _*.nasm
rm -f $ODIR/_*.o $BDIR/_*
make clean > /dev/null
}
## Imprime una cabecera con formato
title() { printf "$REVERSE[%s]$NC" "$*"; }
subtitle() { printf "\n$BOLD%-60s$NC" "$*"; }
## Un diff un poco mas descriptivo
diff() {
#echo '$ diff' "$@"
echo -en "$RED"
command diff "$@"
if [[ $? -eq 0 ]]; then
n_pruebas=$(expr $n_pruebas + 1 )
echo -en "${GREEN}OK$NC "
return 0
else
echo -en "${RED}ERR$NC "
return 1
fi
}
# './pruebas.sh clean' borra lo generado
if [[ "$*" == 'clean' ]]; then
clean
exit 0
fi
make_nasm_exe() {
local file_nasm="$1"
nasm -f elf32 -o "$ODIR/${file_nasm%.*}.o" "$file_nasm"
gcc -m32 -o "${file_nasm%.*}" "$ODIR/${file_nasm%.*}.o" "$ALFALIB"
}
practica1() {
title 'Pruebas practica 1 - generacion'
# Pruebas con los datos del enunciado
subtitle Prueba 1.1
$BDIR/main_0_generacion_ejemplo1 prueba1.nasm
make_nasm_exe prueba1.nasm
diff <(./prueba1 <<< $'-9\n') <(echo -n $'-1\n')
diff <(./prueba1 <<< $'10\n') <(echo -n $'18\n')
subtitle Prueba 1.2
$BDIR/main_0_generacion_ejemplo2 prueba2.nasm
make_nasm_exe prueba2.nasm
diff <(./prueba2 <<< $'0\n') <(echo -n $'true\nfalse\n')
diff <(./prueba2 <<< $'1\n') <(echo -n $'false\ntrue\n')
subtitle Prueba 1.3
$BDIR/main_0_generacion_ejemplo3 prueba3.nasm
make_nasm_exe prueba3.nasm
diff <(./prueba3 <<< $'-3\n3\n0\n') <(echo -n $'true\n3\n0\n3\n')
diff <(./prueba3 <<< $'10\n-9\n1\n') <(echo -n $'false\n-10\n1\n-9\n')
echo
}
practica2() {
title 'Pruebas practica 2 - tabla simbolos'
i=0
for file in $(ls $TABLA_SIMBOLOS_PRUEBAS/*.in); do
i=$(expr $i + 1)
file=$(echo $file | cut -f 1 -d '.')
subtitle "Prueba 2.$i - $file"
diff <($BDIR/main_1_tabla $file.in) "$file.out"
done
echo
}
practica3() {
title 'Pruebas practica 3 - analizador morfologico'
subtitle 'Prueba 3.1 - entrada valida'
diff <($BDIR/main_2_morfo $ANALIZADOR_MORFOLOGICO_PRUEBAS/p3_entrada_1.txt) "$ANALIZADOR_MORFOLOGICO_PRUEBAS/p3_salida_1.txt"
subtitle 'Prueba 3.2 - identificador largo'
diff <($BDIR/main_2_morfo $ANALIZADOR_MORFOLOGICO_PRUEBAS/p3_entrada_2.txt 2> /dev/null) "$ANALIZADOR_MORFOLOGICO_PRUEBAS/p3_salida_2.txt"
diff <($BDIR/main_2_morfo $ANALIZADOR_MORFOLOGICO_PRUEBAS/p3_entrada_2.txt 2>&1 > /dev/null) "$ANALIZADOR_MORFOLOGICO_PRUEBAS/p3_error_2.txt"
subtitle 'Prueba 3.3 - simbolo no permitido'
diff <($BDIR/main_2_morfo $ANALIZADOR_MORFOLOGICO_PRUEBAS/p3_entrada_3.txt 2> /dev/null) "$ANALIZADOR_MORFOLOGICO_PRUEBAS/p3_salida_3.txt"
diff <($BDIR/main_2_morfo $ANALIZADOR_MORFOLOGICO_PRUEBAS/p3_entrada_3.txt 2>&1 > /dev/null) "$ANALIZADOR_MORFOLOGICO_PRUEBAS/p3_error_3.txt"
echo
}
practica4() {
title 'Pruebas practica 4 - analizador sintactico'
i=0
for file in $(ls $ANALIZADOR_SINTACTICO_PRUEBAS/ej_*.alf); do
file=$(basename -s .alf "$file")
file=${file#*_}
i=$(expr $i + 1)
subtitle "Prueba 4.$i - $file"
diff <($BDIR/main_3_sintactico $ANALIZADOR_SINTACTICO_PRUEBAS/ej_$file.alf 2> /dev/null) "$ANALIZADOR_SINTACTICO_PRUEBAS/sal_$file.txt"
done
echo
}
compilador() {
title "Pruebas compilador - $2"
local COMPILADOR_PRUEBAS
COMPILADOR_PRUEBAS=$3
local i=0
for file in $(ls $COMPILADOR_PRUEBAS/*.alf); do
i=$(expr $i + 1)
file=$(basename -s .alf "$file")
# Borramos los generados de la prueba anterior
rm -f "_$file" "_$file.nasm" "$ODIR/_$file.o"
subtitle "Prueba $1.$i - $file"
# Si existe un fichero .err, tiene errores semanticos
if [[ -f "$COMPILADOR_PRUEBAS/$file.err" ]]; then
diff -B <($COMPILADOR "$COMPILADOR_PRUEBAS/$file.alf" "_$file.nasm") "$COMPILADOR_PRUEBAS/$file.err"
continue
fi
$COMPILADOR "$COMPILADOR_PRUEBAS/$file.alf" "_$file.nasm"
make_nasm_exe _$file.nasm
# Si hay ficheros que acaben en _N, ejecutamos para cada par (in, out)
if [[ -f "$COMPILADOR_PRUEBAS/${file}_1.input" ]]; then
# Buscamos por ficheros IN porque no tiene sentido comprobar salidas
# diferentes si no hay entrada/es la misma (los programas son deterministas).
for in_file in $(find "$COMPILADOR_PRUEBAS" -iname "${file}_?.input" -type f); do
diff -B <(./_$file < "$in_file") "${in_file%.*}.output"
done
# En caso contrario, buscamos un out y opcionalmente un in
elif [[ -f "$COMPILADOR_PRUEBAS/$file.output" ]]; then
if [[ -f "$COMPILADOR_PRUEBAS/$file.input" ]]; then
diff -B <("./_$file" < "$COMPILADOR_PRUEBAS/$file.input") "$COMPILADOR_PRUEBAS/$file.output"
else
diff -B <(./_$file) "$COMPILADOR_PRUEBAS/$file.output"
fi
# Nos quejamos si no hay salida
else
echo "error: No existen $file.out ni $file.err"
exit 1
fi
done
echo
}
errores_semanticos() {
title "Pruebas compilador - Ficheros de coreccion errores"
local i=0
for file_path in "$MDIR/ficheros_correccion/errores/"*; do
i=$(expr $i + 1)
file=$(basename -s .alf "$file_path")
subtitle "Prueba 6bis.$i - $file"
if ! $COMPILADOR "$file_path" "_$file.nasm" > /dev/null; then
echo -en "${GREEN}OK${NC} "
else
echo -en "${RED}ERR$NC "
fi
done
echo
}
compile
practica1
practica2
practica3
practica4
compilador 5 'Pruebas propias' "$COMPILADOR_PRUEBAS"
compilador 6 'Ficheros de correccion' "$MDIR/ficheros_correccion"
errores_semanticos
compilador 7 'Examenes anteriores' "$MDIR/pruebas_examen"
title 'Borrando ficheros generados'
echo
clean
title "$n_pruebas/$n_pruebas pruebas completadas con exito"
echo
exit 0