From 181760b9c184e5a9c6c9487530448d2546da4691 Mon Sep 17 00:00:00 2001 From: kornilova-l Date: Thu, 5 Jul 2018 20:50:24 +0300 Subject: [PATCH] Run tests with valgrind --- Dockerfile | 1 + .../org/scalanative/bindgen/BindgenSpec.scala | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/Dockerfile b/Dockerfile index 5028a2b..bdbb335 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/tests/src/test/scala/org/scalanative/bindgen/BindgenSpec.scala b/tests/src/test/scala/org/scalanative/bindgen/BindgenSpec.scala index fab3e2e..c622117 100644 --- a/tests/src/test/scala/org/scalanative/bindgen/BindgenSpec.scala +++ b/tests/src/test/scala/org/scalanative/bindgen/BindgenSpec.scala @@ -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") { @@ -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", "") @@ -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)) + } } } }