* Add can/Makefile

* can/filter-tests/Makefile cleanup:
  - Intall the files into the expect points.

* run_ltp-can_tests.sh cleanup:
  - Use TCID, TST_TOTAL and TST_COUNT.
  - Use test.sh that some functions required.
  - Use tst_require_root and tst_resm.
  - Add setup and cleanup function.

* tst-filter.c and tst-rcv-own-msgs.c:
  - Use "tst_res_flags.h" to correctly return the value.
  - Some cleanup.

Signed-off-by: Zeng Linggang <[email protected]>
---
 testcases/network/can/Makefile                     |  27 ++++++
 testcases/network/can/filter-tests/Makefile        |  36 +++----
 .../network/can/filter-tests/run_ltp-can_tests.sh  | 103 +++++++++++++++------
 testcases/network/can/filter-tests/tst-filter.c    |  55 +++++------
 .../network/can/filter-tests/tst-rcv-own-msgs.c    |  51 +++++-----
 5 files changed, 173 insertions(+), 99 deletions(-)
 create mode 100644 testcases/network/can/Makefile

diff --git a/testcases/network/can/Makefile b/testcases/network/can/Makefile
new file mode 100644
index 0000000..3174453
--- /dev/null
+++ b/testcases/network/can/Makefile
@@ -0,0 +1,27 @@
+#
+#    network/can test suite Makefile.
+#
+#    Copyright (c) 2014 Fujitsu Ltd.
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License along
+#    with this program; if not, write to the Free Software Foundation, Inc.,
+#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+
+top_srcdir             ?= ../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_TARGETS                := *.sh
+
+include $(top_srcdir)/include/mk/generic_trunk_target.mk
diff --git a/testcases/network/can/filter-tests/Makefile 
b/testcases/network/can/filter-tests/Makefile
index c88f704..6a94741 100644
--- a/testcases/network/can/filter-tests/Makefile
+++ b/testcases/network/can/filter-tests/Makefile
@@ -1,24 +1,28 @@
 #
-#  $Id: Makefile,v 1.1 2009/03/02 15:33:55 subrata_modak Exp $
+#    Copyright (c) 2014 Fujitsu Ltd.
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License along
+#    with this program; if not, write to the Free Software Foundation, Inc.,
+#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 #
 #  Send feedback to <[email protected]>
 
-CFLAGS    = -O2 -Wall -Wno-parentheses \
-       -fno-strict-aliasing \
-       -DETH_P_CAN=0x000C \
-       -DPF_CAN=29 \
-       -DAF_CAN=PF_CAN
-
-PROGRAMS =      tst-filter tst-rcv-own-msgs
-
-all: $(PROGRAMS)
+top_srcdir             ?= ../../../..
 
-install:
-       cp -f $(PROGRAMS) /usr/local/bin
+include $(top_srcdir)/include/mk/testcases.mk
 
-clean:
-       rm -f $(PROGRAMS)
+CPPFLAGS               += -DETH_P_CAN=0x000C -DPF_CAN=29 -DAF_CAN=PF_CAN
 
-distclean:
-       rm -f $(PROGRAMS) *~
+INSTALL_TARGETS                := *.sh
 
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/can/filter-tests/run_ltp-can_tests.sh 
b/testcases/network/can/filter-tests/run_ltp-can_tests.sh
index b955ec6..c5aec09 100644
--- a/testcases/network/can/filter-tests/run_ltp-can_tests.sh
+++ b/testcases/network/can/filter-tests/run_ltp-can_tests.sh
@@ -14,44 +14,93 @@
 ## for more details.                                                          
##
 ##                                                                            
##
 ## You should have received a copy of the GNU General Public License          
##
-## along with this program;  if not, write to the Free Software               
##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
USA    ##
+## along with this program;  if not, write to the Free Software Foundation,   
##
+## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA           
##
 ##                                                                            
##
 
################################################################################
 
-if [ $(id -ru) -ne 0 ]; then
-     echo You need to be root to execute these tests
-     exit 1
-fi
+TCID="$1"
+TST_TOTAL=1
+export TST_COUNT
 
-# load needed CAN networklayer modules
-modprobe -f can
-modprobe -f can_raw
+. test.sh
 
