};
static bool debug = FALSE;
+static struct event *test_event, *client_event, *server_event;
static bool small_socket_buffers = FALSE;
static const char *failure = NULL;
static struct timeout *to_continue = NULL;
/* Close the directory */
if (closedir(dirp) < 0)
- i_error("test files: "
+ e_error(test_event, "test files: "
"failed to close directory %s: %m", path);
}
fd = open(path, O_RDONLY);
if (fd < 0) {
- if (debug)
- i_debug("test files: open(%s) failed: %m", path);
+ e_debug(test_event, "test files: open(%s) failed: %m", path);
switch (errno) {
case EFAULT:
fpath = t_strconcat(".", path, NULL);
- if (debug) {
- i_debug("test server: download: "
- "sending payload for %s", fpath);
- }
+ e_debug(server_event, "download: sending payload for %s", fpath);
fstream = test_file_open(fpath, &status, &reason);
if (fstream == NULL) {
i_stream_get_error(fstream));
}
- if (debug) {
- i_debug("test server: download: "
- "finished sending blocking payload for %s"
- "(%"PRIuUOFF_T":%"PRIuUOFF_T")",
- fpath, fstream->v_offset, output->offset);
- }
+ e_debug(server_event, "download: "
+ "finished sending blocking payload for %s"
+ "(%"PRIuUOFF_T":%"PRIuUOFF_T")",
+ fpath, fstream->v_offset, output->offset);
o_stream_destroy(&output);
} else {
}
if (creq->all_sent) {
- if (debug) {
- i_debug("test server: echo: "
- "flushed all payload for %s", creq->path);
- }
+ e_debug(server_event, "echo: flushed all payload for %s",
+ creq->path);
i_stream_unref(&creq->data);
o_stream_destroy(&creq->payload_output);
return 1;
o_stream_set_max_buffer_size(output, SIZE_MAX);
i_assert(creq->data->v_offset >= offset);
- if (debug) {
- i_debug("test server: echo: sent data for %s "
- "(sent %"PRIuUOFF_T", buffered %zu)",
- creq->path, (uoff_t)(creq->data->v_offset - offset),
- o_stream_get_buffer_used_size(output));
- }
+ e_debug(server_event, "echo: sent data for %s "
+ "(sent %"PRIuUOFF_T", buffered %zu)",
+ creq->path, (uoff_t)(creq->data->v_offset - offset),
+ o_stream_get_buffer_used_size(output));
switch (res) {
case OSTREAM_SEND_ISTREAM_RESULT_FINISHED:
o_stream_get_name(output), creq->path,
o_stream_get_error(output));
}
- if (debug) {
- i_debug("test server: echo: "
- "finished sending payload for %s", creq->path);
- }
+ e_debug(server_event, "echo: finished sending payload for %s",
+ creq->path);
if (ret == 0)
return 0;
- if (debug) {
- i_debug("test server: echo: "
- "flushed all payload for %s", creq->path);
- }
+ e_debug(server_event, "echo: flushed all payload for %s",
+ creq->path);
i_stream_unref(&creq->data);
o_stream_destroy(&creq->payload_output);
return 1;
case OSTREAM_SEND_ISTREAM_RESULT_WAIT_INPUT:
i_unreached();
case OSTREAM_SEND_ISTREAM_RESULT_WAIT_OUTPUT:
- if (debug) {
- i_debug("test server echo: "
- "partially sent payload for %s", creq->path);
- }
+ e_debug(server_event, "echo: "
+ "partially sent payload for %s", creq->path);
return 1;
case OSTREAM_SEND_ISTREAM_RESULT_ERROR_INPUT:
i_fatal("test server: echo: "
"failed to finish blocking payload for %s", creq->path);
}
- if (debug) {
- i_debug("test server: echo: "
- "sent all payload for %s", creq->path);
- }
+ e_debug(server_event, "echo: sent all payload for %s", creq->path);
}
static void
i_stream_get_error(input));
}
- if (debug) {
- i_debug("test server: echo: "
- "sent all payload for %s", creq->path);
- }
+ e_debug(server_event, "echo: sent all payload for %s", creq->path);
o_stream_destroy(&payload_output);
}
payload_input =
iostream_temp_finish(&creq->payload_output, 4096);
- if (debug) {
- i_debug("test server: echo: "
- "finished receiving payload for %s", creq->path);
- }
+ e_debug(server_event, "echo: finished receiving payload for %s",
+ creq->path);
resp = http_server_response_create(creq->server_req, 200, "OK");
http_server_response_add_header(resp, "Content-Type", "text/plain");
io_remove(&creq->io);
- if (debug) {
- i_debug("test server: echo: "
- "finished receiving payload for %s",
- creq->path);
- }
+ e_debug(server_event, "echo: finished receiving payload for %s",
+ creq->path);
}
static void
size = 0;
if (http_request_get_payload_size(hreq, &size) > 0 && size == 0) {
- if (debug) {
- i_debug("test server: echo: "
- "empty payload for %s", creq->path);
- }
+ e_debug(server_event, "echo: empty payload for %s", creq->path);
resp = http_server_response_create(creq->server_req, 200, "OK");
http_server_response_add_header(
payload_input = iostream_temp_finish(&payload_output, 4096);
- if (debug) {
- i_debug("test server: echo: "
- "finished receiving blocking payload for %s",
- path);
- }
+ e_debug(server_event, "echo: "
+ "finished receiving blocking payload for %s",
+ path);
resp = http_server_response_create(req, 200, "OK");
http_server_response_add_header(resp,
i_assert(hreq->target.url->have_ssl == tset.ssl);
- if (debug) {
- i_debug("test server: request method=`%s' path=`%s'",
- hreq->method, path);
- }
+ e_debug(server_event, "request method=`%s' path=`%s'",
+ hreq->method, path);
creq = client_request_init(client, req);
/* read payload */
while ((ret = i_stream_read_more(payload, &pdata, &psize)) > 0) {
- if (debug) {
- i_debug("test client: download: "
- "got data for [%u] (size=%d)",
- tcreq->files_idx, (int)psize);
- }
+ e_debug(client_event, "download: got data for [%u] (size=%d)",
+ tcreq->files_idx, (int)psize);
/* compare with file on disk */
pleft = psize;
while ((ret = i_stream_read_more(tcreq->file_in,
}
if (ret == 0) {
- if (debug) {
- i_debug("test client: download: "
- "need more data for [%u]",
- tcreq->files_idx);
- }
+ e_debug(client_event, "download: need more data for [%u]",
+ tcreq->files_idx);
/* we will be called again for this request */
} else {
(void)i_stream_read(tcreq->file_in);
i_fatal("test client: download: "
"payload ended prematurely "
"(at least %zu bytes left)", fsize);
- } else if (debug) {
- i_debug("test client: download: "
+ } else {
+ e_debug(client_event, "download: "
"finished request for [%u]",
tcreq->files_idx);
}
struct istream *fstream;
const char *reason;
- if (debug) {
- i_debug("test client: download: got response for [%u]",
- tcreq->files_idx);
- }
+ e_debug(client_event, "download: got response for [%u]",
+ tcreq->files_idx);
if (to_client_progress != NULL)
timeout_reset(to_client_progress);
path = paths[tcreq->files_idx];
i_assert(path != NULL);
- if (debug) {
- i_debug("test client: download: path for [%u]: %s",
- tcreq->files_idx, path);
- }
+ e_debug(client_event, "download: path for [%u]: %s",
+ tcreq->files_idx, path);
fstream = test_file_open(path, &status, &reason);
i_assert(fstream != NULL);
}
if (resp->status / 100 != 2) {
- if (debug) {
- i_debug("test client: download: "
- "HTTP request for %s failed: %u %s",
- path, resp->status, resp->reason);
- }
+ e_debug(client_event, "download: "
+ "HTTP request for %s failed: %u %s",
+ path, resp->status, resp->reason);
i_stream_unref(&fstream);
test_client_download_finished(tcreq);
return;
}
if (resp->payload == NULL) {
- if (debug) {
- i_debug("test client: download: "
- "no payload for %s [%u]",
- path, tcreq->files_idx);
- }
+ e_debug(client_event, "download: no payload for %s [%u]",
+ path, tcreq->files_idx);
i_stream_unref(&fstream);
test_client_download_finished(tcreq);
return;
for (; client_files_first < client_files_last &&
paths[client_files_first] == NULL; client_files_first++)
- if (debug) {
- i_debug("test client: download: received until [%u]",
- client_files_first-1);
- }
+ e_debug(client_event, "download: received until [%u]",
+ client_files_first-1);
if (client_files_first >= count) {
io_loop_stop(current_ioloop);
tcreq = test_client_request_new(http_client);
tcreq->files_idx = client_files_last;
- if (debug) {
- i_debug("test client: download: retrieving %s [%u]",
- path, tcreq->files_idx);
- }
+ e_debug(client_event, "download: retrieving %s [%u]",
+ path, tcreq->files_idx);
hreq = tcreq->hreq = http_client_request(
http_client, "GET", net_ip2addr(&bind_ip),
t_strconcat("/download/", path, NULL),
if (tcreq->file_in != NULL)
return;
- if (debug) {
- i_debug("test client: echo: finished [%u]: %s",
- files_idx, paths[files_idx]);
- }
+ e_debug(client_event, "echo: finished [%u]: %s",
+ files_idx, paths[files_idx]);
paths[files_idx] = NULL;
files_finished = TRUE;
/* read payload */
while ((ret = i_stream_read_more(payload, &pdata, &psize)) > 0) {
- if (debug) {
- i_debug("test client: echo: "
- "got data for [%u] (size=%d)",
- tcreq->files_idx, (int)psize);
- }
+ e_debug(client_event, "echo: got data for [%u] (size=%d)",
+ tcreq->files_idx, (int)psize);
/* compare with file on disk */
pleft = psize;
while ((ret = i_stream_read_more(tcreq->file_in,
}
if (ret == 0) {
- if (debug) {
- i_debug("test client: echo: "
- "need more data for [%u]",
- tcreq->files_idx);
- }
+ e_debug(client_event, "echo: need more data for [%u]",
+ tcreq->files_idx);
/* we will be called again for this request */
} else {
(void)i_stream_read(tcreq->file_in);
i_fatal("test client: echo: "
"payload ended prematurely "
"(at least %zu bytes left)", fsize);
- } else if (debug) {
- i_debug("test client: echo: "
- "finished request for [%u]",
+ } else {
+ e_debug(client_event, "echo: finished request for [%u]",
tcreq->files_idx);
}
unsigned int count, status;
struct istream *fstream;
- if (debug) {
- i_debug("test client: echo: got response for [%u]",
- tcreq->files_idx);
- }
+ e_debug(client_event, "echo: got response for [%u]",
+ tcreq->files_idx);
if (to_client_progress != NULL)
timeout_reset(to_client_progress);
path = paths[tcreq->files_idx];
i_assert(path != NULL);
- if (debug) {
- i_debug("test client: echo: path for [%u]: %s",
- tcreq->files_idx, path);
- }
+ e_debug(client_event, "echo: path for [%u]: %s",
+ tcreq->files_idx, path);
if (resp->status / 100 != 2) {
i_fatal("test client: echo: "
if (resp->payload == NULL) {
// FIXME: check file is empty
- if (debug) {
- i_debug("test client: echo: "
- "no payload for %s [%u]",
- path, tcreq->files_idx);
- }
+ e_debug(client_event, "echo: no payload for %s [%u]",
+ path, tcreq->files_idx);
i_stream_unref(&fstream);
test_client_echo_finished(tcreq);
return;
}
http_client_wait(tcreq->client);
- if (debug) {
- i_debug("test client: echo: "
- "sent all payload [%u]",
- tcreq->files_idx);
- }
+ e_debug(client_event, "echo: sent all payload [%u]", tcreq->files_idx);
tcreq->file_out = NULL;
test_client_echo_finished(tcreq);
for (; client_files_first < client_files_last &&
paths[client_files_first] == NULL; client_files_first++);
- if (debug) {
- i_debug("test client: echo: received until [%u/%u]",
- client_files_first-1, count);
- }
+ e_debug(client_event, "echo: received until [%u/%u]",
+ client_files_first-1, count);
- if (debug && client_files_first < count) {
+ if (client_files_first < count) {
const char *path = paths[client_files_first];
- i_debug("test client: echo: next blocking: %s [%d]",
+ e_debug(client_event, "echo: next blocking: %s [%d]",
(path == NULL ? "none" : path), client_files_first);
}
fstream = test_file_open(path, NULL, NULL);
if (fstream == NULL) {
paths[client_files_last] = NULL;
- if (debug) {
- i_debug("test client: echo: "
- "skipping %s [%u]",
- path, client_files_last);
- }
+ e_debug(client_event, "echo: skipping %s [%u]",
+ path, client_files_last);
continue;
}
- if (debug) {
- i_debug("test client: echo: retrieving %s [%u]",
- path, client_files_last);
- }
+ e_debug(client_event, "echo: retrieving %s [%u]",
+ path, client_files_last);
if (tset.unknown_size) {
struct istream *ustream;
i_assert(ioloop_nested_last <= count);
for (i = ioloop_nested_first; i < ioloop_nested_last; i++) {
if (paths[i] != NULL) {
- if (debug) {
- i_debug("test client: "
- "not leaving ioloop [%u]", i);
- }
+ e_debug(client_event, "not leaving ioloop [%u]", i);
break;
}
}
if (ioloop_nested_last > client_files_last)
ioloop_nested_last = client_files_last;
- if (debug) {
- i_debug("test client: "
- "echo: entering ioloop for %u...%u (depth=%u)",
- ioloop_nested_first, ioloop_nested_last,
- ioloop_nested_depth);
- }
+ e_debug(client_event,
+ "echo: entering ioloop for %u...%u (depth=%u)",
+ ioloop_nested_first, ioloop_nested_last,
+ ioloop_nested_depth);
ioloop_nested_depth++;
ioloop_nested_depth--;
- if (debug) {
- i_debug("test client: echo: leaving ioloop for %u...%u "
- "(depth=%u)", ioloop_nested_first,
- ioloop_nested_last, ioloop_nested_depth);
- }
+ e_debug(client_event, "echo: leaving ioloop for %u...%u "
+ "(depth=%u)", ioloop_nested_first,
+ ioloop_nested_last, ioloop_nested_depth);
ioloop_nested_first = ioloop_nested_last = 0;
if (client_files_first >= count || failure != NULL) {
i_set_failure_prefix("SERVER: ");
- if (debug)
- i_debug("PID=%s", my_pid);
+ e_debug(test_event, "PID=%s", my_pid);
ioloop_nested = NULL;
ioloop_nested_depth = 0;
test_server_deinit();
io_loop_destroy(&ioloop);
- if (debug)
- i_debug("Terminated");
+ e_debug(test_event, "Terminated");
i_close_fd(&fd_listen);
test_files_deinit();
i_set_failure_prefix("CLIENT: ");
- if (debug)
- i_debug("PID=%s", my_pid);
+ e_debug(test_event, "PID=%s", my_pid);
ioloop_nested = NULL;
ioloop_nested_depth = 0;
test_client_deinit();
io_loop_destroy(&ioloop);
- if (debug)
- i_debug("Terminated");
+ e_debug(test_event, "Terminated");
}
static void
static void main_init(void)
{
ssl_iostream_openssl_init();
+ test_event = event_create(NULL);
+ client_event = event_create(test_event);
+ event_set_append_log_prefix(client_event, "test client: ");
+ server_event = event_create(test_event);
+ event_set_append_log_prefix(server_event, "test server: ");
}
static void main_deinit(void)
{
ssl_iostream_context_cache_free();
ssl_iostream_openssl_deinit();
+ event_unref(&client_event);
+ event_unref(&server_event);
+ event_unref(&test_event);
}
int main(int argc, char *argv[])
switch (c) {
case 'D':
debug = TRUE;
+ event_set_forced_debug(test_event, TRUE);
+ event_set_forced_debug(client_event, TRUE);
+ event_set_forced_debug(server_event, TRUE);
break;
case 'S':
small_socket_buffers = TRUE;