can_run_tests.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. TCID="$1"
  22. TST_TOTAL=1
  23. export TST_COUNT
  24. . test.sh
  25. setup()
  26. {
  27. tst_require_root
  28. # load needed CAN networklayer modules
  29. modprobe can
  30. ret=$?
  31. if [ $ret -ne 0 ]; then
  32. tst_brkm TCONF "modprobe can failed: ret - $ret"
  33. fi
  34. modprobe can_raw
  35. ret=$?
  36. if [ $ret -ne 0 ]; then
  37. tst_brkm TCONF "modprobe can_raw failed: ret - $ret"
  38. fi
  39. # ensure the vcan driver to perform the ECHO on driver level
  40. modprobe -r vcan
  41. ret=$?
  42. if [ $ret -ne 0 ]; then
  43. tst_brkm TCONF "modprobe -r vcan failed: ret - $ret"
  44. fi
  45. modprobe vcan echo=1
  46. ret=$?
  47. if [ $ret -ne 0 ]; then
  48. tst_brkm TCONF "modprobe vcan echo=1 failed: ret - $ret"
  49. fi
  50. VCAN=vcan0
  51. # create virtual CAN device
  52. ip link add dev $VCAN type vcan
  53. ret=$?
  54. if [ $ret -ne 0 ]; then
  55. tst_brkm TBROK \
  56. "ip link add dev $VCAN type vcan failed: ret - $ret"
  57. fi
  58. ip link set dev $VCAN up
  59. ret=$?
  60. if [ $ret -ne 0 ]; then
  61. tst_brkm TBROK "ip link set dev $VCAN up failed: ret - $ret"
  62. fi
  63. # check precondition for CAN frame flow test
  64. HAS_ECHO=`ip link show $VCAN | grep -c ECHO`
  65. if [ $HAS_ECHO -ne 1 ]; then
  66. tst_brkm TBROK "ECHO is not 1"
  67. fi
  68. }
  69. cleanup()
  70. {
  71. ip link set dev $VCAN down
  72. ip link del dev $VCAN
  73. modprobe -r vcan
  74. modprobe -r can_raw
  75. modprobe -r can
  76. }
  77. if [ $# -ne 1 ]; then
  78. tst_brkm TBROK "Usage: $0 [can_filter | can_rcv_own_msgs]"
  79. fi
  80. setup
  81. TST_CLEANUP=cleanup
  82. "$1" "$VCAN"
  83. ret=$?
  84. case "$ret" in
  85. 0) tst_resm TPASS "Test $1 PASS";;
  86. 1) tst_resm TFAIL "Test $1 FAIL";;
  87. 32) tst_resm TCONF "$1 is not appropriate for configuration flag";;
  88. *) tst_resm TBROK "Invalid resm type $ret";;
  89. esac
  90. tst_exit