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
115 lines
3.5 KiB
C++
115 lines
3.5 KiB
C++
//===-- OffloadArchTest.cpp - Tests for offload-arch helpers ---*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include "llvm/Support/CommandLine.h"
|
|
#include "gtest/gtest.h"
|
|
#include <algorithm>
|
|
#include <string>
|
|
|
|
// Defined in AMDGPUArchByHIP.cpp (non-static, compiled into this test).
|
|
#ifdef _WIN32
|
|
bool compareVersions(llvm::StringRef A, llvm::StringRef B);
|
|
llvm::SmallVector<std::string, 8> getCandidateBinPaths(llvm::StringRef ExeDir);
|
|
#endif
|
|
|
|
using namespace llvm;
|
|
|
|
cl::opt<bool> Verbose("offload-arch-test-verbose", cl::Hidden, cl::init(false));
|
|
|
|
#ifdef _WIN32
|
|
|
|
// --- compareVersions ---
|
|
|
|
TEST(CompareVersions, HigherVersionWins) {
|
|
EXPECT_TRUE(
|
|
compareVersions("C:/bin/amdhip64_7.dll", "C:/bin/amdhip64_6.dll"));
|
|
EXPECT_FALSE(
|
|
compareVersions("C:/bin/amdhip64_6.dll", "C:/bin/amdhip64_7.dll"));
|
|
}
|
|
|
|
TEST(CompareVersions, EqualVersionsReturnFalse) {
|
|
EXPECT_FALSE(compareVersions("C:/a/amdhip64_7.dll", "C:/b/amdhip64_7.dll"));
|
|
}
|
|
|
|
TEST(CompareVersions, MultiDigitVersions) {
|
|
EXPECT_TRUE(compareVersions("amdhip64_12.dll", "amdhip64_6.dll"));
|
|
}
|
|
|
|
TEST(CompareVersions, StableSortPreservesInsertionOrder) {
|
|
std::vector<std::string> DLLs = {"C:/rocm/bin/amdhip64_7.dll",
|
|
"C:/Windows/System32/amdhip64_7.dll"};
|
|
llvm::stable_sort(DLLs, compareVersions);
|
|
EXPECT_EQ(DLLs[0], "C:/rocm/bin/amdhip64_7.dll");
|
|
}
|
|
|
|
// --- getCandidateBinPaths ---
|
|
|
|
TEST(CandidateBinPaths, FindsParentBin) {
|
|
auto Paths = getCandidateBinPaths("C:/root/lib/llvm/bin");
|
|
bool Found = false;
|
|
for (const auto &P : Paths)
|
|
if (StringRef(P).equals_insensitive("C:/root/bin"))
|
|
Found = true;
|
|
EXPECT_TRUE(Found);
|
|
}
|
|
|
|
TEST(CandidateBinPaths, NoDuplicatesWhenExeInBin) {
|
|
auto Paths = getCandidateBinPaths("C:/root/bin");
|
|
int Count = 0;
|
|
for (const auto &P : Paths)
|
|
if (StringRef(P).equals_insensitive("C:/root/bin"))
|
|
Count++;
|
|
EXPECT_EQ(Count, 1);
|
|
}
|
|
|
|
TEST(CandidateBinPaths, CaseInsensitiveDedup) {
|
|
// Paths differing only in case should not both appear.
|
|
auto Paths = getCandidateBinPaths("C:/Root/Lib/Bin");
|
|
int Count = 0;
|
|
for (const auto &P : Paths)
|
|
if (StringRef(P).equals_insensitive("C:/Root/bin"))
|
|
Count++;
|
|
EXPECT_LE(Count, 1);
|
|
}
|
|
|
|
TEST(CandidateBinPaths, StopsWithinBound) {
|
|
auto Paths = getCandidateBinPaths("C:/a/b/c/d/e/f/g/h");
|
|
// MaxParentLevels=6 + self = 7 max entries.
|
|
EXPECT_LE(Paths.size(), 7u);
|
|
}
|
|
|
|
TEST(CandidateBinPaths, RootInput) {
|
|
auto Paths = getCandidateBinPaths("C:/");
|
|
// Should produce at least 1 entry (self) and not crash.
|
|
EXPECT_GE(Paths.size(), 1u);
|
|
}
|
|
|
|
TEST(CandidateBinPaths, NonAsciiPath) {
|
|
// Paths with non-ASCII characters should not crash.
|
|
auto Paths = getCandidateBinPaths("C:/\xC3\xBCser/\xC3\xA4pp/bin");
|
|
EXPECT_GE(Paths.size(), 1u);
|
|
}
|
|
|
|
TEST(CandidateBinPaths, UnicodePathDedup) {
|
|
auto Paths =
|
|
getCandidateBinPaths("C:/\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E/lib/bin");
|
|
// Should produce entries without crashing on CJK characters.
|
|
EXPECT_GE(Paths.size(), 1u);
|
|
}
|
|
|
|
TEST(CandidateBinPaths, NoDriveRootBin) {
|
|
auto Paths = getCandidateBinPaths("C:\\Program Files\\AMD\\HIP\\bin");
|
|
for (const auto &P : Paths)
|
|
EXPECT_FALSE(StringRef(P).equals_insensitive("C:/bin"))
|
|
<< "Drive-root bin/ must not appear (DLL planting risk)";
|
|
}
|
|
|
|
#endif // _WIN32
|