|
1 | | -// Copyright (C) 2023-2025 Intel Corporation |
| 1 | +// Copyright (C) 2023-2026 Intel Corporation |
2 | 2 | // Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT. |
3 | 3 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
4 | 4 | // This file contains tests for UMF provider API |
@@ -363,6 +363,65 @@ TEST_P(providerInitializeTest, errorPropagation) { |
363 | 363 | ASSERT_EQ(ret, this->GetParam()); |
364 | 364 | } |
365 | 365 |
|
| 366 | +static int *provider_destroy_count_ptr = nullptr; |
| 367 | + |
| 368 | +TEST_F(test, memoryProviderCreateCleansUpWhenGetNameFails) { |
| 369 | + int provider_destroy_count = 0; |
| 370 | + |
| 371 | + struct provider_fail_get_name : public umf_test::provider_base_t { |
| 372 | + ~provider_fail_get_name() override { (*provider_destroy_count_ptr)++; } |
| 373 | + |
| 374 | + umf_result_t get_name(const char **) noexcept { |
| 375 | + return UMF_RESULT_ERROR_UNKNOWN; |
| 376 | + } |
| 377 | + }; |
| 378 | + |
| 379 | + provider_destroy_count_ptr = &provider_destroy_count; |
| 380 | + |
| 381 | + umf_memory_provider_ops_t provider_ops = |
| 382 | + umf_test::providerMakeCOps<provider_fail_get_name, void>(); |
| 383 | + |
| 384 | + umf_memory_provider_handle_t hProvider = nullptr; |
| 385 | + auto ret = umfMemoryProviderCreate(&provider_ops, nullptr, &hProvider); |
| 386 | + |
| 387 | + ASSERT_EQ(ret, UMF_RESULT_ERROR_UNKNOWN); |
| 388 | + ASSERT_EQ(hProvider, nullptr); |
| 389 | + ASSERT_EQ(provider_destroy_count, 1); |
| 390 | + provider_destroy_count_ptr = nullptr; |
| 391 | +} |
| 392 | + |
| 393 | +TEST_F(test, memoryProviderCreateCleansUpWhenPostInitializeFails) { |
| 394 | + int provider_destroy_count = 0; |
| 395 | + |
| 396 | + struct provider_fail_post_initialize : public umf_test::provider_base_t { |
| 397 | + ~provider_fail_post_initialize() override { |
| 398 | + (*provider_destroy_count_ptr)++; |
| 399 | + } |
| 400 | + |
| 401 | + umf_result_t ext_ctl(umf_ctl_query_source_t, const char *name, void *, |
| 402 | + size_t, umf_ctl_query_type_t, va_list) noexcept { |
| 403 | + if (name && std::string(name) == "post_initialize") { |
| 404 | + return UMF_RESULT_ERROR_UNKNOWN; |
| 405 | + } |
| 406 | + |
| 407 | + return UMF_RESULT_ERROR_INVALID_CTL_PATH; |
| 408 | + } |
| 409 | + }; |
| 410 | + |
| 411 | + provider_destroy_count_ptr = &provider_destroy_count; |
| 412 | + |
| 413 | + umf_memory_provider_ops_t provider_ops = |
| 414 | + umf_test::providerMakeCOps<provider_fail_post_initialize, void>(); |
| 415 | + |
| 416 | + umf_memory_provider_handle_t hProvider = nullptr; |
| 417 | + auto ret = umfMemoryProviderCreate(&provider_ops, nullptr, &hProvider); |
| 418 | + |
| 419 | + ASSERT_EQ(ret, UMF_RESULT_ERROR_UNKNOWN); |
| 420 | + ASSERT_EQ(hProvider, nullptr); |
| 421 | + ASSERT_EQ(provider_destroy_count, 1); |
| 422 | + provider_destroy_count_ptr = nullptr; |
| 423 | +} |
| 424 | + |
366 | 425 | // This fixture can be instantiated with any function that accepts void |
367 | 426 | // and returns any of the results listed inside the variant type. |
368 | 427 | struct providerHandleCheck |
|
0 commit comments