| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // Unit test for SyncChannel. | 5 // Unit test for SyncChannel. |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/dynamic_annotations.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 13 #include "base/platform_thread.h" | 14 #include "base/platform_thread.h" |
| 14 #include "base/stl_util-inl.h" | 15 #include "base/stl_util-inl.h" |
| 15 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 16 #include "base/thread.h" | 17 #include "base/thread.h" |
| 17 #include "base/waitable_event.h" | 18 #include "base/waitable_event.h" |
| 18 #include "ipc/ipc_message.h" | 19 #include "ipc/ipc_message.h" |
| 19 #include "ipc/ipc_sync_channel.h" | 20 #include "ipc/ipc_sync_channel.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 32 class Worker : public Channel::Listener, public Message::Sender { | 33 class Worker : public Channel::Listener, public Message::Sender { |
| 33 public: | 34 public: |
| 34 // Will create a channel without a name. | 35 // Will create a channel without a name. |
| 35 Worker(Channel::Mode mode, const std::string& thread_name) | 36 Worker(Channel::Mode mode, const std::string& thread_name) |
| 36 : done_(new WaitableEvent(false, false)), | 37 : done_(new WaitableEvent(false, false)), |
| 37 channel_created_(new WaitableEvent(false, false)), | 38 channel_created_(new WaitableEvent(false, false)), |
| 38 mode_(mode), | 39 mode_(mode), |
| 39 ipc_thread_((thread_name + "_ipc").c_str()), | 40 ipc_thread_((thread_name + "_ipc").c_str()), |
| 40 listener_thread_((thread_name + "_listener").c_str()), | 41 listener_thread_((thread_name + "_listener").c_str()), |
| 41 overrided_thread_(NULL), | 42 overrided_thread_(NULL), |
| 42 shutdown_event_(true, false) { } | 43 shutdown_event_(true, false) { |
| 44 // The data race on vfptr is real but is very hard |
| 45 // to suppress using standard Valgrind mechanism (suppressions). |
| 46 // We have to use ANNOTATE_BENIGN_RACE to hide the reports and |
| 47 // make ThreadSanitizer bots green. |
| 48 ANNOTATE_BENIGN_RACE(this, "Race on vfptr, http://crbug.com/25841"); |
| 49 } |
| 43 | 50 |
| 44 // Will create a named channel and use this name for the threads' name. | 51 // Will create a named channel and use this name for the threads' name. |
| 45 Worker(const std::string& channel_name, Channel::Mode mode) | 52 Worker(const std::string& channel_name, Channel::Mode mode) |
| 46 : done_(new WaitableEvent(false, false)), | 53 : done_(new WaitableEvent(false, false)), |
| 47 channel_created_(new WaitableEvent(false, false)), | 54 channel_created_(new WaitableEvent(false, false)), |
| 48 channel_name_(channel_name), | 55 channel_name_(channel_name), |
| 49 mode_(mode), | 56 mode_(mode), |
| 50 ipc_thread_((channel_name + "_ipc").c_str()), | 57 ipc_thread_((channel_name + "_ipc").c_str()), |
| 51 listener_thread_((channel_name + "_listener").c_str()), | 58 listener_thread_((channel_name + "_listener").c_str()), |
| 52 overrided_thread_(NULL), | 59 overrided_thread_(NULL), |
| 53 shutdown_event_(true, false) { } | 60 shutdown_event_(true, false) { |
| 61 // The data race on vfptr is real but is very hard |
| 62 // to suppress using standard Valgrind mechanism (suppressions). |
| 63 // We have to use ANNOTATE_BENIGN_RACE to hide the reports and |
| 64 // make ThreadSanitizer bots green. |
| 65 ANNOTATE_BENIGN_RACE(this, "Race on vfptr, http://crbug.com/25841"); |
| 66 } |
| 54 | 67 |
| 55 // The IPC thread needs to outlive SyncChannel, so force the correct order of | 68 // The IPC thread needs to outlive SyncChannel, so force the correct order of |
| 56 // destruction. | 69 // destruction. |
| 57 virtual ~Worker() { | 70 virtual ~Worker() { |
| 58 WaitableEvent listener_done(false, false), ipc_done(false, false); | 71 WaitableEvent listener_done(false, false), ipc_done(false, false); |
| 59 ListenerThread()->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( | 72 ListenerThread()->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
| 60 this, &Worker::OnListenerThreadShutdown1, &listener_done, | 73 this, &Worker::OnListenerThreadShutdown1, &listener_done, |
| 61 &ipc_done)); | 74 &ipc_done)); |
| 62 listener_done.Wait(); | 75 listener_done.Wait(); |
| 63 ipc_done.Wait(); | 76 ipc_done.Wait(); |
| (...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1008 | 1021 |
| 1009 // Tests http://b/1474092 - that if after the done_event is set but before | 1022 // Tests http://b/1474092 - that if after the done_event is set but before |
| 1010 // OnObjectSignaled is called another message is sent out, then after its | 1023 // OnObjectSignaled is called another message is sent out, then after its |
| 1011 // reply comes back OnObjectSignaled will be called for the first message. | 1024 // reply comes back OnObjectSignaled will be called for the first message. |
| 1012 TEST_F(IPCSyncChannelTest, DoneEventRace) { | 1025 TEST_F(IPCSyncChannelTest, DoneEventRace) { |
| 1013 std::vector<Worker*> workers; | 1026 std::vector<Worker*> workers; |
| 1014 workers.push_back(new DoneEventRaceServer()); | 1027 workers.push_back(new DoneEventRaceServer()); |
| 1015 workers.push_back(new SimpleClient()); | 1028 workers.push_back(new SimpleClient()); |
| 1016 RunTest(workers); | 1029 RunTest(workers); |
| 1017 } | 1030 } |
| OLD | NEW |