Skip to content

Commit

Permalink
Run tests with valgrind
Browse files Browse the repository at this point in the history
  • Loading branch information
kornilova203 committed Jul 5, 2018
1 parent 15ded8a commit 181760b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ RUN set -x \
g++ openjdk-8-jdk-headless sbt cmake make curl git \
zlib1g-dev \
libgc-dev libunwind8-dev libre2-dev \
valgrind \
&& rm -rf /var/lib/apt/lists/*

ARG LLVM_VERSION=6.0
Expand Down
22 changes: 22 additions & 0 deletions tests/src/test/scala/org/scalanative/bindgen/BindgenSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.scalanative.bindgen
import java.io.File
import org.scalatest.FunSpec
import scala.io.Source
import scala.sys.process.{Process, ProcessLogger}

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

/**
* @return valgrind exit code
*/
def checkMemoryErrors(inputFile: File): Int = {
val cmd = Seq(
"valgrind",
"--leak-check=full",
"--error-exitcode=1",
bindgenPath,
inputFile.getAbsolutePath,
"--name",
"lib",
"--"
)
Process(cmd).run(ProcessLogger(_ => ())).exitValue()
}

for (input <- inputDirectory.listFiles() if input.getName.endsWith(".h")) {
it(s"should generate bindings for ${input.getName}") {
val testName = input.getName.replace(".h", "")
Expand All @@ -43,6 +61,10 @@ class BindgenSpec extends FunSpec {
assert(output.exists())
assert(contentOf(output) == contentOf(expected))
}

it(s"should generate bindings for ${input.getName} without memory errors") {
assert(0 == checkMemoryErrors(input))
}
}
}
}

0 comments on commit 181760b

Please sign in to comment.