summaryrefslogtreecommitdiff
path: root/runtime/thread_pool_test.cc
diff options
context:
space:
mode:
author Andreas Gampe <agampe@google.com> 2017-01-24 13:12:19 -0800
committer Andreas Gampe <agampe@google.com> 2017-01-27 13:14:34 -0800
commitb15de0c0580633701c19c32bb60bcd64f30da867 (patch)
tree961791f6d7534fc875a4a22c8cabe2a1d4cfaf7e /runtime/thread_pool_test.cc
parent67c60656639acc92dca2ae8713add7d22683c7b9 (diff)
ART: Add ThreadPool mode that creates peers
Add a mode where worker threads in a thread pool will get a Java peer. Add a test. Bug: 29547798 Bug: 31684920 Test: m test-art-host-gtest-thread_pool_test Change-Id: I3654cc2be1294a79881b6ac9f84445a1e7f24b70
Diffstat (limited to 'runtime/thread_pool_test.cc')
-rw-r--r--runtime/thread_pool_test.cc52
1 files changed, 52 insertions, 0 deletions
diff --git a/runtime/thread_pool_test.cc b/runtime/thread_pool_test.cc
index 14c2c3bac8..28aa21f7a2 100644
--- a/runtime/thread_pool_test.cc
+++ b/runtime/thread_pool_test.cc
@@ -20,6 +20,7 @@
#include "atomic.h"
#include "common_runtime_test.h"
+#include "scoped_thread_state_change-inl.h"
#include "thread-inl.h"
namespace art {
@@ -159,4 +160,55 @@ TEST_F(ThreadPoolTest, RecursiveTest) {
EXPECT_EQ((1 << depth) - 1, count.LoadSequentiallyConsistent());
}
+class PeerTask : public Task {
+ public:
+ PeerTask() {}
+
+ void Run(Thread* self) {
+ ScopedObjectAccess soa(self);
+ CHECK(self->GetPeer() != nullptr);
+ }
+
+ void Finalize() {
+ delete this;
+ }
+};
+
+class NoPeerTask : public Task {
+ public:
+ NoPeerTask() {}
+
+ void Run(Thread* self) {
+ ScopedObjectAccess soa(self);
+ CHECK(self->GetPeer() == nullptr);
+ }
+
+ void Finalize() {
+ delete this;
+ }
+};
+
+// Tests for create_peer functionality.
+TEST_F(ThreadPoolTest, PeerTest) {
+ Thread* self = Thread::Current();
+ {
+ ThreadPool thread_pool("Thread pool test thread pool", 1);
+ thread_pool.AddTask(self, new NoPeerTask());
+ thread_pool.StartWorkers(self);
+ thread_pool.Wait(self, false, false);
+ }
+
+ {
+ // To create peers, the runtime needs to be started.
+ self->TransitionFromSuspendedToRunnable();
+ bool started = runtime_->Start();
+ ASSERT_TRUE(started);
+
+ ThreadPool thread_pool("Thread pool test thread pool", 1, true);
+ thread_pool.AddTask(self, new PeerTask());
+ thread_pool.StartWorkers(self);
+ thread_pool.Wait(self, false, false);
+ }
+}
+
} // namespace art