Explorar o código

Initial part of generator C Test

benjamin.schwertfeger@gmail.com %!s(int64=13) %!d(string=hai) anos
pai
achega
bec2ad23a6

+ 7 - 0
test-plugins/org.yakindu.sct.generator.c.test/.classpath

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

+ 28 - 0
test-plugins/org.yakindu.sct.generator.c.test/.project

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.yakindu.sct.generator.c.test</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ManifestBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.SchemaBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.pde.PluginNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

+ 8 - 0
test-plugins/org.yakindu.sct.generator.c.test/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,8 @@
+#Thu Jan 05 09:07:52 CET 2012
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6

+ 14 - 0
test-plugins/org.yakindu.sct.generator.c.test/META-INF/MANIFEST.MF

@@ -0,0 +1,14 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Generator C Test
+Bundle-SymbolicName: org.yakindu.sct.generator.c.test
+Bundle-Version: 1.0.0.qualifier
+Bundle-Vendor: YAKINDU
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Require-Bundle: org.junit4;bundle-version="4.8.1",
+ org.eclipse.core.resources;bundle-version="3.7.100",
+ org.eclipse.core.runtime;bundle-version="3.7.0",
+ org.yakindu.sct.generator.c;bundle-version="1.0.0",
+ org.yakindu.sct.model.sgen;bundle-version="1.0.0",
+ org.yakindu.sct.generator.core;bundle-version="1.0.0",
+ org.yakindu.sct.generator.genmodel;bundle-version="1.0.0"

+ 4 - 0
test-plugins/org.yakindu.sct.generator.c.test/build.properties

@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+               .

+ 86 - 0
test-plugins/org.yakindu.sct.generator.c.test/pom.xml

@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.yakindu.sct</groupId>
+		<artifactId>org.yakindu.sct.releng</artifactId>
+		<version>1.0.0-SNAPSHOT</version>
+		<relativePath>../org.yakindu.sct.releng/pom.xml</relativePath>
+	</parent>
+	<artifactId>org.yakindu.sct.generator.c.test</artifactId>
+	<groupId>org.yakindu.sct.plugins</groupId>
+	<packaging>eclipse-test-plugin</packaging>
+	
+	<profiles>
+		<profile>
+			<id>CI</id>
+			<!-- Test failures are collected by jenkins and evaluated for instable builds -->
+			<properties>
+				<testFailureIgnore>true</testFailureIgnore>
+			</properties>
+		</profile>
+		<profile>
+			<id>macosx</id>
+			<activation>
+				<os>
+					<family>mac</family>
+				</os>
+			</activation>
+			<properties>
+				<test.vmargs>-Xmx512m -XX:MaxPermSize=256m -XstartOnFirstThread</test.vmargs>
+			</properties>
+		</profile>
+		<profile>
+			<id>other-os</id>
+			<activation>
+				<os>
+					<family>!mac</family>
+				</os>
+			</activation>
+			<properties>
+				<test.vmargs>-Xmx512m -XX:MaxPermSize=256m</test.vmargs>
+			</properties>
+		</profile>
+	</profiles>
+
+	<properties>
+		<testFailureIgnore>false</testFailureIgnore>
+	</properties>
+
+	<build>
+		<sourceDirectory>src</sourceDirectory>
+		<plugins>
+			<plugin>
+				<groupId>org.eclipse.tycho</groupId>
+				<artifactId>tycho-surefire-plugin</artifactId>
+				<version>${tycho-version}</version>
+				<configuration>
+					<!-- 
+					<includes>
+						<include>**/All*Tests.class</include>
+					</includes>
+					 -->
+					<useUIHarness>false</useUIHarness>
+					<useUIThread>false</useUIThread>
+					<testFailureIgnore>${testFailureIgnore}</testFailureIgnore>
+					<argLine>${test.vmargs}</argLine>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.eclipse.tycho</groupId>
+				<artifactId>tycho-source-plugin</artifactId>
+				<version>${tycho-version}</version>
+				<executions>
+					<execution>
+						<id>plugin-source</id>
+						<goals>
+							<goal>plugin-source</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
+	</build>
+</project>

