| 1 |
//===-- ThreadLauncherTest.cpp --------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, 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 |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
#include "lldb/Host/ThreadLauncher.h" |
| 10 |
#include "llvm/Testing/Support/Error.h" |
| 11 |
#include "gtest/gtest.h" |
| 12 |
#include <future> |
| 13 |
|
| 14 |
using namespace lldb_private; |
| 15 |
|
| 16 |
TEST(ThreadLauncherTest, LaunchThread) { |
| 17 |
std::promise<int> promise; |
| 18 |
std::future<int> future = promise.get_future(); |
| 19 |
llvm::Expected<HostThread> thread = |
| 20 |
ThreadLauncher::LaunchThread("test", [&promise] { |
| 21 |
promise.set_value(47); |
| 22 |
return (lldb::thread_result_t)47; |
| 23 |
}); |
| 24 |
ASSERT_THAT_EXPECTED(thread, llvm::Succeeded()); |
| 25 |
EXPECT_EQ(future.get(), 47); |
| 26 |
lldb::thread_result_t result; |
| 27 |
thread->Join(&result); |
| 28 |
EXPECT_EQ(result, (lldb::thread_result_t)47); |
| 29 |
} |