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

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

Issue 42555: Added a test for debugger agent protocol message (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. 1 // Copyright 2007-2008 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 3812 matching lines...) Expand 10 before | Expand all | Expand 10 after
3823 CHECK_EQ(1, host_dispatch_hit_count); 3823 CHECK_EQ(1, host_dispatch_hit_count);
3824 } 3824 }
3825 3825
3826 3826
3827 TEST(DebuggerAgent) { 3827 TEST(DebuggerAgent) {
3828 // Make sure this port is not used by other tests to allow tests to run in 3828 // Make sure this port is not used by other tests to allow tests to run in
3829 // parallel. 3829 // parallel.
3830 const int kPort = 5858; 3830 const int kPort = 5858;
3831 3831
3832 // Make a string with the port number. 3832 // Make a string with the port number.
3833 const int kPortBuferLen = 6; 3833 const int kPortBufferLen = 6;
3834 char port_str[kPortBuferLen]; 3834 char port_str[kPortBufferLen];
3835 OS::SNPrintF(i::Vector<char>(port_str, kPortBuferLen), "%d", kPort); 3835 OS::SNPrintF(i::Vector<char>(port_str, kPortBufferLen), "%d", kPort);
3836 3836
3837 bool ok; 3837 bool ok;
3838 3838
3839 // Initialize the socket library. 3839 // Initialize the socket library.
3840 i::Socket::Setup(); 3840 i::Socket::Setup();
3841 3841
3842 // Test starting and stopping the agent without any client connection. 3842 // Test starting and stopping the agent without any client connection.
3843 i::Debugger::StartAgent("test", kPort); 3843 i::Debugger::StartAgent("test", kPort);
3844 i::Debugger::StopAgent(); 3844 i::Debugger::StopAgent();
3845 3845
(...skipping 10 matching lines...) Expand all
3856 // Test starting and stopping the agent with the required port already 3856 // Test starting and stopping the agent with the required port already
3857 // occoupied. 3857 // occoupied.
3858 i::Socket* server = i::OS::CreateSocket(); 3858 i::Socket* server = i::OS::CreateSocket();
3859 server->Bind(kPort); 3859 server->Bind(kPort);
3860 3860
3861 i::Debugger::StartAgent("test", kPort); 3861 i::Debugger::StartAgent("test", kPort);
3862 i::Debugger::StopAgent(); 3862 i::Debugger::StopAgent();
3863 3863
3864 delete server; 3864 delete server;
3865 } 3865 }
3866
3867
3868 class DebuggerAgentProtocolServerThread : public i::Thread {
3869 public:
3870 explicit DebuggerAgentProtocolServerThread(int port)
3871 : port_(port), server_(NULL), client_(NULL),
3872 listening_(OS::CreateSemaphore(0)) {
3873 }
3874 ~DebuggerAgentProtocolServerThread() {
3875 // Close both sockets.
3876 delete client_;
3877 delete server_;
3878 delete listening_;
3879 }
3880
3881 void Run();
3882 void WaitForListening() { listening_->Wait(); }
3883 char* body() { return *body_; }
3884
3885 private:
3886 int port_;
3887 i::SmartPointer<char> body_;
3888 i::Socket* server_; // Server socket used for bind/accept.
3889 i::Socket* client_; // Single client connection used by the test.
3890 i::Semaphore* listening_; // Signalled when the server is in listen mode.
3891 };
3892
3893
3894 void DebuggerAgentProtocolServerThread::Run() {
3895 bool ok;
3896
3897 // Create the server socket and bind it to the requested port.
3898 server_ = i::OS::CreateSocket();
3899 CHECK(server_ != NULL);
3900 ok = server_->Bind(port_);
3901 CHECK(ok);
3902
3903 // Listen for new connections.
3904 ok = server_->Listen(1);
3905 CHECK(ok);
3906 listening_->Signal();
3907
3908 // Accept a connection.
3909 client_ = server_->Accept();
3910 CHECK(client_ != NULL);
3911
3912 // Receive a debugger agent protocol message.
3913 i::DebuggerAgentUtil::ReceiveMessage(client_);
3914 }
3915
3916
3917 TEST(DebuggerAgentProtocolOverflowHeader) {
3918 // Make sure this port is not used by other tests to allow tests to run in
3919 // parallel.
3920 const int kPort = 5860;
3921 static const char* kLocalhost = "localhost";
3922
3923 // Make a string with the port number.
3924 const int kPortBufferLen = 6;
3925 char port_str[kPortBufferLen];
3926 OS::SNPrintF(i::Vector<char>(port_str, kPortBufferLen), "%d", kPort);
3927
3928 // Initialize the socket library.
3929 i::Socket::Setup();
3930
3931 // Create a socket server to receive a debugger agent message.
3932 DebuggerAgentProtocolServerThread* server =
3933 new DebuggerAgentProtocolServerThread(kPort);
3934 server->Start();
3935 server->WaitForListening();
3936
3937 // Connect.
3938 i::Socket* client = i::OS::CreateSocket();
3939 CHECK(client != NULL);
3940 bool ok = client->Connect(kLocalhost, port_str);
3941 CHECK(ok);
3942
3943 // Send headers which overflow the receive buffer.
3944 static const int kBufferSize = 1000;
3945 char buffer[kBufferSize];
3946
3947 // Long key and short value: XXXX....XXXX:0\r\n.
3948 for (int i = 0; i < kBufferSize - 4; i++) {
3949 buffer[i] = 'X';
3950 }
3951 buffer[kBufferSize - 4] = ':';
3952 buffer[kBufferSize - 3] = '0';
3953 buffer[kBufferSize - 2] = '\r';
3954 buffer[kBufferSize - 1] = '\n';
3955 client->Send(buffer, kBufferSize);
3956
3957 // Short key and long value: X:XXXX....XXXX\r\n.
3958 buffer[0] = 'X';
3959 buffer[1] = ':';
3960 for (int i = 2; i < kBufferSize - 2; i++) {
3961 buffer[i] = 'X';
3962 }
3963 buffer[kBufferSize - 2] = '\r';
3964 buffer[kBufferSize - 1] = '\n';
3965 client->Send(buffer, kBufferSize);
3966
3967 // Add empty body to request.
3968 const char* content_length_zero_header = "Content-Length:0\r\n";
3969 client->Send(content_length_zero_header, strlen(content_length_zero_header));
3970 client->Send("\r\n", 2);
3971
3972 // Wait until data is received.
3973 server->Join();
3974
3975 // Check for empty body.
3976 CHECK(server->body() == NULL);
3977
3978 // Close the client before the server to avoid TIME_WAIT issues.
3979 client->Shutdown();
3980 delete client;
3981 delete server;
3982 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698