Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: components/exo/wayland/server_unittest.cc

Issue 2086833004: Run exo_unittests in waterfall (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: disable crashing test Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/exo/display_unittest.cc ('k') | testing/buildbot/chromium.chromiumos.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "components/exo/wayland/server.h" 5 #include "components/exo/wayland/server.h"
6 6
7 #include <stdlib.h>
8
7 #include <wayland-client-core.h> 9 #include <wayland-client-core.h>
8 10
9 #include <memory> 11 #include <memory>
10 12
11 #include "base/atomic_sequence_num.h" 13 #include "base/atomic_sequence_num.h"
12 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/files/scoped_temp_dir.h"
13 #include "base/process/process_handle.h" 16 #include "base/process/process_handle.h"
14 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
15 #include "base/threading/thread.h" 18 #include "base/threading/thread.h"
16 #include "components/exo/display.h" 19 #include "components/exo/display.h"
17 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
18 21
19 namespace exo { 22 namespace exo {
20 namespace wayland { 23 namespace wayland {
21 namespace { 24 namespace {
22 25
23 base::StaticAtomicSequenceNumber g_next_socket_id; 26 base::StaticAtomicSequenceNumber g_next_socket_id;
24 27
25 std::string GetUniqueSocketName() { 28 std::string GetUniqueSocketName() {
26 return base::StringPrintf("wayland-test-%d-%d", base::GetCurrentProcId(), 29 return base::StringPrintf("wayland-test-%d-%d", base::GetCurrentProcId(),
27 g_next_socket_id.GetNext()); 30 g_next_socket_id.GetNext());
28 } 31 }
29 32
30 TEST(ServerTest, AddSocket) { 33 class ServerTest : public testing::Test {
34 public:
35 ServerTest() {}
36 ~ServerTest() override {}
37
38 void SetUp() override {
39 ASSERT_TRUE(xdg_temp_dir_.CreateUniqueTempDir());
40 setenv("XDG_RUNTIME_DIR", xdg_temp_dir_.path().MaybeAsASCII().c_str(),
41 1 /* overwrite */);
42 testing::Test::SetUp();
43 }
44
45 private:
46 base::ScopedTempDir xdg_temp_dir_;
47
48 DISALLOW_COPY_AND_ASSIGN(ServerTest);
49 };
50
51 TEST_F(ServerTest, AddSocket) {
31 std::unique_ptr<Display> display(new Display); 52 std::unique_ptr<Display> display(new Display);
32 std::unique_ptr<Server> server(new Server(display.get())); 53 std::unique_ptr<Server> server(new Server(display.get()));
33 54
34 // Check that calling AddSocket() with a unique socket name succeeds. 55 // Check that calling AddSocket() with a unique socket name succeeds.
35 bool rv = server->AddSocket(GetUniqueSocketName()); 56 bool rv = server->AddSocket(GetUniqueSocketName());
36 EXPECT_TRUE(rv); 57 EXPECT_TRUE(rv);
37 } 58 }
38 59
39 TEST(ServerTest, GetFileDescriptor) { 60 TEST_F(ServerTest, GetFileDescriptor) {
40 std::unique_ptr<Display> display(new Display); 61 std::unique_ptr<Display> display(new Display);
41 std::unique_ptr<Server> server(new Server(display.get())); 62 std::unique_ptr<Server> server(new Server(display.get()));
42 63
43 bool rv = server->AddSocket(GetUniqueSocketName()); 64 bool rv = server->AddSocket(GetUniqueSocketName());
44 EXPECT_TRUE(rv); 65 EXPECT_TRUE(rv);
45 66
46 // Check that the returned file descriptor is valid. 67 // Check that the returned file descriptor is valid.
47 int fd = server->GetFileDescriptor(); 68 int fd = server->GetFileDescriptor();
48 DCHECK_GE(fd, 0); 69 DCHECK_GE(fd, 0);
49 } 70 }
50 71
51 void ConnectToServer(const std::string socket_name, 72 void ConnectToServer(const std::string socket_name,
52 bool* connected_to_server, 73 bool* connected_to_server,
53 base::WaitableEvent* event) { 74 base::WaitableEvent* event) {
54 wl_display* display = wl_display_connect(socket_name.c_str()); 75 wl_display* display = wl_display_connect(socket_name.c_str());
55 *connected_to_server = !!display; 76 *connected_to_server = !!display;
56 event->Signal(); 77 event->Signal();
57 wl_display_disconnect(display); 78 wl_display_disconnect(display);
58 } 79 }
59 80
60 TEST(ServerTest, Dispatch) { 81 TEST_F(ServerTest, Dispatch) {
61 std::unique_ptr<Display> display(new Display); 82 std::unique_ptr<Display> display(new Display);
62 std::unique_ptr<Server> server(new Server(display.get())); 83 std::unique_ptr<Server> server(new Server(display.get()));
63 84
64 std::string socket_name = GetUniqueSocketName(); 85 std::string socket_name = GetUniqueSocketName();
65 bool rv = server->AddSocket(socket_name); 86 bool rv = server->AddSocket(socket_name);
66 EXPECT_TRUE(rv); 87 EXPECT_TRUE(rv);
67 88
68 base::Thread client("client-" + socket_name); 89 base::Thread client("client-" + socket_name);
69 ASSERT_TRUE(client.Start()); 90 ASSERT_TRUE(client.Start());
70 91
71 // Post a task that connects server on the created thread. 92 // Post a task that connects server on the created thread.
72 bool connected_to_server = false; 93 bool connected_to_server = false;
73 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, 94 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC,
74 base::WaitableEvent::InitialState::NOT_SIGNALED); 95 base::WaitableEvent::InitialState::NOT_SIGNALED);
75 client.task_runner()->PostTask( 96 client.task_runner()->PostTask(
76 FROM_HERE, 97 FROM_HERE,
77 base::Bind(&ConnectToServer, socket_name, &connected_to_server, &event)); 98 base::Bind(&ConnectToServer, socket_name, &connected_to_server, &event));
78 99
79 // Call Dispatch() with a 5 second timeout. 100 // Call Dispatch() with a 5 second timeout.
80 server->Dispatch(base::TimeDelta::FromSeconds(5)); 101 server->Dispatch(base::TimeDelta::FromSeconds(5));
81 102
82 // Check if client thread managed to connect to server. 103 // Check if client thread managed to connect to server.
83 event.Wait(); 104 event.Wait();
84 EXPECT_TRUE(connected_to_server); 105 EXPECT_TRUE(connected_to_server);
85 } 106 }
86 107
87 TEST(ServerTest, Flush) { 108 TEST_F(ServerTest, Flush) {
88 std::unique_ptr<Display> display(new Display); 109 std::unique_ptr<Display> display(new Display);
89 std::unique_ptr<Server> server(new Server(display.get())); 110 std::unique_ptr<Server> server(new Server(display.get()));
90 111
91 bool rv = server->AddSocket(GetUniqueSocketName()); 112 bool rv = server->AddSocket(GetUniqueSocketName());
92 EXPECT_TRUE(rv); 113 EXPECT_TRUE(rv);
93 114
94 // Just call Flush to check that it doesn't have any bad side-effects. 115 // Just call Flush to check that it doesn't have any bad side-effects.
95 server->Flush(); 116 server->Flush();
96 } 117 }
97 118
98 } // namespace 119 } // namespace
99 } // namespace wayland 120 } // namespace wayland
100 } // namespace exo 121 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/display_unittest.cc ('k') | testing/buildbot/chromium.chromiumos.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698