-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_syscall.sh
executable file
·95 lines (84 loc) · 1.9 KB
/
run_syscall.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
#! /bin/bash
prepare_function()
{
if [ "$FUNCT" = "read" ]
then
echo "testing read function" > read.txt
echo "testing read function" > ft_read.txt
fi
}
check_error()
{
if [ "$FUNCT" = "read" ] && [ $1 = $STD ]
then
echo -e "\e[2mtesting stdin\e[0m"
else
ERROR_FD=$( ./"$FUNCT" "$1" $IMPLEM ft_"$FUNCT".txt 2>&1 >/dev/null )
fi
}
make_diff ()
{
DIFF=$(diff "$2" "$3")
if [ "$DIFF" != "" ]
then
echo -e "\033[0;31m[KO]\033[0m"
echo "--- EXPECTED RESULT ---" >> diffs/ft_"$FUNCT"."$1".txt
cat a >> diffs/ft_"$FUNCT"."$1".txt
echo "--- ACTUAL RESULT ---" >> diffs/ft_"$FUNCT"."$1".txt
cat b >> diffs/ft_"$FUNCT"."$1".txt
else
echo -e "\033[0;32m[OK]\033[0m"
rm -f diffs/ft_"$FUNCT"."$1".txt
fi
}
run_compare()
{
if [ $? = 0 ]
then
./"$FUNCT" "$1" "$ORIG" "$FUNCT".txt > a
./"$FUNCT" "$1" "$IMPLEM" ft_"$FUNCT".txt > b
DIFF=$(diff a b)
if [ "$DIFF" != "" ]
then
echo -e "\033[0;31m[KO]\033[0m"
echo "--- EXPECTED RESULT ---" >> diffs/ft_"$FUNCT"."$1".txt
cat "$FUNCT".txt >> diffs/ft_"$FUNCT"."$1".txt
echo "" >> diffs/ft_"$FUNCT"."$1".txt
cat a >> diffs/ft_"$FUNCT"."$1".txt
echo "--- ACTUAL RESULT ---" >> diffs/ft_"$FUNCT"."$1".txt
cat ft_"$FUNCT".txt >> diffs/ft_"$FUNCT"."$1".txt
echo "" >> diffs/ft_"$FUNCT"."$1".txt
cat b >> diffs/ft_"$FUNCT"."$1".txt
else
echo -e "\033[0;32m[OK]\033[0m"
fi
rm -rf a b
else
echo -e "\033[0;31m[ERROR]\033[0m"
fi
}
test_input()
{
prepare_function
check_error "$1"
run_compare "$1"
}
STD=0
FD_OPEN=1
FD_WRONG=2
FUNCT=$1
echo -e ""
echo -e "\033[0;1m> ft_"$FUNCT"\033[0m"
COMP=$( clang testers/test_"$FUNCT".c -L. -lasm -o "$FUNCT" 2>&1 >/dev/null )
if [ $? = 0 ]
then
clang -Wall -Werror -Wextra testers/test_"$FUNCT".c -L. -lasm -o "$FUNCT"
test_input $STD
test_input $FD_OPEN
test_input $FD_WRONG
rm -f "$FUNCT"
else
echo -e "\033[0;31m[DONT COMPILE]\033[0m"
fi
rm -f "$FUNCT".txt
rm -f ft_"$FUNCT".txt