mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-30 01:35:20 +08:00
- This allows for ExecutionEnvironment to live longer then platform after its global destruction - Device adds references to ExecutionEnvironment after creation - When device is destroyed it removes the dependency causing the cleanup - Platform upon destruction no longer destroys the device, but decrements the internal ref count. Change-Id: I22593ea44b2b50e3416575a9e97e3ce0a1f8b5c0
72 lines
3.2 KiB
C++
72 lines
3.2 KiB
C++
/*
|
|
* Copyright (c) 2018, Intel Corporation
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
* to deal in the Software without restriction, including without limitation
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included
|
|
* in all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
|
|
#include "test.h"
|
|
#include "runtime/device/device.h"
|
|
#include "runtime/execution_environment/execution_environment.h"
|
|
#include "runtime/platform/platform.h"
|
|
|
|
using namespace OCLRT;
|
|
|
|
TEST(ExecutionEnvironment, givenDefaultConstructorWhenItIsCalledThenExecutionEnvironmentHasInitialRefCountZero) {
|
|
ExecutionEnvironment environment;
|
|
EXPECT_EQ(0, environment.getRefInternalCount());
|
|
EXPECT_EQ(0, environment.getRefApiCount());
|
|
}
|
|
|
|
TEST(ExecutionEnvironment, givenPlatformWhenItIsConstructedThenItCretesExecutionEnvironmentWithOneRefCountInternal) {
|
|
std::unique_ptr<Platform> platform(new Platform);
|
|
ASSERT_NE(nullptr, platform->peekExecutionEnvironment());
|
|
EXPECT_EQ(1, platform->peekExecutionEnvironment()->getRefInternalCount());
|
|
}
|
|
|
|
TEST(ExecutionEnvironment, givenPlatformAndExecutionEnvironmentWithRefCountsWhenPlatformIsDestroyedThenExecutionEnvironmentIsNotDeleted) {
|
|
std::unique_ptr<Platform> platform(new Platform);
|
|
auto executionEnvironment = platform->peekExecutionEnvironment();
|
|
executionEnvironment->incRefInternal();
|
|
platform.reset();
|
|
EXPECT_EQ(1, executionEnvironment->getRefInternalCount());
|
|
executionEnvironment->decRefInternal();
|
|
}
|
|
|
|
TEST(ExecutionEnvironment, givenPlatformWhenItIsInitializedAndCreatesDevicesThenThoseDevicesAddRefcountsToExecutionEnvironment) {
|
|
std::unique_ptr<Platform> platform(new Platform);
|
|
auto executionEnvironment = platform->peekExecutionEnvironment();
|
|
|
|
platform->initialize();
|
|
EXPECT_LT(0u, platform->getNumDevices());
|
|
EXPECT_EQ(static_cast<int32_t>(1u + platform->getNumDevices()), executionEnvironment->getRefInternalCount());
|
|
}
|
|
|
|
TEST(ExecutionEnvironment, givenDeviceThatHaveRefferencesAfterPlatformIsDestroyedThenDeviceIsStillUsable) {
|
|
std::unique_ptr<Platform> platform(new Platform);
|
|
auto executionEnvironment = platform->peekExecutionEnvironment();
|
|
platform->initialize();
|
|
auto device = platform->getDevice(0);
|
|
EXPECT_EQ(1, device->getRefInternalCount());
|
|
device->incRefInternal();
|
|
platform.reset(nullptr);
|
|
EXPECT_EQ(1, device->getRefInternalCount());
|
|
EXPECT_EQ(1, executionEnvironment->getRefInternalCount());
|
|
|
|
device->decRefInternal();
|
|
} |