Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve small things in test lib in execution framework #28

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Require-Bundle: com.google.guava,
org.eclipse.swt;bundle-version="3.105.3",
org.eclipse.ui;bundle-version="3.108.1",
org.eclipse.gemoc.trace.gemoc;bundle-version="2.3.0",
org.eclipse.gemoc.executionframework.engine;bundle-version="2.3.0"
org.eclipse.gemoc.executionframework.engine;bundle-version="2.3.0",
org.eclipse.gemoc.trace.gemoc.api;bundle-version="2.3.0"
Export-Package: org.eclipse.gemoc.executionframework.test.lib,
org.eclipse.gemoc.executionframework.test.lib.impl

Original file line number Diff line number Diff line change
@@ -1,77 +1,52 @@
package org.eclipse.gemoc.executionframework.test.lib.impl

import org.eclipse.gemoc.xdsmlframework.api.engine_addon.IEngineAddon
import org.eclipse.gemoc.xdsmlframework.api.core.IExecutionEngine
import org.eclipse.gemoc.executionframework.test.lib.impl.TestHelper.TestResult
import org.eclipse.gemoc.trace.commons.model.trace.Step
import java.util.Collection
import org.eclipse.gemoc.xdsmlframework.api.core.EngineStatus.RunStatus
import java.util.List
import org.eclipse.gemoc.xdsmlframework.api.core.IExecutionEngine
import org.eclipse.gemoc.xdsmlframework.api.engine_addon.DefaultEngineAddon
import org.eclipse.xtend.lib.annotations.Accessors

