-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtesting.sh
executable file
·166 lines (136 loc) · 3.49 KB
/
testing.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
#!/bin/bash
function showOk {
raspi-gpio set 17 dl
raspi-gpio set 27 dl
raspi-gpio set 22 dh
echo "######"
echo "All tests OK"
echo "######"
}
function showFailed {
raspi-gpio set 17 dh
raspi-gpio set 27 dl
raspi-gpio set 22 dl
echo "######"
echo "Tests FAILED"
echo "######"
}
i2cDir="/sys/class/i2c-adapter/i2c-0"
i2cAddDevCmd="24c32 0x50"
i2cDev="0-0050"
testingDir="/home/pi/testing"
eepFile="rr_base.eep"
encDrvMsg="enc28j60 driver registered"
if [ "$(id -u)" -ne "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
echo "Initializing tests"
# Initialize LEDs: Red Yellow Green => Low
raspi-gpio set 17 op
raspi-gpio set 27 op
raspi-gpio set 22 op
ping -c 1 -W 1 www.google.at &> /dev/null
if [ "$?" -ne "0" ]; then
raspi-gpio set 17 dh
else
raspi-gpio set 17 dl
fi
raspi-gpio set 27 dh
raspi-gpio set 22 dh
# Initialize Button
raspi-gpio set 26 ip pu
# Debugging
#echo "0x50" > ${i2cDir}/delete_device
# Creating EEPROM device node
if [ ! -d "${i2cDir}/${i2cDev}" ]; then
echo "Creating EEPROM device node"
echo "${i2cAddDevCmd}" > ${i2cDir}/new_device
fi
# Visualize "Done initializing"
sleep 2
buttonPressed=$(raspi-gpio get 26 | cut -d '=' -f 2 | cut -d ' ' -f 1)
if [ "${buttonPressed}" -eq "0" ]; then
echo "Updating"
raspi-gpio set 17 dh
raspi-gpio set 27 dl
raspi-gpio set 22 dh
git -C ${testingDir} pull origin_read master
chown -R pi:pi ${testingDir}
sleep 1
reboot
exit 0
else
echo "Done initializing"
raspi-gpio set 17 dl
raspi-gpio set 27 dl
fi
echo "Waiting for button pressed event"
while true; do
buttonPressed=$(raspi-gpio get 26 | cut -d '=' -f 2 | cut -d ' ' -f 1)
if [ "${buttonPressed}" -eq "0" ]; then
startTime=${SECONDS}
raspi-gpio set 17 dl
raspi-gpio set 27 dh
raspi-gpio set 22 dl
result=0
echo "##################"
echo "Button pressed"
echo "Starting tests"
sleep 1
buttonPressed=$(raspi-gpio get 26 | cut -d '=' -f 2 | cut -d ' ' -f 1)
if [ "${buttonPressed}" -eq "0" ]; then
raspi-gpio set 17 dh
numExpEthDrvOk=1
else
numExpEthDrvOk=2
fi
echo "Checking ethernet driver messages"
echo "Expected number of interfaces: ${numExpEthDrvOk}"
yes "dummy" | head -n 20 >> /dev/kmsg
rmmod enc28j60 &> /dev/null
modprobe enc28j60
numEthDrvOk=$(dmesg | tail -n 10 | grep "${encDrvMsg}" | wc -l)
if [ "${numEthDrvOk}" -eq "${numExpEthDrvOk}" ]; then
echo "Ethernet test OK"
else
result=1
echo "######"
echo "Error: Number of working interfaces: ${numEthDrvOk}"
echo "######"
fi
echo "Comparing EEPROM data to factory file"
cmp ${testingDir}/${eepFile} ${i2cDir}/${i2cDev}/eeprom -n $(wc -c ${testingDir}/${eepFile} | cut -d " " -f 1)
# false
if [ "$?" -ne "0" ]; then
echo "Data on EEPROM differs from factory file"
if [ -z "$1" ]; then
echo "Writing factory file to EEPROM"
dd if=${testingDir}/${eepFile} of=${i2cDir}/${i2cDev}/eeprom
fi
echo "Comparing again"
cmp ${testingDir}/${eepFile} ${i2cDir}/${i2cDev}/eeprom -n $(wc -c ${testingDir}/${eepFile} | cut -d " " -f 1)
if [ "$?" -eq "0" ]; then
echo "EEPROM test OK"
else
result=1
echo "######"
echo "Error: Data on EEPROM still differs from factory file"
echo "######"
fi
else
echo "EEPROM test OK"
fi
if [ "${result}" -eq "0" ]; then
showOk
else
showFailed
fi
elapsedTime=$((${SECONDS} - ${startTime}))
echo "Duration: $(($elapsedTime / 60)) min $(($elapsedTime % 60)) sec"
echo "##################"
echo "Waiting for button pressed event"
fi
sleep 1
done
exit 0