summaryrefslogtreecommitdiffstats
path: root/ppapi/tests
diff options
context:
space:
mode:
authorbbudge <bbudge@chromium.org>2015-01-14 14:42:01 -0800
committerCommit bot <commit-bot@chromium.org>2015-01-14 22:42:45 +0000
commitc76a0f987cf778d0cb14da86f132af9a0b200f72 (patch)
tree482fbcc5cdc268b7643f743bd909bab2cc63bc7c /ppapi/tests
parente6ed553d2cc9c34a1e5de42a803a92ad542ca3c9 (diff)
downloadchromium_src-c76a0f987cf778d0cb14da86f132af9a0b200f72.zip
chromium_src-c76a0f987cf778d0cb14da86f132af9a0b200f72.tar.gz
chromium_src-c76a0f987cf778d0cb14da86f132af9a0b200f72.tar.bz2
Pepper: Allow plugins to call PPB_UDP_Socket::SendTo multiple times.
This changes the implementation to allow multiple SendTo calls to be in flight at the same time. The plugin can now call SendTo multiple times before getting PP_ERROR_INPROGRESS. The number of calls is an implementation detail. Plugins that want maximum performance should call SendTo continuously until they get an in progress result, then wait for one or more previous calls to complete before calling Send again. The resource is changed to queue SendTo callbacks. It checks that the plugin stays within the limit, which is currently 8. The browser message filter is changed to call SendTo until the socket is busy, then queue the sends. It checks that the plugin can't grow the queue past the limit. In theory, a plugin could go over the limit by bypassing the resource checks but not saturating the socket. This is not really a problem. Adds a test to send multiple messages in the "optional callbacks" case. BUG=154338 Review URL: https://codereview.chromium.org/632113003 Cr-Commit-Position: refs/heads/master@{#311563}
Diffstat (limited to 'ppapi/tests')
-rw-r--r--ppapi/tests/test_udp_socket.cc71
-rw-r--r--ppapi/tests/test_udp_socket.h1
2 files changed, 72 insertions, 0 deletions
diff --git a/ppapi/tests/test_udp_socket.cc b/ppapi/tests/test_udp_socket.cc
index 8972e4e..2b05682 100644
--- a/ppapi/tests/test_udp_socket.cc
+++ b/ppapi/tests/test_udp_socket.cc
@@ -83,6 +83,7 @@ void TestUDPSocket::RunTests(const std::string& filter) {
RUN_CALLBACK_TEST(TestUDPSocket, ReadWrite, filter);
RUN_CALLBACK_TEST(TestUDPSocket, Broadcast, filter);
RUN_CALLBACK_TEST(TestUDPSocket, SetOption, filter);
+ RUN_CALLBACK_TEST(TestUDPSocket, ParallelSend, filter);
}
std::string TestUDPSocket::GetLocalAddress(pp::NetAddress* address) {
@@ -315,3 +316,73 @@ std::string TestUDPSocket::TestSetOption() {
PASS();
}
+
+std::string TestUDPSocket::TestParallelSend() {
+ // This test only makes sense when callbacks are optional.
+ if (callback_type() != PP_OPTIONAL)
+ PASS();
+
+ pp::UDPSocket server_socket(instance_), client_socket(instance_);
+ pp::NetAddress server_address, client_address;
+
+ ASSERT_SUBTEST_SUCCESS(
+ LookupPortAndBindUDPSocket(&server_socket, &server_address));
+ ASSERT_SUBTEST_SUCCESS(
+ LookupPortAndBindUDPSocket(&client_socket, &client_address));
+ const std::string message = "Simple message that will be sent via UDP";
+ pp::NetAddress recvfrom_address;
+
+ const size_t kParallelSends = 10;
+ std::vector<TestCompletionCallback*> sendto_callbacks(kParallelSends);
+ std::vector<int32_t> sendto_results(kParallelSends);
+ size_t pending = 0;
+ for (size_t i = 0; i < kParallelSends; i++) {
+ sendto_callbacks[i] =
+ new TestCompletionCallback(instance_->pp_instance(), callback_type());
+ sendto_results[i] =
+ client_socket.SendTo(message.c_str(),
+ message.size(),
+ server_address,
+ sendto_callbacks[i]->GetCallback());
+
+ if (sendto_results[i] == PP_ERROR_INPROGRESS) {
+ // Run a pending send to completion to free a slot for the current send.
+ ASSERT_GT(i, pending);
+ sendto_callbacks[pending]->WaitForResult(sendto_results[pending]);
+ CHECK_CALLBACK_BEHAVIOR(*sendto_callbacks[pending]);
+ ASSERT_EQ(message.size(),
+ static_cast<size_t>(sendto_callbacks[pending]->result()));
+ pending++;
+ // Try to send the message again.
+ sendto_results[i] =
+ client_socket.SendTo(message.c_str(),
+ message.size(),
+ server_address,
+ sendto_callbacks[i]->GetCallback());
+ ASSERT_NE(PP_ERROR_INPROGRESS, sendto_results[i]);
+ }
+ }
+
+ // Finish all pending sends.
+ for (size_t i = pending; i < kParallelSends; i++) {
+ sendto_callbacks[i]->WaitForResult(sendto_results[i]);
+ CHECK_CALLBACK_BEHAVIOR(*sendto_callbacks[i]);
+ ASSERT_EQ(message.size(),
+ static_cast<size_t>(sendto_callbacks[i]->result()));
+ }
+
+ for (size_t i = 0; i < kParallelSends; ++i)
+ delete sendto_callbacks[i];
+
+ for (size_t i = 0; i < kParallelSends; i++) {
+ std::string str;
+ ASSERT_SUBTEST_SUCCESS(
+ ReadSocket(&server_socket, &recvfrom_address, message.size(), &str));
+ ASSERT_EQ(message, str);
+ }
+
+ server_socket.Close();
+ client_socket.Close();
+
+ PASS();
+}
diff --git a/ppapi/tests/test_udp_socket.h b/ppapi/tests/test_udp_socket.h
index 7c8721e..2a2a473 100644
--- a/ppapi/tests/test_udp_socket.h
+++ b/ppapi/tests/test_udp_socket.h
@@ -43,6 +43,7 @@ class TestUDPSocket: public TestCase {
std::string TestReadWrite();
std::string TestBroadcast();
std::string TestSetOption();
+ std::string TestParallelSend();
pp::NetAddress address_;
};