blob: 7fa565753dc253b02b0c4c3c1a0addddd3d9d40d (
plain)
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
|
package org.shedlang.compiler.backends.llvm;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;
import org.shedlang.compiler.ShedCompiler;
import org.shedlang.compiler.backends.ExampleSet;
import org.shedlang.compiler.testing.TestProcessRunner;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
public class Amd64ValgrindExampleTests {
@TestFactory
public Stream<DynamicTest> tests() {
return ExampleSet.exampleSets()
.map(exampleSet -> DynamicTest.dynamicTest(
exampleSet.name(),
() -> runTest(exampleSet)
));
}
private void runTest(ExampleSet exampleSet) throws IOException, InterruptedException {
var config = exampleSet.readConfig();
for (var example : config.examples()) {
if (example.expectedError().isEmpty()) {
var compiler = new ShedCompiler();
var targetDir = compiler.compile(
example.projectPath(),
LlvmBackend.AMD64,
Optional.empty()
);
var binPath = targetDir.topLevel(example.bin())
.toString();
var leakExitCode = 127;
var result = TestProcessRunner.runCaptureOutput(List.of(
"valgrind",
"--leak-check=full",
"--error-exitcode=" + leakExitCode,
binPath
));
if (result.exitCode() == leakExitCode) {
Assumptions.abort("Example had leaks:\n" + result.stderr());
}
}
}
}
}
|