CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
229 lines
7.9 KiB
C++
229 lines
7.9 KiB
C++
/*
|
|
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#include <hip_test_common.hh>
|
|
|
|
#include "user_object_common.hh"
|
|
|
|
/*
|
|
Functional Test for API - hipUserObjectCreate
|
|
1) Call hipUserObjectCreate once and release it by calling hipUserObjectRelease
|
|
2) Call hipUserObjectCreate refCount as X and release it by calling
|
|
hipUserObjectRelease with same refCount.
|
|
3) Call hipUserObjectCreate, retain it by calling hipUserObjectRetain
|
|
and release it by calling hipUserObjectRelease twice.
|
|
4) Call hipUserObjectCreate with refCount as X, retain it by calling
|
|
hipUserObjectRetain with count as Y and release it by calling
|
|
hipUserObjectRelease with count as X+Y.
|
|
*/
|
|
|
|
/* 1) Call hipUserObjectCreate once and release it by
|
|
calling hipUserObjectRelease */
|
|
static void hipUserObjectCreate_Functional_1(void* object, void destroyObj(void*)) {
|
|
hipUserObject_t hObject;
|
|
HIP_CHECK(hipUserObjectCreate(&hObject, object, destroyObj, 1, hipUserObjectNoDestructorSync));
|
|
REQUIRE(hObject != nullptr);
|
|
HIP_CHECK(hipUserObjectRelease(hObject));
|
|
}
|
|
|
|
HIP_TEST_CASE(Unit_hipUserObjectCreate_Functional_1) {
|
|
SECTION("Called with int Object") {
|
|
int* object = new int();
|
|
REQUIRE(object != nullptr);
|
|
hipUserObjectCreate_Functional_1(object, destroyIntObj);
|
|
}
|
|
SECTION("Called with float Object") {
|
|
float* object = new float();
|
|
REQUIRE(object != nullptr);
|
|
hipUserObjectCreate_Functional_1(object, destroyFloatObj);
|
|
}
|
|
SECTION("Called with Class Object") {
|
|
BoxClass* object = new BoxClass();
|
|
REQUIRE(object != nullptr);
|
|
hipUserObjectCreate_Functional_1(object, destroyClassObj);
|
|
}
|
|
SECTION("Called with Struct Object") {
|
|
BoxStruct* object = new BoxStruct();
|
|
REQUIRE(object != nullptr);
|
|
hipUserObjectCreate_Functional_1(object, destroyStructObj);
|
|
}
|
|
}
|
|
|
|
/* 2) Call hipUserObjectCreate refCount as X and release it by
|
|
calling hipUserObjectRelease with same refCount. */
|
|
static void hipUserObjectCreate_Functional_2(void* object, void destroyObj(void*)) {
|
|
int refCount = 5;
|
|
hipUserObject_t hObject;
|
|
HIP_CHECK(
|
|
hipUserObjectCreate(&hObject, object, destroyObj, refCount, hipUserObjectNoDestructorSync));
|
|
REQUIRE(hObject != nullptr);
|
|
HIP_CHECK(hipUserObjectRelease(hObject, refCount));
|
|
}
|
|
|
|
HIP_TEST_CASE(Unit_hipUserObjectCreate_Functional_2) {
|
|
SECTION("Called with int Object") {
|
|
int* object = new int();
|
|
REQUIRE(object != nullptr);
|
|
hipUserObjectCreate_Functional_2(object, destroyIntObj);
|
|
}
|
|
SECTION("Called with float Object") {
|
|
float* object = new float();
|
|
REQUIRE(object != nullptr);
|
|
hipUserObjectCreate_Functional_2(object, destroyFloatObj);
|
|
}
|
|
SECTION("Called with Class Object") {
|
|
BoxClass* object = new BoxClass();
|
|
REQUIRE(object != nullptr);
|
|
hipUserObjectCreate_Functional_2(object, destroyClassObj);
|
|
}
|
|
SECTION("Called with Struct Object") {
|
|
BoxStruct* object = new BoxStruct();
|
|
REQUIRE(object != nullptr);
|
|
hipUserObjectCreate_Functional_2(object, destroyStructObj);
|
|
}
|
|
}
|
|
|
|
/* 3) Call hipUserObjectCreate, retain it by calling hipUserObjectRetain
|
|
and release it by calling hipUserObjectRelease twice. */
|
|
static void hipUserObjectCreate_Functional_3(void* object, void destroyObj(void*)) {
|
|
hipUserObject_t hObject;
|
|
HIP_CHECK(hipUserObjectCreate(&hObject, object, destroyObj, 1, hipUserObjectNoDestructorSync));
|
|
REQUIRE(hObject != nullptr);
|
|
HIP_CHECK(hipUserObjectRetain(hObject));
|
|
HIP_CHECK(hipUserObjectRelease(hObject));
|
|
HIP_CHECK(hipUserObjectRelease(hObject));
|
|
}
|
|
|
|
HIP_TEST_CASE(Unit_hipUserObjectCreate_Functional_3) {
|
|
SECTION("Called with int Object") {
|
|
int* object = new int();
|
|
REQUIRE(object != nullptr);
|
|
hipUserObjectCreate_Functional_3(object, destroyIntObj);
|
|
}
|
|
SECTION("Called with float Object") {
|
|
float* object = new float();
|
|
REQUIRE(object != nullptr);
|
|
hipUserObjectCreate_Functional_3(object, destroyFloatObj);
|
|
}
|
|
SECTION("Called with Class Object") {
|
|
BoxClass* object = new BoxClass();
|
|
REQUIRE(object != nullptr);
|
|
hipUserObjectCreate_Functional_3(object, destroyClassObj);
|
|
}
|
|
SECTION("Called with Struct Object") {
|
|
BoxStruct* object = new BoxStruct();
|
|
REQUIRE(object != nullptr);
|
|
hipUserObjectCreate_Functional_3(object, destroyStructObj);
|
|
}
|
|
}
|
|
|
|
/* 4) Call hipUserObjectCreate with refCount as X, retain it by calling
|
|
hipUserObjectRetain with count as Y and release it by calling
|
|
hipUserObjectRelease with count as X+Y. */
|
|
static void hipUserObjectCreate_Functional_4(void* object, void destroyObj(void*)) {
|
|
int refCount = 5;
|
|
int refCountRetain = 8;
|
|
hipUserObject_t hObject;
|
|
HIP_CHECK(
|
|
hipUserObjectCreate(&hObject, object, destroyObj, refCount, hipUserObjectNoDestructorSync));
|
|
REQUIRE(hObject != nullptr);
|
|
HIP_CHECK(hipUserObjectRetain(hObject, refCountRetain));
|
|
HIP_CHECK(hipUserObjectRelease(hObject, refCount + refCountRetain));
|
|
}
|
|
|
|
HIP_TEST_CASE(Unit_hipUserObjectCreate_Functional_4) {
|
|
SECTION("Called with int Object") {
|
|
int* object = new int();
|
|
REQUIRE(object != nullptr);
|
|
hipUserObjectCreate_Functional_4(object, destroyIntObj);
|
|
}
|
|
SECTION("Called with float Object") {
|
|
float* object = new float();
|
|
REQUIRE(object != nullptr);
|
|
hipUserObjectCreate_Functional_4(object, destroyFloatObj);
|
|
}
|
|
SECTION("Called with Class Object") {
|
|
BoxClass* object = new BoxClass();
|
|
REQUIRE(object != nullptr);
|
|
hipUserObjectCreate_Functional_4(object, destroyClassObj);
|
|
}
|
|
SECTION("Called with Struct Object") {
|
|
BoxStruct* object = new BoxStruct();
|
|
REQUIRE(object != nullptr);
|
|
hipUserObjectCreate_Functional_4(object, destroyStructObj);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Negative Test for API - hipUserObjectCreate
|
|
1) Pass User Object as nullptr
|
|
2) Pass object as nullptr
|
|
3) Pass Callback function as nullptr
|
|
4) Pass initialRefcount as 0
|
|
5) Pass initialRefcount as INT_MAX
|
|
6) Pass flag other than hipUserObjectNoDestructorSync
|
|
*/
|
|
HIP_TEST_CASE(Unit_hipUserObjectCreate_Negative) {
|
|
int* object = new int();
|
|
REQUIRE(object != nullptr);
|
|
|
|
hipUserObject_t hObject;
|
|
SECTION("Pass User Object as nullptr") {
|
|
HIP_CHECK_ERROR(
|
|
hipUserObjectCreate(nullptr, object, destroyIntObj, 1, hipUserObjectNoDestructorSync),
|
|
hipErrorInvalidValue);
|
|
delete object;
|
|
}
|
|
SECTION("Pass object as nullptr") {
|
|
HIP_CHECK(
|
|
hipUserObjectCreate(&hObject, nullptr, destroyIntObj, 1, hipUserObjectNoDestructorSync));
|
|
HIP_CHECK(hipUserObjectRelease(hObject, 1));
|
|
delete object;
|
|
}
|
|
SECTION("Pass Callback function as nullptr") {
|
|
HIP_CHECK_ERROR(
|
|
hipUserObjectCreate(&hObject, object, nullptr, 1, hipUserObjectNoDestructorSync),
|
|
hipErrorInvalidValue);
|
|
delete object;
|
|
}
|
|
SECTION("Pass initialRefcount as 0") {
|
|
HIP_CHECK_ERROR(
|
|
hipUserObjectCreate(&hObject, object, destroyIntObj, 0, hipUserObjectNoDestructorSync),
|
|
hipErrorInvalidValue);
|
|
delete object;
|
|
}
|
|
SECTION("Pass initialRefcount as INT_MAX") {
|
|
HIP_CHECK(hipUserObjectCreate(&hObject, object, destroyIntObj, INT_MAX,
|
|
hipUserObjectNoDestructorSync));
|
|
HIP_CHECK(hipUserObjectRelease(hObject, INT_MAX));
|
|
}
|
|
SECTION("Pass flag other than hipUserObjectNoDestructorSync") {
|
|
HIP_CHECK_ERROR(hipUserObjectCreate(&hObject, object, destroyIntObj, 1, hipUserObjectFlags(9)),
|
|
hipErrorInvalidValue);
|
|
delete object;
|
|
}
|
|
}
|
|
|
|
HIP_TEST_CASE(Unit_hipUserObj_Negative_Test) {
|
|
int* object = new int();
|
|
REQUIRE(object != nullptr);
|
|
|
|
hipUserObject_t hObject;
|
|
|
|
// Create a new hObject with 2 reference
|
|
HIP_CHECK(hipUserObjectCreate(&hObject, object, destroyIntObj, 2, hipUserObjectNoDestructorSync));
|
|
REQUIRE(hObject != nullptr);
|
|
|
|
// Release more than created. Will not release the references.
|
|
HIP_CHECK(hipUserObjectRelease(hObject, 4));
|
|
|
|
// Retain reference
|
|
HIP_CHECK(hipUserObjectRetain(hObject, 1));
|
|
|
|
// Release all the references pending
|
|
HIP_CHECK(hipUserObjectRelease(hObject, 3));
|
|
}
|