29package com.jogamp.opencl.test.util;
31import java.io.BufferedReader;
32import java.io.IOException;
33import java.io.InputStreamReader;
34import java.util.Iterator;
37import com.jogamp.common.os.Platform;
38import com.jogamp.common.util.locks.SingletonInstance;
39import com.jogamp.opencl.CLPlatform;
41import org.junit.Assume;
42import org.junit.Before;
43import org.junit.BeforeClass;
44import org.junit.After;
45import org.junit.AfterClass;
46import org.junit.FixMethodOrder;
48import org.junit.rules.TestName;
49import org.junit.runners.MethodSorters;
50import org.junit.runners.model.FrameworkMethod;
51import org.junit.runners.model.TestClass;
53@FixMethodOrder(MethodSorters.NAME_ASCENDING)
55 @Rule
public TestName _unitTestName =
new TestName();
57 public static final String SINGLE_INSTANCE_LOCK_FILE =
"UITestCase.lock";
58 public static final int SINGLE_INSTANCE_LOCK_PORT = 59999;
60 public static final long SINGLE_INSTANCE_LOCK_TO = 6*60*1000;
61 public static final long SINGLE_INSTANCE_LOCK_POLL = 1000;
63 private static volatile SingletonInstance singletonInstance;
65 private static volatile boolean testSupported =
true;
67 private static volatile int maxMethodNameLen = 0;
69 private static final synchronized void initSingletonInstance() {
70 if(
null == singletonInstance ) {
72 singletonInstance = SingletonInstance.createServerSocket(SINGLE_INSTANCE_LOCK_POLL, SINGLE_INSTANCE_LOCK_PORT);
73 if(!singletonInstance.tryLock(SINGLE_INSTANCE_LOCK_TO)) {
74 throw new RuntimeException(
"Fatal: Could not lock single instance: "+singletonInstance.getName());
84 System.err.println(
"setTestSupported: "+v);
89 if(0 == maxMethodNameLen) {
91 final TestClass tc =
new TestClass(getClass());
92 final List<FrameworkMethod> testMethods = tc.getAnnotatedMethods(org.junit.Test.class);
93 for(
final Iterator<FrameworkMethod> iter=testMethods.iterator(); iter.hasNext(); ) {
94 final int l = iter.next().getName().length();
95 if( ml < l ) { ml = l; }
97 maxMethodNameLen = ml;
99 return maxMethodNameLen;
103 return _unitTestName.getMethodName();
107 return getClass().getSimpleName()+separator+getTestMethodName();
111 return getClass().getName()+separator+getTestMethodName();
117 initSingletonInstance();
124 singletonInstance.unlock();
129 System.err.print(
"++++ UITestCase.setUp: "+getFullTestName(
" - "));
131 final boolean abortTest = isOpenCLUnavailable || !testSupported;
133 if( isOpenCLUnavailable ) {
134 System.err.print(
" - CL not supported on this machine");
136 if( !testSupported ) {
137 System.err.print(
" - "+unsupportedTestMsg);
139 System.err.println(
"");
140 Assume.assumeTrue(
false);
142 System.err.println();
147 System.err.println(
"++++ UITestCase.tearDown: "+getFullTestName(
" - "));
151 final BufferedReader stdin =
new BufferedReader(
new InputStreamReader(System.in));
152 System.err.println(preMessage+
"> Press enter to continue");
154 System.err.println(stdin.readLine());
155 }
catch (
final IOException e) { }
158 static final String unsupportedTestMsg =
"Test not supported on this platform.";
static void setTestSupported(final boolean v)
static void oneTimeTearDown()
final String getFullTestName(final String separator)
static boolean isTestSupported()
final String getTestMethodName()
static void oneTimeSetUp()
static void waitForKey(final String preMessage)
final String getSimpleTestName(final String separator)