-
Notifications
You must be signed in to change notification settings - Fork 27
/
correcao.sh
executable file
·2153 lines (1864 loc) · 131 KB
/
correcao.sh
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# DIR_TEST=test
DIR_RESPOSTAS=Respostas
DIR_RESULTADOS=Resultados
# GAB_OBJ_FILES=`ls Gabarito-obj/*.o`
DIR_GAB_SRC="Gabarito-src"
DIR_GAB_OBJ="Gabarito-obj"
DIR_GAB_INCLUDES="Includes"
DIR_GAB_CASOS=Casos
DIR_INCLUDES=Includes
IGNORE_RESULTS=false
IGNORE_VALGRIND=false
RUN_PROFESSOR_SCRIPT=false # precisa rodar primeiro para gerar os arquivos objetos e o resultado txt do gabarito
RUN_STUDENT_SCRIPT=true # tem que rodar depois que o RUN_PROFESSOR_SCRIPT foi rodado primeiro
FIXED_INTERFACE=false # tem que rodar depois que o RUN_PROFESSOR_SCRIPT foi rodado primeiro
TERMINAL_OUTPUT_LOG=""
# Using getopt to handle long options
TEMP=$(getopt -o '' --long resultados,valgrind,professor,interfacefixa -- "$@")
# Terminate the script in case of wrong arguments
if [ $? != 0 ]; then
echo 'Terminating...' >&2
exit 1
fi
if test -f "log.txt"; then
rm -r "log.txt"
fi
# Setting the positional parameters to the processed values
eval set -- "$TEMP"
# Initialize variables
# Process options
while true; do
case "$1" in
--resultados)
IGNORE_RESULTS=true
shift
;;
--valgrind)
IGNORE_VALGRIND=true
shift
;;
--professor)
RUN_PROFESSOR_SCRIPT=true
shift
;;
--interfacefixa)
FIXED_INTERFACE=true
shift
;;
--)
shift
break
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
# Sample output
if [[ "$RUN_PROFESSOR_SCRIPT" == true ]] ; then
RUN_STUDENT_SCRIPT=false
fi
if $IGNORE_RESULTS; then TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG}Ignorando os Resultados\n"; fi
if $IGNORE_VALGRIND; then TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG}Ignorando o Valgrind\n"; fi
if $RUN_PROFESSOR_SCRIPT; then TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG}Rodando apenas o script do Professor"; fi
if $RUN_STUDENT_SCRIPT; then TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG}Rodando o script do Aluno"; fi
if $FIXED_INTERFACE; then TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG}Considerando interface fixa do professor"; fi
echo -e $TERMINAL_OUTPUT_LOG
HEADER_FILES_EXIST=false
# Use the find command to search for .h files within the folder
if test -d "$DIR_GAB_SRC"; then
if find "$DIR_GAB_SRC" -maxdepth 1 -type f -name "*.h" | read; then
HEADER_FILES_EXIST=true
fi
fi
script_com_pesos()
{
if [ ! -f "pontuacao.txt" ]; then
script_sem_pesos
exit
fi
declare -A pesos
arquivosHeaderDisponibilizados=()
# Read the pontuacao.txt file line by line
while IFS="=" read -r key value || [[ -n "$key" ]]; do
if [ "$key" != "" ]; then
if [[ "$key" == *".h" ]]; then
arquivosHeaderDisponibilizados+=("$key")
fi
pesos["$key"]="$value"
fi
done < pontuacao.txt
# Optionally, print the contents of the associative array to verify
# for key in "${!pesos[@]}"; do
# echo "$key = ${pesos[$key]}"
# done
# for file in "${arquivosHeaderDisponibilizados[@]}"; do
# echo "FILE: $file"
# done
contains() {
local file_to_check=$1
for file in "${arquivosHeaderDisponibilizados[@]}"; do
if [[ $file == "$file_to_check" ]]; then
return 0
fi
done
return 1
}
if [[ "$RUN_PROFESSOR_SCRIPT" == true ]] ; then
if test -d "$DIR_GAB_OBJ"; then
rm -r $DIR_GAB_OBJ
fi
mkdir -p $DIR_GAB_OBJ
echo " - Pasta $DIR_GAB_OBJ criada com sucesso!"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Pasta $DIR_GAB_OBJ criada com sucesso!\n"
if test -d "$DIR_INCLUDES"; then
rm -r $DIR_INCLUDES
fi
mkdir -p $DIR_INCLUDES
echo " - Pasta $DIR_INCLUDES criada com sucesso!"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Pasta $DIR_INCLUDES criada com sucesso!\n"
gab_src_files_names=()
# Check if the folder exists and is a directory
if [ -d "$DIR_INCLUDES" ] && [ -d "$DIR_GAB_SRC" ]; then
if [ "$HEADER_FILES_EXIST" = "true" ]; then
for fileH in "${arquivosHeaderDisponibilizados[@]}"; do
if [[ "$fileH" != "main" ]]; then
if [[ -f "$DIR_GAB_SRC/$fileH" ]]; then
cp $DIR_GAB_SRC/$fileH $DIR_INCLUDES
fi
fi
done
echo " - Arquivos .h do professor da pasta $DIR_GAB_SRC copiados para a pasta $DIR_INCLUDES com sucesso!"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Arquivos .h do professor da pasta $DIR_GAB_SRC copiados para a pasta $DIR_INCLUDES com sucesso!\n"
else
echo " - Não existem arquivos header na pasta $DIR_GAB_SRC do professor."
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Não existem arquivos header na pasta $DIR_GAB_SRC do professor.\n"
fi
src_files_array=()
# Read the files with the specific extension into the array
while IFS= read -r -d '' file; do
src_files_array+=("$file")
done < <(find "$DIR_GAB_SRC" -type f -name "*.c" -print0)
# Print the elements of the array for verification
for src_file in "${src_files_array[@]}"; do
x=${src_file%.c} # x sera' o nome do arquivo sem a extensao .c
raw_file_name=${x##*/} # raw_file_name sera' o nome do arquivo puro, sem os diretorios que contem ele
echo "raw_file_name: $raw_file_name"
if contains "$raw_file_name.h" || [[ "$raw_file_name" == "main" ]] ; then
gab_src_files_names+=("$raw_file_name")
src=$DIR_GAB_SRC/$raw_file_name.c
out=$DIR_GAB_OBJ/$raw_file_name.o
output=$(gcc -Wall -c $src -o $out 2>&1)
if [ $? -ne 0 ]; then
echo " - Erro de compilação! Verifique se o arquivo $src está correto."
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Erro de compilação! Verifique se o arquivo $src está correto.\n"
echo $TERMINAL_OUTPUT_LOG >> "log.txt"
exit 1
fi
fi
done
output=$(gcc -Wall -o $DIR_GAB_OBJ/prog $DIR_GAB_OBJ/*.o -lm 2>&1)
echo "$output"
if [ $? -ne 0 ]; then
echo -e " - Arquivos Linkados: Erro! Binário prog não gerado."
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Arquivos Linkados: Erro! Binário prog não gerado.\n"
echo $TERMINAL_OUTPUT_LOG >> "log.txt"
exit 1
else
echo " - Arquivos objetos do gabarito gerados com sucesso na pasta $DIR_GAB_OBJ!"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Arquivos objetos do gabarito gerados com sucesso na pasta $DIR_GAB_OBJ!\n"
fi
else
echo " - Pasta não encontrada: $DIR_INCLUDES ou $DIR_GAB_SRC, abortado!"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Pasta não encontrada: $DIR_INCLUDES ou $DIR_GAB_SRC, abortado!\n"
echo $TERMINAL_OUTPUT_LOG >> "log.txt"
exit 1
fi
for DIR_CASE in "$DIR_GAB_CASOS"/*; do
txt_input_file=$(find "$DIR_CASE" -maxdepth 1 -type f -name "*.txt" | head -n 1)
directory_path=$(dirname "$txt_input_file")
filename=$(basename -- "$txt_input_file") # Get only the file name without the full path
filename_no_ext="${filename%.*}" # Get only the file name without the extension
dir_saida=${DIR_CASE}/saida
if [ ! -d "$dir_saida" ]; then
mkdir -p $dir_saida
fi
txt_output_file=$(find "$DIR_CASE/saida" -maxdepth 1 -type f -name "*.txt" | head -n 1)
if test -f "$txt_output_file"; then
rm $DIR_CASE/saida/*.txt
fi
input_file=$directory_path/entrada.txt
# output="${DIR_CASE}/saida/out_${filename_no_ext}.txt"
output="${DIR_CASE}/saida/saida.txt"
# $DIR_GAB_OBJ/prog < $txt_input_file > $output 2>&1
$DIR_GAB_OBJ/prog $directory_path < $input_file > $output 2>&1
# mv *.txt $DIR_CASE/saida/
for txtfile in *.txt; do
if [[ "$txtfile" != "pontuacao.txt" ]]; then
mv "$txtfile" "$DIR_CASE/saida/"
fi
done
echo " - Output do resultado do professor gerado com sucesso na pasta $output."
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Output do resultado do professor gerado com sucesso na pasta $output.\n"
done
echo -e " - Todos os arquivos necessários do professor gerados. Remova a pasta $DIR_GAB_SRC e envie o script para o Aluno!\n"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Todos os arquivos necessários do professor gerados. Remova a pasta $DIR_GAB_SRC e envie o script para o Aluno!\n"
fi
n_total_cases=0
if [[ "$RUN_STUDENT_SCRIPT" == true ]] ; then
if test -d "$DIR_INCLUDES"; then
if find "$DIR_INCLUDES" -maxdepth 1 -type f -name "*.h" | read; then
HEADER_FILES_EXIST=true
fi
fi
if [ "$HEADER_FILES_EXIST" = "true" ]; then
if [ -d "$DIR_INCLUDES" ]; then
if [ $(find "$DIR_INCLUDES" -maxdepth 1 -type f -name "*.h" | wc -l) -gt 0 ]; then
echo " - Arquivos header necessários do professor existem na pasta $DIR_INCLUDES"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Arquivos header necessários do professor existem na pasta $DIR_INCLUDES\n"
else
echo " - Arquivos header necessários do professor não existem na pasta $DIR_INCLUDES, por favor rode o script do professor primeiro. Abortado!"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Arquivos header necessários do professor não existem na pasta $DIR_INCLUDES, por favor rode o script do professor primeiro. Abortado!\n"
echo $TERMINAL_OUTPUT_LOG >> "log.txt"
exit 1
fi
else
echo " - A pasta $DIR_INCLUDES com os arquivos header do professor não existe, por favor rode o script do professor primeiro. Abortado!"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - A pasta $DIR_INCLUDES com os arquivos header do professor não existe, por favor rode o script do professor primeiro. Abortado!\n"
echo $TERMINAL_OUTPUT_LOG >> "log.txt"
exit 1
fi
fi
if [ -d "$DIR_GAB_OBJ" ]; then
if [ $(find "$DIR_GAB_OBJ" -maxdepth 1 -type f -name "*.o" | wc -l) -gt 0 ]; then
echo " - Arquivos objetos necessários do professor existem na pasta $DIR_GAB_OBJ."
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Arquivos objetos necessários do professor existem na pasta $DIR_GAB_OBJ."
else
echo " - Arquivos objetos necessários do professor não existem na pasta $DIR_GAB_OBJ, por favor rode o script do professor primeiro. Abortado!"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Arquivos objetos necessários do professor não existem na pasta $DIR_GAB_OBJ, por favor rode o script do professor primeiro. Abortado!\n"
echo $TERMINAL_OUTPUT_LOG >> "log.txt"
exit 1
fi
else
echo " - A pasta $DIR_GAB_OBJ com os arquivos objetos do professor não existe, por favor rode o script do professor primeiro. Abortado!"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - A pasta $DIR_GAB_OBJ com os arquivos objetos do professor não existe, por favor rode o script do professor primeiro. Abortado!\n"
echo $TERMINAL_OUTPUT_LOG >> "log.txt"
exit 1
fi
n_cases=0
for DIR_CASE in "$DIR_GAB_CASOS"/*; do
(( n_cases++ ))
done
# Create empty arrays
declare -a src_files_names
declare -a fullpaths
n_files=0
n_folders_to_compile=0
n_compilations=0
for filepath in "$DIR_GAB_OBJ/"*.o; do
# Check if file exists to avoid the loop processing the "*.txt" string when there are no matches
if [[ -f "$filepath" ]]; then
# Extract just the file name without the path and extension
filename=$(basename "$filepath" .o)
src_files_names+=("$filename")
fullpaths+=("$filepath")
(( n_files++ ))
(( n_folders_to_compile++ ))
(( n_compilations++ ))
fi
done
# n_compilations=$((n_compilations * n_files))
# n_compilations=$((n_compilations + n_files)) # considerando a pasta completo
n_compilations=$((n_compilations + 1)) # considerando a pasta completo
n_folders_to_compile=$((n_folders_to_compile + 1)) # considerando a pasta completo
n_linkings=$((n_files + 1))
for headerpath in "$DIR_INCLUDES/"*.h; do
if [[ -f "$headerpath" ]]; then
# Extract just the file name without the path and extension
(( n_files++ ))
fi
done
if [[ ${#src_files_names[@]} -eq 0 ]]; then
echo " - A Pasta $DIR_GAB_OBJ com os arquivos objetos do Gabarito está vazia, por favor rode primeiro o script do Professor!"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - A Pasta $DIR_GAB_OBJ com os arquivos objetos do Gabarito está vazia, por favor rode primeiro o script do Professor!\n"
echo $TERMINAL_OUTPUT_LOG >> "log.txt"
exit 1
fi
src_files_names+=("completo")
src_files_names=()
for file in "${arquivosHeaderDisponibilizados[@]}"; do
filename_no_ext="${file%.*}" # Get only the file name without the extension
src_files_names+=("$filename_no_ext")
done
src_files_names+=("completo")
src_files_names+=("main")
# for file in "${src_files_names[@]}"; do
# echo "ARQUIVO: $file"
# done
declare -A all_students_results
declare -A all_students_pontuacoes
iteration=0
# Check if the folder exists and is a directory
if [ -d "$DIR_RESPOSTAS" ]; then
if [ -z "$(ls -A $DIR_RESPOSTAS)" ]; then
echo " - Erro! Por favor, crie uma pasta com o seu nome dentro da pasta Respostas/, por exemplo Respostas/JoaoAugusto/ e dentro dessa pasta do seu nome coloque os seus arquivos do código fonte."
exit 1
fi
if [ ! -d "$DIR_RESULTADOS" ]; then
mkdir -p $DIR_RESULTADOS
fi
# Loop through all folders in the specified folder using 'find'
while IFS= read -r -d '' STUDENT_ANSWER_FOLDER; do
if [ -d "$STUDENT_ANSWER_FOLDER" ]; then
(( iteration++ ))
# Get the student name
delimiter="/" # Set the delimiter
original_IFS="$IFS" # Save the old IFS
IFS="$delimiter" # Set the IFS to the delimiter to split the string
read -r _ student_name <<< "$STUDENT_ANSWER_FOLDER" # Read the second part of the string into a variable
IFS="$original_IFS"
echo -e "\n#######################################"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG}\n#######################################\n"
echo "ALUNO: $student_name"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG}ALUNO: $student_name\n"
echo -e "#######################################\n"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG}#######################################\n"
declare -a files_to_compile
for element in "${src_files_names[@]}"; do
files_to_compile+=("$element")
done
declare -A test_cases_results
test_cases_results["student_name"]=$student_name
test_cases_results["arquivos_corretos"]=0
test_cases_results["nota_arquivos_corretos"]=0
test_cases_results["compilacoes_corretas"]=0
test_cases_results["nota_compilacoes_corretas"]=0
test_cases_results["linkagens_corretas"]=0
test_cases_results["nota_linkagens_corretas"]=0
declare -A test_cases_pontuacoes
test_cases_pontuacoes["student_name"]=$student_name
for key in "${!pesos[@]}"; do
if [[ "$key" == *".txt" ]]; then
test_cases_pontuacoes["$key"]=0
fi
done
# for key in "${!test_cases_pontuacoes[@]}"; do
# echo "$key = ${test_cases_pontuacoes[$key]}"
# done
# incrementValueDictPontuacao() {
# local key=$1
# local incrementAmount=$2
# # Check if the key exists; if not, initialize it to 0
# [[ ! -v test_cases_pontuacoes["$key"] ]] && test_cases_pontuacoes["$key"]=0
# # Increment the value for the key
# test_cases_pontuacoes["$key"]=$((test_cases_pontuacoes["$key"] + incrementAmount))
# }
for src_file_name in "${src_files_names[@]}"; do
acertos_field=acertos_$src_file_name
nota_acertos_field=nota_acertos_$src_file_name
acertosval_field=acertosval_$src_file_name
nota_acertosval_field=nota_acertosval_$src_file_name
test_cases_results[$acertos_field]=0
test_cases_results[$acertosval_field]=0
test_cases_results[$nota_acertos_field]=0
test_cases_results[$nota_acertosval_field]=0
done
##########################################
# criando os diretorios de resultados para cada aluno
##########################################
echo "CRIANDO O DIRETÓRIO DE RESULTADO PARA $student_name:"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG}CRIANDO O DIRETÓRIO DE RESULTADO PARA $student_name:\n"
# create a directory in the Resultados folder with the student name and copy the content to there
STUDENT_RESULT_FOLDER=${DIR_RESULTADOS}/$student_name
if test -d "$STUDENT_RESULT_FOLDER"; then
rm -r $STUDENT_RESULT_FOLDER
sleep 1
fi
mkdir -p $STUDENT_RESULT_FOLDER
if test -d "$STUDENT_RESULT_FOLDER"; then
echo " - Diretório $STUDENT_RESULT_FOLDER criado com sucesso!"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Diretório $STUDENT_RESULT_FOLDER criado com sucesso!\n"
fi
for src_file_name in "${src_files_names[@]}"; do
FILE_NAME_FOLDER=$STUDENT_RESULT_FOLDER/$src_file_name
mkdir -p $FILE_NAME_FOLDER
if test -d "$FILE_NAME_FOLDER"; then
echo " - Diretório $FILE_NAME_FOLDER criado com sucesso!"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Diretório $FILE_NAME_FOLDER criado com sucesso!\n"
fi
# mkdir -p $FILE_NAME_FOLDER/test
# if test -d "$FILE_NAME_FOLDER/test"; then
# echo " - Diretório $FILE_NAME_FOLDER/test criado com sucesso!"
# TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Diretório $FILE_NAME_FOLDER/test criado com sucesso!\n"
# fi
done
echo -e " - Arquivos criados: ok!"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Arquivos criados: ok!\n"
##########################################
# verifica se os arquivos esperados existem
##########################################
echo -e "\nCHECKANDO OS ARQUIVOS DO ALUNO:"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG}\nCHECKANDO OS ARQUIVOS DO ALUNO:\n"
student_files_missing=0
student_files_found=0
for src_file_name in "${src_files_names[@]}"; do
student_src=$STUDENT_ANSWER_FOLDER/$src_file_name.c
student_hdr=$STUDENT_ANSWER_FOLDER/$src_file_name.h
if [ ! -f "$student_src" ] && [[ "$src_file_name" != "completo" ]] ; then
echo " - Arquivo esperado '$student_src' não encontrado!"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Arquivo esperado '$student_src' não encontrado!\n"
student_files_missing=$(expr $student_files_missing + 1)
elif [[ "$src_file_name" != "completo" ]]; then
echo " - Arquivo esperado '$student_src' encontrado!"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Arquivo esperado '$student_src' encontrado!\n"
student_files_found=$(expr $student_files_found + 1)
fi
if [ "$HEADER_FILES_EXIST" = "true" ]; then
if [ ! -f "$student_hdr" ] && [[ "$src_file_name" != "completo" ]] && [[ "$src_file_name" != "main" ]]; then
echo " - Arquivo esperado '$student_hdr' não encontrado!"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Arquivo esperado '$student_hdr' não encontrado!\n"
student_files_missing=$(expr $student_files_missing + 1)
elif [[ "$src_file_name" != "completo" ]] && [[ "$src_file_name" != "main" ]]; then
echo " - Arquivo esperado '$student_hdr' encontrado!"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Arquivo esperado '$student_hdr' encontrado!\n"
student_files_found=$(expr $student_files_found + 1)
fi
fi
done
if [ $student_files_missing -gt 0 ] ; then
# test_cases_results["arquivos_faltando"]=$student_files_missing
echo -e " - Arquivos esperados enviados: Faltando!"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Arquivos esperados enviados: Faltando!\n"
else
echo -e " - Arquivos esperados enviados: Ok!"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Arquivos esperados enviados: Ok!\n"
fi
test_cases_results["arquivos_corretos"]=$student_files_found
##########################################
# Copiando os arquivos
##########################################
echo -e "\nCOPIANDO OS ARQUIVOS PARA A PASTA DE RESULTADO DO ALUNO:"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG}\nCOPIANDO OS ARQUIVOS PARA A PASTA DE RESULTADO DO ALUNO:\n"
# for src_file_name in "${src_files_names[@]}"; do
# echo " - Pasta $src_file_name:"
# TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Pasta $src_file_name:\n"
# FILE_NAME_FOLDER=$STUDENT_RESULT_FOLDER/$src_file_name
# echo " - Copiando os $DIR_GAB_CASOS de teste para a pasta $FILE_NAME_FOLDER"
# TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Copiando os $DIR_GAB_CASOS de teste para a pasta $FILE_NAME_FOLDER\n"
# cp -r $DIR_GAB_CASOS $FILE_NAME_FOLDER
# if find "$STUDENT_ANSWER_FOLDER" -maxdepth 1 -type f -name "*.h" | read; then
# if find "$DIR_GAB_INCLUDES" -maxdepth 1 -type f -name "*.h" | read; then
# if [[ "$src_file_name" != "completo" ]] ; then
# echo " - Copiando os $DIR_GAB_INCLUDES/*.h do professor para a pasta $FILE_NAME_FOLDER"
# TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Copiando os '$DIR_GAB_INCLUDES/*.h' do professor para a pasta $FILE_NAME_FOLDER\n"
# cp $DIR_GAB_INCLUDES/*.h $FILE_NAME_FOLDER
# fi
# fi
# if [[ "$src_file_name" == "main" ]] || [[ "$src_file_name" == "completo" ]] ; then
# echo " - Copiando os $STUDENT_ANSWER_FOLDER/*.h do aluno para a pasta $FILE_NAME_FOLDER"
# TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Copiando os '$STUDENT_ANSWER_FOLDER/*.h' do aluno para a pasta $FILE_NAME_FOLDER\n"
# cp $STUDENT_ANSWER_FOLDER/*.h $FILE_NAME_FOLDER
# else
# echo " - Copiando os $STUDENT_ANSWER_FOLDER/$src_file_name.h do aluno para a pasta $FILE_NAME_FOLDER"
# TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Copiando os '$STUDENT_ANSWER_FOLDER/src_file_name.h' do aluno para a pasta $FILE_NAME_FOLDER\n"
# cp $STUDENT_ANSWER_FOLDER/$src_file_name.h $FILE_NAME_FOLDER
# fi
# fi
# if [[ "$src_file_name" == "main" ]] || [[ "$src_file_name" == "completo" ]]; then
# echo " - Copiando os $STUDENT_ANSWER_FOLDER/*.c do aluno para a pasta $FILE_NAME_FOLDER"
# TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Copiando os '$STUDENT_ANSWER_FOLDER/*.c' do aluno para a pasta $FILE_NAME_FOLDER\n"
# cp $STUDENT_ANSWER_FOLDER/*.c $FILE_NAME_FOLDER
# else
# echo " - Copiando os $STUDENT_ANSWER_FOLDER/$src_file_name.c do aluno para a pasta $FILE_NAME_FOLDER"
# TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Copiando os '$STUDENT_ANSWER_FOLDER/src_file_name.c' do aluno para a pasta $FILE_NAME_FOLDER\n"
# cp $STUDENT_ANSWER_FOLDER/$src_file_name.c $FILE_NAME_FOLDER
# fi
# done
for src_file_name in "${src_files_names[@]}"; do
echo " - Pasta $src_file_name:"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Pasta $src_file_name:\n"
FILE_NAME_FOLDER=$STUDENT_RESULT_FOLDER/$src_file_name
echo " - Copiando os $DIR_GAB_CASOS de teste para a pasta $FILE_NAME_FOLDER"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Copiando os $DIR_GAB_CASOS de teste para a pasta $FILE_NAME_FOLDER\n"
cp -r $DIR_GAB_CASOS $FILE_NAME_FOLDER
if find "$STUDENT_ANSWER_FOLDER" -maxdepth 1 -type f -name "*.h" | read; then
if find "$DIR_GAB_INCLUDES" -maxdepth 1 -type f -name "*.h" | read; then
if [[ "$src_file_name" != "completo" ]] ; then
echo " - Copiando os $DIR_GAB_INCLUDES/*.h do professor para a pasta $FILE_NAME_FOLDER"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Copiando os '$DIR_GAB_INCLUDES/*.h' do professor para a pasta $FILE_NAME_FOLDER\n"
cp $DIR_GAB_INCLUDES/*.h $FILE_NAME_FOLDER
fi
fi
if [[ "$src_file_name" == "main" ]] || [[ "$src_file_name" == "completo" ]] ; then
echo " - Copiando os $STUDENT_ANSWER_FOLDER/*.h do aluno para a pasta $FILE_NAME_FOLDER"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Copiando os '$STUDENT_ANSWER_FOLDER/*.h' do aluno para a pasta $FILE_NAME_FOLDER\n"
cp $STUDENT_ANSWER_FOLDER/*.h $FILE_NAME_FOLDER
else
echo " - Copiando os $STUDENT_ANSWER_FOLDER/$src_file_name.h do aluno para a pasta $FILE_NAME_FOLDER"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Copiando os '$STUDENT_ANSWER_FOLDER/src_file_name.h' do aluno para a pasta $FILE_NAME_FOLDER\n"
cp $STUDENT_ANSWER_FOLDER/$src_file_name.h $FILE_NAME_FOLDER
fi
fi
if [[ "$src_file_name" == "main" ]] || [[ "$src_file_name" == "completo" ]]; then
echo " - Copiando os $STUDENT_ANSWER_FOLDER/*.c do aluno para a pasta $FILE_NAME_FOLDER"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Copiando os '$STUDENT_ANSWER_FOLDER/*.c' do aluno para a pasta $FILE_NAME_FOLDER\n"
cp $STUDENT_ANSWER_FOLDER/*.c $FILE_NAME_FOLDER
else
echo " - Copiando os $STUDENT_ANSWER_FOLDER/$src_file_name.c do aluno para a pasta $FILE_NAME_FOLDER"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Copiando os '$STUDENT_ANSWER_FOLDER/src_file_name.c' do aluno para a pasta $FILE_NAME_FOLDER\n"
cp $STUDENT_ANSWER_FOLDER/$src_file_name.c $FILE_NAME_FOLDER
fi
done
declare -a student_extra_src_files
if [[ "$FIXED_INTERFACE" == false ]] ; then
echo " - Copiando Arquivos Extras do Aluno:"
for filepath in "$STUDENT_ANSWER_FOLDER/"*.c; do
if [[ -f "$filepath" ]]; then
filename=$(basename "$filepath" .c)
found=false
for gab_src_file in "${src_files_names[@]}"; do
if [[ "$gab_src_file" = "$filename" ]]; then
found=true
break
fi
done
if [ "$found" = "false" ]; then
student_extra_src_files+=("$filename")
files_to_compile+=("$filename")
# for gab_file in "${src_files_names[@]}"; do
# FILE_NAME_FOLDER=$STUDENT_RESULT_FOLDER/$gab_file
# echo "cp $filepath $FILE_NAME_FOLDER"
# cp $filepath $FILE_NAME_FOLDER
# done
echo " - Copiando $filepath para $FILE_NAME_FOLDER/completo"
cp $filepath $STUDENT_RESULT_FOLDER/completo
echo " - Copiando $filepath para $FILE_NAME_FOLDER/main"
cp $filepath $STUDENT_RESULT_FOLDER/main
fi
fi
done
for filepath in "$STUDENT_ANSWER_FOLDER/"*.h; do
if [[ -f "$filepath" ]]; then
filename=$(basename "$filepath" .h)
found=false
for gab_src_file in "${src_files_names[@]}"; do
if [[ "$gab_src_file" = "$filename" ]]; then
found=true
break
fi
done
if [ "$found" = "false" ]; then
# for gab_file in "${src_files_names[@]}"; do
# FILE_NAME_FOLDER=$STUDENT_RESULT_FOLDER/$gab_file
# echo "cp $filepath $FILE_NAME_FOLDER"
# cp $filepath $FILE_NAME_FOLDER
# done
echo " - Copiando $filepath para $FILE_NAME_FOLDER/completo"
cp $filepath $STUDENT_RESULT_FOLDER/completo
echo " - Copiando $filepath para $FILE_NAME_FOLDER/main"
cp $filepath $STUDENT_RESULT_FOLDER/main
fi
fi
done
fi
extra_files_array_size=${#student_extra_src_files[@]}
extra_n_compilation=$((n_folders_to_compile * extra_files_array_size))
# student_n_compilations=$((n_compilations + extra_n_compilation))
student_n_compilations=$((n_compilations))
test_cases_results["student_n_compilations"]=$student_n_compilations
echo -e " - Arquivos copiados: ok!"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Arquivos copiados: ok!\n"
##########################################
# Compilando os arquivos
##########################################
echo -e "\nCOMPILANDO OS ARQUIVOS NA PASTA DE RESULTADO DO ALUNO:"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG}\nCOMPILANDO OS ARQUIVOS NA PASTA DE RESULTADO DO ALUNO:\n"
compilation_errors=0
correct_compilations=0
# echo "cd $STUDENT_RESULT_FOLDER"
cd $STUDENT_RESULT_FOLDER
for src_file_dir in "${src_files_names[@]}"; do
echo " - Compilando a pasta $src_file_dir do aluno, gerando os .o's"
cd $src_file_dir
gcc -Wall -c *.c 2>> result_compilation.txt
if [ $? -ne 0 ]; then
echo " - Erro de compilação! Verifique os arquivos da pasta $src_file_dir."
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Erro de compilação! Verifique os arquivos da pasta $src_file_dir.\n"
compilation_errors=$(expr $compilation_errors + 1)
else
correct_compilations=$(expr $correct_compilations + 1)
fi
cd ../
# echo " - Pasta $ :"
# TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Pasta $src_file_dir:\n"
# for src_file_name in "${files_to_compile[@]}"; do
# if [[ "$src_file_name" == "completo" ]] ; then
# continue
# fi
# source_file=$STUDENT_RESULT_FOLDER/$src_file_dir/$src_file_name.c
# object_file=$STUDENT_RESULT_FOLDER/$src_file_dir/$src_file_name.o
# echo " - Compilando o arquivo $src_file_name.c do aluno, gerando o $src_file_name.o"
# TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Compilando o arquivo $src_file_name.c do aluno, gerando o $src_file_name.o\n"
# gcc -Wall -c $source_file -o $object_file 2>> $STUDENT_RESULT_FOLDER/$src_file_dir/result_compilation.txt
# if [ $? -ne 0 ]; then
# echo " - Erro de compilação! Verifique se o arquivo $source_file está correto."
# TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Erro de compilação! Verifique se o arquivo $source_file está correto.\n"
# compilation_errors=$(expr $compilation_errors + 1)
# else
# correct_compilations=$(expr $correct_compilations + 1)
# fi
# done
# echo " - Arquivo de output gerado: $STUDENT_RESULT_FOLDER/$src_file_dir/result_compilation.txt"
# TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Arquivo de output gerado: $STUDENT_RESULT_FOLDER/$src_file_dir/result_compilation.txt.\n"
done
cd ../../
test_cases_results["compilacoes_corretas"]=$correct_compilations
if [ $compilation_errors -gt 0 ] ; then
echo -e " - Arquivos Compilados: Erro!: $compilation_errors arquivos com erros de compilacao.\n"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Arquivos Compilados: Erro!: $compilation_errors arquivos com erros de compilacao.\n"
# test_cases_results["erros_de_compilacao"]=$compilation_errors
fi
echo " - Copiando os arquivos objetos do professor para cada subpasta do Resultado do $student_name:"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Copiando os arquivos objetos do professor para cada subpasta do Resultado do $student_name:\n"
for src_file_dir in "${src_files_names[@]}"; do
if [[ "$src_file_dir" == "completo" ]] ; then
continue
fi
gab_object=$DIR_GAB_OBJ/$src_file_dir.o
for src_file_name in "${src_files_names[@]}"; do
if [[ "$src_file_name" == "completo" ]] || [[ "$src_file_name" == "$src_file_dir" ]]; then
continue
fi
echo " - Copiando o $gab_object para a pasta $STUDENT_RESULT_FOLDER/$src_file_name"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Copiando o $gab_object para a pasta $STUDENT_RESULT_FOLDER/$src_file_name\n"
cp $gab_object $STUDENT_RESULT_FOLDER/$src_file_name
done
done
echo " - Arquivos Compilados: ok!"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Arquivos Compilados: ok!\n"
##########################################
# Linkando os arquivos compilados
##########################################
echo -e "\nLINKANDO OS ARQUIVOS COMPILADOS:"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG}\nLINKANDO OS ARQUIVOS COMPILADOS:\n"
linking_errors=0
correct_linkings=0
for src_file_dir in "${src_files_names[@]}"; do
echo " - Pasta $src_file_dir:"
echo " - Gerando o binário prog linkando com o(s) arquivo(s) $src_file_dir/*.o"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Pasta $src_file_dir:\n - Gerando o binário prog linkando com o(s) arquivo(s) "$src_file_dir/\*.o"\n"
gcc -o $STUDENT_RESULT_FOLDER/$src_file_dir/prog $STUDENT_RESULT_FOLDER/$src_file_dir/*.o -lm 2>> $STUDENT_RESULT_FOLDER/$src_file_dir/result_linking.txt
if [ $? -ne 0 ]; then
echo -e " - Arquivos Linkados: Erro! Binário prog não gerado."
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Arquivos Linkados: Erro! Binário prog não gerado.\n"
linking_errors=$(expr $linking_errors + 1)
else
echo -e " - Arquivos Linkados: Ok! Binário prog gerado com sucesso."
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Arquivos Linkados: Ok! Binário prog gerado com sucesso.\n"
correct_linkings=$(expr $correct_linkings + 1)
fi
echo " - Arquivo de output gerado: $STUDENT_RESULT_FOLDER/$src_file_dir/result_linking.txt"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Arquivo de output gerado: $STUDENT_RESULT_FOLDER/$src_file_dir/result_linking.txt\n"
done
if [ $linking_errors -gt 0 ] ; then
echo " - Arquivos Linkados: Erro! $linking_errors arquivos com erros de linkagem."
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Arquivos Linkados: Erro! $linking_errors arquivos com erros de linkagem.\n"
# test_cases_results["erros_de_linkagem"]=$linking_errors
fi
test_cases_results["linkagens_corretas"]=$correct_linkings
unset files_to_compile
##################################################
# Executando o Valgrind
##################################################
if [ "$IGNORE_RESULTS" = "false" ] || [ "$IGNORE_VALGRIND" = "false" ]; then
echo -e "\nEXECUTANDO O VALGRIND EM CADA CASO:"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG}\nEXECUTANDO O VALGRIND EM CADA CASO:\n"
for src_file_dir in "${src_files_names[@]}"; do
DIR_CASES=$STUDENT_RESULT_FOLDER/$src_file_dir/Casos
n_cases_folders=0
n_correct_answers=0
n_correct_valgrinds=0
sum_of_the_grades_of_all_cases=0.0
for DIR_CASE in "$DIR_CASES"/*; do
(( n_cases_folders++ ))
(( n_total_cases++ ))
sum_of_the_grades_of_current_case=0.0
txt_out_files=$(find "$DIR_CASE/saida/" -type f -name "*.txt")
if [ -n "$txt_out_files" ]; then
rm -r $DIR_CASE/saida/*.txt
fi
txt_input_file=$(find "$DIR_CASE" -type f -name "*.txt")
case_number=${DIR_CASE##*/}
echo " - Pasta $src_file_dir / Caso $case_number:"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Pasta $src_file_dir / Caso $case_number:\n"
# Valgrind options and arguments
# binary=$STUDENT_RESULT_FOLDER/$src_file_dir/prog
# valgrind_args="--leak-check=full --log-file=$DIR_CASE/result_valgrind.txt"
# output=$(valgrind $valgrind_args $binary < $DIR_CASE/in.txt > "$DIR_CASE/saida/out.txt" 2>&1)
txt_input_file=$(find "$DIR_CASE" -maxdepth 1 -type f -name "*.txt" | head -n 1)
directory_path=$(dirname "$txt_input_file")
filename=$(basename -- "$txt_input_file") # Get only the file name without the full path
filename_no_ext="${filename%.*}" # Get only the file name without the extension
# output="${DIR_CASE}/saida/out_${filename_no_ext}.txt"
output="${DIR_CASE}/saida/saida.txt"
input_file=$directory_path/entrada.txt
# echo "GErando output: $output"
filename_out=$(basename -- "$output") # Get only the file name without the full path
binary=$STUDENT_RESULT_FOLDER/$src_file_dir/prog
valgrind_args="--leak-check=full --log-file=$DIR_CASE/result_valgrind.txt"
# output=$(timeout 5 valgrind $valgrind_args $binary < $txt_input_file > $output 2>&1)
if [ "$IGNORE_VALGRIND" = "false" ]; then
run_output=$(timeout 50 valgrind $valgrind_args $binary $directory_path < $input_file > $output 2>&1)
else
run_output=$(timeout 50 $binary $directory_path < $input_file > $output 2>&1)
fi
# touch "${DIR_CASE}/saida/ranking.txt"
# verificando se o programa já gerou gerou os arquivos dentro da pasta saida
FILES=$(find "${DIR_CASE}/saida/" -maxdepth 1 -type f -name "*.txt" | grep -v "saida.txt")
if [[ -z "$FILES" ]]; then
# não gerou direto la, então copia pra la
find "." -maxdepth 1 -type f -name "*.txt" ! -name "log.txt" ! -name "pontuacao.txt" -exec mv {} "${DIR_CASE}/saida/" \;
fi
# # find "." -maxdepth 1 -type f -name "*.txt" ! -name "log.txt" -exec mv {} "${DIR_CASE}/saida/" \;
# find "." -maxdepth 1 -type f -name "*.txt" ! -name "log.txt" ! -name "pontuacao.txt" -exec mv {} "${DIR_CASE}/saida/" \;
# echo "output: $output"
# output=$(valgrind $valgrind_args $binary < $DIR_CASE/in.txt > "out.txt" 2>&1)
valgrind_desconto=0.5
for key in "${!pesos[@]}"; do
if [[ "$key" == "valgrind" ]]; then
valgrind_desconto=$(echo "scale=2; ${pesos["$key"]}" | bc)
fi
done
if [[ "$IGNORE_VALGRIND" = "true" ]] ; then
valgrind_desconto=0.0
fi
valgrind_desconto_percent=$(echo "scale=2; $valgrind_desconto * 100.0" | bc)
there_is_a_wrong_valgrind=false
if [ "$IGNORE_VALGRIND" = "false" ]; then
if [[ -f "$DIR_CASE/result_valgrind.txt" ]]; then
valgrind_result_file=$DIR_CASE/result_valgrind.txt
echo " - Arquivo de output gerado: $DIR_CASE/result_valgrind.txt."
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Arquivo de output gerado: $DIR_CASE/result_valgrind.txt.\n"
# Valgring returns
allocs=0
frees=0
errors=0
contexts=0
# Using while read loop to process each line of the file
while IFS= read -r line; do
if echo "$line" | grep -q "total heap usage"; then
# Extract the allocs (position 5) and frees (position 7) numbers on the string
allocs=$(echo "$line" | awk '{print $5}')
frees=$(echo "$line" | awk '{print $7}')
elif echo "$line" | grep -q "ERROR SUMMARY"; then
# Extract the errors (position 4) and contexts (position 7) numbers on the string
errors=$(echo "$line" | awk '{print $4}')
contexts=$(echo "$line" | awk '{print $7}')
fi
done < "$valgrind_result_file"
# if [[ -f $valgrind_result_file ]]; then
# rm -r $valgrind_result_file
# fi
# echo "Test Case: $DIR_CASE" >> $valgrind_result_file
# echo "Valgrind result: allocs: $allocs frees: $frees errors: $errors contexts: $contexts" >> $valgrind_result_file
if test "$allocs" = "$frees" && test "$errors" = "0"; then
valgrind_desconto_percent="0.0"
valgrind_desconto=0.0
echo " - Valgrind: Ok! allocs: $allocs, frees: $frees, errors: $errors | Desconto do valgrind: 0.0%"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Valgrind: Ok! allocs: $allocs, frees: $frees, errors: $errors | Desconto do valgrind: 0.0%\n"
else
echo " - Valgrind: Incorreto! allocs: $allocs, frees: $frees, errors: $errors | Desconto do valgrind $valgrind_desconto_percent%"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Valgrind: Incorreto! allocs: $allocs, frees: $frees, errors: $errors | Desconto do valgrind $valgrind_desconto_percent%\n"
there_is_a_wrong_valgrind=true
fi
else
echo " - Valgrind: Incorreto! Verifique se o binário prog foi gerado corretamente. Ou se o Valgrind está instalado."
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Valgrind: Incorreto! Verifique se o binário prog foi gerado corretamente. Ou se o Valgrind está instalado.\n"
there_is_a_wrong_valgrind=true
fi
fi
DIR_CASE_SAIDA=$DIR_CASE/saida
txt_file_names=()
there_is_a_wrong_answer=false
# Loop through all files in the saida folder
declare -A txts_corretos
for key in "${!pesos[@]}"; do
if [[ "$key" == *".txt" ]]; then
txts_corretos["$key"]=0.0
fi
done
for gab_case_txt_file in "$DIR_GAB_CASOS/$case_number/saida"/*.txt; do
if [ -f "$gab_case_txt_file" ]; then # Check if the file is a regular file (not a directory or special file)
# txt_file_names+=("$gab_case_txt_file") # Add the file name to the array
filename=$(basename -- "$gab_case_txt_file") # Get only the file name without the full path
txt_file_names+=("$filename") # Add the file name to the array
filename_no_ext="${filename%.*}" # Get only the file name without the extension
student_output_file=$DIR_CASE/saida/$filename
# echo "student_output_file: $student_output_file"
if test -e "$student_output_file"; then
# mv $filename $DIR_CASE_SAIDA
# Making a copy of the professor out.txt file and the student out.txt file, inside the test cases student folder
output_student_copy="$filename_no_ext"_student_copy.txt
output_professor_copy="$filename_no_ext"_professor_copy.txt
cp $DIR_CASE_SAIDA/$filename $DIR_CASE_SAIDA/$output_student_copy
cp $DIR_GAB_CASOS/$case_number/saida/$filename $DIR_CASE_SAIDA/$output_professor_copy
chmod 777 $DIR_CASE_SAIDA/$output_student_copy
chmod 777 $DIR_CASE_SAIDA/$output_professor_copy
# Removing trailing white spaces at end of each line, and removing trailing newlines at the end of the file
sed -i 's/[[:space:]]*$//' "$DIR_CASE_SAIDA/$output_student_copy"
sed -i ':a; /./,$!{N;ba}; /^$/d' "$DIR_CASE_SAIDA/$output_student_copy"
sed -i 's/[[:space:]]*$//' "$DIR_CASE_SAIDA/$output_professor_copy"
sed -i ':a; /./,$!{N;ba}; /^$/d' "$DIR_CASE_SAIDA/$output_professor_copy"
# Open both files for reading
exec 3< "$DIR_CASE_SAIDA/$output_student_copy"
exec 4< "$DIR_CASE_SAIDA/$output_professor_copy"
files_are_equal="true"
while true; do
# Read a line from each file
read -r line1 <&3
read -r line2 <&4
# Check if we reached the end of both files
if [[ -z "$line1" && -z "$line2" ]]; then
break
fi
# Ignore blank lines and continue the loop
if [[ -z "$line1" && -z "$line2" ]]; then
continue
fi
# Compare lines and check for differences
if [[ "$line1" != "$line2" ]]; then
files_are_equal="false"
fi
done
# Close file descriptors
exec 3<&-
exec 4<&-
if test "$files_are_equal" = "false"; then
there_is_a_wrong_answer=true
echo " - Resultado para o $filename: Incorreto! Peso: 0.0"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Resultado para o $filename: Incorreto!\n"
else
txts_corretos["$filename"]=1.0
echo " - Resultado para o $filename: Ok! Peso: ${pesos[$filename]}"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - Resultado para o $filename: Ok! Peso: ${pesos[$filename]}\n"
(( n_correct_answers++ ))
test_cases_pontuacoes["$filename"]=$((test_cases_pontuacoes["$filename"] + 1))
fi
rm "$DIR_CASE_SAIDA/$output_student_copy"
rm "$DIR_CASE_SAIDA/$output_professor_copy"
else
echo " - O aluno não gerou o arquivo de saída $DIR_CASE_SAIDA/$filename, considerando resultado incorreto! Peso: 0.0"
TERMINAL_OUTPUT_LOG="${TERMINAL_OUTPUT_LOG} - O aluno não gerou o arquivo de saída $DIR_CASE_SAIDA/$filename, considerando resultado incorreto!\n"
there_is_a_wrong_answer=true
fi
fi
done