| 1 | //===-- PredicateTest.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/Utility/Predicate.h" |
| 10 | #include "gtest/gtest.h" |
| 11 | #include <thread> |
| 12 | |
| 13 | using namespace lldb_private; |
| 14 | |
| 15 | TEST(Predicate, WaitForValueEqualTo) { |
| 16 | Predicate<int> P(0); |
| 17 | EXPECT_TRUE(P.WaitForValueEqualTo(0)); |
| 18 | EXPECT_FALSE(P.WaitForValueEqualTo(1, std::chrono::milliseconds(10))); |
| 19 | |
| 20 | std::thread Setter([&P] { |
| 21 | std::this_thread::sleep_for(rtime: std::chrono::milliseconds(100)); |
| 22 | P.SetValue(value: 1, broadcast_type: eBroadcastAlways); |
| 23 | }); |
| 24 | EXPECT_TRUE(P.WaitForValueEqualTo(1)); |
| 25 | Setter.join(); |
| 26 | } |
| 27 | |
| 28 | TEST(Predicate, WaitForValueNotEqualTo) { |
| 29 | Predicate<int> P(0); |
| 30 | EXPECT_EQ(0, P.WaitForValueNotEqualTo(1)); |
| 31 | EXPECT_EQ(std::nullopt, |
| 32 | P.WaitForValueNotEqualTo(0, std::chrono::milliseconds(10))); |
| 33 | } |
| 34 |
