Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Properties;
public class TestCastTester {
public static Properties config = new Properties();
private ArrayList<File> files = new ArrayList<File>();
private int startIteration = 0;
private ArrayList<String> exclusionList;
// -----------------------------------------------------------------------------------------------
public TestCastTester() {
}
// -----------------------------------------------------------------------------------------------
public void run() {
System.out.println("STF409 TestCast Tester v0.1");
try {
FileUtils.loadConfig(config);
} catch (IOException e) {
System.err
.println("[ERROR] Cannot load config file or config file is incomplete.");
return;
}
String atsPath = config.get("ATSPath").toString();
System.out.println("Gathering files...");
FileUtils.visitAllFiles(new File(atsPath), files);
System.out.println("Reading exclusion list...");
exclusionList = FileUtils.readExclusionList(new File("resources/skipList.txt"));
File allLogFile = new File(config.get("LogPath") + "/all.log");
File criticalLogFile = new File(config.get("LogPath") + "/critical.log");
Logger logger = new Logger(allLogFile, criticalLogFile);
logger.init();
for (int i=0; i < files.size(); i++) {
if (startIteration > i)
continue;
File tempFile = new File(config.get("TempPath") + "/" + files.get(i).getName());
if (inExclusionList(files.get(i).getName())) {
System.out.println("**exclusion list match. skipping " + files.get(i).getName());
continue;
}
try {
FileUtils.copyFile(new File(files.get(i).getAbsolutePath()), tempFile);
} catch (IOException e) {
System.err.println("[ERROR] Could not copy file " + files.get(i).getAbsolutePath() + "! Stopping tester...");
return;
}
int moduleCount = FileUtils.countT3Modules(tempFile);
ArrayList<File> filesToProcess = new ArrayList<File>();
if (moduleCount > 1) {
filesToProcess.addAll(FileUtils.splitT3ModuleFiles(tempFile));
} else {
filesToProcess.add(tempFile);
}
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");
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();
runner.evaluateResults(expectedOutput);
// cleanup
if (tempFile.exists()) {
boolean success = tempFile.delete();
if (!success)
System.err.println("[ERROR] Could not delete file " + tempFile.getAbsolutePath());
}
for (int j=0; j < filesToProcess.size(); j++) {
if (filesToProcess.get(j).exists()) {
boolean success = filesToProcess.get(j).delete();
if (!success)
System.err.println("[ERROR] Could not delete file " + tempFile.getAbsolutePath());
}
}
if (projectFile.exists()) {
boolean success = projectFile.delete();
if (!success)
System.err.println("[ERROR] Could not delete file " + tempFile.getAbsolutePath());
}
}
System.out.println("done.");
logger.finish();
}
// -----------------------------------------------------------------------------------------------
private boolean inExclusionList(String filename) {
for (int i=0; i < exclusionList.size(); i++) {
if (filename.contains(exclusionList.get(i)))
return true;
}
return false;
}
// -----------------------------------------------------------------------------------------------
public static void main(String[] args) {
new TestCastTester().run();
}
}