Layer 1 tests: more mature version
authorsrugovac <>
Thu, 15 Mar 2007 13:54:59 +0000 (13:54 +0000)
committersrugovac <>
Thu, 15 Mar 2007 13:54:59 +0000 (13:54 +0000)
org.glite.testsuites.ctb/LB/Makefile [new file with mode: 0644]
org.glite.testsuites.ctb/LB/lb-l1.sh
org.glite.testsuites.ctb/LB/testSocket.c [new file with mode: 0755]

diff --git a/org.glite.testsuites.ctb/LB/Makefile b/org.glite.testsuites.ctb/LB/Makefile
new file mode 100644 (file)
index 0000000..34295c1
--- /dev/null
@@ -0,0 +1,14 @@
+CC=gcc
+CFLAGS=
+EXEC=testSocket
+
+all: $(EXEC)
+
+testSocket: testSocket.c
+       $(CC) -o $@ $< $(CFLAGS) 
+
+clean:
+       rm -rf *.o
+
+mrproper: clean
+       rm -rf $(EXEC)
index 2c526e9..e60f40b 100755 (executable)
@@ -3,16 +3,17 @@
 # Script for testing of LB services 
 # Basic test: PING
 #             check LB binaries
-#             check running services
-###############################################################################
-#                                                       #
-# Returned values:                                      #
-#                                                       #
-#                 Exit  TEST_OK: Test Passed            #
-#                 Exit  TEST_ERROR: Test Failed         #
-#                 Exit  2: Wrong Input                  #
-#                                                       #
-#########################################################
+#             check running services with sockets
+#####################################################################################
+#                                                              #
+# Returned values:                                             #
+#                                                              #
+#                 Exit  TEST_OK: Test Passed                   #
+#                 Exit  TEST_ERROR: Test Failed                #
+#                 Exit  2: Wrong Input                         #
+#                                                              #
+# Authors: Shkelzen Rugovac, Frederic Munster, Othmane Bouhali #
+################################################################
                                                                                 
 ##
 # defining variables
@@ -38,7 +39,7 @@ showHelp()
        echo  "Usage: $0 [OPTIONS] "
        echo  "Options:"
        echo  " -h | --help                   Show this help message."
-        echo  " -m | --m lb_host"
+        echo  " -m | --m lb_host              hostName or IPV4 adress "
        echo  " -g | --log 'logfile'          Redirect all output to the 'logfile'."
        echo  ""
 #      echo  "For proper operation check your grid-proxy-info"
@@ -48,12 +49,14 @@ if [ -z "$1" ]; then
   showHelp
   exit 2
 fi
+logfile=output.log
+flag=0
 while test -n "$1"
 do
        case "$1" in
        "-h" | "--help") showHelp && exit 2 ;;
        "-m" | "--bkserver") shift ; LB_HOST=$1 ;;
-#      "-g" | "--log") shift ; logfile=$1 ;;
+       "-g" | "--log") shift ; logfile=$1 flag=1 ;;
 
        *) echo "Unrecognized option $1 try -h for help"; exit 2 ;;
 
