Skip to content

Commit

Permalink
Verify that debuggers are reset after TDML tests are run
Browse files Browse the repository at this point in the history
Current behavior in Daffodil is to automatically disable debugging after
a call to runOneTest, which helps to avoid errors where enabling
debugging in one test might cause failures in another test.

This updates a test to use the latest TDML API and confirm that this
behavior actually happens. Note that the schema that originally found
the issue with long-lived debugger state is no longer valid in Daffodil,
so it needed some tweaks. This also simplifies the custom debugger to
avoid storing strings that are never needed.

DAFFODIL-790
  • Loading branch information
stevedlawrence committed Dec 14, 2023
1 parent 37d6746 commit 8b553ae
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,25 @@
<!-- use asserts to make sure each header appears the correct number
of times -->
<dfdl:assert message="Date must appear 1 time."
test="{ (fn:count(ex:RootArray/ex:Date) eq 1) }" />
test="{ (fn:count(ex:Date) eq 1) }" />
<dfdl:assert message="From must appear 1 time."
test="{ (fn:count(ex:RootArray/ex:From) eq 1) }" />
test="{ (fn:count(ex:From) eq 1) }" />
<dfdl:assert message="To must appear 0 or 1 times."
test="{ (fn:count(ex:RootArray/ex:To) lt 2) }" />
test="{ (fn:count(ex:To) lt 2) }" />
<dfdl:assert message="Subject must appear 1 time."
test="{ (fn:count(ex:RootArray/ex:Subject) eq 1) }" />
test="{ (fn:count(ex:Subject) eq 1) }" />
</xsd:appinfo>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element name="RootArray" dfdl:occursCountKind="implicit"
minOccurs="1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:choice dfdl:initiatedContent="yes">
<xsd:element name="Date" dfdl:initiator="Date:%SP;"
dfdl:terminator="%CR;%LF;" type="xsd:string" />
<xsd:element name="From" dfdl:initiator="From:%SP;"
dfdl:terminator="%CR;%LF;" type="xsd:string" />
<xsd:element name="To" dfdl:initiator="To:%SP;"
dfdl:terminator="%CR;%LF;" type="xsd:string" />
<xsd:element name="Subject" dfdl:initiator="Subject:%SP;"
dfdl:terminator="%CR;%LF;" type="xsd:string" />
</xsd:choice>
</xsd:complexType>
</xsd:element>
<xsd:sequence dfdl:sequenceKind="unordered" dfdl:separator="%CR;%LF;" dfdl:separatorPosition="postfix">
<xsd:element name="Date" dfdl:initiator="Date:%SP;" type="xsd:string"
maxOccurs="unbounded" dfdl:occursCountKind="parsed"/>
<xsd:element name="From" dfdl:initiator="From:%SP;" type="xsd:string"
maxOccurs="unbounded" dfdl:occursCountKind="parsed"/>
<xsd:element name="To" dfdl:initiator="To:%SP;" type="xsd:string"
maxOccurs="unbounded" dfdl:occursCountKind="parsed"/>
<xsd:element name="Subject" dfdl:initiator="Subject:%SP;" type="xsd:string"
maxOccurs="unbounded" dfdl:occursCountKind="parsed"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Expand All @@ -108,7 +101,6 @@
<tdml:documentPart type="byte">0D0A</tdml:documentPart>
<tdml:documentPart type="text"><![CDATA[To: jane@doe.com]]></tdml:documentPart>
<tdml:documentPart type="byte">0D0A</tdml:documentPart>
<tdml:documentPart type="text"><![CDATA[Subject: Hello World!]]></tdml:documentPart>
</tdml:document>

<tdml:errors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@

package org.apache.daffodil.usertests

import org.apache.daffodil.core.dsom.ExpressionCompilers
import org.apache.daffodil.runtime1.debugger.InteractiveDebugger
import org.apache.daffodil.runtime1.debugger.TraceDebuggerRunner
import org.apache.daffodil.tdml.Runner

import org.junit.AfterClass
import org.junit.Assert._
import org.junit.Test

object TestUserSubmittedTests {
Expand Down Expand Up @@ -52,49 +56,38 @@ class TestUserSubmittedTests {
@Test def test_nameDOB_test2_pass(): Unit = { runner2.runOneTest("nameDOB_test2_pass") }
@Test def test_nameDOB_test2_fail(): Unit = { runner2.runOneTest("nameDOB_test2_fail") }

/*//DFDL-1118
@Test def test_dfdl_782() = {
val tr = new CustomTraceRunner
tr.init
val crunner = new CustomInteractiveDebuggerRunner(tr)
val db = new InteractiveDebugger(crunner, ExpressionCompiler)
Debugger.setDebugging(true)
Debugger.setDebugger(db)
val crunner = new CountTraceDebuggerRunner
val db = new InteractiveDebugger(crunner, ExpressionCompilers)

runner.runOneTest("test_DFDL_782")
// Comment out these two lines to see issue
// documented in DFDL-790
Debugger.setDebugging(false)
Debugger.setDebugger(null)
}
*/
// sets the debugger and enables debugging
runner.setDebugger(db)

}

/*
class CustomInteractiveDebuggerRunner(dr: DebuggerRunner)
extends InteractiveDebuggerRunner {
def init(id: InteractiveDebugger): Unit = dr.init
def getCommand(): String = dr.getCommand
def lineOutput(line: String): Unit = dr.lineOutput(line)
def fini(): Unit = dr.fini
}
// run a test with the debugger and debugging enabled so that we count the lines. runOneTest
// will disable debugging when the test completes
runner.runOneTest("test_DFDL_782")
assertTrue(crunner.numLines > 0)

class CustomTraceRunner extends TraceRunner {
private var _lines = List.empty[String]
// reset the numLines counter to 0
crunner.numLines = 0

def getAllTheLines(): String = {
val sb = new StringBuilder
_lines.foreach(line => {
if (line.length > 0) sb.append(line)
})
val allTheLines = sb.toString
allTheLines
// run the test again, this should not count any lines because debugging was disabled when
// the previous call to runOneTest finished
runner.runOneTest("test_DFDL_782")
assertTrue(crunner.numLines == 0)

// note that this Runner still has the CountTraceDebuggerRunner set as its debugger, so if
// other tests using the same Runner enable debugging via runner.debug and run after this
// test, they will use it and it might affect their behavior. Technically this isn't
// necessary since no other tests in this suite do this, but it's good habit. But commenting
// this line out should not break anything.
runner.setDebugger(null)
}

override def init(): Unit = { _lines = List.empty[String] }
override def lineOutput(line: String) = _lines ++ (line + "\n")
}

// custom trace debugger runner that just counts the number of lines output by the debugger
class CountTraceDebuggerRunner extends TraceDebuggerRunner {
var numLines = 0
override def lineOutput(line: String) = numLines += 1
}
*/

0 comments on commit 8b553ae

Please sign in to comment.