CAN bus tests
[src/qa-testdefinitions.git] / common / scripts / test_can_bitrate.sh
1 #!/bin/sh
2
3 #This test is writen taking the DRA7xx-EVM board as an example
4 #Theorical values of bitrate is from 1Kbit/s to 1Mbit/s
5 #Real values to provide transmission are between 10797 bit/s and 1909090git bit/s
6 #Real values that doesn't provide transmission but belong to the domain are between 781 bit/s and 5209999 bit/s
7
8 if [ ! -e /sys/class/net/can1 ];then
9         lava-test-case canconfig_can0_bitrate --result skip
10         lava-test-case receive_frames_through_can1 --result skip
11         lava-test-case receive_frames_through_can1 --result skip
12         lava-test-case receive_frames_through_can1 --result skip
13         lava-test-case canconfig_can0_bitrate --result skip
14         lava-test-case receive_frames_through_can1 --result skip
15         exit 0
16 fi
17
18 #This is the first part of the test, that tests if the bitrate inserted belongs to the domain and if
19 #this first bitrate afford frames transmission or not
20 canconfig can0 stop
21 if [ $? -eq 0 ];then
22         lava-test-case stop_can0 --result pass
23 else
24         lava-test-case stop_can0 --result fail
25 fi
26 sleep 2
27 canconfig can1 stop
28 if [ $? -eq 0 ];then
29         lava-test-case stop_can1 --result pass
30 else
31         lava-test-case stop_can1 --result fail
32 fi
33 sleep 2
34
35 # b refers to bitrate
36
37 found_bitrate=0
38 for b in `seq 778 790`;do
39         canconfig can0 bitrate $b
40         x=$?
41         if [ $x -eq 0 ];then
42                 lava-test-case can0_bitrate --result pass --measurement $b --units bit/s
43                 echo "$b is the first bitrate in the domain"
44                 found_bitrate=1
45                 canconfig can1 bitrate $b
46                 if [ $? -eq 0 ];then
47                         lava-test-case can1_bitrate --result pass --measurement $b --units bit/s
48                 else
49                         lava-test-case can1_bitrate --result fail --measurement $b --units bit/s
50                 fi
51                 sleep 2
52                 canconfig can0 start
53                 if [ $? -eq 0 ];then
54                         lava-test-case start_can0 --result pass
55                 else
56                         lava-test-case start_can0 --result fail
57                 fi
58                 sleep 2
59                 canconfig can1 start
60                 if [ $? -eq 0 ];then
61                         lava-test-case start_can1 --result pass
62                 else
63                         lava-test-case start_can1 --result fail
64                 fi
65                 sleep 2
66                 file_can=$(mktemp)
67                 cansequence -p can0 &
68                 candump can1 > $file_can &
69                 sleep 3
70                 if [ -s $file_can ];then
71                         lava-test-case Receive_can1 --result pass --measurement $b --units bit/s
72                 else
73                         lava-test-case Receive_can1 --result fail --measurement $b --units bit/s
74                         sleep 2
75                         echo "This bitrate $b belongs to the domain but doesn't provide frames transmission"
76                         break
77                 fi
78                 rm $file_can
79         fi
80 done
81
82 if [ $found_bitrate -eq 0 ];then
83         lava-test-case can0_bitrate --result fail --measurement $b --units bit/s
84         sleep 2
85         echo "There is no supportable bitrate in this interval"
86 fi
87 canconfig can0 stop
88 canconfig can1 stop
89 sleep 2
90 #This is the second part of the test, it tests the first bitrate to provide frames transmission
91
92 canconfig can0 stop
93 canconfig can1 stop
94 found_bitrate_for_transmisson=0
95 for b in `seq 10790 10800`;do
96         canconfig can0 bitrate $b
97         canconfig can1 bitrate $b
98         canconfig can0 start
99         canconfig can1 start
100         sleep 3
101         file_can=$(mktemp)
102         cansequence -p can0 &
103         candump can1 > $file_can &
104         sleep 4
105         if [ -s $file_can ];then
106                 found_bitrate_for_transmisson=1
107                 lava-test-case Receive_can1 --result pass --measurement $b --units bit/s
108                 sleep 2
109                 echo "$b is the first supportable bitrate to provide transmission"
110                 break
111         fi
112         canconfig can0 stop
113         canconfig can1 stop
114         rm $file_can
115 done
116
117 if [ $found_bitrate_for_transmisson -eq 0 ];then
118         lava-test-case Receive_can1 --result fail --measurement $b --units bit/s
119         sleep 2
120         echo "There is no bitrate in this interval to provide frames transmission"
121 fi
122
123
124 #This is the third part of the test, it tests the last bitrate to provide frames transmission
125
126 canconfig can0 stop
127 canconfig can1 stop
128 bitrate_no_transmission=0
129 for b in `seq 1909088 1909092`;do
130         canconfig can0 bitrate $b
131         canconfig can1 bitrate $b
132         canconfig can0 start
133         canconfig can1 start
134         sleep 2
135         file_can=$(mktemp)
136         cansequence -p can0 &
137         candump can1 > $file_can &
138         sleep 3
139         size=$(stat -c %s $file_can)
140         if [ $size -eq 0 ];then
141                 bitrate_no_transmission=1
142                 B=($b-1)
143                 lava-test-case Receive_can1 --result pass --measurement $B --units bit/s
144                 lava-test-case Receive_can1 --result fail --measurement $b --units bit/s
145                 sleep 2
146                 echo "This bitrate $b doesn't provide frames transmission"
147                 echo "The last bitrate to provide frames transmission is $(($b-1))"
148                 break
149         fi
150         canconfig can0 stop
151         canconfig can1 stop
152         rm $file_can
153 done
154
155 if [ $bitrate_no_transmission -eq 0 ];then
156         lava-test-case Receive_can1 --result pass --measurement $b --units bit/s
157         echo "All bitrates in this interval provide frames transmission"
158         canconfig can0 stop
159         canconfig can1 stop
160 fi
161
162 #This is the last part of the test, it tests the last bitrate that belongs to the domain
163 sleep 3
164 canconfig can0 stop
165 canconfig can1 stop
166 out_of_domain=0
167 for b in `seq 5290999 5291000`;do
168         canconfig can0 bitrate $b
169         x=$?
170         sleep 2
171         if [ $x -ne 0 ];then
172                 out_of_domain=1
173                 lava-test-case can0_bitrate --result fail --measurement $b --units bit/s
174                 echo "$b is the first bitrate to be out of the domain"
175                 echo "The last bitrate to belong to the domain is $(($b-1))"
176                 break
177         fi
178 done
179
180 if [ $out_of_domain -eq 0 ];then
181         lava-test-case can0_bitrate --result pass --measurement $b --units bit/s
182         echo "All bitrates in this interval belong to the domain"
183         canconfig can0 stop
184         canconfig can1 stop
185 fi