ut
ut copied to clipboard
Tests fail due to global instances destroyed
In some situations it's important that tests can be executed while other static objects are not yet destroyed such as when using NVCC-compiled cuda kernels. Running tests after main finishes causes problems.
Expected Behavior
Updating from 1.1.8 to 2.0.1 should keep cuda tests passing or provide a way to execute tests from main().
Actual Behavior
Using an empty main executes cuda tests after the cuda context has ended. Alternatively, executing the runner from main does not read command line arguments.
Steps to Reproduce the Problem
- Write a simple cuda kernel and test the output:
// helloworld.cu
#include <cuda.h>
#include <cstdio>
__global__ void g_cuda_hello(int* data)
{
std::printf("Hello from Cuda! %i\n", *data);
*data = 1;
}
__host__ int cuda_hello(int data)
{
int h_data = data;
int* d_data = nullptr;
cudaMalloc((void**)&d_data, sizeof(int));
cudaMemcpy(d_data, &h_data, sizeof(int), cudaMemcpyKind::cudaMemcpyHostToDevice);
g_cuda_hello<<<1,1>>>(d_data);
cudaMemcpy(&h_data, d_data, sizeof(int), cudaMemcpyKind::cudaMemcpyDeviceToHost);
cudaFree(d_data);
return h_data;
}
// test.cpp
#include <cuda_runtime.h>
#include <boost/ut.hpp>
__host__ int cuda_hello(int data);
using namespace boost::ut;
using namespace std::literals::chrono_literals;
"cuda_hello"_test = [] {
expect(cuda_hello(0) == 1_i);
};
int main(int argc, char* argv[])
{
return 0;
}
- Execute with an empty main function and tests fail.
or
- Execute calling
boost::ut::cfg<boost::ut::override>.run();from main and the test passes, but arguments such--helpdo nothing.
Specifications
- Version: 2.0.1
- Platform: x86_64, Manjaro Linux
- Subsystem: clang++ 16.0.6
https://github.com/boost-ext/ut/pull/572 resolved the issue