Skip to content

Commit

Permalink
Bug 1293156 - Make ssl_gtest less verbose by default, r=ekr,ttaubert
Browse files Browse the repository at this point in the history
  • Loading branch information
martinthomson committed Aug 9, 2016
1 parent 0c9572b commit a78f050
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
8 changes: 3 additions & 5 deletions external_tests/ssl_gtest/databuffer.h
Expand Up @@ -18,6 +18,8 @@
#include <arpa/inet.h>
#endif

extern bool g_ssl_gtest_verbose;

namespace nss_test {

class DataBuffer {
Expand Down Expand Up @@ -156,16 +158,12 @@ class DataBuffer {
size_t len_;
};

#ifdef DEBUG
static const size_t kMaxBufferPrint = 10000;
#else
static const size_t kMaxBufferPrint = 32;
#endif

inline std::ostream& operator<<(std::ostream& stream, const DataBuffer& buf) {
stream << "[" << buf.len() << "] ";
for (size_t i = 0; i < buf.len(); ++i) {
if (i >= kMaxBufferPrint) {
if (!g_ssl_gtest_verbose && i >= kMaxBufferPrint) {
stream << "...";
break;
}
Expand Down
4 changes: 4 additions & 0 deletions external_tests/ssl_gtest/ssl_gtest.cc
Expand Up @@ -11,11 +11,13 @@
#include "gtest/gtest.h"

std::string g_working_dir_path;
bool g_ssl_gtest_verbose;

int main(int argc, char **argv) {
// Start the tests
::testing::InitGoogleTest(&argc, argv);
g_working_dir_path = ".";
g_ssl_gtest_verbose = false;

char* workdir = PR_GetEnvSecure("NSS_GTEST_WORKDIR");
if (workdir)
Expand All @@ -25,6 +27,8 @@ int main(int argc, char **argv) {
if (!strcmp(argv[i], "-d")) {
g_working_dir_path = argv[i + 1];
++i;
} else if (!strcmp(argv[i], "-v")) {
g_ssl_gtest_verbose = true;
}
}

Expand Down
12 changes: 9 additions & 3 deletions external_tests/ssl_gtest/test_io.cc
Expand Up @@ -17,6 +17,8 @@

#include "databuffer.h"

extern bool g_ssl_gtest_verbose;

namespace nss_test {

static PRDescIdentity test_fd_identity = PR_INVALID_IO_LAYER;
Expand All @@ -28,6 +30,7 @@ static PRDescIdentity test_fd_identity = PR_INVALID_IO_LAYER;
PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0)

#define LOG(a) std::cerr << name_ << ": " << a << std::endl
#define LOGV(a) do { if (g_ssl_gtest_verbose) LOG(a); } while(false)

class Packet : public DataBuffer {
public:
Expand Down Expand Up @@ -313,7 +316,7 @@ int32_t DummyPrSocket::Read(void *data, int32_t len) {
}

if (input_.empty()) {
LOG("Read --> wouldblock " << len);
LOGV("Read --> wouldblock " << len);
PR_SetError(PR_WOULD_BLOCK_ERROR, 0);
return -1;
}
Expand Down Expand Up @@ -378,6 +381,7 @@ int32_t DummyPrSocket::Write(const void *buf, int32_t length) {
LOG("Droppped packet: " << packet);
break;
case PacketFilter::KEEP:
LOGV("Packet: " << packet);
peer_->PacketReceived(packet);
break;
}
Expand Down Expand Up @@ -458,8 +462,10 @@ void Poller::SetTimer(uint32_t timer_ms, PollTarget *target, PollCallback cb,
}

bool Poller::Poll() {
std::cerr << "Poll() waiters = " << waiters_.size()
<< " timers = " << timers_.size() << std::endl;
if (g_ssl_gtest_verbose) {
std::cerr << "Poll() waiters = " << waiters_.size()
<< " timers = " << timers_.size() << std::endl;
}
PRIntervalTime timeout = PR_INTERVAL_NO_TIMEOUT;
PRTime now = PR_Now();
bool fired = false;
Expand Down
19 changes: 6 additions & 13 deletions external_tests/ssl_gtest/tls_agent.cc
Expand Up @@ -653,7 +653,7 @@ void TlsAgent::SetDowngradeCheckVersion(uint16_t version) {
}

void TlsAgent::Handshake() {
LOG("Handshake");
LOGV("Handshake");
SECStatus rv = SSL_ForceHandshake(ssl_fd_);
if (rv == SECSuccess) {
Connected();
Expand Down Expand Up @@ -685,15 +685,8 @@ void TlsAgent::Handshake() {
return;
}

if (IS_SSL_ERROR(err)) {
LOG("Handshake failed with SSL error " << (err - SSL_ERROR_BASE)
<< " (" << PORT_ErrorToName(err)
<< "): " << PORT_ErrorToString(err));
} else {
LOG("Handshake failed with error " << err
<< " (" << PORT_ErrorToName(err)
<< "): " << PORT_ErrorToString(err));
}
LOG("Handshake failed with error " << PORT_ErrorToName(err)
<< ": " << PORT_ErrorToString(err));
error_code_ = err;
SetState(STATE_ERROR);
}
Expand Down Expand Up @@ -729,7 +722,7 @@ void TlsAgent::SendData(size_t bytes, size_t blocksize) {
++send_ctr_;
}

LOG("Writing " << tosend << " bytes");
LOGV("Writing " << tosend << " bytes");
int32_t rv = PR_Write(ssl_fd_, block, tosend);
ASSERT_EQ(tosend, static_cast<size_t>(rv));

Expand All @@ -746,7 +739,7 @@ void TlsAgent::ReadBytes() {
uint8_t block[1024];

int32_t rv = PR_Read(ssl_fd_, block, sizeof(block));
LOG("ReadBytes " << rv);
LOGV("ReadBytes " << rv);
int32_t err;

if (rv >= 0) {
Expand All @@ -765,7 +758,7 @@ void TlsAgent::ReadBytes() {

// If closed, then don't bother waiting around.
if (rv > 0 || (rv < 0 && ErrorIsNonFatal(err))) {
LOG("Re-arming");
LOGV("Re-arming");
Poller::Instance()->Wait(READABLE_EVENT, adapter_, this,
&TlsAgent::ReadableCallback);
}
Expand Down
5 changes: 4 additions & 1 deletion external_tests/ssl_gtest/tls_agent.h
Expand Up @@ -18,9 +18,12 @@
#define GTEST_HAS_RTTI 0
#include "gtest/gtest.h"

extern bool g_ssl_gtest_verbose;

namespace nss_test {

#define LOG(msg) std::cerr << role_str() << ": " << msg << std::endl
#define LOGV(msg) do { if (g_ssl_gtest_verbose) LOG(msg); } while(false)

enum SessionResumptionMode {
RESUME_NONE = 0,
Expand Down Expand Up @@ -250,7 +253,7 @@ class TlsAgent : public PollTarget {
}

void ReadableCallback_int() {
LOG("Readable");
LOGV("Readable");
switch (state_) {
case STATE_CONNECTING:
Handshake();
Expand Down

0 comments on commit a78f050

Please sign in to comment.