aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/scala/firrtl/util/ClassUtils.scala19
-rw-r--r--src/main/scala/firrtl/util/TestOptions.scala13
2 files changed, 32 insertions, 0 deletions
diff --git a/src/main/scala/firrtl/util/ClassUtils.scala b/src/main/scala/firrtl/util/ClassUtils.scala
new file mode 100644
index 00000000..1b388035
--- /dev/null
+++ b/src/main/scala/firrtl/util/ClassUtils.scala
@@ -0,0 +1,19 @@
+package firrtl.util
+
+object ClassUtils {
+ /** Determine if a named class is loaded.
+ *
+ * @param name - name of the class: "foo.bar" or "org.foo.bar"
+ * @return true if the class has been loaded (is accessible), false otherwise.
+ */
+ def isClassLoaded(name: String): Boolean = {
+ val found = try {
+ Class.forName(name, false, getClass.getClassLoader) != null
+ } catch {
+ case e: ClassNotFoundException => false
+ case x: Throwable => throw x
+ }
+// println(s"isClassLoaded: %s $name".format(if (found) "found" else "didn't find"))
+ found
+ }
+}
diff --git a/src/main/scala/firrtl/util/TestOptions.scala b/src/main/scala/firrtl/util/TestOptions.scala
new file mode 100644
index 00000000..9ee99f8c
--- /dev/null
+++ b/src/main/scala/firrtl/util/TestOptions.scala
@@ -0,0 +1,13 @@
+package firrtl.util
+
+import ClassUtils.isClassLoaded
+
+object TestOptions {
+ // Our timing is inaccurate if we're running tests under coverage.
+ // If any of the classes known to be associated with evaluating coverage are loaded,
+ // assume we're running tests under coverage.
+ // NOTE: We assume we need only ask the class loader that loaded us.
+ // If it was loaded by another class loader (outside of our hierarchy), it wouldn't be available to us.
+ val coverageClasses = List("scoverage.Platform", "com.intellij.rt.coverage.instrumentation.TouchCounter")
+ val accurateTiming = !coverageClasses.exists(isClassLoaded(_))
+}