-
Notifications
You must be signed in to change notification settings - Fork 5
/
astroguard.sh
executable file
·193 lines (164 loc) · 4.18 KB
/
astroguard.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
#!/bin/bash
# astroguard - A code auditing and streamlining tool for C programs to adhere to NASA JPL's Rule of 10
# Developed for Stellaryx Labs [stellaryxlabs.com]
# Written by Angelina Tsuboi [angelinatsuboi.com]
# Released under MIT License
set -- $GRARGS $@
set -e
set -o pipefail
# Default Values
hidebanner=0
version=0.1
file_name=""
file_path=""
file_name_no_ext=""
file_path_no_ext=""
# Default colors
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
blue='\033[0;34m'
magenta='\033[0;35m'
cyan='\033[0;36m'
clear='\033[0m'
banner() {
if [ $hidebanner == 0 ]; then
IFS=
while IFS= read -r line; do
print_color "$line" magenta
done < "./assets/banner.txt"
fi
}
about() {
cat "./assets/help.txt"
}
# Adding color to terminal messages
print_color() {
local text="$1"
local color="$2"
local selected_color="$blue"
case $color in
red)
selected_color="$red"
;;
green)
selected_color="$green"
;;
yellow)
selected_color="$yellow"
;;
blue)
selected_color="$blue"
;;
magenta)
selected_color="$magenta"
;;
cyan)
selected_color="$cyan"
;;
esac
echo -e "${selected_color}${text}${clear}"
}
# Step #1
# Installation Checking
# Checks for the following tools: gcc, gcov, gdb, and lcov
installation() {
print_color "Lauching astroguard 🚀" cyan
print_color "Step 1 > Checking for installations" cyan
if command -v gcc &> /dev/null; then
print_color "GCC is installed!"
else
print_color "GCC is not installed. Please install GCC before proceeding." red
exit 1
fi
if command -v gcov &> /dev/null; then
print_color "gcov is installed!"
else
print_color "gcov is not installed. Please install gcov before running this script." red
exit 1
fi
if command -v lcov &> /dev/null; then
print_color "lcov is installed!"
else
print_color "lcov is not installed. Please install lcov before running this script." red
exit 1
fi
if command -v gdb &> /dev/null; then
print_color "gdb is installed!"
else
print_color "gdb is not installed. Please install gdb before running this script." red
exit 1
fi
}
# Step #2
# Compiles the C program
# Compilations settings set to the most pedantic level
compile() {
print_color "Step 2 > Compiling Input File" cyan
# Compile the C file
gcc -Wall -pedantic -Wtraditional -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -Wconversion -std=iso9899:1999 --coverage "${file_path}" -o "${file_path_no_ext}"
# Check if compilation was successful
if [ $? -eq 0 ]; then
# Execute the compiled program
"${file_path_no_ext}"
else
print_color "Compilation failed." red
fi
}
# Step #3
# Generate code coverage report using gcov
coverage() {
print_color "Step 3 > Generating Coverage Report" cyan
gcov "${file_name}"
}
# Step #4
# Generate line coverage report using lcov
line_coverage() {
print_color "Step 4 > Generating Line Coverage Report" cyan
lcov -c --directory . --output-file main_coverage.info
}
# Step #5
# Generate HTML coverage report using genhtml
gen_html() {
print_color "Step 5 > Generating HTML Coverage Report" cyan
genhtml main_coverage.info --output-directory out
open "./${pwd}${dirname}/out/index.html"
}
while getopts "bBho:" flag; do
case $flag in
b)
hidebanner=1
;;
h)
about
exit 1
;;
\?)
about
exit 2
;;
esac
done
shift $((OPTIND-1))
file_path="$1"
file_name=$(basename -- "$file_path")
file_name_no_ext="${file_name%.*}"
file_path_no_ext="${file_path%.*}"
echo $file_path_no_ext
file_ext="${file_path: -1}"
# Check if a file path is provided
if [ -z "$file_path" ]; then
print_color "Error: File path not provided." red
exit 1
elif [ "${file_ext}" != "c" ]; then
print_color "Error: File must be C." red
exit 1
fi
banner
installation
compile
coverage
line_coverage
gen_html
print_color "Finished running all reports 🚀" cyan
exit