Skip to content

Commit 8666279

Browse files
committed
add testing for all platforms + cleanup
1 parent 8cb3b62 commit 8666279

File tree

2 files changed

+57
-54
lines changed

2 files changed

+57
-54
lines changed

obfuscator/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ test {
6464
if (System.getenv("CI"))
6565
System.out.print("\u001b[1;33m");
6666
testOutputs.put(descriptor.getName(), new StringBuilder());
67-
System.out.print("Running test \"" + descriptor.getName() + "\" -> ");
67+
System.out.print("Running test \"" + descriptor.getDisplayName() + "\" -> ");
6868
System.out.flush();
6969
}
7070

obfuscator/src/test/java/by/radioegor146/ClassicTest.java

Lines changed: 56 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,10 @@ public void execute() throws Throwable {
5050

5151
Path tempSource = temp.resolve("source");
5252
Path tempClasses = temp.resolve("classes");
53-
Path tempOutput = temp.resolve("output");
54-
Path tempCpp = tempOutput.resolve("cpp");
5553
Files.createDirectories(tempSource);
5654
Files.createDirectories(tempClasses);
57-
Files.createDirectories(tempOutput);
58-
Files.createDirectories(tempCpp);
5955

6056
Path idealJar = temp.resolve("test.jar");
61-
Path resultJar = tempOutput.resolve("test.jar");
6257

6358
List<Path> javaFiles = new ArrayList<>();
6459
List<Path> resourceFiles = new ArrayList<>();
@@ -111,66 +106,74 @@ public void execute() throws Throwable {
111106
System.out.println(String.format("Took %dms", idealRunResult.execTime));
112107
idealRunResult.check("Ideal run");
113108

114-
System.out.println("Processing...");
109+
for (Platform platform : Platform.values()) {
110+
System.out.println(String.format("Processing platform %s...", platform.toString()));
115111

116-
new NativeObfuscator().process(idealJar, tempOutput, Collections.emptyList(), Collections.emptyList(),
117-
null, "native_library", Platform.HOTSPOT, false);
112+
Path tempOutput = temp.resolve(String.format("output_%s", platform));
113+
Path tempCpp = tempOutput.resolve("cpp");
114+
Files.createDirectories(tempOutput);
115+
Files.createDirectories(tempCpp);
116+
Path resultJar = tempOutput.resolve("test.jar");
118117

119-
System.out.println("Compiling CPP code...");
120-
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
121-
String arch = "x64";
122-
if (System.getProperty("sun.arch.data.model").equals("32")) {
123-
arch = "x86";
118+
new NativeObfuscator().process(idealJar, tempOutput, Collections.emptyList(), Collections.emptyList(),
119+
null, "native_library", platform, false);
120+
121+
System.out.println("Compiling CPP code...");
122+
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
123+
String arch = "x64";
124+
if (System.getProperty("sun.arch.data.model").equals("32")) {
125+
arch = "x86";
126+
}
127+
ProcessHelper.run(tempCpp, 60_000,
128+
Arrays.asList("cmake", "-DCMAKE_GENERATOR_PLATFORM=" + arch, "."))
129+
.check("CMake prepare");
130+
} else {
131+
ProcessHelper.run(tempCpp, 60_000,
132+
Arrays.asList("cmake", "."))
133+
.check("CMake prepare");
124134
}
125-
ProcessHelper.run(tempCpp, 60_000,
126-
Arrays.asList("cmake", "-DCMAKE_GENERATOR_PLATFORM=" + arch, "."))
127-
.check("CMake prepare");
128-
} else {
129-
ProcessHelper.run(tempCpp, 60_000,
130-
Arrays.asList("cmake", "."))
131-
.check("CMake prepare");
132-
}
133135

134-
ProcessResult compileRunresult = ProcessHelper.run(tempCpp, 160_000,
135-
Arrays.asList("cmake", "--build", ".", "--config", "Release"));
136-
System.out.println(String.format("Took %dms", compileRunresult.execTime));
137-
compileRunresult.check("CMake build");
138-
139-
140-
Files.find(tempCpp.resolve("build").resolve("lib"), 1, (path, args) -> Files.isRegularFile(path))
141-
.forEach(unchecked(p -> Files.copy(p, tempOutput.resolve(p.getFileName()))));
142-
143-
System.out.println("Running test...");
144-
145-
long timeout = 200_000;
146-
ProcessResult testRunResult = ProcessHelper.run(tempOutput, timeout,
147-
Arrays.asList("java",
148-
"-Djava.library.path=.",
149-
"-Dseed=1337",
150-
"-Dtest.src=" + temp.toString(),
151-
"-jar", resultJar.toString()));
152-
System.out.println(String.format("Took %dms", testRunResult.execTime));
153-
testRunResult.check("Test run");
154-
155-
if (!testRunResult.stdout.equals(idealRunResult.stdout)) {
156-
// Some tests are random based
157-
Pattern testResult = Pattern.compile("^Passed = \\d+,? failed = (\\d+)$", Pattern.MULTILINE);
158-
Matcher matcher = testResult.matcher(testRunResult.stdout);
159-
if(matcher.find()) {
160-
if(!matcher.group(1).equals("0")) {
136+
ProcessResult compileRunresult = ProcessHelper.run(tempCpp, 160_000,
137+
Arrays.asList("cmake", "--build", ".", "--config", "Release"));
138+
System.out.println(String.format("Took %dms", compileRunresult.execTime));
139+
compileRunresult.check("CMake build");
140+
141+
142+
Files.find(tempCpp.resolve("build").resolve("lib"), 1, (path, args) -> Files.isRegularFile(path))
143+
.forEach(unchecked(p -> Files.copy(p, tempOutput.resolve(p.getFileName()))));
144+
145+
System.out.println("Running test...");
146+
147+
long timeout = 200_000;
148+
ProcessResult testRunResult = ProcessHelper.run(tempOutput, timeout,
149+
Arrays.asList("java",
150+
"-Djava.library.path=.",
151+
"-Dseed=1337",
152+
"-Dtest.src=" + temp.toString(),
153+
"-jar", resultJar.toString()));
154+
System.out.println(String.format("Took %dms", testRunResult.execTime));
155+
testRunResult.check("Test run");
156+
157+
if (!testRunResult.stdout.equals(idealRunResult.stdout)) {
158+
// Some tests are random based
159+
Pattern testResult = Pattern.compile("^Passed = \\d+,? failed = (\\d+)$", Pattern.MULTILINE);
160+
Matcher matcher = testResult.matcher(testRunResult.stdout);
161+
if(matcher.find()) {
162+
if(!matcher.group(1).equals("0")) {
163+
fail(testRunResult, idealRunResult);
164+
}
165+
} else {
161166
fail(testRunResult, idealRunResult);
162167
}
163-
} else {
164-
fail(testRunResult, idealRunResult);
165168
}
166-
}
167169

168-
System.out.println("OK");
170+
System.out.println("OK");
171+
}
169172
} catch (IOException | RuntimeException e) {
170173
e.printStackTrace(System.err);
171174
throw e;
172175
} finally {
173-
// clean();
176+
clean();
174177
}
175178
}
176179

0 commit comments

Comments
 (0)