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
138 lines
4.2 KiB
C++
138 lines
4.2 KiB
C++
// Copyright (c) 2026 Advanced Micro Devices, Inc.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
/// @file rocminfo_test.cpp
|
|
/// @brief Verifies that rocminfo runs successfully against the simulated GPU
|
|
/// via the rocjitsu CLI launcher and reports expected topology.
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <array>
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <filesystem>
|
|
#include <string>
|
|
#include <system_error>
|
|
|
|
namespace {
|
|
|
|
struct ProcessResult {
|
|
std::string output;
|
|
int exit_code;
|
|
};
|
|
|
|
struct TestPaths {
|
|
std::string rocjitsu_bin = ROCJITSU_BIN;
|
|
std::string config_path = RJ_CONFIG_PATH;
|
|
};
|
|
|
|
std::filesystem::path resolve_relative_to_exe(const std::filesystem::path &exe_dir,
|
|
const char *path) {
|
|
std::filesystem::path candidate(path);
|
|
if (!candidate.is_absolute())
|
|
candidate = exe_dir / candidate;
|
|
return candidate.lexically_normal();
|
|
}
|
|
|
|
std::filesystem::path current_exe_dir() {
|
|
std::error_code ec;
|
|
std::filesystem::path exe = std::filesystem::read_symlink("/proc/self/exe", ec);
|
|
if (ec)
|
|
return {};
|
|
return exe.parent_path();
|
|
}
|
|
|
|
bool installed_paths_exist(const TestPaths &paths) {
|
|
return std::filesystem::exists(paths.rocjitsu_bin) && std::filesystem::exists(paths.config_path);
|
|
}
|
|
|
|
TestPaths installed_paths(const std::filesystem::path &exe_dir) {
|
|
return {
|
|
resolve_relative_to_exe(exe_dir, RJ_INSTALLED_ROCJITSU_BIN).string(),
|
|
resolve_relative_to_exe(exe_dir, RJ_INSTALLED_CONFIG_PATH).string(),
|
|
};
|
|
}
|
|
|
|
const TestPaths &test_paths() {
|
|
static TestPaths paths = [] {
|
|
std::filesystem::path exe_dir = current_exe_dir();
|
|
if (!exe_dir.empty()) {
|
|
TestPaths installed = installed_paths(exe_dir);
|
|
if (installed_paths_exist(installed))
|
|
return installed;
|
|
}
|
|
return TestPaths{};
|
|
}();
|
|
return paths;
|
|
}
|
|
|
|
ProcessResult run_command(const std::string &cmd) {
|
|
ProcessResult result;
|
|
std::array<char, 4096> buf;
|
|
std::string full_cmd = cmd + " 2>&1";
|
|
|
|
FILE *pipe = popen(full_cmd.c_str(), "r");
|
|
if (!pipe) {
|
|
result.exit_code = -1;
|
|
return result;
|
|
}
|
|
|
|
while (fgets(buf.data(), buf.size(), pipe) != nullptr)
|
|
result.output += buf.data();
|
|
|
|
int status = pclose(pipe);
|
|
result.exit_code = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
|
|
return result;
|
|
}
|
|
|
|
const ProcessResult &rocminfo_output() {
|
|
const TestPaths &paths = test_paths();
|
|
const char *rocminfo_path = std::getenv("ROCMINFO_PATH");
|
|
static const ProcessResult result =
|
|
run_command(paths.rocjitsu_bin + " --config " + paths.config_path + " -- " +
|
|
(rocminfo_path ? rocminfo_path : ROCMINFO_PATH));
|
|
return result;
|
|
}
|
|
|
|
TEST(RocminfoTest, ExitsSuccessfully) {
|
|
EXPECT_EQ(rocminfo_output().exit_code, 0)
|
|
<< "rocminfo failed with exit code " << rocminfo_output().exit_code << "\nOutput:\n"
|
|
<< rocminfo_output().output;
|
|
}
|
|
|
|
TEST(RocminfoTest, InterposerActive) {
|
|
EXPECT_NE(rocminfo_output().output.find("gfx950"), std::string::npos)
|
|
<< "Interposer does not appear to be active (no gfx950 agent).\nOutput:\n"
|
|
<< rocminfo_output().output;
|
|
}
|
|
|
|
TEST(RocminfoTest, HsaSystemAttributes) {
|
|
ASSERT_EQ(rocminfo_output().exit_code, 0) << rocminfo_output().output;
|
|
EXPECT_NE(rocminfo_output().output.find("HSA System Attributes"), std::string::npos)
|
|
<< "rocminfo did not report HSA System Attributes.\nOutput:\n"
|
|
<< rocminfo_output().output;
|
|
}
|
|
|
|
TEST(RocminfoTest, DetectsGpuAgent) {
|
|
ASSERT_EQ(rocminfo_output().exit_code, 0) << rocminfo_output().output;
|
|
EXPECT_NE(rocminfo_output().output.find("Device Type: GPU"), std::string::npos)
|
|
<< "rocminfo did not detect a GPU agent.\nOutput:\n"
|
|
<< rocminfo_output().output;
|
|
}
|
|
|
|
TEST(RocminfoTest, ReportsGfx950) {
|
|
ASSERT_EQ(rocminfo_output().exit_code, 0) << rocminfo_output().output;
|
|
EXPECT_NE(rocminfo_output().output.find("gfx950"), std::string::npos)
|
|
<< "rocminfo did not report gfx950 target.\nOutput:\n"
|
|
<< rocminfo_output().output;
|
|
}
|
|
|
|
TEST(RocminfoTest, ReportsWavefrontSize) {
|
|
ASSERT_EQ(rocminfo_output().exit_code, 0) << rocminfo_output().output;
|
|
EXPECT_NE(rocminfo_output().output.find("Wavefront Size:"), std::string::npos)
|
|
<< "rocminfo did not report Wavefront Size.\nOutput:\n"
|
|
<< rocminfo_output().output;
|
|
}
|
|
|
|
} // namespace
|