+ 139 - 0
test-plugins/org.yakindu.sct.generator.c.test/src/org/yakindu/sct/generator/c/test/CTestAdapterTest.java

@@ -0,0 +1,139 @@
+package org.yakindu.sct.generator.c.test;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.concurrent.Semaphore;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.core.runtime.jobs.Job;
+import org.junit.Test;
+import org.yakindu.sct.generator.core.GeneratorExecutor;
+
+import com.google.inject.Guice;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+
+public class CTestAdapterTest {
+	private static final String PROJECT_NAME = "TestScenarios";
+
+	@Inject
+	private GeneratorExecutor generatorExecutor;
+
+	private Injector injector;
+
+	@Test
+	public void runCTest() throws CoreException, IOException,
+			InterruptedException {
+		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+		final int[] doneCounter = new int[1];
+		doneCounter[0] = 1;
+		NullProgressMonitor monitor = new NullProgressMonitor() {
+			@Override
+			public void done() {
+				super.done();
+				doneCounter[0]++;
+
+			}
+		};
+		IProject project = root.getProject(PROJECT_NAME);
+		int counterBefore = doneCounter[0];
+		project.create(monitor);
+		while (counterBefore == doneCounter[0]) {
+			Thread.sleep(10);
+		}
+		copy(new File("TestScenarios"), project.getLocation().toFile());
+
+		counterBefore = doneCounter[0];
+		project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
+		while (counterBefore == doneCounter[0]) {
+			Thread.sleep(10);
+		}
+
+		counterBefore = doneCounter[0];
+		project.open(monitor);
+		while (counterBefore == doneCounter[0]) {
+			Thread.sleep(10);
+		}
+
+		getInjector().injectMembers(this);
+
+		IFile file = project.getFile("GenModelC.sgen");
+		generatorExecutor.executeGenerator(file);
+		waitForJobFinished(file);
+
+		// TODO parameterize cmake skript and call appropriate with conversion
+		// for to junit.xml
+		ProcessBuilder processBuilder = new ProcessBuilder(
+				"/opt/local/bin/cmake");
+		processBuilder.directory(project.getLocation().toFile());
+
+		processBuilder.start();
+	}
+
+	private void waitForJobFinished(ISchedulingRule schedulingRule)
+			throws InterruptedException {
+		final Semaphore semaphore = new Semaphore(1);
+		semaphore.acquire();
+		new Job("Wait Job") {
+			protected org.eclipse.core.runtime.IStatus run(
+					org.eclipse.core.runtime.IProgressMonitor monitor) {
+				semaphore.release();
+				return Status.OK_STATUS;
+			};
+		}.schedule();
+		semaphore.acquire();
+	}
+
+	private Injector getInjector() {
+		if (injector == null) {
+			injector = Guice
+					.createInjector(new org.yakindu.sct.generator.genmodel.SGenRuntimeModule());
+		}
+		return injector;
+	}
+
+	private void copy(File source, File target) throws IOException {
+		for (File child : source.listFiles()) {
+			if (child.isDirectory()) {
+				File childTargetDir = new File(target, child.getName());
+				childTargetDir.mkdir();
+				copy(child, childTargetDir);
+			} else if (child.isFile()) {
+				File childTargetFile = new File(target, child.getName());
+
+				if (childTargetFile.exists()) {
+					childTargetFile.delete();
+				}
+
+				FileReader in = null;
+				FileWriter out = null;
+				try {
+					in = new FileReader(child);
+					out = new FileWriter(childTargetFile);
+
+					int c = in.read();
+					while (c != -1) {
+						out.write(c);
+						c = in.read();
+					}
+				} finally {
+					if (in != null)
+						in.close();
+					if (out != null)
+						out.close();
+				}
+			}
+
+		}
+	}
+}