Files
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

92 lines
3.1 KiB
C++

//===- ImportIDTableTests.cpp - Unit tests for ImportIDTable --------------===//
//
// 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/Transforms/IPO/FunctionImport.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <set>
#include <type_traits>
using namespace llvm;
TEST(ImportIDTableTests, Basic) {
FunctionImporter::ImportIDTable Table;
auto [Def, Decl] = Table.createImportIDs("mod", 123U);
auto [Def2, Decl2] = Table.createImportIDs("stuff", 456U);
// Def and Decl must be of the same unsigned integer type.
static_assert(
std::is_unsigned_v<FunctionImporter::ImportIDTable::ImportIDTy>);
static_assert(std::is_same_v<FunctionImporter::ImportIDTable::ImportIDTy,
decltype(Def)>);
static_assert(std::is_same_v<FunctionImporter::ImportIDTable::ImportIDTy,
decltype(Decl)>);
// Check that all IDs are unique.
std::set<FunctionImporter::ImportIDTable::ImportIDTy> IDs = {Def, Decl, Def2,
Decl2};
EXPECT_THAT(IDs, ::testing::SizeIs(4));
// Verify what Def maps to.
auto DefTuple = Table.lookup(Def);
EXPECT_EQ(std::get<0>(DefTuple), StringRef("mod"));
EXPECT_EQ(std::get<1>(DefTuple), 123U);
EXPECT_EQ(std::get<2>(DefTuple), GlobalValueSummary::Definition);
// Verify what Decl maps to.
auto DeclTuple = Table.lookup(Decl);
EXPECT_EQ(std::get<0>(DeclTuple), StringRef("mod"));
EXPECT_EQ(std::get<1>(DeclTuple), 123U);
EXPECT_EQ(std::get<2>(DeclTuple), GlobalValueSummary::Declaration);
// Verify what Def2 maps to.
auto Def2Tuple = Table.lookup(Def2);
EXPECT_EQ(std::get<0>(Def2Tuple), StringRef("stuff"));
EXPECT_EQ(std::get<1>(Def2Tuple), 456U);
EXPECT_EQ(std::get<2>(Def2Tuple), GlobalValueSummary::Definition);
// Verify what Decl2 maps to.
auto Decl2Tuple = Table.lookup(Decl2);
EXPECT_EQ(std::get<0>(Decl2Tuple), StringRef("stuff"));
EXPECT_EQ(std::get<1>(Decl2Tuple), 456U);
EXPECT_EQ(std::get<2>(Decl2Tuple), GlobalValueSummary::Declaration);
}
TEST(ImportIDTableTests, Duplicates) {
FunctionImporter::ImportIDTable Table;
auto [Def1, Decl1] = Table.createImportIDs("mod", 123U);
auto [Def2, Decl2] = Table.createImportIDs("mod", 123U);
// Verify we get the same IDs back.
EXPECT_EQ(Def1, Def2);
EXPECT_EQ(Decl1, Decl2);
}
TEST(ImportIDTableTests, Present) {
FunctionImporter::ImportIDTable Table;
auto [Def, Decl] = Table.createImportIDs("mod", 123U);
auto Result = Table.getImportIDs("mod", 123U);
// Verify that we get the same IDs back.
ASSERT_NE(Result, std::nullopt);
EXPECT_EQ(Result->first, Def);
EXPECT_EQ(Result->second, Decl);
}
TEST(ImportIDTableTests, Missing) {
FunctionImporter::ImportIDTable Table;
auto Result = Table.getImportIDs("mod", 123U);
// Verify that we get std::nullopt for a non-existent pair.
EXPECT_EQ(Result, std::nullopt);
}