• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2################################################################################
3## Copyright (c) Oliver Hartkopp <oliver.hartkopp@volkswagen.de>, 2011        ##
4## Copyright (c) International Business Machines  Corp., 2009                 ##
5##                                                                            ##
6## This program is free software;  you can redistribute it and#or modify      ##
7## it under the terms of the GNU General Public License as published by       ##
8## the Free Software Foundation; either version 2 of the License, or          ##
9## (at your option) any later version.                                        ##
10##                                                                            ##
11## This program is distributed in the hope that it will be useful, but        ##
12## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
13## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
14## for more details.                                                          ##
15##                                                                            ##
16## You should have received a copy of the GNU General Public License          ##
17## along with this program;  if not, write to the Free Software Foundation,   ##
18## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA           ##
19##                                                                            ##
20################################################################################
21
22TCID="$1"
23TST_TOTAL=1
24export TST_COUNT
25
26. test.sh
27
28setup()
29{
30	tst_require_root
31
32	# load needed CAN networklayer modules
33	modprobe can
34	ret=$?
35	if [ $ret -ne 0 ]; then
36		tst_brkm TCONF "modprobe can failed: ret - $ret"
37	fi
38
39	modprobe can_raw
40	ret=$?
41	if [ $ret -ne 0 ]; then
42		tst_brkm TCONF "modprobe can_raw failed: ret - $ret"
43	fi
44
45	# ensure the vcan driver to perform the ECHO on driver level
46	modprobe -r vcan
47	ret=$?
48	if [ $ret -ne 0 ]; then
49		tst_brkm TCONF "modprobe -r vcan failed: ret - $ret"
50	fi
51
52	modprobe vcan echo=1
53	ret=$?
54	if [ $ret -ne 0 ]; then
55		tst_brkm TCONF "modprobe vcan echo=1 failed: ret - $ret"
56	fi
57
58	VCAN=vcan0
59
60	# create virtual CAN device
61	ip link add dev $VCAN type vcan
62	ret=$?
63	if [ $ret -ne 0 ]; then
64		tst_brkm TBROK \
65			 "ip link add dev $VCAN type vcan failed: ret - $ret"
66	fi
67
68	ip link set dev $VCAN up
69	ret=$?
70	if [ $ret -ne 0 ]; then
71		tst_brkm TBROK "ip link set dev $VCAN up failed: ret - $ret"
72	fi
73
74	# check precondition for CAN frame flow test
75	HAS_ECHO=`ip link show $VCAN | grep -c ECHO`
76	if [ $HAS_ECHO -ne 1 ]; then
77		tst_brkm TBROK "ECHO is not 1"
78	fi
79}
80
81cleanup()
82{
83	ip link set dev $VCAN down
84	ip link del dev $VCAN
85	modprobe -r vcan
86	modprobe -r can_raw
87	modprobe -r can
88}
89
90if [ $# -ne 1 ]; then
91	tst_brkm TBROK "Usage: $0 [can_filter | can_rcv_own_msgs]"
92fi
93
94setup
95TST_CLEANUP=cleanup
96
97"$1" "$VCAN"
98ret=$?
99case "$ret" in
1000)	tst_resm TPASS "Test $1 PASS";;
1011)	tst_resm TFAIL "Test $1 FAIL";;
10232)	tst_resm TCONF "$1 is not appropriate for configuration flag";;
103*)	tst_resm TBROK "Invalid resm type $ret";;
104esac
105
106tst_exit
107