class TestEngineAddon implements IEngineAddon {

@Accessors(PRIVATE_SETTER,PUBLIC_GETTER)
var int amountOfStepsExecuted = 0
@Accessors(PRIVATE_SETTER,PUBLIC_GETTER)
var boolean engineAboutToStart = false
@Accessors(PRIVATE_SETTER,PUBLIC_GETTER)
var boolean engineAboutToStop = false
@Accessors(PRIVATE_SETTER,PUBLIC_GETTER)
var boolean engineStarted = false
@Accessors(PRIVATE_SETTER,PUBLIC_GETTER)
var boolean engineStopped = false
@Accessors(PRIVATE_SETTER,PUBLIC_GETTER)
var boolean engineAboutToDispose = false
class TestEngineAddon extends DefaultEngineAddon {

val int shouldStopAfter
var long timeStart

@Accessors(PRIVATE_SETTER,PUBLIC_GETTER)
val TestResult testResult

new(int shouldStopAfter) {
this.shouldStopAfter = shouldStopAfter
}

override aboutToExecuteStep(IExecutionEngine engine, Step<?> stepToExecute) {
}

override aboutToSelectStep(IExecutionEngine engine, Collection<Step<?>> steps) {
this.testResult = new TestResult
}

override engineAboutToDispose(IExecutionEngine engine) {
engineAboutToDispose = true
testResult.engineAboutToDispose = true
}

override engineAboutToStart(IExecutionEngine engine) {
engineAboutToStart = true
testResult.engineAboutToStart = true
}

override engineAboutToStop(IExecutionEngine engine) {
engineAboutToStop = true
testResult.engineAboutToStop = true
val timeEnd = System.nanoTime
testResult.executionDuration = timeEnd - timeStart
}

override engineStarted(IExecutionEngine executionEngine) {
engineStarted = true
}

override engineStatusChanged(IExecutionEngine engine, RunStatus newStatus) {
testResult.engineStarted = true
timeStart = System.nanoTime
}

override engineStopped(IExecutionEngine engine) {
engineStopped = true
}

override proposedStepsChanged(IExecutionEngine engine, Collection<Step<?>> steps) {
testResult.engineStopped = true
}

override stepExecuted(IExecutionEngine engine, Step<?> stepExecuted) {
amountOfStepsExecuted++
if (shouldStopAfter != -1 && shouldStopAfter < amountOfStepsExecuted) {
testResult.amountOfStepsExecuted++
if (shouldStopAfter != -1 && shouldStopAfter < testResult.amountOfStepsExecuted) {
engine.stop
}
}

override stepSelected(IExecutionEngine engine, Step<?> selectedStep) {
}

override validate(List<IEngineAddon> otherAddons) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.eclipse.gemoc.executionframework.test.lib.impl
import java.io.File
import java.io.PrintWriter
import java.io.StringWriter
import java.util.HashSet
import java.util.Random
import java.util.Set
import org.eclipse.core.resources.IFile
Expand All @@ -14,16 +15,30 @@ import org.eclipse.emf.common.util.URI
import org.eclipse.gemoc.executionframework.test.lib.IEngineWrapper
import org.eclipse.gemoc.executionframework.test.lib.IExecutableModel
import org.eclipse.gemoc.executionframework.test.lib.ILanguageWrapper
import org.eclipse.gemoc.trace.commons.model.trace.Trace
import org.eclipse.gemoc.trace.gemoc.traceaddon.GenericTraceEngineAddon
import org.eclipse.gemoc.xdsmlframework.api.engine_addon.IEngineAddon

import static org.junit.Assert.*

class TestHelper {

private static def testInternal(IProgressMonitor m, IEngineWrapper engine, ILanguageWrapper language,
Set<String> addons, IExecutableModel model) {
static class TestResult {
public var long executionDuration
public var Trace<?, ?, ?> trace
public var int amountOfStepsExecuted = 0
public var boolean engineAboutToStart = false
public var boolean engineAboutToStop = false
public var boolean engineStarted = false
public var boolean engineStopped = false
public var boolean engineAboutToDispose = false
}

private static def testInternal(IProgressMonitor m, IEngineWrapper engine, ILanguageWrapper language,
Set<String> addons, Set<IEngineAddon> otherAddons, IExecutableModel model, boolean cleanup) {
// Create eclipse project in test WS
val eclipseProject = ResourcesPlugin::getWorkspace().getRoot().getProject(Math::abs(new Random().nextInt).toString);
val eclipseProject = ResourcesPlugin::getWorkspace().getRoot().getProject(
Math::abs(new Random().nextInt).toString);
if (eclipseProject.exists)
eclipseProject.delete(true, m)
eclipseProject.create(m)
Expand All @@ -41,37 +56,42 @@ class TestHelper {
val TestEngineAddon testAddon = new TestEngineAddon(model.shouldStopAfter)
engine.prepare(language, model, addons, modelURI)
engine.realEngine.executionContext.executionPlatform.addEngineAddon(testAddon)
for (otherAddon : otherAddons) {
engine.realEngine.executionContext.executionPlatform.addEngineAddon(otherAddon)
}

// Execute engine
engine.run

// Dispose engine
engine.realEngine.dispose

// Generic oracle using test addon
assertTrue("No steps were executed", testAddon.amountOfStepsExecuted > 0)
assertTrue("engineAboutToStart never performed", testAddon.engineAboutToStart)
assertTrue("engineStarted never performed", testAddon.engineStarted)
assertTrue("engineAboutToStop never performed", testAddon.engineAboutToStop)
assertTrue("engineStopped never performed", testAddon.engineStopped)
assertTrue("engineAboutToDispose never performed", testAddon.engineAboutToDispose)

// Done
return Status.OK_STATUS
val testResult = testAddon.testResult
// genericAsserts(testResult)
if (cleanup) {
eclipseProject.delete(true, true, m)
}

// Return
return testResult
}

def static void testWithAddons(IEngineWrapper engine, ILanguageWrapper language, Set<String> addons,
IExecutableModel model) {
def static testWithJob(IEngineWrapper engine, ILanguageWrapper language, Set<String> addons,
Set<IEngineAddon> otherAddons, IExecutableModel model, boolean cleanup) {
val Set<TestResult> out = new HashSet
val job = new Job("single test case") {

override protected run(IProgressMonitor m) {
try {
return testInternal(m, engine, language, addons, model)
val testResult = testInternal(m, engine, language, addons, otherAddons, model, cleanup)
out.add(testResult)
return Status.OK_STATUS
} catch (Throwable t) {
t.printStackTrace
val StringWriter sw = new StringWriter();
t.printStackTrace(new PrintWriter(sw));
val errorStatus = new Status(Status.ERROR, "trace test", "An error occured in the test case", t)
val errorStatus = new Status(Status.ERROR, "test", "An error occured in the test case", t)
return errorStatus
}
}
Expand All @@ -81,14 +101,44 @@ class TestHelper {
if (job.result != null && job.result.exception != null) {
throw job.result.exception
}
return out.head
}

def static void testWithGenericTrace(IEngineWrapper engine, ILanguageWrapper language, IExecutableModel model) {
testWithAddons(engine, language, #{"Generic MultiDimensional Trace"}, model)
def static testWithGenericTrace(IEngineWrapper engine, ILanguageWrapper language, IExecutableModel model,
boolean cleanup) {
val traceAddon = new GenericTraceEngineAddon()
val testResult = testWithJob(engine, language, #{}, #{traceAddon}, model, cleanup)
// TODO when other PR is merged
//testResult.trace = traceAddon.trace
return testResult
}

def static testWithGenericTrace(IEngineWrapper engine, ILanguageWrapper language, IExecutableModel model) {
testWithGenericTrace(engine, language, model, false)
}

def static testWithoutExtraAddons(IEngineWrapper engine, ILanguageWrapper language, IExecutableModel model,
boolean cleanup) {
return testWithJob(engine, language, #{}, #{}, model, cleanup)
}

def static testWithoutExtraAddons(IEngineWrapper engine, ILanguageWrapper language, IExecutableModel model) {
return testWithoutExtraAddons(engine, language, model, false)
}

def static testNoAssert(IEngineWrapper engine, ILanguageWrapper language, IExecutableModel model, boolean cleanup) {
val res = testWithJob(engine, language, #{}, #{}, model, cleanup)

return res
}

def static void testWithoutExtraAddons(IEngineWrapper engine, ILanguageWrapper language, IExecutableModel model) {
testWithAddons(engine, language, #{}, model)
public def static genericAsserts(TestResult testResult) {
assertTrue("No steps were executed", testResult.amountOfStepsExecuted > 0)
assertTrue("engineAboutToStart never performed", testResult.engineAboutToStart)
assertTrue("engineStarted never performed", testResult.engineStarted)
assertTrue("engineAboutToStop never performed", testResult.engineAboutToStop)
assertTrue("engineStopped never performed", testResult.engineStopped)
assertTrue("engineAboutToDispose never performed", testResult.engineAboutToDispose)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ class TestRunConfiguration implements IRunConfiguration {
}

override getMelangeQuery() {
model.melangeQuery
if (model.melangeQuery == null)
"?lang=" + languageName
else
model.melangeQuery
}

override getBreakStart() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
<booleanAttribute key="includeOptional" value="true"/>
<stringAttribute key="location" value="${workspace_loc}/../junit-workspace"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/org.gemoc.execution.sequential.javaengine.tests"/>
<listEntry value="/org.gemoc.execution.sequential.javaengine.tests/xtend-gen/org/gemoc/execution/sequential/javaengine/tests/JavaEngineTests.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
<listEntry value="1"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
Expand Down