Commit 54ef2e8d authored by František Haas's avatar František Haas

processed rest of tests to junit runner

parent f4bc404f
......@@ -13,10 +13,29 @@ To use the for debuging purpose during development a single suite test (for
example "after" test) can be invoked calling
- ant suite-test2 -Dtest2.name=after
Parameters can specified to ant at command line starting with "-Ddisl." are
passed to the test. For example to show tests output specify
Parameters specified to ant at command line starting with "-Ddisl." are passed
to the test. For example to show tests output specify
- -Ddisl.test.verbose=true
When built with "ant prepare-test2" tests can be also run directly. They are
packed in the "build-test" directory.
Implementation
==============
Implementation is a bit tricky in few aspects.
Firstly, building of suite test apps and instrumentations is handled by a
scripted target that lists all directories in a "ch.usi.dag.disl.test2.suite"
package and one by one "app" and "instr" package are jared.
If not scripted, evil ant-contrib would be required.
Secondly, when running the instances of client and server using Process API
never forget to clear environemnt variables as inherited classpath could cause
serious troubles.
If a suite instr test contains a manifest file it's used and if none is present
"DiSLClass" is default for "DiSL-Classes" attribute.
......@@ -235,10 +235,23 @@
for (i = 0; i < dirsets.size(); ++i) {
var it = dirsets.get(i).iterator();
while (it.hasNext()) {
dir = it.next().getName();
self.project.setProperty( "tmp.test2.name", dir);
var name = it.next().getName();
var path = "ch/usi/dag/disl/test2/suite/" + name;
var pkg = "ch.usi.dag.disl.test2.suite." + name;
var manifest = self.project.getProperty("src.test") + "/" + path + "/instr/MANIFEST.MF";
self.project.setProperty( "tmp.test2.name", name);
self.project.setProperty( "tmp.test2.path", path);
self.project.setProperty( "tmp.test2.pkg", pkg);
self.project.setProperty( "tmp.test2.manifest", manifest);
self.project.executeTarget( "package-test2-app");
self.project.executeTarget( "package-test2-instr");
if (new java.io.File( manifest).exists()) {
self.project.executeTarget( "package-test2-instr-manifest");
} else {
self.project.executeTarget( "package-test2-instr-nomanifest");
}
}
}
]]>
......@@ -246,24 +259,33 @@
<target name="package-test2-app">
<jar jarfile="${build.test}/disl-app-${tmp.test2.name}.jar"
basedir="${bin}"
includes="ch/usi/dag/disl/test2/suite/${tmp.test2.name}/app/**">
basedir="${bin}"
includes="${tmp.test2.path}/app/**">
<manifest>
<attribute name="Main-Class" value="ch.usi.dag.disl.test2.suite.${tmp.test2.name}.app.TargetClass" />
<attribute name="Main-Class" value="${tmp.test2.pkg}.app.TargetClass" />
</manifest>
</jar>
</target>
<target name="package-test2-instr">
<target name="package-test2-instr-nomanifest">
<jar jarfile="${build.test}/disl-instr-${tmp.test2.name}.jar"
basedir="${bin}"
includes="ch/usi/dag/disl/test2/suite/${tmp.test2.name}/instr/**"
excludes="ch/usi/dag/disl/test2/suite/${tmp.test2.name}/instr/MANIFEST.MF">
basedir="${bin}"
includes="${tmp.test2.path}/instr/**"
excludes="${tmp.test2.path}/instr/MANIFEST.MF">
<manifest>
<attribute name="DiSL-Classes" value="ch.usi.dag.disl.test2.suite.${tmp.test2.name}.instr.DiSLClass" />
<attribute name="DiSL-Classes" value="${tmp.test2.path}.instr.DiSLClass" />
</manifest>
</jar>
</target>
<target name="package-test2-instr-manifest">
<jar jarfile="${build.test}/disl-instr-${tmp.test2.name}.jar"
basedir="${bin}"
includes="${tmp.test2.path}/instr/**"
excludes="${tmp.test2.path}/instr/MANIFEST.MF"
manifest="${tmp.test2.manifest}">
</jar>
</target>
<target name="package-test2">
<mkdir dir="${build.test}"/>
......@@ -286,9 +308,9 @@
<target name="test2" depends="prepare-test2">
<junit
haltonfailure="no"
haltonerror="no"
failureproperty="junit.failure">
haltonfailure="no"
haltonerror="no"
failureproperty="junit.failure">
<classpath refid="classpath" />
<formatter type="brief" usefile="false" />
<!-- allows properties starting with "-Ddisl." to be passed to tests -->
......@@ -297,8 +319,8 @@
</syspropertyset>
<batchtest fork="yes">
<fileset dir="${src.test}">
<include name="*ch/usi/dag/disl/test2/junit/*Test.java" />
<include name="*ch/usi/dag/disl/test2/suite/*/junit/*Test.java" />
<include name="ch/usi/dag/disl/test2/junit/*Test.java" />
<include name="ch/usi/dag/disl/test2/suite/*/junit/*Test.java" />
</fileset>
</batchtest>
</junit>
......
UNAME := Unknown
ifeq ($(OS),Windows_NT)
UNAME := Windows
......@@ -5,28 +6,53 @@ ifeq ($(OS),Windows_NT)
UNAME := Cygwin
endif
else
UNAME := $(shell uname -s)
UNAME_KNOWN := $(shell uname -s)
ifeq ($(UNAME_KNOWN),Linux)
UNAME := Linux
endif
ifeq ($(UNAME_KNOWN),Darwin)
UNAME := Darwin
endif
endif
.PHONY: all, clean
all: $(UNAME)
all: $(UNAME)-all
Linux:
@./find.sh
Linux-all:
@./find.sh
Darwin:
@./find.sh
Darwin-all:
@./find.sh
Windows:
@echo Windows not yet supported.
Cygwin-all:
@./find.sh
Cygwin:
@echo "Cygwin not yet supported."
Windows-all:
@.\\find.bat
Unknown-all:
$(error error: unsupported operating system $(UNAME))
clean:
clean: $(UNAME)-clean
Linux-clean:
@rm -f var
Darwin-clean:
@rm -f var
Cygwin-clean:
@rm -f var
Windows-clean:
@CMD /C IF EXIST var DEL /Q/F var
Unknown-clean:
$(error error: unsupported operating system $(UNAME))
@ECHO OFF
:: use variable specified by the use
IF EXIST "var.local" (
COPY /B/V/Y "var.local" "var" > NUL
EXIT /B 0
)
:: use environment variable
IF not "%JAVA_HOME%" == "" (
ECHO JAVA_HOME=%JAVA_HOME% > "var"
EXIT /B 0
)
#!/bin/bash
#!/bin/sh
# use variable specified by the user
if [ -f "var.local" ]; then
......
UNAME := Unknown
ifeq ($(OS),Windows_NT)
UNAME := Windows
......@@ -5,28 +6,53 @@ ifeq ($(OS),Windows_NT)
UNAME := Cygwin
endif
else
UNAME := $(shell uname -s)
UNAME_KNOWN := $(shell uname -s)
ifeq ($(UNAME_KNOWN),Linux)
UNAME := Linux
endif
ifeq ($(UNAME_KNOWN),Darwin)
UNAME := Darwin
endif
endif
.PHONY: all, clean
all: $(UNAME)
all: $(UNAME)-all
Linux:
@./find.sh
Linux-all:
@./find.sh
Darwin:
@echo "Darwin is supported"
Darwin-all:
@./find.sh
Windows:
@echo Windows not yet supported.
Cygwin-all:
@./find.sh
Cygwin:
@echo "Cygwin not yet supported."
Windows-all:
@.\\find.bat
Unknown-all:
$(error error: unsupported operating system $(UNAME))
clean:
clean: $(UNAME)-clean
Linux-clean:
@rm -f var
Darwin-clean:
@rm -f var
Cygwin-clean:
@rm -f var
Windows-clean:
@CMD /C IF EXIST var DEL /Q/F var
Unknown-clean:
$(error error: unsupported operating system $(UNAME))
@ECHO OFF
:: use variable specified by the use
IF EXIST "var.local" (
COPY /B/V/Y "var.local" "var" > NUL
EXIT /B 0
)
:: use environment variable
IF not "%JAVA_HOME%" == "" (
ECHO JAVA_HOME=%JAVA_HOME% > "var"
EXIT /B 0
)
#!/bin/bash
#!/bin/sh
# use variable specified by the user
if [ -f "var.local" ]; then
cp -f "var.local" "var"
exit 0
fi
# use environment variable
if [ ! -z "$JAVA_HOME" ]; then
echo "JAVA_HOME="$JAVA_HOME > "var"
exit 0
fi
# guess
JAVAC=`which javac 2>/dev/null`
JH=`readlink -f ${JAVAC}`
JH=`echo ${JH%/*}`
JH=`echo ${JH%/*}`
echo "JAVA_HOME="${JH} > "var"
......@@ -17,31 +17,27 @@ public class TargetClass {
System.out.println("app: TargetClass.print(..) - finally");
}
}
// FIXME
// this main would fail the test
// could be fixed by adding app's code to the server's classpath
//
//public static void main(String[] args) {
// try {
// TargetClass t = new TargetClass();
// System.out.println("app: main - .print(false)");
// t.print(false);
// System.out.println("app: main - .print(true)");
// t.print(true);
// } catch (Throwable e) {
// System.out.println("app: main - catch");
// }
//}
// this main breaks the test on class not found exception of this class
/*
public static void main(String[] args) {
try {
TargetClass t = new TargetClass();
System.out.println("app: TargetClass.main(..) - .print(false)");
t.print(false);
System.out.println("app: TargetClass.main(..) - .print(true)");
t.print(true);
} catch (Throwable e) {
System.out.println("app: TargetClass.main(..) - catch");
}
}*/
public static void main(String[] args) {
TargetClass t = new TargetClass();
System.out.println("app: TargetClass.main(..) - TargetClass.print(false)");
System.out.println("app: TargetClass.main(..) - .print(false)");
t.print(false);
System.out.println("app: TargetClass.main(..) - TargetClass.~print(false)");
System.out.println("app: TargetClass.main(..) - TargetClass.print(true)");
System.out.println("app: TargetClass.main(..) - .print(true)");
t.print(true);
System.out.println("app: TargetClass.main(..) - TargetClass.~print(true)");
}
}
package ch.usi.dag.disl.test2.suite.after.junit;
import static org.junit.Assert.fail;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -14,23 +16,20 @@ public class AfterTest {
@Test
public void test()
throws Exception {
throws Exception {
// FIXME
fail("FIXME");
// see app TargetClass
r.start();
r.waitFor();
r.assertIsNotRunning();
//r.flushClientOut();
//r.flushClientErr();
// FIXME
//r.assertIsFinished();
r.assertIsFinished();
if(Boolean.parseBoolean(System.getProperty("disl.test.verbose"))) { r.destroyIfRunningAndFlushOutputs(); }
//r.assertIsSuccessfull();
r.assertClientOut("client.out.resource");
// FIXME
//r.assertClientErrNull();
r.assertServerOutNull();
r.assertServerErrNull();
if(Boolean.parseBoolean(System.getProperty("disl.test.verbose"))) {
r.verbose();
}
}
@After
......
app: TargetClass.main(..) - TargetClass.print(false)
app: TargetClass.main(..) - .print(false)
app: TargetClass.print(..) - try:begin
app: TargetClass.print(..) - try:end
app: TargetClass.print(..) - finally
disl: after
app: TargetClass.main(..) - TargetClass.~print(false)
app: TargetClass.main(..) - TargetClass.print(true)
app: TargetClass.main(..) - .print(true)
app: TargetClass.print(..) - try:begin
app: TargetClass.print(..) - finally
disl: after
......
......@@ -17,18 +17,13 @@ public class After2Test {
throws Exception {
r.start();
r.waitFor();
r.assertIsNotRunning();
//r.flushClientOut();
//r.flushClientErr();
r.assertIsFinished();
if(Boolean.parseBoolean(System.getProperty("disl.test.verbose"))) { r.destroyIfRunningAndFlushOutputs(); }
r.assertIsSuccessfull();
r.assertClientOut("client.out.resource");
r.assertClientErrNull();
r.assertServerOutNull();
r.assertServerErrNull();
if(Boolean.parseBoolean(System.getProperty("disl.test.verbose"))) {
r.verbose();
}
}
@After
......
......@@ -17,18 +17,13 @@ public class After3Test {
throws Exception {
r.start();
r.waitFor();
r.assertIsNotRunning();
//r.flushClientOut();
//r.flushClientErr();
r.assertIsFinished();
if(Boolean.parseBoolean(System.getProperty("disl.test.verbose"))) { r.destroyIfRunningAndFlushOutputs(); }
r.assertIsSuccessfull();
r.assertClientOut("client.out.resource");
r.assertClientErrNull();
r.assertServerOutNull();
r.assertServerErrNull();
if(Boolean.parseBoolean(System.getProperty("disl.test.verbose"))) {
r.verbose();
}
}
@After
......
......@@ -17,18 +17,13 @@ public class AfterInitTest {
throws Exception {
r.start();
r.waitFor();
r.assertIsNotRunning();
//r.flushClientOut();
//r.flushClientErr();
r.assertIsFinished();
if(Boolean.parseBoolean(System.getProperty("disl.test.verbose"))) { r.destroyIfRunningAndFlushOutputs(); }
r.assertIsSuccessfull();
r.assertClientOut("client.out.resource");
r.assertClientErrNull();
r.assertServerOutNull();
r.assertServerErrNull();
if(Boolean.parseBoolean(System.getProperty("disl.test.verbose"))) {
r.verbose();
}
}
@After
......
package ch.usi.dag.disl.test2.suite.args.app;
public class TargetClass {
public void test_int(int i) {
System.out.println("app: TargetClass.test_int");
}
public void test_Integer(Integer i) {
System.out.println("app: TargetClass.test_Integer");
}
public void test_float(float f) {
System.out.println("app: TargetClass.test_float");
}
public void test_Float(Float f) {
System.out.println("app: TargetClass.test_Float");
}
public void test_double(double d) {
System.out.println("app: TargetClass.test_double");
}
public void test_Double(Double d) {
System.out.println("app: TargetClass.test_Double");
}
public void test_String(String s) {
System.out.println("app: TargetClass.test_String");
}
public void test_Object(Object o) {
System.out.println("app: TargetClass.test_Object");
}
public void test_ObjectArray(Object[] oa) {
System.out.println("app: TargetClass.test_ObjectArray");
}
public void test_MultipleObjectArray(Object[] oa1, Object[] oa2) {
System.out.println("app: TargetClass.test_MultipleObjectArray");
}
public void test_VariableObjectArray(Object[]... oas) {
System.out.println("app: TargetClass.test_VaribleObjectArray");
}
public static void main(String[] args) {
System.out.println("app: TargetClass.main - begin");
TargetClass t = new TargetClass();
t.test_int(42);
t.test_Integer(new Integer(42));
t.test_float(42.42f);
t.test_Float(new Float(42.42f));
t.test_double(42.42);
t.test_Double(new Double(42.42));
t.test_String("my test string");
t.test_Object("my test object string");
t.test_ObjectArray(new Object[] {"str1", "str2", "str3"});
t.test_MultipleObjectArray(new Object[] {"1str1", "1str2", "1str3"}, new Object[] {"2str1", "2str2", "2str3"});
t.test_VariableObjectArray(new Object[] {"1str1", "1str2", "1str3"}, new Object[] {"2str1", "2str2", "2str3"});
/*t.method1();
t.method2(1, 2, 3);
t.method3("object", "string");
t.method3("object2", "string2");
t.method3(t, "THIS IS THE REF TO THIS");
t.method3(1, 2, "object");
t.method4(new String[] { "hello" }, new int[] { 1, 2, 3, 4, 5 });
TargetClass.isValidChar('c');*/
System.out.println("app: TargetClass.main - end");
}
}
package ch.usi.dag.disl.test2.suite.args.instr;
import ch.usi.dag.disl.annotation.AfterReturning;
import ch.usi.dag.disl.marker.BodyMarker;
import ch.usi.dag.disl.processorcontext.ArgumentProcessorContext;
import ch.usi.dag.disl.processorcontext.ArgumentProcessorMode;
import ch.usi.dag.disl.staticcontext.MethodStaticContext;
public class DiSLClass {
@AfterReturning(marker = BodyMarker.class, scope = "TargetClass.*")
public static void postcondition(MethodStaticContext sc, ArgumentProcessorContext pc) {
System.out.printf("disl: args for %s %s\n", sc.thisMethodFullName(), sc.thisMethodDescriptor());
Object[] args = pc.getArgs(ArgumentProcessorMode.METHOD_ARGS);
for(int i = 0 ; i < args.length; ++i) {
System.out.printf("disl: \targ[%d]\n", i);
if (args[i] instanceof Object[]) {
Object[] argsarr = (Object[])args[i];
for (Object arg : argsarr) {
if (arg instanceof Object[]) {
Object[] argsarr2 = (Object[])arg;
for (Object arg2 : argsarr2) {
Object a = (Object)arg2;
String n = a.getClass().getCanonicalName();
switch (n) {
case "java.lang.Integer":
System.out.printf("disl: \t\t\t\t%s\n", n);
System.out.printf("disl: \t\t\t\t%s\n", a.toString());
break;
case "java.lang.Float":
System.out.printf("disl: \t\t\t\t%s\n", n);
System.out.printf("disl: \t\t\t\t%s\n", a.toString());
break;
case "java.lang.Double":
System.out.printf("disl: \t\t\t\t%s\n", n);
System.out.printf("disl: \t\t\t\t%s\n", a.toString());
break;
case "java.lang.String":
System.out.printf("disl: \t\t\t\t%s\n", n);
System.out.printf("disl: \t\t\t\t%s\n", a.toString());
break;
default:
System.out.printf("disl: \t\t\t\t%s\n", n);
System.out.printf("disl: \t\t\t\t== cannot print ==\n");
break;
}
}
} else {
Object a = (Object)arg;
String n = a.getClass().getCanonicalName();
switch (n) {
case "java.lang.Integer":
System.out.printf("disl: \t\t\t%s\n", n);
System.out.printf("disl: \t\t\t%s\n", a.toString());
break;
case "java.lang.Float":
System.out.printf("disl: \t\t\t%s\n", n);
System.out.printf("disl: \t\t\t%s\n", a.toString());
break;
case "java.lang.Double":
System.out.printf("disl: \t\t\t%s\n", n);
System.out.printf("disl: \t\t\t%s\n", a.toString());
break;
case "java.lang.String":
System.out.printf("disl: \t\t\t%s\n", n);
System.out.printf("disl: \t\t\t%s\n", a.toString());
break;
default:
System.out.printf("disl: \t\t\t%s\n", n);
System.out.printf("disl: \t\t\t== cannot print ==\n");
break;
}
}
}