Browse Source

renamed static generator classes to more meaning full names
added test of the native generated code

Kenneth Lausdahl 6 years ago
parent
commit
3f6c0643fb

+ 5 - 4
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/META-INF/MANIFEST.MF

@@ -18,10 +18,11 @@ Require-Bundle: org.junit;bundle-version="4.7.0",
  be.uantwerpen.ansymo.semanticadaptation.testframework;bundle-version="1.0.0"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Export-Package: be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests;x-internal=true
-Import-Package: org.hamcrest.core,
+Import-Package: org.apache.commons.io;version="2.2.0",
+ org.hamcrest.core,
  org.junit;version="4.5.0",
- org.junit.runners.model;version="4.5.0",
  org.junit.runner;version="4.5.0",
- org.junit.runners;version="4.5.0",
  org.junit.runner.manipulation;version="4.5.0",
- org.junit.runner.notification;version="4.5.0"
+ org.junit.runner.notification;version="4.5.0",
+ org.junit.runners;version="4.5.0",
+ org.junit.runners.model;version="4.5.0"

+ 178 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CMakeUtil.java

@@ -0,0 +1,178 @@
+package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.List;
+
+import org.apache.commons.io.IOUtils;
+
+public class CMakeUtil
+{
+	private static String OS = System.getProperty("os.name").toLowerCase();
+
+	private boolean verbose = true;
+
+	public CMakeUtil( boolean verbose)
+	{
+		this.verbose = verbose;
+	}
+
+	
+
+	public static class CMakeGenerateException extends Exception
+	{
+
+		/**
+		 * 
+		 */
+		private static final long serialVersionUID = 1L;
+		public final String errors;
+
+		public CMakeGenerateException(String errors)
+		{
+			super(errors);
+			this.errors = errors;
+		}
+	}
+
+	public boolean generate(File root) throws IOException,
+			InterruptedException, CMakeGenerateException
+	{
+		String cmake = "cmake";
+
+		if (isMac())
+		{
+			cmake = "/usr/local/bin/cmake";
+		}
+
+		ProcessBuilder pb = new ProcessBuilder(cmake,"-DCMAKE_BUILD_TYPE=Debug", ".");
+		pb.directory(root);
+
+		return runProcess(pb, verbose);
+
+	}
+
+	public boolean make(File root, String... goal) throws IOException,
+			InterruptedException, CMakeGenerateException
+	{
+		String make = "make";
+
+		ProcessBuilder pb = new ProcessBuilder(make, "-j3");
+		for (String string : goal)
+		{
+			pb.command().add(string);
+		}
+		pb.directory(root);
+
+		return runProcess(pb, verbose);
+
+	}
+
+	public boolean run(File root, String cmd, boolean verbose)
+			throws IOException, InterruptedException, CMakeGenerateException
+	{
+
+		String name = cmd;
+
+		if (isWindows())
+		{
+			name = name + ".exe";
+		} else
+		{
+			name = "./" + name;
+		}
+
+		ProcessBuilder pb = new ProcessBuilder(name);
+		pb.directory(root);
+
+		return runProcess(pb, verbose);
+
+	}
+
+	public boolean runProcess(ProcessBuilder pb, boolean verbose)
+			throws IOException, InterruptedException, CMakeGenerateException
+	{
+		final Process p = pb.start();
+
+		if (verbose)
+		{
+			Thread outThread = new Thread(new Runnable()
+			{
+
+				@Override
+				public void run()
+				{
+					BufferedReader out = new BufferedReader(new InputStreamReader(p.getInputStream()));
+
+					String tmp = null;
+					try
+					{
+						while ((tmp = out.readLine()) != null)
+						{
+							System.out.println(tmp);
+						}
+					} catch (IOException e)
+					{
+						return;
+					}
+				}
+			});
+
+			outThread.setDaemon(true);
+			outThread.start();
+		}
+
+		p.waitFor();
+		
+		List<String> errors = IOUtils.readLines(p.getErrorStream());
+
+		boolean res = p.exitValue() == 0;
+
+		if (!res)
+		{
+			if (!errors.isEmpty())
+			{
+				StringBuffer sb = new StringBuffer();
+				for (String string : errors)
+				{
+					sb.append(string);
+					sb.append("\n");
+				}
+				throw new CMakeGenerateException(sb.toString());
+			}
+		}
+		return res;
+	}
+
+	public static boolean isMac()
+	{
+
+		return OS.indexOf("mac") >= 0;
+
+	}
+
+	public static boolean isWindows()
+	{
+
+		return OS.indexOf("win") >= 0;
+
+	}
+
+	public static boolean isUnix()
+	{
+
+		return OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0
+				|| OS.indexOf("aix") > 0;
+
+	}
+
+	public boolean isVerbose() {
+		return verbose;
+	}
+
+	public void setVerbose(boolean verbose) {
+		this.verbose = verbose;
+	}
+}

+ 53 - 24
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppBasicTest.xtend