-# ensure the vcan driver to perform the ECHO on driver level
-modprobe -r vcan
-modprobe -f vcan echo=1
+setup()
+{
+       tst_require_root
 
-VCAN=vcan0
+       # load needed CAN networklayer modules
+       modprobe can
+       ret=$?
+       if [ $ret -ne 0 ]; then
+               tst_brkm TCONF "modprobe can failed: ret - $ret"
+       fi
 
-# create virtual CAN device
-ip link add dev $VCAN type vcan || exit 1
-ifconfig $VCAN up
+       modprobe can_raw
+       ret=$?
+       if [ $ret -ne 0 ]; then
+               tst_brkm TCONF "modprobe can_raw failed: ret - $ret"
+       fi
 
-# check precondition for CAN frame flow test
-HAS_ECHO=`ip link show $VCAN | grep -c ECHO`
+       # ensure the vcan driver to perform the ECHO on driver level
+       modprobe -r vcan
+       ret=$?
+       if [ $ret -ne 0 ]; then
+               tst_brkm TCONF "modprobe -r vcan failed: ret - $ret"
+       fi
 
-if [ $HAS_ECHO -ne 1 ]
-then
-    exit 1
-fi
+       modprobe vcan echo=1
+       ret=$?
+       if [ $ret -ne 0 ]; then
+               tst_brkm TCONF "modprobe vcan echo=1 failed: ret - $ret"
+       fi
+
+       VCAN=vcan0
+
+       # create virtual CAN device
+       ip link add dev $VCAN type vcan
+       ret=$?
+       if [ $ret -ne 0 ]; then
+               tst_brkm TBROK
+                        "ip link add dev $VCAN type vcan failed: ret - $ret"
+       fi
 
-# test of CAN filters on af_can.c
-./tst-filter $VCAN || exit 1
+       ip link set dev $VCAN up
+       ret=$?
+       if [ $ret -ne 0 ]; then
+               tst_brkm TBROK "ip link set dev $VCAN up failed: ret - $ret"
+       fi
 
-# test of CAN frame flow down to the netdevice and up again
-./tst-rcv-own-msgs $VCAN || exit 1
+       # check precondition for CAN frame flow test
+       HAS_ECHO=`ip link show $VCAN | grep -c ECHO`
+       if [ $HAS_ECHO -ne 1 ]; then
+               tst_brkm TBROK "ECHO is not 1"
+       fi
+}
+
+cleanup()
+{
+       ip link set dev $VCAN down
+       ip link del dev $VCAN
+       modprobe -r vcan
+       modprobe -r can_raw
+       modprobe -r can
+}
+
+if [ $# -ne 1 ]; then
+       tst_brkm TBROK "Usage: $0 [can_filter | can_rcv_own_msgs]"
+fi
 
-exit 0
+setup
+TST_CLEANUP=cleanup
 
+"$1" "$VCAN"
+ret=$?
+case "$ret" in
+0)     tst_resm TPASS "Test $1 PASS";;
+1)     tst_resm TFAIL "Test $1 FAIL";;
+32)    tst_resm TCONF "$1 is not appropriate for configuration flag";;
+*)     tst_resm TBROK "Invalid resm type $ret";;
+esac
 
+tst_exit
diff --git a/testcases/network/can/filter-tests/tst-filter.c 
b/testcases/network/can/filter-tests/tst-filter.c
index e5fddc7..db01745 100644
--- a/testcases/network/can/filter-tests/tst-filter.c
+++ b/testcases/network/can/filter-tests/tst-filter.c
@@ -1,8 +1,4 @@
 /*
- *  $Id: tst-filter.c 1263 2011-07-09 18:00:41Z hartkopp $
- */
-
-/*
  * tst-filter.c
  *
  * Copyright (c) 2011 Volkswagen Group Electronic Research
@@ -56,6 +52,7 @@
 #include <sys/time.h>
 #include <net/if.h>
 #include "config.h"
+#include "tst_res_flags.h"
 
 #ifdef HAVE_LINUX_CAN_H
 
@@ -66,9 +63,8 @@
 #define TC 18                  /* # of testcases */
 
 const int rx_res[TC] = { 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1 
};
-const int rxbits_res[TC] =
-    { 4369, 4369, 4369, 4369, 17, 4352, 17, 4352, 257, 257, 4112, 4112, 1, 256,
-16, 4096, 1, 256 };
+const int rxbits_res[TC] = { 4369, 4369, 4369, 4369, 17, 4352, 17, 4352, 257,
+                            257, 4112, 4112, 1, 256, 16, 4096, 1, 256 };
 
 canid_t calc_id(int testcase)
 {
@@ -87,7 +83,7 @@ canid_t calc_mask(int testcase)
        canid_t mask = CAN_SFF_MASK;
 
        if (testcase > 15)
-               return (CAN_EFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG);
+               return CAN_EFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG;
 
        if (testcase & 4)
                mask |= CAN_EFF_FLAG;
@@ -116,18 +112,19 @@ int main(int argc, char **argv)
        /* check command line options */
        if (argc != 2) {
                fprintf(stderr, "Usage: %s <device>\n", argv[0]);
-               return 1;
+               return TFAIL;
        }
 
-       if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
+       s = socket(PF_CAN, SOCK_RAW, CAN_RAW);
+       if (s < 0) {
                perror("socket");
-               return 1;
+               return TFAIL;
        }
 
        strcpy(ifr.ifr_name, argv[1]);
        if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
                perror("SIOCGIFINDEX");
-               return 1;
+               return TFAIL;
        }
        addr.can_family = AF_CAN;
        addr.can_ifindex = ifr.ifr_ifindex;
@@ -137,7 +134,7 @@ int main(int argc, char **argv)
 
        if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
                perror("bind");
-               return 1;
+               return TFAIL;
        }
 
        printf("---\n");
@@ -149,9 +146,8 @@ int main(int argc, char **argv)
                setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER,
                           &rfilter, sizeof(rfilter));
 
-               printf
-                   ("testcase %2d filters : can_id = 0x%08X can_mask = 
0x%08X\n",
-                    testcase, rfilter.can_id, rfilter.can_mask);
+               printf("testcase %2d filters : can_id = 0x%08X can_mask = "
+                      "0x%08X\n", testcase, rfilter.can_id, rfilter.can_mask);
 
                printf("testcase %2d sending patterns ... ", testcase);
 
@@ -218,11 +214,9 @@ int main(int argc, char **argv)
                                }
 
                                /* test & calc rxbits */
-                               rxbitval =
-                                   1 <<
-                                   ((frame.
-                                     can_id & (CAN_EFF_FLAG | CAN_RTR_FLAG |
-                                               CAN_ERR_FLAG)) >> 28);
+                               rxbitval = 1 << ((frame.can_id &
+                                                (CAN_EFF_FLAG | CAN_RTR_FLAG |
+                                                 CAN_ERR_FLAG)) >> 28);
 
                                /* only receive a rxbitval once */
                                if ((rxbits & rxbitval) == rxbitval) {
@@ -234,22 +228,23 @@ int main(int argc, char **argv)
                                rxbits |= rxbitval;
                                rx++;
 
-                               printf
-                                   ("testcase %2d rx : can_id = 0x%08X rx = %d 
rxbits = %d\n",
-                                    testcase, frame.can_id, rx, rxbits);
+                               printf("testcase %2d rx : can_id = 0x%08X rx = "
+                                      "%d rxbits = %d\n", testcase,
+                                      frame.can_id, rx, rxbits);
                        }
                }
                /* rx timed out -> check the received results */
                if (rx_res[testcase] != rx) {
                        fprintf(stderr,
-                               "wrong rx value in testcase %d : %d (expected 
%d)\n",
-                               testcase, rx, rx_res[testcase]);
+                               "wrong rx value in testcase %d : %d (expected "
+                               "%d)\n", testcase, rx, rx_res[testcase]);
                        exit(1);
                }
                if (rxbits_res[testcase] != rxbits) {
                        fprintf(stderr,
-                               "wrong rxbits value in testcase %d : %d 
(expected %d)\n",
-                               testcase, rxbits, rxbits_res[testcase]);
+                               "wrong rxbits value in testcase %d : %d "
+                               "(expected %d)\n", testcase, rxbits,
+                               rxbits_res[testcase]);
                        exit(1);
                }
                printf("testcase %2d ok\n---\n", testcase);
@@ -257,7 +252,7 @@ int main(int argc, char **argv)
 
        close(s);
 
-       return 0;
+       return TPASS;
 }
 
 #else
@@ -265,7 +260,7 @@ int main(int argc, char **argv)
 int main(void)
 {
        printf("The linux/can.h was missing upon compilation.\n");
-       return 32;
+       return TCONF;
 }
 
 #endif /* HAVE_LINUX_CAN_H */
