/*
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <ratio>
#include <thread>
-#include <gflags/gflags.h>
#include <glog/logging.h>
-#include <gtest/gtest.h>
-#include <time.h>
+
+#include <folly/portability/Time.h>
+#include <folly/portability/GTest.h>
using namespace folly::detail;
using namespace folly::test;
EXPECT_TRUE(A <= B && B <= C);
}
+template <template <typename> class Atom>
+void run_wake_blocked_test() {
+ for (auto delay = std::chrono::milliseconds(1);; delay *= 2) {
+ bool success = false;
+ Futex<Atom> f(0);
+ auto thr = DSched::thread([&] { success = f.futexWait(0); });
+ /* sleep override */ std::this_thread::sleep_for(delay);
+ f.store(1);
+ f.futexWake(1);
+ DSched::join(thr);
+ LOG(INFO) << "delay=" << delay.count() << "_ms, success=" << success;
+ if (success) {
+ break;
+ }
+ }
+}
+
TEST(Futex, clock_source) {
run_system_clock_test();
run_wait_until_tests<DeterministicAtomic>();
}
-int main(int argc, char ** argv) {
- testing::InitGoogleTest(&argc, argv);
- gflags::ParseCommandLineFlags(&argc, &argv, true);
- return RUN_ALL_TESTS();
+TEST(Futex, wake_blocked_live) {
+ run_wake_blocked_test<std::atomic>();
+}
+
+TEST(Futex, wake_blocked_emulated) {
+ run_wake_blocked_test<EmulatedFutexAtomic>();
}