1 //===- ResourceTest.cpp -----------------------------------------*- C++ -*-===//
3 // This file is licensed under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "../../test/lib/Dialect/Test/TestAttributes.h"
10 #include "../../test/lib/Dialect/Test/TestDialect.h"
11 #include "mlir/Parser/Parser.h"
13 #include "gmock/gmock.h"
18 TEST(MLIRParser
, ResourceKeyConflict
) {
19 std::string moduleStr
= R
"mlir(
20 "test
.use1
"() {attr = #test.e1di64_elements<blob1> : tensor<3xi64> } : () -> ()
25 blob1: "0x08000000010000000000000002000000000000000300000000000000"
30 std::string moduleStr2
= R
"mlir(
31 "test
.use2
"() {attr = #test.e1di64_elements<blob1> : tensor<3xi64> } : () -> ()
36 blob1: "0x08000000040000000000000005000000000000000600000000000000"
43 context
.loadDialect
<test::TestDialect
>();
45 // Parse both modules into the same context so that we ensure the conflicting
46 // resources have been loaded.
47 OwningOpRef
<ModuleOp
> module1
=
48 parseSourceString
<ModuleOp
>(moduleStr
, &context
);
49 OwningOpRef
<ModuleOp
> module2
=
50 parseSourceString
<ModuleOp
>(moduleStr2
, &context
);
51 ASSERT_TRUE(module1
&& module2
);
53 // Merge the two modules so that we can test printing the remapped resources.
54 Block
*block
= module1
->getBody();
55 block
->getOperations().splice(block
->end(),
56 module2
->getBody()->getOperations());
58 // Check that conflicting resources were remapped.
59 std::string outputStr
;
61 llvm::raw_string_ostream
os(outputStr
);
64 StringRef
output(outputStr
);
66 output
.contains("\"test.use1\"() {attr = #test.e1di64_elements<blob1>"));
67 EXPECT_TRUE(output
.contains(
68 "blob1: \"0x08000000010000000000000002000000000000000300000000000000\""));
69 EXPECT_TRUE(output
.contains(
70 "\"test.use2\"() {attr = #test.e1di64_elements<blob1_1>"));
71 EXPECT_TRUE(output
.contains(
73 "\"0x08000000040000000000000005000000000000000600000000000000\""));