Browse Source

Share project "org.yakindu.sct.simulation.core.test" into "https://svn.codespot.com/a/eclipselabs.org/yakindu"

Andreas Mülder 13 years ago
parent
commit
4446a67c97

+ 7 - 0
test-plugins/org.yakindu.sct.simulation.core.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.simulation.core.test/.project

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.yakindu.sct.simulation.core.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>

+ 7 - 0
test-plugins/org.yakindu.sct.simulation.core.test/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,7 @@
+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

+ 12 - 0
test-plugins/org.yakindu.sct.simulation.core.test/META-INF/MANIFEST.MF

@@ -0,0 +1,12 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Test
+Bundle-SymbolicName: org.yakindu.sct.simulation.core.test
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.yakindu.sct.simulation.core.test.Activator
+Bundle-Vendor: Yakindu
+Require-Bundle: org.eclipse.core.runtime,
+ org.junit4;bundle-version="4.8.1",
+ org.yakindu.sct.simulation.core;bundle-version="1.0.0"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-ActivationPolicy: lazy

+ 4 - 0
test-plugins/org.yakindu.sct.simulation.core.test/build.properties

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

+ 81 - 0
test-plugins/org.yakindu.sct.simulation.core.test/pom.xml

@@ -0,0 +1,81 @@
+<?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.simulation.core.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>
+					<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>

+ 101 - 0
test-plugins/org.yakindu.sct.simulation.core.test/src/org/yakindu/sct/simulation/core/runtime/timer/VirtualClockTest.java

@@ -0,0 +1,101 @@
+/**
+ * Copyright (c) 2012 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.core.runtime.timer;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public class VirtualClockTest {
+
+	private VirtualClock clock;
+
+	@Before
+	public void setup() {
+		clock = new VirtualClock();
+	}
+
+	@Test
+	public void testSimpleTimeScaling() throws InterruptedException {
+		long start = System.currentTimeMillis();
+		clock.start();
+		Thread.sleep(200);
+		clock.setFactor(2);
+		Thread.sleep(200);
+		assertFuzzy(clock.getTime() - start, 600);
+	}
+
+	@Test
+	public void testDoubleTimeScaling() throws InterruptedException {
+		long start = System.currentTimeMillis();
+		clock.start();
+		Thread.sleep(200);
+		clock.setFactor(2);
+		Thread.sleep(200);
+		clock.setFactor(0.5);
+		Thread.sleep(200);
+		assertFuzzy(clock.getTime() - start, 700);
+	}
+
+	@Test
+	public void testsuspendResume() throws InterruptedException {
+		long start = System.currentTimeMillis();
+		clock.start();
+		Thread.sleep(200);
+		clock.suspend();
+		Thread.sleep(200);
+		clock.resume();
+		assertFuzzy(clock.getTime() - start, 200);
+	}
+	
+	@Test
+	public void testsuspendResumeTimeScaling() throws InterruptedException {
+		long start = System.currentTimeMillis();
+		clock.start();
+		Thread.sleep(200);
+		clock.setFactor(2);
+		Thread.sleep(200);
+		clock.suspend();
+		Thread.sleep(200);
+		clock.resume();
+		clock.setFactor(0.5);
+		Thread.sleep(200);
+		assertFuzzy(clock.getTime() - start, 700);
+	}
+	
+	@Test
+	public void testScaleDuringsuspend() throws InterruptedException {
+		long start = System.currentTimeMillis();
+		clock.start();
+		Thread.sleep(200);
+		clock.setFactor(4);
+		Thread.sleep(200);
+		clock.suspend();
+		clock.setFactor(0.25);
+		Thread.sleep(200);
+		clock.resume();
+		Thread.sleep(200);
+		assertFuzzy(clock.getTime() - start, 1050);
+	}
+
+	private static final long GAP = 20; // ms
+
+	protected void assertFuzzy(long expected, long actual) {
+		assertTrue("Expected " + expected + " but was " + actual,
+				expected > actual - GAP && expected < actual + GAP);
+	}
+
+}

+ 30 - 0
test-plugins/org.yakindu.sct.simulation.core.test/src/org/yakindu/sct/simulation/core/test/Activator.java

@@ -0,0 +1,30 @@
+package org.yakindu.sct.simulation.core.test;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class Activator implements BundleActivator {
+
+	private static BundleContext context;
+
+	static BundleContext getContext() {
+		return context;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+	 */
+	public void start(BundleContext bundleContext) throws Exception {
+		Activator.context = bundleContext;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+	 */
+	public void stop(BundleContext bundleContext) throws Exception {
+		Activator.context = null;
+	}
+
+}

+ 26 - 0
test-plugins/org.yakindu.sct.simulation.core.test/src/org/yakindu/sct/simulation/core/test/AllTests.java

@@ -0,0 +1,26 @@
+/**
+ * Copyright (c) 2012 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.simulation.core.test;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+import org.yakindu.sct.simulation.core.runtime.timer.VirtualClockTest;
+
+/**
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+@RunWith(value = Suite.class)
+@SuiteClasses(value = { VirtualClockTest.class })
+public class AllTests {
+
+}