diff --git a/tests/unit/active/test_async_op_cuda.cc b/tests/unit/active/test_async_op_cuda.cc index fd9de7f6be..6236c3ba2a 100644 --- a/tests/unit/active/test_async_op_cuda.cc +++ b/tests/unit/active/test_async_op_cuda.cc @@ -57,14 +57,18 @@ using TestAsyncOp = TestParallelHarness; using MyMsg = Message; +inline void checkCudaErrors( + cudaError_t err, std::string const& additionalInfo, + bool skipOnFailure = false +) { + auto errorMsg = fmt::format( + "{} failed with error -> {}\n", additionalInfo, cudaGetErrorString(err)); + + if (cudaSuccess != err and skipOnFailure) { + GTEST_SKIP() << errorMsg; + } -inline void checkCudaErrors(cudaError_t err, std::string const& additionalInfo) { - vtAbortIf( - cudaSuccess != err, - fmt::format( - "{} failed with error -> {}\n", additionalInfo, cudaGetErrorString(err) - ) - ); + vtAbortIf(cudaSuccess != err, errorMsg); } __global__ void kernel(double* dst, double setVal) { @@ -79,9 +83,11 @@ struct CUDAGroup { CUDAGroup() { auto const nBytes = dataSize_ * sizeof(double); + // If first malloc fails, there's probably something wrong with CUDA env + // so call GTEST_SKIP instead of failing the test checkCudaErrors( cudaMalloc((void**)&dataDevicePointer1_, nBytes), - "cudaMalloc(dataDevicePointer1_)" + "cudaMalloc(dataDevicePointer1_)", true ); checkCudaErrors(