[flang] Update CommandTest for AIX (NFC) (#118403)
[llvm-project.git] / llvm / unittests / ExecutionEngine / Orc / LazyCallThroughAndReexportsTest.cpp
blob7f367cfd587398ef8c01e12017fe05e87f9ed007
1 #include "OrcTestCommon.h"
2 #include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
3 #include "llvm/ExecutionEngine/Orc/LazyReexports.h"
4 #include "gtest/gtest.h"
6 using namespace llvm;
7 using namespace llvm::orc;
9 class LazyReexportsTest : public CoreAPIsBasedStandardTest {};
11 static int dummyTarget() { return 42; }
13 TEST_F(LazyReexportsTest, BasicLocalCallThroughManagerOperation) {
14 // Create a callthrough manager for the host (if possible) and verify that
15 // a call to the lazy call-through:
16 // (1) Materializes the MU. This verifies that the symbol was looked up, and
17 // that we didn't arrive at the target via some other path
18 // (2) Returns the expected value (which we take as proof that the call
19 // reached the target).
21 auto JTMB = JITTargetMachineBuilder::detectHost();
23 // Bail out if we can not detect the host.
24 if (!JTMB) {
25 consumeError(JTMB.takeError());
26 GTEST_SKIP();
29 // Bail out if we can not build a local call-through manager.
30 auto LCTM = createLocalLazyCallThroughManager(JTMB->getTargetTriple(), ES,
31 ExecutorAddr());
32 if (!LCTM) {
33 consumeError(LCTM.takeError());
34 GTEST_SKIP();
37 auto DummyTarget = ES.intern("DummyTarget");
39 bool DummyTargetMaterialized = false;
41 cantFail(JD.define(std::make_unique<SimpleMaterializationUnit>(
42 SymbolFlagsMap({{DummyTarget, JITSymbolFlags::Exported}}),
43 [&](std::unique_ptr<MaterializationResponsibility> R) {
44 DummyTargetMaterialized = true;
45 // No dependencies registered, can't fail.
46 cantFail(R->notifyResolved({{DummyTarget,
47 {ExecutorAddr::fromPtr(&dummyTarget),
48 JITSymbolFlags::Exported}}}));
49 cantFail(R->notifyEmitted({}));
50 })));
52 unsigned NotifyResolvedCount = 0;
53 auto NotifyResolved = [&](ExecutorAddr ResolvedAddr) {
54 ++NotifyResolvedCount;
55 return Error::success();
58 auto CallThroughTrampoline = cantFail((*LCTM)->getCallThroughTrampoline(
59 JD, DummyTarget, std::move(NotifyResolved)));
61 auto CTTPtr = CallThroughTrampoline.toPtr<int (*)()>();
63 // Call twice to verify nothing unexpected happens on redundant calls.
64 auto Result = CTTPtr();
65 (void)CTTPtr();
67 EXPECT_TRUE(DummyTargetMaterialized)
68 << "CallThrough did not materialize target";
69 EXPECT_EQ(NotifyResolvedCount, 1U)
70 << "CallThrough should have generated exactly one 'NotifyResolved' call";
71 EXPECT_EQ(Result, 42) << "Failed to call through to target";