Author: gstein
Date: Wed Jul 20 20:41:48 2011
New Revision: 1148932

URL: http://svn.apache.org/viewvc?rev=1148932&view=rev
Log:
Fix up the testing code: ensure the tst machine only operates upon the
proper request (ie. don't pause PROPFIND requests that are issued during
the test sequence). Also switch forced advancement based on a parameter
rather than the INJECT flag: we may be calling from the network code,
instead of post-injection.

* subversion/libsvn_ra_serf/util.c:
  (PBTEST_SET_PAUSED): only pause the parser if it is the *right* one
  (PBTEST_MAYBE_STEP): take a new param, to force advancement after we
    have inject some/all pending content
  (PBTEST_FORCE_SPILL): only force a spill for the proper request
  (PBTEST_THIS_REQ): macro to determine whether the given request is what
    we are using to perform the test sequence
  (maybe_next_step): take a new FORCE parameter, rather than relying on
    whether this particular step is intending to inject content. this
    function may be called by the network code *or* the injection code.
    only for the latter, do we want to advance. also: only do the
    advancement if we're looking at the proper request.
  (write_to_pending): adjust PBTEST_FORCE_SPILL() call, and adjust the
    spill-denial to apply *only* to the testing request
  (svn_ra_serf__process_pending): only disable content injection for the
    correct request. likewise, only perform step advancement (and exit)
    for the proper request. add some debug printing. NULL out the parser
    after we free it, along with an assert that nobody else NULL'd it.
    pass TRUE to PBTEST_MAYBE_STEP() since this is the injection code.
  (svn_ra_serf__handle_xml_parser): switch to use PBTEST_THIS_REQ(). add
    some debug printing. NULL out the parser when done, and assert that
    nobody else has NULL'd it.

Modified:
    subversion/trunk/subversion/libsvn_ra_serf/util.c

Modified: subversion/trunk/subversion/libsvn_ra_serf/util.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/util.c?rev=1148932&r1=1148931&r2=1148932&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/util.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/util.c Wed Jul 20 20:41:48 2011
@@ -117,6 +117,7 @@ static int pbtest_step = 0;
                : ((p)->spill == NULL ? ((p)->head == NULL ? 2 : 3) \
                                      : ((p)->head == NULL ? 6 : 4)))
 
+/* Note: INJECT and COMPLETED are only used for debug output.  */
 typedef struct {
   svn_boolean_t paused;   /* pause the parser on this step?  */
   svn_boolean_t inject;   /* inject pending content on this step?  */
@@ -143,13 +144,17 @@ static const pbtest_desc_t pbtest_descri
 };
 
 #define PBTEST_SET_PAUSED(ctx) \
