<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On 19 June 2014 04:37, Bryce W. Harrington <span dir="ltr"><<a href="mailto:b.harrington@samsung.com" target="_blank">b.harrington@samsung.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class=""><div class="h5">On Mon, May 26, 2014 at 04:58:05PM +0200, Marek Chalupa wrote:<br>
> This function checks if a particular protocol error came in wire.<br>
> It's usefull in the cases where we hitherto used FAIL_TEST.<br>
> The problem with FAIL_TEST is that *any* assert will pass the test,<br>
> but we want only some asserts to pass the test (i. e. we don't<br>
> want the test to pass when it, for example, can't connect to display).<br>
> FAIL_TESTs are good only for sanity testing.<br>
><br>
> The expect_protocol_error allows us to turn all FAIL_TESTs to TESTs<br>
> as will be introduced in following patches.<br>
> ---<br>
> tests/weston-test-client-helper.c | 49 +++++++++++++++++++++++++++++++++++++++<br>
> tests/weston-test-client-helper.h | 4 ++++<br>
> 2 files changed, 53 insertions(+)<br>
><br>
> diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c<br>
> index 186b395..fb2e477 100644<br>
> --- a/tests/weston-test-client-helper.c<br>
> +++ b/tests/weston-test-client-helper.c<br>
> @@ -26,6 +26,7 @@<br>
> #include <stdio.h><br>
> #include <string.h><br>
> #include <unistd.h><br>
> +#include <errno.h><br>
> #include <sys/mman.h><br>
><br>
> #include "../shared/os-compatibility.h"<br>
> @@ -512,6 +513,54 @@ skip(const char *fmt, ...)<br>
> exit(77);<br>
> }<br>
><br>
> +void<br>
> +expect_protocol_error(struct client *client,<br>
> + const struct wl_interface *intf,<br>
> + uint32_t code)<br>
> +{<br>
> + int err;<br>
> + uint32_t errcode, failed = 0;<br>
> + const struct wl_interface *interface;<br>
> + unsigned int id;<br>
> +<br>
> + /* if the error has not came yet, make it happen */<br>
<br>
</div></div>"has not come yet" <br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div><div class="h5"><br>
> + wl_display_roundtrip(client->wl_display);<br>
> +<br>
> + err = wl_display_get_error(client->wl_display);<br>
> +<br>
> + assert(err && "Expected protocol error but nothing came");<br>
> + assert(err == EPROTO && "Expected protocol error but got local error");<br>
> +<br>
> +<br>
> + errcode = wl_display_get_protocol_error(client->wl_display,<br>
> + &interface, &id);<br>
> +<br>
> + /* check error */<br>
> + if (errcode != code) {<br>
> + fprintf(stderr, "Should get error code %d but got %d\n",<br>
> + code, errcode);<br>
> + failed = 1;<br>
> + }<br>
> +<br>
> + /* this should be definitely set */<br>
> + assert(interface);<br>
> +<br>
> + if (strcmp(intf->name, interface->name) != 0) {<br>
> + fprintf(stderr, "Should get interface '%s' but got '%s'\n",<br>
> + intf->name, interface->name);<br>
> + failed = 1;<br>
> + }<br>
> +<br>
> + if (failed) {<br>
> + fprintf(stderr, "Expected other protocol error\n");<br>
> + abort();<br>
> + }<br>
> +<br>
> + /* all OK */<br>
> + fprintf(stderr, "Got expected protocol error on '%s' (object id: %d) "<br>
> + "with code %d\n", interface->name, id, errcode);<br>
> +}<br>
> +<br>
<br>
</div></div>I think if you move the assert higher, you can condense the logic a<br>
bit. Maybe it's clearer: </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class=""><br>
/* this should be definitely set */<br>
</div> assert(interface);<br>
<br>
if (errcode != code) {<br>
<div class=""> fprintf(stderr, "Should get error code %d but got %d\n",<br>
</div> code, errcode);<br>
} else if (strcmp(intf->name, interface->name) != 0) {<br>
<div class=""> fprintf(stderr, "Should get interface '%s' but got '%s'\n",<br>
</div> intf->name, interface->name);<br>
} else {<br>
<div class=""> fprintf(stderr, "Got expected protocol error on '%s' (object id: %d) "<br>
</div><div class=""> "with code %d\n", interface->name, id, errcode);<br>
</div> return;<br>
}<br>
<br>
fprintf(stderr, "Expected a different protocol error\n");<br>
abort();<br>
}<br>
<br>
I wonder if the final error message is a bit redundant.<br></blockquote><div><br></div><div>Maybe, but consider this output (subsurface test):<br><br>test-client: got global pointer 45 75<br>test-client: got keyboard keymap<br>
test-client: got surface enter output 0x156e850<br>libwayland: wl_subcompositor@11: error 0: get_subsurface: wl_subsurface@21: wl_surface@15 is already a sub-surface<br>Got expected protocol error on 'wl_subcompositor' (object id: 11) with code 0<br>
test "test_subsurface_change_link": exit status 0, pass.<br>test-client: got global pointer 45 75<br>test-client: got keyboard keymap<br>test-client: got surface enter output 0x156e850<br>libwayland: wl_subcompositor@13: error 0: get_subsurface: wl_subsurface@20: wl_surface@14 is already a sub-surface<br>
Got expected protocol error on 'wl_subcompositor' (object id: 13) with code 0<br><br></div><div>Without the message about the expected error it would look like the test is wrong,<br>since there's message from libwayland about an error and the test passes.<br>
</div><div></div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class=""><br>
> static void<br>
> log_handler(const char *fmt, va_list args)<br>
> {<br>
> diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h<br>
> index 4bfc3fa..f154661 100644<br>
> --- a/tests/weston-test-client-helper.h<br>
> +++ b/tests/weston-test-client-helper.h<br>
> @@ -129,4 +129,8 @@ get_n_egl_buffers(struct client *client);<br>
> void<br>
> skip(const char *fmt, ...);<br>
><br>
> +void<br>
> +expect_protocol_error(struct client *client,<br>
> + const struct wl_interface *intf, uint32_t code);<br>
> +<br>
> #endif<br>
<br>
<br>
</div>Reviewed-by: Bryce Harrington <<a href="mailto:b.harrington@samsung.com">b.harrington@samsung.com</a>><br>
</blockquote></div><br><br></div><div class="gmail_extra">Thank you,<br></div><div class="gmail_extra">Marek<br></div></div>