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

Tests fail due to global instances destroyed #611

Open
calgray opened this issue Jan 9, 2024 · 1 comment
Open

Tests fail due to global instances destroyed #611

calgray opened this issue Jan 9, 2024 · 1 comment

Comments

@calgray
Copy link

calgray commented Jan 9, 2024

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

  1. 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;
}
  1. Execute with an empty main function and tests fail.

or

  1. Execute calling boost::ut::cfg<boost::ut::override>.run(); from main and the test passes, but arguments such --help do nothing.

Specifications

  • Version: 2.0.1
  • Platform: x86_64, Manjaro Linux
  • Subsystem: clang++ 16.0.6
@calgray calgray changed the title Test execution fails due to global instances destroyed Tests fail due to global instances destroyed Jan 9, 2024
@calgray
Copy link
Author

calgray commented Mar 2, 2024

#572 resolved the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant