* Rename 'opts.c' to 'mc_verify_opts.c' and some cleanup. * Rename 'opts_e.c' to 'mc_verify_opts_error.c' and some cleanup. * Delete 'trace_logic' that is used to debug. * Use 'test.sh' script and use 'tst_*' instead of 'end_testcase'. * Delete some unuseful comments. * Fix old-style function definition.
Signed-off-by: Zeng Linggang <zenglg...@cn.fujitsu.com> --- testcases/network/multicast/mc_opts/mc_opts | 166 +++++---------------- .../network/multicast/mc_opts/mc_verify_opts.c | 149 ++++++++++++++++++ .../multicast/mc_opts/mc_verify_opts_error.c | 76 ++++++++++ testcases/network/multicast/mc_opts/opts.c | 150 ------------------- testcases/network/multicast/mc_opts/opts_e.c | 81 ---------- 5 files changed, 262 insertions(+), 360 deletions(-) create mode 100644 testcases/network/multicast/mc_opts/mc_verify_opts.c create mode 100644 testcases/network/multicast/mc_opts/mc_verify_opts_error.c delete mode 100644 testcases/network/multicast/mc_opts/opts.c delete mode 100644 testcases/network/multicast/mc_opts/opts_e.c diff --git a/testcases/network/multicast/mc_opts/mc_opts b/testcases/network/multicast/mc_opts/mc_opts index f40112c..7d50a76 100755 --- a/testcases/network/multicast/mc_opts/mc_opts +++ b/testcases/network/multicast/mc_opts/mc_opts @@ -35,142 +35,50 @@ unset LIBPATH # -Ported # #****************************************************************************** -#Uncomment the line below for debug output. -#trace_logic=${trace_logic:-"set -x"} -$trace_logic -if [ -z $LTPBIN ]; then - PATH=../../../bin/:./:$PATH -fi TC=mc_opts -TCtmp=${TCtmp:-$LTPROOT/bin/$TC$$} -CLEANUP=${CLEANUP:-ON} -EXECUTABLES=${EXECUTABLES:-"opts opts_e"} -NUMLOOPS=${NUMLOOPS:-10} +EXECUTABLES=${EXECUTABLES:-"mc_verify_opts mc_verify_opts_error"} IPADDR=${IPADDR:-$(mc_gethost `hostname`| grep address |awk '{ print $2 }')} export TCID=$TC export TST_TOTAL=1 export TST_COUNT=1 -this_file=${0##*/} -trap "interrupt_test" 2 - -setup() -{ - mkdir -p $TCtmp - for i in $EXECUTABLES - do - install -m 0755 "$LTPROOT/testcases/bin/$i" "$TCtmp/." - done -} - -#----------------------------------------------------------------------- -# -# FUNCTION: do_test -# PURPOSE: Executes the testcases. -# INPUT: Number of iterations -# OUTPUT: Error messages are logged when any verification test -# fails. -# -#----------------------------------------------------------------------- - -do_test() -{ - $trace_logic - echo "$this_file: doing $0." - - COUNT=1 - while [ $COUNT -le $NUMLOOPS ] - do - # Run setsockopt/getsockopt test - echo "Running mc_$EXECUTABLES on $IPADDR" - for i in $EXECUTABLES - do - $TCtmp/$i $IPADDR - [ $? = 0 ] || end_testcase "$i $IPADDR failed" - done - - echo "Running ping with bad values" - ping -T 777 224.0.0.1 > /dev/null 2>&1 - [ $? = 0 ] && end_testcase "Multicast range should be out of range" - - echo "Running ping on a invalid interface!" - ping -I 3.3.3.3 224.0.0.1 > /dev/null 2>&1 - [ $? = 0 ] && end_testcase "ping on bogus interface should fail" - - COUNT=$(( $COUNT + 1 )) - done -} - -#----------------------------------------------------------------------- -# -# FUNCTION: do_cleanup -# PURPOSE: Called when the testcase is interrupted by the user -# or by interrupt_testcase() when time limit expired -# INPUT: None. -# OUTPUT: None. -# -#----------------------------------------------------------------------- - -do_cleanup() -{ - $trace_logic - echo "$this_file: doing $0." - - cd / - if [ "x$TCtmp" != "x$TCsrc" ]; then - rm -rf $TCtmp - fi -} - -#============================================================================= -# FUNCTION NAME: end_testcase -# -# FUNCTION DESCRIPTION: Clean up -# -# PARAMETERS: string, IF AND ONLY IF the testcase fails -# -# RETURNS: None. -#============================================================================= - -end_testcase() -{ - $trace_logic - echo "$this_file: doing $0." - - # Call other cleanup functions - [ $CLEANUP = "ON" ] && do_cleanup - - [ $# = 0 ] && { tst_resm TPASS "Test Successful"; exit 0; } - tst_resm TFAIL "Test Failed: $@" - exit 1 -} - -#****************************************************************************** -# -# FUNCTION: interrupt_test -# PURPOSE: Handle process interrupts set by trap. -# INPUT: none -# OUTPUT: none -# -#****************************************************************************** +. test.sh -interrupt_test() -{ - echo "test interrupted" - end_testcase -} +if [ -z $IPADDR ]; then + tst_brkm TCONF "Not found $(hostname) in /etc/hosts" +fi -#****************************************************************************** -# -# FUNCTION: MAIN -# PURPOSE: To invoke functions that perform the tasks as described in -# the design in the prolog above. -# INPUT: See SETUP in the prolog above. -# OUTPUT: Logged run results written to testcase run log -# -#****************************************************************************** -setup -do_test -end_testcase +tst_resm TINFO "doing test." + +COUNT=1 +while [ $COUNT -le 10 ] +do + # Run setsockopt/getsockopt test + tst_resm TINFO "Running $EXECUTABLES on $IPADDR" + for i in $EXECUTABLES + do + $i $IPADDR > /dev/null 2>&1 + if [ $? -ne 0 ]; then + tst_brkm TFAIL "$i $IPADDR failed" + fi + done + + tst_resm TINFO "Running ping with bad values" + ping -T 777 224.0.0.1 > /dev/null 2>&1 + if [ $? -eq 0 ]; then + tst_brkm TFAIL "Multicast range should be out of range" + fi + + tst_resm TINFO "Running ping on a invalid interface!" + ping -I 3.3.3.3 224.0.0.1 > /dev/null 2>&1 + if [ $? -eq 0 ]; then + tst_brkm TFAIL "ping on bogus interface should fail" + fi + + COUNT=$(( $COUNT + 1 )) +done + +tst_resm TPASS "Test Successful" +tst_exit diff --git a/testcases/network/multicast/mc_opts/mc_verify_opts.c b/testcases/network/multicast/mc_opts/mc_verify_opts.c new file mode 100644 index 0000000..679b817 --- /dev/null +++ b/testcases/network/multicast/mc_opts/mc_verify_opts.c @@ -0,0 +1,149 @@ +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <errno.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> +#include <stdio.h> +#include <netdb.h> + +#define MAXBUFSIZ 8096 + +static int errors; + +int main(int argc, char *argv[]) +{ + int s; + struct in_addr gimr; + struct ip_mreq simr; + + unsigned i1, i2, i3, i4; + struct hostent *hp, *gethostbyname(); + + char sintf[20], gintf[20]; + unsigned char ttl; + char loop = 0; + unsigned int len = 0; + + if (argc != 2) { + fprintf(stderr, + "usage: %s interface_name (or i.i.i.i)\n", argv[0]); + exit(1); + } + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s == -1) { + perror("Error: can't open socket"); + exit(1); + } + + printf("agrv sub 1 is %s\n", argv[1]); + hp = gethostbyname(argv[1]); + if (hp) + memcpy(&simr.imr_interface.s_addr, hp->h_addr, hp->h_length); + else if (sscanf(argv[1], "%u.%u.%u.%u", &i1, &i2, &i3, &i4) != 4) { + fprintf(stderr, "Bad interface address\n"); + exit(1); + } else + simr.imr_interface.s_addr = + htonl((i1 << 24) | (i2 << 16) | (i3 << 8) | i4); + strcpy(sintf, inet_ntoa(simr.imr_interface)); + + /* verify socket options */ + if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, + &simr.imr_interface.s_addr, + sizeof(simr.imr_interface.s_addr)) != 0) { + perror("Error: Setting IP_MULTICAST_IF"); + errors++; + } else + printf("Set interface: %s for multicasting\n", sintf); + + len = sizeof(gimr); + if (getsockopt + (s, IPPROTO_IP, IP_MULTICAST_IF, &gimr, (socklen_t *)&len) != 0) { + perror("Getting IP_MULTICAST_IF"); + errors++; + } else { + strcpy(gintf, inet_ntoa(gimr)); + printf("Got multicasting socket interface: %s\n", gintf); + } + + /* Verify that the multicastion for the interface was set */ + if (strcmp(sintf, gintf) != 0) { + printf("Error: IP_MULTICAST_IF was not set\n"); + errors++; + } else + printf + ("Socket has been set for multicasting on interface: %s\n", + sintf); + + len = sizeof(ttl); + if (getsockopt + (s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, (socklen_t *)&len) != 0) { + perror("Error: Gettting IP_MULTICAST_TTL"); + errors++; + } else + printf("getsockopt: got ttl = %i\n", ttl); + if (ttl != 1) + printf("Error: IP_MULTICAST_TTL not default value, ttl = %i\n", + ttl); + ttl = 10; /* Set ttl to 10 */ + len = sizeof(ttl); + if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, + &ttl, sizeof(ttl)) != 0) { + perror("Error: Setting IP_MULTICAST_TTL"); + errors++; + } else + printf("TTL set on multicast socket\n"); + if (getsockopt + (s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, (socklen_t *)&len) != 0) { + perror("Error: Getting IP_MULTICAST_TTL"); + errors++; + } + if (ttl != 10) { + printf("Error: IP_MULTICAST_TTL not set, ttl = %i\n", ttl); + errors++; + } + + len = sizeof(loop); + if (getsockopt + (s, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, + (socklen_t *)&len) != 0) { + perror("Error: Getting IP_MULTICAST_LOOP"); + errors++; + } else + printf("Got loopback setting\n"); + if (loop != 1) { + printf("Error: IP_MULTICAST_LOOP not enabled, loop = %i\n", + loop); + errors++; + } else + printf("IP_MULTICAST_LOOP is enabled\n"); + + loop = 0; /* Disable IP_MULTICAST_LOOP */ + if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(char)) != + 0) { + errors++; + perror("Error: Setting IP_MULTICAST_LOOP"); + } else + printf("Multicast loopback disabled\n"); + if (getsockopt + (s, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, + (socklen_t *)&len) != 0) { + perror("Error: Getting IP_MULTICAST_LOOP"); + errors++; + } else + printf("Got multicast loopback value\n"); + if (loop != 0) { + printf("Error: IP_MULTICAST_LOOP not disabled, loop = %i\n", + loop); + errors++; + } else + printf("IP_MULTICAST_LOOP disabled\n"); + + close(s); + if (errors) + exit(1); + exit(0); +} diff --git a/testcases/network/multicast/mc_opts/mc_verify_opts_error.c b/testcases/network/multicast/mc_opts/mc_verify_opts_error.c new file mode 100644 index 0000000..9807e88 --- /dev/null +++ b/testcases/network/multicast/mc_opts/mc_verify_opts_error.c @@ -0,0 +1,76 @@ +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <errno.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> +#include <netdb.h> + +int main(int argc, char *argv[]) +{ + int s; + struct in_addr simr, gimr; + + unsigned i1, i2, i3, i4; + struct hostent *hp, *gethostbyname(); + + unsigned char ttl; + char no_loop = 0, do_loop = 1; + unsigned long len = 0; + + if (argc != 2) { + fprintf(stderr, + "usage: %s interface_name (or i.i.i.i)\n", argv[0]); + exit(1); + } + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s == -1) { + perror("can't open socket"); + exit(1); + } + + hp = gethostbyname(argv[1]); + if (hp) + memcpy(&simr.s_addr, hp->h_addr, hp->h_length); + else if (sscanf(argv[1], "%u.%u.%u.%u", &i1, &i2, &i3, &i4) != 4) { + fprintf(stderr, "Bad interface address\n"); + exit(1); + } else + simr.s_addr = htonl((i1 << 24) | (i2 << 16) | (i3 << 8) | i4); + + /* verify socket options error messages */ + if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, &simr, + sizeof(simr)) != 0) + perror("Setting IP_MULTICAST_IF"), exit(1); + len = sizeof(gimr); + if (getsockopt + (s, IPPROTO_IP, IP_MULTICAST_IF, &gimr, (socklen_t *)&len) != 0) + perror("Getting IP_MULTICAST_IF"), exit(1); + + len = sizeof(ttl); + if (getsockopt + (s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, (socklen_t *)&len) != 0) + perror("Getting IP_MULTICAST_TTL"), exit(1); + + ttl = 10; /* Set ttl to 10 */ +/* printf("setting ttl=10\n");*/ + if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) != 0) + perror("Setting IP_MULTICAST_TTL"), exit(1); + + if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, &do_loop, sizeof(char)) + != 0) + perror("Setting IP_MULTICAST_LOOP"), exit(1); + if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, &no_loop, sizeof(char)) + != 0) + perror("Setting IP_MULTICAST_LOOP"), exit(1); + len = sizeof(no_loop); + if (getsockopt + (s, IPPROTO_IP, IP_MULTICAST_LOOP, &no_loop, + (socklen_t *)&len) != 0) + perror("Getting IP_MULTICAST_LOOP"), exit(1); + + close(s); + exit(0); +} diff --git a/testcases/network/multicast/mc_opts/opts.c b/testcases/network/multicast/mc_opts/opts.c deleted file mode 100644 index 0174d91..0000000 --- a/testcases/network/multicast/mc_opts/opts.c +++ /dev/null @@ -1,150 +0,0 @@ -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <errno.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> -#include <stdio.h> -#include <netdb.h> - -#define MAXBUFSIZ 8096 - -char buff[MAXBUFSIZ]; -int errors = 0; - -int main(argc, argv) -int argc; -char *argv[]; -{ - int s; - struct in_addr gimr; - struct ip_mreq simr; - - unsigned i1, i2, i3, i4; - struct hostent *hp, *gethostbyname(); - - char sintf[20], gintf[20]; - int n = 0; - unsigned char ttl; - char loop = 0; - unsigned int len = 0; - - if (argc != 2) { - fprintf(stderr, - "usage: %s interface_name (or i.i.i.i)\n", argv[0]); - exit(1); - } - if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { - perror("Error: can't open socket"); - exit(1); - } - - printf("agrv sub 1 is %s\n", argv[1]); - if ((hp = gethostbyname(argv[1]))) - memcpy(&simr.imr_interface.s_addr, hp->h_addr, hp->h_length); - else if ((n = sscanf(argv[1], "%u.%u.%u.%u", &i1, &i2, &i3, &i4)) != 4) { - fprintf(stderr, "Bad interface address\n"); - exit(1); - } else - simr.imr_interface.s_addr = - htonl((i1 << 24) | (i2 << 16) | (i3 << 8) | i4); - strcpy(sintf, inet_ntoa(simr.imr_interface)); - - /* verify socket options */ - if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, - &simr.imr_interface.s_addr, - sizeof(simr.imr_interface.s_addr)) != 0) { - perror("Error: Setting IP_MULTICAST_IF"); - errors++; - } else - printf("Set interface: %s for multicasting\n", sintf); - - len = sizeof(gimr); - if (getsockopt - (s, IPPROTO_IP, IP_MULTICAST_IF, &gimr, (socklen_t *) & len) != 0) { - perror("Getting IP_MULTICAST_IF"); - errors++; - } else { - strcpy(gintf, inet_ntoa(gimr)); - printf("Got multicasting socket interface: %s\n", gintf); - } - - /* Verify that the multicastion for the interface was set */ - if (strcmp(sintf, gintf) != 0) { - printf("Error: IP_MULTICAST_IF was not set\n"); - errors++; - } else - printf - ("Socket has been set for multicasting on interface: %s\n", - sintf); - - len = sizeof(ttl); - if (getsockopt - (s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, (socklen_t *) & len) != 0) { - perror("Error: Gettting IP_MULTICAST_TTL"); - errors++; - } else - printf("getsockopt: got ttl = %i\n", ttl); - if (ttl != 1) - printf("Error: IP_MULTICAST_TTL not default value, ttl = %i\n", - ttl); - ttl = 10; /* Set ttl to 10 */ - len = sizeof(ttl); - if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) != 0) { - perror("Error: Setting IP_MULTICAST_TTL"); - errors++; - } else - printf("TTL set on multicast socket\n"); - if (getsockopt - (s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, (socklen_t *) & len) != 0) { - perror("Error: Getting IP_MULTICAST_TTL"); - errors++; - } - if (ttl != 10) { - printf("Error: IP_MULTICAST_TTL not set, ttl = %i\n", ttl); - errors++; - } - - len = sizeof(loop); - if (getsockopt - (s, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, - (socklen_t *) & len) != 0) { - perror("Error: Getting IP_MULTICAST_LOOP"); - errors++; - } else - printf("Got loopback setting\n"); - if (loop != 1) { - printf("Error: IP_MULTICAST_LOOP not enabled, loop = %i\n", - loop); - errors++; - } else - printf("IP_MULTICAST_LOOP is enabled\n"); - - loop = 0; /* Disable IP_MULTICAST_LOOP */ - if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(char)) != - 0) { - errors++; - perror("Error: Setting IP_MULTICAST_LOOP"); - } else - printf("Multicast loopback disabled\n"); - if (getsockopt - (s, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, - (socklen_t *) & len) != 0) { - perror("Error: Getting IP_MULTICAST_LOOP"); - errors++; - } else - printf("Got multicast loopback value\n"); - if (loop != 0) { - printf("Error: IP_MULTICAST_LOOP not disabled, loop = %i\n", - loop); - errors++; - } else - printf("IP_MULTICAST_LOOP disabled\n"); - - close(s); - if (errors) - exit(1); - exit(0); -} diff --git a/testcases/network/multicast/mc_opts/opts_e.c b/testcases/network/multicast/mc_opts/opts_e.c deleted file mode 100644 index f91fa93..0000000 --- a/testcases/network/multicast/mc_opts/opts_e.c +++ /dev/null @@ -1,81 +0,0 @@ -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <errno.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> -#include <netdb.h> - -#define MAXBUFSIZ 8096 - -char buff[MAXBUFSIZ]; - -int main(argc, argv) -int argc; -char *argv[]; -{ - int s; - struct in_addr simr, gimr; - - unsigned i1, i2, i3, i4; - struct hostent *hp, *gethostbyname(); - - unsigned char ttl; - char no_loop = 0, do_loop = 1; - unsigned long len = 0; - int n = 0; - - if (argc != 2) { - fprintf(stderr, - "usage: %s interface_name (or i.i.i.i)\n", argv[0]); - exit(1); - } - if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { - perror("can't open socket"); - exit(1); - } - - if ((hp = gethostbyname(argv[1]))) - memcpy(&simr.s_addr, hp->h_addr, hp->h_length); - else if ((n = sscanf(argv[1], "%u.%u.%u.%u", &i1, &i2, &i3, &i4)) != 4) { - fprintf(stderr, "Bad interface address\n"); - exit(1); - } else - simr.s_addr = htonl((i1 << 24) | (i2 << 16) | (i3 << 8) | i4); - - /* verify socket options error messages */ - if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, &simr, - sizeof(simr)) != 0) - perror("Setting IP_MULTICAST_IF"), exit(1); - len = sizeof(gimr); - if (getsockopt - (s, IPPROTO_IP, IP_MULTICAST_IF, &gimr, (socklen_t *) & len) != 0) - perror("Getting IP_MULTICAST_IF"), exit(1); - - len = sizeof(ttl); - if (getsockopt - (s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, (socklen_t *) & len) != 0) - perror("Getting IP_MULTICAST_TTL"), exit(1); - - ttl = 10; /* Set ttl to 10 */ -/* printf("setting ttl=10\n");*/ - if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) != 0) - perror("Setting IP_MULTICAST_TTL"), exit(1); - - if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, &do_loop, sizeof(char)) - != 0) - perror("Setting IP_MULTICAST_LOOP"), exit(1); - if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, &no_loop, sizeof(char)) - != 0) - perror("Setting IP_MULTICAST_LOOP"), exit(1); - len = sizeof(no_loop); - if (getsockopt - (s, IPPROTO_IP, IP_MULTICAST_LOOP, &no_loop, - (socklen_t *) & len) != 0) - perror("Getting IP_MULTICAST_LOOP"), exit(1); - - close(s); - exit(0); -} -- 1.9.3 ------------------------------------------------------------------------------ Comprehensive Server Monitoring with Site24x7. Monitor 10 servers for $9/Month. Get alerted through email, SMS, voice calls or mobile push notifications. Take corrective actions from your mobile device. http://p.sf.net/sfu/Zoho _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list