Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenCL tests fail gracefully if the OpenCL library can't be loaded #116

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions src/test/scala/test_util/package.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import opencl.executor.Executor
import org.scalatest.BeforeAndAfter
import org.scalactic.source.Position
import org.scalatest.{BeforeAndAfter, Tag}
import org.scalatest.matchers.should.Matchers
import org.scalatest.funsuite.AnyFunSuite
import util.{AssertSame, Time, TimeSpan}
Expand All @@ -8,13 +9,39 @@ package object test_util {
abstract class Tests extends AnyFunSuite with Matchers

abstract class TestsWithExecutor extends Tests with BeforeAndAfter {
var openclIsAvailable = true
before {
Executor.loadLibrary()
Executor.init()
try {
Executor.loadLibrary()
Executor.init()
} catch {
case _: UnsatisfiedLinkError =>
openclIsAvailable = false
}
}

after {
Executor.shutdown()
try {
Executor.shutdown()
} catch {
case _: Throwable =>
}
}

override protected def test(testName: String, testTags: Tag*)
(testFun: => Any)
(implicit pos: Position): Unit = {
super.test(testName, testTags:_*) {
// try to execute test ...
try {
testFun
} catch {
// ... only if execution fails due to a unsatisfied link error we
// enforce the assumption that OpenCL must be available.
case _: UnsatisfiedLinkError =>
assume(openclIsAvailable)
}
}
}
}

Expand Down