Skip to content

SKIP test without behavoir of failing if no tests are executed #3160

@SimeonEhrig

Description

@SimeonEhrig

Description

We use Catch2 to test an abstraction library for CPU/GPU programming named alpaka. In some parts of the test we need to get a device (CPU/GPU). But sometimes the device is not available. This is expected behavior of our library, because you can compile an application with support for Nvidia, AMD and Intel GPUs, ship the application on different systems and check at runtime if the GPU is available. Therefore the tests needs to work in the same way.

At the moment, we use this code snippet:

TEMPLATE_LIST_TEST_CASE("atomicOperationsWorking", "[atomic]", TestApis)
{
    auto cfg = TestType::makeDict();

    auto deviceSpec = cfg[object::deviceSpec];
    auto exec = cfg[object::exec];

    auto devSelector = onHost::makeDeviceSelector(deviceSpec);
    if(!devSelector.isAvailable())
    {
        SUCCEED("No device available for " << deviceSpec.getName());
        return;
    }

    auto device = devSelector.makeDevice(0);
    // ...
}

Since getting a device is a function we use very frequently, I would like to move it into a helper function as follows:

    auto getDevice(auto cfg)
    {
        auto deviceSpec = cfg[object::deviceSpec];
        auto devSelector = onHost::makeDeviceSelector(deviceSpec);
        UNSCOPED_INFO("DeviceSpec: " << getName(deviceSpec));
        UNSCOPED_INFO("API: " << deviceSpec.getApi().getName());

        if(!devSelector.isAvailable())
        {
            SKIP("No device available for " << deviceSpec.getName());
        }

        onHost::Device device = devSelector.makeDevice(0);
        UNSCOPED_INFO("Device: " << device.getName());
        return device;
    }

The problem is that we have test files that contain only tests that rely on a device, and we have test files that also contain tests that do not require a device and are intended to test something device-independent. In the first cases, ctest fails if no device is available. If I set the argument --allow-running-no-tests for all test, it is possible that in the second case tests passes, which does nothing.

I could set the argument --allow-running-no-tests for specific test executables but to be honest, I think this really error prone and we have some developers and contributors, which are not familiar with such Catch2 details.

Is is possible to implement an SKIP macro which does not trigger the no-running-test check? It does not need to be part of Catch2. I'm also fine to implement it as test helper for our library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions