Dear QVTo developers,
Our team is developing with QVTo tool, and we found a bug while running with QVTo Junit test. After spending some time to find the reason behind, we fixed it. Hereunder please find the problem, the fixed file, and the analysis.
Problem
After building the QVTo source code, we ran the Junit test with following command line:
junit --launch "org.eclipse.m2m.tests.qvt.oml/org.eclipse.m2m.tests.qvt.oml.AllTests.launch" --flatXML --output "${WORKSPACE}/MMT-QVTo.test.results/org.eclipse.m2m.tests.qvt.oml.AllTests.xml"
Occasionally, we got the following failure. One of the Junit tests aims to test for the stack overflow, and it failed with an assertion. It is noticeable to see that the failure is not happened all the time. Sometime it passed, while sometime
it failed.
INFO: Running test org.eclipse.m2m.tests.qvt.oml.transform.TestStackTrace.testMappingCallInProperty...
INFO: ...OK [0,202s]
INFO: Running test org.eclipse.m2m.tests.qvt.oml.transform.TestStackTrace.testStackOverFlow...
INFO: ...Failure [0,188s]
WARN: junit.framework.AssertionFailedError: expected:<6> but was:<5>
at junit.framework.Assert.fail(Assert.java:57)
at junit.framework.Assert.failNotEquals(Assert.java:329)
at junit.framework.Assert.assertEquals(Assert.java:78)
at junit.framework.Assert.assertEquals(Assert.java:234)
at junit.framework.Assert.assertEquals(Assert.java:241)
Fixed File
${WORKSPACE}/org.eclipse.m2m.tests.qvt.oml/src/org/eclipse/m2m/tests/qvt/oml/transform/TestStackTrace.java, line 92:
85 for
(QVTStackTraceElement element :
e.getQvtStackTrace()) {
86
if(--elementCount
== 0) {
87
break;
88 }
89
assertEquals("causeStackOverFlow",
element.getOperationName());
//$NON-NLS-1$
90
assertEquals("auxtransf",
element.getModuleName());
//$NON-NLS-1$
91
assertEquals("auxtransf.qvto",
element.getUnitName());
//$NON-NLS-1$
92
//assertEquals(6, element.getLineNumber());
93
assertTrue((5 == element.getLineNumber()) || (6 ==
element.getLineNumber()));
94 }
We made a comment of line 92, and added one line below in line 93. Instead of only checking line number 5, both line number 5 and 6 are acceptable.
Analysis
The test code here wants to test for the stack overflow, with
causeStackOverFlow method in auxtransf.qvto file. If we look inside this qvto file, we may find:
1 modeltype ecore uses 'http://www.eclipse.org/emf/2002/Ecore';
2
3 transformation auxtransf(in inModel : ecore, out outModel : ecore);
4
5 query causeStackOverFlow() : OclAny {
6 causeStackOverFlow(); -- line 7: causing stack overflow
7 }
The method causeStackOverFlow called itself here, the stack will be finally overflow because each call will push method related data into the stack. When the stack is full, an exception will be thrown.
The author of this piece of code might return the line number, and line 6 is the expected value. But the line sequence of this call should be: 5, 6, 5, 6, 5, 6, …, instead of 6, 6, 6, …. Because the entrance of this call is line 5, which
might be neglected by the author. This is also the reason why the test failure shows occasionally. When the exception failed in line 6, it passed. When the exception failed in line 5, it failed.
We recommend to fix this bug, in order to avoid any further problem by the other developers.
Best wishes,
Jiazhuo Zhang