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
101 lines
2.7 KiB
C++
101 lines
2.7 KiB
C++
/*
|
|
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#include <hip_test_common.hh>
|
|
#include <hip/hip_runtime_api.h>
|
|
|
|
#if defined(__linux__)
|
|
#include <cstdlib>
|
|
#include <dirent.h>
|
|
|
|
static int CountOpenFds() {
|
|
DIR* d = opendir("/proc/self/fd");
|
|
REQUIRE(d != nullptr);
|
|
int dir_fd = dirfd(d);
|
|
int count = 0;
|
|
while (struct dirent* ent = readdir(d)) {
|
|
if (ent->d_name[0] == '.') continue;
|
|
int fd = atoi(ent->d_name);
|
|
if (fd == dir_fd) continue;
|
|
++count;
|
|
}
|
|
closedir(d);
|
|
return count;
|
|
}
|
|
|
|
HIP_TEST_CASE(Unit_hipModuleLoad_Positive_NoFdLeak) {
|
|
HIP_CHECK(hipFree(nullptr));
|
|
|
|
{
|
|
hipModule_t warmup = nullptr;
|
|
HIP_CHECK(hipModuleLoad(&warmup, "empty_module.code"));
|
|
HIP_CHECK(hipModuleUnload(warmup));
|
|
}
|
|
|
|
const int baseline = CountOpenFds();
|
|
|
|
{
|
|
hipModule_t module = nullptr;
|
|
HIP_CHECK(hipModuleLoad(&module, "empty_module.code"));
|
|
REQUIRE(module != nullptr);
|
|
const int after_load = CountOpenFds();
|
|
INFO("Open FDs before load: " << baseline
|
|
<< ", after load (before unload): " << after_load);
|
|
REQUIRE(after_load == baseline);
|
|
HIP_CHECK(hipModuleUnload(module));
|
|
}
|
|
|
|
constexpr int kIterations = 32;
|
|
for (int i = 0; i < kIterations; ++i) {
|
|
hipModule_t module = nullptr;
|
|
HIP_CHECK(hipModuleLoad(&module, "empty_module.code"));
|
|
REQUIRE(module != nullptr);
|
|
HIP_CHECK(hipModuleUnload(module));
|
|
}
|
|
const int after_cycles = CountOpenFds();
|
|
INFO("Open FDs before: " << baseline << ", after " << kIterations
|
|
<< " load/unload cycles: " << after_cycles);
|
|
REQUIRE(after_cycles == baseline);
|
|
}
|
|
#endif
|
|
|
|
HIP_TEST_CASE(Unit_hipModuleLoad_Positive_Basic) {
|
|
HIP_CHECK(hipFree(nullptr));
|
|
hipModule_t module = nullptr;
|
|
HIP_CHECK(hipModuleLoad(&module, "empty_module.code"));
|
|
REQUIRE(module != nullptr);
|
|
HIP_CHECK(hipModuleUnload(module));
|
|
}
|
|
|
|
HIP_TEST_CASE(Unit_hipModuleLoad_Negative_Parameters) {
|
|
HIP_CHECK(hipFree(nullptr));
|
|
hipModule_t module;
|
|
|
|
SECTION("module == nullptr") {
|
|
HIP_CHECK_ERROR(hipModuleLoad(nullptr, "empty_module.code"), hipErrorInvalidValue);
|
|
}
|
|
|
|
SECTION("fname == nullptr") {
|
|
HIP_CHECK_ERROR(hipModuleLoad(&module, nullptr), hipErrorInvalidValue);
|
|
}
|
|
|
|
SECTION("fname == empty string") {
|
|
HIP_CHECK_ERROR(hipModuleLoad(&module, ""), hipErrorInvalidValue);
|
|
}
|
|
|
|
SECTION("fname == non existent file") {
|
|
HIP_CHECK_ERROR(hipModuleLoad(&module, "non existent file"), hipErrorFileNotFound);
|
|
}
|
|
}
|
|
|
|
HIP_TEST_CASE(Unit_hipModuleLoad_Negative_Load_From_A_File_That_Is_Not_A_Module) {
|
|
HIP_CHECK(hipFree(nullptr));
|
|
hipModule_t module;
|
|
|
|
HIP_CHECK_ERROR(hipModuleLoad(&module, "not_a_module.txt"), hipErrorInvalidImage);
|
|
HIP_CHECK_ERROR(hipModuleLoad(&module, "empty_file.txt"), hipErrorInvalidImage);
|
|
}
|