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

Side by Side Diff: test/cctest/test-debug.cc

Issue 23484014: Cleanup Socket class and remove it from the platform files. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Cleanup leftover junk, and rename test-sockets to test-socket. Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 19 matching lines...) Expand all
30 #include <stdlib.h> 30 #include <stdlib.h>
31 31
32 #define V8_DISABLE_DEPRECATIONS 1 32 #define V8_DISABLE_DEPRECATIONS 1
33 #include "v8.h" 33 #include "v8.h"
34 34
35 #include "api.h" 35 #include "api.h"
36 #include "cctest.h" 36 #include "cctest.h"
37 #include "compilation-cache.h" 37 #include "compilation-cache.h"
38 #include "debug.h" 38 #include "debug.h"
39 #include "deoptimizer.h" 39 #include "deoptimizer.h"
40 #include "platform.h" 40 #include "platform/socket.h"
41 #include "stub-cache.h" 41 #include "stub-cache.h"
42 #include "utils.h" 42 #include "utils.h"
43 #undef V8_DISABLE_DEPRECATIONS 43 #undef V8_DISABLE_DEPRECATIONS
44 44
45 45
46 using ::v8::internal::EmbeddedVector; 46 using ::v8::internal::EmbeddedVector;
47 using ::v8::internal::Object; 47 using ::v8::internal::Object;
48 using ::v8::internal::OS; 48 using ::v8::internal::OS;
49 using ::v8::internal::Handle; 49 using ::v8::internal::Handle;
50 using ::v8::internal::Heap; 50 using ::v8::internal::Heap;
(...skipping 5889 matching lines...) Expand 10 before | Expand all | Expand 10 after
5940 const int kPort2 = 5857 + FlagDependentPortOffset(); 5940 const int kPort2 = 5857 + FlagDependentPortOffset();
5941 const int kPort3 = 5856 + FlagDependentPortOffset(); 5941 const int kPort3 = 5856 + FlagDependentPortOffset();
5942 5942
5943 // Make a string with the port2 number. 5943 // Make a string with the port2 number.
5944 const int kPortBufferLen = 6; 5944 const int kPortBufferLen = 6;
5945 char port2_str[kPortBufferLen]; 5945 char port2_str[kPortBufferLen];
5946 OS::SNPrintF(i::Vector<char>(port2_str, kPortBufferLen), "%d", kPort2); 5946 OS::SNPrintF(i::Vector<char>(port2_str, kPortBufferLen), "%d", kPort2);
5947 5947
5948 bool ok; 5948 bool ok;
5949 5949
5950 // Initialize the socket library.
5951 i::Socket::SetUp();
5952
5953 // Test starting and stopping the agent without any client connection. 5950 // Test starting and stopping the agent without any client connection.
5954 debugger->StartAgent("test", kPort1); 5951 debugger->StartAgent("test", kPort1);
5955 debugger->StopAgent(); 5952 debugger->StopAgent();
5956 // Test starting the agent, connecting a client and shutting down the agent 5953 // Test starting the agent, connecting a client and shutting down the agent
5957 // with the client connected. 5954 // with the client connected.
5958 ok = debugger->StartAgent("test", kPort2); 5955 ok = debugger->StartAgent("test", kPort2);
5959 CHECK(ok); 5956 CHECK(ok);
5960 debugger->WaitForAgent(); 5957 debugger->WaitForAgent();
5961 i::Socket* client = i::OS::CreateSocket(); 5958 i::Socket* client = new i::Socket;
5962 ok = client->Connect("localhost", port2_str); 5959 ok = client->Connect("localhost", port2_str);
5963 CHECK(ok); 5960 CHECK(ok);
5964 // It is important to wait for a message from the agent. Otherwise, 5961 // It is important to wait for a message from the agent. Otherwise,
5965 // we can close the server socket during "accept" syscall, making it failing 5962 // we can close the server socket during "accept" syscall, making it failing
5966 // (at least on Linux), and the test will work incorrectly. 5963 // (at least on Linux), and the test will work incorrectly.
5967 char buf; 5964 char buf;
5968 ok = client->Receive(&buf, 1) == 1; 5965 ok = client->Receive(&buf, 1) == 1;
5969 CHECK(ok); 5966 CHECK(ok);
5970 debugger->StopAgent(); 5967 debugger->StopAgent();
5971 delete client; 5968 delete client;
5972 5969
5973 // Test starting and stopping the agent with the required port already 5970 // Test starting and stopping the agent with the required port already
5974 // occoupied. 5971 // occoupied.
5975 i::Socket* server = i::OS::CreateSocket(); 5972 i::Socket* server = new i::Socket;
5976 server->Bind(kPort3); 5973 ok = server->Bind(kPort3);
5974 CHECK(ok);
5977 5975
5978 debugger->StartAgent("test", kPort3); 5976 debugger->StartAgent("test", kPort3);
5979 debugger->StopAgent(); 5977 debugger->StopAgent();
5980 5978
5981 delete server; 5979 delete server;
5982 } 5980 }
5983 5981
5984 5982
5985 class DebuggerAgentProtocolServerThread : public i::Thread { 5983 class DebuggerAgentProtocolServerThread : public i::Thread {
5986 public: 5984 public:
(...skipping 20 matching lines...) Expand all
6007 i::Socket* server_; // Server socket used for bind/accept. 6005 i::Socket* server_; // Server socket used for bind/accept.
6008 i::Socket* client_; // Single client connection used by the test. 6006 i::Socket* client_; // Single client connection used by the test.
6009 i::Semaphore listening_; // Signalled when the server is in listen mode. 6007 i::Semaphore listening_; // Signalled when the server is in listen mode.
6010 }; 6008 };
6011 6009
6012 6010
6013 void DebuggerAgentProtocolServerThread::Run() { 6011 void DebuggerAgentProtocolServerThread::Run() {
6014 bool ok; 6012 bool ok;
6015 6013
6016 // Create the server socket and bind it to the requested port. 6014 // Create the server socket and bind it to the requested port.
6017 server_ = i::OS::CreateSocket(); 6015 server_ = new i::Socket;
6018 CHECK(server_ != NULL); 6016 CHECK(server_ != NULL);
6019 ok = server_->Bind(port_); 6017 ok = server_->Bind(port_);
6020 CHECK(ok); 6018 CHECK(ok);
6021 6019
6022 // Listen for new connections. 6020 // Listen for new connections.
6023 ok = server_->Listen(1); 6021 ok = server_->Listen(1);
6024 CHECK(ok); 6022 CHECK(ok);
6025 listening_.Signal(); 6023 listening_.Signal();
6026 6024
6027 // Accept a connection. 6025 // Accept a connection.
6028 client_ = server_->Accept(); 6026 client_ = server_->Accept();
6029 CHECK(client_ != NULL); 6027 CHECK(client_ != NULL);
6030 6028
6031 // Receive a debugger agent protocol message. 6029 // Receive a debugger agent protocol message.
6032 i::DebuggerAgentUtil::ReceiveMessage(client_); 6030 i::DebuggerAgentUtil::ReceiveMessage(client_);
6033 } 6031 }
6034 6032
6035 6033
6036 TEST(DebuggerAgentProtocolOverflowHeader) { 6034 TEST(DebuggerAgentProtocolOverflowHeader) {
6037 // Make sure this port is not used by other tests to allow tests to run in 6035 // Make sure this port is not used by other tests to allow tests to run in
6038 // parallel. 6036 // parallel.
6039 const int kPort = 5860 + FlagDependentPortOffset(); 6037 const int kPort = 5860 + FlagDependentPortOffset();
6040 static const char* kLocalhost = "localhost"; 6038 static const char* kLocalhost = "localhost";
6041 6039
6042 // Make a string with the port number. 6040 // Make a string with the port number.
6043 const int kPortBufferLen = 6; 6041 const int kPortBufferLen = 6;
6044 char port_str[kPortBufferLen]; 6042 char port_str[kPortBufferLen];
6045 OS::SNPrintF(i::Vector<char>(port_str, kPortBufferLen), "%d", kPort); 6043 OS::SNPrintF(i::Vector<char>(port_str, kPortBufferLen), "%d", kPort);
6046 6044
6047 // Initialize the socket library.
6048 i::Socket::SetUp();
6049
6050 // Create a socket server to receive a debugger agent message. 6045 // Create a socket server to receive a debugger agent message.
6051 DebuggerAgentProtocolServerThread* server = 6046 DebuggerAgentProtocolServerThread* server =
6052 new DebuggerAgentProtocolServerThread(kPort); 6047 new DebuggerAgentProtocolServerThread(kPort);
6053 server->Start(); 6048 server->Start();
6054 server->WaitForListening(); 6049 server->WaitForListening();
6055 6050
6056 // Connect. 6051 // Connect.
6057 i::Socket* client = i::OS::CreateSocket(); 6052 i::Socket* client = new i::Socket;
6058 CHECK(client != NULL); 6053 CHECK(client != NULL);
6059 bool ok = client->Connect(kLocalhost, port_str); 6054 bool ok = client->Connect(kLocalhost, port_str);
6060 CHECK(ok); 6055 CHECK(ok);
6061 6056
6062 // Send headers which overflow the receive buffer. 6057 // Send headers which overflow the receive buffer.
6063 static const int kBufferSize = 1000; 6058 static const int kBufferSize = 1000;
6064 char buffer[kBufferSize]; 6059 char buffer[kBufferSize];
6065 6060
6066 // Long key and short value: XXXX....XXXX:0\r\n. 6061 // Long key and short value: XXXX....XXXX:0\r\n.
6067 for (int i = 0; i < kBufferSize - 4; i++) { 6062 for (int i = 0; i < kBufferSize - 4; i++) {
6068 buffer[i] = 'X'; 6063 buffer[i] = 'X';
6069 } 6064 }
6070 buffer[kBufferSize - 4] = ':'; 6065 buffer[kBufferSize - 4] = ':';
6071 buffer[kBufferSize - 3] = '0'; 6066 buffer[kBufferSize - 3] = '0';
6072 buffer[kBufferSize - 2] = '\r'; 6067 buffer[kBufferSize - 2] = '\r';
6073 buffer[kBufferSize - 1] = '\n'; 6068 buffer[kBufferSize - 1] = '\n';
6074 client->Send(buffer, kBufferSize); 6069 int result = client->Send(buffer, kBufferSize);
6070 CHECK_EQ(kBufferSize, result);
6075 6071
6076 // Short key and long value: X:XXXX....XXXX\r\n. 6072 // Short key and long value: X:XXXX....XXXX\r\n.
6077 buffer[0] = 'X'; 6073 buffer[0] = 'X';
6078 buffer[1] = ':'; 6074 buffer[1] = ':';
6079 for (int i = 2; i < kBufferSize - 2; i++) { 6075 for (int i = 2; i < kBufferSize - 2; i++) {
6080 buffer[i] = 'X'; 6076 buffer[i] = 'X';
6081 } 6077 }
6082 buffer[kBufferSize - 2] = '\r'; 6078 buffer[kBufferSize - 2] = '\r';
6083 buffer[kBufferSize - 1] = '\n'; 6079 buffer[kBufferSize - 1] = '\n';
6084 client->Send(buffer, kBufferSize); 6080 result = client->Send(buffer, kBufferSize);
6081 CHECK_EQ(kBufferSize, result);
6085 6082
6086 // Add empty body to request. 6083 // Add empty body to request.
6087 const char* content_length_zero_header = "Content-Length:0\r\n"; 6084 const char* content_length_zero_header = "Content-Length:0\r\n";
6088 client->Send(content_length_zero_header, 6085 int length = StrLength(content_length_zero_header);
6089 StrLength(content_length_zero_header)); 6086 result = client->Send(content_length_zero_header, length);
6090 client->Send("\r\n", 2); 6087 CHECK_EQ(length, result);
6088 result = client->Send("\r\n", 2);
6089 CHECK_EQ(2, result);
6091 6090
6092 // Wait until data is received. 6091 // Wait until data is received.
6093 server->Join(); 6092 server->Join();
6094 6093
6095 // Check for empty body. 6094 // Check for empty body.
6096 CHECK(server->body() == NULL); 6095 CHECK(server->body() == NULL);
6097 6096
6098 // Close the client before the server to avoid TIME_WAIT issues. 6097 // Close the client before the server to avoid TIME_WAIT issues.
6099 client->Shutdown(); 6098 client->Shutdown();
6100 delete client; 6099 delete client;
(...skipping 1447 matching lines...) Expand 10 before | Expand all | Expand 10 after
7548 TEST(LiveEditDisabled) { 7547 TEST(LiveEditDisabled) {
7549 v8::internal::FLAG_allow_natives_syntax = true; 7548 v8::internal::FLAG_allow_natives_syntax = true;
7550 LocalContext env; 7549 LocalContext env;
7551 v8::HandleScope scope(env->GetIsolate()); 7550 v8::HandleScope scope(env->GetIsolate());
7552 v8::Debug::SetLiveEditEnabled(false); 7551 v8::Debug::SetLiveEditEnabled(false);
7553 CompileRun("%LiveEditCompareStrings('', '')"); 7552 CompileRun("%LiveEditCompareStrings('', '')");
7554 } 7553 }
7555 7554
7556 7555
7557 #endif // ENABLE_DEBUGGER_SUPPORT 7556 #endif // ENABLE_DEBUGGER_SUPPORT
OLDNEW
« src/platform.h ('K') | « test/cctest/cctest.status ('k') | test/cctest/test-socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698