diff --git a/gtests/net/packetdrill/config.c b/gtests/net/packetdrill/config.c index 2c29cbc115d354cbd0ffd4bf37a479cc98406e59..4df80329ee7e42e56ffdf7679be6c79c1ba86cfe 100644 --- a/gtests/net/packetdrill/config.c +++ b/gtests/net/packetdrill/config.c @@ -119,7 +119,7 @@ void show_usage(void) "\t[--wire_server_dev=<eth_dev_name>]\n" "\t[--dry_run]\n" "\t[--verbose|-v]\n" - "\t[--debug]\n" + "\t[--debug] * requires compilation with DEBUG *\n" "\tscript_path ...\n"); } @@ -470,6 +470,9 @@ static void process_option(int opt, char *optarg, struct config *config, config->verbose = true; break; case OPT_DEBUG: +#if !defined(DEBUG) + die("error: --debug requires building with DEBUG on.\n"); +#endif debug_logging = true; break; default: diff --git a/gtests/net/packetdrill/logging.h b/gtests/net/packetdrill/logging.h index 53a2c60189376537d01dfc23087702643191ecd1..a537ffa4e6dc42b9e830693a422e708b1017a253 100644 --- a/gtests/net/packetdrill/logging.h +++ b/gtests/net/packetdrill/logging.h @@ -31,11 +31,15 @@ extern int debug_logging; /* Use a gcc variadic macro to conditionally compile debug printing. */ +#if defined(DEBUG) #define DEBUGP(...) \ if (debug_logging) { \ fprintf(stdout, __VA_ARGS__); \ fflush(stdout); \ } +#else +#define DEBUGP(...) {} +#endif /* DEBUG */ /* Log the message to stderr and then exit with a failure status code. */ extern void die(char *format, ...); diff --git a/gtests/net/packetdrill/packet_parser.c b/gtests/net/packetdrill/packet_parser.c index 056b1e0ea24b81315f4bee9e08dd63c27787f8d1..03209545f813bef3db8fa1325ea5cd402d4386c0 100644 --- a/gtests/net/packetdrill/packet_parser.c +++ b/gtests/net/packetdrill/packet_parser.c @@ -232,6 +232,7 @@ static int parse_ipv4(struct packet *packet, u8 *header_start, u8 *packet_end, p += ip_header_bytes; assert(p <= packet_end); +#if defined(DEBUG) if (debug_logging) { char src_string[ADDR_STR_LEN]; char dst_string[ADDR_STR_LEN]; @@ -241,6 +242,7 @@ static int parse_ipv4(struct packet *packet, u8 *header_start, u8 *packet_end, DEBUGP("src IP: %s\n", ip_to_string(&src_ip, src_string)); DEBUGP("dst IP: %s\n", ip_to_string(&dst_ip, dst_string)); } +#endif /* DEBUG */ /* Examine the L4 header. */ const int layer4_bytes = ip_total_bytes - ip_header_bytes; @@ -304,6 +306,7 @@ static int parse_ipv6(struct packet *packet, u8 *header_start, u8 *packet_end, p += ip_header_bytes; assert(p <= packet_end); +#if defined(DEBUG) if (debug_logging) { char src_string[ADDR_STR_LEN]; char dst_string[ADDR_STR_LEN]; @@ -313,6 +316,7 @@ static int parse_ipv6(struct packet *packet, u8 *header_start, u8 *packet_end, DEBUGP("src IP: %s\n", ip_to_string(&src_ip, src_string)); DEBUGP("dst IP: %s\n", ip_to_string(&dst_ip, dst_string)); } +#endif /* DEBUG */ /* Examine the L4 header. */ const int layer4_bytes = ip_total_bytes - ip_header_bytes; diff --git a/gtests/net/packetdrill/run_packet.c b/gtests/net/packetdrill/run_packet.c index 30638f1a93f92a90efc96cbee2107641a44239c3..07ebe30a5e95ef864bab4bd468aa00d0e8c6d6e4 100644 --- a/gtests/net/packetdrill/run_packet.c +++ b/gtests/net/packetdrill/run_packet.c @@ -328,6 +328,7 @@ static struct socket *handle_listen_for_script_packet( socket->live.remote_isn = ntohl(packet->tcp->seq); } +#if defined(DEBUG) if (debug_logging) { char local_string[ADDR_STR_LEN]; char remote_string[ADDR_STR_LEN]; @@ -344,6 +345,7 @@ static struct socket *handle_listen_for_script_packet( DEBUGP("live: initial tsn: %u\n", socket->live.remote_initial_tsn); } } +#endif /* DEBUG */ return socket; } diff --git a/gtests/net/packetdrill/run_system_call.c b/gtests/net/packetdrill/run_system_call.c index 6972d661c9529077d381b69ab30ca185040f5235..88db2335e4567549ae218ac672644f5e29d0fc13 100644 --- a/gtests/net/packetdrill/run_system_call.c +++ b/gtests/net/packetdrill/run_system_call.c @@ -1841,6 +1841,7 @@ static int run_syscall_accept(struct state *state, } for (socket = state->sockets; socket != NULL; socket = socket->next) { +#if defined(DEBUG) if (debug_logging) { char remote_string[ADDR_STR_LEN]; DEBUGP("socket state=%d script addr: %s:%d\n", @@ -1849,7 +1850,7 @@ static int run_syscall_accept(struct state *state, remote_string), socket->script.remote.port); } - +#endif /* DEBUG */ if ((socket->state == SOCKET_PASSIVE_SYNACK_SENT) || /* TFO */ (socket->state == SOCKET_PASSIVE_SYNACK_ACKED) || (socket->state == SOCKET_PASSIVE_COOKIE_ECHO_RECEIVED)) { @@ -1886,6 +1887,7 @@ static int run_syscall_accept(struct state *state, socket->live.fd = live_accepted_fd; socket->script.fd = script_accepted_fd; +#if defined(DEBUG) if (debug_logging) { char local_string[ADDR_STR_LEN]; char remote_string[ADDR_STR_LEN]; @@ -1896,6 +1898,7 @@ static int run_syscall_accept(struct state *state, ip_to_string(&socket->live.remote.ip, remote_string), ntohs(socket->live.remote.port)); } +#endif /* DEBUG */ return STATUS_OK; }