OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/message_loop/message_loop.h" | |
6 #include "base/run_loop.h" | |
7 #include "gpu/ipc/common/traits_test_service.mojom.h" | |
8 #include "mojo/public/cpp/bindings/binding_set.h" | |
9 #include "testing/gtest/include/gtest/gtest.h" | |
10 | |
11 namespace gpu { | |
12 | |
13 namespace { | |
14 | |
15 class StructTraitsTest : public testing::Test, public mojom::TraitsTestService { | |
16 public: | |
17 StructTraitsTest() {} | |
18 | |
19 protected: | |
20 mojom::TraitsTestServicePtr GetTraitsTestProxy() { | |
21 return traits_test_bindings_.CreateInterfacePtrAndBind(this); | |
22 } | |
23 | |
24 private: | |
25 // TraitsTestService: | |
26 void EchoMailbox(const Mailbox& m, | |
27 const EchoMailboxCallback& callback) override { | |
28 callback.Run(m); | |
29 } | |
30 | |
31 void EchoMailboxHolder(const MailboxHolder& r, | |
32 const EchoMailboxHolderCallback& callback) override { | |
33 callback.Run(r); | |
34 } | |
35 | |
36 void EchoSyncToken(const SyncToken& s, | |
37 const EchoSyncTokenCallback& callback) override { | |
38 callback.Run(s); | |
39 } | |
40 | |
41 base::MessageLoop loop_; | |
42 mojo::BindingSet<TraitsTestService> traits_test_bindings_; | |
43 }; | |
44 | |
45 } // namespace | |
46 | |
47 TEST_F(StructTraitsTest, Mailbox) { | |
48 const int8_t mailbox_name[GL_MAILBOX_SIZE_CHROMIUM] = { | |
49 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, | |
Tom Sepez
2016/05/31 17:30:24
nit: Any particular reason for this pattern? If s
Fady Samuel
2016/05/31 17:59:58
No reason.
| |
50 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7, | |
51 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7}; | |
52 gpu::Mailbox input; | |
53 input.SetName(mailbox_name); | |
54 base::RunLoop loop; | |
55 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); | |
56 proxy->EchoMailbox(input, [mailbox_name, &loop](const Mailbox& pass) { | |
57 gpu::Mailbox test_mailbox; | |
58 test_mailbox.SetName(mailbox_name); | |
59 EXPECT_EQ(test_mailbox, pass); | |
60 loop.Quit(); | |
61 }); | |
62 loop.Run(); | |
63 } | |
64 | |
65 TEST_F(StructTraitsTest, MailboxHolder) { | |
66 gpu::MailboxHolder input; | |
67 const int8_t mailbox_name[GL_MAILBOX_SIZE_CHROMIUM] = { | |
68 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, | |
69 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7, | |
70 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7}; | |
71 gpu::Mailbox mailbox; | |
72 mailbox.SetName(mailbox_name); | |
73 const gpu::CommandBufferNamespace namespace_id = gpu::IN_PROCESS; | |
74 const int32_t extra_data_field = 0xbeefbeef; | |
75 const gpu::CommandBufferId command_buffer_id( | |
76 gpu::CommandBufferId::FromUnsafeValue(0xdeadbeef)); | |
77 const uint64_t release_count = 0xdeadbeefdead; | |
Tom Sepez
2016/05/31 17:30:24
nit: Probably should have an L suffix?
Fady Samuel
2016/05/31 17:59:58
Done.
| |
78 const gpu::SyncToken sync_token(namespace_id, extra_data_field, | |
79 command_buffer_id, release_count); | |
80 const uint32_t texture_target = 1337; | |
81 input.mailbox = mailbox; | |
82 input.sync_token = sync_token; | |
83 input.texture_target = texture_target; | |
84 | |
85 base::RunLoop loop; | |
86 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); | |
87 proxy->EchoMailboxHolder(input, [mailbox, sync_token, texture_target, | |
88 &loop](const MailboxHolder& pass) { | |
89 EXPECT_EQ(mailbox, pass.mailbox); | |
90 EXPECT_EQ(sync_token, pass.sync_token); | |
91 EXPECT_EQ(texture_target, pass.texture_target); | |
92 loop.Quit(); | |
93 }); | |
94 } | |
95 | |
96 TEST_F(StructTraitsTest, SyncToken) { | |
97 const gpu::CommandBufferNamespace namespace_id = gpu::IN_PROCESS; | |
98 const int32_t extra_data_field = 0xbeefbeef; | |
99 const gpu::CommandBufferId command_buffer_id( | |
100 gpu::CommandBufferId::FromUnsafeValue(0xdeadbeef)); | |
101 const uint64_t release_count = 0xdeadbeefdead; | |
102 const bool verified_flush = false; | |
103 gpu::SyncToken input(namespace_id, extra_data_field, command_buffer_id, | |
104 release_count); | |
105 base::RunLoop loop; | |
106 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); | |
107 proxy->EchoSyncToken( | |
108 input, [namespace_id, extra_data_field, command_buffer_id, release_count, | |
109 verified_flush, &loop](const SyncToken& pass) { | |
110 EXPECT_EQ(namespace_id, pass.namespace_id()); | |
111 EXPECT_EQ(extra_data_field, pass.extra_data_field()); | |
112 EXPECT_EQ(command_buffer_id, pass.command_buffer_id()); | |
113 EXPECT_EQ(release_count, pass.release_count()); | |
114 EXPECT_EQ(verified_flush, pass.verified_flush()); | |
115 loop.Quit(); | |
116 }); | |
117 loop.Run(); | |
118 } | |
119 | |
120 } // namespace gpu | |
OLD | NEW |