From 50856e2b70cf397b222c8cc3bc065f4792c78320 Mon Sep 17 00:00:00 2001 From: Simon Wegendt Date: Mon, 18 Nov 2019 15:25:24 +0100 Subject: [PATCH] add library download --- .../runtime/tests/AbstractRuntimeTest.xtend | 6 +++--- .../mita/program/runtime/tests/MqttTest.xtend | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/bundles/org.eclipse.mita.program.tests/src/org/eclipse/mita/program/runtime/tests/AbstractRuntimeTest.xtend b/bundles/org.eclipse.mita.program.tests/src/org/eclipse/mita/program/runtime/tests/AbstractRuntimeTest.xtend index ef316be1..64c1dbb2 100644 --- a/bundles/org.eclipse.mita.program.tests/src/org/eclipse/mita/program/runtime/tests/AbstractRuntimeTest.xtend +++ b/bundles/org.eclipse.mita.program.tests/src/org/eclipse/mita/program/runtime/tests/AbstractRuntimeTest.xtend @@ -91,15 +91,15 @@ class AbstractRuntimeTest { } def Stream runAtMost(Path pathToExecutable, int timeInSeconds) { - return runAtMost("", pathToExecutable, timeInSeconds); + return runAtMost(pathToExecutable, #[], timeInSeconds); } - def Stream runAtMost(String prefix, Path pathToExecutable, int timeInSeconds) { + def Stream runAtMost(Path pathToExecutable, String[] env, int timeInSeconds) { println("running exe..."); println(pathToExecutable); println(""); val Runtime rt = Runtime.getRuntime(); - val Process pr = rt.exec(pathToExecutable.toString); + val Process pr = rt.exec(pathToExecutable.toString, env); val output = new BufferedReader(new InputStreamReader(pr.inputStream)); pr.waitFor(timeInSeconds, TimeUnit.SECONDS); if(pr.alive) { diff --git a/bundles/org.eclipse.mita.program.tests/src/org/eclipse/mita/program/runtime/tests/MqttTest.xtend b/bundles/org.eclipse.mita.program.tests/src/org/eclipse/mita/program/runtime/tests/MqttTest.xtend index f586b2d2..458dc118 100644 --- a/bundles/org.eclipse.mita.program.tests/src/org/eclipse/mita/program/runtime/tests/MqttTest.xtend +++ b/bundles/org.eclipse.mita.program.tests/src/org/eclipse/mita/program/runtime/tests/MqttTest.xtend @@ -7,6 +7,7 @@ import org.junit.Test import static extension org.eclipse.mita.base.util.BaseUtils.zip; import java.util.stream.Collectors +import java.util.concurrent.TimeUnit class MqttTest extends AbstractRuntimeTest { @Test @@ -38,11 +39,22 @@ class MqttTest extends AbstractRuntimeTest { native unchecked fn exit(status: int16): void header "stdlib.h"; ''').key; + val Runtime rt = Runtime.getRuntime(); + val pahoLibUrl = "https://www.eclipse.org/downloads/download.php?file=/paho/1.4/Eclipse-Paho-MQTT-C-1.3.1-Linux.tar.gz"; + val downloadLocation = "/tmp/paho.tar.gz"; + + val wgetCommand = rt.exec(#["wget", pahoLibUrl, "-O", downloadLocation]); + wgetCommand.waitFor(60, TimeUnit.SECONDS); + + val extractCommand = rt.exec(#["tar", "xvzf", downloadLocation, "-C", projectPath.toString, "--strip-components=1"]); + extractCommand.waitFor(60, TimeUnit.SECONDS); + compileMita(projectPath); compileC(projectPath, "all"); - val mosquitto = runAtMost(Paths.get("mosquitto"), 60); + val mosquitto = rt.exec("mosquitto"); val executable = projectPath.resolve(Paths.get("src-gen", "build", "app")); - val lines = runAtMost("LD_LIBRARY_PATH=" + projectPath.resolve(Paths.get("lib")), executable, 60); + val lines = runAtMost(executable, #["LD_LIBRARY_PATH=" + projectPath.resolve(Paths.get("lib"))], 60); + mosquitto.destroyForcibly; val expectedLines = (0..9).map[it.toString]; lines.collect(Collectors.toList).zip(expectedLines).forEach[ Assert.assertEquals(it.key, it.value)