@@ -5,14 +5,20 @@ package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests
 
 import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation.BuildUtilities
 import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation.CppGenerator
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests.CMakeUtil.CMakeGenerateException
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SemanticAdaptation
+import be.uantwerpen.ansymo.semanticadaptation.testframework.CMakeListsGenerator
+import be.uantwerpen.ansymo.semanticadaptation.testframework.FmuMainTestGenerator
 import be.uantwerpen.ansymo.semanticadaptation.tests.AbstractSemanticAdaptationTest
 import be.uantwerpen.ansymo.semanticadaptation.tests.SemanticAdaptationInjectorProvider
 import com.google.inject.Inject
 import java.io.File
+import java.io.FileFilter
 import java.io.FileWriter
 import java.nio.file.Files
+import java.nio.file.Paths
 import java.util.regex.Pattern
+import org.apache.commons.io.FileUtils
 import org.eclipse.emf.ecore.EObject
 import org.eclipse.emf.ecore.resource.ResourceSet
 import org.eclipse.xtext.generator.IGeneratorContext
@@ -21,10 +27,11 @@ import org.eclipse.xtext.testing.InjectWith
 import org.eclipse.xtext.testing.XtextRunner
 import org.eclipse.xtext.testing.util.ParseHelper
 import org.eclipse.xtext.testing.validation.ValidationTestHelper
+import org.junit.Assert
+import org.junit.BeforeClass
+import org.junit.Ignore
 import org.junit.Test
 import org.junit.runner.RunWith
-import be.uantwerpen.ansymo.semanticadaptation.testframework.StaticGenerators
-import org.junit.Ignore
 
 @RunWith(XtextRunner)
 @InjectWith(SemanticAdaptationInjectorProvider)
@@ -34,6 +41,24 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 	@Inject extension ParseHelper<SemanticAdaptation>
 	@Inject extension  ValidationTestHelper
 
