[llvm] c73516a - [ORC] Add tests for error handling paths in suspended generators.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Thu May 9 06:24:53 PDT 2024
Author: Lang Hames
Date: 2024-05-09T23:24:45+10:00
New Revision: c73516af10f800d0d5641651eefce128b866a155
URL: https://github.com/llvm/llvm-project/commit/c73516af10f800d0d5641651eefce128b866a155
DIFF: https://github.com/llvm/llvm-project/commit/c73516af10f800d0d5641651eefce128b866a155.diff
LOG: [ORC] Add tests for error handling paths in suspended generators.
Test that (1) errors returned from a manually suspended generator are
propagated as expected, and (2) automatic suspension does not interfere with
our ability to resume (and return errors from) a generator.
Added:
Modified:
llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp
Removed:
################################################################################
diff --git a/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp
index 3b24e29e1ed38..a6fa69f97fcbe 100644
--- a/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp
@@ -1132,6 +1132,71 @@ TEST_F(CoreAPIsStandardTest, SimpleAsynchronousGeneratorTest) {
EXPECT_TRUE(LookupCompleted);
}
+TEST_F(CoreAPIsStandardTest, ErrorFromSuspendedAsynchronousGeneratorTest) {
+
+ auto &G = JD.addGenerator(std::make_unique<SimpleAsyncGenerator>());
+
+ bool LookupCompleted = false;
+
+ ES.lookup(
+ LookupKind::Static, makeJITDylibSearchOrder(&JD), SymbolLookupSet(Foo),
+ SymbolState::Ready,
+ [&](Expected<SymbolMap> Result) {
+ LookupCompleted = true;
+ EXPECT_THAT_EXPECTED(Result, Failed());
+ },
+ NoDependenciesToRegister);
+
+ EXPECT_FALSE(LookupCompleted);
+
+ G.takeLookup().LS.continueLookup(
+ make_error<StringError>("boom", inconvertibleErrorCode()));
+
+ EXPECT_TRUE(LookupCompleted);
+}
+
+TEST_F(CoreAPIsStandardTest, ErrorFromAutoSuspendedAsynchronousGeneratorTest) {
+
+ auto &G = JD.addGenerator(std::make_unique<SimpleAsyncGenerator>());
+
+ std::atomic_size_t LookupsCompleted = 0;
+
+ ES.lookup(
+ LookupKind::Static, makeJITDylibSearchOrder(&JD), SymbolLookupSet(Foo),
+ SymbolState::Ready,
+ [&](Expected<SymbolMap> Result) {
+ ++LookupsCompleted;
+ EXPECT_THAT_EXPECTED(Result, Failed());
+ },
+ NoDependenciesToRegister);
+
+ EXPECT_EQ(LookupsCompleted, 0);
+
+ // Suspend the first lookup.
+ auto LS1 = std::move(G.takeLookup().LS);
+
+ // Start a second lookup that should be auto-suspended.
+ ES.lookup(
+ LookupKind::Static, makeJITDylibSearchOrder(&JD), SymbolLookupSet(Foo),
+ SymbolState::Ready,
+ [&](Expected<SymbolMap> Result) {
+ ++LookupsCompleted;
+ EXPECT_THAT_EXPECTED(Result, Failed());
+ },
+ NoDependenciesToRegister);
+
+ EXPECT_EQ(LookupsCompleted, 0);
+
+ // Unsuspend the first lookup.
+ LS1.continueLookup(make_error<StringError>("boom", inconvertibleErrorCode()));
+
+ // Unsuspend the second.
+ G.takeLookup().LS.continueLookup(
+ make_error<StringError>("boom", inconvertibleErrorCode()));
+
+ EXPECT_EQ(LookupsCompleted, 2);
+}
+
TEST_F(CoreAPIsStandardTest, BlockedGeneratorAutoSuspensionTest) {
// Test that repeated lookups while a generator is in use cause automatic
// lookup suspension / resumption.
More information about the llvm-commits
mailing list