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

TestCast testing tool update (java version)

parent 605fbbae
Loading
Loading
Loading
Loading
+8 −2
Original line number Original line Diff line number Diff line
@@ -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) {
	public static T3ExpectedOutput extractExpectedOutput(File f) {
		T3ExpectedOutput t3ExpectedOutput = new T3ExpectedOutput();
		T3ExpectedOutput t3ExpectedOutput = new T3ExpectedOutput();
		
		
@@ -95,9 +98,10 @@ public class FileUtils {
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			BufferedReader br = new BufferedReader(new InputStreamReader(in));


			String strLine = "";
			String strLine = "";
			Matcher configMatch; 
			while ((strLine = br.readLine()) != null) {
			while ((strLine = br.readLine()) != null) {
				if (strLine.matches("^\\s*\\*\\*\\s*@verdict\\s*.*")) {
				if (s_verdictMatch.matcher(strLine).matches()) {
					Matcher matcher = Pattern.compile("^^\\s*\\*\\*\\s*@verdict\\s*pass\\s*(.*)").matcher(strLine);
					Matcher matcher = s_verdictPassMatch.matcher(strLine);
					if (matcher.find()) {
					if (matcher.find()) {
						String result = matcher.group(1);
						String result = matcher.group(1);
						String[] split = result.split(",");
						String[] split = result.split(",");
@@ -107,6 +111,8 @@ public class FileUtils {
					}
					}
					
					
//					System.out.println(strLine);
//					System.out.println(strLine);
				} else if ((configMatch = s_configMatch.matcher(strLine)).matches()) {
					t3ExpectedOutput.setConfiguration(configMatch.group(1));
				}
				}
			}
			}
			in.close();
			in.close();
+14 −1
Original line number Original line Diff line number Diff line
public class T3ExpectedOutput {
public class T3ExpectedOutput {
	private String expectedOutput;
	private String expectedOutput = "";
	private String executionResult;
	private String executionResult;
	private String m_configuration;


	public String getExpectedOutput() {
	public String getExpectedOutput() {
		return expectedOutput;
		return expectedOutput;
@@ -18,10 +19,22 @@ public class T3ExpectedOutput {
		this.executionResult = executionResult;
		this.executionResult = executionResult;
	}
	}


	public void setConfiguration(String config) {
		m_configuration = config;
	}

	public String getConfiguration() {
		return m_configuration;
	}

	@Override
	@Override
	public String toString() {
	public String toString() {
		return "T3ExpectedOutput [expectedOutput=" + expectedOutput
		return "T3ExpectedOutput [expectedOutput=" + expectedOutput
				+ ", executionResult=" + executionResult + "]";
				+ ", executionResult=" + executionResult + "]";
	}
	}


	public boolean isConfiguration(String config) {
		return m_configuration != null && m_configuration.equals(config);
	}

}
}
+46 −26
Original line number Original line Diff line number Diff line
@@ -7,6 +7,7 @@ import java.io.PrintWriter;
public class TestCastProjectBuilder {
public class TestCastProjectBuilder {
	private String files = "";
	private String files = "";
	private String sut = "";
	private String sut = "";
	private String enc = "";
	
	
	private String template1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + 
	private String template1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + 
	"<solution>\n" + 
	"<solution>\n" + 
@@ -19,7 +20,7 @@ public class TestCastProjectBuilder {
		" <verstool />\n"; 
		" <verstool />\n"; 


	private String template3 = 
	private String template3 = 
	" <codec_rules>CodecRules_Project3.txt</codec_rules>\n" + 
	" <codec_rules>CodecRules1.txt</codec_rules>\n" + 
	" <ExternalAttributeFiles>\n" + 
	" <ExternalAttributeFiles>\n" + 
	"  <items />\n" + 
	"  <items />\n" + 
	" </ExternalAttributeFiles>\n" + 
	" </ExternalAttributeFiles>\n" + 
@@ -34,15 +35,49 @@ public class TestCastProjectBuilder {
	" </TestCampaigns>\n" + 
	" </TestCampaigns>\n" + 
	" <ttcn3_settings>\n" + 
	" <ttcn3_settings>\n" + 
	"  <tc_block />\n" + 
	"  <tc_block />\n" + 
	"  <ttcn3_version>Ttcn3_2010</ttcn3_version>\n" + 
	"  <ttcn3_version>Ttcn3_2016</ttcn3_version>\n" + 
	"  <asn>BER</asn>\n" + 
	"  <asn>BER</asn>\n" + 
	"  <dll_timeout>10</dll_timeout>\n" + 
	"  <dll_timeout>10</dll_timeout>\n" + 
	"  <port>7777</port>\n" + 
	"  <port>7777</port>\n" + 
	"  <ctime>60</ctime>\n" + 
	"  <ctime>60</ctime>\n" + 
	"  <sa_count>1</sa_count>\n" + 
	"  <sa_count>1</sa_count>\n" + 
	"  <rtime>20</rtime>\n" + 
	"  <rtime>20</rtime>\n" + 
	"  <codec_type>internal</codec_type>\n" + 
	"  <codec_type>internal</codec_type>\n";
	"  <enc>\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>";

	public void addFile(String filename) {
		File f = new File(filename);
		files += "   <script>\n";
		files += "    <name>" + f.getName().substring(0, f.getName().indexOf(".ttcn")) + "</name>\n";
		files += "    <file>" + filename + "</file>\n"; 
		files += "    <type>ttcn3</type>\n"; 
		files += "   </script>\n"; 
	}

	public void setSUT(String sutFile) {
		sut = " <sut>\n";
		sut += "  <exe>" + sutFile + "</exe>\n";
		sut += " </sut>\n";
	}
	
	public void setEncoding(boolean bTciXml) {
		enc =   "  <enc>\n"; 
		if (bTciXml) {
			enc += "   <tci_xml />\n";					
		} else {
			enc +=
				"   <plain>\n" + 
				"   <plain>\n" + 
				"    <byte_order>le</byte_order>\n" + 
				"    <byte_order>le</byte_order>\n" + 
				"    <signed />\n" + 
				"    <signed />\n" + 
@@ -62,28 +97,13 @@ public class TestCastProjectBuilder {
				"    <str_end>\\r\\n</str_end>\n" + 
				"    <str_end>\\r\\n</str_end>\n" + 
				"    <uni_end>\\r\\n</uni_end>\n" + 
				"    <uni_end>\\r\\n</uni_end>\n" + 
				"    <any>none</any>\n" + 
				"    <any>none</any>\n" + 
	"   </plain>\n" + 
				"   </plain>\n";
	"  </enc>\n" + 
	" </ttcn3_settings>\n" + 
	"</solution>";

	public void addFile(String filename) {
		File f = new File(filename);
		files += "   <script>\n";
		files += "    <name>" + f.getName().substring(0, f.getName().indexOf(".ttcn")) + "</name>\n";
		files += "    <file>" + filename + "</file>\n"; 
		files += "    <type>ttcn3</type>\n"; 
		files += "   </script>\n"; 
		}
		}

		enc += "  </enc>\n"; 
	public void setSUT(String sutFile) {
		sut = " <sut>\n";
		sut += "  <exe>" + sutFile + "</exe>\n";
		sut += " </sut>\n";
	}
	}
	
	
	public String getProjectFileString() {
	public String getProjectFileString() {
		return template1 + files + template2 + sut + template3;
		return template1 + files + template2 + sut + template3 + enc + template4;
	}
	}
	
	
	public void saveProjectFile(File f) {
	public void saveProjectFile(File f) {
+16 −11
Original line number Original line Diff line number Diff line
@@ -20,7 +20,7 @@ public class TestCastRunner {
		pass, inconc, fail, error, none
		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) {
	public TestCastRunner(File projectFile, String scriptName, Logger logger, int testNumber) {
		this.projectFile = projectFile;
		this.projectFile = projectFile;
@@ -29,7 +29,7 @@ public class TestCastRunner {
		this.testNumber = testNumber;
		this.testNumber = testNumber;
	}
	}


	public void run() {
	public void run(boolean bExecute) {
		List<String> args = new ArrayList<String>();
		List<String> args = new ArrayList<String>();
		File tempDir = new File(TestCastTester.config.get("TempPath")
		File tempDir = new File(TestCastTester.config.get("TempPath")
				.toString());
				.toString());
@@ -41,7 +41,12 @@ public class TestCastRunner {
		args.add(projectFile.getAbsolutePath());
		args.add(projectFile.getAbsolutePath());
		args.add("-s");
		args.add("-s");
		args.add(scriptName);
		args.add(scriptName);
		if (bExecute) {
			args.add("-rb");
			args.add("-r");
			args.add("-r");
			args.add("-log");
			args.add("log");
		}
		ProcessBuilder processBuilder = new ProcessBuilder(args);
		ProcessBuilder processBuilder = new ProcessBuilder(args);
		processBuilder.redirectErrorStream(true);
		processBuilder.redirectErrorStream(true);
		try {
		try {
@@ -54,7 +59,7 @@ public class TestCastRunner {
			while ((line = br.readLine()) != null) {
			while ((line = br.readLine()) != null) {
				cmdLineOutputAll.append("    --->" + line);
				cmdLineOutputAll.append("    --->" + line);
				cmdLineOutputAll.append("\n");
				cmdLineOutputAll.append("\n");
				
				// System.out.println(line);
				if (line.matches("^\\[ERR\\].*")) {
				if (line.matches("^\\[ERR\\].*")) {
					cmdLineOutputErrors.append("    --->" + line + "\n");
					cmdLineOutputErrors.append("    --->" + line + "\n");
					accepted = false;
					accepted = false;
@@ -114,9 +119,9 @@ public class TestCastRunner {
				logger.writeAll(cmdLineOutputAll.toString());
				logger.writeAll(cmdLineOutputAll.toString());
				logger.writeCritical(cmdLineOutputAll.toString());
				logger.writeCritical(cmdLineOutputAll.toString());
			} else {
			} else {
				logger.writeScreen(testNumber + ": [inconc] " + scriptName + " - cannot interprete expected output!");		
				logger.writeScreen(testNumber + ": [inconc] " + scriptName + " - cannot interpret expected output!");		
				logger.writeAll(testNumber + ": [inconc] " + scriptName + " - cannot interprete expected output!\n");		
				logger.writeAll(testNumber + ": [inconc] " + scriptName + " - cannot interpret expected output!\n");		
				logger.writeCritical(testNumber + ": [oncinc] " + scriptName + " - cannot interprete expected output!\n");		
				logger.writeCritical(testNumber + ": [inconc] " + scriptName + " - cannot interpret expected output!\n");
			}
			}
		} else { // testcast accepts the input
		} else { // testcast accepts the input
			if (expectedOutput.getExpectedOutput().contains("accept")) {
			if (expectedOutput.getExpectedOutput().contains("accept")) {
@@ -157,9 +162,9 @@ public class TestCastRunner {
				logger.writeAll(cmdLineOutputAll.toString());
				logger.writeAll(cmdLineOutputAll.toString());
				logger.writeCritical(cmdLineOutputAll.toString());
				logger.writeCritical(cmdLineOutputAll.toString());
			} else {
			} else {
				logger.writeScreen(testNumber + ": [inconc] " + scriptName + " - cannot interprete expected output!");		
				logger.writeScreen(testNumber + ": [inconc] " + scriptName + " - cannot interpret expected output!");		
				logger.writeAll(testNumber + ": [inconc] " + scriptName + " - cannot interprete expected output!\n");		
				logger.writeAll(testNumber + ": [inconc] " + scriptName + " - cannot interpret expected output!\n");		
				logger.writeCritical(testNumber + ": [oncinc] " + scriptName + " - cannot interprete expected output!\n");		
				logger.writeCritical(testNumber + ": [inconc] " + scriptName + " - cannot interpret expected output!\n");
			}
			}
		}
		}
	}
	}
+41 −7
Original line number Original line Diff line number Diff line
import java.io.File;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Properties;
import java.util.Properties;


@@ -18,7 +20,7 @@ public class TestCastTester {
	// -----------------------------------------------------------------------------------------------
	// -----------------------------------------------------------------------------------------------


	public void run() {
	public void run() {
		System.out.println("STF409 TestCast Tester v0.1");
		System.out.println("STF521 TestCast Tester v1.0");
		try {
		try {
			FileUtils.loadConfig(config);
			FileUtils.loadConfig(config);
		} catch (IOException e) {
		} catch (IOException e) {
@@ -38,11 +40,27 @@ public class TestCastTester {
		File criticalLogFile = new File(config.get("LogPath") + "/critical.log");
		File criticalLogFile = new File(config.get("LogPath") + "/critical.log");
		Logger logger = new Logger(allLogFile, criticalLogFile);
		Logger logger = new Logger(allLogFile, criticalLogFile);
		logger.init();
		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++) {
		for (int i=0; i < files.size(); i++) {
			if (startIteration > i)
			if (startIteration > i)
				continue;
				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())) {
			if (inExclusionList(files.get(i).getName())) {
				System.out.println("**exclusion list match. skipping " + files.get(i).getName());
				System.out.println("**exclusion list match. skipping " + files.get(i).getName());
@@ -70,16 +88,29 @@ public class TestCastTester {
						
						
			T3ExpectedOutput expectedOutput = FileUtils.extractExpectedOutput(filesToProcess.get(0));
			T3ExpectedOutput expectedOutput = FileUtils.extractExpectedOutput(filesToProcess.get(0));


			
			TestCastProjectBuilder builder = new TestCastProjectBuilder();
			TestCastProjectBuilder builder = new TestCastProjectBuilder();
			for (int j=0; j < filesToProcess.size(); j++) {
			for (int j=0; j < filesToProcess.size(); j++) {
				builder.addFile(filesToProcess.get(j).getAbsolutePath());
				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");
			builder.saveProjectFile(projectFile);
			
			
			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);
			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);
			runner.evaluateResults(expectedOutput);
						
						
			// cleanup
			// cleanup
@@ -100,6 +131,9 @@ public class TestCastTester {
				if (!success)
				if (!success)
					System.err.println("[ERROR] Could not delete file " + tempFile.getAbsolutePath());
					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.");
		System.out.println("done.");
		logger.finish();
		logger.finish();