2018-05-09 22:29:30 +08:00
|
|
|
//===-- PredicateTest.cpp ---------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-05-09 22:29:30 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
Move Predicate.h from Host to Utility
Summary:
This class was initially in Host because its implementation used to be
very OS-specific. However, with C++11, it has become a very simple
std::condition_variable wrapper, with no host-specific code.
It is also a general purpose utility class, so it makes sense for it to
live in a place where it can be used by everyone.
This has no effect on the layering right now, but it enables me to later
move the Listener+Broadcaster+Event combo to a lower layer, which is
important, as these are used in a lot of places (notably for launching a
process in Host code).
Reviewers: jingham, zturner, teemperor
Reviewed By: zturner
Subscribers: xiaobai, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D50384
llvm-svn: 341089
2018-08-31 01:51:10 +08:00
|
|
|
#include "lldb/Utility/Predicate.h"
|
2018-05-09 22:29:30 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
TEST(Predicate, WaitForValueEqualTo) {
|
|
|
|
Predicate<int> P(0);
|
|
|
|
EXPECT_TRUE(P.WaitForValueEqualTo(0));
|
|
|
|
EXPECT_FALSE(P.WaitForValueEqualTo(1, std::chrono::milliseconds(10)));
|
|
|
|
|
|
|
|
std::thread Setter([&P] {
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
|
P.SetValue(1, eBroadcastAlways);
|
|
|
|
});
|
|
|
|
EXPECT_TRUE(P.WaitForValueEqualTo(1));
|
|
|
|
Setter.join();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Predicate, WaitForValueNotEqualTo) {
|
|
|
|
Predicate<int> P(0);
|
|
|
|
EXPECT_EQ(0, P.WaitForValueNotEqualTo(1));
|
|
|
|
EXPECT_EQ(llvm::None,
|
|
|
|
P.WaitForValueNotEqualTo(0, std::chrono::milliseconds(10)));
|
|
|
|
}
|