[llvm] 14c55e6 - [unittest] Improve OpenMPIRBuilderTest after D149162
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 20 14:37:59 PDT 2023
Author: Fangrui Song
Date: 2023-07-20T14:37:54-07:00
New Revision: 14c55e6e2fa1c342a1ef908445db3d31a3475485
URL: https://github.com/llvm/llvm-project/commit/14c55e6e2fa1c342a1ef908445db3d31a3475485
DIFF: https://github.com/llvm/llvm-project/commit/14c55e6e2fa1c342a1ef908445db3d31a3475485.diff
LOG: [unittest] Improve OpenMPIRBuilderTest after D149162
Make it less sensitive to omp_offload.info operands order and improve
the failure diagnostic.
Caught by D155789
Added:
Modified:
llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
Removed:
################################################################################
diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
index f6889cd5f074a5..82ab4c9f4c93ab 100644
--- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -20,6 +20,7 @@
#include "llvm/Passes/PassBuilder.h"
#include "llvm/Support/Casting.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
+#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <optional>
@@ -5860,15 +5861,15 @@ TEST_F(OpenMPIRBuilderTest, registerTargetGlobalVariable) {
// Metadata generated for the host offload module
NamedMDNode *OffloadMetadata = M->getNamedMetadata("omp_offload.info");
- EXPECT_NE(OffloadMetadata, nullptr);
- if (OffloadMetadata) {
- EXPECT_EQ(OffloadMetadata->getOperand(0)->getOperand(1).equalsStr(
- "test_data_int_0"),
- true);
- EXPECT_EQ(OffloadMetadata->getOperand(1)->getOperand(1).equalsStr(
- "test_data_int_1_decl_tgt_ref_ptr"),
- true);
- }
+ ASSERT_THAT(OffloadMetadata, testing::NotNull());
+ StringRef Nodes[2] = {
+ cast<MDString>(OffloadMetadata->getOperand(0)->getOperand(1))
+ ->getString(),
+ cast<MDString>(OffloadMetadata->getOperand(1)->getOperand(1))
+ ->getString()};
+ EXPECT_THAT(
+ Nodes, testing::UnorderedElementsAre("test_data_int_0",
+ "test_data_int_1_decl_tgt_ref_ptr"));
}
TEST_F(OpenMPIRBuilderTest, createGPUOffloadEntry) {
More information about the llvm-commits
mailing list