-  (pbtest_step < 14                                          \
+  (PBTEST_THIS_REQ(ctx) && pbtest_step < 14                  \
    ? (ctx)->paused = pbtest_description[pbtest_step].paused  \
    : FALSE)
 
-#define PBTEST_MAYBE_STEP(ctx) maybe_next_step(ctx)
+#define PBTEST_MAYBE_STEP(ctx, force) maybe_next_step(ctx, force)
 
-#define PBTEST_FORCE_SPILL() (pbtest_step == 6)
+#define PBTEST_FORCE_SPILL(ctx) (PBTEST_THIS_REQ(ctx) && pbtest_step == 6)
+
+#define PBTEST_THIS_REQ(ctx) \
+  ((ctx)->response_type != NULL \
+   && strcmp((ctx)->response_type, "update-report") == 0)
 
 #else /* PBTEST_ACTIVE  */
 
@@ -157,9 +162,10 @@ static const pbtest_desc_t pbtest_descri
    end up with "statement with no effect" warnings. Obviously, this
    depends upon particular usage, which is easy to verify.  */
 #define PBTEST_SET_PAUSED(ctx)  /* empty */
-#define PBTEST_MAYBE_STEP(ctx)  /* empty */
+#define PBTEST_MAYBE_STEP(ctx, force)  /* empty */
 
 #define PBTEST_FORCE_SPILL() FALSE
+#define PBTEST_THIS_REQ(ctx) FALSE
 
 #endif /* PBTEST_ACTIVE  */
 
@@ -1311,9 +1317,10 @@ add_done_item(svn_ra_serf__xml_parser_t 
 #ifdef PBTEST_ACTIVE
 
 /* Determine whether we should move to the next step. Print out the
-   transition for debugging purposes.  */
+   transition for debugging purposes. If FORCE is TRUE, then we
+   definitely make a step (injection has completed).  */
 static void
-maybe_next_step(svn_ra_serf__xml_parser_t *parser)
+maybe_next_step(svn_ra_serf__xml_parser_t *parser, svn_boolean_t force)
 {
   const pbtest_desc_t *desc;
   int state;
@@ -1323,10 +1330,15 @@ maybe_next_step(svn_ra_serf__xml_parser_
   if (pbtest_step == 14)
     return;
 
+  /* If this is not the request running the test, then exit.  */
+  if (!PBTEST_THIS_REQ(parser))
+    return;
+
   desc = &pbtest_description[pbtest_step];
   state = PBTEST_STATE(parser->pending);
 
-  if (desc->inject || state == desc->when_next || pbtest_step == 0)
+  /* Forced? ... or reached target state?  */
+  if (force || state == desc->when_next)
     {
       ++pbtest_step;
 
@@ -1337,8 +1349,8 @@ maybe_next_step(svn_ra_serf__xml_parser_
       ++desc;
       parser->paused = desc->paused;
 
-      SVN_DBG(("PBTEST: advanced: step=%d  paused=%d  inject=%d\n",
-               pbtest_step, desc->paused, desc->inject));
+      SVN_DBG(("PBTEST: advanced: step=%d  paused=%d  inject=%d  state=%d\n",
+               pbtest_step, desc->paused, desc->inject, state));
     }
   else
     {
@@ -1397,13 +1409,13 @@ write_to_pending(svn_ra_serf__xml_parser
 
      For testing purposes, there are points when we may want to
      create the spill file, regardless.  */
-  if (PBTEST_FORCE_SPILL()
+  if (PBTEST_FORCE_SPILL(ctx)
       || (ctx->pending->spill == NULL
           && ctx->pending->memory_size > SPILL_SIZE))
     {
 #ifdef PBTEST_ACTIVE
       /* Only allow a spill file for steps 6 or later.  */
-      if (pbtest_step >= 6)
+      if (!PBTEST_THIS_REQ(ctx) || pbtest_step >= 6)
 #endif
       SVN_ERR(svn_io_open_unique_file3(&ctx->pending->spill,
                                        NULL /* temp_path */,
@@ -1500,7 +1512,8 @@ svn_ra_serf__process_pending(svn_ra_serf
 
 #ifdef PBTEST_ACTIVE
   /* If this step should not inject content, then fast-path exit.  */
-  if (pbtest_step < 14 && !pbtest_description[pbtest_step].inject)
+  if (PBTEST_THIS_REQ(parser)
+      && pbtest_step < 14 && !pbtest_description[pbtest_step].inject)
     {
       SVN_DBG(("PBTEST: process: injection disabled\n"));
       return SVN_NO_ERROR;
@@ -1548,9 +1561,10 @@ svn_ra_serf__process_pending(svn_ra_serf
   /* For steps 4 and 9, we wait until all of the memory content has been
      injected. At that point, we can take another step which will pause
      the parser, and we'll need to exit.  */
-  if (pbtest_step == 4 || pbtest_step == 9)
+  if (PBTEST_THIS_REQ(parser)
+      && (pbtest_step == 4 || pbtest_step == 9))
     {
-      PBTEST_MAYBE_STEP(parser);
+      PBTEST_MAYBE_STEP(parser, TRUE);
       return SVN_NO_ERROR;
     }
 #endif
@@ -1609,17 +1623,25 @@ svn_ra_serf__process_pending(svn_ra_serf
      the network, then we're completely done with the parsing.  */
   if (parser->pending->network_eof)
     {
+#ifdef PBTEST_ACTIVE
+      if (PBTEST_THIS_REQ(parser))
+        SVN_DBG(("process: terminating parse.\n"));
+#endif
+
+      SVN_ERR_ASSERT(parser->xmlp != NULL);
+
       /* Tell the parser that no more content will be parsed. Ignore the
          return status. We just don't care.  */
       (void) XML_Parse(parser->xmlp, NULL, 0, 1);
 
       XML_ParserFree(parser->xmlp);
+      parser->xmlp = NULL;
       add_done_item(parser);
     }
 
   /* For testing step 12, we have written all of the disk content. This
      will advance to step 13 and pause the parser again.  */
-  PBTEST_MAYBE_STEP(parser);
+  PBTEST_MAYBE_STEP(parser, TRUE);
 
   return SVN_NO_ERROR;
 }
@@ -1682,9 +1704,8 @@ svn_ra_serf__handle_xml_parser(serf_requ
       /* This is the first invocation. If we're looking at an update
          report, then move to step 1 of the testing sequence.  */
 #ifdef PBTEST_ACTIVE
-      if (ctx->response_type != NULL
-          && strcmp(ctx->response_type, "update-report") == 0)
-        PBTEST_MAYBE_STEP(ctx);
+      if (PBTEST_THIS_REQ(ctx))
+        PBTEST_MAYBE_STEP(ctx, TRUE);
 #endif
     }
 
@@ -1717,9 +1738,17 @@ svn_ra_serf__handle_xml_parser(serf_requ
       PBTEST_SET_PAUSED(ctx);
 
 #ifdef PBTEST_ACTIVE
-      SVN_DBG(("response: len=%d  paused=%d  status=%08x\n",
-               (int)len, ctx->paused, status));
-      SVN_DBG(("content=%s\n", data));
+      if (PBTEST_THIS_REQ(ctx))
+        {
+          SVN_DBG(("response: len=%d  paused=%d  status=%08x\n",
+                   (int)len, ctx->paused, status));
+#if 0
+          /* ### DATA is not necessarily NUL-terminated, but this
+             ### generally works. so if you want to see content... */
+          if (len > 0)
+            SVN_DBG(("content=%s\n", data));
+#endif
+        }
 #endif
 
       /* Note: once the callbacks invoked by inject_to_parser() sets the
@@ -1741,7 +1770,7 @@ svn_ra_serf__handle_xml_parser(serf_requ
              Note: this only happens on writing to PENDING. If the
              parser is unpaused, then we will never change state within
              this network-reading loop.  */
-          PBTEST_MAYBE_STEP(ctx);
+          PBTEST_MAYBE_STEP(ctx, FALSE);
         }
       else
 #endif
@@ -1755,7 +1784,10 @@ svn_ra_serf__handle_xml_parser(serf_requ
         }
       if (err)
         {
+          SVN_ERR_ASSERT(ctx->xmlp != NULL);
+
           XML_ParserFree(ctx->xmlp);
+          ctx->xmlp = NULL;
           add_done_item(ctx);
           return svn_error_trace(err);
         }
@@ -1770,14 +1802,27 @@ svn_ra_serf__handle_xml_parser(serf_requ
           if (ctx->pending != NULL)
             ctx->pending->network_eof = TRUE;
 
+#ifdef PBTEST_ACTIVE
+          if (PBTEST_THIS_REQ(ctx))
+            SVN_DBG(("network: reached EOF.\n"));
+#endif
+
           /* We just hit the end of the network content. If we have nothing
              in the PENDING structures, then we're completely done.  */
           if (!HAS_PENDING_DATA(ctx->pending))
             {
+#ifdef PBTEST_ACTIVE
+              if (PBTEST_THIS_REQ(ctx))
+                SVN_DBG(("network: terminating parse.\n"));
+#endif
+
+              SVN_ERR_ASSERT(ctx->xmlp != NULL);
+
               /* Ignore the return status. We just don't care.  */
               (void) XML_Parse(ctx->xmlp, NULL, 0, 1);
 
               XML_ParserFree(ctx->xmlp);
+              ctx->xmlp = NULL;
               add_done_item(ctx);
             }
 


Reply via email to