summaryrefslogtreecommitdiffstats
path: root/base/properties_test.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2017-02-10 19:02:51 -0800
committerElliott Hughes <enh@google.com>2017-02-13 11:29:02 -0800
commitb30769a87acc15fc7f628d8541cdf97aba22e2e2 (patch)
treed93d47723f27c92021a558e2b71cff64fe5084a9 /base/properties_test.cpp
parent7e7913cb6703c7ff7e2fc31d5dafdfd25f01b899 (diff)
downloadsystem_core-b30769a87acc15fc7f628d8541cdf97aba22e2e2.tar.gz
system_core-b30769a87acc15fc7f628d8541cdf97aba22e2e2.tar.bz2
system_core-b30769a87acc15fc7f628d8541cdf97aba22e2e2.zip
Implement android::base::WaitForProperty.
Also adapt libcutils to the bionic change that was necessary for this. Bug: http://b/35201172 Test: ran tests Change-Id: I72a98b70b03d23e958b46778b505fbd5c86c32ae
Diffstat (limited to 'base/properties_test.cpp')
-rw-r--r--base/properties_test.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/base/properties_test.cpp b/base/properties_test.cpp
index da89ec5a9..d8186be6e 100644
--- a/base/properties_test.cpp
+++ b/base/properties_test.cpp
@@ -18,7 +18,12 @@
#include <gtest/gtest.h>
+#include <atomic>
+#include <chrono>
#include <string>
+#include <thread>
+
+using namespace std::chrono_literals;
TEST(properties, smoke) {
android::base::SetProperty("debug.libbase.property_test", "hello");
@@ -119,3 +124,18 @@ TEST(properties, GetUintProperty_uint8_t) { CheckGetUintProperty<uint8_t>(); }
TEST(properties, GetUintProperty_uint16_t) { CheckGetUintProperty<uint16_t>(); }
TEST(properties, GetUintProperty_uint32_t) { CheckGetUintProperty<uint32_t>(); }
TEST(properties, GetUintProperty_uint64_t) { CheckGetUintProperty<uint64_t>(); }
+
+TEST(properties, WaitForProperty) {
+ std::atomic<bool> flag{false};
+ std::thread thread([&]() {
+ std::this_thread::sleep_for(100ms);
+ android::base::SetProperty("debug.libbase.WaitForProperty_test", "a");
+ while (!flag) std::this_thread::yield();
+ android::base::SetProperty("debug.libbase.WaitForProperty_test", "b");
+ });
+
+ android::base::WaitForProperty("debug.libbase.WaitForProperty_test", "a");
+ flag = true;
+ android::base::WaitForProperty("debug.libbase.WaitForProperty_test", "b");
+ thread.join();
+}