Skip to content

Commit 181760b

Browse files
committed
Run tests with valgrind
1 parent 15ded8a commit 181760b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ RUN set -x \
1313
g++ openjdk-8-jdk-headless sbt cmake make curl git \
1414
zlib1g-dev \
1515
libgc-dev libunwind8-dev libre2-dev \
16+
valgrind \
1617
&& rm -rf /var/lib/apt/lists/*
1718

1819
ARG LLVM_VERSION=6.0

tests/src/test/scala/org/scalanative/bindgen/BindgenSpec.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.scalanative.bindgen
33
import java.io.File
44
import org.scalatest.FunSpec
55
import scala.io.Source
6+
import scala.sys.process.{Process, ProcessLogger}
67

78
class BindgenSpec extends FunSpec {
89
describe("Bindgen") {
@@ -32,6 +33,23 @@ class BindgenSpec extends FunSpec {
3233
def contentOf(file: File) =
3334
Source.fromFile(file).getLines.mkString("\n").trim()
3435

36+
/**
37+
* @return valgrind exit code
38+
*/
39+
def checkMemoryErrors(inputFile: File): Int = {
40+
val cmd = Seq(
41+
"valgrind",
42+
"--leak-check=full",
43+
"--error-exitcode=1",
44+
bindgenPath,
45+
inputFile.getAbsolutePath,
46+
"--name",
47+
"lib",
48+
"--"
49+
)
50+
Process(cmd).run(ProcessLogger(_ => ())).exitValue()
51+
}
52+
3553
for (input <- inputDirectory.listFiles() if input.getName.endsWith(".h")) {
3654
it(s"should generate bindings for ${input.getName}") {
3755
val testName = input.getName.replace(".h", "")
@@ -43,6 +61,10 @@ class BindgenSpec extends FunSpec {
4361
assert(output.exists())
4462
assert(contentOf(output) == contentOf(expected))
4563
}
64+
65+
it(s"should generate bindings for ${input.getName} without memory errors") {
66+
assert(0 == checkMemoryErrors(input))
67+
}
4668
}
4769
}
4870
}

0 commit comments

Comments
 (0)