You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2017/06/23 21:37:22 UTC

[trafficserver] branch master updated: For #2126 - Fix for transform test crash.

This is an automated email from the ASF dual-hosted git repository.

amc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 9aab3f8  For #2126 - Fix for transform test crash.
9aab3f8 is described below

commit 9aab3f864c375dc32197cd9d2b33f078080e90e1
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Thu Jun 22 10:04:50 2017 -0500

    For #2126 - Fix for transform test crash.
---
 proxy/InkAPITest.cc | 94 +++++++++++++++++++----------------------------------
 1 file changed, 34 insertions(+), 60 deletions(-)

diff --git a/proxy/InkAPITest.cc b/proxy/InkAPITest.cc
index bac0996..fcdc164 100644
--- a/proxy/InkAPITest.cc
+++ b/proxy/InkAPITest.cc
@@ -6492,13 +6492,6 @@ EXCLUSIVE_REGRESSION_TEST(SDK_API_HttpTxnCache)(RegressionTest *test, int /* aty
 //                    TSHttpTxnUntransformedRespCache
 ///////////////////////////////////////////////////////
 
-/** Append Transform Data Structure **/
-typedef struct {
-  TSVIO output_vio;
-  TSIOBuffer output_buffer;
-  TSIOBufferReader output_reader;
-  int append_needed;
-} MyTransformData;
 /** Append Transform Data Structure Ends **/
 
 typedef struct {
@@ -6516,48 +6509,35 @@ typedef struct {
   bool test_passed_txn_untransformed_resp_cache;
   bool test_passed_transform_create;
   int req_no;
-  MyTransformData *transformData;
-  int magic;
+  uint32_t magic;
 } TransformTestData;
 
+/** Append Transform Data Structure **/
+struct AppendTransformTestData {
+  TSVIO output_vio               = nullptr;
+  TSIOBuffer output_buffer       = nullptr;
+  TSIOBufferReader output_reader = nullptr;
+  TransformTestData *test_data   = nullptr;
+  int append_needed              = 1;
+
+  ~AppendTransformTestData()
+  {
+    if (output_buffer)
+      TSIOBufferDestroy(output_buffer);
+  }
+};
+
 /**** Append Transform Code (Tailored to needs)****/
 
 static TSIOBuffer append_buffer;
 static TSIOBufferReader append_buffer_reader;
 static int64_t append_buffer_length;
 
-static MyTransformData *
-my_data_alloc()
-{
-  MyTransformData *data;
-
-  data                = (MyTransformData *)TSmalloc(sizeof(MyTransformData));
-  data->output_vio    = nullptr;
-  data->output_buffer = nullptr;
-  data->output_reader = nullptr;
-  data->append_needed = 1;
-
-  return data;
-}
-
-static void
-my_data_destroy(MyTransformData *data)
-{
-  if (data) {
-    if (data->output_buffer) {
-      TSIOBufferDestroy(data->output_buffer);
-    }
-    TSfree(data);
-  }
-}
-
 static void
 handle_transform(TSCont contp)
 {
   TSVConn output_conn;
   TSVIO write_vio;
-  TransformTestData *contData;
-  MyTransformData *data;
   int64_t towrite;
   int64_t avail;
 
@@ -6571,25 +6551,19 @@ handle_transform(TSCont contp)
   write_vio = TSVConnWriteVIOGet(contp);
 
   /* Get our data structure for this operation. The private data
-     structure contains the output VIO and output buffer. If the
-     private data structure pointer is NULL, then we'll create it
-     and initialize its internals. */
-  contData = (TransformTestData *)TSContDataGet(contp);
-  data     = contData->transformData;
-  if (!data) {
+     structure contains the output VIO and output buffer.
+  */
+  auto *data = static_cast<AppendTransformTestData *>(TSContDataGet(contp));
+  if (!data->output_buffer) {
     towrite = TSVIONBytesGet(write_vio);
     if (towrite != INT64_MAX) {
       towrite += append_buffer_length;
     }
-    contData->transformData = my_data_alloc();
-    data                    = contData->transformData;
-    data->output_buffer     = TSIOBufferCreate();
-    data->output_reader     = TSIOBufferReaderAlloc(data->output_buffer);
-    data->output_vio        = TSVConnWrite(output_conn, contp, data->output_reader, towrite);
-    // Don't need this as the structure is encapsulated in another structure
-    // which is set to be Continuation's Data.
-    // TSContDataSet (contp, data);
+    data->output_buffer = TSIOBufferCreate();
+    data->output_reader = TSIOBufferReaderAlloc(data->output_buffer);
+    data->output_vio    = TSVConnWrite(output_conn, contp, data->output_reader, towrite);
   }
+  ink_assert(data->output_vio);
 
   /* We also check to see if the write VIO's buffer is non-NULL. A
      NULL buffer indicates that the write operation has been
@@ -6672,16 +6646,15 @@ handle_transform(TSCont contp)
 static int
 transformtest_transform(TSCont contp, TSEvent event, void * /* edata ATS_UNUSED */)
 {
-  TransformTestData *contData = (TransformTestData *)TSContDataGet(contp);
-  if (contData->test_passed_transform_create == false) {
-    contData->test_passed_transform_create = true;
-    SDK_RPRINT(contData->test, "TSTransformCreate", "TestCase1", TC_PASS, "ok");
+  auto *data = static_cast<AppendTransformTestData *>(TSContDataGet(contp));
+  if (data->test_data->test_passed_transform_create == false) {
+    data->test_data->test_passed_transform_create = true;
+    SDK_RPRINT(data->test_data->test, "TSTransformCreate", "TestCase1", TC_PASS, "ok");
   }
   /* Check to see if the transformation has been closed by a call to
      TSVConnClose. */
   if (TSVConnClosedGet(contp)) {
-    my_data_destroy(contData->transformData);
-    contData->transformData = nullptr;
+    delete data;
     TSContDestroy(contp);
     return 0;
   } else {
@@ -6745,14 +6718,16 @@ transformable(TSHttpTxn txnp, TransformTestData *data)
 }
 
 static void
-transform_add(TSHttpTxn txnp, TransformTestData *data)
+transform_add(TSHttpTxn txnp, TransformTestData *test_data)
 {
   TSVConn connp;
+  auto *data = new AppendTransformTestData;
 
-  connp = TSTransformCreate(transformtest_transform, txnp);
+  data->test_data = test_data;
+  connp           = TSTransformCreate(transformtest_transform, txnp);
   TSContDataSet(connp, data);
   if (connp == nullptr) {
-    SDK_RPRINT(data->test, "TSHttpTxnTransform", "", TC_FAIL, "Unable to create Transformation.");
+    SDK_RPRINT(data->test_data->test, "TSHttpTxnTransform", "", TC_FAIL, "Unable to create Transformation.");
     return;
   }
 
@@ -7015,7 +6990,6 @@ EXCLUSIVE_REGRESSION_TEST(SDK_API_HttpTxnTransform)(RegressionTest *test, int /*
   socktest->test_passed_txn_transformed_resp_cache = false;
   socktest->test_passed_txn_transformed_resp_cache = false;
   socktest->test_passed_transform_create           = false;
-  socktest->transformData                          = nullptr;
   socktest->req_no                                 = 1;
   socktest->magic                                  = MAGIC_ALIVE;
   TSContDataSet(cont, socktest);

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].