summaryrefslogtreecommitdiffstats
path: root/common/scripts/test_can_bitrate.sh
blob: 08592fe4233743e91ee91ddf7182b14bce6a7499 (plain)
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
#!/bin/sh

#This test is writen taking the DRA7xx-EVM board as an example
#Theorical values of bitrate is from 1Kbit/s to 1Mbit/s
#Real values to provide transmission are between 10797 bit/s and 1909090git bit/s
#Real values that doesn't provide transmission but belong to the domain are between 781 bit/s and 5209999 bit/s

if [ ! -e /sys/class/net/can1 ];then
	lava-test-case canconfig_can0_bitrate --result skip
	lava-test-case receive_frames_through_can1 --result skip
	lava-test-case receive_frames_through_can1 --result skip
	lava-test-case receive_frames_through_can1 --result skip
	lava-test-case canconfig_can0_bitrate --result skip
	lava-test-case receive_frames_through_can1 --result skip
	exit 0
fi

#This is the first part of the test, that tests if the bitrate inserted belongs to the domain and if
#this first bitrate afford frames transmission or not
ip link set can0 down
if [ $? -eq 0 ];then
    lava-test-case stop_can0 --result pass
else
    lava-test-case stop_can0 --result fail
fi
sleep 2
ip link set can1 down
if [ $? -eq 0 ];then
    lava-test-case stop_can1 --result pass
else
    lava-test-case stop_can1 --result fail
fi
sleep 2

# b refers to bitrate

found_bitrate=0
for b in `seq 778 790`;do
	ip link set can0 type can bitrate $b
	x=$?
	if [ $x -eq 0 ];then
		lava-test-case can0_bitrate --result pass --measurement $b --units bit/s
		echo "$b is the first bitrate in the domain"
		found_bitrate=1
		ip link set can1 type can bitrate $b
		if [ $? -eq 0 ];then
			lava-test-case can1_bitrate --result pass --measurement $b --units bit/s
		else
			lava-test-case can1_bitrate --result fail --measurement $b --units bit/s
		fi
		sleep 2
		ip link set can0 up
		if [ $? -eq 0 ];then
			lava-test-case start_can0 --result pass
		else
			lava-test-case start_can0 --result fail
		fi
		sleep 2
		ip link set can1 up
		if [ $? -eq 0 ];then
			lava-test-case start_can1 --result pass
		else
			lava-test-case start_can1 --result fail
		fi
		sleep 2
		file_can=$(mktemp)
		cangen can0 &
		candump can1 > $file_can &
		sleep 3
		if [ -s $file_can ];then
			lava-test-case Receive_can1 --result pass --measurement $b --units bit/s
		else
			lava-test-case Receive_can1 --result fail --measurement $b --units bit/s
			sleep 2
			echo "This bitrate $b belongs to the domain but doesn't provide frames transmission"
		fi
		rm $file_can
		break
	fi
done

if [ $found_bitrate -eq 0 ];then
	lava-test-case can0_bitrate --result fail --measurement $b --units bit/s
	sleep 2
	echo "There is no supportable bitrate in this interval"
fi
ip link set can0 down
ip link set can1 down
sleep 2
#This is the second part of the test, it tests the first bitrate to provide frames transmission

ip link set can0 down
ip link set can1 down
found_bitrate_for_transmisson=0
for b in `seq 10790 10800`;do
    ip link set can0 type can bitrate $b
    ip link set can1 type can bitrate $b
    ip link set can0 up
    ip link set can1 up
    sleep 3
    file_can=$(mktemp)
	cangen can0 &
	candump can1 > $file_can &
	sleep 4
    if [ -s $file_can ];then
		found_bitrate_for_transmisson=1
		lava-test-case Receive_can1 --result pass --measurement $b --units bit/s
        sleep 2
		echo "$b is the first supportable bitrate to provide transmission"
		break
	fi
	ip link set can0 down
	ip link set can1 down
	rm $file_can
done

if [ $found_bitrate_for_transmisson -eq 0 ];then
	lava-test-case Receive_can1 --result fail --measurement $b --units bit/s
	sleep 2
	echo "There is no bitrate in this interval to provide frames transmission"
fi


#This is the third part of the test, it tests the last bitrate to provide frames transmission

ip link set can0 down
ip link set can1 down
bitrate_no_transmission=0
for b in `seq 1909088 1909092`;do
    ip link set can0 type can bitrate $b
    ip link set can1 type can bitrate $b
    ip link set can0 up
    ip link set can1 up
    sleep 2
    file_can=$(mktemp)
    cangen can0 &
    candump can1 > $file_can &
    sleep 3
	size=$(stat -c %s $file_can)
	if [ $size -eq 0 ];then
		bitrate_no_transmission=1
		lava-test-case Receive_can1 --result pass --measurement $(($b-1)) --units bit/s
		lava-test-case Receive_can1 --result fail --measurement $b --units bit/s
		sleep 2
		echo "This bitrate $b doesn't provide frames transmission"
		echo "The last bitrate to provide frames transmission is $(($b-1))"
		break
	fi
	ip link set can0 down
	ip link set can1 down
    rm $file_can
done

if [ $bitrate_no_transmission -eq 0 ];then
	lava-test-case Receive_can1 --result pass --measurement $b --units bit/s
	echo "All bitrates in this interval provide frames transmission"
	ip link set can0 down
	ip link set can1 down
fi

#This is the last part of the test, it tests the last bitrate that belongs to the domain
sleep 3
ip link set can0 down
ip link set can1 down
out_of_domain=0
for b in `seq 5290999 5291000`;do
	ip link set can0 type can bitrate $b
	x=$?
	sleep 2
	if [ $x -ne 0 ];then
		out_of_domain=1
		lava-test-case can0_bitrate --result fail --measurement $b --units bit/s
		echo "$b is the first bitrate to be out of the domain"
		echo "The last bitrate to belong to the domain is $(($b-1))"
		break
	fi
done

if [ $out_of_domain -eq 0 ];then
	lava-test-case can0_bitrate --result pass --measurement $b --units bit/s
	echo "All bitrates in this interval belong to the domain"
	canconfig can0 stop
	canconfig can1 stop
fi