-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-cli.sh
354 lines (308 loc) · 8.31 KB
/
test-cli.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
#!/usr/bin/env bash
#########################################################################
#
# The test-cli is an application intended to runs all the tests in non-lava environment
# Input: It takes input from a text file which contains testcases of respectives suites
# Output: Prints all the executed test steps results to console and records into local files.
# Author: Muhammad Farhan <engr.farhan@icloud.com>
#
# Usage: ./test-cli.sh [ComponentUnderTest]
#
#
#########################################################################
#### GET TARGET INFO ###########
function hwinfo () {
clear
TIME=1
echo " "
echo $0
echo " "
echo "Choose an option below!
1 - Verify desktop processor
2 - Verify system kernel
3 - Verify installed softwares
4 - Operation system version
5 - Verify desktop memory
6 - Verify serial number
7 - Verify system IP
0 - Exit"
echo " "
echo -n "Chosen option: "
read opcao
case $opcao in
1)
function processador () {
CPU_INFO=`cat /proc/cpuinfo | grep -i "^model name" | cut -d ":" -f2 | sed -n '1p'`
echo "CPU model: $CPU_INFO"
sleep $TIME
}
processador
read -n 1 -p "<Enter> for main menu"
hwinfo
;;
2)
function kernel () {
#RED HAT: cat /etc/redhat-release
KERNEL_VERSION_UBUNTU=`uname -r`
KERNEL_VERSION_CENTOS=`uname -r`
if [ -f /etc/lsb-release ]
then
echo "kernel version: $KERNEL_VERSION_UBUNTU"
else
echo "kernel version: $KERNEL_VERSION_CENTOS"
fi
}
kernel
read -n 1 -p "<Enter> for main menu"
hwinfo
;;
3)
function softwares () {
#while true; do
TIME=3
echo " "
echo "Choose an option below for program's list!
1 - List Ubuntu programs
2 - List Fedora programs
3 - Install programs
4 - Back to menu"
echo " "
echo -n "Chosen option: "
read alternative
case $alternative in
1)
echo "Listing all programs Ubuntu's systems..."
sleep $TIME
dpkg -l > /tmp/programs.txt
echo Programs listed and available at /tmp
sleep $TIME
echo " "
echo "Back to menu!" | tr [a-z] [A-Z]
sleep $TIME
;;
2)
echo "Listing all programs Fedora's systems..."
sleep $TIME
yum list installed > /tmp/programs.txt
echo Programs listed and available at /tmp
sleep $TIME
;;
3)
echo Installing programss...
LIST_OF_APPS="pinta brasero gimp vlc inkscape blender filezilla"
#use aptitude command for programs loop.
apt install aptitude -y
aptitude install -y $LIST_OF_APPS
;;
4)
echo Back to main menu...
sleep $TIME
;;
esac
#done
}
softwares
hwinfo
;;
4)
function sistema () {
VERSION=`cat /etc/os-release | grep -i ^PRETTY`
if [ -f /etc/os-release ]
then
echo "The system version: $VERSION"
else
echo "System not supported"
fi
}
sistema
read -n 1 -p "<Enter> for main menu"
hwinfo
;;
5)
function memory () {
MEMORY_FREE=`free -m | grep ^Mem | tr -s ' ' | cut -d ' ' -f 4`
#MEMORY_TOTAL=
#MEMORY_USED=
echo Verifying system memory...
echo "Memory free is: $MEMORY_FREE"
}
memory
read -n 1 -p "<Enter> for main menu"
hwinfo
;;
6)
function serial () {
SERIAL_NUMBER=`dmidecode -t 1 | grep -i serial`
echo $SERIAL_NUMBER
}
serial
read -n 1 -p "<Enter> for main menu"
hwinfo
;;
7)
function ip () {
IP_SISTEMA=`hostname -I`
echo IP is: $IP_SISTEMA
}
ip
read -n 1 -p "<Enter> for main menu"
hwinfo
;;
0)
echo Exiting the system...
sleep $TIME
exit 0
;;
*)
echo Invalid option, try again!
;;
esac
}
#############3 return the current path ###############
LEVEL=$1
for ((i = 0; i < LEVEL; i++)); do
echo $i
# CDIR=../$CDIR
done
# cd $CDIR
echo "You are in: "$PWD
sh=$(which $SHELL)
# exec $sh
###############
#SERVER HEALTH
#################
function heath () {
date
echo "uptime:"
uptime
echo "Currently connected:"
w
echo "--------------------"
echo "Last logins:"
last -a | head -3
echo "--------------------"
echo "Disk and memory usage:"
df -h | xargs | awk '{print "Free/total disk: " $11 " / " $9}'
free -m | xargs | awk '{print "Free/total memory: " $17 " / " $8 " MB"}'
echo "--------------------"
start_log=$(head -1 /var/log/messages | cut -c 1-12)
oom=$(grep -ci kill /var/log/messages)
echo -n "OOM errors since $start_log :" $oom
echo ""
echo "--------------------"
echo "Utilization and most expensive processes:"
top -b | head -3
echo
top -b | head -10 | tail -4
echo "--------------------"
echo "Open TCP ports:"
nmap -p -T4 127.0.0.1
echo "--------------------"
echo "Current connections:"
ss -s
echo "--------------------"
echo "processes:"
ps auxf --width=200
echo "--------------------"
echo "vmstat:"
vmstat 1 5
}
# Set test results file path
TEST_RESULTS=/tmp/$1.log
echo "Test CLI has been started to execute the script: $1"
for c in 31 32 35 36 ; do
echo -en "\r \e[${c}m Automated Test CLI Controller v1.2 is Ready \e[0m "
echo $date
sleep 1
done
usage()
{
# hwinfo
echo "\n\n\n****Name of Component Under the test is missing.*******\n\n\nTHIS IS HOW YOU PROVIDE COMPONENT TO CLI: $0 COMPONENT_NAME "
echo -e "\n\n\nPLEASE SPECIFY THE COMPONENT_NAME - Incase of help contact engr.farhan@icloud.com"
exit 1
}
case "$1" in
runtime)
echo "verifying all the debian packages installed on system"
echo "*****************************\n"
Total_test=`wc -l runtime/debian_package_input_file | cut -d " " -f1`
cd "$1"
for i in `cat debian_package_input_file`; do ./$i | tee -a $TEST_RESULTS ; done
;;
filesystem)
echo "Executing all filesystem testcases on system"
echo "*****************************\n"
Total_test=`wc -l filesystem/filesystem_tests_input_file | cut -d " " -f1`
cd "$1"
for i in `cat filesystem_tests_input_file`; do ./$i | tee -a $TEST_RESULTS ; done
;;
kernel)
echo "Executing all Kernel testcases on system"
echo "*****************************\n"
Total_test=`wc -l kernel/general_kernel_features_test_input | cut -d " " -f1`
cd "$1"
for i in `cat general_kernel_features_test_input`; do ./$i | tee -a $TEST_RESULTS ; done
;;
IO)
echo "Executing Board IO testcases on system"
echo "*****************************\n"
Total_test=`wc -l IO/IO_tests_input_file | cut -d " " -f1`
cd "$1"
for i in `cat IO_tests_input_file`; do ./$i | tee -a $TEST_RESULTS ; done
;;
""|--help)
usage
;;
*)
echo "Invalid suite name: $1"
exit 1
;;
esac
# API to get test counts and results
get_ok_results()
{
(cat $TEST_RESULTS | grep -i "test passed$" || cat $TEST_RESULTS | grep -i "RESULT=pass") | wc -l
}
# To get no. of failed test counts
get_failed_results()
{
(cat $TEST_RESULTS | grep -i "test failed$" || cat $TEST_RESULTS | grep -i "RESULT=fail") | wc -l
}
# To get no. of skipped test counts
get_count_skip()
{
(cat $TEST_RESULTS | grep -iw "skip$" || cat $TEST_RESULTS | grep -i "RESULT=skip") | wc -l
}
# To get list of passed testcases
get_ok_results()
{
cat $TEST_RESULTS | grep -i "test passed$" || cat $TEST_RESULTS | grep -i "RESULT=pass" | awk '{print $2,$3}' | cut -d ">" -f1
}
# To get list of failed testcases
get_failed_results()
{
cat $TEST_RESULTS | grep -i "test failed$" || cat $TEST_RESULTS | grep -i "RESULT=fail" | awk '{print $2,$3}' | cut -d ">" -f1
}
# To get list of skipped testcases
get_testcase_skip()
{
cat $TEST_RESULTS | grep -iw "skip$" || cat $TEST_RESULTS | grep -iw "RESULT=skip" | awk '{print $2,$3}' | cut -d ">" -f1
}
echo "\n Test Summary Report:"
echo "*****************************\n"
echo "Total number of Linux debian packages those are tested: $Total_test \n"
echo "Total number of Linux debian packages those are Passed: $(get_ok_results)"
echo "Total number of Linux debian packages those are Failed: $(get_failed_results)"
echo "Total number of Linux debian packages those are Skipped: $(get_count_skip)"
echo "*****************************\n"
echo "=============Detail Lists==================\n"
echo "List of testcases passed:\n"
get_ok_results
echo "List of testcases failed:\n"
get_failed_results
echo "List of testcases skipped:\n"
get_testcase_skip
echo "====================finished============"
# Remove log file
rm -rf $TEST_RESULTS