[netperf-dev] netperf4 commit notice r10 - trunk/src

raj at netperf.org raj at netperf.org
Thu Oct 27 16:15:04 PDT 2005


Author: raj
Date: 2005-10-27 16:15:02 -0700 (Thu, 27 Oct 2005)
New Revision: 10

Modified:
   trunk/src/netlib.c
   trunk/src/netperf.c
   trunk/src/netsysstats_common.c
   trunk/src/netsysstats_linux.c
   trunk/src/nettest_bsd.c
Log:
valgrind cleanups - mostly for stuff where we were sending null pointers
places they should not go


Modified: trunk/src/netlib.c
===================================================================
--- trunk/src/netlib.c	2005-10-27 21:30:24 UTC (rev 9)
+++ trunk/src/netlib.c	2005-10-27 23:15:02 UTC (rev 10)
@@ -190,6 +190,7 @@
 void
 report_test_status(server_t *server)
 {
+  int ret;
   test_hash_t *h;
   bsd_data_t  *my_data;
   test_t      *test;
@@ -203,16 +204,27 @@
           "cnt1","cnt2","cnt3","cnt4");
   for (i = 0; i < TEST_HASH_BUCKETS; i ++) {
     h = &test_hash[i];
-    pthread_mutex_lock(&h->hash_lock);
+    ret = pthread_mutex_lock(&h->hash_lock);
+    if (ret) {
+      fprintf(where,"__func__ pthread_mutex_lock returned %d\n",ret);
+      fflush(where);
+    }
     test = h->test;
 
-    my_data = (bsd_data_t *)test->test_specific_data;
-    a    = my_data->stats.counter[0];
-    b    = my_data->stats.counter[1];
-    c    = my_data->stats.counter[2];
-    d    = my_data->stats.counter[3];
+    while (test != NULL) {
 
-    while (test != NULL) {
+      my_data = (bsd_data_t *)test->test_specific_data;
+      /* of course, there can be times when we don't yet have a my_data?
+	 so, we best not be trying to dereference that pointer had we?!?
+	 raj 2005-10-27 */
+      if (my_data) {
+	a    = my_data->stats.counter[0];
+	b    = my_data->stats.counter[1];
+	c    = my_data->stats.counter[2];
+	d    = my_data->stats.counter[3];
+      }
+      
+      
       if (!xmlStrcmp(test->server_id,server->id)) {
         switch (test->state) {
         case TEST_PREINIT:
@@ -271,8 +283,13 @@
                 test->id,test->test_name,state,req_st,a,b,c,d);
       }
       test = test->next;
+      printf("in report_test_status, test is moving to %p\n",test);
     }
-    pthread_mutex_unlock(&h->hash_lock);
+    ret = pthread_mutex_unlock(&h->hash_lock);
+    if (ret) {
+      fprintf(where,"__func__ pthread_mutex_unlock returned %d\n",ret);
+      fflush(where);
+    }
   }
   fflush(where);
 }

Modified: trunk/src/netperf.c
===================================================================
--- trunk/src/netperf.c	2005-10-27 21:30:24 UTC (rev 9)
+++ trunk/src/netperf.c	2005-10-27 23:15:02 UTC (rev 10)
@@ -1654,8 +1654,20 @@
 wait_command(xmlNodePtr cmd, uint32_t junk)
 {
   int seconds;
+  xmlChar *string;
+
   wait_for_tests_to_enter_requested_state(cmd);
-  seconds = atoi((char *)xmlGetProp(cmd,(const xmlChar *)"seconds"));
+  
+  /* again with the ass-u-me either the string will be there, or that
+     atoi will do what we want it to if given a null pointer... so,
+     lets fix that sort of bug - again...  raj 2005-10-27 */
+  string = xmlGetProp(cmd,(const xmlChar *)"seconds");
+  if (string) {
+    seconds = atoi((char *)string);
+  }
+  else {
+    seconds = 0;
+  }
   if (seconds) {
     sleep(seconds);
   }

Modified: trunk/src/netsysstats_common.c
===================================================================
--- trunk/src/netsysstats_common.c	2005-10-27 21:30:24 UTC (rev 9)
+++ trunk/src/netsysstats_common.c	2005-10-27 23:15:02 UTC (rev 10)
@@ -359,7 +359,7 @@
     ap = xmlSetProp(stats,(xmlChar *)"tid",test->id);
     if (GET_TEST_STATE == TEST_MEASURE) {
       /* get_cpu_time_counters sets current timestamp */
-      get_cpu_time_counters(tsd->ending_cpu_counters, &(tsd->curr_time), tsd);
+      get_cpu_time_counters(tsd->ending_cpu_counters, &(tsd->curr_time), test);
       if (ap != NULL) {
         ap = set_stat_attribute(test, stats,"time_sec",tsd->curr_time.tv_sec);
       }

Modified: trunk/src/netsysstats_linux.c
===================================================================
--- trunk/src/netsysstats_linux.c	2005-10-27 21:30:24 UTC (rev 9)
+++ trunk/src/netsysstats_linux.c	2005-10-27 23:15:02 UTC (rev 10)
@@ -154,6 +154,15 @@
 
   NETPERF_DEBUG_ENTRY(test->debug,test->where);
 
+  if (test->debug) {
+    fprintf(test->where,
+	    "__func__ res %p timeptr %p test %p tsd %p\n",
+	    res,
+	    time,
+	    test,
+	    tsd);
+    fflush(test->where);
+  }
   lseek (proc_stat_fd, 0, SEEK_SET);
   read (proc_stat_fd, p, proc_stat_buflen);
   
@@ -169,10 +178,10 @@
     records = sscanf(proc_stat_buf,
 		     "%s %lld %lld %lld %lld",
 		     cpunam,
-		     res[i].user,
-		     nicetime,
-		     res[i].kernel,
-		     res[i].idle);
+		     &(res[i].user),
+		     &nicetime,
+		     &(res[i].kernel),
+		     &(res[i].idle));
     res[i].user += nicetime;
     res[i].other = 0;
     res[i].interrupt = 0;

Modified: trunk/src/nettest_bsd.c
===================================================================
--- trunk/src/nettest_bsd.c	2005-10-27 21:30:24 UTC (rev 9)
+++ trunk/src/nettest_bsd.c	2005-10-27 23:15:02 UTC (rev 10)
@@ -659,14 +659,24 @@
     } 
     break;
   }
- 
-  if (args != NULL) {
+
+  /* probably a good idea to make sure that new_data is real */
+  if ((args != NULL) &&
+      (NULL != new_data)) {
     /* zero the bsd test specific data structure */
     memset(new_data,0,sizeof(bsd_data_t));
 
     string =  xmlGetProp(args,(const xmlChar *)"fill_file");
-    /* fopen the fill file it will be used when allocating buffer rings */
-    fill_source = fopen((char *)string,"r");
+    /* fopen the fill file it will be used when allocating buffer
+       rings. only call fopen if there is really a "fill_file"
+       property present... */
+    if (string) {
+      fill_source = fopen((char *)string,"r");
+    }
+
+    /* we are relying on the good graces of the validating and
+       attribute filling of libxml when we parsed the message that got
+       us here... */
     string =  xmlGetProp(args,(const xmlChar *)"send_buffer_size");
     units  =  xmlGetProp(args,(const xmlChar *)"send_buffer_units");
     new_data->send_buf_size = convert(string,units);
@@ -689,11 +699,23 @@
     string =  xmlGetProp(args,(const xmlChar *)"rsp_size");
     new_data->rsp_size = atoi((char *)string);
 
+    /* relying on the DTD to give us defaults isn't always the most
+       robust way to go about doing things. */
     string =  xmlGetProp(args,(const xmlChar *)"port_min");
-    new_data->port_min = atoi((char *)string);
+    if (string) {
+      new_data->port_min = atoi((char *)string);
+    }
+    else {
+      new_data->port_min = -1;
+    }
 
     string =  xmlGetProp(args,(const xmlChar *)"port_max");
-    new_data->port_max = atoi((char *)string);
+    if (string) {
+      new_data->port_max = atoi((char *)string);
+    }
+    else {
+      new_data->port_max = -1;
+    }
 
     string =  xmlGetProp(args,(const xmlChar *)"send_width");
     new_data->send_width = atoi((char *)string);



More information about the netperf-dev mailing list