+	val static hcfRoot = Paths.get("target", "hcfDummy", "hcf").toFile()
+
+	@BeforeClass
+	def static setupHcf() {
+		if (!CMakeUtil.windows) {
+			FileUtils.write(new File(hcfRoot.parent, "CMakeLists.txt"),
+				CMakeListsGenerator.generateCMakeListsHcfDummy());
+
+			val cmake = new CMakeUtil(true)
+			try {
+				Assert.assertTrue("Expected cmake to parse", cmake.generate(hcfRoot));
+				Assert.assertTrue("Expected no make errors", cmake.make(hcfRoot));
+			} catch (CMakeGenerateException e) {
+				e.printStackTrace
+			}
+		}
+	}
+
 	@Ignore
 	@Test def window_sa_canonical() {
 		__parseNoErrors('test_input/single_folder_spec/window/window_sa_canonical.BASE.sa', 'generated', "powerwindow");
@@ -53,25 +78,25 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 	@Test def loop() {
 		__parseNoErrors('test_input/single_folder_spec/loop/loop_canonical.sa', 'generated', "loop");
 	}
-	
+
 	@Test def rate() {
 		__parseNoErrors('test_input/single_folder_spec/rate/rate.sa', 'generated', "rate");
 	}
-	
+
 	@Test def rate_canonical() {
 		__parseNoErrors('test_input/single_folder_spec/rate/rate_canonical.sa', 'generated', "rate_canonical");
 	}
-	
-	@Test def power(){
-		__parseNoErrors('test_input/single_folder_spec/power/power.BASE.sa', 'generated','power');
+
+	@Test def power() {
+		__parseNoErrors('test_input/single_folder_spec/power/power.BASE.sa', 'generated', 'power');
 	}
-	
-	@Test def rollback_test(){
-		__parseNoErrors('test_input/single_folder_spec/rollback_test/rollback_test.sa', 'generated','rollback_test');
+
+	@Test def rollback_test() {
+		__parseNoErrors('test_input/single_folder_spec/rollback_test/rollback_test.sa', 'generated', 'rollback_test');
 	}
-	
-	@Test def controller_test(){
-		__parseNoErrors('test_input/single_folder_spec/controller/controller.sa', 'generated','controller');
+
+	@Test def controller_test() {
+		__parseNoErrors('test_input/single_folder_spec/controller/controller.sa', 'generated', 'controller');
 	}
 
 	def __parseNoErrorsWithValidation(String directory, String filename) {
@@ -107,7 +132,6 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 			if (correctFileContent.size != testFileContent.size) {
 				System.out.println("Error: Lines are of different length in file: " + filename2);
 			} else {
-				val error = false;
 				for (var i = 0; i < testFileContent.size; i++) {
 					val testLine = testFileContent.get(i);
 					val correctLine = correctFileContent.get(i);
@@ -124,12 +148,9 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 	}
 
 	def __parseNoErrors(String filename, String directory, String projectName) {
-		val saRootDir = new File(directory + File.separatorChar + projectName);
+		val saRootDir = Paths.get("target", directory, projectName).toFile();
 		val srcGenPath = new File(saRootDir, "sources")
 		val resourcesPath = new File(saRootDir, "resources");
-		val saFrameworkPath = new File(saRootDir, "framework")
-
-		System.out.println("Rootdir: " + saRootDir.absolutePath)
 
 		val model = __parse(filename)
 		__assertNoParseErrors(model, filename)
@@ -146,7 +167,6 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 		saRootDir.mkdirs();
 		srcGenPath.mkdirs();
 		resourcesPath.mkdirs();
-		saFrameworkPath.mkdirs();
 
 		for (files : fsa.allFiles.entrySet) {
 			val fName = files.key.substring(14);
@@ -161,7 +181,7 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 			BuildUtilities.writeToFile(fp, files.value.toString);
 		}
 
-		val mainCpp = StaticGenerators.generateMainCppFile(resourcesPath.absolutePath.replace("\\", "\\\\"));
+		val mainCpp = FmuMainTestGenerator.generateMainCppFile(resourcesPath.absolutePath.replace("\\", "\\\\"));
 		BuildUtilities.writeToFile(new File(srcGenPath, "main.cpp"), mainCpp);
 
 		for (rf : cppGen.resourcePaths) {
@@ -171,14 +191,23 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 		}
 
 		BuildUtilities.writeToFile(new File(saRootDir, "CMakeLists.txt"),
-			StaticGenerators.generateCMakeLists(projectName, "framework"));
+			CMakeListsGenerator.generateCMakeLists(projectName));
 
-		val cMakeToolChain = StaticGenerators.generateToolChainCmake();
+		val cMakeToolChain = CMakeListsGenerator.generateToolChainCmake();
 		BuildUtilities.writeToFile(new File(saRootDir, "msys-toolchain.cmake"), cMakeToolChain);
 
-		(new BuildUtilities()).copyNativeLibFiles(saFrameworkPath);
-		System.out.println("Stored framework at: " + saFrameworkPath);
+		if (!CMakeUtil.windows) {
+			val cmake = new CMakeUtil(true)
+			FileUtils.copyDirectory(hcfRoot, new File(saRootDir, "hcf"), new FileFilter() {
+
+				override accept(File pathname) {
+					return !pathname.name.equals("CMakeCache.txt")
+				}
 
+			})
+			Assert.assertTrue("Expected cmake to parse", cmake.generate(saRootDir));
+			Assert.assertTrue("Expected no make errors", cmake.make(saRootDir));
+		}
 	}
 
 	def __parseNoErrorsPrint(String filename) {

+ 0 - 70
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/BuildUtilities.java

@@ -1,82 +1,12 @@
 package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.io.InputStream;
 import java.nio.file.Files;
 import java.nio.file.StandardCopyOption;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.jar.JarEntry;
-import java.util.jar.JarInputStream;
 
 public class BuildUtilities {
-	public void copyNativeLibFiles(File outfolder) {
-		List<File> libFiles;
-		File outputFile = null;
-		InputStream jarfile = null;
-		FileOutputStream fos = null;
-		JarInputStream jarstream = null;
-		JarEntry filejarentry = null;
-
-		if (!outfolder.exists()) {
-			outfolder.mkdir();
-		}
-		else
-		{
-			return;
-		}
-
-		libFiles = new LinkedList<>();
-
-		try {
-			jarfile = new FileInputStream(new File("jars/cppFramework.jar"));
-			jarstream = new JarInputStream(jarfile);
-			filejarentry = jarstream.getNextJarEntry();
-
-			// Extract the framework files
-			while (filejarentry != null) {
-				System.out.println("Extracting file: " + filejarentry.getName());
-				if (!filejarentry.getName().contains("hybridCosimulation-framework") || filejarentry.isDirectory()) {
-					filejarentry = jarstream.getNextJarEntry();
-					continue;
-				}
-
-				// Ignore these files
-				if (filejarentry.getName().contains(".gitignore") || filejarentry.getName().contains(".gitmodules")
-						/*|| filejarentry.getName().contains("README.md")*/ || filejarentry.getName().contains("LICENSE")) {
-					filejarentry = jarstream.getNextJarEntry();
-					continue;
-				}
-				String tmpFileName = filejarentry.getName().replace("hybridCosimulation-framework/", "");
-
-				outputFile = new File(outfolder.toString() + File.separator + tmpFileName);
-
-				libFiles.add(new File(outfolder.getName() + File.separator + tmpFileName));
-
-				outputFile.getParentFile().mkdirs();
-				fos = new FileOutputStream(outputFile);
-
-				while (jarstream.available() > 0) {
-					int b = jarstream.read();
-					if (b >= 0) {
-						fos.write(b);
-					}
-				}
-				fos.flush();
-				fos.close();
-				jarstream.closeEntry();
-				filejarentry = jarstream.getNextJarEntry();
-			}
-			jarstream.close();
-			jarfile.close();
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-	}
 
 	public static void writeToFile(File file, String content) throws IOException
 	{

+ 1 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/CppGenerator.xtend

@@ -268,7 +268,7 @@ class CppGenerator extends SemanticAdaptationGenerator {
 				fsa.generateFile("modelDescription.xml", modelDescription);
 
 				// Compile the fmu.cpp file
-				val fmuCppFile = StaticGenerators.GenFmuCppFile(adapClassName);
+				val fmuCppFile = FmuGenerator.genFmuCppFile(adapClassName);
 				fsa.generateFile("Fmu.cpp", fmuCppFile);
 
 			}

+ 2 - 2
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/StaticGenerators.xtend

@@ -1,7 +1,7 @@
 package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation
 
-class StaticGenerators {
-	def static String GenFmuCppFile(String adapClassName)
+class FmuGenerator {
+	def static String genFmuCppFile(String adapClassName)
 	{
 		'''
 		#include <stdio.h>

+ 249 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.testframework/src/be/uantwerpen/ansymo/semanticadaptation/testframework/CMakeListsGenerator.xtend

@@ -0,0 +1,249 @@
+package be.uantwerpen.ansymo.semanticadaptation.testframework
+
+class CMakeListsGenerator {
+
+	def static String generateToolChainCmake() {
+		'''
+			# the name of the target operating system
+			SET(CMAKE_SYSTEM_NAME Windows)
+			
+			SET(WIN32 true)
+			
+			# which compilers to use for C and C++
+			SET(CMAKE_C_COMPILER /mingw64/bin/gcc)
+			SET(CMAKE_CXX_COMPILER /mingw64/bin/g++)
+			#SET(CMAKE_RC_COMPILER i486-mingw32-windres)
+			
+			# here is the target environment located
+			#SET(CMAKE_FIND_ROOT_PATH /usr/i486-mingw32)
+			
+			# adjust the default behaviour of the FIND_XXX() commands:
+			# search headers and libraries in the target environment, search 
+			# programs in the host environment
+			#set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+			#set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+			#set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+			
+		'''
+	}
+
+	def static String addHcf() {
+		'''
+			#
+			# install hcf frameowrk
+			#
+			set(HCF_DIR hcf)
+					if(EXISTS ${HCF_DIR})
+						execute_process(COMMAND git pull WORKING_DIRECTORY ${HCF_DIR})
+						execute_process(COMMAND git submodule update --init --recursive WORKING_DIRECTORY ${HCF_DIR})
+					else()
+						execute_process(COMMAND git clone --depth 1 git@github.com:into-cps/hybridCosimulation-framework.git ${HCF_DIR} )
+						execute_process(COMMAND git submodule update --init --recursive WORKING_DIRECTORY ${HCF_DIR})
+					endif()
+			add_subdirectory(${HCF_DIR}/semantic-adaptation)
+			#
+			#
+			#
+		'''
+	}
+
+	def static String generateCMakeListsHcfDummy() {
+		'''
+			#
+			# #%~
+			# The Overture Abstract Syntax Tree
+			# %%
+			# Copyright (C) 2017 - 2014 Aarhus University
+			# %%
+			# This program is free software: you can redistribute it and/or modify
+			# it under the terms of the GNU General Public License as
+			# published by the Free Software Foundation, either version 3 of the
+			# License, or (at your option) any later version.
+			# 
+			# This program is distributed in the hope that it will be useful,
+			# but WITHOUT ANY WARRANTY; without even the implied warranty of
+			# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+			# GNU General Public License for more details.
+			# 
+			# You should have received a copy of the GNU General Public
+			# License along with this program.  If not, see
+			# <http://www.gnu.org/licenses/gpl-3.0.html>.
+			# #~%
+			#
+			cmake_minimum_required (VERSION 3.5.2)
+			# this (3.5.2) is the first version where External Project uses --recursive
+			project (dummy C CXX)
+			
+			# HOW to
+			#
+			# cmake -DCMAKE_TOOLCHAIN_FILE=msys-toolchain.cmake -DCMAKE_BUILD_TYPE=Debug .
+			# make
+			# 
+			# to list dependencies use:
+			#  objdump -p binaries/win64/window-sa.dll |  grep 'DLL Name:'
+			#
+			
+			
+			
+			if (WIN32)
+				#windows, becuase windows just cannot figure out to do it correct. 
+				# must be a bug in msys mingw gcc 6.3	
+				# it doesnt read the rsp files.
+				set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES 0)
+				set(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES 0)
+				
+				set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_LIBRARIES 0)
+				set(CMAKE_C_USE_RESPONSE_FILE_FOR_LIBRARIES 0)
+			endif() 
+			
+			«addHcf»
+			
+			include(CheckCXXCompilerFlag)
+			
+			
+			CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
+			CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
+			if(COMPILER_SUPPORTS_CXX11)
+			  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+			elseif(COMPILER_SUPPORTS_CXX0X)
+			  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
+			else()
+			  message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
+			endif()
+		'''
+	}
+
+	def static String generateCMakeLists(String projectName) {
+		'''
+			#
+			# #%~
+			# The Overture Abstract Syntax Tree
+			# %%
+			# Copyright (C) 2017 - 2014 Aarhus University
+			# %%
+			# This program is free software: you can redistribute it and/or modify
+			# it under the terms of the GNU General Public License as
+			# published by the Free Software Foundation, either version 3 of the
+			# License, or (at your option) any later version.
+			# 
+			# This program is distributed in the hope that it will be useful,
+			# but WITHOUT ANY WARRANTY; without even the implied warranty of
+			# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+			# GNU General Public License for more details.
+			# 
+			# You should have received a copy of the GNU General Public
+			# License along with this program.  If not, see
+			# <http://www.gnu.org/licenses/gpl-3.0.html>.
+			# #~%
+			#
+			cmake_minimum_required (VERSION 3.5.2)
+			# this (3.5.2) is the first version where External Project uses --recursive
+			project («projectName» C CXX)
+			
+			# HOW to
+			#
+			# cmake -DCMAKE_TOOLCHAIN_FILE=msys-toolchain.cmake -DCMAKE_BUILD_TYPE=Debug .
+			# make
+			# 
+			# to list dependencies use:
+			#  objdump -p binaries/win64/window-sa.dll |  grep 'DLL Name:'
+			#
+			
+			
+			
+			if (WIN32)
+				#windows, becuase windows just cannot figure out to do it correct. 
+				# must be a bug in msys mingw gcc 6.3	
+				# it doesnt read the rsp files.
+				set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES 0)
+				set(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES 0)
+				
+				set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_LIBRARIES 0)
+				set(CMAKE_C_USE_RESPONSE_FILE_FOR_LIBRARIES 0)
+			endif() 
+			
+			«addHcf»
+			
+			include(CheckCXXCompilerFlag)
+			
+			
+			CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
+			CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
+			if(COMPILER_SUPPORTS_CXX11)
+			  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+			elseif(COMPILER_SUPPORTS_CXX0X)
+			  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
+			else()
+			  message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
+			endif()
+			
+			add_definitions(-DFMI_COSIMULATION)
+			
+			file(GLOB CPP_FILES sources/*.cpp)
+			
+			file(GLOB CPP_MAIN_FILES sources/main*.cpp)
+			
+			list(REMOVE_ITEM CPP_FILES ${CPP_MAIN_FILES})
+			
+			## library ##
+			
+			#determine the library path
+			set(FMI_BIN_DIR "${CMAKE_CURRENT_SOURCE_DIR}/binaries")
+			
+			if(WIN32 OR MINGW)
+				set(FMI_BIN_DIR "${FMI_BIN_DIR}/win")
+				# not sure why this doesnt work on MSYS so we just reset it
+				SET (CMAKE_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITECTURE}")
+			endif()
+			
+			if(APPLE)
+				set(FMI_BIN_DIR "${FMI_BIN_DIR}/darwin")
+			endif()
+			
+			if(UNIX AND NOT APPLE)
+			  # for Linux, BSD, Solaris, Minix
+				set(FMI_BIN_DIR "${FMI_BIN_DIR}/linux")
+			endif()
+			
+			
+			if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
+			  set(FMI_BIN_DIR "${FMI_BIN_DIR}64")
+			else ()
+				set(FMI_BIN_DIR "${FMI_BIN_DIR}32")
+			endif ()
+			
+			message("FMI output is ${FMI_BIN_DIR}")
+			#SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "")
+			file(MAKE_DIRECTORY ${FMI_BIN_DIR})
+			set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${FMI_BIN_DIR})
+			set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${FMI_BIN_DIR})
+			
+			#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY bb)
+			#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${FMI_BIN_DIR})
+			
+			
+			add_library(${PROJECT_NAME} SHARED ${CPP_FILES})
+			target_link_libraries(${PROJECT_NAME} PUBLIC hcf)
+			set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
+			SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "")
+			
+			
+			set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
+			
+			## Main executable ##
+			add_executable(${PROJECT_NAME}_main ${CPP_MAIN_FILES} ${CPP_FILES})
+			target_link_libraries(${PROJECT_NAME}_main PUBLIC hcf)
+			
+			
+			# I need this: -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic
+			
+			if (WIN32)
+				#windows	
+				set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic")
+				set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc  -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic")
+			endif() 
+			
+		'''
+	}
+
+}

+ 147 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.testframework/src/be/uantwerpen/ansymo/semanticadaptation/testframework/FmuMainTestGenerator.xtend

@@ -0,0 +1,147 @@
+package be.uantwerpen.ansymo.semanticadaptation.testframework
+
+class FmuMainTestGenerator {
+	def static String generateMainCppFile(String folderPath)
+	{
+		'''
+		/*
+		 * main.cpp
+		 *
+		 *  Created on: Mar 14, 2017
+		 *      Author: kel
+		 */
+		#include <iostream>
+		#include "fmi2TypesPlatform.h"
+		#include "fmi2Functions.h"
+		#include <string>
+		
+		#include <memory>
+		#include <iostream>
+		
+		#include <cstdio>
+		#include <stdarg.h>     /* va_list, va_start, va_arg, va_end */
+		#include <fstream>
+		
+		using namespace std;
+		
+		void fmuLoggerCache(void *componentEnvironment, fmi2String instanceName,
+				fmi2Status status, fmi2String category, fmi2String message, ...) {
+			va_list argp;
+		
+			// replace C format strings
+			va_start(argp, message);
+			size_t size = vsnprintf(nullptr, 0, message, argp) + 1; // Extra space for '\0'
+			va_end(argp);
+		
+			va_start(argp, message);
+			unique_ptr<char[]> buf(new char[size]);
+			vsnprintf(buf.get(), size, message, argp);
+			va_end(argp);
+		
+			string completeMessage = string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
+		
+			cout << "FROM MAIN: Name: " << instanceName << " Status: " << status << " Category: "
+					<< category << " Msg: " << completeMessage << endl;
+		}
+		
+		fmi2Status setReal(fmi2Component comp, fmi2ValueReference id, fmi2Real val) {
+			const fmi2ValueReference vr[] { id };
+			size_t nvr = 1;
+			fmi2Real value[] { val };
+			return fmi2SetReal(comp, vr, nvr, value);
+		}
+		
+		fmi2Real getReal(fmi2Component comp, fmi2ValueReference id) {
+			const fmi2ValueReference vr[] { id };
+			size_t nvr = 1;
+			fmi2Real value[1];
+			fmi2GetReal(comp, vr, nvr, value);
+		
+			return value[0];
+		}
+		
+		int main(int argc, char *argv[]) {
+		//	setvbuf(stdout, NULL, _IONBF, 0);
+		//	setvbuf(stderr, NULL, _IONBF, 0);
+		
+			cout << "hello" << endl;
+		
+			fmi2CallbackFunctions callback = { &fmuLoggerCache, NULL, NULL, NULL, NULL };
+			fmi2Component comp =
+					fmi2Instantiate("this system", fmi2CoSimulation, "{1234}",
+							"«folderPath»",
+							&callback, fmi2True,
+							fmi2True);
+		
+			if (comp == NULL) {
+				cout << "init failed" << endl;
+				return -1;
+			}
+		
+			if (fmi2SetupExperiment(comp, false, 0.0, 0, true, 100) != fmi2OK) {
+				printf("Error fmi2SetupExperiment");
+				return 1;
+			}
+		
+			if (fmi2EnterInitializationMode(comp) != fmi2OK) {
+				printf("Error fmi2SetupExperiment");
+				return 1;
+			}
+		
+			if (fmi2ExitInitializationMode(comp) != fmi2OK) {
+				printf("Error fmi2SetupExperiment");
+				return 1;
+			}
+		
+		#define ID_Window_SA_IN_reaction_force 0
+		#define ID_Window_SA_IN_displacement 1
+		#define ID_Window_SA_IN_speed 2
+		
+		#define ID_Window_SA_OUT_disp 3
+		#define ID_Window_SA_OUT_tau 4
+		
+			std::fstream fs;
+			fs.open("result.csv",
+					std::fstream::in | std::fstream::out | std::fstream::trunc);
+		
+			//cout << "------------ Header ---------" << endl;
+			fs << "\"time\",\"ID_Window_SA_OUT_disp\",\"ID_Window_SA_OUT_tau\"" << endl;
+			double time = 0.0;
+			double stepSize = 0.01;
+		
+			for (double time = 0.0; time < 10;) {
+				if (setReal(comp, ID_Window_SA_IN_reaction_force, -1.0) != fmi2OK) {
+					printf("Error setting real");
+					return 1;
+				}
+				if (setReal(comp, ID_Window_SA_IN_displacement, time) != fmi2OK) {
+					printf("Error setting real");
+					return 1;
+				}
+				if (setReal(comp, ID_Window_SA_IN_speed, 1.0) != fmi2OK) {
+					printf("Error setting real");
+					return 1;
+				}
+		
+				if (fmi2DoStep(comp, time, stepSize, false) != fmi2OK) {
+					printf("Errorin do step");
+					return 1;
+				}
+				time += stepSize;
+		
+				auto disp = getReal(comp, ID_Window_SA_OUT_disp);
+				auto tau = getReal(comp, ID_Window_SA_OUT_tau);
+		
+				cout << "time: " << time << " disp: " << disp << " tau: " << tau
+						<< endl;
+				fs << time << "," << disp << "," << tau << endl;
+			}
+			fs.close();
+		
+			return 0;
+		}
+		
+		'''
+	}
+
+}

+ 0 - 307
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.testframework/src/be/uantwerpen/ansymo/semanticadaptation/testframework/StaticGenerators.xtend

@@ -1,307 +0,0 @@
-package be.uantwerpen.ansymo.semanticadaptation.testframework
-
-class StaticGenerators {
-	def static String generateMainCppFile(String folderPath)
-	{
-		'''
-		/*
-		 * main.cpp
-		 *
-		 *  Created on: Mar 14, 2017
-		 *      Author: kel
-		 */
-		#include <iostream>
-		#include "fmi2TypesPlatform.h"
-		#include "fmi2Functions.h"
-		#include <string>
-		
-		#include <memory>
-		#include <iostream>
-		
-		#include <cstdio>
-		#include <stdarg.h>     /* va_list, va_start, va_arg, va_end */
-		#include <fstream>
-		
-		using namespace std;
-		
-		void fmuLoggerCache(void *componentEnvironment, fmi2String instanceName,
-				fmi2Status status, fmi2String category, fmi2String message, ...) {
-			va_list argp;
-		
-			// replace C format strings
-			va_start(argp, message);
-			size_t size = vsnprintf(nullptr, 0, message, argp) + 1; // Extra space for '\0'
-			va_end(argp);
-		
-			va_start(argp, message);
-			unique_ptr<char[]> buf(new char[size]);
-			vsnprintf(buf.get(), size, message, argp);
-			va_end(argp);
-		
-			string completeMessage = string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
-		
-			cout << "FROM MAIN: Name: " << instanceName << " Status: " << status << " Category: "
-					<< category << " Msg: " << completeMessage << endl;
-		}
-		
-		fmi2Status setReal(fmi2Component comp, fmi2ValueReference id, fmi2Real val) {
-			const fmi2ValueReference vr[] { id };
-			size_t nvr = 1;
-			fmi2Real value[] { val };
-			return fmi2SetReal(comp, vr, nvr, value);
-		}
-		
-		fmi2Real getReal(fmi2Component comp, fmi2ValueReference id) {
-			const fmi2ValueReference vr[] { id };
-			size_t nvr = 1;
-			fmi2Real value[1];
-			fmi2GetReal(comp, vr, nvr, value);
-		
-			return value[0];
-		}
-		
-		int main(int argc, char *argv[]) {
-		//	setvbuf(stdout, NULL, _IONBF, 0);
-		//	setvbuf(stderr, NULL, _IONBF, 0);
-		
-			cout << "hello" << endl;
-		
-			fmi2CallbackFunctions callback = { &fmuLoggerCache, NULL, NULL, NULL, NULL };
-			fmi2Component comp =
-					fmi2Instantiate("this system", fmi2CoSimulation, "{1234}",
-							"«folderPath»",
-							&callback, fmi2True,
-							fmi2True);
-		
-			if (comp == NULL) {
-				cout << "init failed" << endl;
-				return -1;
-			}
-		
-			if (fmi2SetupExperiment(comp, false, 0.0, 0, true, 100) != fmi2OK) {
-				printf("Error fmi2SetupExperiment");
-				return 1;
-			}
-		
-			if (fmi2EnterInitializationMode(comp) != fmi2OK) {
-				printf("Error fmi2SetupExperiment");
-				return 1;
-			}
-		
-			if (fmi2ExitInitializationMode(comp) != fmi2OK) {
-				printf("Error fmi2SetupExperiment");
-				return 1;
-			}
-		
-		#define ID_Window_SA_IN_reaction_force 0
-		#define ID_Window_SA_IN_displacement 1
-		#define ID_Window_SA_IN_speed 2
-		
-		#define ID_Window_SA_OUT_disp 3
-		#define ID_Window_SA_OUT_tau 4
-		
-			std::fstream fs;
-			fs.open("result.csv",
-					std::fstream::in | std::fstream::out | std::fstream::trunc);
-		
-			//cout << "------------ Header ---------" << endl;
-			fs << "\"time\",\"ID_Window_SA_OUT_disp\",\"ID_Window_SA_OUT_tau\"" << endl;
-			double time = 0.0;
-			double stepSize = 0.01;
-		
-			for (double time = 0.0; time < 10;) {
-				if (setReal(comp, ID_Window_SA_IN_reaction_force, -1.0) != fmi2OK) {
-					printf("Error setting real");
-					return 1;
-				}
-				if (setReal(comp, ID_Window_SA_IN_displacement, time) != fmi2OK) {
-					printf("Error setting real");
-					return 1;
-				}
-				if (setReal(comp, ID_Window_SA_IN_speed, 1.0) != fmi2OK) {
-					printf("Error setting real");
-					return 1;
-				}
-		
-				if (fmi2DoStep(comp, time, stepSize, false) != fmi2OK) {
-					printf("Errorin do step");
-					return 1;
-				}
-				time += stepSize;
-		
-				auto disp = getReal(comp, ID_Window_SA_OUT_disp);
-				auto tau = getReal(comp, ID_Window_SA_OUT_tau);
-		
-				cout << "time: " << time << " disp: " << disp << " tau: " << tau
-						<< endl;
-				fs << time << "," << disp << "," << tau << endl;
-			}
-			fs.close();
-		
-			return 0;
-		}
-		
-		'''
-	}
-
-	def static String generateToolChainCmake(){
-		'''
-		# the name of the target operating system
-		SET(CMAKE_SYSTEM_NAME Windows)
-		
-		SET(WIN32 true)
-		
-		# which compilers to use for C and C++
-		SET(CMAKE_C_COMPILER /mingw64/bin/gcc)
-		SET(CMAKE_CXX_COMPILER /mingw64/bin/g++)
-		#SET(CMAKE_RC_COMPILER i486-mingw32-windres)
-		
-		# here is the target environment located
-		#SET(CMAKE_FIND_ROOT_PATH /usr/i486-mingw32)
-		
-		# adjust the default behaviour of the FIND_XXX() commands:
-		# search headers and libraries in the target environment, search 
-		# programs in the host environment
-		#set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
-		#set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
-		#set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
-		
-		'''
-	}
-
-	def static String generateCMakeLists(String projectName, String frameworkPath)
-	{
-		'''
-		#
-		# #%~
-		# The Overture Abstract Syntax Tree
-		# %%
-		# Copyright (C) 2017 - 2014 Aarhus University
-		# %%
-		# This program is free software: you can redistribute it and/or modify
-		# it under the terms of the GNU General Public License as
-		# published by the Free Software Foundation, either version 3 of the
-		# License, or (at your option) any later version.
-		# 
-		# This program is distributed in the hope that it will be useful,
-		# but WITHOUT ANY WARRANTY; without even the implied warranty of
-		# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-		# GNU General Public License for more details.
-		# 
-		# You should have received a copy of the GNU General Public
-		# License along with this program.  If not, see
-		# <http://www.gnu.org/licenses/gpl-3.0.html>.
-		# #~%
-		#
-		cmake_minimum_required (VERSION 3.5.2)
-		# this (3.5.2) is the first version where External Project uses --recursive
-		project («projectName» C CXX)
-		
-		# HOW to
-		#
-		# cmake -DCMAKE_TOOLCHAIN_FILE=msys-toolchain.cmake -DCMAKE_BUILD_TYPE=Debug .
-		# make
-		# 
-		# to list dependencies use:
-		#  objdump -p binaries/win64/window-sa.dll |  grep 'DLL Name:'
-		#
-		
-		
-		
-		if (WIN32)
-			#windows, becuase windows just cannot figure out to do it correct. 
-			# must be a bug in msys mingw gcc 6.3	
-			# it doesnt read the rsp files.
-			set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES 0)
-			set(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES 0)
-			
-			set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_LIBRARIES 0)
-			set(CMAKE_C_USE_RESPONSE_FILE_FOR_LIBRARIES 0)
-		endif() 
-		
-		
-		add_subdirectory(«frameworkPath»)
-		
-		include(CheckCXXCompilerFlag)
-		
-		
-		CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
-		CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
-		if(COMPILER_SUPPORTS_CXX11)
-		  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
-		elseif(COMPILER_SUPPORTS_CXX0X)
-		  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
-		else()
-		  message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
-		endif()
-		
-		add_definitions(-DFMI_COSIMULATION)
-		
-		file(GLOB CPP_FILES sources/*.cpp)
-		
-		file(GLOB CPP_MAIN_FILES sources/main*.cpp)
-		
-		list(REMOVE_ITEM CPP_FILES ${CPP_MAIN_FILES})
-		
-		## library ##
-		
-		#determine the library path
-		set(FMI_BIN_DIR "${CMAKE_CURRENT_SOURCE_DIR}/binaries")
-		
-		if(WIN32 OR MINGW)
-			set(FMI_BIN_DIR "${FMI_BIN_DIR}/win")
-			# not sure why this doesnt work on MSYS so we just reset it
-			SET (CMAKE_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITECTURE}")
-		endif()
-		
-		if(APPLE)
-			set(FMI_BIN_DIR "${FMI_BIN_DIR}/darwin")
-		endif()
-		
-		if(UNIX AND NOT APPLE)
-		  # for Linux, BSD, Solaris, Minix
-			set(FMI_BIN_DIR "${FMI_BIN_DIR}/linux")
-		endif()
-		
-		
-		if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
-		  set(FMI_BIN_DIR "${FMI_BIN_DIR}64")
-		else ()
-			set(FMI_BIN_DIR "${FMI_BIN_DIR}32")
-		endif ()
-		
-		message("FMI output is ${FMI_BIN_DIR}")
-		#SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "")
-		file(MAKE_DIRECTORY ${FMI_BIN_DIR})
-		set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${FMI_BIN_DIR})
-		set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${FMI_BIN_DIR})
-		
-		#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY bb)
-		#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${FMI_BIN_DIR})
-		
-		
-		add_library(${PROJECT_NAME} SHARED ${CPP_FILES})
-		target_link_libraries(${PROJECT_NAME} PUBLIC hcf)
-		set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
-		SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "")
-		
-		
-		set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
-		
-		## Main executable ##
-		add_executable(${PROJECT_NAME}_main ${CPP_MAIN_FILES} ${CPP_FILES})
-		target_link_libraries(${PROJECT_NAME}_main PUBLIC hcf)
-		
-		
-		# I need this: -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic
-		
-		if (WIN32)
-			#windows	
-			set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic")
-			set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc  -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic")
-		endif() 
-		
-		'''
-	}
-	
-}