@@ -68,16 +71,15 @@ done
 
 function ping_host
 {
-  echo  " Testing ping to $LB_HOST"
+  echo  " Testing ping to $LB_HOST" >> $logfile
          result=`ping -c 5 $LB_HOST 2>/dev/null |  grep "0% packet loss"| wc -l`
-                                                                      
   if [ $result -gt 0 ]; then
- echo "Pinging $LB_HOST                        OK "
- else 
-   echo ""
-    echo "Ping failed: The $LB_HOST is not accessible! "
-    echo ""
-    echo " LB Basic Test:                      Failed. "
+       echo "Pinging $LB_HOST                        OK " >> $logfile
 else 
+    echo "" >> $logfile
+    echo "Ping failed: The $LB_HOST is not accessible! "  >> $logfile
+    echo "" >> $logfile
+    echo " LB Basic Test:                      Failed. " >> $logfile
     exit $TEST_ERROR
   fi
 #  echo "<font color="green"> - OK </font>"
@@ -85,10 +87,10 @@ function ping_host
 
 check_exec()
 {
-        [ $DEBUG -gt 0 ] && [ -n "$2" ] && echo -n -e "$2\t" || echo -n -e "$1\t"
+        [ $DEBUG -gt 0 ] && [ -n "$2" ] && echo -n -e "$2\t" >> $logfile || echo -n -e "$1\t" >> $logfile
         eval $1
         RV=$?
-        [ $DEBUG -gt 0 ] && [ $RV -eq 0 ] && echo "OK" || echo "FAILED"
+        [ $DEBUG -gt 0 ] && [ $RV -eq 0 ] && echo "OK" >> $logfile || echo "FAILED" >> $logfile
         return $RV
 }
 
@@ -97,31 +99,35 @@ check_exec()
 #########################
 check_binaries()
 {
       check_exec 'LBJOBREG=`which $LBJOBREG`' "Checking binary $LBJOBREG ? " || exit 1
       check_exec 'LBJOBLOG=`which $LBJOBLOG`' "Checking binary $LBJOBLOG ? " || exit 1
       check_exec 'LBLOGEV=`which $LBLOGEV`' "Checking binary $LBLOGEV ?" || exit 1
       check_exec 'LBUSERJOBS=`which $LBUSERJOBS`' "Checking binary $LBUSERJOBS ?" || exit 1
       check_exec 'LBJOBSTAT=`which $LBJOBSTAT`' "Checking binary $LBJOBSTAT ? " || exit 1
-check_exec 'LBCHANGEACL=`which $LBCHANGEACL`' "Checking binary $LBCHANGEACL ?" || exit 1
-check_exec 'LBMON=`which $LBMON`' "Checking binary $LBMON       " || exit 1
+ check_exec 'LBJOBREG=`which $LBJOBREG`' "Checking binary $LBJOBREG ? " || exit 1
+ check_exec 'LBJOBLOG=`which $LBJOBLOG`' "Checking binary $LBJOBLOG ? " || exit 1
+ check_exec 'LBLOGEV=`which $LBLOGEV`' "Checking binary $LBLOGEV ?" || exit 1
+ check_exec 'LBUSERJOBS=`which $LBUSERJOBS`' "Checking binary $LBUSERJOBS ?" || exit 1
+ check_exec 'LBJOBSTAT=`which $LBJOBSTAT`' "Checking binary $LBJOBSTAT ? " || exit 1
+ check_exec 'LBCHANGEACL=`which $LBCHANGEACL`' "Checking binary $LBCHANGEACL ?" || exit 1
+ check_exec 'LBMON=`which $LBMON`' "Checking binary $LBMON       " || exit 1
 }
 #
 # check the services
 ##################"
 check_services()
 {
-INTERLOGD=`ps aux 2>/dev/null | grep $LB_LOGD |wc -l`
-if [ $INTERLOGD -gt 1 ]; then
- echo "logd running? -                         OK"
+echo "Listening to locallogger port (9002)" >> $logfile
+./testSocket $LB_HOST 9002 >> $logfile
+if [ $? -eq 0 ]; then
+ echo "logd running ? -                         [OK]" >> $logfile
  else 
-    echo "logd running? -                      FAILED"
+    echo "logd running ? -                      [FAILED]" >> $logfile
     exit $TEST_ERROR
   fi
-INTERLOGD=`ps aux 2>/dev/null | grep $LB_INTERLOGD |wc -l`
-if [ $INTERLOGD -gt 1 ]; then
- echo "Inetrlogd running test? -               OK"
+echo "Listening to interlogger ports (9000-9001-9003)" >> $logfile
+./testSocket $LB_HOST 9000 >> $logfile &&
+./testSocket $LB_HOST 9001 >> $logfile &&
+./testSocket $LB_HOST 9003 >> $logfile 
+if [ $? -eq 0 ]; then
+ echo "Inetrlogd running ? -               [OK]" >> $logfile
  else 
-    echo "interlogd running test? -            FAILED"
+    echo "interlogd running ? -            [FAILED]" >> $logfile
     exit $TEST_ERROR
   fi
 }
@@ -132,3 +138,8 @@ if [ $INTERLOGD -gt 1 ]; then
 ping_host
 check_binaries
 check_services
+if [ $flag -ne 1 ];then
+       cat $logfile
+       rm $logfile
+fi
+
diff --git a/org.glite.testsuites.ctb/LB/testSocket.c b/org.glite.testsuites.ctb/LB/testSocket.c
new file mode 100755 (executable)
index 0000000..cf1adc8
--- /dev/null
@@ -0,0 +1,58 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <netinet/in.h>
+#include <netdb.h>
+
+#define BUFFSIZE 32
+void Die(char *mess) {
+perror(mess); 
+exit(1); }
+int main(int argc, char *argv[]) {
+int sock;
+struct hostent *hip;
+char *adrIPp;
+struct in_addr adrIP;
+struct sockaddr_in echoserver;
+char buffer[BUFFSIZE];
+unsigned int echolen;
+int received = 0;
+if (argc != 3) {
+           fprintf(stderr, "USAGE: TCPecho <server_ip> <port>\n");
+           exit(1);
+            }
+//conversion from DNS to IPv4
+if((hip=gethostbyname(argv[1]))==NULL)
+{
+printf("Erreur avec gethostbyname\n");
+//           exit(1);
+}
+adrIP.s_addr=*(int *)hip->h_addr;
+adrIPp =(char *)inet_ntoa(adrIP);
+/* Create the TCP socket */
+if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
+              Die("Failed to create socket");
+            }
+/* Construct the server sockaddr_in structure */
+memset(&echoserver, 0, sizeof(echoserver));       /* Clear struct */
+echoserver.sin_family = AF_INET;                  /* Internet/IP */
+echoserver.sin_addr.s_addr = inet_addr(adrIPp);  /* IP address */
+echoserver.sin_port = htons(atoi(argv[2]));       /* server port */
+printf("Connecting a socket with : %s,%s", adrIPp,argv[2]);
+/* Establish connection */
+if (connect(sock,
+           (struct sockaddr *) &echoserver,
+            sizeof(echoserver)) < 0) {
+              Die("Failed to connect with server");
+            }
+else 
+       {
+       shutdown(sock,2);
+       printf(" [OK]\n");
+       exit(0);
+       }
+}