tests: Pass argument to client main

Change the API to pass an "void *" argument to the client main
function, allowing the caller to call the same main function with
different input.

A helper (client_create_noarg) is added for when no argument is passed,
and the existing test cases are changed to use this function instead.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
This commit is contained in:
Jonas Ådahl 2015-12-28 11:25:00 +08:00
parent 7efe8fbd89
commit 046012a6cf
6 changed files with 45 additions and 37 deletions

View File

@ -614,7 +614,7 @@ TEST(closure_leaks)
{
struct display *d = display_create();
client_create(d, leak_closure);
client_create_noarg(d, leak_closure);
display_run(d);
display_destroy(d);
@ -645,7 +645,7 @@ TEST(closure_leaks_after_error)
struct display *d = display_create();
struct client_info *cl;
cl = client_create(d, leak_after_error);
cl = client_create_noarg(d, leak_after_error);
display_run(d);
wl_client_post_no_memory(cl->wl_client);

View File

@ -95,7 +95,7 @@ empty_client(void)
TEST(tc_leaks_tests)
{
struct display *d = display_create();
client_create(d, empty_client);
client_create_noarg(d, empty_client);
display_run(d);
display_destroy(d);
}
@ -209,7 +209,7 @@ TEST(post_error_to_one_client)
wl_global_create(d->wl_display, &wl_seat_interface,
1, d, bind_seat);
cl = client_create(d, post_error_main);
cl = client_create_noarg(d, post_error_main);
display_run(d);
/* the display was stopped by client, so it can
@ -264,8 +264,8 @@ TEST(post_error_to_one_from_two_clients)
wl_global_create(d->wl_display, &wl_seat_interface,
1, d, bind_seat);
client_create(d, post_error_main2);
cl = client_create(d, post_error_main3);
client_create_noarg(d, post_error_main2);
cl = client_create_noarg(d, post_error_main3);
display_run(d);
/* post error only to the second client */
@ -289,8 +289,8 @@ TEST(post_error_to_two_clients)
wl_global_create(d->wl_display, &wl_seat_interface,
1, d, bind_seat);
cl = client_create(d, post_error_main3);
cl2 = client_create(d, post_error_main3);
cl = client_create_noarg(d, post_error_main3);
cl2 = client_create_noarg(d, post_error_main3);
display_run(d);
@ -331,7 +331,7 @@ TEST(post_nomem_tst)
wl_global_create(d->wl_display, &wl_seat_interface,
1, d, bind_seat);
cl = client_create(d, post_nomem_main);
cl = client_create_noarg(d, post_nomem_main);
display_run(d);
assert(cl->data);
@ -340,7 +340,7 @@ TEST(post_nomem_tst)
/* first client terminated. Run it again,
* but post no memory to client */
cl = client_create(d, post_nomem_main);
cl = client_create_noarg(d, post_nomem_main);
display_run(d);
assert(cl->data);
@ -447,7 +447,7 @@ TEST(threading_errors_tst)
{
struct display *d = display_create();
client_create(d, threading_post_err);
client_create_noarg(d, threading_post_err);
display_run(d);
display_destroy(d);
@ -502,7 +502,7 @@ TEST(threading_cancel_read_tst)
{
struct display *d = display_create();
client_create(d, threading_cancel_read);
client_create_noarg(d, threading_cancel_read);
display_run(d);
display_destroy(d);
@ -542,7 +542,7 @@ threading_read_eagain(void)
TEST(threading_read_eagain_tst)
{
struct display *d = display_create();
client_create(d, threading_read_eagain);
client_create_noarg(d, threading_read_eagain);
display_run(d);
@ -604,7 +604,7 @@ TEST(threading_read_after_error_tst)
{
struct display *d = display_create();
client_create(d, threading_read_after_error);
client_create_noarg(d, threading_read_after_error);
display_run(d);
display_destroy(d);

View File

@ -230,7 +230,7 @@ TEST(queue_proxy_destroy)
test_set_timeout(2);
client_create(d, client_test_proxy_destroy);
client_create_noarg(d, client_test_proxy_destroy);
display_run(d);
display_destroy(d);
@ -242,7 +242,7 @@ TEST(queue_multiple_queues)
test_set_timeout(2);
client_create(d, client_test_multiple_queues);
client_create_noarg(d, client_test_multiple_queues);
display_run(d);
display_destroy(d);
@ -254,7 +254,7 @@ TEST(queue_roundtrip)
test_set_timeout(2);
client_create(d, client_test_queue_roundtrip);
client_create_noarg(d, client_test_queue_roundtrip);
display_run(d);
display_destroy(d);

View File

@ -119,7 +119,7 @@ FAIL_TEST(sanity_malloc_indirect)
FAIL_TEST(tc_client_memory_leaks)
{
struct display *d = display_create();
client_create(d, sanity_malloc_direct);
client_create_noarg(d, sanity_malloc_direct);
display_run(d);
display_destroy(d);
}
@ -127,7 +127,7 @@ FAIL_TEST(tc_client_memory_leaks)
FAIL_TEST(tc_client_memory_leaks2)
{
struct display *d = display_create();
client_create(d, sanity_malloc_indirect);
client_create_noarg(d, sanity_malloc_indirect);
display_run(d);
display_destroy(d);
}
@ -195,11 +195,11 @@ TEST(tc_client_no_fd_leaks)
struct display *d = display_create();
/* Client which does not consume the WAYLAND_DISPLAY socket. */
client_create(d, sanity_fd_no_leak);
client_create_noarg(d, sanity_fd_no_leak);
display_run(d);
/* Client which does consume the WAYLAND_DISPLAY socket. */
client_create(d, sanity_client_no_leak);
client_create_noarg(d, sanity_client_no_leak);
display_run(d);
display_destroy(d);
@ -209,7 +209,7 @@ FAIL_TEST(tc_client_fd_leaks)
{
struct display *d = display_create();
client_create(d, sanity_fd_leak);
client_create_noarg(d, sanity_fd_leak);
display_run(d);
display_destroy(d);
@ -219,7 +219,7 @@ FAIL_TEST(tc_client_fd_leaks_exec)
{
struct display *d = display_create();
client_create(d, sanity_fd_leak);
client_create_noarg(d, sanity_fd_leak);
display_run(d);
display_destroy(d);
@ -263,7 +263,7 @@ TEST(timeout_turnoff)
FAIL_TEST(tc_timeout_tst)
{
struct display *d = display_create();
client_create(d, timeout_tst);
client_create_noarg(d, timeout_tst);
display_run(d);
display_destroy(d);
}
@ -271,7 +271,7 @@ FAIL_TEST(tc_timeout_tst)
FAIL_TEST(tc_timeout2_tst)
{
struct display *d = display_create();
client_create(d, timeout_reset_tst);
client_create_noarg(d, timeout_reset_tst);
display_run(d);
display_destroy(d);
}
@ -280,10 +280,10 @@ TEST(tc_timeout3_tst)
{
struct display *d = display_create();
client_create(d, timeout2_tst);
client_create_noarg(d, timeout2_tst);
display_run(d);
client_create(d, timeout_turnoff);
client_create_noarg(d, timeout_turnoff);
display_run(d);
display_destroy(d);

View File

@ -151,7 +151,8 @@ client_destroyed(struct wl_listener *listener, void *data)
}
static void
run_client(void (*client_main)(void), int wayland_sock, int client_pipe)
run_client(void (*client_main)(void *data), void *data,
int wayland_sock, int client_pipe)
{
char s[8];
int cur_alloc, cur_fds;
@ -170,7 +171,7 @@ run_client(void (*client_main)(void), int wayland_sock, int client_pipe)
cur_alloc = get_current_alloc_num();
cur_fds = count_open_fds();
client_main();
client_main(data);
/* Clients using wl_display_connect() will end up closing the socket
* passed in through the WAYLAND_SOCKET environment variable. When
@ -185,7 +186,8 @@ run_client(void (*client_main)(void), int wayland_sock, int client_pipe)
static struct client_info *
display_create_client(struct display *d,
void (*client_main)(void),
void (*client_main)(void *data),
void *data,
const char *name)
{
int pipe_cli[2];
@ -205,7 +207,7 @@ display_create_client(struct display *d,
close(sock_wayl[1]);
close(pipe_cli[1]);
run_client(client_main, sock_wayl[0], pipe_cli[0]);
run_client(client_main, data, sock_wayl[0], pipe_cli[0]);
close(sock_wayl[0]);
close(pipe_cli[0]);
@ -246,11 +248,14 @@ display_create_client(struct display *d,
}
struct client_info *
client_create_with_name(struct display *d, void (*client_main)(void),
client_create_with_name(struct display *d,
void (*client_main)(void *data), void *data,
const char *name)
{
int can_continue = 1;
struct client_info *cl = display_create_client(d, client_main, name);
struct client_info *cl = display_create_client(d,
client_main, data,
name);
/* let the show begin! */
assert(write(cl->pipe, &can_continue, sizeof(int)) == sizeof(int));

View File

@ -78,8 +78,8 @@ int stop_display(struct client *, int);
* wl_global_create(d->wl_display, ...);
* ... other setups ...
*
* client_create(d, client_main);
* client_create(d, client_main2);
* client_create(d, client_main, data);
* client_create(d, client_main2, data);
*
* display_run(d);
* display_destroy(d);
@ -95,6 +95,9 @@ void display_run(struct display *d);
void display_resume(struct display *d);
struct client_info *client_create_with_name(struct display *d,
void (*client_main)(void),
void (*client_main)(void *data),
void *data,
const char *name);
#define client_create(d, c) client_create_with_name((d), (c), (#c))
#define client_create(d, c, data) client_create_with_name((d), (c), data, (#c))
#define client_create_noarg(d, c) \
client_create_with_name((d), (void(*)(void *)) (c), NULL, (#c))