Run TCK tests automatically if TCK test device is found
This commit is contained in:
parent
2af4393d2e
commit
41d7c186dc
@ -5,6 +5,7 @@
|
||||
|
||||
package de.ailis.usb4java.test;
|
||||
|
||||
import org.junit.internal.AssumptionViolatedException;
|
||||
import org.junit.internal.runners.JUnit38ClassRunner;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runner.manipulation.Filter;
|
||||
@ -34,7 +35,15 @@ public class TCKRunner extends JUnit38ClassRunner
|
||||
@Override
|
||||
public boolean shouldRun(Description description)
|
||||
{
|
||||
return System.getProperty("TCK_TESTS") != null;
|
||||
try
|
||||
{
|
||||
UsbAssume.assumeTckTestsEnabled();
|
||||
return true;
|
||||
}
|
||||
catch (AssumptionViolatedException e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -20,7 +20,10 @@ public class UsbAssume
|
||||
{
|
||||
/** If USB tests are to be executed. */
|
||||
private static Boolean usbTests;
|
||||
|
||||
|
||||
/** If TCK tests are to be executed. */
|
||||
private static Boolean tckTests;
|
||||
|
||||
/**
|
||||
* Assume that USB tests are enabled. Call this in the first line of
|
||||
* tests method or preparation methods when you want to ignore the
|
||||
@ -47,9 +50,12 @@ public class UsbAssume
|
||||
InputStream inputStream = proc.getInputStream();
|
||||
try
|
||||
{
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
BufferedReader reader =
|
||||
new BufferedReader(new InputStreamReader(
|
||||
inputStream));
|
||||
int lines = 0;
|
||||
while (reader.readLine() != null) lines++;
|
||||
while (reader.readLine() != null)
|
||||
lines++;
|
||||
usbTests = lines >= 2;
|
||||
}
|
||||
finally
|
||||
@ -65,6 +71,64 @@ public class UsbAssume
|
||||
}
|
||||
}
|
||||
assumeTrue("This test is ignored when USB_TESTS property is not set",
|
||||
usbTests);
|
||||
usbTests);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assume that TCK tests are enabled. Call this in the first line of
|
||||
* tests method or preparation methods when you want to ignore the
|
||||
* tests when the system is not able to run the TCK tests anyway.
|
||||
*
|
||||
* TCK tests can be controlled with the system property TCK_TESTS. When
|
||||
* set to true then TCK tests are always run, if set to false then they
|
||||
* are never run. If this property is not set then the command-line tool
|
||||
* lsusb is called to scan for the TCK hardware. If this tool found the
|
||||
* TCK hardware then TCK tests are enabled. In all other cases they are
|
||||
* disabled.
|
||||
*/
|
||||
public static void assumeTckTestsEnabled()
|
||||
{
|
||||
assumeUsbTestsEnabled();
|
||||
if (tckTests == null && System.getProperty("TCK_TESTS") != null)
|
||||
tckTests = Boolean.valueOf(System.getProperty("TCK_TESTS"));
|
||||
if (tckTests == null)
|
||||
{
|
||||
tckTests = false;
|
||||
try
|
||||
{
|
||||
final Process proc = Runtime.getRuntime().exec("lsusb");
|
||||
if (proc.waitFor() == 0)
|
||||
{
|
||||
InputStream inputStream = proc.getInputStream();
|
||||
try
|
||||
{
|
||||
BufferedReader reader =
|
||||
new BufferedReader(new InputStreamReader(
|
||||
inputStream));
|
||||
String line = reader.readLine();
|
||||
while (line != null)
|
||||
{
|
||||
if (line.contains("0547:1002"))
|
||||
{
|
||||
tckTests = true;
|
||||
break;
|
||||
}
|
||||
line = reader.readLine();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Ignored. USB tests are silently disabled when lsusb could
|
||||
// not be run.
|
||||
}
|
||||
}
|
||||
assumeTrue("This test is ignored when TCK_TESTS property is not set",
|
||||
tckTests);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user