-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBasicCheck.sh
More file actions
95 lines (86 loc) · 1.91 KB
/
BasicCheck.sh
File metadata and controls
95 lines (86 loc) · 1.91 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
# This program is responsible to check for memory leaks, Thread debugger
# and run the input program
# this TEST made through CPP Course by Tzvi Mints, Or Abuhazira
# and Eilon Tsadok
#!/bin/bash
Answer=(FAIL FAIL FAIL)
# This function is responsible for print output to the screen
output_to_screen() {
echo "Compilation Memory leaks thread race"
echo -e " ${Answer[0]} \t\t ${Answer[1]} \t\t ${Answer[2]}"
echo -e "\t\t Summary: $1"
exit $1
}
# This function is responsible for making step 3 in the assignment
step3() {
compile $1 $2
first=$?
memorychk $1 $2
second=$?
threaddebugger $1 $2
third=$?
answer=$((2#$first$second$third))
output_to_screen $answer
}
# This function is responsible for Thread debugger used by Helgrind
threaddebugger() {
valgrind --tool=helgrind --error-exitcode=1 ./$1 $2 >/dev/null 2>&1
if [ $? -eq 0 ]
then
Answer[2]=PASS
return 0
else
return 1
fi
}
# This function is responsible to check for memory leaks used by Velgrind
memorychk() {
valgrind --leak-check=full --error-exitcode=1 ./$1 $2 >/dev/null 2>&1
if [ $? -eq 0 ]
then
Answer[1]=PASS
return 0
else
return 1
fi
}
# This function is responsible to compile the input
# Program and then go to step 3, which is memory check
compile() {
./$1 $2 2>/dev/null
if [ $? -eq 0 ]
then
Answer[0]=PASS
return 0
else
return 1
fi
}
# Check if there currect amount of values
if [ $# -lt 2 ] # Less then 2
then
echo "There Less Then 2 Arguments"
exit 7
fi
dir_path=$1
program=$2
shift 2
arguments=$@
# Print First Line
echo "BasicCheck.sh $dir_path <$program> $arguments"
# Search for Makefile
cd $dir_path
find Makefile >/dev/null 2>&1
if [ $? -eq 0 ]
then
make >/dev/null 2>&1
if [ $? -eq 0 ]
then
step3 $program $arguments
else
output_to_screen 7
fi
else
echo "Makefile Not Found"
output_to_screen 7
fi