git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GitHub] mbeckerle closed pull request #68: Fix so trace works even when layering is being used.


mbeckerle closed pull request #68: Fix so trace works even when layering is being used.
URL: https://github.com/apache/incubator-daffodil/pull/68
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/daffodil-core/src/test/scala/org/apache/daffodil/util/TestUtils.scala b/daffodil-core/src/test/scala/org/apache/daffodil/util/TestUtils.scala
index a26aabfe0..70c69d2bc 100644
--- a/daffodil-core/src/test/scala/org/apache/daffodil/util/TestUtils.scala
+++ b/daffodil-core/src/test/scala/org/apache/daffodil/util/TestUtils.scala
@@ -79,8 +79,8 @@ object TestUtils {
     throw new FileNotFoundException("Couldn't find file " + f + " relative to " + cwd + ".")
   }
 
-  def testString(testSchema: Node, data: String, isTracing: Boolean = false) = {
-    runSchemaOnData(testSchema, Misc.stringToReadableByteChannel(data), isTracing)
+  def testString(testSchema: Node, data: String, areTracing: Boolean = false) = {
+    runSchemaOnData(testSchema, Misc.stringToReadableByteChannel(data), areTracing)
   }
 
   def testBinary(testSchema: Node, hexData: String, areTracing: Boolean = false): (DFDL.ParseResult, Node) = {
@@ -139,15 +139,19 @@ object TestUtils {
     }
   }
 
-  def testUnparsingBinary(testSchema: scala.xml.Elem, infoset: Node, unparseTo: Array[Byte]) {
+  def testUnparsingBinary(testSchema: scala.xml.Elem, infoset: Node, unparseTo: Array[Byte], areTracing: Boolean = false) {
     val compiler = Compiler()
     val pf = compiler.compileNode(testSchema)
     if (pf.isError) throwDiagnostics(pf.diagnostics)
-    val u = pf.onPath("/")
+    val u = pf.onPath("/").asInstanceOf[DataProcessor]
     if (u.isError) throwDiagnostics(u.getDiagnostics)
     val outputStream = new java.io.ByteArrayOutputStream()
     val out = java.nio.channels.Channels.newChannel(outputStream)
     val inputter = new ScalaXMLInfosetInputter(infoset)
+    if (areTracing) {
+      u.setDebugger(builtInTracer)
+      u.setDebugging(true)
+    }
     val actual = u.unparse(inputter, out)
     if (actual.isProcessingError) throwDiagnostics(actual.getDiagnostics)
     val unparsed = outputStream.toByteArray()
diff --git a/daffodil-io/src/main/scala/org/apache/daffodil/io/DataOutputStreamImplMixin.scala b/daffodil-io/src/main/scala/org/apache/daffodil/io/DataOutputStreamImplMixin.scala
index 72ed28480..97e0b6f8d 100644
--- a/daffodil-io/src/main/scala/org/apache/daffodil/io/DataOutputStreamImplMixin.scala
+++ b/daffodil-io/src/main/scala/org/apache/daffodil/io/DataOutputStreamImplMixin.scala
@@ -304,7 +304,6 @@ trait DataOutputStreamImplMixin extends DataStreamCommonState
       // turn debugging off
       this.cst.debugging = false
       debugOutputStream = Nope
-      setJavaOutputStream(new ByteArrayOutputStream())
     }
   }
 
@@ -816,9 +815,15 @@ trait DataOutputStreamImplMixin extends DataStreamCommonState
   }
 
   final override def pastData(nBytesRequested: Int): ByteBuffer = {
-    Assert.usage(isReadable)
-    if (!areDebugging)
-      throw new IllegalStateException("Must be debugging.")
+    Assert.usage(isReadable ||
+      // when unparsing trace/debug wants to access pastData from this DOS
+      // even after it has been closed. This is just a consequence of the
+      // creation and completion of DOS interacting with the DOS being
+      // created on the fly to implement layering, where we allocate a new
+      // DOS for the layer, and then later just drop it when the layer exits.
+      // At that point the layer is closed, but trace/debug still wants to print
+      // pastData from it as part of what it displays.
+      areDebugging)
     Assert.usage(nBytesRequested >= 0)
     if (debugOutputStream == Nope) {
       ByteBuffer.allocate(0)
diff --git a/daffodil-runtime1/src/main/scala/org/apache/daffodil/layers/LayerTransformer.scala b/daffodil-runtime1/src/main/scala/org/apache/daffodil/layers/LayerTransformer.scala
index a5f7a6c85..383a8c736 100644
--- a/daffodil-runtime1/src/main/scala/org/apache/daffodil/layers/LayerTransformer.scala
+++ b/daffodil-runtime1/src/main/scala/org/apache/daffodil/layers/LayerTransformer.scala
@@ -142,6 +142,7 @@ abstract class LayerTransformer()
 
     val newDIS = ByteBufferDataInputStream(decodedInputStream, 0L)
     newDIS.cst.setPriorBitOrder(BitOrder.MostSignificantBitFirst) // must initialize priorBitOrder
+    newDIS.setDebugging(s.areDebugging)
     newDIS
   }
 
@@ -156,6 +157,7 @@ abstract class LayerTransformer()
     val newDOS = DirectOrBufferedDataOutputStream(encodedOutputStream, null)
     newDOS.setPriorBitOrder(BitOrder.MostSignificantBitFirst)
     newDOS.setAbsStartingBitPos0b(ULong(0L))
+    newDOS.setDebugging(s.areDebugging)
     newDOS
   }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@xxxxxxxxxxxxxxxx


With regards,
Apache Git Services