Unit test for producer.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Fri, 10 Dec 2004 09:08:07 +0000 (09:08 +0000)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Fri, 10 Dec 2004 09:08:07 +0000 (09:08 +0000)
Fix small memory leak in InitContext/FreeContext.

org.glite.lb.client/Makefile
org.glite.lb.client/test/prod_proto_test.c
org.glite.lb.client/test/producer_test.cpp
org.glite.lb.common/src/context.c

index 6fd7a20..f3abc86 100644 (file)
@@ -224,7 +224,7 @@ producer_test: producer_test.o prod_proto_test.o
        ${LINKXX} -o $@ ${LIB} ${TEST_LIBS} $+ ${EXT_LIB} ${GLOBUS_LIBS}
 
 producer_test.o: %.o: %.cpp
-       ${CXX} -c ${CXXFLAGS} ${TEST_INC} $<
+       ${CXX} -c ${CXXFLAGS} ${TEST_INC} ${GLOBUSINC} $<
        
 stage: compile ${FAKELIB} ${FAKETHRLIB} 
        $(MAKE) install PREFIX=${stagedir}
index e0214fe..ef4ddc8 100644 (file)
@@ -1,33 +1,37 @@
 #define edg_wll_gss_read_full(a,b,c,d,e,f)  test_edg_wll_gss_read_full(a,b,c,d,e,f)
 #define edg_wll_gss_write_full(a,b,c,d,e,f) test_edg_wll_gss_write_full(a,b,c,d,e,f)
-#define edg_wll_GssConnection               int
 
 #include "prod_proto.h"
 #include "glite/lb/producer.h"
 #include "glite/lb/escape.h"
-#include "glite/lb/lb_gss.h"
 
+/* virtual read will return all zeroes (answer from logger always without error) */
 int
-test_edg_wll_gss_read_full(int *fd,
+test_edg_wll_gss_read_full(edg_wll_GssConnection *con,
                           void *buf,
                           size_t bufsize,
                           struct timeval *timeout,
                           size_t *total,
                           edg_wll_GssStatus *code) 
 {
-  return(0);
+  code->major_status = 0;
+  code->minor_status = 0;
+  if (bufsize > 0) memset(buf, 0, bufsize);
+  return bufsize;
 }
 
 int
-test_edg_wll_gss_write_full(int *fd,
+test_edg_wll_gss_write_full(edg_wll_GssConnection *con,
                            const void *buf,
                            size_t bufsize,
                            struct timeval *timeout,
                            size_t *total,
                            edg_wll_GssStatus *code) 
 {
-  *total = write(*fd, buf, bufsize);
-  return(*total < 0 ? *total : 0);
+  *total = write(*(int *)con, buf, bufsize);
+  code->major_status = 0;
+  code->minor_status = *total < 0 ? *total : 0;
+  return *total < 0 ? *total : 0;
 }
 
 #include "prod_proto.c"
index b717b85..c2199c5 100644 (file)
 #include <assert.h>
 #include <string.h>
 
+#include "glite/lb/context-int.h"
+
 extern "C" {
-int edg_wll_log_proto_client(int *,char *,char *,int,int);
+int edg_wll_log_proto_client(edg_wll_Context, int *,char *);
 }
 
 class ProducerTest: public  CppUnit::TestFixture
@@ -35,14 +37,47 @@ public:
   }
 
   void testProtoClient() {
-    int ret=0;
-    CPPUNIT_ASSERT( ret == 0 );
+    edg_wll_Context context;
+    int err;
+    char *tst_msg = "DATE=20040831150159.702224 HOST=\"some.host\" PROG=edg-wms LVL=USAGE DG.PRIORITY=0 DG.SOURCE=\"UserInterface\" DG.SRC_INSTANCE=\"\" DG.EVNT=\"RegJob\" DG.JOBID=\"https://some.host:1234/x67qr549qc\" DG.SEQCODE=\"UI=2:NS=0:WM=0:BH=1:JSS=0:LM=0:LRMS=0:APP=0\" DG.REGJOB.JDL=\"\" DG.REGJOB.NS=\"ns address\" DG.REGJOB.PARENT=\"\" DG.REGJOB.JOBTYPE=\"SIMPLE\" DG.REGJOB.NSUBJOBS=\"0\" DG.REGJOB.SEED=\"\"";
+
+    err = edg_wll_InitContext(&context);
+    CPPUNIT_ASSERT(err == 0);
+    err = edg_wll_log_proto_client(context, &pd[1], tst_msg);
+    CPPUNIT_ASSERT(err == 0);
+    log_proto_server(pd[0], tst_msg);
+    edg_wll_FreeContext(context);
   }
 
 private:
   int  pd[2];
+  int sock;
+
+  void log_proto_server(int con, char *logline) {
+    int i;
+    char b[4];
+    char *buf;
+    ssize_t size, retsize;
+
+    // read DGLOG
+    retsize = read(con, b, 5);
+    CPPUNIT_ASSERT(retsize == 5);
+    CPPUNIT_ASSERT(b[0] = 'D' && b[1] == 'G' && b[2] == 'L' && b[3] == 'O' && b[4] == 'G');
+
+    // read size (including '\0', little endian)
+    for (i = 0; i < 4; i++)
+      CPPUNIT_ASSERT(read(con, b + i, 1) == 1);
+    size = 0;
+    for (i = 0; i < 4; i++)
+      size = (size << 8) + b[3-i];
+
+    // read the message
+    buf = (char *)malloc(size);
+    retsize = read(con, buf, size);
+    CPPUNIT_ASSERT(size == retsize);
 
-  int log_proto_server(int con, char *logline) {
+    CPPUNIT_ASSERT(strcmp(buf, logline) == 0);
+    free(buf);
   }
 };
 
index e58270f..33cb50c 100644 (file)
@@ -59,6 +59,14 @@ void edg_wll_FreeContext(edg_wll_Context ctx)
                }       
                free(ctx->connPool);
        }
+       if (ctx->connPoolNotif) {
+               if (ctx->connPoolNotif[0].peerName) free(ctx->connPoolNotif[0].peerName);
+               edg_wll_gss_close(&ctx->connPoolNotif[0].gss,&close_timeout);
+               if (ctx->connPoolNotif[0].gsiCred)
+                       gss_release_cred(&min_stat, &ctx->connPoolNotif[0].gsiCred);
+               if (ctx->connPoolNotif[0].buf) free(ctx->connPoolNotif[0].buf);
+               free(ctx->connPoolNotif);
+       }
        if ( ctx->connProxy ) {
                if ( ctx->connProxy->buf ) free(ctx->connProxy->buf);
                edg_wll_plain_close(&ctx->connProxy->conn);