aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-03-09 22:27:20 +0000
committerMichael Williamson <mike@zwobble.org>2025-03-09 22:27:20 +0000
commit76eb6ec8f01f2d806e0056ec2606a2acf9dd1038 (patch)
treef885f3a3113e04babfc75e63a444d1c48df755ac /src/test/java
parent2bd3bd067b0f2f1e6e3b849ab1a7cc2a8357334a (diff)
Add valgrind tests
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/backends/llvm/Amd64ValgrindExampleTests.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/backends/llvm/Amd64ValgrindExampleTests.java b/src/test/java/org/shedlang/compiler/backends/llvm/Amd64ValgrindExampleTests.java
new file mode 100644
index 00000000..7fa56575
--- /dev/null
+++ b/src/test/java/org/shedlang/compiler/backends/llvm/Amd64ValgrindExampleTests.java
@@ -0,0 +1,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());
+ }
+ }
+ }
+ }
+}