Files
TheRock/rocm-systems/projects/hipfile/test/amd_detail/configuration.cpp
T
derek.holloway 7502bf64a4
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
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

240 lines
7.6 KiB
C++

/* Copyright (c) Advanced Micro Devices, Inc. All rights reserved.
*
* SPDX-License-Identifier: MIT
*/
#include "configuration.h"
#include "environment.h"
#include "hipfile-warnings.h"
#include "mhip.h"
#include "msys.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <optional>
#include <string>
using namespace hipFile;
using namespace testing;
using namespace std;
HIPFILE_WARN_NO_GLOBAL_CTOR_OFF
struct HipFileConfiguration : public Test {
StrictMock<MSys> msys;
StrictMock<MHip> mhip;
void expect_configuration_fastpath(const char *hipfile_force_compat_mode,
void *hipAmdFileRead = reinterpret_cast<void *>(0xDEADBEEF),
void *hipAmdFileWrite = reinterpret_cast<void *>(0xCAFEBABE))
{
EXPECT_CALL(msys, getenv(StrEq(hipFile::Environment::FORCE_COMPAT_MODE)))
.WillOnce(Return(const_cast<char *>(hipfile_force_compat_mode)));
EXPECT_CALL(mhip, hipRuntimeGetVersion).Times(2);
EXPECT_CALL(mhip, hipGetProcAddress(StrEq("hipAmdFileRead"), _, _, _))
.WillOnce(Return(hipAmdFileRead));
EXPECT_CALL(mhip, hipGetProcAddress(StrEq("hipAmdFileWrite"), _, _, _))
.WillOnce(Return(hipAmdFileWrite));
}
void expect_configuration_fallback(const char *hipfile_force_compat_mode,
const char *hipfile_allow_compat_mode)
{
EXPECT_CALL(msys, getenv(StrEq(hipFile::Environment::FORCE_COMPAT_MODE)))
.WillOnce(Return(const_cast<char *>(hipfile_force_compat_mode)));
EXPECT_CALL(msys, getenv(StrEq(hipFile::Environment::ALLOW_COMPAT_MODE)))
.WillOnce(Return(const_cast<char *>(hipfile_allow_compat_mode)));
}
void expect_configuration_statslevel(const char *hipfile_stats_level)
{
EXPECT_CALL(msys, getenv(StrEq(hipFile::Environment::STATS_LEVEL)))
.WillOnce(Return(const_cast<char *>(hipfile_stats_level)));
}
void expect_configuration_unsupported_file_systems(const char *hipfile_unsupported_file_systems)
{
EXPECT_CALL(msys, getenv(StrEq(hipFile::Environment::UNSUPPORTED_FILE_SYSTEMS)))
.WillOnce(Return(const_cast<char *>(hipfile_unsupported_file_systems)));
}
};
TEST_F(HipFileConfiguration, FastpathEnabledIfForceCompatModeEnvironmentVariableIsNotSet)
{
expect_configuration_fastpath(nullptr);
ASSERT_TRUE(Configuration().fastpath());
}
TEST_F(HipFileConfiguration, FastpathEnabledIfForceCompatModeEnvironmentVariableIsInvalid)
{
expect_configuration_fastpath("not-a-bool");
ASSERT_TRUE(Configuration().fastpath());
}
TEST_F(HipFileConfiguration, FastpathEnabledIfForceCompatModeEnvironmentVariableIsFalse)
{
expect_configuration_fastpath("false");
ASSERT_TRUE(Configuration().fastpath());
}
TEST_F(HipFileConfiguration, OverrideEnabledFastpathBackend)
{
Configuration config{};
expect_configuration_fastpath("false");
ASSERT_TRUE(config.fastpath());
config.fastpath(false);
ASSERT_FALSE(config.fastpath());
}
TEST_F(HipFileConfiguration, FastpathDisabledIfForceCompatModeEnvironmentVariableIsTrue)
{
expect_configuration_fastpath("true");
ASSERT_FALSE(Configuration().fastpath());
}
TEST_F(HipFileConfiguration, FastpathDisabledIfHipAmdFileReadIsNotFound)
{
expect_configuration_fastpath(nullptr, nullptr);
ASSERT_FALSE(Configuration().fastpath());
}
TEST_F(HipFileConfiguration, FastpathDisabledIfHipAmdFileWriteIsNotFound)
{
expect_configuration_fastpath(nullptr, reinterpret_cast<void *>(0x1), nullptr);
ASSERT_FALSE(Configuration().fastpath());
}
TEST_F(HipFileConfiguration, OverrideDisabledFastpathBackend)
{
Configuration config{};
expect_configuration_fastpath("true");
ASSERT_FALSE(config.fastpath());
config.fastpath(true);
ASSERT_TRUE(config.fastpath());
}
TEST_F(HipFileConfiguration, CantOverrideDisabledFastpathBackendIfHipAmdFileReadIsNotAvailable)
{
Configuration config{};
expect_configuration_fastpath(nullptr, nullptr);
ASSERT_FALSE(config.fastpath());
config.fastpath(true);
ASSERT_FALSE(config.fastpath());
}
TEST_F(HipFileConfiguration, CantOverrideDisabledFastpathBackendIfHipAmdFileWriteIsNotAvailable)
{
Configuration config{};
expect_configuration_fastpath(nullptr, reinterpret_cast<void *>(0x1), nullptr);
ASSERT_FALSE(config.fastpath());
config.fastpath(true);
ASSERT_FALSE(config.fastpath());
}
TEST_F(HipFileConfiguration, FallbackEnabledIfAllowCompatModeEnvironmentVariableIsNotSet)
{
expect_configuration_fallback(nullptr, nullptr);
ASSERT_TRUE(Configuration().fallback());
}
TEST_F(HipFileConfiguration, FallbackEnabledIfAllowCompatModeEnvironmentVariableIsInvalid)
{
expect_configuration_fallback(nullptr, "not-a-bool");
ASSERT_TRUE(Configuration().fallback());
}
TEST_F(HipFileConfiguration, FallbackEnabledIfAllowCompatModeEnvironmentVariableIsTrue)
{
expect_configuration_fallback(nullptr, "true");
ASSERT_TRUE(Configuration().fallback());
}
TEST_F(HipFileConfiguration, OverrideEnabledFallbackBackend)
{
Configuration config{};
expect_configuration_fallback(nullptr, nullptr);
ASSERT_TRUE(config.fallback());
config.fallback(false);
ASSERT_FALSE(config.fallback());
}
TEST_F(HipFileConfiguration, FallbackDisabledIfAllowCompatModeEnvironmentVariableIsFalse)
{
expect_configuration_fallback(nullptr, "false");
ASSERT_FALSE(Configuration().fallback());
}
TEST_F(HipFileConfiguration, OverrideDisabledFallbackBackend)
{
Configuration config{};
expect_configuration_fallback(nullptr, "false");
ASSERT_FALSE(config.fallback());
config.fallback(true);
ASSERT_TRUE(config.fallback());
}
TEST_F(HipFileConfiguration, FallbackForcedOnWhenForceCompatTrueAndAllowCompatFalse)
{
// HIPFILE_FORCE_COMPAT_MODE=true + HIPFILE_ALLOW_COMPAT_MODE=false would disable both backends.
// The guard must force the fallback path back on.
expect_configuration_fallback("true", "false");
ASSERT_TRUE(Configuration().fallback());
}
TEST_F(HipFileConfiguration, FallbackEnabledWhenForceCompatTrueAndAllowCompatTrue)
{
// FORCE=true + ALLOW=true: forced fallback, unchanged behavior.
expect_configuration_fallback("true", "true");
ASSERT_TRUE(Configuration().fallback());
}
TEST_F(HipFileConfiguration, StatsLevelEnvironmentVariableIsNotSet)
{
expect_configuration_statslevel(nullptr);
ASSERT_EQ(1, Configuration().statsLevel());
}
TEST_F(HipFileConfiguration, StatsLevelEnvironmentVariableIsInvalid)
{
expect_configuration_statslevel("not-a-number");
ASSERT_EQ(1, Configuration().statsLevel());
}
TEST_F(HipFileConfiguration, StatsLevelEnvironmentVariableIsSet)
{
expect_configuration_statslevel("2");
ASSERT_EQ(2, Configuration().statsLevel());
}
TEST_F(HipFileConfiguration, UnsupportedFilesystemsDisabledIfEnvironmentVariableIsNotSet)
{
expect_configuration_unsupported_file_systems(nullptr);
ASSERT_FALSE(Configuration().unsupportedFileSystems());
}
TEST_F(HipFileConfiguration, UnsupportedFilesystemsDisabledIfEnvironmentVariableIsInvalid)
{
expect_configuration_unsupported_file_systems("not-a-bool");
ASSERT_FALSE(Configuration().unsupportedFileSystems());
}
TEST_F(HipFileConfiguration, UnsupportedFilesystemsEnabledIfEnvironmentVariableIsTrue)
{
expect_configuration_unsupported_file_systems("true");
ASSERT_TRUE(Configuration().unsupportedFileSystems());
}
TEST_F(HipFileConfiguration, UnsupportedFilesystemsDisabledIfEnvironmentVariableIsFalse)
{
expect_configuration_unsupported_file_systems("false");
ASSERT_FALSE(Configuration().unsupportedFileSystems());
}
HIPFILE_WARN_NO_GLOBAL_CTOR_ON