diff --git a/testcases/network/can/filter-tests/tst-rcv-own-msgs.c 
b/testcases/network/can/filter-tests/tst-rcv-own-msgs.c
index 5730fd3..2f9cbf2 100644
--- a/testcases/network/can/filter-tests/tst-rcv-own-msgs.c
+++ b/testcases/network/can/filter-tests/tst-rcv-own-msgs.c
@@ -1,8 +1,4 @@
 /*
- *  $Id: tst-rcv-own-msgs.c 1193 2010-08-09 14:00:21Z hartkopp $
- */
-
-/*
  * tst-rcv-own-msgs.c
  *
  * Copyright (c) 2010 Volkswagen Group Electronic Research
@@ -56,13 +52,14 @@
 #include <sys/time.h>
 #include <net/if.h>
 #include "config.h"
+#include "tst_res_flags.h"
 
 #ifdef HAVE_LINUX_CAN_H
 
 #include <linux/can.h>
 #include <linux/can/raw.h>
 
-#define max(a,b) (a > b ? a : b)
+#define max(a, b) ((a) > (b) ? (a) : (b))
 
 struct rxs {
        int s;
@@ -141,13 +138,13 @@ struct rxs test_sockets(int s, int t, canid_t can_id)
 
 void setopts(int s, int loopback, int recv_own_msgs)
 {
-       setsockopt(s, SOL_CAN_RAW, CAN_RAW_LOOPBACK,
-                  &loopback, sizeof(loopback));
-       setsockopt(s, SOL_CAN_RAW, CAN_RAW_RECV_OWN_MSGS,
-                  &recv_own_msgs, sizeof(recv_own_msgs));
+       setsockopt(s, SOL_CAN_RAW, CAN_RAW_LOOPBACK, &loopback,
+                  sizeof(loopback));
+       setsockopt(s, SOL_CAN_RAW, CAN_RAW_RECV_OWN_MSGS, &recv_own_msgs,
+                  sizeof(recv_own_msgs));
 
-       printf("check loopback %d recv_own_msgs %d ... ",
-              loopback, recv_own_msgs);
+       printf("check loopback %d recv_own_msgs %d ... ", loopback,
+              recv_own_msgs);
 }
 
 int main(int argc, char **argv)
@@ -160,33 +157,35 @@ int main(int argc, char **argv)
        /* check command line options */
        if (argc != 2) {
                fprintf(stderr, "Usage: %s <device>\n", argv[0]);
-               return 1;
+               return TFAIL;
        }
 
-       if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
+       s = socket(PF_CAN, SOCK_RAW, CAN_RAW);
+       if (s < 0) {
                perror("socket");
-               return 1;
+               return TFAIL;
        }
-       if ((t = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
+       t = socket(PF_CAN, SOCK_RAW, CAN_RAW);
+       if (t < 0) {
                perror("socket");
-               return 1;
+               return TFAIL;
        }
 
        strcpy(ifr.ifr_name, argv[1]);
        if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
                perror("SIOCGIFINDEX");
-               return 1;
+               return TFAIL;
        }
        addr.can_ifindex = ifr.ifr_ifindex;
        addr.can_family = AF_CAN;
 
        if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
                perror("bind");
-               return 1;
+               return TFAIL;
        }
        if (bind(t, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
                perror("bind");
-               return 1;
+               return TFAIL;
        }
 
        printf("Starting PF_CAN frame flow test.\n");
@@ -196,7 +195,7 @@ int main(int argc, char **argv)
                printf("ok.\n");
        else {
                printf("failure!\n");
-               return 1;
+               return TFAIL;
        }
 
        /* check loopback 0 recv_own_msgs 0 */
@@ -206,7 +205,7 @@ int main(int argc, char **argv)
                printf("ok.\n");
        else {
                printf("failure!\n");
-               return 1;
+               return TFAIL;
        }
 
        /* check loopback 0 recv_own_msgs 1 */
@@ -216,7 +215,7 @@ int main(int argc, char **argv)
                printf("ok.\n");
        else {
                printf("failure!\n");
-               return 1;
+               return TFAIL;
        }
 
        /* check loopback 1 recv_own_msgs 0 */
@@ -226,7 +225,7 @@ int main(int argc, char **argv)
                printf("ok.\n");
        else {
                printf("failure!\n");
-               return 1;
+               return TFAIL;
        }
 
        /* check loopback 1 recv_own_msgs 1 */
@@ -236,7 +235,7 @@ int main(int argc, char **argv)
                printf("ok.\n");
        else {
                printf("failure!\n");
-               return 1;
+               return TFAIL;
        }
 
        printf("PF_CAN frame flow test was successful.\n");
@@ -244,7 +243,7 @@ int main(int argc, char **argv)
        close(s);
        close(t);
 
-       return 0;
+       return TPASS;
 }
 
 #else
@@ -252,7 +251,7 @@ int main(int argc, char **argv)
 int main(void)
 {
        printf("The linux/can.h was missing upon compilation.\n");
-       return 32;
+       return TCONF;
 }
 
 #endif /* HAVE_LINUX_CAN_H */
-- 
1.9.3




------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to