xref: /llvm-project/lldb/unittests/Utility/PredicateTest.cpp (revision d2a6114f27016065f6c7e7d39c0412e7d8d5e03b)
180814287SRaphael Isemann //===-- PredicateTest.cpp -------------------------------------------------===//
27fae4932SRaphael Isemann //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67fae4932SRaphael Isemann //
77fae4932SRaphael Isemann //===----------------------------------------------------------------------===//
87fae4932SRaphael Isemann 
97fae4932SRaphael Isemann #include "lldb/Utility/Predicate.h"
107fae4932SRaphael Isemann #include "gtest/gtest.h"
117fae4932SRaphael Isemann #include <thread>
127fae4932SRaphael Isemann 
137fae4932SRaphael Isemann using namespace lldb_private;
147fae4932SRaphael Isemann 
TEST(Predicate,WaitForValueEqualTo)157fae4932SRaphael Isemann TEST(Predicate, WaitForValueEqualTo) {
167fae4932SRaphael Isemann   Predicate<int> P(0);
177fae4932SRaphael Isemann   EXPECT_TRUE(P.WaitForValueEqualTo(0));
187fae4932SRaphael Isemann   EXPECT_FALSE(P.WaitForValueEqualTo(1, std::chrono::milliseconds(10)));
197fae4932SRaphael Isemann 
207fae4932SRaphael Isemann   std::thread Setter([&P] {
217fae4932SRaphael Isemann     std::this_thread::sleep_for(std::chrono::milliseconds(100));
227fae4932SRaphael Isemann     P.SetValue(1, eBroadcastAlways);
237fae4932SRaphael Isemann   });
247fae4932SRaphael Isemann   EXPECT_TRUE(P.WaitForValueEqualTo(1));
257fae4932SRaphael Isemann   Setter.join();
267fae4932SRaphael Isemann }
277fae4932SRaphael Isemann 
TEST(Predicate,WaitForValueNotEqualTo)287fae4932SRaphael Isemann TEST(Predicate, WaitForValueNotEqualTo) {
297fae4932SRaphael Isemann   Predicate<int> P(0);
307fae4932SRaphael Isemann   EXPECT_EQ(0, P.WaitForValueNotEqualTo(1));
31*d2a6114fSKazu Hirata   EXPECT_EQ(std::nullopt,
327fae4932SRaphael Isemann             P.WaitForValueNotEqualTo(0, std::chrono::milliseconds(10)));
337fae4932SRaphael Isemann }
34