Commit 489eccda authored by urbant's avatar urbant
Browse files

TestCast testing tool update (java version)

parent 605fbbae
......@@ -86,6 +86,9 @@ public class FileUtils {
// -----------------------------------------------------------------------------------------------
private static Pattern s_verdictPassMatch = Pattern.compile("^^\\s*\\*\\*\\s*@verdict\\s*pass\\s*(.*)");
private static Pattern s_verdictMatch = Pattern.compile("^\\s*\\*\\*\\s*@verdict\\s*.*");
private static Pattern s_configMatch = Pattern.compile("^\\s*\\*\\*\\s*@configuration\\s*(.*)");
public static T3ExpectedOutput extractExpectedOutput(File f) {
T3ExpectedOutput t3ExpectedOutput = new T3ExpectedOutput();
......@@ -95,9 +98,10 @@ public class FileUtils {
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine = "";
Matcher configMatch;
while ((strLine = br.readLine()) != null) {
if (strLine.matches("^\\s*\\*\\*\\s*@verdict\\s*.*")) {
Matcher matcher = Pattern.compile("^^\\s*\\*\\*\\s*@verdict\\s*pass\\s*(.*)").matcher(strLine);
if (s_verdictMatch.matcher(strLine).matches()) {
Matcher matcher = s_verdictPassMatch.matcher(strLine);
if (matcher.find()) {
String result = matcher.group(1);
String[] split = result.split(",");
......@@ -107,6 +111,8 @@ public class FileUtils {
}
// System.out.println(strLine);
} else if ((configMatch = s_configMatch.matcher(strLine)).matches()) {
t3ExpectedOutput.setConfiguration(configMatch.group(1));
}
}
in.close();
......
public class T3ExpectedOutput {
private String expectedOutput;
private String expectedOutput = "";
private String executionResult;
private String m_configuration;
public String getExpectedOutput() {
return expectedOutput;
......@@ -18,10 +19,22 @@ public class T3ExpectedOutput {
this.executionResult = executionResult;
}
public void setConfiguration(String config) {
m_configuration = config;
}
public String getConfiguration() {
return m_configuration;
}
@Override
public String toString() {
return "T3ExpectedOutput [expectedOutput=" + expectedOutput
+ ", executionResult=" + executionResult + "]";
}
public boolean isConfiguration(String config) {
return m_configuration != null && m_configuration.equals(config);
}
}
......@@ -7,6 +7,7 @@ import java.io.PrintWriter;
public class TestCastProjectBuilder {
private String files = "";
private String sut = "";
private String enc = "";
private String template1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<solution>\n" +
......@@ -19,7 +20,7 @@ public class TestCastProjectBuilder {
" <verstool />\n";
private String template3 =
" <codec_rules>CodecRules_Project3.txt</codec_rules>\n" +
" <codec_rules>CodecRules1.txt</codec_rules>\n" +
" <ExternalAttributeFiles>\n" +
" <items />\n" +
" </ExternalAttributeFiles>\n" +
......@@ -34,36 +35,25 @@ public class TestCastProjectBuilder {
" </TestCampaigns>\n" +
" <ttcn3_settings>\n" +
" <tc_block />\n" +
" <ttcn3_version>Ttcn3_2010</ttcn3_version>\n" +
" <ttcn3_version>Ttcn3_2016</ttcn3_version>\n" +
" <asn>BER</asn>\n" +
" <dll_timeout>10</dll_timeout>\n" +
" <port>7777</port>\n" +
" <ctime>60</ctime>\n" +
" <sa_count>1</sa_count>\n" +
" <rtime>20</rtime>\n" +
" <codec_type>internal</codec_type>\n" +
" <enc>\n" +
" <plain>\n" +
" <byte_order>le</byte_order>\n" +
" <signed />\n" +
" <int>dword</int>\n" +
" <float>double</float>\n" +
" <custom_int>8</custom_int>\n" +
" <string>null</string>\n" +
" <custom_str>32</custom_str>\n" +
" <char>U16</char>\n" +
" <bool>dword</bool>\n" +
" <bin>dword</bin>\n" +
" <custom_bin>16</custom_bin>\n" +
" <align>1</align>\n" +
" <coll>word</coll>\n" +
" <str_unit>bytes</str_unit>\n" +
" <pad />\n" +
" <str_end>\\r\\n</str_end>\n" +
" <uni_end>\\r\\n</uni_end>\n" +
" <any>none</any>\n" +
" </plain>\n" +
" </enc>\n" +
" <codec_type>internal</codec_type>\n";
private String template4 =
" <no_bs_dq />\n" +
" <length-form>definite</length-form>\n" +
" <forbidden_ctrl_warn />\n" +
" <omit-match-err />\n" +
" <log-tmpt-names />\n" +
" <strict-def-check />\n" +
" <default-step>0.1</default-step>\n" +
" <strict-ver-check />\n" +
" <dll_ctimeout>10</dll_ctimeout>\n" +
" </ttcn3_settings>\n" +
"</solution>";
......@@ -82,8 +72,38 @@ public class TestCastProjectBuilder {
sut += " </sut>\n";
}
public void setEncoding(boolean bTciXml) {
enc = " <enc>\n";
if (bTciXml) {
enc += " <tci_xml />\n";
} else {
enc +=
" <plain>\n" +
" <byte_order>le</byte_order>\n" +
" <signed />\n" +
" <int>dword</int>\n" +
" <float>double</float>\n" +
" <custom_int>8</custom_int>\n" +
" <string>null</string>\n" +
" <custom_str>32</custom_str>\n" +
" <char>U16</char>\n" +
" <bool>dword</bool>\n" +
" <bin>dword</bin>\n" +
" <custom_bin>16</custom_bin>\n" +
" <align>1</align>\n" +
" <coll>word</coll>\n" +
" <str_unit>bytes</str_unit>\n" +
" <pad />\n" +
" <str_end>\\r\\n</str_end>\n" +
" <uni_end>\\r\\n</uni_end>\n" +
" <any>none</any>\n" +
" </plain>\n";
}
enc += " </enc>\n";
}
public String getProjectFileString() {
return template1 + files + template2 + sut + template3;
return template1 + files + template2 + sut + template3 + enc + template4;
}
public void saveProjectFile(File f) {
......
......@@ -20,7 +20,7 @@ public class TestCastRunner {
pass, inconc, fail, error, none
}
private verdictEnum testVerdict = verdictEnum.pass;
private verdictEnum testVerdict = verdictEnum.none;
public TestCastRunner(File projectFile, String scriptName, Logger logger, int testNumber) {
this.projectFile = projectFile;
......@@ -29,7 +29,7 @@ public class TestCastRunner {
this.testNumber = testNumber;
}
public void run() {
public void run(boolean bExecute) {
List<String> args = new ArrayList<String>();
File tempDir = new File(TestCastTester.config.get("TempPath")
.toString());
......@@ -41,7 +41,12 @@ public class TestCastRunner {
args.add(projectFile.getAbsolutePath());
args.add("-s");
args.add(scriptName);
args.add("-r");
if (bExecute) {
args.add("-rb");
args.add("-r");
args.add("-log");
args.add("log");
}
ProcessBuilder processBuilder = new ProcessBuilder(args);
processBuilder.redirectErrorStream(true);
try {
......@@ -54,7 +59,7 @@ public class TestCastRunner {
while ((line = br.readLine()) != null) {
cmdLineOutputAll.append(" --->" + line);
cmdLineOutputAll.append("\n");
// System.out.println(line);
if (line.matches("^\\[ERR\\].*")) {
cmdLineOutputErrors.append(" --->" + line + "\n");
accepted = false;
......@@ -69,7 +74,7 @@ public class TestCastRunner {
updateVerdict(verdictEnum.fail);
} else if (line.contains("<error>")) {
updateVerdict(verdictEnum.error);
} else if (line.contains("<none>")) {
} else if (line.contains("<none>")) {
updateVerdict(verdictEnum.none);
}
}
......@@ -114,9 +119,9 @@ public class TestCastRunner {
logger.writeAll(cmdLineOutputAll.toString());
logger.writeCritical(cmdLineOutputAll.toString());
} else {
logger.writeScreen(testNumber + ": [inconc] " + scriptName + " - cannot interprete expected output!");
logger.writeAll(testNumber + ": [inconc] " + scriptName + " - cannot interprete expected output!\n");
logger.writeCritical(testNumber + ": [oncinc] " + scriptName + " - cannot interprete expected output!\n");
logger.writeScreen(testNumber + ": [inconc] " + scriptName + " - cannot interpret expected output!");
logger.writeAll(testNumber + ": [inconc] " + scriptName + " - cannot interpret expected output!\n");
logger.writeCritical(testNumber + ": [inconc] " + scriptName + " - cannot interpret expected output!\n");
}
} else { // testcast accepts the input
if (expectedOutput.getExpectedOutput().contains("accept")) {
......@@ -157,9 +162,9 @@ public class TestCastRunner {
logger.writeAll(cmdLineOutputAll.toString());
logger.writeCritical(cmdLineOutputAll.toString());
} else {
logger.writeScreen(testNumber + ": [inconc] " + scriptName + " - cannot interprete expected output!");
logger.writeAll(testNumber + ": [inconc] " + scriptName + " - cannot interprete expected output!\n");
logger.writeCritical(testNumber + ": [oncinc] " + scriptName + " - cannot interprete expected output!\n");
logger.writeScreen(testNumber + ": [inconc] " + scriptName + " - cannot interpret expected output!");
logger.writeAll(testNumber + ": [inconc] " + scriptName + " - cannot interpret expected output!\n");
logger.writeCritical(testNumber + ": [inconc] " + scriptName + " - cannot interpret expected output!\n");
}
}
}
......
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Properties;
......@@ -18,7 +20,7 @@ public class TestCastTester {
// -----------------------------------------------------------------------------------------------
public void run() {
System.out.println("STF409 TestCast Tester v0.1");
System.out.println("STF521 TestCast Tester v1.0");
try {
FileUtils.loadConfig(config);
} catch (IOException e) {
......@@ -38,11 +40,27 @@ public class TestCastTester {
File criticalLogFile = new File(config.get("LogPath") + "/critical.log");
Logger logger = new Logger(allLogFile, criticalLogFile);
logger.init();
String sAdapterPath = "\"" + new File(config.get("LoopbackAdapterPath") + "/loopback/LoopbackSUT_NC.exe").getAbsolutePath() + "\"",
sBroadcastPath = "\"" + new File(config.get("LoopbackAdapterPath") + "/broadcast/InterLoopbackAdapter.exe").getAbsolutePath() + "\"" ,
sExternalFuncPath = "java -jar " + "\"" + new File(config.get("LoopbackAdapterPath") + "/external_functions/external.jar").getAbsolutePath() + "\"",
sProjectPath = config.get("TempPath") + "/testcast.tcproj",
sTempPath = config.get("TempPath") + "/";
System.out.println("Adapter path is: " + sAdapterPath);
File codecRulesFile = new File(sTempPath + "CodecRules1.txt");
PrintWriter out;
try {
out = new PrintWriter(new FileWriter(codecRulesFile));
out.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Number of found tests: " + files.size());
for (int i=0; i < files.size(); i++) {
if (startIteration > i)
continue;
File tempFile = new File(config.get("TempPath") + "/" + files.get(i).getName());
File tempFile = new File(sTempPath + files.get(i).getName());
if (inExclusionList(files.get(i).getName())) {
System.out.println("**exclusion list match. skipping " + files.get(i).getName());
......@@ -67,19 +85,32 @@ public class TestCastTester {
if (filesToProcess.size() <= 0)
continue;
T3ExpectedOutput expectedOutput = FileUtils.extractExpectedOutput(filesToProcess.get(0));
TestCastProjectBuilder builder = new TestCastProjectBuilder();
for (int j=0; j < filesToProcess.size(); j++) {
builder.addFile(filesToProcess.get(j).getAbsolutePath());
}
builder.setSUT(new File(config.get("LoopbackAdapterPath") + "/LoopbackSUT_NC.exe").getAbsolutePath());
File projectFile = new File(config.get("TempPath") + "/testcast.tcproj");
String sSut = sAdapterPath;
boolean bTciXml = true;
if (expectedOutput.isConfiguration("port:broadcast"))
sSut = sBroadcastPath;
else if (expectedOutput.isConfiguration("external_functions")) {
sSut = sExternalFuncPath;
bTciXml = false;
}
builder.setEncoding(bTciXml);
builder.setSUT(sSut);
File projectFile = new File(sProjectPath);
builder.saveProjectFile(projectFile);
TestCastRunner runner = new TestCastRunner(projectFile, filesToProcess.get(0).getName().substring(0, filesToProcess.get(0).getName().indexOf(".ttcn")), logger, i+1);
runner.run();
String sExpRes = expectedOutput.getExecutionResult();
runner.run(sExpRes == null || !sExpRes.contains("noexecution"));
runner.evaluateResults(expectedOutput);
// cleanup
......@@ -100,6 +131,9 @@ public class TestCastTester {
if (!success)
System.err.println("[ERROR] Could not delete file " + tempFile.getAbsolutePath());
}
File userFile = new File(sProjectPath + ".user");
if (userFile.exists())
userFile.delete();
}
System.out.println("done.");
logger.finish();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment