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

Fix failing stream test with a debug-only death test #934

Merged
merged 1 commit into from
Dec 14, 2021
Merged
Changes from all commits
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
33 changes: 22 additions & 11 deletions tests/cuda_stream_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <cuda_runtime_api.h>

#include <gtest/gtest-death-test.h>
#include <gtest/gtest.h>

struct CudaStreamTest : public ::testing::Test {
Expand Down Expand Up @@ -55,17 +56,6 @@ TEST_F(CudaStreamTest, MoveConstructor)
EXPECT_EQ(stream_b, view_a);
}

TEST_F(CudaStreamTest, TestSyncNoThrow)
{
rmm::cuda_stream stream_a;
// Cannot test this in debug mode because it will cause an assertion.
// But need this test to get full code coverage
#ifdef NDEBUG
cudaStreamDestroy(static_cast<cudaStream_t>(stream_a));
#endif
EXPECT_NO_THROW(stream_a.synchronize_no_throw());
}

TEST_F(CudaStreamTest, TestStreamViewOstream)
{
rmm::cuda_stream stream_a;
Expand All @@ -88,3 +78,24 @@ TEST_F(CudaStreamTest, TestStreamViewDestructor)
auto view = std::make_shared<rmm::cuda_stream_view>(rmm::cuda_stream_per_thread);
view->synchronize();
}

TEST_F(CudaStreamTest, TestSyncNoThrow)
{
rmm::cuda_stream stream_a;
EXPECT_NO_THROW(stream_a.synchronize_no_throw());
}

#ifndef NDEBUG
using CudaStreamDeathTest = CudaStreamTest;

TEST_F(CudaStreamDeathTest, TestSyncNoThrow)
{
auto test = []() {
rmm::cuda_stream stream_a;
cudaStreamDestroy(static_cast<cudaStream_t>(stream_a));
// should assert here or in `~cuda_stream()`
stream_a.synchronize_no_throw();
};
EXPECT_DEATH(test(), "Assertion");
}
#endif