[llvm-branch-commits] [llvm] cd8a80d - [Orc] Add a unit test for asynchronous definition generation.

Lang Hames via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Jan 12 19:30:27 PST 2021


Author: Lang Hames
Date: 2021-01-13T14:23:36+11:00
New Revision: cd8a80de96080da33d0a7d5d5821120ddcfc4ece

URL: https://github.com/llvm/llvm-project/commit/cd8a80de96080da33d0a7d5d5821120ddcfc4ece
DIFF: https://github.com/llvm/llvm-project/commit/cd8a80de96080da33d0a7d5d5821120ddcfc4ece.diff

LOG: [Orc] Add a unit test for asynchronous definition generation.

Added: 
    

Modified: 
    llvm/include/llvm/ExecutionEngine/Orc/Core.h
    llvm/lib/ExecutionEngine/Orc/Core.cpp
    llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/Core.h b/llvm/include/llvm/ExecutionEngine/Orc/Core.h
index 3020694ee732..4a4b58ed32e3 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/Core.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Core.h
@@ -850,6 +850,9 @@ class LookupState {
   friend class ExecutionSession;
 
 public:
+  LookupState();
+  LookupState(LookupState &&);
+  LookupState &operator=(LookupState &&);
   ~LookupState();
 
   /// Continue the lookup. This can be called by DefinitionGenerators

diff  --git a/llvm/lib/ExecutionEngine/Orc/Core.cpp b/llvm/lib/ExecutionEngine/Orc/Core.cpp
index 458dfc1ef421..3a18cd2ef761 100644
--- a/llvm/lib/ExecutionEngine/Orc/Core.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/Core.cpp
@@ -577,7 +577,10 @@ LookupState::LookupState(std::unique_ptr<InProgressLookupState> IPLS)
 
 void LookupState::reset(InProgressLookupState *IPLS) { this->IPLS.reset(IPLS); }
 
-LookupState::~LookupState() {}
+LookupState::LookupState() = default;
+LookupState::LookupState(LookupState &&) = default;
+LookupState &LookupState::operator=(LookupState &&) = default;
+LookupState::~LookupState() = default;
 
 void LookupState::continueLookup(Error Err) {
   assert(IPLS && "Cannot call continueLookup on empty LookupState");

diff  --git a/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp
index 866ed7656fb6..62c55cecf20e 100644
--- a/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp
@@ -110,7 +110,7 @@ TEST_F(CoreAPIsStandardTest, MaterializationSideEffctsOnlyBasic) {
 
   ES.lookup(
       LookupKind::Static, makeJITDylibSearchOrder(&JD),
-      SymbolLookupSet({Foo}, SymbolLookupFlags::WeaklyReferencedSymbol),
+      SymbolLookupSet(Foo, SymbolLookupFlags::WeaklyReferencedSymbol),
       SymbolState::Ready,
       [&](Expected<SymbolMap> LookupResult) {
         if (LookupResult)
@@ -1088,6 +1088,53 @@ TEST_F(CoreAPIsStandardTest, GeneratorTest) {
       << "Expected fallback def for Bar to be equal to BarSym";
 }
 
+TEST_F(CoreAPIsStandardTest, AsynchronousGeneratorTest) {
+  class TestGenerator : public DefinitionGenerator {
+  public:
+    TestGenerator(LookupState &TLS) : TLS(TLS) {}
+    Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD,
+                        JITDylibLookupFlags JDLookupFlags,
+                        const SymbolLookupSet &Name) override {
+      TLS = std::move(LS);
+      return Error::success();
+    }
+
+  private:
+    LookupState &TLS;
+  };
+
+  LookupState LS;
+  JD.addGenerator(std::make_unique<TestGenerator>(LS));
+
+  bool LookupCompleted = false;
+
+  ES.lookup(
+      LookupKind::Static, makeJITDylibSearchOrder(&JD), SymbolLookupSet(Foo),
+      SymbolState::Ready,
+      [&](Expected<SymbolMap> Result) {
+        LookupCompleted = true;
+        if (!Result) {
+          ADD_FAILURE() << "Lookup failed unexpected";
+          logAllUnhandledErrors(Result.takeError(), errs(), "");
+          return;
+        }
+
+        EXPECT_EQ(Result->size(), 1U) << "Unexpected number of results";
+        EXPECT_EQ(Result->count(Foo), 1U) << "Expected result for Foo";
+        EXPECT_EQ((*Result)[Foo].getAddress(), FooSym.getAddress())
+            << "Bad result for Foo";
+      },
+      NoDependenciesToRegister);
+
+  EXPECT_FALSE(LookupCompleted);
+
+  cantFail(JD.define(absoluteSymbols({{Foo, FooSym}})));
+
+  LS.continueLookup(Error::success());
+
+  EXPECT_TRUE(LookupCompleted);
+}
+
 TEST_F(CoreAPIsStandardTest, FailResolution) {
   auto MU = std::make_unique<SimpleMaterializationUnit>(
       SymbolFlagsMap({{Foo, JITSymbolFlags::Exported | JITSymbolFlags::Weak},


        


More information about the llvm-branch-commits mailing list